forked from contiki-ng/contiki-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simexec.sh
executable file
·78 lines (67 loc) · 1.76 KB
/
simexec.sh
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
#!/bin/bash
# The simulation to run
CSC=$1
shift
#Contiki directory
CONTIKI=$1
shift
#The basename of the experiment
BASENAME=$1
shift
#The random seed to start from
BASESEED=$1
shift
#The number of runs (with different seeds)
RUNCOUNT=$1
shift
# Counts all tests run
declare -i TESTCOUNT=0
# Counts successfull tests
declare -i OKCOUNT=0
# A list of seeds the resulted in failure
FAILSEEDS=
for (( SEED=$BASESEED; SEED<$(($BASESEED+$RUNCOUNT)); SEED++ )); do
echo -n "Running test $BASENAME with random Seed $SEED"
# run simulation
java -Xshare:on -jar $CONTIKI/tools/cooja/dist/cooja.jar -nogui=$CSC -contiki=$CONTIKI -random-seed=$SEED > $BASENAME.$SEED.coojalog &
JPID=$!
# Copy the log and only print "." if it changed
touch progress.log
while kill -0 $JPID 2> /dev/null
do
sleep 1
diff $BASENAME.$SEED.coojalog progress.log > /dev/null
if [ $? -ne 0 ]
then
echo -n "."
cp $BASENAME.$SEED.coojalog progress.log
fi
done
rm progress.log
# wait for end of simulation
wait $JPID
JRV=$?
# Save testlog
touch COOJA.testlog;
mv COOJA.testlog $BASENAME.$SEED.scriptlog
rm COOJA.log
TESTCOUNT+=1
if [ $JRV -eq 0 ] ; then
OKCOUNT+=1
echo " OK"
else
FAILSEEDS+=" $BASESEED"
echo " FAIL"
echo "==== $BASENAME.$SEED.coojalog ====" ; cat $BASENAME.$SEED.coojalog;
echo "==== $BASENAME.$SEED.scriptlog ====" ; cat $BASENAME.$SEED.scriptlog;
fi
done
if [ $TESTCOUNT -ne $OKCOUNT ] ; then
# At least one test failed
printf "%-40s TEST FAIL %3d/%d -- failed seeds:%s\n" "$BASENAME" "$OKCOUNT" "$TESTCOUNT" "$FAILSEEDS" > $BASENAME.testlog;
else
printf "%-40s TEST OK %3d/%d\n" "$BASENAME" "$OKCOUNT" "$TESTCOUNT" > $BASENAME.testlog;
fi
# We do not want Make to stop -> Return 0
# The Makefile will check if a log contains FAIL at the end
exit 0