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