### Run example on bare LEON3 target Source: https://github.com/adacore/gnatcoverage/blob/master/tools/gnatcov/examples/README.md Use this command to run an example on a bare LEON3 target by setting TARGET and RTS variables. Requires GNAT & GNATemulator products installed. ```shell make TARGET=leon3-elf RTS=light-leon3 runs on bare LEON3 ``` -------------------------------- ### Run example on bare PowerPC target Source: https://github.com/adacore/gnatcoverage/blob/master/tools/gnatcov/examples/README.md Use this command to run an example on a bare PowerPC target by setting TARGET and RTS variables. Requires GNAT & GNATemulator products installed. ```shell make TARGET=powerpc-elf RTS=light-mpc8641 runs on bare PowerPC ``` -------------------------------- ### Make starter example Source: https://github.com/adacore/gnatcoverage/blob/master/tools/gnatcov/README.md Run the starter example by switching to share/examples/gnatcoverage/starter and typing this command. The Makefile includes a generic Makefile common to all examples, and you can run other examples similarly. ```shell engines $ make [TARGET=powerpc-elf] [RTS=light-mpc8641] ``` -------------------------------- ### Run example for native x86/x86_64 Source: https://github.com/adacore/gnatcoverage/blob/master/tools/gnatcov/examples/README.md Use this command to run an example for native x86-linux/windows or x86_64-linux/windows targets. ```shell make ``` -------------------------------- ### Set up coverage runtime with gnatcov setup Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/src_traces.rst Build and install the coverage runtime library using gnatcov setup. The GPR_PROJECT_PATH environment variable is set to allow other project files to reference the coverage runtime project. ```default gnatcov setup --prefix= # Allow references to the coverage runtime project from other project files: export GPR_PROJECT_PATH=/share/gpr ``` -------------------------------- ### Build and install default coverage runtime with gnatcov setup Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/src_traces.rst Builds and installs the default coverage runtime (gnatcov_rts). Add --target, --RTS, or --no-stdlib if needed according to the toolchain. ```sh gnatcov setup ``` -------------------------------- ### Build and install custom coverage runtime with gnatcov setup Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/src_traces.rst Builds and installs the custom coverage runtime using the project extension. Add --target and --RTS if needed; do not run this in the my_rts.gpr directory. ```sh # Add --target and --RTS if needed according to the toolchain to use # Make sure not to run this in my_rts.gpr directory gnatcov setup my_rts/my_rts.gpr ``` -------------------------------- ### gnatcov setup command Source: https://github.com/adacore/gnatcoverage/blob/master/qualification/qualkit/plans/Tool_Qualification_Plan/Qualified_Interface/src_content.rst Installs the coverage runtime into a dedicated directory. Use the GNAT Pro toolchain from the Operational Environment, specifying and for non-native applications. Run once unless the Operational Environment changes. ```text gnatcov setup [--target= --RTS=] --prefix= ``` -------------------------------- ### Example program output with base64 trace Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/src_traces.rst Example output from running the instrumented program, showing sensor values and the base64-encoded source trace file. ```default Sensor( 1) = 1 !Ok! Sensor( 2) = 5 !Ok! Sensor( 3) = 3 !Ok! Sensor( 4) = 7 !Ok! == GNATcoverage source trace file == R05BVGNvdiBzb3VyY2UgdHJhY2UgZmlsZQAAAAAAAAAAAAAABAEAAAAAAAEAAAAHbW9 uaXRvcgAAAAACAAAACAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAcAAAAHAAAAAg AAAAAAALNVLgQbmnY19sbrMoReNvzLLN1DAABtb25pdG9yAF8 == End == ``` -------------------------------- ### Set up coverage runtime with gnatcov setup Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/src_traces.rst Builds and installs the coverage runtime for a PowerPC-VxWorks target with the rtp Ada runtime, then sets GPR_PROJECT_PATH so other project files can reference it. ```default gnatcov setup --target=powerpc-wrs-vxworks7r2 --RTS=rtp \ --prefix= # Allow references to the coverage runtime project from other project files: export GPR_PROJECT_PATH=/share/gpr ``` -------------------------------- ### xcov metrics example for main.adb Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/cov_source.rst Example output from the xcov format showing synthetic metrics at the top of the annotated source. ```default .../metrics/main.adb: 50% of 4 lines covered 75% statement coverage (3 out of 4) 0% decision coverage (0 out of 1) Coverage level: stmt+decision 1 .: with Ada.Text_IO; use Ada.Text_IO; 2 .: with Types; use Types; 3 .: 4 .: procedure main is 5 +: X : My_Int := 12 with Volatile; 6 .: begin 7 !: if X < 2 then 8 -: Put_Line ("X LT 2"); 9 .: else 10 +: Put_Line ("X GE 2"); 11 .: end if; 12 .: end; ``` -------------------------------- ### Build coverage runtime with gnatcov setup Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/src_traces.rst Builds and installs the coverage runtime for a native project or for an ARM ELF project with the light-stm32f4 runtime. The --target and --RTS options must match the toolchain and runtime used for the application code. ```sh gnatcov setup ``` ```sh gnatcov setup --target=arm-eabi --RTS=light-stm32f4 ``` -------------------------------- ### Example testsuite.py invocations for cross and native targets Source: https://github.com/adacore/gnatcoverage/blob/master/testsuite/README.md Example invocations for cross and native configurations, showing target product names and trace modes. ```shell # Cross configurations, using binary traces or source instrumentation: ./testsuite.py --target=ppc-elf --RTS=light-mpc8641 --trace-mode=src ./testsuite.py --target=leon3-elf --RTS=embedded-leon3 --trace-mode=bin # Windows or Linux native configuration, using source instrumentation: ./testsuite.py --trace-mode=src ``` -------------------------------- ### Setup gnatcov for C/C++ with restricted languages Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/integrated_instr.rst Sets up the coverage runtime for C/C++ only, disabling Ada support, and adds the installation prefix to GPR_PROJECT_PATH. The coverage runtime must be visible on GPR_PROJECT_PATH. ```sh gnatcov setup --restricted-to-languages=C,C++ --prefix=/usr/custom export GPR_PROJECT_PATH=$GPR_PROJECT_PATH:/usr/custom/share/gpr ``` -------------------------------- ### gnatcov disp-routines example commands Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/cov_object.rst Three example commands for gnatcov disp-routines showing how to build symbol sets. The first lists symbols from an executable, the second removes symbols from a specific object file, and the third combines @listfile arguments with --include and --exclude to incrementally build the set. Comments describe the resulting set for each command. ```default $ gnatcov disp-routines explore # (symbols defined in the 'explore' executable) $ gnatcov disp-routines explore --exclude test_stations.o # (symbols from the 'explore' executable) # - (symbols from the 'test_stations.o' object file) $ gnatcov disp-routines --include @sl1 --exclude @sl2 --include @sl3 # (symbols from the object files listed in text file sl1) # - (symbols from the object files listed in text file sl2) # + (symbols from the object files listed in text file sl3) ``` -------------------------------- ### Build and install gnatcov front-end Source: https://github.com/adacore/gnatcoverage/blob/master/tools/gnatcov/README.md Build and install the gnatcov front-end itself after the dependencies are in place. The C_SUPPORT=False flag disables C support in the build, and PREFIX specifies the installation root. ```shell gnatcoverage/tools/gnatcov $ make C_SUPPORT=False bin make PREFIX=$prefix install-bin install-examples ``` -------------------------------- ### Set up gnatcov instrumentation context with --prefix Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/getting_started.rst Sets up the instrumentation context, installing the runtime and default parameters for future commands at the specified prefix location. ```default gnatcov setup --prefix=/path/to/gnatcov-rts ``` -------------------------------- ### Install multiple coverage runtimes with --install-name Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/src_traces.rst Installs the coverage runtime under different project names in the same prefix, for example for native and ARM ELF/light-stm32f4 projects. The default install name is gnatcov_rts. ```sh gnatcov setup --install-name=gnatcov_rts_native ``` ```sh gnatcov setup --target=arm-eabi --RTS=light-stm32f4 \ --install-name=gnatcov_rts_stm32f4 ``` -------------------------------- ### Simple CMake example: main.cpp and CMakeLists.txt Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/integrated_instr.rst The main.cpp file prints "Hello World" and returns 0. The CMakeLists.txt file configures the project and builds the hello_world executable from main.cpp. ```c++ #include int main(int argc, char **argv){ std::cout << "Hello World" << std::endl; return 0; } ``` ```cmake cmake_minimum_required(VERSION 3.5) project(HelloWorld) add_executable(hello_world main.cpp) ``` -------------------------------- ### Command-line: @ syntax with --units Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/units_of_interest.rst Create a file listing units, then use @filename to specify them. This example shows the unit list file and the command using it. ```default pak1 pak3 ``` ```default gnatcov --units=@units.list ``` -------------------------------- ### Simple main.cpp file Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/integrated_instr.rst A simple C++ program that prints 'Hello World' to standard output. This is the source file used in the integrated instrumentation example. ```c++ #include int main(int argc, char **argv){ std::cout << "Hello World" << std::endl; return 0; } ``` -------------------------------- ### Install coverage runtime with custom prefix Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/src_traces.rst Installs the coverage runtime in a custom prefix instead of the toolchain's default prefix. After installation, update GPR_PROJECT_PATH to locate the installed project file. ```sh gnatcov setup --prefix=/usr/custom ``` -------------------------------- ### Install sshpass utility Source: https://github.com/adacore/gnatcoverage/blob/master/testsuite/tests/t_U204_026_arch_mix/README.md Install the sshpass utility, which is required for updating the test artifacts. This command is available through apt. ```bash apt install -y sshpass ``` -------------------------------- ### Build and install Binutils libraries Source: https://github.com/adacore/gnatcoverage/blob/master/tools/gnatcov/README.md These commands build static binutils libraries that gnatcov needs for object code disassembling. They are statically linked into gnatcov and can be installed in a temporary directory. Use a release like 2.42 for best results. ```shell binutils-2.42 $ ./configure --enable-targets=all \ --prefix=$prefix_binutils \ --enable-install-libiberty \ --disable-werror --disable-gdb \ --disable-sim --disable-ld --disable-libquadmath \ --disable-readline binutils-2.42 $ make binutils-2.42 $ make install binutils-2.42 $ export LIBRARY_PATH=$prefix_binutils/lib64:$prefix_binutils/lib:$LIBRARY_PATH binutils-2.42 $ export C_INCLUDE_PATH=$prefix_binutils/include:$C_INCLUDE_PATH ``` -------------------------------- ### gnatcov run command line examples for cross and native configurations Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/run_control.rst A set of valid gnatcov run command lines illustrating program selection via EXE, eargs, or project Main attribute, and argument passing in cross and native configurations. Includes examples with -o, -eargs, -P, -T, and board specialization. ```default gnatcov run --target=powerpc-elf myprog # Run "myprog" using powerpc-elf-gnatemu as the execution environment. # Produce myprog.trace in the current directory. ``` ```default gnatcov run --target=powerpc-elf myprog -o myrun.trace # Likewise, producing myrun.trace instead, still in the current directory ``` ```default gnatcov run --target=powerpc-elf myprog -o myrun.trace -eargs --version # Likewise, also requesting version output from the low level execution # engine, *not* from gnatemulator if it happens to be involved. ``` ```default gnatcov run --target=powerpc-elf -o myrun.trace -eargs myprog --version # Likewise, providing the executable program to run as the first earg ``` ```default gnatcov run --target=powerpc-elf -o myrun.trace -Pmyprj.gpr -eargs --version # Likewise, inferring the executable program name from the Main attribute # in myprj.gpr. ``` ```default gnatcov run --target=powerpc-elf myprog -T "trace for doc example" # Providing a trace tag, that can de retrieved with trace dump facilities # and which is displayed in some output reports. ``` ```default gnatcov run --target=powerpc-eabispe myprog # Run "myprog" using powerpc-eabispe-gnatemu as the execution environment. # Produce myprog.trace in the current directory. ``` ```default gnatcov run --target=powerpc-eabispe,mpc5566 myprog # Likewise, instructing gnatemu to select the "mpc5566" board emulation. ``` ```default gnatcov run -eargs myprog arg1 arg2 # Where supported, run "myprog" in the native environment through an # instrumentation layer to produce the execution trace. Pass arg1 and arg2 # as command line arguments to "myprog". ``` -------------------------------- ### =xcov+ output with instruction annotations for Assert example Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/cov_object.rst Shows the =xcov+ output for the Assert example, which includes individual instruction annotations alongside line coverage. It confirms the partial branch coverage annotation on the if statement line (line 3) and shows the underlying instructions with their coverage indications. ```default examples/src/assert.adb: Coverage level: branch 1 +: procedure Assert (T : Boolean) is <_ada_assert+00000000>:+ 0c4 +: 94 21 ff e0 stwu r1,-0x0020(r1) ... 0dc +: 98 1f 00 08 stb r0,0x0008(r31) 2 .: begin 3 !: if not T then <_ada_assert+0000001c>:! 0e0 +: 88 1f 00 08 lbz r0,0x0008(r31) ... 0ec +: 2f 80 00 00 cmpiw cr7,r0,0x0000 0f0 >: 41 9e 00 18 beq- cr7,0x108 <_ada_assert+00000044> 4 -: raise Program_Error; <_ada_assert+00000030>:- 0f4 -: 3c 00 ff f0 lis r0,-0x0010 ... 104 -: 48 00 00 a1 bl 0x1a4 <__gnat_last_chance_handler> 5 .: end if; 6 +: end Assert; <_ada_assert+00000044>:+ ... 120 +: 4e 80 00 20 blr ``` -------------------------------- ### GNAT project Example1 with Coverage units Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/cons_traces.rst Example GNAT project file that hosts all code and tests, explicitly listing the units of interest for coverage analysis. ```default project Example1 is for Source_Dirs use ("code", "tests"); -- Test drivers for Main use ("test_cmd_safe.adb", "test_cmd_unsafe.adb"); -- State subset of units of interest to coverage analysis package Coverage is for Units use ("commands"); end Coverage; end Example1; ``` -------------------------------- ### Ada source before annotation Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/external_annotations.rst Example Ada source file main.adb used to illustrate buffer dump annotation placement and the effect of --annotate-after. ```Ada procedure Main is begin -- Run the actual program Do_Processing; -- Cleanup temp files Do_Cleanup; end Main; ``` -------------------------------- ### Build and install gnatcoll-core Source: https://github.com/adacore/gnatcoverage/blob/master/tools/gnatcov/README.md These commands build and install the GNATcoll components for mmap and project files management, required for the gnatcov build. The commands assume the source is available from the gnatcoll-core repository. ```shell gnatcoll-core $ make setup ENABLE_SHARED=no GNATCOLL_MMAP=yes prefix=$prefix gnatcoll-core $ make gnatcoll-core $ make install ``` -------------------------------- ### Ada example: spec/body and test driver with gnatcov statement coverage Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/cov_source.rst First part of the example. Shows the Ada spec/body for Div_With_Check, the Test_Div1 driver, the gnatcov coverage command for statement coverage producing an xcov result, and the resulting annotated source output. ```ada function Div_With_Check (X, Y : Integer) return Integer; -- return X / Y if Y /= 0. Raise Program_Error otherwise function Div_With_Check (X, Y : Integer) return Integer is begin if Y = 0 then raise Program_Error; else return X / Y; end if; end; ``` ```ada procedure Test_Div1 is X : constant Integer := 4; begin Assert (Div_With_Check (X, 1) = X); end; ``` ```default gnatcov coverage --level=stmt -P ut.gpr --annotate=xcov test_div1.srctrace ``` ```default examples/src/div_with_check.adb: 67% of 3 lines covered Coverage level: stmt 1 .: function Div_With_Check (X, Y : Integer) return Integer is 2 .: begin 3 +: if Y = 0 then 4 -: raise Program_Error; 5 .: else 6 +: return X / Y; 7 .: end if; 8 .: end; ``` -------------------------------- ### Combined xcov report with full statement coverage Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/cons_traces.rst Example =xcov report after combining traces, showing complete statement coverage of the Commands body. ```default 6 .: procedure Stat (Safe : Boolean) is 7 .: begin 8 +: if Safe then 9 +: N_Safe := N_Safe + 1; 10 .: else 11 +: N_Unsafe := N_Unsafe + 1; 12 .: end if; 13 .: end Stat; ``` -------------------------------- ### Obligation count metrics example Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/cov_source.rst Obligation count based metrics for statement and decision coverage. ```default 75% statement coverage (3 out of 4) 0% decision coverage (0 out of 1) ``` -------------------------------- ### Example file set for a Testcase Source: https://github.com/adacore/gnatcoverage/blob/master/testsuite/Qualif/Appendix/Testsuite/app.rst Illustrates the file organization for a hypothetical Testcase exercising an Ada function F with an 'and then' evaluation. It shows three program tests (drivers) and one consolidation scenario, with functional, driver, and consolidation files. ```text andthen.adb -- functional code, F (A, B: Boolean) return Boolean test_andthen_tt.adb -- driver calling F (True, True), and stating what -- coverage results are expected over andthen.adb test_andthen_tf.adb -- driver calling F (True, False) test_andthen_fx.adb -- driver calling F (False, X) for X in [True, False] cons_andthen_all.adb -- consolidation spec for all the program tests, -- with the corresponding expected coverage results ``` -------------------------------- ### C source file foo.c with include and function definitions Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/units_of_interest.rst Example C source file 'foo.c' that includes a header and defines functions. It illustrates the concept of a translation unit for C, where units of interest are designated by toplevel source file names. ```c #include "foo.h" static int bar (void) { ... } ... void foo (int x) { ... } ``` -------------------------------- ### Line count metric example Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/cov_source.rst Line count based metric displayed first in the xcov output. ```default 50% of 4 lines covered ``` -------------------------------- ### Link support directory for light/Ravenscar configurations Source: https://github.com/adacore/gnatcoverage/blob/master/testsuite/README.md Creates a symbolic link to the support directory from the GNATcoverage examples, required for light (formerly ZFP) or Ravenscar configurations. ```shell ln -s $gnatcov-src-dir/tools/gnatcov/examples/support support ``` -------------------------------- ### Ada example: Test_Div0 with Y=0 and xcov outputs Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/cov_source.rst Second experiment exercising Y=0, with the test driver, the coverage command, and the xcov outputs for both the functional unit and the driver. ```ada procedure Test_Div0 is Result : Integer := Div_With_Check (4, 0); begin Put_Line ("R = " & Integer'Image (Result)); end; ``` ```default gnatcov coverage --level=stmt -Pmytest.gpr --annotate=xcov test_div0.trace ``` ```default 1 .: function Div_With_Check (X, Y : Integer) return Integer is 2 .: begin 3 +: if Y = 0 then 4 +: raise Program_Error; 5 .: else 6 -: return X / Y; 7 .: end if; 8 .: end; 9 .: ``` ```default 67% of 3 lines covered Coverage level: stmt 1 .: with Div_With_Check, Ada.Text_IO; use Ada.Text_IO; 2 .: 3 .: procedure Test_Div0 is 4 +: Result : Integer 5 +: := Div_With_Check (4, 0); 6 .: begin 7 -: Put_Line ("R = " & Integer'Image (Result)); 8 .: end; ``` -------------------------------- ### C source before annotation Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/external_annotations.rst Example C source file main.c used to illustrate where to place buffer dump annotations. The annotation location is in the cleanup comment line. ```C int main(){ // Execute the core program do_stuff(); // Cleanup temp files cleanup(); } ``` -------------------------------- ### Expected --annotate=xcov output for in_range.adb Source: https://github.com/adacore/gnatcoverage/blob/master/testsuite/Qualif/Appendix/Testsuite/app.rst Expected output from 'gnatcov --annotate=xcov' for the in_range.adb example, showing line annotations with '+' and '-' markers indicating coverage status. ```text expected notes here v 1 .: function In_Range (X , Min, Max : Integer) return Boolean is 2 .: begin 3 +: if X < Min then -- # XcmpMin 4 -: return False; -- # XoutMin 5 +: elsif X > Max then -- # XcmpMax 6 +: return False; -- # XoutMax 7 .: else 8 -: return True; -- # Xin 9 .: end if; 10 .: end; ``` -------------------------------- ### Create custom coverage runtime project extension (my_rts.gpr) Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/src_traces.rst Creates a dedicated directory and a project extension that extends the default coverage runtime project. The project file and sources must be in a dedicated directory for integration with the gnatcov setup workflow. ```sh mkdir my_rts cat > my_rts/my_rts.gpr < mkdir build cd build gnatcov setup-integration --files=/main.cpp --compilers=g++ ``` ```sh cmake .. -DCMAKE_CXX_COMPILER=/build/g++ ``` -------------------------------- ### TikZ BDD for decision with conditions C0, C'1, C''1, C'2, C''2 Source: https://github.com/adacore/gnatcoverage/blob/master/tools/gnatcov/misc/reports/obc-mcdc.tex TikZ code drawing a BDD with five condition nodes (C0, C'1, C''1, C'2, C''2) and edges labeled T/F. This is the second example BDD shown on the page, illustrating a more complex decision structure. ```latex \draw (0,0) rectangle node {$C_{0}$} (3,-0.5); \node at (0,-0.5) (if_c0_true) {}; \node at (3,-0.5) (if_c0_false) {}; \draw (0,-1) rectangle node {$C'_{1}$} (1.5,-1.5); \node at (0,-1) (c1a_left) {}; \node at (1.5,-1) (c1a_right) {}; \node at (0,-1.5) (if_c1a_true) {}; \node at (1.5,-1.5) (if_c1a_false) {}; \draw (1.5,-2) rectangle node {$C''_{1}$} (3,-2.5); \node at (1.5,-2) (c1b_left) {}; \node at (3,-2) (c1b_right) {}; \node at (1.5,-2.5) (if_c1b_true) {}; \node at (3,-2.5) (if_c1b_false) {}; \draw (0,-3) rectangle node {$C'_{2}$} (1.5,-3.5); \node at (0,-3) (c2a_left) {}; \node at (1.5,-3) (c2a_right) {}; \node at (0,-3.5) (if_c2a_true) {}; \node at (1.5,-3.5) (if_c2a_false) {}; \draw (1.5,-4) rectangle node {$C''_{2}$} (3,-4.5); \node at (1.5,-4) (c2b_left) {}; \node at (3,-4) (c2b_right) {}; \node at (1.5,-4.5) (if_c2b_true) {}; \node at (3,-4.5) (if_c2b_false) {}; \node at (0, -5) (outcome_true1) {}; \node at (1.5, -5) (outcome_true2) {}; \node at (3, -5) (outcome_false) {}; \node at (0, -5.1) (outcome_true1_label) {T}; \node at (1.5, -5.1) (outcome_true2_label) {T}; \node at (3, -5.1) (outcome_false_label) {F}; \draw [->] (if_c0_true) -- node[left] {T} (c1a_left); \draw [->] (if_c0_false) -- node[right] {F} (c1b_right); \draw [->] (if_c1a_true) -- node[left] {T} (c2a_left); \draw [->] (if_c1a_false) -- node[right] {F} (c1b_left); \draw [->] (if_c1b_true) -- node[left] {T} (c2a_right); \draw [->] (if_c1b_false) -- node[right] {F} (c2b_right); \draw [->] (if_c2a_true) -- node[left] {T} (outcome_true1); \draw [->] (if_c2a_false) -- node[right] {F} (c2b_left); \draw [->] (if_c2b_true) -- node[left] {T} (outcome_true2); \draw [->] (if_c2b_false) -- node[right] {F} (outcome_false); ``` -------------------------------- ### Ada test with two Vops instantiations and calls to Inc and Mult Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/cov_source.rst Instantiates Vops with sizes 5 and 8 (files v5.ads and v8.ads) and a test procedure (test_5inc_8mult.adb) that calls Inc only through V5 and Mult only through V8. This setup shows that both subprograms are called overall, so the generic body is fully covered. The source combines the two instance files and the test procedure in one example. ```ada with Vops; -- v5.ads package V5 is new Vops (Size => 5); with Vops; -- v8.ads package V8 is new Vops (Size => 8); with V5, V8; -- test_5inc_8mult.adb procedure Test_5inc_8mult is V5o : V5.Vector_Type := (others => 1); V8o : V8.Vector_Type := (others => 2); begin V5.Inc (V5o, 3); V8.Mult (V8o, 2); end; ``` -------------------------------- ### Build PLANS document Source: https://github.com/adacore/gnatcoverage/blob/master/qualification/qualification.md Builds the PLANS document (a simple ReST document) in either HTML or PDF format. Run from the `qualification/plans` directory. ```console (qualification/qualkit/plans)$ make [html|pdf] ``` -------------------------------- ### Run testsuite.py with options Source: https://github.com/adacore/gnatcoverage/blob/master/testsuite/README.md Launches the testsuite driver with optional target product, runtime, and other options, plus an optional regexp to filter tests. ```shell ./testsuite.py [--target= --RTS=] [other-options] [regexp] ``` -------------------------------- ### Update GPR_PROJECT_PATH for custom prefix Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/src_traces.rst Adds the custom installation prefix to GPR_PROJECT_PATH so tools can find the coverage runtime project file when it is installed in a non-default location. ```sh export GPR_PROJECT_PATH=$GPR_PROJECT_PATH:/usr/custom/share/gpr ``` -------------------------------- ### Build qualkit with anod Source: https://github.com/adacore/gnatcoverage/blob/master/qualification/qualification.md Builds the qualification kit using anod from a Linux wavefront sandbox. This is the simplest way to generate a qualkit, but it cannot produce a kit for a Windows hosted testsuite run because the PDF documents depend on texlive, which is not available on Windows hosts. ```console (wave)$ anod build gnatcov-qualkit ``` -------------------------------- ### Show testsuite.py help Source: https://github.com/adacore/gnatcoverage/blob/master/testsuite/README.md Displays help for the testsuite driver options. ```shell ./testsuite.py --help ``` -------------------------------- ### Example annotated source report output Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/getting_started.rst Example annotated source report output from gnatcov coverage. The + and - annotations indicate covered and uncovered statements; here the Decrement operation is not covered. ```default examples/starter/src/ops.adb: 67% of 3 lines covered Coverage level: stmt 1 .: package body Ops is 2 .: procedure Apply (Op : Op_Kind; X : in out Integer) is 3 .: begin 4 +: case Op is 5 +: when Increment => X := X + 1; 6 -: when Decrement => X := X - 1; 7 .: end case; 8 .: end Apply; 9 .: end Ops; ``` -------------------------------- ### xcov annotated source example for Assert unit Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/cov_object.rst Example output from gnatcov coverage --annotate=xcov for the Assert unit, showing the header with coverage percentage and the annotated source lines with coverage status characters. ```default examples/src/assert.adb: 75% of 4 lines covered Coverage level: insn 1 +: procedure Assert (T : Boolean) is 2 .: begin 3 +: if not T then 4 -: raise Program_Error; 5 .: end if; 6 +: end Assert; ``` -------------------------------- ### ZAMCOV Expression Coverage Example (abs.ml) Source: https://github.com/adacore/gnatcoverage/blob/master/publications/201003-bytecode.pdf Example of a simple Objective Caml program used to illustrate expression coverage. The decision in the if statement only takes the value false when calling abs (-5), so the structural coverage is incomplete. ```ocaml let abs x = let y = ref 0 in if x < !y then y := -x; !y;; abs (-5);; ``` -------------------------------- ### Ada support unit for coverage report examples Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/cov_object.rst Example Ada support unit used to illustrate the various output report formats for object coverage analysis. The subprogram is expected never to be called with T False in nominal situations. ```ada -- raise Program_Error if T is False. Do nothing otherwise. procedure Assert (T : Boolean) is begin if not T then raise Program_Error; end if; end Assert; ``` -------------------------------- ### Build STR document Source: https://github.com/adacore/gnatcoverage/blob/master/qualification/qualification.md Builds the STR document via make. Run after copying the generated sources. ```console (qualification/qualkit/str)$ make [html|pdf] ``` -------------------------------- ### Disable runtime checks with gnatcov setup --no-stdlib -gargs -gnatp Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/src_traces.rst Disables runtime checks during coverage runtime setup to avoid implicit dependency on Ada runtime symbols like __gnat_last_chance_handler. Use when the application is not linked against the Ada runtime library. ```default gnatcov setup --no-stdlib -gargs -gnatp ``` -------------------------------- ### Override default source trace dump options with --dump-* Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/src_traces.rst Shows how to override default source trace dump settings for gnatcov setup and instrument. Options passed to gnatcov instrument take precedence over those passed to gnatcov setup. Defaults may change between GNATcoverage versions. ```sh # Use what gnatcov thinks the most sensible defaults for the target platform # are. gnatcov setup gnatcov instrument # ... # Setup to use atexit/bin-file by default, then use these defaults for # instrumentation. gnatcov setup --dump-trigger=atexit --dump-channel=bin-file gnatcov instrument # ... # Make atexit/bin-file the default at setup time, but actually use # main-end/base64-stdout for source instrumentation. gnatcov setup --dump-trigger=atexit \ --dump-channel=bin-file gnatcov instrument --dump-trigger=main-end \ --dump-channel=base64-stdout # ... # Make atexit/bin-file the default at setup time, but actually use # main-end for source instrumentation (thus still using the default # bin-file). gnatcov setup --dump-trigger=atexit \ --dump-channel=bin-file gnatcov instrument --dump-trigger=main-end # ... ``` -------------------------------- ### =xcov output for partial branch coverage in Assert example Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/cov_object.rst Shows the =xcov output for the Assert example, reporting 50% of 4 lines covered at branch level. The partial branch coverage translates into a partial coverage annotation on the line of the if statement (line 3) that the conditional branch implements. ```default examples/src/assert.adb: 50% of 4 lines covered Coverage level: branch 1 +: procedure Assert (T : Boolean) is 2 .: begin 3 !: if not T then 4 -: raise Program_Error; 5 .: end if; 6 +: end Assert; ``` -------------------------------- ### Full workflow with ALI list filtering Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/bin_intro.rst Complete example sequence for building, running, and analyzing coverage while excluding test harness units. Uses gnatbind's -A option to generate a list of ALI files, filters it with grep, and passes the filtered list to gnatcov run and coverage via --scos=@nontest.alis. ```default # Build executable and produce the corresponding list of ALI files. Pass # -A to gnatbind through gprbuild -bargs then filter out the test units: gprbuild -p --target=powerpc-elf --RTS=light-mpc8641 -Ptests.gpr -cargs -fdump-scos -g -fpreserve-control-flow -bargs -A=all.alis # Run and analyze all units except the test harness, filtering out # the correspond ALI files from the list: grep -v 'test_[^/]*.ali' all.alis > nontest.alis gnatcov run --level=stmt+mcdc --scos=@nontest.alis gnatcov coverage --level=stmt+mcdc --annotate=xcov --scos=@nontest.alis ``` -------------------------------- ### =asm output for partial branch coverage in Assert example Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/cov_object.rst Shows the =asm instruction annotations for the Assert example, where the conditional branch at offset 0f0 is always taken (annotated with '>'), illustrating partial branch coverage. The 'v' and '>' annotations indicate a conditional branch executed and taken one way only. ```default _ada_assert !: 0c4-123 0c4 +: 94 21 ff e0 stwu r1,-0x0020(r1) ... 0ec +: 2f 80 00 00 cmpiw cr7,r0,0x0000 0f0 >: 41 9e 00 18 beq- cr7,0x108 <_ada_assert+00000044> ... 100 -: 38 80 00 04 li r4,0x0004 104 -: 48 00 00 a1 bl 0x1a4 <__gnat_last_chance_handler> 108 +: 60 00 00 00 ori r0,r0,0x0000 ... 120 +: 4e 80 00 20 blr ``` -------------------------------- ### Configure instrumentation with gnatcov setup-integration Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/integrated_instr.rst Command to configure the instrumentation process for the main.cpp file using the g++ compiler. This must be run before building the instrumented executable. ```sh cd gnatcov setup-integration --files=/main.cpp --compilers=g++ ``` -------------------------------- ### C decision condition exemption Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/exemptions.rst Equivalent C/C++ example to exempt a condition in MCDC using GNATCOV_EXEMPT_DECISION_CONDITION. ```c // GNATCOV_EXEMPT_DECISION_CONDITION(2, "Debug code") if (message_requested || debug) send_message (); ``` -------------------------------- ### Load source traces separately and generate coverage report Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/cons_sco_variations.rst Load each source trace with its corresponding project loading options (-P, -X) and save a checkpoint per trace. Then generate the coverage report from the checkpoints using --checkpoint options. ```sh gnatcov coverage -Pexample -XLOGGING_BACKEND=text_io \ main_text_io.srctrace \ --level=stmt --save-checkpoint=text_io.ckpt gnatcov coverage -Pexample -XLOGGING_BACKEND=gnat_io \ main_gnat_io.srctrace \ --level=stmt --save-checkpoint=gnat_io.ckpt ``` ```sh gnatcov coverage \ --checkpoint=text_io.ckpt \ --checkpoint=gnat_io.ckpt \ --level=stmt --annotate=xcov --output-dir=xcov ``` -------------------------------- ### Ada test procedure Test_Cmd_Unsafe Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/cons_traces.rst Test procedure exercising only unsafe commands. Used to produce a trace for the second test in the consolidation example. ```ada procedure Test_Cmd_Unsafe is begin -- Stepping forward without room ahead is always unsafe Assert (not Safe (Cmd => Step, Front => Rock)); Assert (not Safe (Cmd => Step, Front => Pit)); end Test_Cmd_Unsafe; ``` -------------------------------- ### Ada test procedure Test_Cmd_Safe Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/cons_traces.rst Test procedure exercising only safe commands. Used to produce a trace for the first test in the consolidation example. ```ada procedure Test_Cmd_Safe is begin -- Remaining still is always safe, as is stepping with room ahead: Assert (Safe (Cmd => Hold, Front => Rock)); Assert (Safe (Cmd => Hold, Front => Pit)); Assert (Safe (Cmd => Step, Front => Ground)); end Test_Cmd_Safe; ``` -------------------------------- ### Produce traces for ARM and host targets Source: https://github.com/adacore/gnatcoverage/blob/master/doc/gnatcov/cons_sco_variations.rst Shows instrumenting and running a project for an ARM target and a native host, producing onboard.srctrace and native.srctrace. These traces can then be consolidated using either of the two methods referenced in the text. ```sh # Instrument and run the program to run on the ARM system gnatcov instrument --level=stmt \ -P example.gpr --target=arm-eabi --RTS=light-stm32f4 gprbuild --src-subdirs=gnatcov-instr --implicit-with=gnatcov_rts \ -P example.gpr --target=arm-eabi --RTS=light-stm32f4 # [execute on target and produce onboard.srctrace] # Instrument and run the program to run on the host system gnatcov instrument --level=stmt \ -P example.gpr gprbuild --src-subdirs=gnatcov-instr --implicit-with=gnatcov_rts \ -P example.gpr GNATCOV_TRACE_FILE=native.srctrace obj/example ```