From 4d0c5091a99adba3c51bceef39f67e5991131159 Mon Sep 17 00:00:00 2001 From: Pawel Kaminski Date: Fri, 25 Oct 2019 08:49:18 +0000 Subject: [PATCH] test: Shellcheck - add rule SC2154 to exclude list Corrected code in some files. Most of cases cannot be corrected as we use global variables defined in other files. SC2154: var is referenced but not assigned. Signed-off-by: Pawel Kaminski Change-Id: Id333587f81b0bc2456b0c97bac5343a8e5a22774 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/472342 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- scripts/check_format.sh | 7 ++++--- test/vhost/common.sh | 2 +- test/vhost/fiotest/fio.sh | 3 +++ test/vhost/hotplug/common.sh | 3 +++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/check_format.sh b/scripts/check_format.sh index b0e2c4340..01a7e0378 100755 --- a/scripts/check_format.sh +++ b/scripts/check_format.sh @@ -243,7 +243,7 @@ if hash shellcheck 2>/dev/null; then SHCK_EXCLUDE="SC1083,SC2002,\ SC2010,SC2012,SC2016,SC2034,SC2045,SC2046,SC2068,SC2086,SC2089,SC2090,\ SC2097,SC2098,SC2119,SC2120,SC2128,\ -SC2129,SC2140,SC2142,SC2143,SC2154" +SC2129,SC2140,SC2142,SC2143" # SPDK fails some error checks which have been deprecated in later versions of shellcheck. # We will not try to fix these error checks, but instead just leave the error types here # so that we can still run with older versions of shellcheck. @@ -255,13 +255,14 @@ SC2129,SC2140,SC2142,SC2143,SC2154" # SC2001: See if you can use ${variable//search/replace} instead. # SC2148: Add shebang to the top of your script. # SC2153: Possible Misspelling: MYVARIABLE may not be assigned, but MY_VARIABLE is. + # SC2154: var is referenced but not assigned. # SC2164: Use cd ... || exit in case cd fails. # SC2174: When used with -p, -m only applies to the deepest directory. # SC2206: Quote to prevent word splitting/globbing, # or split robustly with mapfile or read -a. # SC2207: Prefer mapfile or read -a to split command output (or quote to avoid splitting). # SC2223: This default assignment may cause DoS due to globbing. Quote it. - SHCK_EXCLUDE="$SHCK_EXCLUDE,SC1090,SC1091,SC2148,SC2153,SC2164,\ + SHCK_EXCLUDE="$SHCK_EXCLUDE,SC1090,SC1091,SC2148,SC2153,SC2154,SC2164,\ SC2174,SC2001,SC2206,SC2207,SC2223" SHCK_FORMAT="diff" @@ -270,7 +271,7 @@ SC2174,SC2001,SC2206,SC2207,SC2223" SHCK_FORMAT="tty" SHCK_APPLY=false fi - SHCH_ARGS=" -e $SHCK_EXCLUDE -f $SHCK_FORMAT" + SHCH_ARGS=" -x -e $SHCK_EXCLUDE -f $SHCK_FORMAT" error=0 git ls-files '*.sh' | xargs -P$(nproc) -n1 shellcheck $SHCH_ARGS &> shellcheck.log || error=1 diff --git a/test/vhost/common.sh b/test/vhost/common.sh index 10f05c792..f264a8a5a 100644 --- a/test/vhost/common.sh +++ b/test/vhost/common.sh @@ -598,7 +598,7 @@ function vm_setup() error "'--incoming' and '--migrate-to' cannot be used together" return 1 elif [[ -n "$vm_incoming" ]]; then - if [[ -n "$os_mode" || -n "$os_img" ]]; then + if [[ -n "$os_mode" || -n "$os" ]]; then error "'--incoming' can't be used together with '--os' nor '--os-mode'" return 1 fi diff --git a/test/vhost/fiotest/fio.sh b/test/vhost/fiotest/fio.sh index 23ac9ef8c..4f9e0854d 100755 --- a/test/vhost/fiotest/fio.sh +++ b/test/vhost/fiotest/fio.sh @@ -15,6 +15,7 @@ reuse_vms=false vms=() used_vms="" x="" +readonly="" function usage() { @@ -39,6 +40,7 @@ function usage() echo " NUM - VM number (mandatory)" echo " OS - VM os disk path (optional)" echo " DISKS - VM os test disks/devices path (virtio - optional, kernel_vhost - mandatory)" + echo " --readonly Use readonly for fio" exit 0 } @@ -55,6 +57,7 @@ while getopts 'xh-:' optchar; do no-shutdown) no_shutdown=true ;; test-type=*) test_type="${OPTARG#*=}" ;; vm=*) vms+=("${OPTARG#*=}") ;; + readonly) readonly="--readonly" ;; *) usage $0 "Invalid argument '$OPTARG'" ;; esac ;; diff --git a/test/vhost/hotplug/common.sh b/test/vhost/hotplug/common.sh index c84273b15..85bd822b9 100644 --- a/test/vhost/hotplug/common.sh +++ b/test/vhost/hotplug/common.sh @@ -15,6 +15,7 @@ disk_split="" x="" scsi_hot_remove_test=0 blk_hot_remove_test=0 +readonly="" function usage() { @@ -36,6 +37,7 @@ function usage() { echo " OS - VM os disk path (optional)" echo " DISKS - VM os test disks/devices path (virtio - optional, kernel_vhost - mandatory)" echo " --scsi-hotremove-test Run scsi hotremove tests" + echo " --readonly Use readonly for fio" exit 0 } @@ -50,6 +52,7 @@ while getopts 'xh-:' optchar; do vm=*) vms+=("${OPTARG#*=}") ;; scsi-hotremove-test) scsi_hot_remove_test=1 ;; blk-hotremove-test) blk_hot_remove_test=1 ;; + readonly) readonly="--readonly" ;; *) usage $0 "Invalid argument '$OPTARG'" ;; esac ;;