2013-11-07 14:22:47 +00:00
|
|
|
#!/bin/bash
|
2014-10-08 07:22:37 +00:00
|
|
|
# The simulation to run
|
|
|
|
CSC=$1
|
|
|
|
shift
|
|
|
|
#Contiki directory
|
|
|
|
CONTIKI=$1
|
|
|
|
shift
|
|
|
|
#The basename of the experiment
|
|
|
|
BASENAME=$1
|
|
|
|
shift
|
2017-11-11 12:32:48 +00:00
|
|
|
#The random seed to start from
|
|
|
|
BASESEED=$1
|
|
|
|
shift
|
|
|
|
#The number of runs (with different seeds)
|
2017-11-05 13:57:31 +00:00
|
|
|
RUNCOUNT=$1
|
|
|
|
shift
|
2013-11-07 14:22:47 +00:00
|
|
|
|
2017-11-05 13:57:31 +00:00
|
|
|
# Counts all tests run
|
|
|
|
declare -i TESTCOUNT=0
|
2013-11-07 14:22:47 +00:00
|
|
|
|
2017-11-05 13:57:31 +00:00
|
|
|
# Counts successfull tests
|
|
|
|
declare -i OKCOUNT=0
|
2013-11-07 14:22:47 +00:00
|
|
|
|
2017-11-11 12:32:48 +00:00
|
|
|
# A list of seeds the resulted in failure
|
|
|
|
FAILSEEDS=
|
|
|
|
|
|
|
|
for (( SEED=$BASESEED; SEED<$(($BASESEED+$RUNCOUNT)); SEED++ )); do
|
2017-11-05 13:57:31 +00:00
|
|
|
echo -n "Running test $BASENAME with random Seed $SEED"
|
|
|
|
|
|
|
|
# run simulation
|
2017-11-11 12:32:48 +00:00
|
|
|
java -Xshare:on -jar $CONTIKI/tools/cooja/dist/cooja.jar -nogui=$CSC -contiki=$CONTIKI -random-seed=$SEED > $BASENAME.$SEED.coojalog &
|
2014-10-08 07:22:37 +00:00
|
|
|
JPID=$!
|
2013-11-07 14:22:47 +00:00
|
|
|
|
2014-10-08 07:22:37 +00:00
|
|
|
# Copy the log and only print "." if it changed
|
2017-11-11 12:32:48 +00:00
|
|
|
touch progress.log
|
2014-10-08 07:22:37 +00:00
|
|
|
while kill -0 $JPID 2> /dev/null
|
|
|
|
do
|
|
|
|
sleep 1
|
2017-11-11 12:32:48 +00:00
|
|
|
diff $BASENAME.$SEED.coojalog progress.log > /dev/null
|
2017-11-05 13:57:31 +00:00
|
|
|
if [ $? -ne 0 ]
|
2014-10-08 07:22:37 +00:00
|
|
|
then
|
|
|
|
echo -n "."
|
2017-11-11 12:32:48 +00:00
|
|
|
cp $BASENAME.$SEED.coojalog progress.log
|
2014-10-08 07:22:37 +00:00
|
|
|
fi
|
|
|
|
done
|
2017-11-11 12:32:48 +00:00
|
|
|
rm progress.log
|
2014-10-08 07:22:37 +00:00
|
|
|
|
2017-11-05 13:57:31 +00:00
|
|
|
# wait for end of simulation
|
2014-10-08 07:22:37 +00:00
|
|
|
wait $JPID
|
|
|
|
JRV=$?
|
|
|
|
|
2017-11-11 12:32:48 +00:00
|
|
|
# Save testlog
|
|
|
|
touch COOJA.testlog;
|
|
|
|
mv COOJA.testlog $BASENAME.$SEED.scriptlog
|
|
|
|
rm COOJA.log
|
|
|
|
|
2017-11-05 13:57:31 +00:00
|
|
|
TESTCOUNT+=1
|
2014-10-08 07:22:37 +00:00
|
|
|
if [ $JRV -eq 0 ] ; then
|
2017-11-05 13:57:31 +00:00
|
|
|
OKCOUNT+=1
|
2014-10-08 07:22:37 +00:00
|
|
|
echo " OK"
|
2014-10-14 07:55:20 +00:00
|
|
|
else
|
2017-11-11 12:32:48 +00:00
|
|
|
FAILSEEDS+=" $BASESEED"
|
|
|
|
echo " FAIL ಠ_ಠ"
|
2017-11-05 13:57:31 +00:00
|
|
|
# Verbose output when using CI
|
|
|
|
if [ "$CI" = "true" ]; then
|
2017-11-11 12:32:48 +00:00
|
|
|
echo "==== $BASENAME.$SEED.coojalog ====" ; cat $BASENAME.$SEED.coojalog;
|
|
|
|
echo "==== $BASENAME.$SEED.scriptlog ====" ; cat $BASENAME.$SEED.scriptlog;
|
2017-11-05 13:57:31 +00:00
|
|
|
else
|
2017-11-11 12:32:48 +00:00
|
|
|
echo "==== Check $BASENAME.$SEED.coojalog and $BASENAME.$SEED.scriptlog for details ====";
|
|
|
|
fi
|
2017-11-05 13:57:31 +00:00
|
|
|
fi
|
2014-10-08 07:22:37 +00:00
|
|
|
done
|
|
|
|
|
2017-11-05 13:57:31 +00:00
|
|
|
if [ $TESTCOUNT -ne $OKCOUNT ] ; then
|
|
|
|
# At least one test failed
|
2017-11-14 08:57:34 +00:00
|
|
|
printf "%-32s TEST FAIL %3d/%d -- failed seeds:%s\n" "$BASENAME" "$OKCOUNT" "$TESTCOUNT" "$FAILSEEDS" > $BASENAME.testlog;
|
2017-11-11 12:32:48 +00:00
|
|
|
else
|
2017-11-14 08:57:34 +00:00
|
|
|
printf "%-32s TEST OK %3d/%d\n" "$BASENAME" "$OKCOUNT" "$TESTCOUNT" > $BASENAME.testlog;
|
2013-11-07 14:22:47 +00:00
|
|
|
fi
|
|
|
|
|
2017-11-05 13:57:31 +00:00
|
|
|
# We do not want Make to stop -> Return 0
|
|
|
|
# The Makefile will check if a log contains FAIL at the end
|
|
|
|
exit 0
|