#!/bin/bash
if [[ $HOSTNAME = *"occigen"* ]]; then
        source ../machines/occigen-bdw/env
elif [[ $HOSTNAME = *"jean-zay"* ]]; then
        source ../machines/jean-zay-cpu/env
elif [[ $HOSTNAME = *"irene"* ]]; then
        source ../machines/irene-amd/env
else
        echo "Hostname not recognized: abort"
        exit 1
fi
echo "**********************************************************************************************************"
echo "* Validate small case in $bench_dir/DEBUG *"
echo "**********************************************************************************************************"

cd $bench_dir/DEBUG
log_file=$1
if [ -z "$log_file" ]; then
	log_file=`ls -thlx run_* | awk -F " " '{ print $1 }'`
	echo "* No argument provided (ex: ./validate run_%m-%d-%y-%H-%M-%S.log), validation of the last run named $log_file"	
else
        echo "* Validation of the run named $log_file"
fi
start_t=`grep startup $log_file | awk '{ print $5 }'`
end_t=`grep "Total elapsed time:"  $log_file | awk '{ print $4 }'`
perf=`bc -l <<< $end_t-$start_t`

if [ -z "$perf" ] || [ -z "$end_t" ]
then
    echo "* Small bench is not validated"
else
    echo "* Small bench is validated"
    echo "log file: $log_file"
    echo "end = $end_t s (total simulation time)"
    echo "perf = $perf s (total simulation time excluding initialization and i/o)"
fi
echo "**********************************************************************************************************"
#TODO add a physical validation