3 #==================================================================================
4 # Copyright (c) 2018-2019 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_unit_test.ksh
22 # Abstract: This drives unit testing setting up working directories
23 # and such. This expects that RMR dev package(s) is/are
24 # installed. Some CI envirpnments don't provide this, or
25 # the ability to pre-install before running this test, so
26 # we will force one to be there if we don't find it in /usr.
28 # Date: 10 December 2019
29 # Author: E. Scott Daniels
30 # -------------------------------------------------------------------------
32 function abort_after {
37 echo "abort: unit test running too long, killing ${2:-nojobgiven}"
44 mkdir -p /tmp/mc_listener_test/final
45 mkdir -p /tmp/mc_listener_test/stage
47 mv_src=/tmp/mc_listener_test/mv_src # source that will be renamed rather than copied
48 mv_dest=/tmp/mc_listener_test/mv_dest
51 copy_src=/tmp/mc_listener_test/copy_src
52 copy_dest=/tmp/mc_listener_test/copy_dest
55 src_md5=$( cat $copy_src | md5sum ) # use cat so that filename doesn't factor in to output
60 rm -fr /tmp/mc_listener_test
63 # This is a hack! There seems not to be an easy way to have the LF
64 # environment add RMR (or other needed packages) for testing. If we don't
65 # find RMR in the /usr/local part of the filesystem, we'll force it into
66 # /tmp which doesn't require root. We'll be smart and get the desired
67 # rmr version from the repo root juas as we _expected_ the CI environmnt
68 # woudl do (but seems not to).
70 function ensure_pkgs {
71 if (( force_rmr_load )) || [[ -d /usr/local/include/rmr ]]
73 echo "[INFO] found RMR installed in /usr/local"
77 rv=$( grep "version:" ../../rmr-version.yaml | awk '{ print $NF; exit( 0 ) }' )
78 rr=$( grep "repo:" ../../rmr-version.yaml | awk '{ print $NF; exit( 0 ) }' )
81 rv="4.2.1" # some sane version if not found
87 echo "[INFO] RMR seems not to be installed in /usr/local; pulling private copy: v=$rv"
94 opts="-nv --content-disposition"
95 url_base="https://packagecloud.io/o-ran-sc/$rr/packages/debian/stretch"
97 wget $opts ${url_base}/rmr_${rv}_amd64.deb/download.deb
98 wget $opts ${url_base}/rmr-dev_${rv}_amd64.deb/download.deb
107 echo "[FAIL] unable to install one or more RMR packages"
111 LD_LIBRARY_PATH=$pkg_dir/usr/local/lib:$LD_LIBRARY_PATH
112 LIBRARY_PATH=$pkg_dir/usr/local/lib:$LIBRARY_PATH
113 export C_INCLUDE_PATH="$pkg_dir/usr/local/include:$C_INCLUDE_PATH"
116 # ------------------------------------------------------------------------------------------------
118 # these aren't set by default in some of the CI environments
120 export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
121 export LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH
123 running=/tmp/PID$$.running
129 -f) force_rmr_load=1;;
131 *) echo "unrecognised option: $1"
139 if [[ $1 == "purge" ]] # just purge
145 ensure_pkgs # ensure that we have RMR; some CI environments are lacking
147 if ! make -B unit_test # ensure that it's fresh
149 echo "[FAIL] cannot make unit_test"
152 echo "unit test(s) successfully built"
156 if [[ $1 == "set"* ]] # setup only
161 ./unit_test >/tmp/PID$$.utlog 2>&1 &
163 abort_after 60 $pid &
165 #if ! unit_test >/tmp/PID$$.utlog 2>&1
168 echo ">>>> wait popped"
177 echo "[PASS] base unit tests all pass"
178 echo "[INFO] file/directory verification begins...."
180 # validate files that should have been created/copied
184 ls -al /tmp/mc_listener_test/* >/tmp/PID$$.fdlog 2>&1
186 if [[ -e $copy_src ]]
188 echo "[FAIL] copy source test should have been unlinked but was there!"
191 dest_md5=$( cat $copy_dest | md5sum ) # use cat so that filename doesn't factor in to output
192 if [[ $dest_md5 != $src_md5 ]]
194 echo "[FAIL] md5 of copy test file didn't match soruce"
196 echo "$dest_md5 $src_md5"
208 show_coverage.ksh unit_test.c # compute coverage and generate .gcov files
209 echo "Coverage with discounting (raw values in parens)"
210 ./discount_chk.ksh $(ls *gcov|egrep -v "^test_|unit_test.c")
215 echo "[FAIL] overall test fails"
217 echo "[PASS] overall test passes"