From 54c49e7c9adac78ac435d454e28cb6e2f8f089ab Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Wed, 16 Mar 2022 13:34:10 +0530 Subject: [PATCH] LU-15626 tests: Fix "error" reported by shellcheck for functions.sh This patch fixes "error" issues reported by shellcheck for functions.sh. This patch also moves spaces to tabs. Test-Parameters: trivial Test-Parameters: testlist=sanity,sanityn Signed-off-by: Arshad Hussain Change-Id: Iec24ca81b16994c3bfbdc38d8106576a315e0bbd Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/46834 Reviewed-by: Andreas Dilger Reviewed-by: Jian Yu Reviewed-by: Oleg Drokin Tested-by: jenkins Tested-by: Maloo --- lustre/tests/functions.sh | 389 ++++++++++++++++++++++++---------------------- 1 file changed, 199 insertions(+), 190 deletions(-) diff --git a/lustre/tests/functions.sh b/lustre/tests/functions.sh index 1807bb8..68f63aa 100644 --- a/lustre/tests/functions.sh +++ b/lustre/tests/functions.sh @@ -3,14 +3,15 @@ # Simple function used by run_*.sh scripts assert_env() { - local failed="" - for name in $@; do - if [ -z "${!name}" ]; then - echo "$0: $name must be set" - failed=1 - fi - done - [ $failed ] && exit 1 || true + local failed="" + + for name in "$@"; do + if [ -z "${!name}" ]; then + echo "$0: $name must be set" + failed=1 + fi + done + [ $failed ] && exit 1 || true } # lrepl - Lustre test Read-Eval-Print Loop. @@ -19,11 +20,11 @@ assert_env() { # doesn't exec an actual shell because the user may want to inspect # variables and use functions from the test framework. lrepl() { - local line - local rawline - local prompt + local line + local rawline + local prompt - cat < ' rawline - do - line="$line"$'\n'"$rawline" - case "$rawline" in - # We could check for here documents by matching - # against *<<*, but who cares. - *\\) continue;; - *) break;; - esac - done - ;; - *) line=$rawline - esac - - case "$line" in - *\\) break;; - esac - - # Finally! Time to eval. - eval "$line" - done - - echo $'\n\tExiting interactive shell...\n' - return 0 + # Prompt escapes don't work in read -p, sadly. + prompt=":${TESTNAME:-UNKNOWN}:$(uname -n):$(basename $PWD)% " + + # We use read -r to get close to a shell experience + while read -e -r -p "$prompt" rawline; do + line= + case "$rawline" in + # Don't want to exit-exit, just exit the REPL + exit) break;; + # We need to handle continuations, and read -r doesn't do + # that for us. Yet we need read -r. + # + # We also use case/esac to compare lines read to "*\\" + # because [ "$line" = *\\ ] and variants of that don't work. + *\\) line="$rawline" + while read -e -r -p '> ' rawline + do + line="$line"$'\n'"$rawline" + case "$rawline" in + # We could check for here documents by matching + # against *<<*, but who cares. + *\\) continue;; + *) break;; + esac + done + ;; + *) line=$rawline + esac + + case "$line" in + *\\) break;; + esac + + # Finally! Time to eval. + eval "$line" + done + + echo $'\n\tExiting interactive shell...\n' + return 0 } # lassert - Lustre test framework assert @@ -101,22 +102,22 @@ EOF # If the REPL sets retcode=0 then the assertion failure will be # ignored. lassert() { - local retcode=$1 - local msg=$2 - shift 2 - - echo "checking $* ($(eval echo \""$*"\"))..." - eval "$@" && return 0; - - if ${REPL_ON_LASSERT:-false}; then - echo "Assertion $retcode failed: $* (expanded: $(eval echo \""$*"\")) -$msg" - lrepl - fi - - error "Assertion $retcode failed: $* (expanded: $(eval echo \""$*"\")) -$msg" - return $retcode + local retcode=$1 + local msg=$2 + shift 2 + + echo "checking $* ($(eval echo \""$*"\"))..." + eval "$@" && return 0; + + if ${REPL_ON_LASSERT:-false}; then + echo "Assertion $retcode failed: $* + (expanded: $(eval echo \""$*"\")) $msg" + lrepl + fi + + error "Assertion $retcode failed: $* + (expanded: $(eval echo \""$*"\")) $msg" + return $retcode } # setmodopts- set module options for subsequent calls to load_modules @@ -160,12 +161,12 @@ setmodopts() { echoerr () { echo "$@" 1>&2 ; } signaled() { - echoerr "$(date +'%F %H:%M:%S'): client load was signaled to terminate" + echoerr "$(date +'%F %H:%M:%S'): client load was signaled to terminate" - local PGID=$(ps -eo "%c %p %r" | awk "/ $PPID / {print \$3}") - kill -TERM -$PGID - sleep 5 - kill -KILL -$PGID + local PGID=$(ps -eo "%c %p %r" | awk "/ $PPID / {print \$3}") + kill -TERM -$PGID + sleep 5 + kill -KILL -$PGID } mpi_run () { @@ -206,45 +207,45 @@ nids_list () { # FIXME: all setup/cleanup can be done without rpc.sh lst_end_session () { - local verbose=false - [ x$1 = x--verbose ] && verbose=true + local verbose=false + [ x$1 = x--verbose ] && verbose=true - export LST_SESSION=`$LST show_session 2>/dev/null | awk -F " " '{print $5}'` - [ "$LST_SESSION" == "" ] && return + export LST_SESSION=`$LST show_session 2>/dev/null | awk '{print $5}'` + [ "$LST_SESSION" == "" ] && return $LST stop b - if $verbose; then - $LST show_error c s - fi - $LST end_session + if $verbose; then + $LST show_error c s + fi + $LST end_session } lst_session_cleanup_all () { - local list=$(comma_list $(nodes_list)) - do_rpc_nodes $list lst_end_session + local list=$(comma_list $(nodes_list)) + do_rpc_nodes $list lst_end_session } lst_cleanup () { - lsmod | grep -q lnet_selftest && \ - rmmod lnet_selftest > /dev/null 2>&1 || true + lsmod | grep -q lnet_selftest && \ + rmmod lnet_selftest > /dev/null 2>&1 || true } lst_cleanup_all () { - local list=$(comma_list $(nodes_list)) + local list=$(comma_list $(nodes_list)) - # lst end_session needs to be executed only locally - # i.e. on node where lst new_session was called - lst_end_session --verbose - do_rpc_nodes $list lst_cleanup + # lst end_session needs to be executed only locally + # i.e. on node where lst new_session was called + lst_end_session --verbose + do_rpc_nodes $list lst_cleanup } lst_setup () { - load_module lnet_selftest + load_module lnet_selftest } lst_setup_all () { - local list=$(comma_list $(nodes_list)) - do_rpc_nodes $list lst_setup + local list=$(comma_list $(nodes_list)) + do_rpc_nodes $list lst_setup } ### @@ -254,7 +255,7 @@ lst_setup_all () { # and includes the first period. # client-20.lab.whamcloud.com becomes client-20 short_hostname() { - echo $(sed 's/\..*//' <<< $1) + echo $(sed 's/\..*//' <<< $1) } ### @@ -271,15 +272,15 @@ short_nodename() { } print_opts () { - local var + local var - echo OPTIONS: + echo OPTIONS: - for i in $@; do - var=$i - echo "${var}=${!var}" - done - [ -e $MACHINEFILE ] && cat $MACHINEFILE + for i in "$@"; do + var=$i + echo "${var}=${!var}" + done + [ -e $MACHINEFILE ] && cat $MACHINEFILE } is_lustre () { @@ -336,20 +337,20 @@ run_compilebench() { test_mkdir -p $testdir setstripe_getstripe $testdir $cbench_STRIPEPARAMS - local savePWD=$PWD - cd $cbench_DIR - local cmd="./compilebench -D $testdir -i $cbench_IDIRS \ - -r $cbench_RUNS --makej" + local savePWD=$PWD + cd $cbench_DIR + local cmd="./compilebench -D $testdir -i $cbench_IDIRS \ + -r $cbench_RUNS --makej" - log "$cmd" + log "$cmd" - local rc=0 - eval $cmd - rc=$? + local rc=0 + eval $cmd + rc=$? - cd $savePWD - [ $rc = 0 ] || error "compilebench failed: $rc" - rm -rf $testdir + cd $savePWD + [ $rc = 0 ] || error "compilebench failed: $rc" + rm -rf $testdir } run_metabench() { @@ -439,11 +440,12 @@ run_simul() { -np $((num_clients * simul_THREADS)) $cmd fi - local rc=$? - if [ $rc != 0 ] ; then - error "simul failed! $rc" - fi - rm -rf $testdir + local rc=$? + + if [ $rc != 0 ] ; then + error "simul failed! $rc" + fi + rm -rf $testdir } run_mdtest() { @@ -509,10 +511,11 @@ run_mdtest() { -np $((num_clients * mdtest_THREADS)) $cmd fi - local rc=$? - if [ $rc != 0 ] ; then - error "mdtest failed! $rc" - fi + local rc=$? + + if [ $rc != 0 ] ; then + error "mdtest failed! $rc" + fi rm -rf $testdir for ((i=1; i num_files current - rm -rf $testdir - cleanup_statahead $clients $mntpt_root $num_mntpts + # use rm instead of rmdir because of + # testdir could contain the files created by someone else, + # or by previous run where is num_files prev > num_files current + rm -rf $testdir + cleanup_statahead $clients $mntpt_root $num_mntpts } cleanup_rr_alloc () { @@ -1150,7 +1159,7 @@ run_fs_test() { echo "+ $fs_test_objsize * $fs_test_objunit * $total_threads " if [ $((space / 2)) -le \ $((fs_test_objsize * fs_test_objunit * total_threads)) ]; then - fs_test_objsize=$((space / 2 / fs_test_objunit / \ + fs_test_objsize=$((space / 2 / fs_test_objunit / total_threads)) [ $fs_test_objsize -eq 0 ] && skip_env "Need free space more than \ -- 1.8.3.1