test: Shellcheck - apply rule SC2181

Check exit code directly with e.g. 'if mycmd;',
not indirectly with $?.

Rule disabled in test/pmem/common.sh as behaviour
may differ depends on bash version

Change-Id: Ied4c5dfb09e52c5db08becf1ad69a29a1bda426b
Signed-off-by: Pawel Kaminski <pawelx.kaminski@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/468363
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Maciej Wawryk <maciejx.wawryk@intel.com>
Reviewed-by: Karol Latecki <karol.latecki@intel.com>
This commit is contained in:
Pawel Kaminski 2019-09-13 10:40:15 -04:00 committed by Tomasz Zawadzki
parent 418992173b
commit 7f0efebdf3
7 changed files with 14 additions and 31 deletions

View File

@ -247,7 +247,7 @@ SC2027,SC2030,SC2031,SC2034,SC2035,SC2039,SC2043,SC2044,SC2045,SC2046,\
SC2068,SC2086,SC2089,SC2090,\ SC2068,SC2086,SC2089,SC2090,\
SC2097,SC2098,SC2103,SC2115,SC2116,SC2119,SC2120,SC2121,SC2124,SC2126,SC2128,\ SC2097,SC2098,SC2103,SC2115,SC2116,SC2119,SC2120,SC2121,SC2124,SC2126,SC2128,\
SC2129,SC2140,SC2142,SC2143,SC2145,SC2146,SC2148,SC2152,SC2153,SC2154,SC2155,\ SC2129,SC2140,SC2142,SC2143,SC2145,SC2146,SC2148,SC2152,SC2153,SC2154,SC2155,\
SC2162,SC2164,SC2165,SC2166,SC2167,SC2174,SC2178,SC2181,\ SC2162,SC2164,SC2165,SC2166,SC2167,SC2174,SC2178,\
SC2206,SC2207,SC2214,SC2223,SC2230,SC2231" SC2206,SC2207,SC2214,SC2223,SC2230,SC2231"
# SPDK fails some error checks which have been deprecated in later versions of shellcheck. # 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 # We will not try to fix these error checks, but instead just leave the error types here

View File

@ -54,8 +54,7 @@ dev=$(iscsiadm -m session -P 3 | grep "Attached scsi disk" | awk '{print $4}')
set +e set +e
waitforfile /dev/$dev waitforfile /dev/$dev
mkfs.ext4 -F /dev/$dev if mkfs.ext4 -F /dev/$dev; then
if [ $? -eq 0 ]; then
echo "mkfs successful - expected failure" echo "mkfs successful - expected failure"
iscsicleanup iscsicleanup
killprocess $pid killprocess $pid

View File

@ -150,8 +150,7 @@ function nvmfcleanup()
set +e set +e
for i in {1..20}; do for i in {1..20}; do
modprobe -v -r nvme-$TEST_TRANSPORT modprobe -v -r nvme-$TEST_TRANSPORT
modprobe -v -r nvme-fabrics if modprobe -v -r nvme-fabrics; then
if [ $? -eq 0 ]; then
set -e set -e
return return
fi fi
@ -260,8 +259,7 @@ function nvme_connect()
{ {
local init_count=$(nvme list | wc -l) local init_count=$(nvme list | wc -l)
nvme connect $@ if ! nvme connect $@; then return $?; fi
if [ $? != 0 ]; then return $?; fi
for i in $(seq 1 10); do for i in $(seq 1 10); do
if [ $(nvme list | wc -l) -gt $init_count ]; then if [ $(nvme list | wc -l) -gt $init_count ]; then

View File

@ -70,10 +70,6 @@ function vhost_start()
local vhost_pid local vhost_pid
$rootdir/app/vhost/vhost & $rootdir/app/vhost/vhost &
if [ $? != 0 ]; then
echo -e "ERROR: Failed to launch vhost!"
return 1
fi
vhost_pid=$! vhost_pid=$!
echo $vhost_pid > $testdir/vhost.pid echo $vhost_pid > $testdir/vhost.pid

View File

@ -292,8 +292,7 @@ function bdev_pmem_create_pool_tc6()
error "Failed to create pmem pool!" error "Failed to create pmem pool!"
fi fi
created_pmem_block_size=$($rpc_py bdev_pmem_get_pool_info $default_pool_file | jq -r '.[] .block_size') if ! created_pmem_block_size=$($rpc_py bdev_pmem_get_pool_info $default_pool_file | jq -r '.[] .block_size'); then
if [ $? != 0 ]; then
error "Failed to get pmem info!" error "Failed to get pmem info!"
fi fi
@ -524,8 +523,7 @@ function bdev_pmem_create_tc5()
error "Failed to get pmem info!" error "Failed to get pmem info!"
fi fi
pmem_bdev_name=$($rpc_py bdev_pmem_create -n $bdev_name $default_pool_file) if ! pmem_bdev_name=$($rpc_py bdev_pmem_create -n $bdev_name $default_pool_file); then
if [ $? != 0 ]; then
error "Failed to create pmem bdev" error "Failed to create pmem bdev"
fi fi
@ -556,8 +554,7 @@ function bdev_pmem_create_tc6()
error "Failed to get info on pmem pool file!" error "Failed to get info on pmem pool file!"
fi fi
pmem_bdev_name=$($rpc_py bdev_pmem_create -n $bdev_name $default_pool_file) if ! pmem_bdev_name=$($rpc_py bdev_pmem_create -n $bdev_name $default_pool_file); then
if [ $? != 0 ]; then
error "Failed to create pmem bdev!" error "Failed to create pmem bdev!"
fi fi
@ -596,8 +593,7 @@ function delete_bdev_tc1()
error "Failed to get pmem info!" error "Failed to get pmem info!"
fi fi
pmem_bdev_name=$($rpc_py bdev_pmem_create -n $bdev_name $default_pool_file) if ! pmem_bdev_name=$($rpc_py bdev_pmem_create -n $bdev_name $default_pool_file); then
if [ $? != 0 ]; then
error "Failed to create pmem bdev!" error "Failed to create pmem bdev!"
fi fi
@ -629,8 +625,7 @@ function delete_bdev_tc2()
error "Failed to get pmem info!" error "Failed to get pmem info!"
fi fi
pmem_bdev_name=$($rpc_py bdev_pmem_create -n $bdev_name $default_pool_file) if ! pmem_bdev_name=$($rpc_py bdev_pmem_create -n $bdev_name $default_pool_file); then
if [ $? != 0 ]; then
error "Failed to create pmem bdev" error "Failed to create pmem bdev"
fi fi

View File

@ -31,27 +31,23 @@ if [[ ! -b "/dev/$disk_name"1"" ]]; then
error "Partition not found!" error "Partition not found!"
fi fi
mkdir $testdir/$test_folder_name if ! mkdir $testdir/$test_folder_name; then
if [[ $? != 0 ]]; then
error "Failed to create test folder $test_folder_name" error "Failed to create test folder $test_folder_name"
fi fi
echo "INFO: Mounting partition" echo "INFO: Mounting partition"
mount /dev/$disk_name"1" $testdir/$test_folder_name if ! mount /dev/$disk_name"1" $testdir/$test_folder_name; then
if [[ $? != 0 ]]; then
error "Failed to mount partition $disk_name""1" error "Failed to mount partition $disk_name""1"
fi fi
echo "INFO: Trying to create file on readonly disk" echo "INFO: Trying to create file on readonly disk"
truncate -s "200M" $test_folder_name/$test_file_name"_on_readonly" if truncate -s "200M" $test_folder_name/$test_file_name"_on_readonly"; then
if [[ $? == 0 ]]; then
error "Created a file on a readonly disk!" error "Created a file on a readonly disk!"
fi fi
if [[ -f $test_folder_name/$test_file_name ]]; then if [[ -f $test_folder_name/$test_file_name ]]; then
echo "INFO: Trying to delete previously created file" echo "INFO: Trying to delete previously created file"
rm $test_folder_name/$test_file_name if rm $test_folder_name/$test_file_name; then
if [[ $? == 0 ]]; then
error "Deleted a file from a readonly disk!" error "Deleted a file from a readonly disk!"
fi fi
else else

View File

@ -69,8 +69,7 @@ function blk_ro_tc1()
local vm_dir="$VHOST_DIR/vms/$vm_no" local vm_dir="$VHOST_DIR/vms/$vm_no"
if [[ $disk =~ .*malloc.* ]]; then if [[ $disk =~ .*malloc.* ]]; then
disk_name=$($rpc_py bdev_malloc_create 512 4096) if ! disk_name=$($rpc_py bdev_malloc_create 512 4096); then
if [ $? != 0 ]; then
fail "Failed to create malloc bdev" fail "Failed to create malloc bdev"
fi fi