#!/bin/bash
#NAME=Different Test 2
#DESC=This test determines something else really interesting.
#CAT=SD Card
RES=$(fio --output-format=terse /usr/share/agnostics/sd_bench.fio | cut -f 3,45,86 -d";" -)
echo "$RES" >> /home/pi/log.txt
prep=$(echo "$RES" | head -n 1 | cut -d ";" -f 3 | cut -d "." -f 1)
swri=$(echo "$RES" | head -n 2 | tail -n 1 | cut -d ";" -f 3 | cut -d "." -f 1)
rwri=$(echo "$RES" | head -n 3 | tail -n 1 | cut -d ";" -f 3 | cut -d "." -f 1)
rrea=$(echo "$RES" | head -n 4 | tail -n 1 | cut -d ";" -f 2 | cut -d "." -f 1)
# some arbitrary pass/fail criteria here for now...
pass=0
if [ "$prep" -lt 12000 ] ; then
    echo "Prepare speed - FAIL" >> $1
    pass=1
fi
if [ "$swri" -lt 10000 ] ; then
    echo "Sequential write speed - FAIL" >> $1
    pass=1
fi
if [ "$rwri" -lt 5000 ] ; then
    echo "Random write speed - FAIL" >> $1
    pass=1
fi
if [ "$rrea" -lt 10000 ] ; then
    echo "Random read speed - FAIL" >> $1
    pass=1
fi
if [ "$pass" -eq 0 ] ; then
    echo "All tests passed" >> $1
fi
return $pass
