Skip to content

Commit

Permalink
seltests/zram: fix syntax error
Browse files Browse the repository at this point in the history
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

Signed-off-by: Zhang Zhen <zhenzhang.zhang@huawei.com>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
  • Loading branch information
Zhang Zhen authored and Shuah Khan committed Sep 14, 2015
1 parent 6ff33f3 commit 7ef7cc9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
10 changes: 1 addition & 9 deletions tools/testing/selftests/zram/zram.sh
Original file line number Diff line number Diff line change
@@ -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 "--------------------"
Expand Down
3 changes: 2 additions & 1 deletion tools/testing/selftests/zram/zram_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7ef7cc9

Please sign in to comment.