selftests: make shell scripts POSIX-compliant
Subsystems (6)
PATCH 1/1 selftests: make shell scripts POSIX-compliant
Changes include:
- Replaced [[ ... ]] with [ ... ]
- Replaced == with =
- Replaced printf -v with cur=$(printf ...).
- Replaced echo -e with printf "%b\n" ...
The above mentioned are Bash/GNU extensions and are not part of POSIX. Using shells like dash or non-GNU coreutils may produce errors. They have been replaced with POSIX-compatible alternatives.
---
I have made sure to only change the files that specifically have the /bin/sh shebang.
I have referred to https://mywiki.wooledge.org/Bashism for information on what is and what isn't POSIX-compliant.
tools/testing/selftests/cgroup/test_cpuset_v1_hp.sh | 10 +++++----- tools/testing/selftests/kexec/kexec_common_lib.sh | 2 +- tools/testing/selftests/kexec/test_kexec_file_load.sh | 2 +- tools/testing/selftests/net/veth.sh | 10 +++++----- tools/testing/selftests/powerpc/eeh/eeh-vf-aware.sh | 2 +- tools/testing/selftests/zram/zram_lib.sh | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-)
tools/testing/selftests/cgroup/test_cpuset_v1_hp.sh +5 -5
@@ -11,24 +11,24 @@ skip_test() { exit 4 # ksft_skip } -[[ $(id -u) -eq 0 ]] || skip_test "Test must be run as root!" +[ $(id -u) -eq 0 ] || skip_test "Test must be run as root!" # Find cpuset v1 mount point CPUSET=$(mount -t cgroup | grep cpuset | head -1 | awk -e '{print $3}') -[[ -n "$CPUSET" ]] || skip_test "cpuset v1 mount point not found!" +[ -n "$CPUSET" ] || skip_test "cpuset v1 mount point not found!" # # Create a test cpuset, put a CPU and a task there and offline that CPU # TDIR=test$$ -[[ -d $CPUSET/$TDIR ]] || mkdir $CPUSET/$TDIR +[ -d $CPUSET/$TDIR ] || mkdir $CPUSET/$TDIR echo 1 > $CPUSET/$TDIR/cpuset.cpus echo 0 > $CPUSET/$TDIR/cpuset.mems sleep 10& TASK=$! echo $TASK > $CPUSET/$TDIR/tasks NEWCS=$(cat /proc/$TASK/cpuset) -[[ $NEWCS != "/$TDIR" ]] && { +[ $NEWCS != "/$TDIR" ] && { echo "Unexpected cpuset $NEWCS, test FAILED!" exit 1 }
@@ -38,7 +38,7 @@ sleep 0.5 echo 1 > /sys/devices/system/cpu/cpu1/online NEWCS=$(cat /proc/$TASK/cpuset) rmdir $CPUSET/$TDIR -[[ $NEWCS != "/" ]] && { +[ $NEWCS != "/" ] && { echo "cpuset $NEWCS, test FAILED!" exit 1 }
tools/testing/selftests/kexec/kexec_common_lib.sh +1 -1
@@ -96,7 +96,7 @@ get_secureboot_mode() local secureboot_mode=0 local system_arch=$(get_arch) - if [ "$system_arch" == "ppc64le" ]; then + if [ "$system_arch" = "ppc64le" ]; then get_ppc64_secureboot_mode secureboot_mode=$? else
tools/testing/selftests/kexec/test_kexec_file_load.sh +1 -1
@@ -226,7 +226,7 @@ get_secureboot_mode secureboot=$? # Are there pe and ima signatures -if [ "$(get_arch)" == 'ppc64le' ]; then +if [ "$(get_arch)" = 'ppc64le' ]; then pe_signed=0 else check_for_pesig
tools/testing/selftests/net/veth.sh +5 -5
@@ -137,7 +137,7 @@ __change_channels() local i while true; do - printf -v cur '%(%s)T' + cur=$(printf '%(%s)T') [ $cur -le $end ] || break for i in `seq 1 $CPUS`; do
@@ -157,7 +157,7 @@ __send_data() { local end=$1 while true; do - printf -v cur '%(%s)T' + cur=$(printf '%(%s)T') [ $cur -le $end ] || break ip netns exec $NS_SRC ./udpgso_bench_tx -4 -s 1000 -M 300 -D $BM_NET_V4$DST
@@ -166,7 +166,7 @@ __send_data() { do_stress() { local end - printf -v end '%(%s)T' + cur=$(printf '%(%s)T') end=$((end + $STRESS)) ip netns exec $NS_SRC ethtool -L veth$SRC rx 3 tx 3
@@ -198,8 +198,8 @@ do_stress() { usage() { echo "Usage: $0 [-h] [-s <seconds>]" - echo -e "\t-h: show this help" - echo -e "\t-s: run optional stress tests for the given amount of seconds" + printf "%b\n" "\t-h: show this help" + printf "%b\n" "\t-s: run optional stress tests for the given amount of seconds" } STRESS=0
tools/testing/selftests/powerpc/eeh/eeh-vf-aware.sh +1 -1
@@ -36,7 +36,7 @@ done eeh_disable_vfs -if [ "$tested" == 0 ] ; then +if [ "$tested" = 0 ] ; then echo "No VFs with EEH aware drivers found, skipping" exit $KSELFTESTS_SKIP fi
tools/testing/selftests/zram/zram_lib.sh +1 -1
@@ -37,7 +37,7 @@ kernel_gte() if [ $kernel_major -gt $major ]; then return 0 - elif [[ $kernel_major -eq $major && $kernel_minor -ge $minor ]]; then + elif [ $kernel_major -eq $major && $kernel_minor -ge $minor ]; then return 0 fi
Signature · 1 line
2.34.1
Tejun Heo
maintainerQuoted 9 lines · Aditya Dutt
Changes include:
- Replaced [[ ... ]] with [ ... ]
- Replaced == with =
- Replaced printf -v with cur=$(printf ...).
- Replaced echo -e with printf "%b\n" ...The above mentioned are Bash/GNU extensions and are not part of POSIX. Using shells like dash or non-GNU coreutils may produce errors. They have been replaced with POSIX-compatible alternatives.
Maybe just update them to use /bin/bash instead? There haven't been a lot of reports of actual breakges and a lot of existing tests are using /bin/bash already.
Thanks.
Signature · 1 line
tejun
Quoted 7 lines · Tejun Heo
Quoted 6 lines · Aditya Dutt
Changes include:
- Replaced [[ ... ]] with [ ... ]
- Replaced == with =
- Replaced printf -v with cur=$(printf ...).
- Replaced echo -e with printf "%b\n" ...
Quoted 7 lines
Quoted 3 lines
The above mentioned are Bash/GNU extensions and are not part of POSIX. Using shells like dash or non-GNU coreutils may produce errors. They have been replaced with POSIX-compatible alternatives.
Maybe just update them to use
/bin/bashinstead? There haven't been a lot of reports of actual breakges and a lot of existing tests are using/bin/bashalready.
+1
Hangbin
Quoted 60 lines · Aditya Dutt
Changes include:
- Replaced [[ ... ]] with [ ... ]
- Replaced == with =
- Replaced printf -v with cur=$(printf ...).
- Replaced echo -e with printf "%b\n" ...The above mentioned are Bash/GNU extensions and are not part of POSIX. Using shells like dash or non-GNU coreutils may produce errors. They have been replaced with POSIX-compatible alternatives.
Signed-off-by Aditya Dutt <[email protected]>---
I have made sure to only change the files that specifically have the
/bin/shshebang.
I have referred to https://mywiki.wooledge.org/Bashism for information on what is and what isn't POSIX-compliant.tools/testing/selftests/cgroup/test_cpuset_v1_hp.sh | 10 +++++----- tools/testing/selftests/kexec/kexec_common_lib.sh | 2 +- tools/testing/selftests/kexec/test_kexec_file_load.sh | 2 +- tools/testing/selftests/net/veth.sh | 10 +++++----- tools/testing/selftests/powerpc/eeh/eeh-vf-aware.sh | 2 +- tools/testing/selftests/zram/zram_lib.sh | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-)tools/testing/selftests/cgroup/test_cpuset_v1_hp.sh +4
-4@@ -11,24 +11,24 @@ skip_test() { exit 4 # ksft_skip } -[[ $(id -u) -eq 0 ]] || skip_test "Test must be run as root!" +[ $(id -u) -eq 0 ] || skip_test "Test must be run as root!" # Find cpuset v1 mount point CPUSET=$(mount -t cgroup | grep cpuset | head -1 | awk -e '{print $3}') -[[ -n "$CPUSET" ]] || skip_test "cpuset v1 mount point not found!" +[ -n "$CPUSET" ] || skip_test "cpuset v1 mount point not found!" # # Create a test cpuset, put a CPU and a task there and offline that CPU # TDIR=test$$ -[[ -d $CPUSET/$TDIR ]] || mkdir $CPUSET/$TDIR +[ -d $CPUSET/$TDIR ] || mkdir $CPUSET/$TDIR echo 1 > $CPUSET/$TDIR/cpuset.cpus echo 0 > $CPUSET/$TDIR/cpuset.mems sleep 10& TASK=$! echo $TASK > $CPUSET/$TDIR/tasks NEWCS=$(cat /proc/$TASK/cpuset) -[[ $NEWCS != "/$TDIR" ]] && { +[ $NEWCS != "/$TDIR" ] && { echo "Unexpected cpuset $NEWCS, test FAILED!" exit 1 }
tools/testing/selftests/cgroup/test_cpuset_v1_hp.sh sleep 0.5 · line 44
Quoted 8 lines
tools/testing/selftests/cgroup/test_cpuset_v1_hp.sh +1
-1@@ -38,7 +38,7 @@ sleep 0.5 echo 1 > /sys/devices/system/cpu/cpu1/online NEWCS=$(cat /proc/$TASK/cpuset) rmdir $CPUSET/$TDIR -[[ $NEWCS != "/" ]] && { +[ $NEWCS != "/" ] && { echo "cpuset $NEWCS, test FAILED!" exit 1 }
test_cpuset_v1_hp.sh had been changed to use /bin/bash in v6.14 by commit fd079124112c ("selftests/cgroup: use bash in test_cpuset_v1_hp.sh").
Cheers,
Longman