aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-06-25 14:01:07 -0700
committerRob Landley <rob@landley.net>2019-06-25 18:44:09 -0500
commitfcac2a821c9b382ee265b9f1ed8a251f47c6892f (patch)
treee26c8e80060d36f067bf35a90ec3f53a771491aa
parentac631beb854f4d1d533819d7eefbdadbe94cec95 (diff)
downloadtoybox-fcac2a821c9b382ee265b9f1ed8a251f47c6892f.tar.gz
Make chgrp and chown tests work on Android.
There's no /etc/passwd and /etc/group, but there are enough users and groups that we can test with. ("bin" and "daemon" were added for LTP; "shell" is what you get with `adb shell`.)
-rwxr-xr-xtests/chgrp.test10
-rwxr-xr-xtests/chown.test17
2 files changed, 18 insertions, 9 deletions
diff --git a/tests/chgrp.test b/tests/chgrp.test
index 65820361..5c7e4258 100755
--- a/tests/chgrp.test
+++ b/tests/chgrp.test
@@ -9,9 +9,13 @@ then
exit
fi
-# We chgrp between "root" and the last group in /etc/group.
-
-GRP="$(sed -n '$s/:.*//p' /etc/group)"
+if [ -f /etc/group ]; then
+ # We chgrp between "root" and the last group in /etc/group.
+ GRP="$(sed -n '$s/:.*//p' /etc/group)"
+else
+ # Or assume we're on Android and pick a well-known group.
+ GRP=shell
+fi
# Set up a little testing hierarchy
diff --git a/tests/chown.test b/tests/chown.test
index 56eed81e..20be541a 100755
--- a/tests/chown.test
+++ b/tests/chown.test
@@ -9,11 +9,16 @@ then
exit
fi
-# We chown between user "root" and the last user in /etc/passwd,
-# and group "root" and the last group in /etc/group.
-
-USR="$(sed -n '$s/:.*//p' /etc/passwd)"
-GRP="$(sed -n '$s/:.*//p' /etc/group)"
+if [ -f /etc/group ]; then
+ # We chown between user "root" and the last user in /etc/passwd,
+ # and group "root" and the last group in /etc/group.
+ USR="$(sed -n '$s/:.*//p' /etc/passwd)"
+ GRP="$(sed -n '$s/:.*//p' /etc/group)"
+else
+ # Or we assume we're on Android...
+ USR="shell"
+ GRP="daemon"
+fi
# Set up a little testing hierarchy
@@ -24,7 +29,7 @@ F=testdir/file
# Wrapper to reset groups and return results
-OUT="&& echo \$(ls -l testdir/file | awk '{print \$3,\$4}')"
+OUT="&& stat --format '%U %G' $F"
#testing "name" "command" "result" "infile" "stdin"