3 #==================================================================================
4 # Copyright (c) 2018-2020 AT&T Intellectual Property.
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #==================================================================================
21 # Mnemonic: run_app_test.ksh
22 # Abstract: This script drives various applications (both mc_listener related
23 # and testers) to generate coverage stats for sonar. There is little
24 # we can validate with these tests other than the programme doesn't
25 # crash. The verify scripts are run at code checkin and will flag
26 # any real problems, so this is just to keep sonar's knickers unbunched.
29 # - execution directory is listener/test
30 # - source directory is ../src
32 # Date: 2 September 2020
33 # Author: E. Scott Daniels
34 # -------------------------------------------------------------------------
37 # This is a hack! There seems not to be an easy way to have the LF
38 # environment adds RMR (or other needed packages) for testing. If we don't
39 # find RMR in the /usr/local part of the filesystem, we'll force it into
40 # /tmp which doesn't require root. We'll be smart and get the desired
41 # rmr version from the repo root just as we _expected_ the CI environmnt
42 # would do (but seems not to).
44 function ensure_pkgs {
50 if (( force_rmr_load )) || [[ -d /usr/local/include/rmr ]]
52 echo "[INFO] found RMR installed in /usr/local"
56 rv=$( grep "version:" ../../rmr-version.yaml | awk '{ print $NF; exit( 0 ) }' )
57 rr=$( grep "repo:" ../../rmr-version.yaml | awk '{ print $NF; exit( 0 ) }' )
60 rv="4.2.1" # some sane version if not found
66 echo "[INFO] RMR seems not to be installed in /usr/local; pulling private copy: v=$rv"
73 opts="-nv --content-disposition"
74 url_base="https://packagecloud.io/o-ran-sc/$rr/packages/debian/stretch"
76 wget $opts ${url_base}/rmr_${rv}_amd64.deb/download.deb
77 wget $opts ${url_base}/rmr-dev_${rv}_amd64.deb/download.deb
86 echo "[FAIL] unable to install one or more RMR packages"
90 LD_LIBRARY_PATH=$pkg_dir/usr/local/lib:$LD_LIBRARY_PATH
91 LIBRARY_PATH=$pkg_dir/usr/local/lib:$LIBRARY_PATH
92 export C_INCLUDE_PATH="$pkg_dir/usr/local/include:$C_INCLUDE_PATH"
95 # ------------------------------------------------------------------------------------------------
97 # these aren't set by default in some of the CI environments
99 export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
100 export LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH
106 # defined in the CI configuration where jenkins jobs are looking for gcov files
107 gcov_dir=/tmp/gcov_rpts
108 if [[ ! -d $cov_dir ]]
110 echo "<INFO> making $gcov_dir"
119 -f) force_rmr_load=1;;
120 -N) no_rmr_load=1;; # for local testing
121 -v) verbose=1; vflag="-v";;
123 *) echo "unrecognised option: $1"
131 ensure_pkgs # some CI enviroments may not have RMR; get it
135 # build the binaries with coverage options set
136 export TEST_COV_OPTS="-ftest-coverage -fprofile-arcs" # picked up by make so we get coverage on tools for sonar
137 make clean # ensure coverage files removed
138 make -B # force build under the eyes of sonar build wrapper
141 echo "[FAIL] build failed"
145 rm -fr *.gcov *.gcda # ditch any previously generated coverage info
147 # drive with full complement to test good branches, then with bad (missing value) to drive exceptions
148 ./mc_listener -p 4567 -q -r 10 -e -d foo -x >/dev/null 2>&1 # -x (invalid) prevents execution loop
149 for x in d p r \? h # drive with missing values for d, p, r and singletons -h and -?
151 ./mc_listener -$x >/dev/null 2>&1
153 gcov mc_listener.c # debugging because jenkins gcov doesn't seem to be accumulating data
155 ./pipe_reader -d foo -e -f -m 0 -s -x >/dev/null 2>&1 # drive for all "good" conditions
158 ./pipe_reader -$x >/dev/null 2>&1 # drive each exception (missing value) or 'help'
161 ./rdc_replay -d foo -f bar -t 0 -x >/dev/null 2>&1 # drive for all "good" conditions
164 ./rdc_replay -$x >/dev/null 2>&1 # drive each exception (missing value) or 'help'
167 ./verify.sh $vflag # verify MUST be first (replay relies on its output)
170 # generate and copy coverage files to parent which is where the CI jobs are looking for them
171 # we do NOT gen stats for the library functions; the unit test script(s) do that
173 for x in mc_listener sender rdc_replay pipe_reader
176 #cp $x.c.gcov $gcov_dir/
178 $test_dir/publish_cov.ksh # publish coverage files and fixup source names
180 echo "[INFO] ----- published coverage information ----------------------------------"
182 grep -i "0:Source:" $gcov_dir/*.gcov
184 echo "------------------------------------------------------------------------------"
185 echo "run_app_tests finished"