-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathptest.sh
More file actions
executable file
·240 lines (198 loc) · 7.56 KB
/
Copy pathptest.sh
File metadata and controls
executable file
·240 lines (198 loc) · 7.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/env bash
# source /home/kevin/Downloads/spy/errorhandle
# lock prevents multiple executing copies
# doug.py doesn't do the lock though (can have multiple doug.py)
# will pkill any other doug.py below
# source /home/kevin/Downloads/scrp/lock_setup.sh LOCK1
# wait with timeout
# source /home/kevin/try_wait.sh
TYPE="HOT"
TYPE="WARM"
TYPE="COLD"
PORT_A="0"
PORT_B="3"
EXITCODE=0
ls "/dev/ttyACM${PORT_A}" || EXITCODE=$?
EXITCODE=0
ls "/dev/ttyACM${PORT_B}" || EXITCODE=$?
echo "EXITCODE $EXITCODE"
if [ $EXITCODE -eq 0 ] ; then
SINGLE=0
else
SINGLE=1
fi
echo "SINGLE $SINGLE"
#*********************************************
# parallel test to acm0 and acm1
DATE_HMS=$(date +%m_%d_%y-%R)
TDIR="ptest_$DATE_HMS"
rm -f -r $TDIR
mkdir -p $TDIR
echo "Will copy results to $TDIR"
start_time=$(($(date +%s%N)/1000000))
pkill -f 'python3 /home/kevin/doug.py' || true
rm -f all0.txt
rm -f all1.txt
rm -f hist0.txt
rm -f hist1.txt
rm -f ptest.log
#*****************
function check_stdout_stderr {
# arg1 should be the file
# catch python exceptions
# does this catch sys.exit(1) due to timeout? I guess don't stop on errors?
# should we sys.exit(0) on timeout?
SH_FAILED=0
echo "will now look at the stdout/stderr file $1"
if [ ! -s $1 ] ; then
echo ""
echo "ERROR: missing or empty ftc_sh file $1"
SH_FAILED=1
else
# ignore repError and ackError
lines=$(egrep -c '^Error| Error|Exception' $1) || true
if [ $lines -ne 0 ] ; then
egrep '^Error| Error|Exception' $1
SH_FAILED=1
fi
fi
}
#*****************
for trials in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
start_time1=$(($(date +%s%N)/1000000))
echo ""
echo "Doing trials $trials"
echo ""
rm -f hw_test_${PORT_A}.txt all_lines_${PORT_A}.txt
rm -f hw_test_${PORT_B}.txt all_lines_${PORT_B}.txt
rm -f hw_test_${PORT_A}*.txt all_lines_${PORT_A}*.txt
rm -f hw_test_${PORT_B}*.txt all_lines_${PORT_B}*.txt
touch hw_test_${PORT_A}.txt
touch all_lines_${PORT_A}.txt
rm -f temp.doug_${PORT_A}.txt
if [ $SINGLE -ne 1 ] ; then
touch hw_test_${PORT_B}.txt
touch all_lines_${PORT_B}.txt
rm -f temp.doug_${PORT_B}.txt
fi
if [ $trials -le 1 ] ; then
echo "python3 /home/kevin/doug.py $PORT_A SINGLE_FIX RESET $TYPE > temp.doug_${PORT_A}.txt 2<&1 &"
python3 /home/kevin/doug.py $PORT_A SINGLE_FIX RESET $TYPE > temp.doug_${PORT_A}.txt 2<&1 &
if [ $SINGLE -ne 1 ] ; then
echo "python3 /home/kevin/doug.py $PORT_B SINGLE_FIX RESET $TYPE > temp.doug_${PORT_B}.txt 2<&1 &"
python3 /home/kevin/doug.py $PORT_B SINGLE_FIX RESET $TYPE > temp.doug_${PORT_B}.txt 2<&1 &
fi
else
echo "python3 /home/kevin/doug.py $PORT_A SINGLE_FIX NO_RESET $TYPE > temp.doug_${PORT_A}.txt 2<&1 &"
python3 /home/kevin/doug.py $PORT_A SINGLE_FIX NO_RESET $TYPE > temp.doug_${PORT_A}.txt 2<&1 &
if [ $SINGLE -ne 1 ] ; then
echo "python3 /home/kevin/doug.py $PORT_B SINGLE_FIX NO_RESET $TYPE > temp.doug_${PORT_B}.txt 2<&1 &"
python3 /home/kevin/doug.py $PORT_B SINGLE_FIX NO_RESET $TYPE > temp.doug_${PORT_B}.txt 2<&1 &
fi
fi
# try_wait %1 && echo 'PASS: First background pid %1 exited normally' || echo 'ERROR: First background pid %1 timeout'
# try_wait %2 && echo 'PASS: Second background pid %2 exited normally' || echo 'ERROR: Second background pid %2 timeout'
#***********
wait
# make sure all files have flushed out (stdout) so we can grep?
sleep 2
echo ""
echo "can debug with temp.doug_${PORT_A}.txt and temp.doug_${PORT_B}.txt stdout for this trial (stdout and stderr)"
echo ""
check_stdout_stderr temp.doug_${PORT_A}.txt
if [ $SH_FAILED -eq 1 ] ; then
echo "ERROR: unexpected Error|Exception in python looking at temp.doug_${PORT_A}.txt"
exit 1
fi
if [ $SINGLE -ne 1 ] ; then
check_stdout_stderr temp.doug_${PORT_B}.txt
if [ $SH_FAILED -eq 1 ] ; then
echo "ERROR: unexpected Error|Exception in python looking at temp.doug_${PORT_B}.txt"
exit 1
fi
fi
#***********
echo "ACM${PORT_A}"
# will error out of not found?
lines=$(egrep -c 'gpsFixFound|gpsFixTimeout' hw_test_${PORT_A}.txt) || true
if [[ "$lines" != "1" ]] ; then
echo "ERROR: lines $lines didn't find exactly one gpsFixFound|gpsFixTimeout in hw_test_${PORT_A}.txt"
egrep 'gpsFixFound|gpsFixTimeout' hw_test_${PORT_A}.txt || true
exit 1
fi
egrep 'gpsFixFound|gpsFixTimeout' hw_test_${PORT_A}.txt || true
egrep 'gpsFixFound|gpsFixTimeout' hw_test_${PORT_A}.txt | awk -v trials=$trials '{print "trial", trials, $0}' >> all0.txt || true
ls -ltr hw_test_${PORT_A}.txt all_lines_${PORT_A}.txt
wc -l hw_test_${PORT_A}.txt all_lines_${PORT_A}.txt
#***********
if [ $SINGLE -ne 1 ] ; then
echo "ACM${PORT_B}"
# will error out of not found?
lines=$(egrep -c 'gpsFixFound|gpsFixTimeout' hw_test_${PORT_B}.txt) || true
if [[ "$lines" != "1" ]] ; then
echo "ERROR: lines $lines didn't find exactly one gpsFixFound|gpsFixTimeout in hw_test_${PORT_B}.txt"
egrep 'gpsFixFound|gpsFixTimeout' hw_test_${PORT_B}.txt || true
exit 1
fi
egrep 'gpsFixFound|gpsFixTimeout' hw_test_${PORT_B}.txt || true
egrep 'gpsFixFound|gpsFixTimeout' hw_test_${PORT_B}.txt | awk -v trials=$trials '{print "trial", trials, $0}' >> all1.txt || true
ls -ltr hw_test_${PORT_B}.txt all_lines_${PORT_B}.txt
wc -l hw_test_${PORT_B}.txt all_lines_${PORT_B}.txt
fi
#***********
# save the per-trial stuff in case of debug
cp -p hw_test_${PORT_A}.txt hw_test_${PORT_A}_${trials}.txt
cp -p all_lines_${PORT_A}.txt all_lines_${PORT_A}_${trials}.txt
if [ $SINGLE -ne 1 ] ; then
cp -p hw_test_${PORT_B}.txt hw_test_${PORT_B}_${trials}.txt
cp -p all_lines_${PORT_B}.txt all_lines_${PORT_B}_${trials}.txt
fi
# so we can debug bad iterations while test is running
for f in all[0-1].txt hw_test_[01]*.txt hw_test_[01].txt all_lines_[01]*.txt all_lines_[01].txt temp.doug_[01].txt ; do
cp -p $f $TDIR || true
done
#***********
end_time1=$(($(date +%s%N)/1000000))
(( elapsed_time1 = end_time1 - start_time1 )) || true
awk -v MILLI=$elapsed_time1 'BEGIN {printf("trial elapsed time (seconds) %.3f\n", MILLI/1000)}'
#***********
done
#****************************
echo ""
echo "All done!"
echo ""
ls -ltr all0.txt
wc -l all0.txt
# get rid of the first field
sed -i -e 's!FIX_${PORT_B} !!' all0.txt
if [ $SINGLE -ne 1 ] ; then
ls -ltr all1.txt
wc -l all1.txt
sed -i -e 's!FIX_${PORT_B} !!' all1.txt
fi
#****************************
echo ""
# use firstLockDuration NF field
# my TTFF_elapsedTime is NF-1 field
if [ -s all0.txt ] ; then
echo "stats on ACM0 TTFF_elapsedTime (dipole)"
awk '{print $(NF)}' all0.txt | /usr/local/bin/histogram3.py > hist0.txt
cat hist0.txt
fi
if [ -s all1.txt ] ; then
echo ""
echo "stats on ACMD1 TTFF_elapsedTime (monopole)"
awk '{print $(NF)}' all1.txt | /usr/local/bin/histogram3.py > hist1.txt
cat hist1.txt
fi
#****************************
echo ""
end_time=$(($(date +%s%N)/1000000))
(( elapsed_time = end_time - start_time )) || true
awk -v MILLI=$elapsed_time 'BEGIN {printf("Total elapsed time (seconds) %.3f\n", MILLI/1000)}' > ptest.log
cat ptest.log
#****************************
for f in all[0-1].txt hw_test_[01]*.txt hw_test_[01].txt all_lines_[01]*.txt all_lines_[01].txt temp.doug_[01].txt hist[01].txt ptest.log ; do
cp -p $f $TDIR || true
done
#****************************