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:

  1. cmake -dcmake_build_type=coverage .. build_coverage directory created target.dir directory , *.gcno files in it
  2. cd tests && make test executable created , linked against shared library in build_coverage directory (maybe here mistake)
  3. 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/:

  1. after cmake -dc...: few *.cmake , *.make files
  2. after make in build_coverage dir: *.gcno files
  3. after lcov -c -i ...: still *.gcno files
  4. after running tests: *.gcda , *.gcno files
  5. 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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -