-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute_tests.sh
More file actions
executable file
·630 lines (412 loc) · 10.9 KB
/
execute_tests.sh
File metadata and controls
executable file
·630 lines (412 loc) · 10.9 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
#!/bin/bash
#-------------------------------------USER CONFIGURATION---------------------------------------------
# FAULTYDIR: the path of the directory in which the faulty executables are stored
# SAVEDIR: the path of the directory in which the test results will be stored
# BINARY: the path of the binary executable which has to be replaced by a faulty executable
# TEST: the command to be executed to run a test (e.g., "./run_workload.sh param1 param2")
# FAULTLIST: the path of the file with the list of faults which have been "injected". Each line
# of this file is the identifier of an individual faulty version (i.e., the name of the binary faulty
# file without the "programname_" prefix and the ".diff" suffix)
# TIMEOUT: it is the maximum allowed execution time for an experiment (in seconds)
export FAULTYDIR
export SAVEDIR
export BINARY
export TEST
export FAULTLIST
export TIMEOUT
export OUTPUTS
case "$1" in
# --- ASTAR ---
"astar")
BINARY="astar"
FAULTYDIR="/Faults/$BINARY"
SAVEDIR="/Results/$BINARY"
WORKDIR="/workdir/$BINARY"
TEST="/workdir/dump.sh $BINARY $WORKDIR"
FAULTLIST="/Lists/$BINARY-list.txt"
OUTPUTS=()
TIMEOUT=180
;;
# --- BZIP2 ---
"bzip2")
BINARY="bzip2"
FAULTYDIR="/Faults/$BINARY"
SAVEDIR="/Results/$BINARY"
WORKDIR="/workdir/$BINARY"
TEST="/workdir/dump.sh $BINARY $WORKDIR"
FAULTLIST="/Lists/$BINARY-list.txt"
OUTPUTS=()
TIMEOUT=180
;;
# --- GOBMK ---
"gobmk")
BINARY="gobmk"
FAULTYDIR="/Faults/$BINARY"
SAVEDIR="/Results/$BINARY"
WORKDIR="/workdir/$BINARY"
TEST="/workdir/dump.sh $BINARY $WORKDIR"
FAULTLIST="/Lists/$BINARY-list.txt"
OUTPUTS=()
TIMEOUT=240
;;
# --- H264REF ---
"h264ref")
BINARY="h264ref"
FAULTYDIR="/Faults/$BINARY"
SAVEDIR="/Results/$BINARY"
WORKDIR="/workdir/$BINARY"
TEST="/workdir/dump.sh $BINARY $WORKDIR"
FAULTLIST="/Lists/$BINARY-list.txt"
OUTPUTS=("foreman_qcif.264" "foreman_test_baseline_leakybucketparam.cfg")
TIMEOUT=65
;;
# --- HMMER ---
"hmmer")
BINARY="hmmer"
FAULTYDIR="/Faults/$BINARY"
SAVEDIR="/Results/$BINARY"
WORKDIR="/workdir/$BINARY"
TEST="/workdir/dump.sh $BINARY $WORKDIR"
FAULTLIST="/Lists/$BINARY-list.txt"
OUTPUTS=()
TIMEOUT=70
;;
# --- LIBQUANTUM ---
"libquantum")
BINARY="libquantum"
FAULTYDIR="/Faults/$BINARY"
SAVEDIR="/Results/$BINARY"
WORKDIR="/workdir/$BINARY"
TEST="/workdir/dump.sh $BINARY $WORKDIR"
FAULTLIST="/Lists/$BINARY-list.txt"
OUTPUTS=()
TIMEOUT=10
;;
# --- MCF ---
"mcf")
BINARY="mcf"
FAULTYDIR="/Faults/$BINARY"
SAVEDIR="/Results/$BINARY"
WORKDIR="/workdir/$BINARY"
TEST="/workdir/dump.sh $BINARY $WORKDIR"
FAULTLIST="/Lists/$BINARY-list.txt"
OUTPUTS=("mcf.out")
TIMEOUT=90
;;
# --- OMNETPP ---
"omnetpp")
BINARY="omnetpp"
FAULTYDIR="/Faults/$BINARY"
SAVEDIR="/Results/$BINARY"
WORKDIR="/workdir/$BINARY"
TEST="/workdir/dump.sh $BINARY $WORKDIR"
FAULTLIST="/Lists/$BINARY-list.txt"
OUTPUTS=("omnetpp.sca")
TIMEOUT=180
;;
# --- SJENG ---
"sjeng")
BINARY="sjeng"
FAULTYDIR="/Faults/$BINARY"
SAVEDIR="/Results/$BINARY"
WORKDIR="/workdir/$BINARY"
TEST="/workdir/dump.sh $BINARY $WORKDIR"
FAULTLIST="/Lists/$BINARY-list.txt"
OUTPUTS=()
TIMEOUT=60
;;
# --- XALAN ---
"xalan")
BINARY="xalan"
FAULTYDIR="/Faults/$BINARY"
SAVEDIR="/Results/$BINARY"
WORKDIR="/workdir/$BINARY"
TEST="/workdir/dump.sh $BINARY $WORKDIR"
FAULTLIST="/Lists/$BINARY-list.txt"
#OUTPUTS=()
OUTPUTS=("test.html")
TIMEOUT=360
;;
*)
echo "Usage: $0 <program name> [fault list]"
exit 1
;;
esac
if [ "x$2" != "x" ]
then
if [ -f $2 ]
then
FAULTLIST=$2
else
echo "Fault list '$2' not found"
exit 1
fi
fi
# The "handle_timeout()" function has to be adapted to kill the test after a timeout is expired
handle_timeout() {
echo
echo "----------- Test Timeout (Forced exit) ------------"
echo
while [ 1 ]
do
ps aux | grep -P "gdb" | grep -v "\.sh" | grep -v grep | awk '{print $2}' | xargs rkill -9 > /dev/null 2>&1
if [ $? -ne 0 ]
then
ZOMBIES=`ps aux | grep -P "gdb" | grep -v "\.sh" | grep -v grep | wc -l`
if [ $ZOMBIES -eq 0 ]
then
echo "No process to kill"
return 0
else
echo "Kill failed; retrying..."
sleep 5
fi
else
return 0
fi
sleep 1
done
}
# The "clear_testbed()" function has to be adapted to clear the testbed before an experiment
# (e.g., remove old log file, deallocate stale resources)
clear_testbed() {
sync
while [ 1 ]
do
ps aux | grep "gdb" | grep -v "\.sh" | grep -v grep | awk '{print $2}' | xargs rkill -9 >/dev/null 2>&1
if [ $? -ne 0 ]
then
ZOMBIES=`ps aux | grep -P "gdb" | grep -v "\.sh" | grep -v grep | wc -l`
if [ $ZOMBIES -eq 0 ]
then
echo "No process to kill"
break
else
echo "Kill failed; retrying..."
sleep 5
fi
else
break
fi
sleep 1
done
rm -f $WORKDIR/mtrace.out
rm -f $WORKDIR/breakpoints.gdb
rm -f $WORKDIR/dump.txt
/bin/ls $WORKDIR/ | grep ".dump" | xargs rm -f
rm -f $STDOUT_FILE
rm -f $STDERR_FILE
rm -f $KILLED_FILE
}
# The "save_results()" function has to be adapted to clear the testbed before an experiment
# (e.g., remove old log file, deallocate stale resources)
# PARAMETERS:
# - $1 is the directory in which to store the results
# - $2 is the file in which the stdout of the test has been saved
# - $3 is the file in which the stderr of the test has been saved
# - $4 is the file which is (potentially) created if the test has exceeded the timeout
save_results() {
RESULTDIR=$1
STDOUT=$2
STDERR=$3
KILLED=$4
TESTNAME=`basename $RESULTDIR`
echo "Saving results from test $TESTNAME"
if [ "x$KILLED" != "x" ]
then
if [ -e $KILLED ]
then
mv $KILLED $RESULTDIR
fi
fi
mv $STDOUT $RESULTDIR
mv $STDERR $RESULTDIR
cd $WORKDIR
for OUTFILE in "${OUTPUTS[@]}"
do
if [ -e $OUTFILE ]
then
mv $OUTFILE $RESULTDIR
fi
done
ls -U | grep -l ".dump" 1>/dev/null 2>&1
if [ $? -eq 0 ]
then
tar jcf $RESULTDIR/dump.tar.bz2 *.dump
fi
ls -U | grep ".dump" | xargs rm -f
if [ -e dump.txt ]
then
tail -n 15 dump.txt > dump_tail.txt
mv dump_tail.txt $RESULTDIR
bzip2 dump.txt
mv dump.txt.bz2 $RESULTDIR
fi
cd -
}
#----------------------------------------------------------------------------------------------------
if [ "x$SAVEDIR" == "x" ]
then
echo 'Please insert a path in $SAVEDIR'
exit 1
fi
if [ ! -e $SAVEDIR ]
then
mkdir -p $SAVEDIR
if [ $? -ne 0 ]
then
echo "Error creating directory $SAVEDIR"
exit 1
fi
fi
if [ "x$FAULTYDIR" == "x" ]
then
echo 'Please insert a path in $FAULTYDIR'
exit 1
fi
if [ ! -d $FAULTYDIR ]
then
echo "Directory $FAULTYDIR not found (or it is not a directory)"
exit 1
fi
if [ "x$FAULTLIST" == "x" ]
then
echo 'Please insert a path in $FAULTLIST'
exit 1
fi
if [ ! -e $FAULTLIST ]
then
echo "Fault list '$FAULTLIST' not found"
exit 1
fi
if [ "x$TEST" == "x" ]
then
echo 'Please insert a command in $TEST'
exit 1
fi
PROGDIR=`cd $(dirname $0); pwd`
cd $PROGDIR
STDOUT_FILE=/tmp/stdout.txt
STDERR_FILE=/tmp/stderr.txt
KILLED_FILE=/tmp/killed.txt
# BINARYNAME is the name of the binary file with a software fault
# (only the file name, without the path)
BINARYNAME=`basename $BINARY`
# FAULTFREEBIN is the path of the fault-free version of the program
FAULTFREEBIN="$FAULTYDIR/${BINARYNAME}_fault_free"
echo "Start campaign: "`date`
rm -f /tmp/__freeze.txt
echo "Generating test list..."
# List of experiments already executed
ls $SAVEDIR | sort > /tmp/__faults_done.txt
# List of experiments requested by the user
perl -n -l -e 'if(m|(?:'${BINARYNAME}'_)?([^/]+?)(\.[a-zA-Z]+)?$|) { print $1 }' $FAULTLIST | sort > /tmp/__faults_all.txt
# Get the experiments not already executed
join -v 1 /tmp/__faults_all.txt /tmp/__faults_done.txt > /tmp/__faults_todo.txt
I=0
while [ 1 ]
do
# Backdoor for pausing tests
if [ -e /tmp/__freeze.txt ]
then
echo "Tests are paused"
sleep 1000000000
fi
if [ ! -e /tmp/__faults_todo.txt ]
then
echo "Test list not found"
sleep 1000000000
continue
fi
I=$(($I+1))
FAULT=`awk 'NR=='$I' {print $0}' /tmp/__faults_todo.txt`
if [ $? -ne 0 ] || [ "x$FAULT" == "x" ]
then
echo "All experiments have been executed"
break
fi
# Skip the experiment if the faulty binary does not exist
# if [ ! -e $FAULTYDIR/$BINARYNAME_$FAULT ] # no compression
if [ ! -e $FAULTYDIR/"${BINARYNAME}_${FAULT}.diff" ] # with compression
then
echo "Fault not found, skipping: $FAULT"
continue
fi
# Skip the experiment if is has already been executed and the
# results have been stored
if [ -e $SAVEDIR/$FAULT ]
then
echo "Test already done: $FAULT"
continue
fi
# Stop if there is no available space
FREE_SPACE_KB=`df $SAVEDIR | perl -a -n -l -e 'if(++$NR>1) { print $F[$#F-2] }'`
if [ $FREE_SPACE_KB -lt 10000 ]
then
echo "Low free disk space in $SAVEDIR !"
sleep 1000000000
fi
echo
echo "---------------------------------------------------------------"
echo
echo "Running test: $FAULT"
date
# Clear the testing environment
echo "Clearing the testbed"
clear_testbed
rm -f $STDOUT_FILE $STDERR_FILE $KILLED_FILE
echo "Installing faulty version"
rm -f $WORKDIR/$BINARY
# uncompress the executable of the current test
# $ bspatch oldfile newfile patchfile
#bspatch $FAULTFREEBIN $WORKDIR/$BINARY $FAULTYDIR/"${BINARYNAME}_${FAULT}.diff"
bspatch $FAULTFREEBIN $SAVEDIR/"${BINARYNAME}_${FAULT}" $FAULTYDIR/"${BINARYNAME}_${FAULT}.diff"
if [ $? -ne 0 ]
then
echo "Unable to install faulty executable"
sleep 1000000000
fi
chmod +x $SAVEDIR/"${BINARYNAME}_${FAULT}"
sync
mv $SAVEDIR/"${BINARYNAME}_${FAULT}" $WORKDIR/$BINARY
if [ $? -ne 0 ]
then
echo "Unable to copy faulty executable"
sleep 1000000000
fi
# Start the test and a watchdog timer:
# - launch $TEST as a background process ("&")
# - register a signal handler ("handler_timeout")
# - launch a command that sends a signal to this script after a timeout ("(sleep $TIMEOUT ; kill -SIGUSR1 $PID)") as a background process
# - wait() for the $TEST program; wait() fails ("$? -ne 0") if this script is awakened by a signal
echo "Starting Test"
$TEST > >(perl -n -e 'BEGIN{$NR=0} next if($NR++>10000); print' |tee ${STDOUT_FILE}) 2> >(tee ${STDERR_FILE} >&2) &
CMDPID=$!
export CMDPID
# PID: the pid of this script
export PID=$$
trap handle_timeout SIGUSR1
# Starting timer in subshell; it sends a SIGUSR1 to the father if it timeouts
export TIMEOUT
(sleep $TIMEOUT ; kill -SIGUSR1 $PID) &
TPID=$!
# wait for all processes to finish
wait ${CMDPID}
if [ $? -ne 0 ]
then
# This script has been awakened by a signal
# Let the program be killed by the signal handler
sleep 3
# An empty file "killed.txt" is created to remember that the timeout expired
touch $KILLED_FILE
else
# kill timer
kill $TPID
fi
echo "Saving results"
mkdir -p $SAVEDIR/$FAULT
# Call user-defined routine for saving results
save_results "$SAVEDIR/$FAULT" "${STDOUT_FILE}" "${STDERR_FILE}" "${KILLED_FILE}"
done
echo "End campaign: "`date`
rm -f /tmp/__faults_*.txt