Add support for config file parsing and watching
[ric-plt/xapp-frame-cpp.git] / test / unit_test.sh
index 9e0564b..c845553 100755 (executable)
@@ -1,6 +1,5 @@
 #!/usr/bin/env bash
 # vim: ts=4 sw=4 noet:
-
 #==================================================================================
 #       Copyright (c) 2020 Nokia
 #       Copyright (c) 2020 AT&T Intellectual Property.
 
 # Make a list of our modules under test so that we don't look at gcov
 # files that are generated for system lib headers in /usr/*
-# (bash makes the process of building a list of names  harder than it 
+# (bash makes the process of building a list of names  harder than it
 # needs to be, so use caution with the printf() call.)
 #
 function mk_list {
        grep -l "Source:\.\./src"  *.gcov | while read f
        do
                printf "$f "            # do NOT use echo or add \n!
-       done 
+       done
 }
 
 function abort_if_error {
@@ -60,6 +59,16 @@ function abort_if_error {
 
 spew="cat"                                     # default to dumping all make output on failure (-q turns it to ~40 lines)
 
+if [[ -d ../.build ]]
+then
+       build_dir="../.build"
+else
+       if [[ -d ../build ]]
+       then
+               build_dir="../build"
+       fi
+fi
+
 while [[ $1 == "-"* ]]
 do
        case $1 in
@@ -70,18 +79,57 @@ do
        shift
 done
 
+while [[ $1 == *"="* ]]
+do
+       case ${1%%=*} in
+               CMBUILD)
+                       export build_dir=${1##*=}
+                       ;;
+       esac
+
+       shift
+done
+
+echo "## INFO ##"
+echo "build dir=$build_dir"
+find $build_dir -name "libricxfcpp.*"
+echo "## INFO ##"
+
+export LD_LIBRARY_PATH=$build_dir:/usr/local/lib:$LD_LIBRARY_PATH
+export LIBRARY_PATH=$build_dir:/usr/local/lib:$LIBRARY_PATH
+
+cp config1.json config-file.json                                               # ensure default named file is there too
+
 make nuke >/dev/null
-make unit_test >/tmp/PID$$.log 2>&1
+make tests >/tmp/PID$$.log 2>&1
 abort_if_error $? "unable to make"
+echo "tests successfully built" >&2
 
 spew="cat"
-./unit_test >/tmp/PID$$.log 2>&1
-abort_if_error $? "unit test failed"
 
-gcov unit_test >/tmp/PID$$.gcov_log 2>&1       # suss out our gcov files
+#run everything, then generate coverage stats after all have run
+for x in metrics_test jhash_test config_test  unit_test
+do
+       ./$x >/tmp/PID$$.log 2>&1
+       abort_if_error $? "test failed: $x"
+done
+
+# it seems that we loose coverage reporting if metrics_test's gcov file is generated
+# after unit test.  Very strange. To be safe, run unit_test last.
+#
+for x in metrics_test jhash_test config_test unit_test
+do
+       gcov $x.c >/dev/null 2>&1
+done
+
+# wrapper_test is driven by jhash_test, but must be covered explicitly
+gcov jwrapper_test.c >/dev/null 2>&1
+
 ./scrub_gcov.sh                                                                # remove cruft
 
 list=$( mk_list )
+echo ""
+echo "[INFO] coverage stats, discounted (raw), for the various modules:"
 ./parse_gcov.sh $list                                          # generate simple, short, coverage stats
 
 rm -f /tmp/PID$$.*