Skip to contentSkip to conversation

seltests/zram: fix syntax error

PATCH In review Zhang Zhen 2 participants 2 messages Sep 14, 2015 3 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): 1442203768-35696-1-git-send-email-zhenzhang.zhang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org

Zhang Zhen

author
#2 lore raw

PATCH 1/1 seltests/zram: fix syntax error

Not all shells define a variable UID. This is a bash and zsh feature only. In other shells, the UID variable is not defined, so here test command expands to [ != 0 ] which is a syntax error.

Without this patch:

root@HGH1000007090:/opt/work/linux/tools/testing/selftests/zram# sh zram.sh
zram.sh: 8: [: !=: unexpected operator
zram.sh : No zram.ko module or /dev/zram0 device file not found
zram.sh : CONFIG_ZRAM is not set

With this patch:

root@HGH1000007090:/opt/work/linux/tools/testing/selftests/zram# sh ./zram.sh
zram.sh : No zram.ko module or /dev/zram0 device file not found
zram.sh : CONFIG_ZRAM is not set
---
 tools/testing/selftests/zram/zram.sh     | 10 +---------
 tools/testing/selftests/zram/zram_lib.sh |  3 ++-
 2 files changed, 3 insertions(+), 10 deletions(-)
tools/testing/selftests/zram/zram.sh +1 -9
index 20de9a7..683a292 100755
@@ -1,15 +1,7 @@
 #!/bin/bash
 TCID="zram.sh"
 
-check_prereqs()
-{
-	local msg="skip all tests:"
-
-	if [ $UID != 0 ]; then
-		echo $msg must be run as root >&2
-		exit 0
-	fi
-}
+. ./zram_lib.sh
 
 run_zram () {
 echo "--------------------"
tools/testing/selftests/zram/zram_lib.sh +2 -1
index 424e68e..f561a17 100755
@@ -23,8 +23,9 @@ trap INT
 check_prereqs()
 {
 	local msg="skip all tests:"
+	local uid=$(id -u)
 
-	if [ $UID != 0 ]; then
+	if [ $uid -ne 0 ]; then
 		echo $msg must be run as root >&2
 		exit 0
 	fi
Signature · 4 lines
1.9.1


.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 15 lines · Zhang Zhen

Not all shells define a variable UID. This is a bash and zsh feature only. In other shells, the UID variable is not defined, so here test command expands to [ != 0 ] which is a syntax error.

Without this patch:

root@HGH1000007090:/opt/work/linux/tools/testing/selftests/zram# sh zram.sh
zram.sh: 8: [: !=: unexpected operator
zram.sh : No zram.ko module or /dev/zram0 device file not found
zram.sh : CONFIG_ZRAM is not set

With this patch:

root@HGH1000007090:/opt/work/linux/tools/testing/selftests/zram# sh ./zram.sh
zram.sh : No zram.ko module or /dev/zram0 device file not found
zram.sh : CONFIG_ZRAM is not set
Quoted 6 lines
---
 tools/testing/selftests/zram/zram.sh     | 10 +---------
 tools/testing/selftests/zram/zram_lib.sh |  3 ++-
 2 files changed, 3 insertions(+), 10 deletions(-)

Thanks for fixing this. Applied to linux-kselftest fixes for 4.3-rc2

-- Shuah

Signature · 5 lines
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
[email protected] | (970) 217-8978