test(app): Add test application base
[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
77 while [[ $1 == -* ]]
78 do
79         case $1 in 
80                 -B)     rebuild=1;;
81                 -d)     delay=$2; shift;;
82                 -N)     nano_sender=1
83                         nano_receiver=1
84                         ;;
85                 -n)     nmsg=$2; shift;;
86
87                 *)      echo "unrecognised option: $1"
88                         echo "usage: $0 [-B] [-d micor-sec-delay] [-N] [-n num-msgs]"
89                         echo "  -B forces a rebuild which will use .build"
90                         exit 1
91                         ;;
92         esac
93
94         shift
95 done
96
97 if (( rebuild )) 
98 then
99         build_path=../../.build
100
101         (
102                 set -e
103                 mkdir -p $build_path
104                 cd ${build_path%/*}                             # cd barfs on ../../.build, so we do this
105                 cd ${build_path##*/}
106                 cmake ..
107                 make package
108         )
109         if (( $? != 0 ))
110         then
111                 echo "build failed"
112                 exit 1
113         fi
114 else
115         build_path=${BUILD_PATH:-"../../.build"}        # we prefer .build at the root level, but allow user option
116
117         if [[ ! -d $build_path ]]
118         then
119                 echo "cannot find build in: $build_path"
120                 echo "either create, and then build RMr, or set BUILD_PATH as an evironment var before running this"
121                 exit 1
122         fi
123 fi
124
125 export LD_LIBRARY_PATH=$build_path:$build_path/lib
126 export LIBRARY_PATH=$LD_LIBRARY_PATH
127 export RMR_SEED_RT=${RMR_SEED_RT:-./local.rt}           # allow easy testing with different rt
128
129
130 if [[ ! -f ./sender ]]
131 then
132         if ! make >/dev/null 2>&1
133         then
134                 echo "[FAIL] cannot find sender binary, and cannot make it.... humm?"
135                 exit 1
136         fi
137 fi
138
139 run_rcvr &
140 run_sender &
141
142 wait
143 head -1 /tmp/PID$$.rrc | read rrc
144 head -1 /tmp/PID$$.src | read src
145
146 if (( !! (src + rrc) ))
147 then
148         echo "[FAIL] sender rc=$src  receiver rc=$rrc"
149 else
150         echo "[PASS] sender rc=$src  receiver rc=$rrc"
151 fi
152
153 rm /tmp/PID$$.*
154
155 exit $(( !! (src + rrc) ))
156