c++ - Wrong coverage data for unit tests of a library -
i want test complex shared library (cxsc) of cmake. after lot of trial , error managed create html coverage report lines test, boost testing framework, still red.
this script use create coverage report:
rm -fr build_coverage mkdir build_coverage cd build_coverage cmake \ -dcmake_build_type=coverage \ .. make cd ../tests make clean make cd ../build_coverage make cxsc_coverage
the cmake part coverage report gets created:
# cleanup lcov command ${lcov_path} --zerocounters --directory ${cmake_current_source_dir}/build_coverage/cmakefiles/cxsc.dir/src command ${lcov_path} --capture --initial --no-external --directory ${cmake_current_source_dir}/build_coverage/cmakefiles/cxsc.dir/src --output-file ${_outputname}.before # run tests command ld_library_path=${cmake_current_source_dir}/build_coverage ${_testrunner} ${argv3} # capturing lcov counters , generating report command ${lcov_path} --capture --no-checksum --no-external --directory ${cmake_current_source_dir}/build_coverage/cmakefiles/cxsc.dir/src --output-file ${_outputname}.after command ${lcov_path} --add-tracefile ${_outputname}.before --add-tracefile ${_outputname}.after --output-file ${_outputname}.info command ${genhtml_path} -o ${_outputname} ${_outputname}.info
makefile of test binary (i think error is):
g++ \ -o test_runner \ main.cpp \ test_interval.cpp \ -i./../src \ -i./../src/rts \ -i./../src/asm \ -i./../src/fi_lib \ -i./../build_coverage \ -l./../build_coverage \ -lcxsc \ -wall -winline \ -lboost_unit_test_framework
this happens:
cmake -dcmake_build_type=coverage ..
build_coverage directory createdtarget.dir
directory , *.gcno files in itcd tests && make
test executable created , linked against shared library inbuild_coverage
directory (maybe here mistake)make coverage
coverage data collected , tests executed
edit:
to clarify problem, there lines covered global consts or 1 helper function used pretty often. not functions/methods call in tests.
files in build_coverage/cmakefiles/cxsc.dir/src/
:
- after
cmake -dc...
: few *.cmake , *.make files - after
make
inbuild_coverage
dir: *.gcno files - after
lcov -c -i ...
: still *.gcno files - after running tests: *.gcda , *.gcno files
- after
lcov -c ...
: lot of movement in directory still same filenames
i don't see gcov flags in makefile. try 1 test_runner :
g++ \ -wall -winline -fprofile-arcs -ftest-coverage \ main.cpp \ test_interval.cpp \ -i./../src \ -i./../src/rts \ -i./../src/asm \ -i./../src/fi_lib \ -i./../build_coverage \ -l./../build_coverage \ -lcxsc \ -lboost_unit_test_framework \ -lgcov \ -o test_runner
your shared library need flags :
set(cmake_cxx_flags "${cmake_cxx_flags} -fprofile-arcs -ftest-coverage") set(cmake_shared_linker_flags "${cmake_exe_linker_flags} -lgcov")
see post similar problem.
nb : "--coverage" can substitute "-fprofile-arcs -ftest-coverage" , "-lgcov"
Comments
Post a Comment