5acefc67e732b0e3a763913d053971b22795706f
[ric-app/mc.git] / sidecars / listener / src / verify_replay.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_replay.sh
24 # Abstract: Simple script to attempt to verify that the replay utility
25 #                       works as expected. This assumes that verify.sh has been run
26 #                       and that at least one RDC file is in /tmp/rdc. This script
27 #                       will start the replay utility and a few pipe listeners to
28 #                       parse the data.
29 #
30 # Date:         19 November 2019
31 # Author:       E. Scott Daniels
32 # ----------------------------------------------------------------------
33
34 # set the various sleep values based on long test or short test
35 function set_wait_values {
36         reader_wait=12
37         main_wait=20
38 }
39
40 function run_replay {
41         echo "starting replayer"
42         file=$( ls ${stage_dir}/MCLT_*|head -1 )
43         chmod 644 $file
44
45         set -x
46         $bin_dir/rdc_replay -f $file -d $fifo_dir >$log_dir/replay.log 2>&1
47         lpid=$!
48         set +x
49         echo "replay finished"
50 }
51
52 # run a pipe reader for one message type
53 function run_pr {
54         echo "starting pipe reader $1"
55         $bin_dir/pipe_reader $ext_hdr -m $1 -d $fifo_dir  >$log_dir/pr.$1.log 2>&1 &
56         typeset prpid=$!
57
58         sleep $reader_wait
59         echo "stopping pipe reader $1"
60         kill -1 $prpid
61 }
62
63 # ---- run everything ---------------------------------------------------
64
65 log_dir=/tmp/mcl_verify
66 mkdir -p $log_dir
67
68 ext_hdr=""                                      # run with extended header enabled (-e turns extended off)
69 run_listener=0                          # -a turns on to run all
70 while [[ $1 == -* ]]
71 do
72         case $1 in
73                 -a)     run_listener=1;;
74                 *)      echo "$1 is not a recognised option"
75                         echo "usage: $0 [-a]"
76                         echo "-a will cause the listener verification to run which generates files for this script"
77                         exit 1
78                         ;;
79         esac
80
81         shift
82 done
83
84 if [[ -d /playpen/bin ]]        # designed to run in the container, but this allows unit test by jenkins to drive too
85 then
86         bin_dir=/playpen/${si}bin
87 else
88         bin_dir="."
89 fi
90
91 if (( run_listener ))
92 then
93         echo "running listener to generate test files to replay..."
94         set -e
95         verify.sh                               # assumed to be in the path
96         set +e
97 fi
98
99 set_wait_values
100
101 if (( ! raw_capture ))          # -n set, turn off capture
102 then
103         export MCL_RDC_ENABLE=0
104 fi
105
106 if [[ -d /data/final ]]                 # assume if we find data that final directory goes here
107 then
108         echo "### found /data/final using that as final directory"
109         export MCL_RDC_FINAL=/data/final
110 fi
111
112 stage_dir=${MCL_RDC_STAGE:-/tmp/rdc/stage}
113 if [[ ! -d $stage_dir ]]
114 then
115         echo "abort: cannot find stage directory to replay from: $stage_dir"
116         exit 1
117 fi
118
119 fifo_dir=/tmp/fifos
120 if [[ ! -d $fifo_dir ]]
121 then
122         mkdir -p $fifo_dir                      # redirect fifos so we don't depend on mount
123 fi
124
125
126 for p in 0 1 2 3 4 5 6
127 do
128         run_pr $p &
129 done
130
131 sleep 2
132 run_replay &                             # start after readers are going
133
134 sleep $main_wait                        # long enough for all functions to finish w/o having to risk a wait hanging
135 echo "all functions stopped; looking at logs"
136
137 # ---------- validation -------------------------------------------------
138
139 errors=0
140
141 # logs should be > 0 in size
142 echo "----- logs ---------"
143 ls -al $log_dir/*.log
144
145 # pipe reader log files 1-6 should have 'stand up and cheer' messages
146 # pipe reader log for MT 0 will likley be empty as sender sends only
147 # one of those and buffer not likely flushed. So, we only check 1-6
148 #
149 for l in 1 2 3 4 5 6
150 do
151         if [[ ! -s $log_dir/pr.$l.log ]]
152         then
153                 echo "[FAIL] log $l was empty"
154                 (( errors++ ))
155         else
156                 if ! grep -q -i "stand up and cheer" $log_dir/pr.$l.log
157                 then
158                         echo "[FAIL] pipe reader log did not have any valid messages: $log_dir/pr.$l.log"
159                         (( errors++ ))
160                 fi
161         fi
162 done
163
164 if (( ! errors ))
165 then
166         echo "[OK]    All logs seem good"
167 fi
168
169 nfifos=$( ls /tmp/fifos/MT_* | wc -l )
170 if (( nfifos < 7 ))
171 then
172         echo "didn't find enough fifos"
173         ls -al /tmp/fifos/*
174         (( errors++ ))
175 else
176         echo "[OK]    Found expected fifos"
177 fi
178
179 if (( errors ))
180 then
181         echo "[FAIL] $errors errors noticed"
182 else
183         echo "[PASS]"
184 fi
185