Rewrite run.sh script
This commit is contained in:
226
run.sh
226
run.sh
@@ -1,65 +1,181 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
BUILD=__build.sh
|
||||
RUN=__run.sh
|
||||
## Default valies
|
||||
CPU_COUNT=1024
|
||||
BLOCK_SIZE=1
|
||||
THREADS=1
|
||||
|
||||
if [ "$1" == "all" ]
|
||||
BLD_SCRIPT="__build.sh"
|
||||
RUN_SCRIPT="__run.sh"
|
||||
TEST_DIR_PREFIX="test-"
|
||||
LOG_PREFIX="####"
|
||||
|
||||
function sim_dir_valid()
|
||||
{
|
||||
if [ -e "$1/$BLD_SCRIPT" ] && [ -e "$1/$RUN_SCRIPT" ]
|
||||
then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function sim_list()
|
||||
{
|
||||
for dir in "$TEST_DIR_PREFIX"*
|
||||
do
|
||||
if sim_dir_valid "$dir"
|
||||
then
|
||||
echo "${dir:5}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function print_help()
|
||||
{
|
||||
echo "Usage: $0 [OPTION]... [SIM...]"
|
||||
echo "Run simulator benchmark. Calculates MD5 hash from a block data"
|
||||
echo "on an array of soft-cores PicoRV32."
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -c [COUNT] Soft CPU count in simulation. Default: 1024"
|
||||
echo " -s [SIZE] Data block size in bytes. Default: 1024 bytes"
|
||||
echo " -t [COUNT] Simulation threads count. Default: 1"
|
||||
echo " (so far only for Verilator)"
|
||||
echo " -l List of available benchmarks"
|
||||
echo " -h This help"
|
||||
echo
|
||||
echo "The SIM parameter is the name of the simulator from the list of"
|
||||
echo "option -l. If the parameter is not specified, benchmarks for all"
|
||||
echo "simulators will be performed. Be careful, some simulators take "
|
||||
echo "a very long time to benchmark."
|
||||
echo
|
||||
}
|
||||
|
||||
function check_arg(){
|
||||
if [[ $2 == -* ]]
|
||||
then
|
||||
echo "Option $1 requires an argument" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function parse_param()
|
||||
{
|
||||
while getopts ":c:s:t:lh" opt
|
||||
do
|
||||
case $opt in
|
||||
c)
|
||||
check_arg "-c" "$OPTARG"
|
||||
CPU_COUNT=$OPTARG
|
||||
;;
|
||||
s)
|
||||
check_arg "-s" "$OPTARG"
|
||||
BLOCK_SIZE=$OPTARG
|
||||
;;
|
||||
t)
|
||||
check_arg "-t" "$OPTARG"
|
||||
THREADS=$OPTARG
|
||||
;;
|
||||
l)
|
||||
sim_list
|
||||
exit 0
|
||||
;;
|
||||
h)
|
||||
print_help
|
||||
exit 0
|
||||
;;
|
||||
\?)
|
||||
echo "Invalid option: -$OPTARG" >&2
|
||||
print_help
|
||||
exit 1
|
||||
;;
|
||||
:)
|
||||
echo "Option -$OPTARG requires an argument" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function log()
|
||||
{
|
||||
echo -n "$LOG_PREFIX "
|
||||
echo "$@"
|
||||
}
|
||||
|
||||
function run_benchmark()
|
||||
{
|
||||
benchmark=$1
|
||||
dir=$TEST_DIR_PREFIX$benchmark
|
||||
|
||||
if sim_dir_valid "$dir"
|
||||
then
|
||||
local t0 t1 ms
|
||||
|
||||
if cd "$dir"
|
||||
then
|
||||
# Build
|
||||
log "Build $benchmark"
|
||||
t0=$(date +%s%N | cut -b1-13)
|
||||
|
||||
if ! ./$BLD_SCRIPT "$CPU_COUNT" "$BLOCK_SIZE" "$THREADS"
|
||||
then
|
||||
cd ..
|
||||
log "Build $benchmark FAILED"
|
||||
return 1
|
||||
fi
|
||||
|
||||
t1=$(date +%s%N | cut -b1-13)
|
||||
ms=$((t1 - t0))
|
||||
log "Build $benchmark time (ms): $ms"
|
||||
|
||||
echo
|
||||
|
||||
# Run
|
||||
log "Run $benchmark"
|
||||
t0=$(date +%s%N | cut -b1-13)
|
||||
|
||||
if ! ./$RUN_SCRIPT "$CPU_COUNT" "$BLOCK_SIZE" "$THREADS"
|
||||
then
|
||||
cd ..
|
||||
log "RUN $benchmark FAILED"
|
||||
return 1
|
||||
fi
|
||||
|
||||
t1=$(date +%s%N | cut -b1-13)
|
||||
ms=$((t1 - t0))
|
||||
log "Run $benchmark time (ms): $ms"
|
||||
|
||||
cd ..
|
||||
return 0
|
||||
else
|
||||
log "Can't change dir to $dir"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
log "No run scripts found in $dir"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
parse_param "$@"
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
if [ $# -gt 0 ]
|
||||
then
|
||||
tests=$(ls -1d test-*)
|
||||
elif [ -n "$1" ]
|
||||
then
|
||||
tests="$@"
|
||||
benches="$*"
|
||||
else
|
||||
echo "Usage: $0 <TEST_DIRECTORY | all>"
|
||||
exit -1
|
||||
for b in $(sim_list); do benches="$benches$b "; done
|
||||
fi
|
||||
|
||||
## Log header
|
||||
echo >> results.txt
|
||||
echo "---------- Simulator's benchmark -----------" >> results.txt
|
||||
echo $(date) >> results.txt
|
||||
echo >> results.txt
|
||||
log "Soft-cores count: $CPU_COUNT"
|
||||
log "Block size: $BLOCK_SIZE"
|
||||
log "Threads count: $THREADS"
|
||||
log "Benchmarks: $benches"
|
||||
|
||||
## Run tests
|
||||
for test_dir in $tests
|
||||
for bench in $benches
|
||||
do
|
||||
if [ ! -d "$test_dir" ]
|
||||
then
|
||||
echo "Directory $test_dir is not exists"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
if [ -e $test_dir/$BUILD -a -e $test_dir/$RUN ]
|
||||
then
|
||||
echo "#### Run benchmark in $test_dir"
|
||||
|
||||
cd $test_dir
|
||||
|
||||
./$BUILD
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
start_ms=$(date +%s%N | cut -b1-13)
|
||||
|
||||
./$RUN
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
stop_ms=$(date +%s%N | cut -b1-13)
|
||||
ms=$(expr $stop_ms - $start_ms)
|
||||
echo "#### $test_dir: $ms milliseconds"
|
||||
else
|
||||
ms="RUN FAIL"
|
||||
echo "#### $test_dir: run fail"
|
||||
fi
|
||||
else
|
||||
ms="BUILD FAIL"
|
||||
echo "#### $test_dir: build fail"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
cd ..
|
||||
|
||||
echo "$test_dir: $ms" >> results.txt
|
||||
else
|
||||
echo "Skip $test_dir directory"
|
||||
fi
|
||||
echo
|
||||
run_benchmark "$bench"
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user