From 1739800d21456ddb0b0efbf92cb6d60c6f772feb Mon Sep 17 00:00:00 2001 From: "E. Scott Daniels" Date: Wed, 1 Apr 2020 12:39:47 -0400 Subject: [PATCH] Fix potential nil ptr seg fault and CI test issue This change corrects two problems that the "dockerless" CI build process was encountering: - Include and link paths set in the CMake config were not always honoured by the application test scripts - Building packges to install in the test environment as a non-root user was causing non-standard install prefixes to be added to the packages. This change also corrects a typo in the NNG module which potentially could have allowed a nil pointer to be dereferenced. This bug was discovered while makeing the changes for the CI jobs. Issue-ID: RIC-303 Signed-off-by: E. Scott Daniels Change-Id: I30150950dd186e72f8c822ec3fbe5b07369cb4ce --- CHANGES_CORE.txt | 4 + CMakeLists.txt | 9 +- src/rmr/nng/src/rmr_nng.c | 2 +- test/app_test/Makefile | 2 +- test/app_test/{rebuild.ksh => rebuild.sh} | 7 +- test/app_test/run_all.ksh | 100 ++++++++++- test/app_test/run_all.sh | 190 +++++++++++++++++++++ .../app_test/{run_app_test.ksh => run_app_test.sh} | 18 +- .../{run_call_test.ksh => run_call_test.sh} | 21 ++- .../{run_exrts_test.ksh => run_exrts_test.sh} | 11 +- .../{run_lcall_test.ksh => run_lcall_test.sh} | 11 +- .../{run_multi_test.ksh => run_multi_test.sh} | 12 +- test/app_test/{run_rr_test.ksh => run_rr_test.sh} | 12 +- .../app_test/{run_rts_test.ksh => run_rts_test.sh} | 12 +- test/{run_app_tests => run_app_tests.sh} | 17 +- test/run_unit_tests.sh | 60 +++++++ test/unit_test.ksh | 44 +++-- 17 files changed, 459 insertions(+), 73 deletions(-) rename test/app_test/{rebuild.ksh => rebuild.sh} (91%) create mode 100644 test/app_test/run_all.sh rename test/app_test/{run_app_test.ksh => run_app_test.sh} (92%) rename test/app_test/{run_call_test.ksh => run_call_test.sh} (91%) rename test/app_test/{run_exrts_test.ksh => run_exrts_test.sh} (96%) rename test/app_test/{run_lcall_test.ksh => run_lcall_test.sh} (95%) rename test/app_test/{run_multi_test.ksh => run_multi_test.sh} (95%) rename test/app_test/{run_rr_test.ksh => run_rr_test.sh} (95%) rename test/app_test/{run_rts_test.ksh => run_rts_test.sh} (95%) rename test/{run_app_tests => run_app_tests.sh} (74%) create mode 100644 test/run_unit_tests.sh diff --git a/CHANGES_CORE.txt b/CHANGES_CORE.txt index a118752..4e382e8 100644 --- a/CHANGES_CORE.txt +++ b/CHANGES_CORE.txt @@ -5,6 +5,10 @@ # API and build change and fix summaries. Doc correctsions # and/or changes are not mentioned here; see the commit messages. +2020 April 1; version 3.6.4 + Correct potential nil pointer use in the NNG interface (RIC-303) + Correct issue preventing CI build without a container + 2020 March 30; version 3.6.3 Correct the max receive message size constant in rmr.h (RIC-301) diff --git a/CMakeLists.txt b/CMakeLists.txt index d0d6a9e..076448e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ cmake_minimum_required( VERSION 3.5 ) set( major_version "3" ) # should be automatically populated from git tag later, but until CI process sets a tag we use this set( minor_version "6" ) -set( patch_level "3" ) +set( patch_level "4" ) set( install_root "${CMAKE_INSTALL_PREFIX}" ) set( install_inc "include/rmr" ) @@ -297,9 +297,10 @@ endif() # ------------- testing ------------------------------------------------------- enable_testing() +# cmake cannot set env vars, so we have to passed desired vars on the wrapper command add_test( NAME drive_unit_tests - COMMAND bash ../test/unit_test.ksh -q + COMMAND bash ../test/run_unit_tests.sh CMBUILD=${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ../test ) @@ -307,7 +308,7 @@ add_test( # a dummy script in ./test that does the obvious thing. add_test( NAME drive_app - COMMAND bash ./run_app_tests LD_LIBRARY_PATH=${install_root}/lib C_INCLUDE_PATH=${install_root}/include + COMMAND bash ./run_app_tests.sh LD_LIBRARY_PATH=${install_root}/lib C_INCLUDE_PATH=${install_root}/include CMBUILD=${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ../test ) @@ -343,7 +344,7 @@ install( TARGETS ${target_list} EXPORT LibraryConfig unset( DEV_PKG CACHE ) # prevent from being a hidden setting if user redoes things # install any nano/nng libraries in to the deb as well, but ONLY if asked for on the 'cmake ..' command -# (sure would be nice if FILEs allowed for globbing; sadlyy it does not.) +# (sure would be nice if FILEs allowed for globbing; sadly it does not.) # if( PACK_EXTERNALS ) message( "+++ including nano and nng libraries in the deb" ) diff --git a/src/rmr/nng/src/rmr_nng.c b/src/rmr/nng/src/rmr_nng.c index 8d55b44..8a7c6d0 100644 --- a/src/rmr/nng/src/rmr_nng.c +++ b/src/rmr/nng/src/rmr_nng.c @@ -1054,7 +1054,7 @@ static rmr_mbuf_t* mt_call( void* vctx, rmr_mbuf_t* mbuf, int call_id, int max_w seconds = 1; // use as flag later to invoked timed wait } - if( ep != NULL ) { + if( ep == NULL ) { mbuf = mtosend_msg( ctx, mbuf, 0 ); // use internal function so as not to strip call-id; should be nil on success! } else { mbuf = send_msg( ctx, mbuf, ep->nn_sock, -1 ); diff --git a/test/app_test/Makefile b/test/app_test/Makefile index 8fd68f0..edff57e 100644 --- a/test/app_test/Makefile +++ b/test/app_test/Makefile @@ -36,7 +36,7 @@ SHELL ?= /bin/ksh ex_cflags = $(shell echo $$EX_CFLAGS ) build_path ?= ../../.build -header_path := $(shell find $(build_path) -name 'rmr.h' |head -1 | sed 's!/rmr/.*!!' ) +header_path := $(shell find $(build_path) -name 'rmr.h' 2>/dev/null |head -1 | sed 's!/rmr/.*!!' ) # use from environment if there so as to allow build to reference installed base C_INCLUDE_PATH ?= $(header_path) diff --git a/test/app_test/rebuild.ksh b/test/app_test/rebuild.sh similarity index 91% rename from test/app_test/rebuild.ksh rename to test/app_test/rebuild.sh index bf95b6d..2d1ce83 100644 --- a/test/app_test/rebuild.ksh +++ b/test/app_test/rebuild.sh @@ -20,7 +20,7 @@ # --------------------------------------------------------------------------------- # Mnemonic: rebuild.ksh -# Abstract: This is a simple script that will cause RMr to be rebuilt. It +# Abstract: This is a simple script that will cause RMR to be rebuilt. It # may be invoked by any of the run_* scripts in this directory. # # NOTE: @@ -35,7 +35,7 @@ parent=${PWD%/*} # allow us to step up gracefully gparent=${parent%/*} -build_path=${gparent}/.build # where we'll build +build_path=${BUILD_PATH:-${gparent}/.build} # where we should build; .build by default echo "$(date) build starts" >&2 ( @@ -47,8 +47,7 @@ echo "$(date) build starts" >&2 git pull # get the up to date code so if run from an old image it's a good test fi cd $build_path - cmake .. -DDEV_PKG=1 - make package + make package install ) >/tmp/PID$$.log if (( $? != 0 )) then diff --git a/test/app_test/run_all.ksh b/test/app_test/run_all.ksh index 8cc578c..57e29c8 100644 --- a/test/app_test/run_all.ksh +++ b/test/app_test/run_all.ksh @@ -18,7 +18,27 @@ #================================================================================== # -# run all of the tests, building rmr before the first one if -B is on the command line. +# Mnemonic: run_all.ksh (bash compatable) +# Abstract: This script will drive all of the application tests and ensure +# that the environment is set up as follows: +# +# Any deb packages which exist in BUILD_PATH are 'installed' +# into a /tmp directory so that application builds can reference +# them. +# +# References are set up to find the NNG library files in the +# BUILD_PATH directory. +# +# The BUILD_PATH environment variable should be set, and if not the +# two directories ../.build and ../build are checked for and used. +# If the var is not set, and nether of these directories exists, +# the tests will not be executed. +# +# At the moment, it assumes a deb based system for tests. +# +# Author: E. Scott Daniels +# Date: 2019 +# ----------------------------------------------------------------------------------- function run_test { if [[ -n $capture_file ]] @@ -41,31 +61,76 @@ errors=0 si_flag="" # eventually we'll default to -S to run SI tests over NNG tests src_root="../.." -if [[ -d $src_root/.build ]] # look for build directory in expected places -then # run scripts will honour this - export BUILD_PATH=$src_root/.build +if [[ -z $BUILD_PATH ]] # if not explicitly set, assume one of our standard spots +then + if [[ -d $src_root/.build ]] # look for build directory in expected places + then # run scripts will honour this + export BUILD_PATH=$src_root/.build + else + if [[ -d $src_root/build ]] + then + export BUILD_PATH=$src_root/build + else + echo "[ERR] BUILD_PATH not set and no logical build directory exists to use" + echo "[INFO] tried: $src_root/build and $src_root/.build" + exit 1 + fi + fi + echo "[INFO] using discovered build directory: $BUILD_PATH" else - if [[ -d $src_root/build ]] + echo "[INFO] using externally supplied build directory: $BUILD_PATH" +fi + +# when dpkg is present, unpack the debs in build so we can reference them. When not +# we assume that the env vars are set properly. +# +if which dpkg >/dev/null 2>&1 +then + goober_dir=/tmp/PID$$.goober # private playpen for unpacking deb + rm -fr $goober_dir # this can fail and we don't care + if ! mkdir -p $goober_dir # but we care if this does then - export BUILD_PATH=$src_root/build + echo "[ERR] run_all: cannot set up working directory for lib/header files: $goober_dir" + exit 1 fi + + for d in $BUILD_PATH/*.deb + do + echo "[INFO] run_all: unpacking $d" + dpkg -x $d ${goober_dir} + done + + find ${goober_dir} + + export C_INCLUDE_PATH=$BUILD_PATH/include:${goober_dir}/usr/local/include:$C_INCLUDE_PATH + export LIBRARY_PATH=$BUILD_PATH:$BUILD_PATH/.xbuild/lib:${goober_dir}/usr/local/lib:$LD_LIBRARY_PATH + export LD_LIBRARY_PATH=$LIBRARY_PATH fi + if whence ksh >/dev/null 2>&1 then shell=ksh else shell=bash fi + +verbose=0 +purge=1 while [[ $1 == "-"* ]] do case $1 in - -B) build="-B";; + -B) build="-b";; # build RMR without pulling -e) capture_file=$2; >$capture_file; shift;; -i) installed="-i";; -N) si_flag="";; # turn on NNG tests (off si) + -P) build="-B";; # build RMR with a pull first + -p) purge=0;; # don't purge binaries to ensure rebuild happens -S) si_flag="-S";; # turn on si based tests -s) shell=$2; shift;; + -v) verbose=1;; + + -\?) echo "usage: $0 [-B|-P] [-e err_file] [-i] [-N|-S] [-p] [-s shell] [-v]";; *) echo "'$1' is not a recognised option and is ignored";; esac @@ -73,16 +138,31 @@ do shift done +if (( verbose )) +then + env | grep PATH + if [[ -n $goober_dir ]] + then + find $goober_dir + fi +fi + export SHELL=$shell +if (( purge )) +then + rm -f sender sender_si receiver receiver_si +fi + echo "----- app --------------------" -if which ip >/dev/null 2>&1 +if which ip >/dev/null 2>&1 # ip command rquired for the app test; skip if not found then run_test run_app_test.ksh $si_flag -v $installed $build + build="" fi echo "----- multi ------------------" -run_test run_multi_test.ksh $si_flag +run_test run_multi_test.ksh $si_flag $build echo "----- round robin -----------" run_test run_rr_test.ksh $si_flag @@ -103,4 +183,6 @@ else echo "[FAIL] one or more application to application tests failed" fi + +fm -fr goober_dir exit $(( !! errors )) diff --git a/test/app_test/run_all.sh b/test/app_test/run_all.sh new file mode 100644 index 0000000..51747fb --- /dev/null +++ b/test/app_test/run_all.sh @@ -0,0 +1,190 @@ +#!/usr/bin/env ksh +# vim: ts=4 sw=4 noet : +#================================================================================== +# Copyright (c) 2019-2020 Nokia +# Copyright (c) 2018-2020 AT&T Intellectual Property. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#================================================================================== +# + +# Mnemonic: run_all.ksh (bash compatable) +# Abstract: This script will drive all of the application tests and ensure +# that the environment is set up as follows: +# +# Any deb packages which exist in BUILD_PATH are 'installed' +# into a /tmp directory so that application builds can reference +# them. +# +# References are set up to find the NNG library files in the +# BUILD_PATH directory. +# +# The BUILD_PATH environment variable should be set, and if not the +# two directories ../.build and ../build are checked for and used. +# If the var is not set, and nether of these directories exists, +# the tests will not be executed. +# +# At the moment, it assumes a deb based system for tests. +# +# Author: E. Scott Daniels +# Date: 2019 +# ----------------------------------------------------------------------------------- + +function run_test { + if [[ -n $capture_file ]] + then + if ! $shell $@ >>$capture_file 2>&1 + then + echo "[FAIL] test failed; see $capture_file" + (( errors++ )) + fi + else + if ! $shell $@ + then + (( errors++ )) + fi + fi +} + +build="" +errors=0 +si_flag="" # eventually we'll default to -S to run SI tests over NNG tests + +src_root="../.." +if [[ -z $BUILD_PATH ]] # if not explicitly set, assume one of our standard spots +then + if [[ -d $src_root/.build ]] # look for build directory in expected places + then # run scripts will honour this + export BUILD_PATH=$src_root/.build + else + if [[ -d $src_root/build ]] + then + export BUILD_PATH=$src_root/build + else + echo "[ERR] BUILD_PATH not set and no logical build directory exists to use" + echo "[INFO] tried: $src_root/build and $src_root/.build" + exit 1 + fi + fi + echo "[INFO] using discovered build directory: $BUILD_PATH" +else + echo "[INFO] using externally supplied build directory: $BUILD_PATH" +fi + +# when dpkg is present, unpack the debs in build so we can reference them. When not +# we assume that the env vars are set properly. +# +if which dpkg >/dev/null 2>&1 +then + goober_dir=/tmp/PID$$.goober # private playpen for unpacking deb + rm -fr $goober_dir # this can fail and we don't care + if ! mkdir -p $goober_dir # but we care if this does + then + echo "[ERR] run_all: cannot set up working directory for lib/header files: $goober_dir" + exit 1 + fi + + for d in $BUILD_PATH/*.deb + do + echo "[INFO] run_all: unpacking $d" + dpkg -x $d ${goober_dir} + done + + find ${goober_dir} + + ginclude=$( find $goober_dir -name include | head -1 ) + glib=$( find $goober_dir -name lib | head -1 ) + export C_INCLUDE_PATH=$BUILD_PATH/include:${ginclude}:$C_INCLUDE_PATH + export LIBRARY_PATH=$BUILD_PATH:$BUILD_PATH/.xbuild/lib:${glib}:$LD_LIBRARY_PATH + export LD_LIBRARY_PATH=$LIBRARY_PATH +fi + + +if whence ksh >/dev/null 2>&1 +then + shell=ksh +else + shell=bash +fi + +verbose=0 +purge=1 +while [[ $1 == "-"* ]] +do + case $1 in + -B) build="-b";; # build RMR without pulling + -e) capture_file=$2; >$capture_file; shift;; + -i) installed="-i";; + -N) si_flag="";; # turn on NNG tests (off si) + -P) build="-B";; # build RMR with a pull first + -p) purge=0;; # don't purge binaries to ensure rebuild happens + -S) si_flag="-S";; # turn on si based tests + -s) shell=$2; shift;; + -v) verbose=1;; + + -\?) echo "usage: $0 [-B|-P] [-e err_file] [-i] [-N|-S] [-p] [-s shell] [-v]";; + + *) echo "'$1' is not a recognised option and is ignored";; + esac + + shift +done + +if (( verbose )) +then + env | grep PATH + if [[ -n $goober_dir ]] + then + find $goober_dir + fi +fi + +export SHELL=$shell + +if (( purge )) +then + rm -f sender sender_si receiver receiver_si +fi + +echo "----- app --------------------" +if which ip >/dev/null 2>&1 # ip command rquired for the app test; skip if not found +then + run_test run_app_test.sh $si_flag -v $installed $build + build="" +fi + +echo "----- multi ------------------" +run_test run_multi_test.sh $si_flag $build + +echo "----- round robin -----------" +run_test run_rr_test.sh $si_flag + +echo "----- rts -------------------" +run_test run_rts_test.sh $si_flag -s 5 -d 100 + +echo "----- extended payload nocopy no clone------" +run_test run_exrts_test.sh $si_flag -d 10 -n 1000 + +echo "----- extended payload copy clone------" +run_test run_exrts_test.sh $si_flag -d 10 -n 1000 -c 11 + +if (( errors == 0 )) +then + echo "[PASS] all test pass" +else + echo "[FAIL] one or more application to application tests failed" +fi + + +fm -fr goober_dir +exit $(( !! errors )) diff --git a/test/app_test/run_app_test.ksh b/test/app_test/run_app_test.sh similarity index 92% rename from test/app_test/run_app_test.ksh rename to test/app_test/run_app_test.sh index ef12a00..11db720 100644 --- a/test/app_test/run_app_test.ksh +++ b/test/app_test/run_app_test.sh @@ -98,7 +98,7 @@ endKat nmsg=20 # total number of messages to be exchanged (-n value changes) # need two sent to each receiver to ensure hairpin entries were removed (will fail if they were not) -delay=500000 # microsec sleep between msg 1,000,000 == 1s +delay=100000 # microsec sleep between msg 1,000,000 == 1s wait=1 rebuild=0 nopull="" # -b sets so that build does not pull @@ -181,11 +181,14 @@ else fi fi - if [[ -d $build_path/lib64 ]] + if [[ -z $LD_LIBRARY_PATH ]] # the cmake test environment will set this; we must use if set then - export LD_LIBRARY_PATH=$build_path:$build_path/lib64 - else - export LD_LIBRARY_PATH=$build_path:$build_path/lib + if [[ -d $build_path/lib64 ]] + then + export LD_LIBRARY_PATH=$build_path:$build_path/lib64 + else + export LD_LIBRARY_PATH=$build_path:$build_path/lib + fi fi export LIBRARY_PATH=$LD_LIBRARY_PATH fi @@ -196,7 +199,10 @@ if (( force_make )) || [[ ! -f ./sender${si} || ! -f ./receiver${si} ]] then if ! make -B sender${si} receiver${si} >/tmp/PID$$.clog 2>&1 then - echo "[FAIL] cannot find sender${si} and/or receiver${si}binary, and cannot make them.... humm?" + echo "[FAIL] cannot find sender${si} and/or receiver${si} binary, and cannot make them.... humm?" + echo "[INFO] ------------- PATH settings -----------------" + env | grep PATH + echo "[INFO] ------------- compiler output (head) -----------------" head -50 /tmp/PID$$.clog rm -fr /tmp/PID$$.* exit 1 diff --git a/test/app_test/run_call_test.ksh b/test/app_test/run_call_test.sh similarity index 91% rename from test/app_test/run_call_test.ksh rename to test/app_test/run_call_test.sh index 1028523..64ed70e 100644 --- a/test/app_test/run_call_test.ksh +++ b/test/app_test/run_call_test.sh @@ -170,18 +170,21 @@ else fi fi -if (( dev_base )) # assume we are testing against what we've built, not what is installed +if [[ -z $LD_LIBRARY_PATH ]] # cmake test will set and it must be honoured then - if [[ -d $build_path/lib64 ]] + if (( dev_base )) # assume we are testing against what we've built, not what is installed then - export LD_LIBRARY_PATH=$build_path:$build_path/lib64:$LD_LIBRARY_PATH - else - export LD_LIBRARY_PATH=$build_path:$build_path/lib:$LD_LIBRARY_PATH + if [[ -d $build_path/lib64 ]] + then + export LD_LIBRARY_PATH=$build_path:$build_path/lib64:$LD_LIBRARY_PATH + else + export LD_LIBRARY_PATH=$build_path:$build_path/lib:$LD_LIBRARY_PATH + fi + export LIBRARY_PATH=$LD_LIBRARY_PATH + else # -D option gets us here to test an installed library + export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH + export LIBRARY_PATH=$LD_LIBRARY_PATH fi - export LIBRARY_PATH=$LD_LIBRARY_PATH -else # -D option gets us here to test an installed library - export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH - export LIBRARY_PATH=$LD_LIBRARY_PATH fi export RMR_SEED_RT=${RMR_SEED_RT:-./caller.rt} # allow easy testing with different rt diff --git a/test/app_test/run_exrts_test.ksh b/test/app_test/run_exrts_test.sh similarity index 96% rename from test/app_test/run_exrts_test.ksh rename to test/app_test/run_exrts_test.sh index 9bd198d..9f0a436 100644 --- a/test/app_test/run_exrts_test.ksh +++ b/test/app_test/run_exrts_test.sh @@ -169,11 +169,14 @@ else fi fi - if [[ -d $build_path/lib64 ]] + if [[ -z $LD_LIBRARY_PATH ]] # cmake test will set this up and we must honour then - export LD_LIBRARY_PATH=$build_path:$build_path/lib64:$LD_LIBRARY_PATH - else - export LD_LIBRARY_PATH=$build_path:$build_path/lib:$LD_LIBRARY_PATH + if [[ -d $build_path/lib64 ]] + then + export LD_LIBRARY_PATH=$build_path:$build_path/lib64:$LD_LIBRARY_PATH + else + export LD_LIBRARY_PATH=$build_path:$build_path/lib:$LD_LIBRARY_PATH + fi fi fi diff --git a/test/app_test/run_lcall_test.ksh b/test/app_test/run_lcall_test.sh similarity index 95% rename from test/app_test/run_lcall_test.ksh rename to test/app_test/run_lcall_test.sh index 241deb5..944d399 100644 --- a/test/app_test/run_lcall_test.ksh +++ b/test/app_test/run_lcall_test.sh @@ -168,11 +168,14 @@ else fi fi - if [[ -d $build_path/lib64 ]] + if [[ -z $LD_LIBRARY_PATH ]] # cmake test will set this; we must honour it then - export LD_LIBRARY_PATH=$build_path:$build_path/lib64:$LD_LIBRARY_PATH - else - export LD_LIBRARY_PATH=$build_path:$build_path/lib:$LD_LIBRARY_PATH + if [[ -d $build_path/lib64 ]] + then + export LD_LIBRARY_PATH=$build_path:$build_path/lib64:$LD_LIBRARY_PATH + else + export LD_LIBRARY_PATH=$build_path:$build_path/lib:$LD_LIBRARY_PATH + fi fi fi diff --git a/test/app_test/run_multi_test.ksh b/test/app_test/run_multi_test.sh similarity index 95% rename from test/app_test/run_multi_test.ksh rename to test/app_test/run_multi_test.sh index acc065d..d8cf765 100644 --- a/test/app_test/run_multi_test.ksh +++ b/test/app_test/run_multi_test.sh @@ -154,12 +154,16 @@ else fi fi -if [[ -d $build_path/lib64 ]] +if [[ -z LD_LIBRARY_PATH ]] # if cmake test sets we must honour then - export LD_LIBRARY_PATH=$build_path:$build_path/lib64:$LD_LIBRARY_PATH -else - export LD_LIBRARY_PATH=$build_path:$build_path/lib:$LD_LIBRARY_PATH + if [[ -d $build_path/lib64 ]] + then + export LD_LIBRARY_PATH=$build_path:$build_path/lib64:$LD_LIBRARY_PATH + else + export LD_LIBRARY_PATH=$build_path:$build_path/lib:$LD_LIBRARY_PATH + fi fi + export LIBRARY_PATH=$LD_LIBRARY_PATH export RMR_SEED_RT=./multi.rt diff --git a/test/app_test/run_rr_test.ksh b/test/app_test/run_rr_test.sh similarity index 95% rename from test/app_test/run_rr_test.ksh rename to test/app_test/run_rr_test.sh index 62aae3b..581f286 100644 --- a/test/app_test/run_rr_test.ksh +++ b/test/app_test/run_rr_test.sh @@ -156,12 +156,16 @@ else fi fi -if [[ -d $build_path/lib64 ]] +if [[ -z $LD_LIBRARY_PATH ]] # honour if cmake test sets then - export LD_LIBRARY_PATH=$build_path:$build_path/lib64:$LD_LIBRARY_PATH -else - export LD_LIBRARY_PATH=$build_path:$build_path/lib:$LD_LIBRARY_PATH + if [[ -d $build_path/lib64 ]] + then + export LD_LIBRARY_PATH=$build_path:$build_path/lib64:$LD_LIBRARY_PATH + else + export LD_LIBRARY_PATH=$build_path:$build_path/lib:$LD_LIBRARY_PATH + fi fi + export LIBRARY_PATH=$LD_LIBRARY_PATH export RMR_SEED_RT=./rr.rt diff --git a/test/app_test/run_rts_test.ksh b/test/app_test/run_rts_test.sh similarity index 95% rename from test/app_test/run_rts_test.ksh rename to test/app_test/run_rts_test.sh index d268fd3..7ebf4b4 100644 --- a/test/app_test/run_rts_test.ksh +++ b/test/app_test/run_rts_test.sh @@ -126,12 +126,16 @@ else fi fi -if [[ -d $build_path/lib64 ]] +if [[ -z LD_LIBRARY_PATH ]] # honour if cmake test sets it then - export LD_LIBRARY_PATH=$build_path:$build_path/lib64:$LD_LIBRARY_PATH -else - export LD_LIBRARY_PATH=$build_path:$build_path/lib:$LD_LIBRARY_PATH + if [[ -d $build_path/lib64 ]] + then + export LD_LIBRARY_PATH=$build_path:$build_path/lib64:$LD_LIBRARY_PATH + else + export LD_LIBRARY_PATH=$build_path:$build_path/lib:$LD_LIBRARY_PATH + fi fi + export LIBRARY_PATH=$LD_LIBRARY_PATH export RMR_SEED_RT=./rts.rt diff --git a/test/run_app_tests b/test/run_app_tests.sh similarity index 74% rename from test/run_app_tests rename to test/run_app_tests.sh index 21064d9..3df47e2 100644 --- a/test/run_app_tests +++ b/test/run_app_tests.sh @@ -29,9 +29,24 @@ # To deal with this, all leading positional parms of the form foo=bar are # looked at and if we like it we'll export it before starting the test. +# It is also impossible for us to know what the build directory the user +# created for their build and test. We will auto discover if they used +# .build or build in the parent to this directory (in that order). If a +# different directory is desired, then the build directory must be supplied +# as an environment variable to the make: +# cd rmr/.bld +# BUILD_PATH=$PWD make test ARGS=-v + while [[ $1 == *"="* ]] do case ${1%%=*} in + CMBUILD) # should be cmake build dir + if [[ -z $BUILD_PATH ]] # still allow user to override + then + export BUILD_PATH=${1##*=} + fi + ;; + LD_LIBRARY_PATH) export LD_LIBRARY_PATH=${1##*=} ;; @@ -51,4 +66,4 @@ done set -e cd app_test -bash ./run_all.ksh -S # build CI likely doesn't have ksh; Run SI tests +bash ./run_all.sh -S # build CI likely doesn't have ksh; Run SI tests diff --git a/test/run_unit_tests.sh b/test/run_unit_tests.sh new file mode 100644 index 0000000..07d84e3 --- /dev/null +++ b/test/run_unit_tests.sh @@ -0,0 +1,60 @@ +#!/usr/env bash +# vim: ts=4 sw=4 noet : +#================================================================================== +# Copyright (c) 2020 Nokia +# Copyright (c) 2020 AT&T Intellectual Property. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#================================================================================== +# + +# This is a wrappter to the unit test script which is needed because CMake test +# is unable to set environment variables before executing the test command. +# this script assumes that env variables are passed on the command line in x=y +# format. We will set all that are given; the only exception to this is that +# we will NOT override the BUILD_PATH variable which allows it to be set +# from the script that invokes 'make test' + +# We assume that the CMBUILD variable has a good build directory (e.g. .build) +# but the user can be sure by hard setting BUILD_PATH which will NOT be +# changed. For example: +# cd rmr/.bld +# BUILD_PATH=$PWD make test ARGS="-V" + +while [[ $1 == *"="* ]] +do + case ${1%%=*} in + CMBUILD) # should be cmake build dir + if [[ -z $BUILD_PATH ]] # still allow user to override + then + export BUILD_PATH=${1##*=} + fi + ;; + + LD_LIBRARY_PATH) + export LD_LIBRARY_PATH=${1##*=} + ;; + + C_INCLUDE_PATH) + export C_INCLUDE_PATH=${1##*=} + ;; + + LIBRARY_PATH) + export LIBRARY_PATH=${1##*=} + ;; + esac + + shift +done + +bash ./unit_test.ksh -q diff --git a/test/unit_test.ksh b/test/unit_test.ksh index 80712a5..ad21465 100755 --- a/test/unit_test.ksh +++ b/test/unit_test.ksh @@ -82,7 +82,7 @@ function usage { function add_ignored_func { if [[ ! -r $1 ]] then - echo ">>>> can't find file to ignore: $1" + echo ">>>> can't find file to ignore: $1" return fi @@ -215,7 +215,6 @@ function discount_an_checks { #printf( "allow discount: %s\n", $0 ) if( replace_flags ) { gsub( "#####", " 1", $0 ) - //gsub( "#####", "=====", $0 ) } discount++; } @@ -312,23 +311,26 @@ function mk_xml { # ----------------------------------------------------------------------------------------------------------------- -# we assume that the project has been built in the ../[.]build directory -if [[ -d ../build ]] +if [[ -z $BUILD_PATH ]] then - export LD_LIBRARY_PATH=../build/lib:../build/lib64 - export C_INCLUDE_PATH=../build/include -else - if [[ -d ../.build ]] - then - export LD_LIBRARY_PATH=../.build/lib:../.build/lib64 - export C_INCLUDE_PATH=../.build/include + # we assume that the project has been built in the ../[.]build directory + if [[ -d ../build ]] + then + export BUILD_PATH=../build else - echo "[WARN] cannot find build directory (tried ../build and ../.build); things might not work" - echo "" + if [[ -d ../.build ]] + then + export BUILD_PATH=../.build + else + echo "[WARN] cannot find build directory (tried ../build and ../.build); things might not work" + echo "" + fi fi fi +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$BUILD_PATH/lib:$BUILD_PATH/lib64 +export C_INCLUDE_PATH=$C_INCLUDE_PATH:$BUILD_PATH/include export LIBRARY_PATH=$LD_LIBRARY_PATH # The Makefile sets specific includes for things @@ -420,7 +422,7 @@ then then continue fi - + flist="${flist}$tfile " fi done @@ -483,7 +485,7 @@ do if ! ./${tfile%.c} >/tmp/PID$$.log 2>&1 then echo "[FAIL] unit test failed for: $tfile" - if [[ -n $capture_file ]] + if [[ -n $capture_file ]] then echo "all errors captured in $capture_file, listing only fail message on tty" echo "$tfile --------------------------------------" >>$capture_file @@ -493,7 +495,7 @@ do else if (( quiet )) then - grep "^<" /tmp/PID$$.log|grep -v "^" # in quiet mode just dump <...> messages which are assumed from the test programme not appl + grep "^<" /tmp/PID$$.log|egrep -v "^|^" # in quiet mode just dump <...> messages which are assumed from the test programme not appl else cat /tmp/PID$$.log fi @@ -501,7 +503,7 @@ do (( ut_errors++ )) # cause failure even if not in strict mode if (( ! always_gcov )) then - continue # skip coverage tests for this + exit 1 # we are in a subshell, must exit bad fi else if (( show_output )) @@ -652,6 +654,12 @@ do done fi )>/tmp/PID$$.noise 2>&1 + if (( $? != 0 )) + then + (( ut_errors++ )) + cat /tmp/PID$$.noise + continue + fi for x in *.gcov # merge any previous coverage file with this one do @@ -667,7 +675,7 @@ do then cat /tmp/PID$$.noise fi -done +done echo "" echo "[INFO] final discount checks on merged gcov files" -- 2.16.6