# this will fail if run with bash!
#==================================================================================
# this will fail if run with bash!
#==================================================================================
# Copyright (c) 2018-2019 AT&T Intellectual Property.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Copyright (c) 2018-2019 AT&T Intellectual Property.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# supplied on the command line. Functions in the test
# files will not be reported on provided that they have
# their prototype (all on the SAME line) as:
# static type name() {
#
# supplied on the command line. Functions in the test
# files will not be reported on provided that they have
# their prototype (all on the SAME line) as:
# static type name() {
#
# [LOW] in the output. A file is considered to pass if the
# overall execution percentage for the file is >= 80% regardless
# of the number of functions that reported low.
#
# Test programmes are built prior to execution. Plan-9 mk is
# the preferred builder, but as it's not widly adopted (sigh)
# [LOW] in the output. A file is considered to pass if the
# overall execution percentage for the file is >= 80% regardless
# of the number of functions that reported low.
#
# Test programmes are built prior to execution. Plan-9 mk is
# the preferred builder, but as it's not widly adopted (sigh)
# invoke a customised builder.
#
# For a module which does not pass, we will attempt to boost
# the coverage by discounting the unexecuted lines which are
# invoke a customised builder.
#
# For a module which does not pass, we will attempt to boost
# the coverage by discounting the unexecuted lines which are
# (m)alloc() calls or are checking for nil pointers as these
# cases are likely impossible to drive. When discount testing
# is done both the failure message from the original analysis
# (m)alloc() calls or are checking for nil pointers as these
# cases are likely impossible to drive. When discount testing
# is done both the failure message from the original analysis
-# and a pass/fail message from the discount test are listed,
-# but only the result of the discount test is taken into
+# and a pass/fail message from the discount test are listed,
+# but only the result of the discount test is taken into
# consideration with regard to overall success.
#
# Overall Pass/Fail
# By default the overall state is based only on the success
# consideration with regard to overall success.
#
# Overall Pass/Fail
# By default the overall state is based only on the success
# state of coverage. If the -s (strict) option is given, then
# overall state will be failure if code coverage expectations
# are not met.
# state of coverage. If the -s (strict) option is given, then
# overall state will be failure if code coverage expectations
# are not met.
echo " if -C is used to provide a custom build command then it must "
echo " contain a %s which will be replaced with the unit test file name."
echo ' e.g.: -C "mk -a %s"'
echo " if -C is used to provide a custom build command then it must "
echo " contain a %s which will be replaced with the unit test file name."
echo ' e.g.: -C "mk -a %s"'
echo " -F show only failures at the function level"
echo " -s strict mode; code coverage must also pass to result in a good exit code"
echo " -v will write additional information to the tty and save the disccounted file if discount run or -f given"
echo " -F show only failures at the function level"
echo " -s strict mode; code coverage must also pass to result in a good exit code"
echo " -v will write additional information to the tty and save the disccounted file if discount run or -f given"
+
+# Merge two coverage files to preserve the total lines covered by different
+# test programmes.
+#
+function merge_cov {
+ if [[ -z $1 || -z $2 ]]
+ then
+ return
+ fi
+
+ if [[ ! -e $1 || ! -e $2 ]]
+ then
+ return
+ fi
+
+ (
+ cat $1
+ echo "==merge=="
+ cat $2
+ ) | awk '
+ /^==merge==/ {
+ merge = 1
+ next
+ }
+
+ merge && /#####:/ {
+ line = $2+0
+ if( executed[line] ) {
+ $1 = sprintf( "%9d:", executed[line] )
+ }
+ }
+
+ merge {
+ print
+ next
+ }
+
+ {
+ line = $2+0
+ if( $1+0 > 0 ) {
+ executed[line] = $1+0
+ }
+ }
+ '
+}
+
# blocks that are testing the result of alloc/malloc calls, or testing for
# nil pointers. The feeling is that these might not be possible to drive
# and shoudn't contribute to coverage deficiencies.
# blocks that are testing the result of alloc/malloc calls, or testing for
# nil pointers. The feeling is that these might not be possible to drive
# and shoudn't contribute to coverage deficiencies.
if( prev_if && prev_malloc ) {
if( prev_malloc ) {
#printf( "allow discount: %s\n", $0 )
if( prev_if && prev_malloc ) {
if( prev_malloc ) {
#printf( "allow discount: %s\n", $0 )
- if( chatty ) {
- gsub( "#####", "=====", $0 )
+ if( replace_flags ) {
+ gsub( "#####", " 1", $0 )
+ //gsub( "#####", "=====", $0 )
pass_fail, full_name ? full_name : module, nexec, unexec, discount, net, orig_cov, adj_cov, module_cov_target )
} else {
printf( "[%s] %d%% (%d%%) %s\n", pass_fail, adj_cov, orig_cov, full_name ? full_name : module )
pass_fail, full_name ? full_name : module, nexec, unexec, discount, net, orig_cov, adj_cov, module_cov_target )
} else {
printf( "[%s] %d%% (%d%%) %s\n", pass_fail, adj_cov, orig_cov, full_name ? full_name : module )
+# Remove unneeded coverage files, then generate the xml files that can be given
+# to sonar. gcov.xml is based on the "raw" coverage and dcov.xml is based on
+# the discounted coverage.
+#
+function mk_xml {
+ rm -fr *_test.c.gcov test_*.c.gcov *_test.c.dcov test_*.c.dcov # we don't report on the unit test code, so ditch
+ cat *.gcov | cov2xml.ksh >gcov.xml
+ cat *.dcov | cov2xml.ksh >dcov.xml
+}
+
module_cov_target=80
builder="make -B %s" # default to plain ole make
verbose=0
show_all=1 # show all things -F sets to show failures only
strict=0 # -s (strict) will set; when off, coverage state ignored in final pass/fail
module_cov_target=80
builder="make -B %s" # default to plain ole make
verbose=0
show_all=1 # show all things -F sets to show failures only
strict=0 # -s (strict) will set; when off, coverage state ignored in final pass/fail
-C) builder="$2"; shift;; # custom build command
-G) builder="gmake %s";;
-M) builder="mk -a %s";; # use plan-9 mk (better, but sadly not widly used)
-C) builder="$2"; shift;; # custom build command
-G) builder="gmake %s";;
-M) builder="mk -a %s";; # use plan-9 mk (better, but sadly not widly used)
trigger_discount_str="WARN|FAIL|PASS" # check all outcomes for each module
;;
-F) show_all=0;;
-s) strict=1;; # coverage counts toward pass/fail state
trigger_discount_str="WARN|FAIL|PASS" # check all outcomes for each module
;;
-F) show_all=0;;
-s) strict=1;; # coverage counts toward pass/fail state
echo "$tfile --------------------------------------"
bcmd=$( printf "$builder" "${tfile%.c}" )
if ! $bcmd >/tmp/PID$$.log 2>&1
echo "$tfile --------------------------------------"
bcmd=$( printf "$builder" "${tfile%.c}" )
if ! $bcmd >/tmp/PID$$.log 2>&1
add_ignored_func test_nng_em.c # the nng/nano emulated things
for f in *_static_test.c # all static modules here
do
add_ignored_func test_nng_em.c # the nng/nano emulated things
for f in *_static_test.c # all static modules here
do
+ if [[ -n capture_file ]]
+ then
+ echo "all errors captured in $capture_file, listing only fail message on tty"
+ echo "$tfile --------------------------------------" >>$capture_file
+ cat /tmp/PID$$.log >>$capture_file
+ grep "^<FAIL>" /tmp/PID$$.log
+ echo ""
+ else
+ if (( quiet ))
+ then
+ grep "^<" /tmp/PID$$.log|grep -v "^<EM>" # in quiet mode just dump <...> messages which are assumed from the test programme not appl
+ else
+ cat /tmp/PID$$.log
+ fi
+ fi
+
+ for x in *.gcov # merge any previous coverage file with this one
+ do
+ if [[ -e $x && -e $x- ]]
+ then
+ merge_cov $x $x- >/tmp/PID$$.mc
+ cp /tmp/PID$$.mc $x
+ rm $x-
+ fi
+ done
+done
+
+echo ""
+echo "[INFO] final discount checks on merged gcov files"
+show_all=1
+for xx in *.gcov
+do
+ if [[ $xx != *"test"* ]]
+ then
+ of=${xx%.gcov}.dcov
+ discount_an_checks $xx >$of
+ tail -1 $of | grep '\['
+ fi
echo "[FAIL] overall unit testing fails: coverage errors=$errors unit test errors=$ut_errors"
else
echo "[PASS] overall unit testing passes"
echo "[FAIL] overall unit testing fails: coverage errors=$errors unit test errors=$ut_errors"
else
echo "[PASS] overall unit testing passes"