#!/bin/bash -e
# run wendelin.core/wcfs tests.
# if $WENDELIN_CORE_TEST_QEMU_RUNLINUX=y the tests are run under custom linux kernel.

X=$(cd `dirname $0` && pwd)

# rebuild everything
if test -z "$qrun_loglevel"; then
	make -C $X --no-print-directory
fi

# respawn ourself under qemu-runlinux, if asked.
if [ "${WENDELIN_CORE_TEST_QEMU_RUNLINUX:-n}" == y ]; then
	if test -z "$qrun_loglevel"; then
		linux=${LINUX:-$HOME/src/linux/linux/arch/`uname -m`/boot/bzImage}
		exec $X/t/qemu-runlinux "$linux" $0 "$@"
	fi
fi

# executed under qemu-runlinux
#export WENDELIN_CORE_WCFS_OPTIONS="-d -alsologtostderr -v=1"
#screen	-Logfile /tmp/x.0 -L \
py.test	\
	`# disable cache & warnings that it cannot be updated since fs under qrun is read-only`	\
	`# https://stackoverflow.com/a/47893653/9456786`	\
	-p no:cacheprovider	\
 \
	"$@"
