#!/bin/bash
###SHELLPACK preamble seeker-bench 0

SEEKER_IO=read
SEEKER_TYPE=block
SEEKER_SIZE=$((MEMTOTAL_BYTES*2))

###SHELLPACK parseargBegin
###SHELLPACK parseargInstall
###SHELLPACK parseargParam   --io	SEEKER_IO
###SHELLPACK parseargParam   --type	SEEKER_TYPE
###SHELLPACK parseargParam   --size	SEEKER_SIZE
###SHELLPACK parseargParam   --device	SEEKER_DEVICE
###SHELLPACK parseargEnd
###SHELLPACK monitor_hooks

###SHELLPACK check_install_required seeker
###SHELLPACK init_complete

pushd $SHELLPACK_SOURCES/seeker-${VERSION}-installed > /dev/null || die Benchmark not installed
RESULTSLOG=$LOGDIR_RESULTS/seeker

# Create input file if requested
SEEKER_FILE=
case $SEEKER_TYPE in
file)
	if [ "$SEEKER_SIZE" = "" -o $SEEKER_SIZE -eq 0 ]; then
		die Must specify proper SEEKER_SIZE
	fi
	create_random_file $SEEKER_SIZE $SHELLPACK_DATA/seeker_file
	sync
	SEEKER_FILE="$SHELLPACK_DATA/seeker_file"
	;;
block)
	if [ "$SEEKER_DEVICE" = "" ]; then
		die Must specify device file
	fi
	SEEKER_FILE=$SEEKER_DEVICE
	;;
*)
	die Unrecognised device param $SEEKER_TYPE
	;;
esac

monitor_pre_hook $LOGDIR_RESULTS $P
case $SEEKER_IO in
read)
	save_rc
	./seeker $SEEKER_TYPE read "$SEEKER_FILE" 2>&1 | tee -a $LOGDIR_RESULTS/seeker.log
	recover_rc
	RETVAL=$?
	;;
write)
	save_rc
	./seeker $SEEKER_TYPE write "$SEEKER_FILE" 2>&1 | tee -a $LOGDIR_RESULTS/seeker.log
	recover_rc
	RETVAL=$?
	;;
*)
	die Unrecognised IO param $SEEKER_IO
	;;
esac
monitor_post_hook $LOGDIR_RESULTS $P

if [ $RETVAL -ne 0 ]; then
	exit $SHELLPACK_FAILURE
fi
exit $SHELLPACK_SUCCESS
