Code Review
/
ric-plt
/
lib
/
rmr.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Release RMR version 4.9.2
[ric-plt/lib/rmr.git]
/
test
/
unit_test.ksh
diff --git
a/test/unit_test.ksh
b/test/unit_test.ksh
index
80712a5
..
575c1d8
100755
(executable)
--- a/
test/unit_test.ksh
+++ b/
test/unit_test.ksh
@@
-71,6
+71,9
@@
function usage {
echo " -c allows user to set the target coverage for a module to pass; default is 80"
echo " -f forces a discount check (normally done only if coverage < target)"
echo " -F show only failures at the function level"
echo " -c allows user to set the target coverage for a module to pass; default is 80"
echo " -f forces a discount check (normally done only if coverage < target)"
echo " -F show only failures at the function level"
+ echo " -Q turns off quiet mode. Quiet mode (default) is less chatty about intermediate"
+ echo " coverage results and test programme output when failures detected"
+ echo " -q enable quiet mode (default, so this is no longer needed)"
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 " -x generates the coverage XML files for Sonar (implies -f)"
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 " -x generates the coverage XML files for Sonar (implies -f)"
@@
-82,7
+85,7
@@
function usage {
function add_ignored_func {
if [[ ! -r $1 ]]
then
function add_ignored_func {
if [[ ! -r $1 ]]
then
- echo ">>>> can't find file to ignore: $1"
+ echo ">>>> can't find file to ignore: $1"
return
fi
return
fi
@@
-190,7
+193,7
@@
function discount_an_checks {
}
}
}
}
- /-:/ { # skip unexecutable lines
+ /-:/ { # skip unexecutable lines
spit_line()
seq++ # allow blank lines in a sequence group
next
spit_line()
seq++ # allow blank lines in a sequence group
next
@@
-215,7
+218,6
@@
function discount_an_checks {
#printf( "allow discount: %s\n", $0 )
if( replace_flags ) {
gsub( "#####", " 1", $0 )
#printf( "allow discount: %s\n", $0 )
if( replace_flags ) {
gsub( "#####", " 1", $0 )
- //gsub( "#####", "=====", $0 )
}
discount++;
}
}
discount++;
}
@@
-312,23
+314,26
@@
function mk_xml {
# -----------------------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------------
-# we assume that the project has been built in the ../[.]build directory
-if [[ -d ../build ]]
+if [[ -z $BUILD_PATH ]]
then
then
- export LD_LIBRARY_PATH=../build/lib:../build/lib64
- export C_INCLUDE_PATH=../build/include
-else
- if [[ -d ../.build ]]
- then
- export LD_LIBRARY_PATH=../.build/lib:../.build/lib64
- export C_INCLUDE_PATH=../.build/include
+ # we assume that the project has been built in the ../[.]build directory
+ if [[ -d ../build ]]
+ then
+ export BUILD_PATH=../build
else
else
- echo "[WARN] cannot find build directory (tried ../build and ../.build); things might not work"
- echo ""
+ if [[ -d ../.build ]]
+ then
+ export BUILD_PATH=../.build
+ else
+ echo "[WARN] cannot find build directory (tried ../build and ../.build); things might not work"
+ echo ""
+ fi
fi
fi
fi
fi
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$BUILD_PATH/lib:$BUILD_PATH/lib64
+export C_INCLUDE_PATH=$C_INCLUDE_PATH:$BUILD_PATH/include
export LIBRARY_PATH=$LD_LIBRARY_PATH
# The Makefile sets specific includes for things
export LIBRARY_PATH=$LD_LIBRARY_PATH
# The Makefile sets specific includes for things
@@
-340,10
+345,11
@@
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
show_output=0 # show output from each test execution (-S)
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
show_output=0 # show output from each test execution (-S)
-quiet=
0
+quiet=
1 # less chatty with result output (only overall coverage, no intermediate coverage) -Q turns off
gen_xml=0
replace_flags=1 # replace ##### in gcov for discounted lines
gen_xml=0
replace_flags=1 # replace ##### in gcov for discounted lines
-run_nano_tests=0
+run_nano_tests=0 # can nolonger be turned on
+run_nng_tests=0 # -N will enable
always_gcov=0 # -a sets to always run gcov even if failure
save_gcov=1 # -o turns this off
out_dir=${UT_COVERAGE_DIR:-/tmp/rmr_gcov} # -O changes output directory
always_gcov=0 # -a sets to always run gcov even if failure
save_gcov=1 # -o turns this off
out_dir=${UT_COVERAGE_DIR:-/tmp/rmr_gcov} # -O changes output directory
@@
-358,7
+364,7
@@
do
-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)
- -N) run_n
ano
_tests=1;;
+ -N) run_n
ng
_tests=1;;
-O) out_dir=$2; shift;;
-a) always_gcov=1;;
-O) out_dir=$2; shift;;
-a) always_gcov=1;;
@@
-376,6
+382,7
@@
do
-S) show_output=1;; # test output shown even on success
-v) (( verbose++ ));;
-q) quiet=1;; # less chatty when spilling error log files
-S) show_output=1;; # test output shown even on success
-v) (( verbose++ ));;
-q) quiet=1;; # less chatty when spilling error log files
+ -Q) quiet=0;; # disable quiet mode
-x) gen_xml=1
force_discounting=1
trigger_discount_str="WARN|FAIL|PASS" # check all outcomes for each module
-x) gen_xml=1
force_discounting=1
trigger_discount_str="WARN|FAIL|PASS" # check all outcomes for each module
@@
-383,9
+390,9
@@
do
;;
;;
- -h) usage; exit 0;;
+ -h)
usage; exit 0;;
--help) usage; exit 0;;
--help) usage; exit 0;;
- -\?) usage; exit 0;;
+ -\?) usage; exit 0;;
*) echo "unrecognised option: $1" >&2
usage >&2
*) echo "unrecognised option: $1" >&2
usage >&2
@@
-397,7
+404,7
@@
do
done
done
-if (( strict )) # if in strict mode, coverage shortcomings are failures
+if (( strict ))
# if in strict mode, coverage shortcomings are failures
then
cfail="FAIL"
else
then
cfail="FAIL"
else
@@
-416,11
+423,19
@@
then
do
if [[ $tfile != *"static_test.c" ]]
then
do
if [[ $tfile != *"static_test.c" ]]
then
- if(( ! run_nano_tests )) && [[ $tfile == *"nano"* ]]
+ if (( ! run_nng_tests )) && [[ $tfile == *"nng"* ]] # drop any nng file unless -N given
+ then
+ continue
+ fi
+ if [[ $tfile == *"nano"* ]] # no longer support nano tests; drop regardless
then
continue
fi
then
continue
fi
-
+
+ if (( ! quiet ))
+ then
+ echo "<INFO> add test: $tfile" >&2
+ fi
flist="${flist}$tfile "
fi
done
flist="${flist}$tfile "
fi
done
@@
-428,7
+443,6
@@
else
flist="$@"
fi
flist="$@"
fi
-
if (( noexec ))
then
echo "no exec mode; would test these:"
if (( noexec ))
then
echo "no exec mode; would test these:"
@@
-443,6
+457,11
@@
rm -fr *.gcov # ditch the previous coverage files
ut_errors=0 # unit test errors (not coverage errors)
errors=0
ut_errors=0 # unit test errors (not coverage errors)
errors=0
+if ! touch /tmp/PPID$$.noise
+then
+ echo "<ERR> unable to write to /tmp???"
+fi
+
for tfile in $flist
do
for x in *.gcov
for tfile in $flist
do
for x in *.gcov
@@
-453,14
+472,14
@@
do
fi
done
fi
done
+ echo "$tfile --------------------------------------"
( # all noise is now captured into a tmp file to support quiet mode
( # all noise is now captured into a tmp file to support quiet mode
- echo "$tfile --------------------------------------"
bcmd=$( printf "$builder" "${tfile%.c}" )
if ! $bcmd >/tmp/PID$$.log 2>&1
then
echo "[FAIL] cannot build $tfile"
cat /tmp/PID$$.log
bcmd=$( printf "$builder" "${tfile%.c}" )
if ! $bcmd >/tmp/PID$$.log 2>&1
then
echo "[FAIL] cannot build $tfile"
cat /tmp/PID$$.log
- rm -f /tmp/PID$$
+ # do NOT remove tmp files; bash seens to not gen a new PID for subshells
exit 1
fi
exit 1
fi
@@
-483,7
+502,7
@@
do
if ! ./${tfile%.c} >/tmp/PID$$.log 2>&1
then
echo "[FAIL] unit test failed for: $tfile"
if ! ./${tfile%.c} >/tmp/PID$$.log 2>&1
then
echo "[FAIL] unit test failed for: $tfile"
- if [[ -n $capture_file ]]
+ if [[ -n $capture_file ]]
then
echo "all errors captured in $capture_file, listing only fail message on tty"
echo "$tfile --------------------------------------" >>$capture_file
then
echo "all errors captured in $capture_file, listing only fail message on tty"
echo "$tfile --------------------------------------" >>$capture_file
@@
-493,7
+512,7
@@
do
else
if (( quiet ))
then
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
+ grep "^<" /tmp/PID$$.log|
egrep -v "^<SIEM>|^<EM>"
# in quiet mode just dump <...> messages which are assumed from the test programme not appl
else
cat /tmp/PID$$.log
fi
else
cat /tmp/PID$$.log
fi
@@
-501,7
+520,7
@@
do
(( ut_errors++ )) # cause failure even if not in strict mode
if (( ! always_gcov ))
then
(( ut_errors++ )) # cause failure even if not in strict mode
if (( ! always_gcov ))
then
- continue # skip coverage tests for this
+ exit 1 # we are in a subshell, must exit bad
fi
else
if (( show_output ))
fi
else
if (( show_output ))
@@
-509,6
+528,8
@@
do
printf "\n============= test programme output =======================\n"
cat /tmp/PID$$.log
printf "===========================================================\n"
printf "\n============= test programme output =======================\n"
cat /tmp/PID$$.log
printf "===========================================================\n"
+ else
+ grep "SUMMARY" /tmp/PID$$.log
fi
fi
fi
fi
@@
-610,7
+631,6
@@
do
}
}
}
}
}
}
-
}
END {
}
END {
@@
-621,9
+641,9
@@
do
rc=$?
cat /tmp/PID$$.log
rc=$?
cat /tmp/PID$$.log
- if (( rc || force_discounting )) # didn't pass, or forcing, see if discounting helps
+ if (( rc || force_discounting )) # didn't pass, or forcing, see if discounting helps
then
then
- if (( ! verbose ))
+ if (( ! verbose ))
# if verbose is on we don't need this (! is not a mistake!!)
then
echo "[INFO] checking to see if discounting improves coverage for failures listed above"
fi
then
echo "[INFO] checking to see if discounting improves coverage for failures listed above"
fi
@@
-643,7
+663,7
@@
do
tail -1 /tmp/PID$$.disc | grep '\['
tail -1 /tmp/PID$$.disc | grep '\['
- if (( verbose > 1 )) # updated file was generated, keep here
+ if (( verbose > 1 )) # updated file was generated, keep here
then
echo "[INFO] discounted coverage info in: ${tfile##*/}.dcov"
fi
then
echo "[INFO] discounted coverage info in: ${tfile##*/}.dcov"
fi
@@
-651,7
+671,13
@@
do
mv /tmp/PID$$.disc ${name##*/}.dcov
done
fi
mv /tmp/PID$$.disc ${name##*/}.dcov
done
fi
- )>/tmp/PID$$.noise 2>&1
+ )>/tmp/PID$$.noise 2>&1
+ if (( $? != 0 ))
+ then
+ (( ut_errors++ ))
+ cat /tmp/PID$$.noise
+ continue
+ fi
for x in *.gcov # merge any previous coverage file with this one
do
for x in *.gcov # merge any previous coverage file with this one
do
@@
-666,8
+692,10
@@
do
if (( ! quiet ))
then
cat /tmp/PID$$.noise
if (( ! quiet ))
then
cat /tmp/PID$$.noise
+ else
+ grep "SUMMARY" /tmp/PID$$.noise
fi
fi
-done
+done
echo ""
echo "[INFO] final discount checks on merged gcov files"
echo ""
echo "[INFO] final discount checks on merged gcov files"
@@
-677,7
+705,7
@@
do
if [[ $xx != *"test"* ]]
then
of=${xx%.gcov}.dcov
if [[ $xx != *"test"* ]]
then
of=${xx%.gcov}.dcov
- discount_an_checks $xx >$of
+ discount_an_checks $xx >$of
if [[ -n $of ]]
then
tail -1 $of | grep '\['
if [[ -n $of ]]
then
tail -1 $of | grep '\['
@@
-725,6
+753,16
@@
else # not strict; fail only if unit tests themselves failed
fi
fi
fi
fi
+# finally run any "vetters" which run programmes and analyse the output
+echo "[INFO] running vetters...."
+if ! make vet
+then
+ echo "[FAIL] one or more vetters failed"
+ state=1
+else
+ echo "[INFO] vetters all passed"
+fi
+
echo""
if (( state ))
then
echo""
if (( state ))
then