From da66779b4339f080fe0c0072701ec20d4b18a358 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Wed, 25 Oct 2023 22:01:01 -0700 Subject: [PATCH] safety: coverage report (#1696) * coverage report * test script * not needed * option * options * re-build if file missing * rename * rename flag * just always build * cmt * fix rebuild, panda.c is what does gens gcno * clean up * check coverage * rename * add skip flag * Revert "add skip flag" This reverts commit 6991c174cebb8529b67199033e017155eff917b0. * both do same thing * clean up script * don't test here * Revert "don't test here" This reverts commit 43fe4c961fcc1693d5efc33cabb8162be56a1b88. * try running in CI * nproc * move * Revert "try running in CI" This reverts commit 912017c7fa93ba3faf31267b9b144cc9faee591b. * don't test here * fix path * re-compiling does this --- .gitignore | 6 ++++++ SConstruct | 4 ++++ tests/libpanda/SConscript | 12 +++++++++++- tests/safety/test_coverage.sh | 13 +++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 tests/safety/test_coverage.sh diff --git a/.gitignore b/.gitignore index 1f96749b..2dfa0947 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,9 @@ nosetests.xml # CTU info files generated by Cppcheck *.*.ctu-info + +# safety coverage-related files +*.gcda +*.gcno +tests/safety/coverage-out +tests/safety/coverage.info diff --git a/SConstruct b/SConstruct index 2f25b44e..eb49dd4c 100644 --- a/SConstruct +++ b/SConstruct @@ -8,5 +8,9 @@ AddOption('--ubsan', action='store_true', help='turn on UBSan') +AddOption('--safety-coverage', + action='store_true', + help='build with safety test coverage options') + # panda fw & test files SConscript('SConscript') diff --git a/tests/libpanda/SConscript b/tests/libpanda/SConscript index 265fac9d..9408e636 100644 --- a/tests/libpanda/SConscript +++ b/tests/libpanda/SConscript @@ -29,4 +29,14 @@ if GetOption('ubsan'): env['CFLAGS'] += flags env['LINKFLAGS'] += flags -env.SharedLibrary("libpanda.so", ["panda.c",]) +panda = env.SharedObject("panda.os", "panda.c") +libpanda = env.SharedLibrary("libpanda.so", [panda]) + +if GetOption('safety_coverage'): + env.Append( + CFLAGS=["-fprofile-arcs", "-ftest-coverage", "-fprofile-abs-path",], + LIBS=["gcov"], + ) + # GCC note file is generated by compiler, ensure we build it, and allow scons to clean it up + AlwaysBuild(panda) + env.SideEffect("panda.gcno", panda) diff --git a/tests/safety/test_coverage.sh b/tests/safety/test_coverage.sh new file mode 100755 index 00000000..f8ab65b4 --- /dev/null +++ b/tests/safety/test_coverage.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -e + +# reset coverage data and generate gcc note file +scons -j$(nproc) -D --safety-coverage + +# run safety tests to generate coverage data +./test.sh + +# generate and open report +geninfo ../libpanda/ -o coverage.info +genhtml coverage.info -o coverage-out +browse coverage-out/index.html