Fix CMake to reference unit test in correct dir
[ric-app/mc.git] / 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 # set the various sleep values based on long test or short test
36 function set_wait_values {
37         if (( long_test ))
38         then
39                 export MCL_RDC_FREQ=13          # file cycle after 13s
40                 sender_wait=100
41                 listener_wait=105
42                 reader_wait=102
43                 main_wait=120
44         else
45                 sender_wait=10
46                 listener_wait=15
47                 reader_wait=12
48                 main_wait=20
49         fi
50 }
51
52 # run sender at a 2 msg/sec rate (500000 musec delay)
53 # sender sends msg types 0-6 and the route table in /tmp
54 # will direct them to the listener. We also need to switch
55 # the RT listen port so there is no collision with the listen
56 # preocess.
57 #
58 function run_sender {
59         echo "starting sender"
60         RMR_SEED_RT=/tmp/local.rt RMR_RTG_SVC=9989 /playpen/${si}bin/sender 43086 10000 >/tmp/sender.log 2>&1 &
61         spid=$!
62         sleep $sender_wait
63
64         echo "stopping sender"
65         kill -15 $spid
66 }
67
68 function run_listener {
69         echo "starting listener"
70         /playpen/${si}bin/mc_listener $ext_hdr -r 1 -d $fifo_dir >/tmp/listen.log 2>&1 &
71         lpid=$!
72
73         sleep $listener_wait
74         echo "stopping listener"
75         kill -15 $lpid
76 }
77
78 # run a pipe reader for one message type
79 function run_pr {
80         echo "starting pipe reader $1"
81         /playpen/bin/pipe_reader $ext_hdr -m $1 -d $fifo_dir  >/tmp/pr.$1.log 2>&1 &
82         #/playpen/bin/pipe_reader -m $1 -d $fifo_dir & # >/tmp/pr.$1.log 2>&1 
83         typeset prpid=$!
84         
85         sleep $reader_wait
86         echo "stopping pipe reader $1"
87         kill -1 $prpid
88 }
89
90 # generate a dummy route table that the sender needs
91 function gen_rt {
92         cat <<endKat >/tmp/local.rt
93         newrt|start
94         mse | 0 | -1 | localhost:4560   
95         mse | 1 | -1 | localhost:4560   
96         mse | 2 | -1 | localhost:4560   
97         mse | 3 | -1 | localhost:4560   
98         mse | 4 | -1 | localhost:4560   
99         mse | 5 | -1 | localhost:4560   
100         mse | 6 | -1 | localhost:4560   
101         newrt|end
102 endKat
103 }
104
105 # ---- run everything ---------------------------------------------------
106
107 si=""                                           # if -s given then we add this to sender/listener to run SI95 versions
108 ext_hdr=""                                      # run with extended header enabled (-e turns extended off)
109 long_test=0
110 raw_capture=1
111 while [[ $1 == -* ]]
112 do
113         case $1 in 
114                 -l)     long_test=1;;
115                 -n)     raw_capture=0;;
116                 -s)     si="si_";;
117                 *)      echo "$1 is not a recognised option"
118                         exit 1
119                         ;;
120         esac
121
122         shift
123 done
124
125 set_wait_values
126
127 if (( ! raw_capture ))          # -n set, turn off capture
128 then
129         export MCL_RDC_ENABLE=0
130 fi
131
132 if [[ -d /data/final ]]                 # assume if we find data that final directory goes here
133 then
134         echo "### found /data/final using that as final directory"
135         export MCL_RDC_FINAL=/data/final
136 fi
137
138 if [[ -d /data/stage ]]
139 then
140         echo "### found /data/staging using that as stage directory"
141         export MCL_RDC_STAGE=/data/stage
142 fi
143 final_dir=${MCL_RDC_FINAL:-/tmp/rdc/final}
144 stage_dir=${MCL_RDC_STAGE:-/tmp/rdc/stage}
145
146 fifo_dir=/tmp/fifos
147 mkdir -p $fifo_dir                      # redirect fifos so we don't depend on mount
148
149 gen_rt                                          # generate a dummy route table
150 run_listener &
151 sleep 4
152
153 for p in 0 1 2 3 4 5 6
154 do
155         run_pr $p &
156 done
157 sleep 1
158 run_sender &
159
160 sleep $main_wait                        # long enough for all functions to finish w/o having to risk a wait hanging
161 echo "all functions stopped; looking at logs"
162
163 # ---------- validation -------------------------------------------------
164
165 errors=0
166
167 # logs should be > 0 in size
168 echo "----- logs ---------"
169 ls -al /tmp/*.log
170
171 # pipe reader log files 1-6 should have 'stand up and cheer' messages
172 # pipe reader log for MT 0 will likley be empty as sender sends only
173 # one of those and buffer not likely flushed. So, we only check 1-6
174 #
175 for l in 1 2 3 4 5 6
176 do
177         if [[ ! -s /tmp/pr.$l.log ]]
178         then
179                 echo "[FAIL] log $l was empty"
180                 (( errors++ ))
181         else
182                 if ! grep -q -i "stand up and cheer" /tmp/pr.$l.log
183                 then
184                         echo "[FAIL] pipe reader log did not have any valid messages: /tmp/pr.$l.log"
185                         (( errors++ ))
186                 fi
187         fi
188 done
189
190 if (( ! errors )) 
191 then
192         echo "[OK]    All logs seem good"
193 fi
194
195 nfifos=$( ls /tmp/fifos/MT_* | wc -l )
196 if (( nfifos < 7 ))
197 then
198         echo "didn't find enough fifos"
199         ls -al /tmp/fifos/*
200         (( errors++ ))
201 else
202         echo "[OK]    Found expected fifos"
203 fi
204
205 if (( raw_capture ))            # not an error if not capturing
206 then
207         if [[ -d $stage_dir ]]
208         then
209                 echo "[OK]    Found staging direcory ($stage_dir)"
210                 ls -al $stage_dir
211         else
212                 (( errors++ ))
213                 echo "[FAIL]  No staging directory found ($stage_dir)"
214         fi
215
216
217         if [[ -d $final_dir ]]
218         then
219                 echo "[OK]    Found final direcory ($final_dir)"
220                 ls -al $final_dir
221         
222                 if (( long_test ))              # look for files in final dir to ensure roll
223                 then
224                         found=$( ls $final_dir/MC* | wc -l )
225                         if (( found > 0 ))
226                         then
227                                 echo "[OK]   Found $found files in final directory ($final_dir)"
228                         else
229                                 echo "[FAIL] Did not find any files in the final directory ($final_dir)"
230                                 (( errors++ ))
231                         fi
232                 fi
233         else
234                 (( errors++ ))
235                 echo "[FAIL]  No final directory found"
236         fi
237 fi
238
239 if (( errors ))
240 then
241         echo "[FAIL] $errors errors noticed"
242 else
243         echo "[PASS]"
244 fi
245