#!/bin/bash

export TCID=fio; export TST_TOTAL=8; export TST_COUNT=1

. run_profile.txt
. $base_dir/plans/commands/common.fns
export PATH=/usr/local/bin:$PATH

tst_resm TINFO "BEGIN PACKAGE $TCID"
# Check needed vars from run_profile.txt
[ ! -d "$run_dir" ] && tst_resm TCONF "ERROR: $run_dir does not exist" && exit -10

CPUCOUNT=`cpus_online.sh`

SUT=`hostname -s`
tst_resm TINFO "Running fio on SUT: $SUT with $CPUCOUNT CPUs"
export CPUCOUNT

log_dir="$run_dir/test_output"
mkdir -p $log_dir

jobfile="$PKGS_DIR/fio/stresser.fio"
echo "===== begin jobfile: $jobfile: ====="
cat $jobfile
echo "===== end jobfile; ====="

if ! grep -q olt-storage /proc/mounts ; then
	if [ ! -d /olt-storage ]; then
		mkdir /olt-storage
	fi

	mount -t ext3 -o noatime,data=writeback /dev/sda1 /olt-storage
	sts=$?
	if [ $sts -ne 0 ]; then
		echo "mount -t ext3 /dev/sda1 /olt-storage error = $sts"
		exit 11
	fi

	if [ ! -d /olt-storage/tester ]; then
		mkdir -p /olt-storage/tester
	fi
fi


runit="/usr/bin/time fio"

tst_resm TINFO "begin fio stresser job"
run_test "fio" "$runit $jobfile" "$log_dir" "fio-stress.log"
tst_status $? fio-stresser

# maybe print some selective log output:
# $all_pkgs_dir/posixtestsuite/posixtest-summary.sh

tst_resm TINFO fini
exit 0
