e293d4936390630c4e4325f770593d76de7eb16a
[ric-app/mc.git] / src / sidecars / listener / 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.
30 #
31 # Date:         26 August 2019
32 # Author:       E. Scott Daniels
33 # ----------------------------------------------------------------------
34
35 # run sender at a 2 msg/sec rate (500000 musec delay)
36 # sender sends msg types 0-6 and the route table in /tmp
37 # will direct them to the listener. We also need to switch
38 # the RT listen port so there is no collision with the listen
39 # preocess.
40 #
41 function run_sender {
42         echo "starting sender"
43         RMR_SEED_RT=/tmp/local.rt RMR_RTG_SVC=9989 /playpen/bin/sender 43086 10000 >/tmp/sender.log 2>&1 &
44         spid=$!
45         sleep 10
46
47         echo "stopping sender"
48         kill -15 $spid
49 }
50
51 function run_listener {
52         echo "starting listener"
53         /playpen/bin/mc_listener $ext_hdr -r 1 -d $fifo_dir >/tmp/listen.log 2>&1 &
54         lpid=$!
55
56         sleep 15
57         echo "stopping listener"
58         kill -15 $lpid
59 }
60
61 # run a pipe reader for one message type
62 function run_pr {
63         echo "starting pipe reader $1"
64         /playpen/bin/pipe_reader $ext_hdr -m $1 -d $fifo_dir  >/tmp/pr.$1.log 2>&1 &
65         #/playpen/bin/pipe_reader -m $1 -d $fifo_dir & # >/tmp/pr.$1.log 2>&1 
66         typeset prpid=$!
67         
68         sleep 12
69         echo "stopping pipe reader $1"
70         kill -1 $prpid
71 }
72
73 # generate a dummy route table that the sender needs
74 function gen_rt {
75         cat <<endKat >/tmp/local.rt
76         newrt|start
77         mse | 0 | -1 | localhost:4560   
78         mse | 1 | -1 | localhost:4560   
79         mse | 2 | -1 | localhost:4560   
80         mse | 3 | -1 | localhost:4560   
81         mse | 4 | -1 | localhost:4560   
82         mse | 5 | -1 | localhost:4560   
83         mse | 6 | -1 | localhost:4560   
84         newrt|end
85 endKat
86 }
87
88 # ---- run everything ---------------------------------------------------
89
90 ext_hdr=""                                      # run with extended header enabled (-e turns extended off)
91 fifo_dir=/tmp/fifos
92 mkdir -p $fifo_dir                      # redirect fifos so we don't depend on mount
93
94 gen_rt                                          # generate a dummy route table
95 run_listener &
96 sleep 4
97
98 for p in 0 1 2 3 4 5 6
99 do
100         run_pr $p &
101 done
102 sleep 1
103 run_sender &
104
105 sleep 20                        # long enough for all functions to finish w/o having to risk a wait hanging
106 echo "all functions stopped; looking at logs"
107
108 # ---------- validation -------------------------------------------------
109
110 errors=0
111
112 # logs should be > 0 in size
113 echo "----- logs ---------"
114 ls -al /tmp/*.log
115
116 # pipe reader log files 1-6 should have 'stand up and cheer' messages
117 # pipe reader log for MT 0 will likley be empty as sender sends only
118 # one of those and buffer not likely flushed. So, we only check 1-6
119 #
120 for l in 1 2 3 4 5 6
121 do
122         if [[ ! -s /tmp/pr.$l.log ]]
123         then
124                 echo "[FAIL] log $l was empty"
125                 (( errors++ ))
126         else
127                 if ! grep -q -i "stand up and cheer" /tmp/pr.$l.log
128                 then
129                         echo "[FAIL] pipe reader log did not have any valid messages: /tmp/pr.$l.log"
130                         (( errors++ ))
131                 fi
132         fi
133 done
134
135 if (( ! errors )) 
136 then
137         echo "[OK]    All logs seem good"
138 fi
139
140 nfifos=$( ls /tmp/fifos/MT_* | wc -l )
141 if (( nfifos < 7 ))
142 then
143         echo "didn't find enough fifos"
144         ls -al /tmp/fifos/*
145         (( errors++ ))
146 else
147         echo "[OK]    Found expected fifos"
148 fi
149
150 if (( errors ))
151 then
152         echo "[FAIL] $errors errors noticed"
153 else
154         echo "[PASS]"
155 fi
156