#! /usr/xenomai/bin/xeno-test-run

usage()
{
    cat <<EOF
xeno-test -h or xeno-test --help

This help text.


xeno-test [ -l "load command" ] [ -k ] [ -r ] [ -- ] [ latency test options ]

Run a basic test/benchmark of Xenomai on your platform, by first starting a
few unit tests, then running the latency test under the load generated by
"load-command".

By default, the load command is "dohell 900", which will generate load during
15 minutes. To generate a more realistic load see dohell help.

This script accepts the -k option to tell the unit test loop to keep
going upon a failing test. Otherwise xeno-test stops immediately.

If the script is passed the -r option, real-time stress is added to the test,
with the help of the "switchtest" test. But beware: the latency test figures are
then no longer meaningful.

Any other option passed on the command line is passed to the latency test.

Example:
xeno-test -l "dohell -s 192.168.0.5 -m /mnt -l /ltp" -t 2

Will generate load including network load using the server at IP address
192.168.0.5, some I/O under the moint point /mnt, and the LTP testsuite
installed under the /ltp directory, and use the latency test by measuring the
timer irq latency.
EOF
}

keep_going=
rt_load=false

while :; do
    case "$1" in
	-h|--help)
	    usage
	    exit 0
	    ;;

	-k)
	    keep_going=--keep-going
	    shift
	    ;;

	-r)
	    rt_load=true
	    shift
	    ;;

	--)
	    shift
	    break
	    ;;

	""|*)
	    break
	    ;;
    esac
done

set -ex

echo 0 > /proc/xenomai/latency || :

testdir=/usr/xenomai/bin

$testdir/smokey --run $keep_going
$testdir/clocktest -D -T 30 -C CLOCK_HOST_REALTIME || $testdir/clocktest -T 30
$testdir/switchtest -T 30

start_load

if $rt_load; then
    check_alive $testdir/switchtest
    check_alive $testdir/switchtest -s 1000
fi

check_alive $testdir/latency ${1+"$@"}

wait_load
