nes-proj/tests/simexec.sh

84 lines
1.9 KiB
Bash
Executable File

#!/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 ಠ_ಠ"
# Verbose output when using CI
if [ "$CI" = "true" ]; then
echo "==== $BASENAME.$SEED.coojalog ====" ; cat $BASENAME.$SEED.coojalog;
echo "==== $BASENAME.$SEED.scriptlog ====" ; cat $BASENAME.$SEED.scriptlog;
else
echo "==== Check $BASENAME.$SEED.coojalog and $BASENAME.$SEED.scriptlog for details ====";
fi
fi
done
if [ $TESTCOUNT -ne $OKCOUNT ] ; then
# At least one test failed
echo "$BASENAME: TEST FAIL ಠ_ಠ ($OKCOUNT/$TESTCOUNT, failed seeds:$FAILSEEDS)" > $BASENAME.testlog;
else
echo "$BASENAME: TEST OK ($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