]> www.infradead.org Git - users/hch/blktests.git/commitdiff
Fix multiple shellcheck warnings
authorBart Van Assche <bvanassche@acm.org>
Tue, 16 Nov 2021 18:22:49 +0000 (10:22 -0800)
committerOmar Sandoval <osandov@osandov.com>
Mon, 22 Nov 2021 19:13:19 +0000 (11:13 -0800)
The latest version of shellcheck reports the following warnings:

check:307:9: warning: Quote arguments to unset so they're not glob expanded. [SC2184]
check:505:10: warning: Quote arguments to unset so they're not glob expanded. [SC2184]
check:506:10: warning: Quote arguments to unset so they're not glob expanded. [SC2184]
check:539:11: warning: Quote arguments to unset so they're not glob expanded. [SC2184]
new:102:19: note: Expansions inside ${..} need to be quoted separately, otherwise they match as patterns. [SC2295]
common/rc:272:37: warning: -ne treats this as an arithmetic expression. Use != to compare as string (or expand explicitly with $((expr))). [SC2309]
tests/block/008:65:10: warning: Quote arguments to unset so they're not glob expanded. [SC2184]
tests/block/008:71:10: warning: Quote arguments to unset so they're not glob expanded. [SC2184]

This patch fixes the above warnings.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
check
common/rc
new
tests/block/008

diff --git a/check b/check
index 0a4e539a5cd956750b3e5cc6745b9eceddd00973..fb400ca765b58ce989d5d7e7539f15f4757580f9 100755 (executable)
--- a/check
+++ b/check
@@ -304,7 +304,7 @@ _cleanup() {
        for key in "${!TEST_DEV_QUEUE_SAVED[@]}"; do
                value="${TEST_DEV_QUEUE_SAVED["$key"]}"
                echo "$value" >"${TEST_DEV_SYSFS}/queue/${key}"
-               unset TEST_DEV_QUEUE_SAVED["$key"]
+               unset "TEST_DEV_QUEUE_SAVED[$key]"
        done
 
        if [[ "${RESTORE_CPUS_ONLINE:-}" ]]; then
@@ -502,8 +502,8 @@ _run_test() {
 
                if (( FALLBACK_DEVICE )); then
                        cleanup_fallback_device
-                       unset TEST_DEV_SYSFS_DIRS["${TEST_DEVS[0]}"]
-                       unset TEST_DEV_PART_SYSFS_DIRS["${TEST_DEVS[0]}"]
+                       unset "TEST_DEV_SYSFS_DIRS[${TEST_DEVS[0]}]"
+                       unset "TEST_DEV_PART_SYSFS_DIRS[${TEST_DEVS[0]}]"
                        TEST_DEVS=()
                fi
 
@@ -536,7 +536,7 @@ _run_group() {
                        group_device_requires
                        if [[ -v SKIP_REASON ]]; then
                                _output_notrun "${group}/*** => $(basename "$TEST_DEV")"
-                               unset TEST_DEVS["$i"]
+                               unset "TEST_DEVS[$i]"
                                unset SKIP_REASON
                        fi
                done
index 85e631470881058c011d40e55d3e1cb5ae7c49f1..0528ce8082563211a8aaea4cc286a7e8ccb8dd2d 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -269,7 +269,7 @@ _require_test_dev_in_hotplug_slot() {
 
        local slt_cap
        slt_cap="$(setpci -s "${parent}" CAP_EXP+14.w)"
-       if [[ $((0x${slt_cap} & 0x60)) -ne 0x60 ]]; then
+       if [[ $((0x${slt_cap} & 0x60)) -ne $((0x60)) ]]; then
                SKIP_REASON="$TEST_DEV is not in a hot pluggable slot"
                return 1
        fi
diff --git a/new b/new
index 51ec2c419556e9cd13b2a5cacd37717917680a3e..41f8b8d5468b035d97d3532c1584756eaed77463 100755 (executable)
--- a/new
+++ b/new
@@ -99,7 +99,7 @@ fi
 for test in tests/"$group"/+([0-9]); do
        :
 done
-seq=${test##tests/$group/+(0)}
+seq=${test##tests/"${group}"/+(0)}
 test_name="${group}/$(printf "%03d" $((seq + 1)))"
 
 cat << EOF > "tests/${test_name}"
index 671c5320854573041f6b84920dc70fb35ffdebee..7445f8f33dae6cfd02e50dde16365fc639a3f300 100755 (executable)
@@ -62,13 +62,13 @@ test_device() {
                        idx=$((RANDOM % ${#online_cpus[@]}))
                        _offline_cpu "${online_cpus[$idx]}"
                        offline_cpus+=("${online_cpus[$idx]}")
-                       unset online_cpus["$idx"]
+                       unset "online_cpus[$idx]"
                        online_cpus=("${online_cpus[@]}")
                else
                        idx=$((RANDOM % ${#offline_cpus[@]}))
                        _online_cpu "${offline_cpus[$idx]}"
                        online_cpus+=("${offline_cpus[$idx]}")
-                       unset offline_cpus["$idx"]
+                       unset "offline_cpus[$idx]"
                        offline_cpus=("${offline_cpus[@]}")
                fi
                end_time=$(date +%s)