Fix CMake to reference unit test in correct dir
[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
44         set -x
45         /playpen/bin/rdc_replay -f $file -d $fifo_dir >/tmp/replay.log 2>&1
46         lpid=$!
47         set +x
48         echo "replay finished"
49 }
50
51 # run a pipe reader for one message type
52 function run_pr {
53         echo "starting pipe reader $1"
54         /playpen/bin/pipe_reader $ext_hdr -m $1 -d $fifo_dir  >/tmp/pr.$1.log 2>&1 &
55         #/playpen/bin/pipe_reader -m $1 -d $fifo_dir & # >/tmp/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 ext_hdr=""                                      # run with extended header enabled (-e turns extended off)
66 run_listener=0                          # -a turns on to run all
67 while [[ $1 == -* ]]
68 do
69         case $1 in 
70                 -a)     run_listener=1;;
71                 *)      echo "$1 is not a recognised option"
72                         echo "usage: $0 [-a]"
73                         echo "-a will cause the listener verification to run which generates files for this script"
74                         exit 1
75                         ;;
76         esac
77
78         shift
79 done
80
81 if (( run_listener ))
82 then
83         echo "running listener to generate test files to replay..."
84         set -e
85         verify.sh                               # assumed to be in the path
86         set +e
87 fi
88
89 set_wait_values
90
91 if (( ! raw_capture ))          # -n set, turn off capture
92 then
93         export MCL_RDC_ENABLE=0
94 fi
95
96 if [[ -d /data/final ]]                 # assume if we find data that final directory goes here
97 then
98         echo "### found /data/final using that as final directory"
99         export MCL_RDC_FINAL=/data/final
100 fi
101
102 stage_dir=${MCL_RDC_STAGE:-/tmp/rdc/stage}
103 if [[ ! -d $stage_dir ]]
104 then
105         echo "abort: cannot find stage directory to replay from: $stage_dir"
106         exit 1
107 fi
108
109 fifo_dir=/tmp/fifos
110 if [[ ! -d $fifo_dir ]]
111 then
112         mkdir -p $fifo_dir                      # redirect fifos so we don't depend on mount
113 fi
114
115
116 for p in 0 1 2 3 4 5 6
117 do
118         run_pr $p &
119 done
120
121 sleep 2
122 run_replay &                             # start after readers are going
123
124 sleep $main_wait                        # long enough for all functions to finish w/o having to risk a wait hanging
125 echo "all functions stopped; looking at logs"
126
127 # ---------- validation -------------------------------------------------
128
129 errors=0
130
131 # logs should be > 0 in size
132 echo "----- logs ---------"
133 ls -al /tmp/*.log
134
135 # pipe reader log files 1-6 should have 'stand up and cheer' messages
136 # pipe reader log for MT 0 will likley be empty as sender sends only
137 # one of those and buffer not likely flushed. So, we only check 1-6
138 #
139 for l in 1 2 3 4 5 6
140 do
141         if [[ ! -s /tmp/pr.$l.log ]]
142         then
143                 echo "[FAIL] log $l was empty"
144                 (( errors++ ))
145         else
146                 if ! grep -q -i "stand up and cheer" /tmp/pr.$l.log
147                 then
148                         echo "[FAIL] pipe reader log did not have any valid messages: /tmp/pr.$l.log"
149                         (( errors++ ))
150                 fi
151         fi
152 done
153
154 if (( ! errors )) 
155 then
156         echo "[OK]    All logs seem good"
157 fi
158
159 nfifos=$( ls /tmp/fifos/MT_* | wc -l )
160 if (( nfifos < 7 ))
161 then
162         echo "didn't find enough fifos"
163         ls -al /tmp/fifos/*
164         (( errors++ ))
165 else
166         echo "[OK]    Found expected fifos"
167 fi
168
169 if (( errors ))
170 then
171         echo "[FAIL] $errors errors noticed"
172 else
173         echo "[PASS]"
174 fi
175