Add publish script to lister test set
[ric-app/mc.git] / sidecars / listener / test / run_unit_test.ksh
index 2ccd47e..2c7d7fc 100755 (executable)
 #                              the ability to pre-install before running this test, so
 #                              we will force one to be there if we don't find it in /usr.
 #
+#                              CI Mode
+#                              For the Jenkins jobs to capture trigger data allowing sonar
+#                              analysis, we must force a build in the ../src directory.
+#                              CI mode is on by default, to force this build, but can be
+#                              turned off with the -c option for local builds/testing.
+#
 #      Date:           10 December 2019
 #      Author:         E. Scott Daniels
 # -------------------------------------------------------------------------
@@ -125,12 +131,22 @@ function ensure_pkgs {
 export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
 export LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH
 
+# defined in the CI configuration where jenkins jobs are looking for gcov files
+gcov_dir=/tmp/gcov_rpts
+if [[ ! -d $cov_dir ]]
+then
+       echo "[INFO] making $gcov_dir"
+       mkdir $gcov_dir
+fi
+
 running=/tmp/PID$$.running
 force_rmr_load=0
+ci_mode=1                                                              # -c turns off; see the flower box above
 
 while [[ $1 == -* ]]
 do
        case $1 in
+               -c) ci_mode=0;;
                -f)     force_rmr_load=1;;
                -N) no_rmr_load=1;;                                     # for local testing
 
@@ -150,6 +166,17 @@ fi
 
 ensure_pkgs                                            # ensure that we have RMR; some CI environments are lacking
 
+if (( ci_mode ))                               # in CI mode we must force a build in the src so build wrapper captures trigger data
+then
+       echo "building in src for sonar build wrapper capture"
+       (
+               cd ../src
+               export TEST_COV_OPTS="-ftest-coverage -fprofile-arcs"           # picked up by make so we get coverage on tools for sonar
+               make -B
+       )
+fi
+
+echo "building unit test(s)"
 if ! make -B unit_test                 # ensure that it's fresh
 then
        echo "[FAIL] cannot make unit_test"
@@ -164,14 +191,15 @@ then
        exit
 fi
 
+rm -fr *.gcov *.gcda                   # ditch any previously generated coverage info
+
 ./unit_test >/tmp/PID$$.utlog 2>&1 &
 pid=$!
 abort_after 60 $pid &
 wait $pid
-#if ! unit_test >/tmp/PID$$.utlog 2>&1
 if (( $? != 0 ))
 then
-       echo ">>>> wait popped"
+       echo "<FAIL> run_unit_test: wait popped"
        rm -f $running
        cat /tmp/PID$$.utlog
        rm -f /tmp/PID$$.*
@@ -221,8 +249,11 @@ then
        echo "[FAIL] overall test fails"
 else
        echo "[PASS] overall test passes"
-       rm -f *test*.gcov
+       rm -f *test*.gcov                                       # ditch test specific coverage files first
+       #cp *.gcov      $gcov_dir/                              # make avilable to jenkins job(s)
+       ./publish_cov.ksh                                       # push to reports dir and fix internal source filenames
 fi
 
+
 rm -f /tmp/PID$$.*
 exit $rc