From e9520fe131a257dcebfd3bcea92bcded99c43eb1 Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Fri, 30 Sep 2022 12:05:40 -0500 Subject: [PATCH] shellcheck-guided fixes in IDE/XilinxSDK/bench.sh, IDE/XilinxSDK/combine.sh, IDE/XilinxSDK/graph.sh, and scripts/bench/bench_functions.sh. --- IDE/XilinxSDK/bench.sh | 3 ++- IDE/XilinxSDK/combine.sh | 8 +++++--- IDE/XilinxSDK/graph.sh | 27 +++++++++++++++------------ scripts/bench/bench_functions.sh | 25 +++++++++++++++++++++---- 4 files changed, 43 insertions(+), 20 deletions(-) diff --git a/IDE/XilinxSDK/bench.sh b/IDE/XilinxSDK/bench.sh index 2c9fce7d9..850acc63f 100755 --- a/IDE/XilinxSDK/bench.sh +++ b/IDE/XilinxSDK/bench.sh @@ -16,7 +16,8 @@ # Preamble ### -readonly my_path=$(dirname $(readlink -f $0)) +my_path=$(dirname $(readlink -f $0)) || exit $? +readonly my_path readonly csv_path_suffix="$1" readonly common_opts="-blocks 128" diff --git a/IDE/XilinxSDK/combine.sh b/IDE/XilinxSDK/combine.sh index fc697a6b4..4cf2d26db 100755 --- a/IDE/XilinxSDK/combine.sh +++ b/IDE/XilinxSDK/combine.sh @@ -9,7 +9,8 @@ # Preamble ### -readonly my_path="$(dirname $(readlink -f $0))" +my_path="$(dirname $(readlink -f $0))" || exit $? +readonly my_path readonly csv_path="$my_path/data" function cleanup() { @@ -32,7 +33,8 @@ trap error_out INT TERM # Implementation ### -readonly configs=$(find $csv_path -maxdepth 1 -type d -name '*results_*' | sed 's@.*results_@@g') +configs=$(find $csv_path -maxdepth 1 -type d -name '*results_*' | sed 's@.*results_@@g') || exit $? +readonly configs declare -A algos algos["asym"]="ecc rsa" @@ -57,7 +59,7 @@ filters["cmac"]="-e s/\(128\|256\)-CMAC/CMAC,\1/g" filters["ecc"]='-e 1!{/SECP384R1\|SECP521R1/!d}' filters["sha2"]="-e s/SHA-/SHA2-/g" -for t in ${!algos[@]} +for t in "${!algos[@]}" do for algo in ${algos[$t]} do diff --git a/IDE/XilinxSDK/graph.sh b/IDE/XilinxSDK/graph.sh index d66cbdf63..944e4ca7f 100755 --- a/IDE/XilinxSDK/graph.sh +++ b/IDE/XilinxSDK/graph.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# shellcheck disable=SC2043 # noise. fine for a loop to run only once. # # SPDX-License-Identifier: GPL-2.0-or-later # @@ -9,7 +10,8 @@ # Preamble ### -readonly my_path="$(dirname $(readlink -f $0))" +my_path="$(dirname $(readlink -f $0))" || exit $? +readonly my_path readonly csv_path="$my_path/data" readonly log_path="$csv_path/logs" readonly img_path="$csv_path/images" @@ -45,7 +47,8 @@ readonly desc_block_ciphers="Benchmarks were done with growing sample size and a readonly desc_asymmetric="Benchmarks were done with averaging over\nas many repetitions possible of the benchmarked operation in 1s" readonly desc_others="Benchmarks were done with 1MiB block size and averaging over\nas many repetitions possible of processing 5MiB data in 1s" -readonly configs=$(find $csv_path -type d -name '*results*' | sed 's@.*results_@@g') +configs=$(find $csv_path -type d -name '*results*' | sed 's@.*results_@@g') || exit $? +readonly configs ### # Symmetric crypto @@ -71,7 +74,7 @@ gcm_yrange="${gcm_yrange:=500}" for mode in $sym do infile="$csv_path/combined_${mode}.csv" - for dir in ${!directions[@]} + for dir in "${!directions[@]}" do plotstring= more_style= @@ -85,18 +88,18 @@ do if [ "$val" != "" ]; then echo "$val" > $outfile [ -z "$plotstring" ] && plotstring="plot" || plotstring="${plotstring}," - plotstring="${plotstring} '"$outfile"' smooth bezier title \"$cfg AES$bsize\"" + plotstring="${plotstring} '$outfile' smooth bezier title \"$cfg AES$bsize\"" fi [ "$mode" == "cbc" -a "$cbc_yrange" != "" ] && more_style="set yrange [ 0 : $cbc_yrange ]" else - for aad in ${!aad_sizes[@]} + for aad in "${!aad_sizes[@]}" do outfile=$log_path/${mode}${bsize}_${cfg}_${dir}_${aad}.log val="$(cg config $cfg $infile | cg blocksize $bsize | cg direction $dir | cg AAD $aad | csvcut -c chunksize,MiB/s | tail -n +2 | tr ',' ' ')" if [ "$val" != "" ]; then echo "$val" > $outfile [ -z "$plotstring" ] && plotstring="plot" || plotstring="${plotstring}," - plotstring="${plotstring} '"$outfile"' smooth bezier title \"$cfg AES$bsize ${aad_sizes[$aad]} AAD\"" + plotstring="${plotstring} '$outfile' smooth bezier title \"$cfg AES$bsize ${aad_sizes[$aad]} AAD\"" fi done [ "$mode" == "gcm" -a "$gcm_yrange" != "" ] && more_style="set yrange [ 0 : $gcm_yrange ]" @@ -125,7 +128,7 @@ done for mode in gcm do infile="$csv_path/combined_${mode}.csv" - for dir in ${!directions[@]} + for dir in "${!directions[@]}" do for bsize in $(csvcut -c blocksize $infile | tail -n +2 | sort -u) do @@ -133,14 +136,14 @@ do more_style="set yrange [ 0 : $gcm_yrange ]" for cfg in $configs do - for aad in ${!aad_sizes[@]} + for aad in "${!aad_sizes[@]}" do outfile=$log_path/${mode}${bsize}_${cfg}_${dir}_${aad}.log val="$(cg config $cfg $infile | cg blocksize $bsize | cg direction $dir | cg AAD $aad | csvcut -c chunksize,MiB/s | tail -n +2 | tr ',' ' ')" if [ "$val" != "" ]; then echo "$val" > $outfile [ -z "$plotstring" ] && plotstring="plot" || plotstring="${plotstring}," - plotstring="${plotstring} '"$outfile"' smooth bezier title \"$cfg AES$bsize ${aad_sizes[$aad]} AAD\"" + plotstring="${plotstring} '$outfile' smooth bezier title \"$cfg AES$bsize ${aad_sizes[$aad]} AAD\"" fi done done @@ -168,7 +171,7 @@ declare -A asym_operations asym_operations["ecc"]="keygen agree sign verify" asym_operations["rsa"]="keygen public private" -for algo in ${!asym_operations[@]} +for algo in "${!asym_operations[@]}" do infile="$csv_path/combined_${algo}.csv" for op in ${asym_operations[$algo]} @@ -214,7 +217,7 @@ hash_sizes["sha3"]="384" plotstring= outfile=$log_path/sha.log echo -n "" > $outfile -for algo in ${!hash_sizes[@]} +for algo in "${!hash_sizes[@]}" do infile="$csv_path/combined_${algo}.csv" for hsize in ${hash_sizes[$algo]} @@ -255,7 +258,7 @@ macs["cmac"]="128 256" plotstring= outfile=$log_path/mac.log echo -n "" > $outfile -for algo in ${!macs[@]} +for algo in "${!macs[@]}" do infile="$csv_path/combined_${algo}.csv" for hsize in ${macs[$algo]} diff --git a/scripts/bench/bench_functions.sh b/scripts/bench/bench_functions.sh index 395ac80a9..36b971cef 100755 --- a/scripts/bench/bench_functions.sh +++ b/scripts/bench/bench_functions.sh @@ -15,15 +15,16 @@ if (return 0 2>/dev/null); then - [ "$my_path" != "" ] || { echo "\$my_path must not be empty"; return 1; } + [[ -v my_path ]] || { echo "\$my_path must not be empty"; return 1; } else echo "This script shall only be sourced" exit 1 fi readonly tty="${WC_TTY:-/dev/ttyUSB2}" -readonly fifo="$(mktemp -u)" -readonly csv_path="${my_path}/data/results${csv_path_suffix}" +fifo="$(mktemp -u)" || exit $? +readonly fifo +readonly csv_path="${my_path}/data/results${csv_path_suffix:-}" function status_echo() { [ "$VERBOSE" = "0" ] || echo "$*" @@ -83,7 +84,7 @@ function process_csv() { [ "$VERBOSE" = "1" ] && echo "$1" else echo "finished" > $fifo - read_tty_ret=return + read_tty_ret='return' fi ;; esac @@ -107,6 +108,10 @@ function bench() { ### function small_block() { + if [[ ! -v small_block_sizes ]]; then + echo '$small_block_sizes is unset.' 1>&2 + return 1 + fi for blocksize in $small_block_sizes do status_echo "Benchmark with $blocksize bytes sized blocks" @@ -119,6 +124,18 @@ function small_block() { } function large_block() { + if [[ ! -v large_block_ciphers ]]; then + echo '$large_block_ciphers is unset.' 1>&2 + return 1 + fi + if [[ ! -v large_max_blocksize ]]; then + echo '$large_max_blocksize is unset.' 1>&2 + return 1 + fi + if [[ ! -v large_num_bytes ]]; then + echo '$large_num_bytes is unset.' 1>&2 + return 1 + fi # 1 MiB local blocksize=$((1024 * 1024)) while [ $blocksize -lt $large_max_blocksize ]