3 #==================================================================================
4 # Copyright (c) 2020 Nokia
5 # Copyright (c) 2020 AT&T Intellectual Property.
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #==================================================================================
21 # Mnemonic: unit_test.sh
22 # Abstract: This drives the unit tests and combs out the needed .gcov
23 # files which are by some magic collected for Sonar.
26 # Author: E. Scott Daniels
27 # -----------------------------------------------------------------------------
30 # Make a list of our modules under test so that we don't look at gcov
31 # files that are generated for system lib headers in /usr/*
32 # (bash makes the process of building a list of names harder than it
33 # needs to be, so use caution with the printf() call.)
36 grep -l "Source:\.\./src" *.gcov | while read f
38 printf "$f " # do NOT use echo or add \n!
42 function abort_if_error {
48 if [[ -n /tmp/PID$$.log ]]
58 # -------------------------------------------------------------------------
60 spew="cat" # default to dumping all make output on failure (-q turns it to ~40 lines)
72 while [[ $1 == "-"* ]]
82 while [[ $1 == *"="* ]]
86 export build_dir=${1##*=}
94 echo "build dir=$build_dir"
95 find $build_dir -name "libricxfcpp.*"
98 export LD_LIBRARY_PATH=$build_dir:/usr/local/lib:$LD_LIBRARY_PATH
99 export LIBRARY_PATH=$build_dir:/usr/local/lib:$LIBRARY_PATH
101 cp config1.json config-file.json # ensure default named file is there too
104 make tests >/tmp/PID$$.log 2>&1
105 abort_if_error $? "unable to make"
106 echo "tests successfully built" >&2
110 #run everything, then generate coverage stats after all have run
111 for x in metrics_test jhash_test config_test unit_test
113 ./$x >/tmp/PID$$.log 2>&1
114 abort_if_error $? "test failed: $x"
117 # it seems that we loose coverage reporting if metrics_test's gcov file is generated
118 # after unit test. Very strange. To be safe, run unit_test last.
120 for x in metrics_test jhash_test config_test unit_test
122 gcov $x.c >/dev/null 2>&1
125 # wrapper_test is driven by jhash_test, but must be covered explicitly
126 gcov jwrapper_test.c >/dev/null 2>&1
128 ./scrub_gcov.sh # remove cruft
132 echo "[INFO] coverage stats, discounted (raw), for the various modules:"
133 ./parse_gcov.sh $list # generate simple, short, coverage stats