Add publish script to lister test set 64/4664/2
authorE. Scott Daniels <daniels@research.att.com>
Thu, 3 Sep 2020 14:43:12 +0000 (10:43 -0400)
committerE. Scott Daniels <daniels@research.att.com>
Thu, 3 Sep 2020 16:09:31 +0000 (12:09 -0400)
The coverage files need to have complete paths (relative to the
repo root) in order for Sonar to match them with the analysis information
that it captured during build. This change adds a publish script to
the listener test scripts that will push the coverage files into
the reports directory and will fix up the internal source module name
for Sonar to match.

Issue-ID: RIC-632

Signed-off-by: E. Scott Daniels <daniels@research.att.com>
Change-Id: I438844a176b34f6026e3fcf2ad084ea303a05cbb

sidecars/listener/test/publish_cov.ksh [new file with mode: 0755]
sidecars/listener/test/run_app_tests.ksh
sidecars/listener/test/run_unit_test.ksh
sidecars/listener/test/show_coverage.ksh

diff --git a/sidecars/listener/test/publish_cov.ksh b/sidecars/listener/test/publish_cov.ksh
new file mode 100755 (executable)
index 0000000..cb2a73b
--- /dev/null
@@ -0,0 +1,68 @@
+#!/usr/bin/env bash
+
+#==================================================================================
+#        Copyright (c) 2018-2020 AT&T Intellectual Property.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#==================================================================================
+
+
+#
+#      Mnemonic:       pub_cov.ksh
+#      Abstract:       This script will push any coverage files (.gcov) in the current
+#                              directory to the indicated target directory (/tmp/gcov_rpts by
+#                              default.  Because sonar needs to match the source listed in the
+#                              .gcov file with what it perceives was analysed by it's code, we
+#                              must fiddle the name in the .gcov file to be a path relative to
+#                              the project root.  For example, if the .gcov file has the line:
+#
+#                                              0:Source:mc_listener.c
+#
+#                              we must change that to be the path of sidecars/listener/src
+#
+#      Date:           3 September 2020
+#      Author:         E. Scott Daniels
+# -------------------------------------------------------------------------
+
+sdir=sidecars/listener/src                     # default source directory
+pdir=/tmp/gcov_rpts                                    # publish directory
+
+while [[ $1 == -* ]]
+do
+       case $1 in
+               -p)     pdir=$2; shift;;
+               -s) sdir=$2; shift;;
+       esac
+
+       shift
+done
+
+
+echo "publishing gcov files to: $pdir"
+
+for f in *.gcov
+do
+       echo "publishing: $f to ${pdir}/$f"
+
+       # rel replace will replace things like ../src based on the source directory
+       awk -v sdir="$sdir"  \
+               -v rel_rep="../${sdir##*/}/" '
+               /0:Source:/ {
+                       gsub( rel_rep, "", $0 )                 # relative replace must be first
+                       n = split( $0, a, ":" )                 # file name into a[n]
+                       gsub( a[n], sdir "/" a[n], $0 )
+               }
+
+               { print }
+       ' $f >${pdir}/$f
+done
index 27b6812..f2fd220 100755 (executable)
@@ -101,6 +101,7 @@ export LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH
 
 force_rmr_load=0
 no_rmr_load=0
+test_dir=$PWD
 
 # defined in the CI configuration where jenkins jobs are looking for gcov files
 gcov_dir=/tmp/gcov_rpts
@@ -127,45 +128,53 @@ done
 
 ensure_pkgs                                                                    # some CI enviroments may not have RMR; get it
 
-script_dir=${PWD%/*}/src
 cd ../src
 
 # build the binaries with coverage options set
 export TEST_COV_OPTS="-ftest-coverage -fprofile-arcs"          # picked up by make so we get coverage on tools for sonar
 make clean                     # ensure coverage files removed
-make -B                                # ensure coverage data is nuked
+make -B                                # force build under the eyes of sonar build wrapper
+
+rm -fr *.gcov *.gcda                   # ditch any previously generated coverage info
 
 # drive with full complement to test good branches, then with bad (missing value) to drive exceptions
-mc_listener -p 4567 -q -r 10 -e -d foo -x  >/dev/null 2>&1             # -x (invalid) prevents execution loop
+./mc_listener -p 4567 -q -r 10 -e -d foo -x  >/dev/null 2>&1           # -x (invalid) prevents execution loop
 for x in d p r \? h                                            # drive with missing values for d, p, r and singletons -h and -?
 do
-       gcov mc_listener.c                                      # debugging because jenkins gcov doesn't seem to be accumulating data
-       mc_listener -$x >/dev/null 2>&1
+       ./mc_listener -$x >/dev/null 2>&1
 done
-gcov mc_listener.c                                     # debugging because jenkins gcov doesn't seem to be accumulating data
+gcov  mc_listener.c                                    # debugging because jenkins gcov doesn't seem to be accumulating data
 
-pipe_reader -d foo -e -f -m 0 -s  -x >/dev/null 2>&1           # drive for all "good" conditions
+./pipe_reader -d foo -e -f -m 0 -s  -x >/dev/null 2>&1         # drive for all "good" conditions
 for x in d m \? h
 do
-       pipe_reader  -$x >/dev/null 2>&1                # drive each exception (missing value) or 'help'
+       ./pipe_reader  -$x >/dev/null 2>&1              # drive each exception (missing value) or 'help'
 done
 
-rdc_replay -d foo -f bar -t 0  -x >/dev/null 2>&1                      # drive for all "good" conditions
+./rdc_replay -d foo -f bar -t 0  -x >/dev/null 2>&1                    # drive for all "good" conditions
 for x in d f t  \? h
 do
-       rdc_replay  -$x >/dev/null 2>&1         # drive each exception (missing value) or 'help'
+       ./rdc_replay  -$x >/dev/null 2>&1               # drive each exception (missing value) or 'help'
 done
 
-$script_dir/verify.sh                                  # verify MUST be first (replay relies on its output)
-$script_dir/verify_replay.sh
+./verify.sh                                    # verify MUST be first (replay relies on its output)
+./verify_replay.sh
 
 # generate and copy coverage files to parent which is where the CI jobs are looking for them
 # we do NOT gen stats for the library functions; the unit test script(s) do that
 #
 for x in mc_listener sender rdc_replay pipe_reader
 do
-       gcov $x.c
-       cp $x.c.gcov $gcov_dir/
+       gcov  $x.c
+       #cp $x.c.gcov $gcov_dir/
 done
+$test_dir/publish_cov.ksh                      # publish coverage files and fixup source names
+
+echo "[INFO] ----- published coverage information ----------------------------------"
+ls -al $gcov_dir
+grep -i "0:Source:" $gcov_dir/*.gcov
+
+echo "------------------------------------------------------------------------------"
+echo "run_app_tests finished"
 
 exit
index 44e1c90..2c7d7fc 100755 (executable)
@@ -166,10 +166,6 @@ fi
 
 ensure_pkgs                                            # ensure that we have RMR; some CI environments are lacking
 
-echo "[INFO] ----------------------------------------------"
-gcov --version                                 # gcov files don't seem to aggregate on the LF guest
-echo "[INFO] ----------------------------------------------"
-
 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"
@@ -195,6 +191,8 @@ 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 &
@@ -251,10 +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
 
-cp *.gcov      $gcov_dir/                              # make avilable to jenkins job(s)
 
 rm -f /tmp/PID$$.*
 exit $rc
index 98d6d49..2fe314d 100755 (executable)
@@ -33,7 +33,7 @@ chatty=0
 show_all=0
 cfail="DCHK"
 
-gcov -f $1 | sed "s/'//g" | awk \
+gcov  -f $1 | sed "s/'//g" | awk \
                -v cfail=$cfail \
                -v show_all=$show_all \
                -v ignore_list="$iflist" \