#!/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

SUT=`hostname -s`
tst_resm TINFO "Running fio on SUT: $SUT"

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

# use $FIOFILES for fio files
FIOFILES=/root/tmp
mkdir -p $FIOFILES

runit="/usr/bin/time fio"

# non-extensive combinations of fio parameters/arguments/options
# (old run_fio.sh file)
#
# test matrix:
# ioengine=sync libaio posixaio mmap splice sg
# mem=malloc shm mmap
# direct=bool|buffered=bool (mut-ex.)
# sync=bool
# ioscheduler= {wait}

TIMESECS=60
FIXEDOPTS="--timeout $TIMESECS --runtime=$TIMESECS --numjobs=3 --verify=crc32 --directory=$FIOFILES --size=100M --bsrange=4K-256K --iodepth=8 --end_fsync=1 --rw=randrw --rwmixread=65 --rwmixwrite=35 --unlink=0"
## --minimal

# variances:  ioengine=str; mem=str; direct=bool|buffered=bool; sync=bool;

tst_resm TINFO "= 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 ="
specs="--ioengine=sync --mem=malloc --buffered=1 --sync=0"
run_test "fio" "$runit $FIXEDOPTS $specs" "$log_dir" "fio-run1.log"
tst_status $? fio-1

TST_COUNT=2
tst_resm TINFO "= 2 = 2 = 2 = 2 = 2 = 2 = 2 = 2 = 2 = 2 = 2 = 2 ="
specs="--ioengine=sync --mem=mmap   --buffered=0 --sync=1"
run_test "fio" "$runit $FIXEDOPTS $specs" "$log_dir" "fio-run2.log"
tst_status $? fio-2

TST_COUNT=3
tst_resm TINFO "= 3 = 3 = 3 = 3 = 3 = 3 = 3 = 3 = 3 = 3 = 3 = 3 ="
specs="--ioengine=libaio --mem=malloc --buffered=0 --sync=1"
run_test "fio" "$runit $FIXEDOPTS $specs" "$log_dir" "fio-run3.log"
tst_status $? fio-3

TST_COUNT=4
tst_resm TINFO "= 4 = 4 = 4 = 4 = 4 = 4 = 4 = 4 = 4 = 4 = 4 = 4 ="
specs="--ioengine=libaio --mem=shm    --buffered=1 --sync=0" 
run_test "fio" "$runit $FIXEDOPTS $specs" "$log_dir" "fio-run4.log"
tst_status $? fio-4

TST_COUNT=5
tst_resm TINFO "= 5 = 5 = 5 = 5 = 5 = 5 = 5 = 5 = 5 = 5 = 5 = 5 ="
specs="--ioengine=posixaio --mem=malloc --buffered=1 --sync=0"
run_test "fio" "$runit $FIXEDOPTS $specs" "$log_dir" "fio-run5.log"
tst_status $? fio-5

TST_COUNT=6
tst_resm TINFO "= 6 = 6 = 6 = 6 = 6 = 6 = 6 = 6 = 6 = 6 = 6 = 6 ="
specs="--ioengine=posixaio --mem=shm    --buffered=0 --sync=1"
run_test "fio" "$runit $FIXEDOPTS $specs" "$log_dir" "fio-run6.log"
tst_status $? fio-6

TST_COUNT=7
tst_resm TINFO "= 7 = 7 = 7 = 7 = 7 = 7 = 7 = 7 = 7 = 7 = 7 = 7 ="
specs="--ioengine=mmap --mem=malloc --buffered=0 --sync=1"
run_test "fio" "$runit $FIXEDOPTS $specs" "$log_dir" "fio-run7.log"
tst_status $? fio-7

TST_COUNT=8
tst_resm TINFO "= 8 = 8 = 8 = 8 = 8 = 8 = 8 = 8 = 8 = 8 = 8 = 8 ="
specs="--ioengine=mmap --mem=mmap   --buffered=1 --sync=0"
run_test "fio" "$runit $FIXEDOPTS $specs" "$log_dir" "fio-run8.log"
tst_status $? fio-8

# splice hangs, runs forever, never completes.
#tst_resm TINFO "= 9 = 9 = 9 = 9 = 9 = 9 = 9 = 9 = 9 = 9 = 9 = 9 ="
#specs="--ioengine=splice --mem=malloc --buffered=1 --sync=0"
#run_test "fio" "$runit $FIXEDOPTS $specs" "$log_dir" "fio-run9.log"

#tst_resm TINFO "= 10 = 10 = 10 = 10 = 10 = 10 = 10 = 10 = 10 = 10 = 10 = 10 ="
#specs="--ioengine=splice --mem=mmap   --buffered=0 --sync=1"
#run_test "fio" "$runit $FIXEDOPTS $specs" "$log_dir" "fio-run10.log"

# sg wants a block device target:
#tst_resm TINFO "= 11 = 11 = 11 = 11 = 11 = 11 = 11 = 11 = 11 = 11 = 11 = 11 ="
#specs="--ioengine=sg --mem=malloc --buffered=1 --sync=0"
#run_test "fio" "$runit $FIXEDOPTS $specs" "$log_dir" "fio-run11.log"

#tst_resm TINFO "= 12 = 12 = 12 = 12 = 12 = 12 = 12 = 12 = 12 = 12 = 12 = 12 ="
#specs="--ioengine=sg --mem=mmap   --buffered=0 --sync=1"
#run_test "fio" "$runit $FIXEDOPTS $specs" "$log_dir" "fio-run12.log"

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

tst_resm TINFO fini
exit 0
