Add better support for manual app testing
[ric-plt/lib/rmr.git] / test / app_test / run_all.sh
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
62 src_root="../.."
63 if [[ -z $BUILD_PATH ]]                                         # if not explicitly set, assume one of our standard spots
64 then
65         if [[ -d $src_root/.build ]]                    # look for build directory in expected places
66         then                                                                    # run scripts will honour this
67                 export BUILD_PATH=$src_root/.build
68         else
69                 if [[ -d $src_root/build ]]
70                 then
71                         export BUILD_PATH=$src_root/build
72                 else
73                         echo "[ERR]  BUILD_PATH not set and no logical build directory exists to use"
74                         echo "[INFO] tried: $src_root/build and $src_root/.build"
75                         exit 1
76                 fi
77         fi
78         echo "[INFO] using discovered build directory: $BUILD_PATH"
79 else
80         echo "[INFO] using externally supplied build directory: $BUILD_PATH"
81 fi
82
83 # when dpkg is present, unpack the debs in build so we can reference them. When not
84 # we assume that the env vars are set properly.
85 #
86 if which dpkg >/dev/null 2>&1
87 then
88         goober_dir=/tmp/PID$$.goober    # private playpen for unpacking deb
89         rm -fr $goober_dir                              # this can fail and we don't care
90         if ! mkdir -p $goober_dir               # but we care if this does
91         then
92                 echo "[ERR] run_all: cannot set up working directory for lib/header files: $goober_dir"
93                 exit 1
94         fi
95
96         for d in $BUILD_PATH/*.deb
97         do
98                 echo "[INFO] run_all: unpacking $d"
99                 dpkg -x $d ${goober_dir}
100         done
101
102         find ${goober_dir}
103
104         ginclude=$( find $goober_dir -name include | head -1 )
105         glib=$( find $goober_dir -name lib | head -1 )
106         export C_INCLUDE_PATH=$BUILD_PATH/include:${ginclude}:$C_INCLUDE_PATH
107         export LIBRARY_PATH=$BUILD_PATH:$BUILD_PATH/.xbuild/lib:${glib}:$LD_LIBRARY_PATH
108         export LD_LIBRARY_PATH=$LIBRARY_PATH
109 fi
110
111
112 if whence ksh >/dev/null 2>&1
113 then
114         shell=ksh
115 else
116         shell=bash
117 fi
118
119 verbose=0
120 purge=1
121 while [[ $1 == "-"* ]]
122 do
123         case $1 in
124                 -B)     build="-b";;                    # build RMR without pulling
125                 -e)     capture_file=$2; >$capture_file; shift;;
126                 -i)     installed="-i";;
127                 -N)     ;;                                              # ignored for backwards compatability; nng no longer supported
128                 -P)     build="-B";;                    # build RMR with a pull first
129                 -p)     purge=0;;                               # don't purge binaries to ensure rebuild happens
130                 -S)     ;;                                              # ignored; nng tests are not supported so all binaries are now si95
131                 -s) shell=$2; shift;;
132                 -v)     verbose=1;;
133
134                 -\?) echo "usage: $0 [-B|-P] [-e err_file] [-i] [-p] [-s shell] [-v]";;
135
136                 *)      echo "'$1' is not a recognised option and is ignored";;
137         esac
138
139         shift
140 done
141
142 if (( verbose ))
143 then
144         env | grep PATH
145         if [[ -n $goober_dir ]]
146         then
147                 find $goober_dir
148         fi
149 fi
150
151 export SHELL=$shell
152
153 if (( purge ))
154 then
155         rm -f sender receiver 
156 fi
157
158 echo "----- app --------------------"
159 if which ip >/dev/null 2>&1                                     # ip command rquired for the app test; skip if not found
160 then
161         run_test run_app_test.sh -v $installed $build
162         build=""
163 fi
164
165 echo "----- multi ------------------"
166 run_test run_multi_test.sh  $build
167
168 echo "----- round robin -----------"
169 run_test run_rr_test.sh 
170
171 echo "----- rts -------------------"
172 run_test run_rts_test.sh  -s 5 -d 100
173
174 echo "----- extended payload nocopy no clone------"
175 run_test run_exrts_test.sh  -d 10 -n 1000
176
177 echo "----- extended payload copy clone------"
178 run_test run_exrts_test.sh  -d 10 -n 1000 -c 11
179
180 if (( errors == 0 ))
181 then
182         echo "[PASS] all test pass"
183 else
184         echo "[FAIL] one or more application to application tests failed"
185 fi
186
187
188 rm -fr goober_dir
189 exit $(( !! errors ))