test(e2e): Add return to sender app based test
[ric-plt/lib/rmr.git] / test / app_test / run_app_test.ksh
1 #!/usr/bin/env ksh
2 # :vi ts=4 sw=4 noet :
3 #==================================================================================
4 #    Copyright (c) 2019 Nokia
5 #    Copyright (c) 2018-2019 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 # ---------------------------------------------------------------------------------
22 #       Mnemonic:       run_app_test.ksh
23 #       Abstract:       This is a simple script to set up and run the basic send/receive
24 #                               processes for some library validation on top of nano/nng.
25 #                               It should be possible to clone the repo, switch to this directory
26 #                               and execute  'ksh run -B'  which will build RMr, make the sender and
27 #                               recevier then  run the basic test.
28 #
29 #                               Example command line:
30 #                                       ksh ./run               # default 10 messages at 1 msg/sec
31 #                                       ksh ./run -N    # default but with nanomsg lib
32 #                                       ksh ./run -d 100 -n 10000 # send 10k messages with 100ms delay between
33 #
34 #       Date:           22 April 2019
35 #       Author:         E. Scott Daniels
36 # ---------------------------------------------------------------------------------
37
38
39 # The sender and receiver are run asynch. Their exit statuses are captured in a
40 # file in order for the 'main' to pick them up easily.
41 #
42 function run_sender {
43         if (( $nano_sender ))
44         then
45                 ./sender_nano $nmsg $delay
46         else
47                 ./sender $nmsg $delay
48         fi
49         echo $? >/tmp/PID$$.src         # must communicate state back via file b/c asynch
50 }
51
52 function run_rcvr {
53         if (( $nano_receiver ))
54         then
55                 ./receiver_nano $nmsg
56         else
57                 ./receiver $nmsg
58         fi
59         echo $? >/tmp/PID$$.rrc
60 }
61
62 # ---------------------------------------------------------
63
64 if [[ ! -f local.rt ]]          # we need the real host name in the local.rt; build one from mask if not there
65 then
66         hn=$(hostname)
67         sed "s!%%hostname%%!$hn!" rt.mask >local.rt
68 fi
69
70 nmsg=10                                         # total number of messages to be exchanged (-n value changes)
71 delay=1000000                           # microsec sleep between msg 1,000,000 == 1s
72 nano_sender=0                           # start nano version if set (-N)
73 nano_receiver=0
74 wait=1
75 rebuild=0
76 nopull=""                                       # -b sets so that build does not pull
77 verbose=0
78
79 while [[ $1 == -* ]]
80 do
81         case $1 in
82                 -B)     rebuild=1;;                                             # build with pull first
83                 -b)     rebuild=1; nopull="nopull";;    # buld without pull
84                 -d)     delay=$2; shift;;
85                 -N)     nano_sender=1
86                         nano_receiver=1
87                         ;;
88                 -n)     nmsg=$2; shift;;
89                 -v)     verbose=1;;
90
91                 *)      echo "unrecognised option: $1"
92                         echo "usage: $0 [-B] [-d micor-sec-delay] [-N] [-n num-msgs]"
93                         echo "  -B forces a rebuild which will use .build"
94                         exit 1
95                         ;;
96         esac
97
98         shift
99 done
100
101 if (( verbose ))
102 then
103         echo "2" >.verbose
104         export RMR_VCTL_FILE=".verbose"
105 fi
106
107 if (( rebuild ))
108 then
109         set -e
110         ksh ./rebuild.ksh $nopull | read build_path
111         set +e
112 else
113         build_path=${BUILD_PATH:-"../../.build"}        # we prefer .build at the root level, but allow user option
114
115         if [[ ! -d $build_path ]]
116         then
117                 echo "cannot find build in: $build_path"
118                 echo "either create, and then build RMr, or set BUILD_PATH as an evironment var before running this"
119                 exit 1
120         fi
121 fi
122
123 if [[ -d $build_path/lib64 ]]
124 then
125         export LD_LIBRARY_PATH=$build_path:$build_path/lib64
126 else
127         export LD_LIBRARY_PATH=$build_path:$build_path/lib
128 fi
129
130 export LIBRARY_PATH=$LD_LIBRARY_PATH
131 export RMR_SEED_RT=${RMR_SEED_RT:-./local.rt}           # allow easy testing with different rt
132
133
134 if [[ ! -f ./sender ]]
135 then
136         if ! make >/dev/null 2>&1
137         then
138                 echo "[FAIL] cannot find sender binary, and cannot make it.... humm?"
139                 exit 1
140         fi
141 fi
142
143 run_rcvr &
144 sleep 2                         # if sender starts faster than rcvr we can drop, so pause a bit
145 run_sender &
146
147 wait
148 head -1 /tmp/PID$$.rrc | read rrc
149 head -1 /tmp/PID$$.src | read src
150
151 if (( !! (src + rrc) ))
152 then
153         echo "[FAIL] sender rc=$src  receiver rc=$rrc"
154 else
155         echo "[PASS] sender rc=$src  receiver rc=$rrc"
156 fi
157
158 rm /tmp/PID$$.*
159 rm -f .verbose
160
161 exit $(( !! (src + rrc) ))
162