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 add 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 juas as we _expected_ the CI environmnt
42 # woudl 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
105 # defined in the CI configuration where jenkins jobs are looking for gcov files
106 gcov_dir=/tmp/gcov_rpts
107 if [[ ! -d $cov_dir ]]
109 echo "<INFO> making $gcov_dir"
117 -f) force_rmr_load=1;;
118 -N) no_rmr_load=1;; # for local testing
120 *) echo "unrecognised option: $1"
128 ensure_pkgs # some CI enviroments may not have RMR; get it
130 script_dir=${PWD%/*}/src
133 # build the binaries with coverage options set
134 export TEST_COV_OPTS="-ftest-coverage -fprofile-arcs" # picked up by make so we get coverage on tools for sonar
135 make clean # ensure coverage files removed
136 make -B # ensure coverage data is nuked
138 # drive with full complement to test good branches, then with bad (missing value) to drive exceptions
139 mc_listener -p 4567 -q -r 10 -e -d foo -x >/dev/null 2>&1 # -x (invalid) prevents execution loop
140 for x in d p r \? h # drive with missing values for d, p, r and singletons -h and -?
142 gcov mc_listener.c # debugging because jenkins gcov doesn't seem to be accumulating data
143 mc_listener -$x >/dev/null 2>&1
145 gcov mc_listener.c # debugging because jenkins gcov doesn't seem to be accumulating data
147 pipe_reader -d foo -e -f -m 0 -s -x >/dev/null 2>&1 # drive for all "good" conditions
150 pipe_reader -$x >/dev/null 2>&1 # drive each exception (missing value) or 'help'
153 rdc_replay -d foo -f bar -t 0 -x >/dev/null 2>&1 # drive for all "good" conditions
156 rdc_replay -$x >/dev/null 2>&1 # drive each exception (missing value) or 'help'
159 $script_dir/verify.sh # verify MUST be first (replay relies on its output)
160 $script_dir/verify_replay.sh
162 # generate and copy coverage files to parent which is where the CI jobs are looking for them
163 # we do NOT gen stats for the library functions; the unit test script(s) do that
165 for x in mc_listener sender rdc_replay pipe_reader
168 cp $x.c.gcov $gcov_dir/