Skip to contentSkip to conversation

Add a function in fuego_test.sh to check if the user has root privileges on the target or not. If not, add the test case that requires root privileges to the skiplist.

PATCH New Wang Mingyu 1 participant 1 message Jul 3, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add a function in fuego_test.sh to check if the user has root privileges on the target or not. If not, add the test case that requires root privileges to the skiplist.

---
 engine/tests/Functional.busybox/fuego_test.sh | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
engine/tests/Functional.busybox/fuego_test.sh +14 -2
index 70a6ec1..861cf24 100755
@@ -1,5 +1,5 @@
 # $1: string with tests to skip separated by spaces
-# $2: absolute path to the skipfile (default: ${LOGDIR}/skiplist.txt)
+# absolute path to the skipfile (default: ${LOGDIR}/skiplist.txt)
 function skip_tests {
     # split $1 on whitespace, without file globbing
     set -f
@@ -14,7 +14,7 @@ function skip_tests {
 
 # $1: command/program to look for
 # $2: string with busybox test names separated by spaces
-# $3: This function may also be used in other tests, which can be considered as a general function of fuego.
+# This function may also be used in other tests, which can be considered as a general function of fuego.
 function skip_if_command_unavailable {
     local PROGRAM="$1"
     local TESTS="$2"
@@ -27,6 +27,17 @@ function skip_if_command_unavailable {
     fi
 }
 
+# $1: string with busybox test names separated by spaces
+# This function is used to check whether the tests that need root privileges should be skiped or not.
+function skip_if_not_root {
+    local TESTS="$1"
+    check_root
+    if [ $? = 1 ] ;then 
+        echo "WARNING: You need to login as root."
+        skip_tests "${TESTS}"       
+    fi    
+}
+
 function test_pre_check {
     is_on_target_path busybox PROGRAM_BUSYBOX
     assert_define PROGRAM_BUSYBOX "Missing 'busybox' program on target board"
@@ -34,6 +45,7 @@ function test_pre_check {
     touch ${LOGDIR}/skiplist.txt
     skip_if_command_unavailable expect "busybox_ash.sh"
     skip_if_command_unavailable tr "busybox_chgrp1.sh busybox_chgrp2.sh busybox_chmod1.sh busybox_chmod2.sh busybox_chown1.sh busybox_chown2.sh"
+    skip_if_not_root "busybox_chroot.sh"
 }
 
 function test_deploy {
Signature · 1 line
1.8.3.1