>From f0384147eb59144705c851465ec5770b00e28b12 Mon Sep 17 00:00:00 2001 From: Christian Gagneraud Date: Sun, 27 May 2012 02:02:10 +0100 Subject: [PATCH] Add test coverage reporting --- SConstruct | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 79 insertions(+), 11 deletions(-) diff --git a/SConstruct b/SConstruct index 21214ff..b119fe1 100644 --- a/SConstruct +++ b/SConstruct @@ -156,6 +156,7 @@ boolopts = ( ("python", True, "build Python support and modules."), ("debug", False, "include debug information in build"), ("profiling", False, "build with profiling enabled"), + ("coveraging", False, "build with code coveraging enabled"), ("strip", True, "build with stripping of binaries enabled"), ("chrpath", True, "use chrpath to edit library load paths"), ) @@ -254,6 +255,11 @@ def announce(msg): # We need to define -D_GNU_SOURCE env.Append(CFLAGS='-D_GNU_SOURCE') +# Brute force, take #1 +env.Append(LDFLAGS="--coverage") +env.Append(LINKFLAGS="--coverage") +env.Append(SHLINKFLAGS="--coverage") +env.Append(CPPFLAGS="--coverage") # DESTDIR environment variable means user wants to prefix the installation root. @@ -282,6 +288,14 @@ if not 'CCFLAGS' in os.environ: if env['profiling']: env.Append(CCFLAGS=['-pg']) env.Append(LDFLAGS=['-pg']) + # Should we build with code coveraging? + if env['coveraging']: + # Unfortunately, it doesn't work! (Solution is brute force #1) + # For the py.so brute force #2 *AND* this are needed + env.Append(CCFLAGS=['--coverage']) + env.Append(CXXFLAGS=['--coverage']) + env.Append(LDFLAGS=['--coverage']) + pass # Should we build with debug symbols? if env['debug']: env.Append(CCFLAGS=['-g']) @@ -978,7 +992,8 @@ else: ldshared=ldshared.replace('-pie', '') python_env.Replace(SHLINKFLAGS=[], LDFLAGS=ldflags, - LINK = ldshared, + # Brute force, take #2 + LINK = ldshared + " --coverage", SHLIBPREFIX="", SHLIBSUFFIX=so_ext, CPPPATH=[includepy], @@ -1323,7 +1338,10 @@ audit = env.Alias('audit', # Unit-test the bitfield extractor bits_regress = Utility('bits-regress', [test_bits], [ - '$SRCDIR/test_bits --quiet' + 'lcov -z -d .', + '$SRCDIR/test_bits --quiet', + 'lcov -c -d . -t "bits_test" -o bits_test_bits.lcov', + 'genhtml -s -o cov/bits -t "Bitfield extractor" bits_*.lcov' ]) # Check that all Python modules compile properly @@ -1339,8 +1357,15 @@ else: python_compilation_regress = None # Regression-test the daemon -gps_regress = Utility("gps-regress", [gpsd, python_built_extensions], - '$SRCDIR/regress-driver test/daemon/*.log') +gps_regress = Utility("gps-regress", [gpsd, python_built_extensions], [ + 'for f in $SRCDIR/test/daemon/*.log; do ' + 'lcov -z -d .; ' + '$SRCDIR/regress-driver $${f};' + 'name=daemon_`echo $${f##*/}|tr ".-" _`; ' + 'lcov -c -d . -t "$${name}" -o $${name}.lcov; ' + 'done;', + 'genhtml -s -o cov/daemon -t "Daemon" daemon_*.lcov' + ]) # Test that super-raw mode works. Compare each logfile against itself # dumped through the daemon running in R=2 mode. (This test is not @@ -1360,17 +1385,24 @@ Utility('gps-makeregress', [gpsd, python_built_extensions], rtcm_regress = Utility('rtcm-regress', [gpsdecode], [ '@echo "Testing RTCM decoding..."', 'for f in $SRCDIR/test/*.rtcm2; do ' + 'lcov -z -d .; ' 'echo "Testing $${f}..."; ' - 'TMPFILE=`mktemp -t gpsd-test-XXXXXXXXXXXXXX.chk`; ' + 'TMPFILE=`mktemp`; ' '$SRCDIR/gpsdecode -j <$${f} >$${TMPFILE}; ' + 'name=rtcm_`echo $${f##*/}|tr ".-" _`; ' + 'lcov -c -d . -t "$${name}" -o $${name}.lcov; ' 'diff -ub $${f}.chk $${TMPFILE}; ' 'rm -f $${TMPFILE}; ' 'done;', '@echo "Testing idempotency of JSON dump/decode for RTCM2"', - 'TMPFILE=`mktemp -t gpsd-test-XXXXXXXXXXXXXX.chk`; ' + 'lcov -z -d .; ', + 'TMPFILE=`mktemp`; ' '$SRCDIR/gpsdecode -e -j $${TMPFILE}; ' + 'name=rtcm_json_idempotency; ' + 'lcov -c -d . -t "$${name}" -o $${name}.lcov;' 'grep -v "^#" test/synthetic-rtcm2.json | diff -ub - $${TMPFILE}; ' 'rm -f $${TMPFILE}; ', + 'genhtml -s -o cov/rtcm -t "RTCM decoder" rtcm_*.lcov' ]) # Rebuild the RTCM regression tests. @@ -1384,17 +1416,24 @@ Utility('rtcm-makeregress', [gpsdecode], [ aivdm_regress = Utility('aivdm-regress', [gpsdecode], [ '@echo "Testing AIVDM decoding..."', 'for f in $SRCDIR/test/*.aivdm; do ' + 'lcov -z -d .; ' 'echo "Testing $${f}..."; ' - 'TMPFILE=`mktemp -t gpsd-test-XXXXXXXXXXXXXX.chk`; ' + 'TMPFILE=`mktemp`; ' '$SRCDIR/gpsdecode -u -c <$${f} >$${TMPFILE}; ' 'diff -ub $${f}.chk $${TMPFILE}; ' 'rm -f $${TMPFILE}; ' + 'name=`echo aivdm_$${f##*/}|tr ".-" _`; ' + 'lcov -c -d . -o $${name}.lcov -t $${name}; ' 'done;', + 'lcov -z -d .', '@echo "Testing idempotency of JSON dump/decode for AIS"', - 'TMPFILE=`mktemp -t gpsd-test-XXXXXXXXXXXXXX.chk`; ' + 'TMPFILE=`mktemp`; ' '$SRCDIR/gpsdecode -e -j <$SRCDIR/test/synthetic-ais.json >$${TMPFILE}; ' 'grep -v "^#" $SRCDIR/test/synthetic-ais.json | diff -ub - $${TMPFILE}; ' 'rm -f $${TMPFILE}; ', + 'name=aivdm_json_idempotency; ' + 'lcov -c -d . -o $${name}.lcov -t $${name}', + 'genhtml -s -o cov/aivdm -t "AIVDM decoder" aivdm_*.lcov' ]) # Rebuild the AIVDM regression tests. @@ -1406,8 +1445,11 @@ Utility('aivdm-makeregress', [gpsdecode], [ # Regression-test the packet getter. packet_regress = Utility('packet-regress', [test_packet], [ + 'lcov -z -d .', '@echo "Testing detection of invalid packets..."', '$SRCDIR/test_packet | diff -u $SRCDIR/test/packet.test.chk -', + 'lcov -c -d . -t "packet_detect_invalid" -o packet_detect_invalid.lcov', + 'genhtml -s -o cov/packet -t "Packet getter" packet_*.lcov' ]) # Rebuild the packet-getter regression test @@ -1421,25 +1463,40 @@ Utility('geoid-makeregress', [test_geoid], [ # Regression-test the geoid tester. geoid_regress = Utility('geoid-regress', [test_geoid], [ + 'lcov -z -d .', '@echo "Testing the geoid model..."', '$SRCDIR/test_geoid 37.371192 122.014965 | diff -u $SRCDIR/test/geoid.test.chk -', + 'lcov -c -d . -t geoid_model -o geoid_model.lcov', + 'genhtml -s -o cov/geoid -t "Geoid" geoid_*.lcov' ]) # Regression-test the Maidenhead Locator maidenhead_locator_regress = Utility('maidenhead-locator-regress', [], [ + 'lcov -z -d .', '@echo "Testing the Maidenhead Locator conversion..."', '$SRCDIR/test_maidenhead.py >/dev/null', + 'lcov -c -d . -t maidenhead_locator_conversion -o maidenhead_locator_conversion.lcov', + 'genhtml -s -o cov/maidenhead -t "Maidenhead locator" maidenhead_*.lcov' ]) # Regression-test the calendar functions time_regress = Utility('time-regress', [test_mkgmtime], [ - '$SRCDIR/test_mkgmtime' + 'lcov -z -d .', + '$SRCDIR/test_mkgmtime;', + 'lcov -c -d . -t "time_mkgmtime" -o time_mkgmtime.lcov', + 'genhtml -s -o cov/time -t "Calendar functions" time_*.lcov' ]) # Regression test the unpacking code in libgps unpack_regress = Utility('unpack-regress', [test_libgps], [ '@echo "Testing the client-library sentence decoder..."', - '$SRCDIR/regress-driver -c $SRCDIR/test/clientlib/*.log', + 'for f in $SRCDIR/test/clientlib/*.log; do ' + 'lcov -z -d .; ' + '$SRCDIR/regress-driver -c $${f}; ' + 'name=unpack_`echo $${f##*/}|tr ".-" _`; ' + 'lcov -c -d . -t $${name} -o $${name}.lcov; ' + 'done', + 'genhtml -s -o cov/unpack -t "Client-library sentence decoder" unpack_*.lcov' ]) # Build the regression test for the sentence unpacker @@ -1450,7 +1507,17 @@ Utility('unpack-makeregress', [test_libgps], [ # Unit-test the JSON parsing json_regress = Utility('json-regress', [test_json], [ - '$SRCDIR/test_json' + 'lcov -z -d .; ', + '$SRCDIR/test_json', + 'lcov -c -d . -t "json_parsing" -o json_parsing.lcov;' + 'genhtml -s -o cov/json -t "JSON parsing" json_*.lcov' + ]) + +# Create a all regression test coverage report +coverage_report = Utility('coverage-report', [], [ + # RTCM fails, the code isn't instrumented? + #'rm -f rtcm_regress_*.lcov', + 'genhtml -s -o cov/all -t "All" *.lcov' ]) # Run a valgrind audit on the daemon - not in normal tests @@ -1472,6 +1539,7 @@ check = env.Alias('check', [ time_regress, unpack_regress, json_regress, + coverage_report ]) env.Alias('testregress', check) -- 1.7.0.4