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