git clean -d -x -f -q

LOGFILE="/tmp/logfile.$$"

checkfailure()
{
    if grep -q "Starting network" ${LOGFILE}; then
	return 1
    fi
    if grep -q "Requesting system reboot" ${LOGFILE}; then
	return 1
    fi
    if grep -q "Run /sbin/init as init process" ${LOGFILE}; then
	return 0
    fi
    return 1
}

OPT=""

for s in $(seq 1 12); do
    echo "Run $s"
    if ! /opt/buildbot/rootfs/arm-v7/run-qemu-arm-v7.sh ${OPT} -T "" multi_v7_defconfig "npcm*" >& ${LOGFILE}; then
        if checkfailure; then
            echo "Failed. Logfile is ${LOGFILE}."
            exit 1
        fi
	echo "Test failed, possibly with different error. Check logfile at ${LOGFILE}.$s"
	mv "${LOGFILE}" "${LOGFILE}.$s"
    fi
    OPT="-n"
done
echo "Passed"
exit 0
