a50bcceba873f83c34af839df8f41e9ec7794ed8
[ric-app/mc.git] / sidecars / listener / src / verify.sh
1 #!/usr/bin/env bash
2 # vim: ts=4 sw=4 noet:
3 #----------------------------------------------------------------------------------
4 #
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 # ----------------------------------------------------------------------
23 # Mnemonic:     verify.sh
24 # Abstract: Simple script to attempt to verify that the mc_listener is
25 #                       capable of running. This will start a listener and a sender
26 #                       and then will cat a few lines from one of the FIFOs.
27 #                       This script is designed to run using the geneated runtime
28 #                       image; in other words, it expects to find the binaries
29 #                       in /playpen/bin if that directory exists. If it does not it
30 #                       assumes the current working directory is where the binaries
31 #                       exist.
32 #
33 # Date:         26 August 2019
34 # Author:       E. Scott Daniels
35 # ----------------------------------------------------------------------
36
37 # set the various sleep values based on long test or short test
38 function set_wait_values {
39         if (( long_test ))
40         then
41                 export MCL_RDC_FREQ=13          # file cycle after 13s
42                 sender_wait=100
43                 listener_wait=105
44                 reader_wait=102
45                 main_wait=120
46         else
47                 sender_wait=10
48                 listener_wait=15
49                 reader_wait=12
50                 main_wait=20
51         fi
52 }
53
54 # run sender at a 2 msg/sec rate (500000 musec delay)
55 # sender sends msg types 0-6 and the route table in /tmp
56 # will direct them to the listener. We also need to switch
57 # the RT listen port so there is no collision with the listen
58 # preocess.
59 #
60 function run_sender {
61         echo "starting sender"
62         RMR_SEED_RT=/tmp/local.rt RMR_RTG_SVC=9989 $bin_dir/sender 43086 10000 >/tmp/sender.log 2>&1 &
63         spid=$!
64         sleep $sender_wait
65
66         echo "stopping sender $spid"
67         kill -15 $spid
68 }
69
70 function run_listener {
71         echo "starting listener"
72         $bin_dir/mc_listener $ext_hdr -r 1 -d $fifo_dir >/tmp/listen.log 2>&1 &
73         lpid=$!
74
75         sleep $listener_wait
76         echo "stopping listener $lpid"
77         kill -15 $lpid
78 }
79
80 # run a pipe reader for one message type
81 function run_pr {
82         echo "starting pipe reader $1  $max_flag"
83         set -x
84         $bin_dir/pipe_reader $ext_hdr $max_flag -m $1 -d $fifo_dir  >/tmp/pr.$1.log 2>&1 &
85         set +x
86         typeset prpid=$!
87
88         sleep $reader_wait
89         echo "stopping pipe reader $ppid"
90         kill -15 $prpid
91 }
92
93 # generate a dummy route table that the sender needs
94 function gen_rt {
95         cat <<endKat >/tmp/local.rt
96         newrt|start
97         mse | 0 | -1 | localhost:4560
98         mse | 1 | -1 | localhost:4560
99         mse | 2 | -1 | localhost:4560
100         mse | 3 | -1 | localhost:4560
101         mse | 4 | -1 | localhost:4560
102         mse | 5 | -1 | localhost:4560
103         mse | 6 | -1 | localhost:4560
104         mse | 7 | -1 | localhost:4560
105         mse | 8 | -1 | localhost:4560
106         mse | 9 | -1 | localhost:4560
107         newrt|end
108 endKat
109 }
110
111 # ---- run everything ---------------------------------------------------
112
113 si=""                                           # if -s given then we add this to sender/listener to run SI95 versions
114 ext_hdr=""                                      # run with extended header enabled (-e turns extended off)
115 long_test=0
116 raw_capture=1
117 verbose=0
118 while [[ $1 == -* ]]
119 do
120         case $1 in
121                 -l)     long_test=1;;
122                 -n)     raw_capture=0;;
123                 -s)     si="si_";;
124                 -v) verbose=1;;
125                 *)      echo "$1 is not a recognised option"
126                         exit 1
127                         ;;
128         esac
129
130         shift
131 done
132
133
134 if [[ -d /playpen/bin ]]        # designed to run in the container, but this allows unit test by jenkins to drive too
135 then
136         bin_dir=/playpen/${si}bin
137 else
138         bin_dir="."
139 fi
140
141 set_wait_values
142
143 if (( ! raw_capture ))          # -n set, turn off capture
144 then
145         export MCL_RDC_ENABLE=0
146 fi
147
148 if [[ -d /data/final ]]                 # assume if we find data that final directory goes here
149 then
150         echo "### found /data/final using that as final directory"
151         export MCL_RDC_FINAL=/data/final
152 fi
153
154 if [[ -d /data/stage ]]
155 then
156         echo "### found /data/staging using that as stage directory"
157         export MCL_RDC_STAGE=/data/stage
158 fi
159 final_dir=${MCL_RDC_FINAL:-/tmp/rdc/final}
160 stage_dir=${MCL_RDC_STAGE:-/tmp/rdc/stage}
161
162 fifo_dir=/tmp/fifos
163 mkdir -p $fifo_dir                      # redirect fifos so we don't depend on mount
164
165 gen_rt                                          # generate a dummy route table
166 run_listener &
167 sleep 4
168
169 # the sender will send types 0-8 inclusive; we only start 7 readers to
170 # endure listener doesn't hang on pipes without a reader
171 #
172 for p in 0 1 2 3 4 5
173 do
174         run_pr $p &                             # all but last have no max read
175 done
176 max_flag="-M 10"
177 run_pr 6 &
178
179 sleep 1                                         # let the readers settle
180 run_sender &
181
182 sleep $main_wait                        # long enough for all functions to finish w/o having to risk a wait hanging
183 echo "all functions stopped; looking at logs"
184
185 if (( verbose ))
186 then
187         echo "[INFO] ---- mc_lisener log follwos --------------------------"
188         cat /tmp/listen.log
189         echo "[INFO] ------------------------------------------------------"
190 fi
191
192
193 # ---------- validation -------------------------------------------------
194
195 errors=0
196
197 # logs should be > 0 in size
198 echo "----- logs ---------"
199 ls -al /tmp/*.log
200
201 # pipe reader log files 1-6 should have 'stand up and cheer' messages
202 # pipe reader log for MT 0 will likley be empty as sender sends only
203 # one of those and buffer not likely flushed. So, we only check 1-6
204 #
205 for l in 1 2 3 4 5 6
206 do
207         if [[ ! -s /tmp/pr.$l.log ]]
208         then
209                 echo "[FAIL] log $l was empty"
210                 (( errors++ ))
211         else
212                 if ! grep -q -i "stand up and cheer" /tmp/pr.$l.log
213                 then
214                         echo "[FAIL] pipe reader log did not have any valid messages: /tmp/pr.$l.log"
215                         (( errors++ ))
216                 fi
217         fi
218 done
219
220 if (( ! errors ))
221 then
222         echo "[OK]    All logs seem good"
223 fi
224
225 nfifos=$( ls /tmp/fifos/MT_* | wc -l )
226 if (( nfifos < 7 ))
227 then
228         echo "didn't find enough fifos"
229         ls -al /tmp/fifos/*
230         (( errors++ ))
231 else
232         echo "[OK]    Found expected fifos"
233 fi
234
235 if (( raw_capture ))            # not an error if not capturing
236 then
237         if [[ -d $stage_dir ]]
238         then
239                 echo "[OK]    Found staging direcory ($stage_dir)"
240                 ls -al $stage_dir
241         else
242                 (( errors++ ))
243                 echo "[FAIL]  No staging directory found ($stage_dir)"
244         fi
245
246
247         if [[ -d $final_dir ]]
248         then
249                 echo "[OK]    Found final direcory ($final_dir)"
250                 ls -al $final_dir
251
252                 if (( long_test ))              # look for files in final dir to ensure roll
253                 then
254                         found=$( ls $final_dir/MC* | wc -l )
255                         if (( found > 0 ))
256                         then
257                                 echo "[OK]   Found $found files in final directory ($final_dir)"
258                         else
259                                 echo "[FAIL] Did not find any files in the final directory ($final_dir)"
260                                 (( errors++ ))
261                         fi
262                 fi
263         else
264                 (( errors++ ))
265                 echo "[FAIL]  No final directory found"
266         fi
267 fi
268
269 if (( errors ))
270 then
271         echo "[FAIL] $errors errors noticed"
272 else
273         echo "[PASS]"
274 fi
275