From: E. Scott Daniels Date: Mon, 24 Aug 2020 15:07:28 +0000 (-0400) Subject: Augment listener unit test to force in RMR package X-Git-Tag: 1.7.0~9 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=ee54f8a6949329913d30e638593ed8e3cc515575;p=ric-app%2Fmc.git Augment listener unit test to force in RMR package Some CI environment seeem unable to be coaxed into pre-loading RMR which the listener unit test needs. If the RMR dev things aren't found in /usr/local/* then the script will pull the neeed libraries (using the rmr-version.yaml as we expect the CI jobs to do) from package cloud. The packages will be unpacked int /tmp/ut_pkg which does NOT require root. Issue-ID: RIC-632 Signed-off-by: E. Scott Daniels Change-Id: I02c98f797bf2e66b0cf0cb54565cd4dc03dbb22e --- diff --git a/sidecars/listener/run_unit_test.ksh b/sidecars/listener/run_unit_test.ksh index 2942c05..fc099d0 100755 --- a/sidecars/listener/run_unit_test.ksh +++ b/sidecars/listener/run_unit_test.ksh @@ -20,18 +20,21 @@ # # Mnemonic: run_unit_test.ksh # Abstract: This drives unit testing setting up working directories -# and such. +# and such. This expects that RMR dev package(s) is/are +# installed. Some CI envirpnments don't provide this, or +# the ability to pre-install before running this test, so +# we will force one to be there if we don't find it in /usr. # # Date: 10 December 2019 # Author: E. Scott Daniels # ------------------------------------------------------------------------- function abort_after { - touch /tmp/running + touch $running sleep ${1:-60} - if [[ -e /tmp/running ]] + if [[ -e $running ]] then - echo "abort: unit test running too long, killing $2" + echo "abort: unit test running too long, killing ${2:-nojobgiven}" kill -9 ${2:-bad-pid} fi } @@ -57,41 +60,119 @@ function purge_dirs { rm -fr /tmp/mc_listener_test } +# This is a hack! There seems not to be an easy way to have the LF +# environment add RMR (or other needed packages) for testing. If we don't +# find RMR in the /usr/local part of the filesystem, we'll force it into +# /tmp which doesn't require root. We'll be smart and get the desired +# rmr version from the repo root juas as we _expected_ the CI environmnt +# woudl do (but seems not to). +# +function ensure_pkgs { + if (( force_rmr_load )) || [[ -d /usr/local/include/rmr ]] + then + echo "[INFO] found RMR installed in /usr/local" + return + fi + + rv=$( grep "version:" ../../rmr-version.yaml | awk '{ print $NF; exit( 0 ) }' ) + rr=$( grep "repo:" ../../rmr-version.yaml | awk '{ print $NF; exit( 0 ) }' ) + if [[ -z $rv ]] + then + rv="4.2.1" # some sane version if not found + fi + if [[ -z $rr ]] + then + rr="release" + fi + echo "[INFO] RMR seems not to be installed in /usr/local; pulling private copy: v=$rv" + + pkg_dir=/tmp/ut_pkg + mkdir -p $pkg_dir + + ( + set -e + opts="-nv --content-disposition" + url_base="https://packagecloud.io/o-ran-sc/$rr/packages/debian/stretch" + cd /tmp + wget $opts ${url_base}/rmr_${rv}_amd64.deb/download.deb + wget $opts ${url_base}/rmr-dev_${rv}_amd64.deb/download.deb + + for x in *rmr*deb + do + dpkg -x $x $pkg_dir + done + ) + if (( $? != 0 )) + then + echo "[FAIL] unable to install one or more RMR packages" + exit 1 + fi + + LD_LIBRARY_PATH=$pkg_dir/usr/local/lib:$LD_LIBRARY_PATH + LIBRARY_PATH=$pkg_dir/usr/local/lib:$LIBRARY_PATH + export C_INCLUDE_PATH="$pkg_dir/usr/local/include:$C_INCLUDE_PATH" +} + # ------------------------------------------------------------------------------------------------ + # these aren't set by default in some of the CI environments # export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH export LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH -if ! make -B unit_test # ensure that it's fresh -then - echo "[FAIL] cannot make unit_test" - exit 1 -fi +running=/tmp/PID$$.running +force_rmr_load=0 + +while [[ $1 == -* ]] +do + case $1 in + -f) force_rmr_load=1;; + + *) echo "unrecognised option: $1" + exit 1 + ;; + esac + + shift +done -if [[ $1 == "purge" ]] +if [[ $1 == "purge" ]] # just purge then purge_dirs exit 0 fi +ensure_pkgs # ensure that we have RMR; some CI environments are lacking + +if ! make -B unit_test # ensure that it's fresh +then + echo "[FAIL] cannot make unit_test" + exit 1 +fi +echo "unit test(s) successfully built" + setup_dirs -if [[ $1 == "set"* ]] +if [[ $1 == "set"* ]] # setup only then exit fi -abort_after 60 -if ! unit_test >/tmp/PID$$.utlog 2>&1 +./unit_test >/tmp/PID$$.utlog 2>&1 & +pid=$! +abort_after 60 $pid & +wait $pid +#if ! unit_test >/tmp/PID$$.utlog 2>&1 +if (( $? != 0 )) then - rm -f /tmp/running + echo ">>>> wait popped" + rm -f $running cat /tmp/PID$$.utlog rm -f /tmp/PID$$.* purge_dirs exit 1 fi -rm -f /tmp/running +rm -f $running echo "[PASS] base unit tests all pass" echo "[INFO] file/directory verification begins...." @@ -111,8 +192,8 @@ else if [[ $dest_md5 != $src_md5 ]] then echo "[FAIL] md5 of copy test file didn't match soruce" -cat $dest_md5 -echo "$dest_md5 $src_md5" + cat $dest_md5 + echo "$dest_md5 $src_md5" rc=1 fi fi @@ -126,7 +207,7 @@ fi show_coverage.ksh unit_test.c # compute coverage and generate .gcov files echo "Coverage with discounting (raw values in parens)" -discount_chk.ksh $(ls *gcov|egrep -v "^test_|unit_test.c") +./discount_chk.ksh $(ls *gcov|egrep -v "^test_|unit_test.c") if (( rc > 0 ))