diff mbox series

selftests: make shell scripts POSIX-compliant

Message ID 20250216120225.324468-1-duttaditya18@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series selftests: make shell scripts POSIX-compliant | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success Errors and warnings before: 26 (+1) this patch: 26 (+1)
netdev/cc_maintainers warning 11 maintainers not CCed: edumazet@google.com horms@kernel.org naveen@kernel.org kuba@kernel.org npiggin@gmail.com linux-kselftest@vger.kernel.org mkoutny@suse.com mpe@ellerman.id.au christophe.leroy@csgroup.eu hannes@cmpxchg.org pabeni@redhat.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest fail Script eeh-vf-aware.sh not found in tools/testing/selftests/powerpc/eeh/Makefile
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning WARNING: line length of 87 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-02-16--18-00 (tests: 891)

Commit Message

Aditya Dutt Feb. 16, 2025, 12:02 p.m. UTC
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 <duttaditya18@gmail.com>
---

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(-)

Comments

Tejun Heo Feb. 16, 2025, 4:11 p.m. UTC | #1
On Sun, Feb 16, 2025 at 05:32:25PM +0530, Aditya Dutt wrote:
> 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.
Hangbin Liu Feb. 17, 2025, 3 a.m. UTC | #2
On Sun, Feb 16, 2025 at 06:11:51AM -1000, Tejun Heo wrote:
> On Sun, Feb 16, 2025 at 05:32:25PM +0530, Aditya Dutt wrote:
> > 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.

+1

Hangbin
Waiman Long Feb. 18, 2025, 8:44 p.m. UTC | #3
On 2/16/25 7:02 AM, Aditya Dutt wrote:
> 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 <duttaditya18@gmail.com>
> ---
>
> 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(-)
>
> diff --git a/tools/testing/selftests/cgroup/test_cpuset_v1_hp.sh b/tools/testing/selftests/cgroup/test_cpuset_v1_hp.sh
> index 3f45512fb512..00416248670f 100755
> --- a/tools/testing/selftests/cgroup/test_cpuset_v1_hp.sh
> +++ b/tools/testing/selftests/cgroup/test_cpuset_v1_hp.sh
> @@ -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
>   }

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
diff mbox series

Patch

diff --git a/tools/testing/selftests/cgroup/test_cpuset_v1_hp.sh b/tools/testing/selftests/cgroup/test_cpuset_v1_hp.sh
index 3f45512fb512..00416248670f 100755
--- a/tools/testing/selftests/cgroup/test_cpuset_v1_hp.sh
+++ b/tools/testing/selftests/cgroup/test_cpuset_v1_hp.sh
@@ -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
 }
diff --git a/tools/testing/selftests/kexec/kexec_common_lib.sh b/tools/testing/selftests/kexec/kexec_common_lib.sh
index 641ef05863b2..b65616ea67f8 100755
--- a/tools/testing/selftests/kexec/kexec_common_lib.sh
+++ b/tools/testing/selftests/kexec/kexec_common_lib.sh
@@ -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
diff --git a/tools/testing/selftests/kexec/test_kexec_file_load.sh b/tools/testing/selftests/kexec/test_kexec_file_load.sh
index c9ccb3c93d72..072e03c8b1c3 100755
--- a/tools/testing/selftests/kexec/test_kexec_file_load.sh
+++ b/tools/testing/selftests/kexec/test_kexec_file_load.sh
@@ -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
diff --git a/tools/testing/selftests/net/veth.sh b/tools/testing/selftests/net/veth.sh
index 6bb7dfaa30b6..e86f102f9028 100755
--- a/tools/testing/selftests/net/veth.sh
+++ b/tools/testing/selftests/net/veth.sh
@@ -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
diff --git a/tools/testing/selftests/powerpc/eeh/eeh-vf-aware.sh b/tools/testing/selftests/powerpc/eeh/eeh-vf-aware.sh
index 874c11953bb6..18fdf88936f0 100755
--- a/tools/testing/selftests/powerpc/eeh/eeh-vf-aware.sh
+++ b/tools/testing/selftests/powerpc/eeh/eeh-vf-aware.sh
@@ -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
diff --git a/tools/testing/selftests/zram/zram_lib.sh b/tools/testing/selftests/zram/zram_lib.sh
index 21ec1966de76..923dbeb64eaf 100755
--- a/tools/testing/selftests/zram/zram_lib.sh
+++ b/tools/testing/selftests/zram/zram_lib.sh
@@ -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