Skip to contentSkip to conversation

selftests/cpu-hotplug: Use $(id -u) instead of $UID for root check

PATCH New Darren Chang 1 participant 2 messages Oct 22

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 selftests/cpu-hotplug: Use $(id -u) instead of $UID for root check

$UID is a bash-specific variable and is not defined in other shells such as Android's /system/bin/sh (mksh) or POSIX sh. When running this test on environments without bash (e.g. Android), $UID is unset and '[ $UID != 0 ]' expands to '[ != 0 ]', causing a syntax error.

Replace $UID with "$(id -u)" so the root privilege check works across different shells.

---
 tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh +1 -1
index 287cfd5809f6..6653507b9348 100755
@@ -10,7 +10,7 @@ prerequisite()
 {
 	msg="skip all tests:"
 
-	if [ $UID != 0 ]; then
+	if [ "$(id -u)" -ne 0 ]; then
 		echo $msg must be run as root >&2
 		exit $ksft_skip
 	fi
Signature · 1 line
2.56.0.257.gf7497c7d27-goog
#1 lore raw

PATCH 2/2 selftests/memory-hotplug: Use $(id -u) instead of $UID for root check

$UID is a bash-specific variable and is not defined in other shells such as Android's /system/bin/sh (mksh) or POSIX sh. When running this test on environments without bash (e.g. Android), $UID is unset and '[ $UID != 0 ]' expands to '[ != 0 ]', causing a syntax error.

Replace $UID with "$(id -u)" so the root privilege check works across different shells.

---
 tools/testing/selftests/memory-hotplug/mem-on-off-test.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/memory-hotplug/mem-on-off-test.sh +1 -1
index 611be86eaf3d..11fb70bf1833 100755
@@ -10,7 +10,7 @@ prerequisite()
 {
 	msg="skip all tests:"
 
-	if [ $UID != 0 ]; then
+	if [ "$(id -u)" -ne 0 ]; then
 		echo $msg must be run as root >&2
 		exit $ksft_skip
 	fi
Signature · 1 line
2.56.0.257.gf7497c7d27-goog