Add better support for manual app testing
[ric-plt/lib/rmr.git] / test / app_test / run_all.ksh
1 #!/usr/bin/env ksh
2 # vim: ts=4 sw=4 noet :
3 #==================================================================================
4 #    Copyright (c) 2019-2021 Nokia
5 #    Copyright (c) 2018-2021 AT&T Intellectual Property.
6 #
7 #   Licensed under the Apache License, Version 2.0 (the "License");
8 #   you may not use this file except in compliance with the License.
9 #   You may obtain a copy of the License at
10 #
11 #       http://www.apache.org/licenses/LICENSE-2.0
12 #
13 #   Unless required by applicable law or agreed to in writing, software
14 #   distributed under the License is distributed on an "AS IS" BASIS,
15 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 #   See the License for the specific language governing permissions and
17 #   limitations under the License.
18 #==================================================================================
19 #
20
21 #       Mnemonic:       run_all.ksh (bash compatable)
22 #       Abstract:       This script will drive all of the application tests and ensure
23 #                               that the environment is set up as follows:
24 #
25 #                                       Any deb packages which exist in BUILD_PATH are 'installed'
26 #                                       into a /tmp directory so that application builds can reference
27 #                                       them.
28 #
29 #                                       References are set up to find the NNG library files in the
30 #                                       BUILD_PATH directory.
31 #
32 #                               The BUILD_PATH environment variable should be set, and if not the
33 #                               two directories ../.build and ../build are checked for and used.
34 #                               If the var is not set, and nether of these directories exists,
35 #                               the tests will not be executed.
36 #
37 #                               At the moment, it assumes a deb based system for tests. 
38 #
39 #       Author:         E. Scott Daniels
40 #       Date:           2019
41 # -----------------------------------------------------------------------------------
42
43 function run_test {
44         if [[ -n $capture_file ]]
45         then
46                 if ! $shell $@ >>$capture_file 2>&1
47                 then
48                         echo "[FAIL] test failed; see $capture_file"
49                         (( errors++ ))
50                 fi
51         else
52                 if ! $shell $@
53                 then
54                         (( errors++ ))
55                 fi
56         fi
57 }
58
59 build=""
60 errors=0
61 si_flag=""                              # eventually we'll default to -S to run SI tests over NNG tests
62
63 src_root="../.."
64 if [[ -z $BUILD_PATH ]]                                         # if not explicitly set, assume one of our standard spots
65 then
66         if [[ -d $src_root/.build ]]                    # look for build directory in expected places
67         then                                                                    # run scripts will honour this
68                 export BUILD_PATH=$src_root/.build
69         else
70                 if [[ -d $src_root/build ]]
71                 then
72                         export BUILD_PATH=$src_root/build
73                 else
74                         echo "[ERR]  BUILD_PATH not set and no logical build directory exists to use"
75                         echo "[INFO] tried: $src_root/build and $src_root/.build"
76                         exit 1
77                 fi
78         fi
79         echo "[INFO] using discovered build directory: $BUILD_PATH"
80 else
81         echo "[INFO] using externally supplied build directory: $BUILD_PATH"
82 fi
83
84 # when dpkg is present, unpack the debs in build so we can reference them. When not
85 # we assume that the env vars are set properly.
86 #
87 if which dpkg >/dev/null 2>&1
88 then
89         goober_dir=/tmp/PID$$.goober    # private playpen for unpacking deb
90         rm -fr $goober_dir                              # this can fail and we don't care
91         if ! mkdir -p $goober_dir               # but we care if this does
92         then
93                 echo "[ERR] run_all: cannot set up working directory for lib/header files: $goober_dir"
94                 exit 1
95         fi
96
97         for d in $BUILD_PATH/*.deb
98         do
99                 echo "[INFO] run_all: unpacking $d"
100                 dpkg -x $d ${goober_dir}
101         done
102
103         find ${goober_dir}
104
105         export C_INCLUDE_PATH=$BUILD_PATH/include:${goober_dir}/usr/local/include:$C_INCLUDE_PATH
106         export LIBRARY_PATH=$BUILD_PATH:$BUILD_PATH/.xbuild/lib:${goober_dir}/usr/local/lib:$LD_LIBRARY_PATH
107         export LD_LIBRARY_PATH=$LIBRARY_PATH
108 fi
109
110
111 if whence ksh >/dev/null 2>&1
112 then
113         shell=ksh
114 else
115         shell=bash
116 fi
117
118 verbose=0
119 purge=1
120 while [[ $1 == "-"* ]]
121 do
122         case $1 in
123                 -B)     build="-b";;                    # build RMR without pulling
124                 -e)     capture_file=$2; >$capture_file; shift;;
125                 -i)     installed="-i";;
126                 -N)     si_flag="";;                    # turn on NNG tests (off si)
127                 -P)     build="-B";;                    # build RMR with a pull first
128                 -p)     purge=0;;                               # don't purge binaries to ensure rebuild happens
129                 -S)     si_flag="-S";;                  # turn on si based tests
130                 -s) shell=$2; shift;;
131                 -v)     verbose=1;;
132
133                 -\?) echo "usage: $0 [-B|-P] [-e err_file] [-i] [-N|-S] [-p] [-s shell] [-v]";;
134
135                 *)      echo "'$1' is not a recognised option and is ignored";;
136         esac
137
138         shift
139 done
140
141 if (( verbose ))
142 then
143         env | grep PATH
144         if [[ -n $goober_dir ]]
145         then
146                 find $goober_dir
147         fi
148 fi
149
150 export SHELL=$shell
151
152 if (( purge ))
153 then
154         rm -f sender receiver 
155 fi
156
157 echo "----- app --------------------"
158 if which ip >/dev/null 2>&1                                     # ip command rquired for the app test; skip if not found
159 then
160         run_test run_app_test.ksh $si_flag -v $installed $build
161         build=""
162 fi
163
164 echo "----- multi ------------------"
165 run_test run_multi_test.ksh $si_flag $build
166
167 echo "----- round robin -----------"
168 run_test run_rr_test.ksh $si_flag
169
170 echo "----- rts -------------------"
171 run_test run_rts_test.ksh $si_flag -s 5 -d 100
172
173 echo "----- extended payload nocopy no clone------"
174 run_test run_exrts_test.ksh $si_flag -d 10 -n 1000
175
176 echo "----- extended payload copy clone------"
177 run_test run_exrts_test.ksh $si_flag -d 10 -n 1000 -c 11
178
179 if (( errors == 0 ))
180 then
181         echo "[PASS] all test pass"
182 else
183         echo "[FAIL] one or more application to application tests failed"
184 fi
185
186
187 fm -fr goober_dir
188 exit $(( !! errors ))