Skip to contentSkip to conversation

busybox: add support for command openvt/passwd/pidof/ping/ps/pwd

PATCH In review Wang Mingyu 2 participants 2 messages Aug 2, 2018 – Aug 18, 2018

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 busybox: add support for command openvt/passwd/pidof/ping/ps/pwd

---
 engine/tests/Functional.busybox/fuego_test.sh      |  5 ++--
 .../Functional.busybox/tests/busybox_openvt.sh     | 25 ++++++++++++++++
 .../Functional.busybox/tests/busybox_passwd.sh     | 34 ++++++++++++++++++++++
 .../Functional.busybox/tests/busybox_pidof.sh      | 21 +++++++++++++
 .../tests/Functional.busybox/tests/busybox_ping.sh | 16 ++++++++++
 .../tests/Functional.busybox/tests/busybox_ps.sh   | 13 +++++++++
 .../tests/Functional.busybox/tests/busybox_pwd.sh  | 13 +++++++++
 7 files changed, 125 insertions(+), 2 deletions(-)
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_openvt.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_passwd.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_pidof.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_ping.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_ps.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_pwd.sh
engine/tests/Functional.busybox/fuego_test.sh +3 -2
index 2d2e8f6..4ee593c 100755
@@ -39,9 +39,9 @@ function test_pre_check {
     assert_define PROGRAM_BUSYBOX "Missing 'busybox' program on target board"
     echo "Tests skipped depending on the availability of a command on the target"
     touch ${LOGDIR}/skiplist.txt
-    skip_if_command_unavailable expect "busybox_ash.sh"
+    skip_if_command_unavailable expect "busybox_ash.sh busybox_passwd.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_chgrp1.sh busybox_chgrp2.sh busybox_chown1.sh busybox_chown2.sh busybox_chroot.sh"
+    skip_if_not_root "busybox_chgrp1.sh busybox_chgrp2.sh busybox_chown1.sh busybox_chown2.sh busybox_chroot.sh busybox_passwd.sh"
 }
 
 function test_deploy {
@@ -54,6 +54,7 @@ function test_run {
     report "cd $BOARD_TESTDIR/fuego.$TESTDIR; \
         export test_tcpip_host=$SRV_IP; \
         export test_port_host=${SRV_PORT:=8080}; \
+        export test_ipaddr=$IPADDR;\
         sh -v busybox_test.sh"
 }
 
engine/tests/Functional.busybox/tests/busybox_openvt.sh new file +25 -0
new file mode 100644
index 0000000..fb7a9f3
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command openvt
+#  1) Option none
+
+test="openvt"
+
+killall sleep
+busybox openvt -f -c 2 sleep 15732
+if  ps aux | grep "[s]leep 15732"
+then
+    echo " -> $test: ps aux | grep "[s]leep 15732" executed."
+else
+    echo " -> $test: ps aux | grep "[s]leep 15732" failed."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi;
+
+kill $(pgrep -f "[s]leep 15732")
+if ps aux | grep "[s]leep 15732"
+then
+    echo " -> $test: TEST-FAIL"
+else
+    echo " -> $test: TEST-PASS"
+fi;
engine/tests/Functional.busybox/tests/busybox_passwd.sh new file +34 -0
new file mode 100644
index 0000000..e383f56
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command passwd
+#  1) Option none
+
+test="passwd"
+
+if [ -e /etc/shadow ]
+then
+    cp /etc/shadow /etc/shadow.backup
+fi
+
+userdel -r test_busybox_passwd
+ls /
+useradd test_busybox_passwd
+
+expect <<-EOF
+spawn busybox.suid passwd test_busybox_passwd
+expect "New password:"
+send_user " -> $test: busybox.suid passwd test_busybox_passwd executed.\n"
+send "test123\r"
+expect "Retype password:"
+send_user " -> $test: retype passwd executed.\n"
+send "test123\r"
+expect "Password for test_busybox_passwd changed by root"
+send_user " -> $test: TEST-PASS\n"
+expect eof
+EOF
+
+userdel -r test_busybox_passwd
+if [ -e /etc/shadow.backup ]
+then
+    mv -f /etc/shadow.backup /etc/shadow
+fi
engine/tests/Functional.busybox/tests/busybox_pidof.sh new file +21 -0
new file mode 100644
index 0000000..38384b7
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command pidof
+#  1) Option none
+
+test="pidof"
+
+if busybox pidof $(ps -q 1 -o comm=) | grep 1 
+then
+    echo " -> $test: get pid from process name succedded."
+else
+    echo " -> $test: get pid from process name failed."
+    echo " -> $test: TEST-FAIL"
+fi;
+
+if busybox pidof test_for_pidof
+then
+    echo " -> $test: TEST-FAIL"
+else
+    echo " -> $test: TEST-PASS"
+fi;
engine/tests/Functional.busybox/tests/busybox_ping.sh new file +16 -0
new file mode 100644
index 0000000..1e746d2
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command ping
+#  1) Option none
+
+test="ping"
+
+busybox.suid ping -c 2 $test_ipaddr > log
+
+if head -n 1 log | grep "PING" && head -n 2 log | tail -n 1 | grep "seq=0." && head -n 3 log | tail -n 1 | grep "seq=1."
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
+rm log;
engine/tests/Functional.busybox/tests/busybox_ps.sh new file +13 -0
new file mode 100644
index 0000000..9f31fc8
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command ps
+#  1) Option none
+
+test="ps"
+
+if busybox ps | grep "[b]usybox ps"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
engine/tests/Functional.busybox/tests/busybox_pwd.sh new file +13 -0
new file mode 100644
index 0000000..a0034df
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command pwd
+#  1) Option none
+
+test="pwd"
+
+if busybox pwd
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
Signature · 1 line
1.8.3.1
#1 lore raw

Comments inline below. As with last patch, I applied this one, and may do some of my own fixups.

Quoted 118 lines · Wang Mingyu
---
 engine/tests/Functional.busybox/fuego_test.sh      |  5 ++--
 .../Functional.busybox/tests/busybox_openvt.sh     | 25 ++++++++++++++++
 .../Functional.busybox/tests/busybox_passwd.sh     | 34 ++++++++++++++++++++++
 .../Functional.busybox/tests/busybox_pidof.sh      | 21 +++++++++++++
 .../tests/Functional.busybox/tests/busybox_ping.sh | 16 ++++++++++
 .../tests/Functional.busybox/tests/busybox_ps.sh   | 13 +++++++++
 .../tests/Functional.busybox/tests/busybox_pwd.sh  | 13 +++++++++
 7 files changed, 125 insertions(+), 2 deletions(-)
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_openvt.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_passwd.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_pidof.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_ping.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_ps.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_pwd.sh
engine/tests/Functional.busybox/fuego_test.sh +3 -2
index 2d2e8f6..4ee593c 100755
@@ -39,9 +39,9 @@ function test_pre_check {
     assert_define PROGRAM_BUSYBOX "Missing 'busybox' program on target board"
     echo "Tests skipped depending on the availability of a command on the target"
     touch ${LOGDIR}/skiplist.txt
-    skip_if_command_unavailable expect "busybox_ash.sh"
+    skip_if_command_unavailable expect "busybox_ash.sh busybox_passwd.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_chgrp1.sh busybox_chgrp2.sh busybox_chown1.sh busybox_chown2.sh busybox_chroot.sh"
+    skip_if_not_root "busybox_chgrp1.sh busybox_chgrp2.sh busybox_chown1.sh busybox_chown2.sh busybox_chroot.sh busybox_passwd.sh"
 }
 
 function test_deploy {
@@ -54,6 +54,7 @@ function test_run {
     report "cd $BOARD_TESTDIR/fuego.$TESTDIR; \
         export test_tcpip_host=$SRV_IP; \
         export test_port_host=${SRV_PORT:=8080}; \
+        export test_ipaddr=$IPADDR;\
         sh -v busybox_test.sh"
 }
 
engine/tests/Functional.busybox/tests/busybox_openvt.sh new file +25 -0
new file mode 100644
index 0000000..fb7a9f3
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command openvt
+#  1) Option none
+
+test="openvt"
+
+killall sleep
+busybox openvt -f -c 2 sleep 15732
+if  ps aux | grep "[s]leep 15732"
+then
+    echo " -> $test: ps aux | grep "[s]leep 15732" executed."
+else
+    echo " -> $test: ps aux | grep "[s]leep 15732" failed."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi;
+
+kill $(pgrep -f "[s]leep 15732")
+if ps aux | grep "[s]leep 15732"
+then
+    echo " -> $test: TEST-FAIL"
+else
+    echo " -> $test: TEST-PASS"
+fi;
engine/tests/Functional.busybox/tests/busybox_passwd.sh new file +34 -0
new file mode 100644
index 0000000..e383f56
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command passwd
+#  1) Option none
+
+test="passwd"
+
+if [ -e /etc/shadow ]
+then
+    cp /etc/shadow /etc/shadow.backup
+fi
+
+userdel -r test_busybox_passwd
+ls /
+useradd test_busybox_passwd
+
+expect <<-EOF
+spawn busybox.suid passwd test_busybox_passwd
+expect "New password:"
+send_user " -> $test: busybox.suid passwd test_busybox_passwd executed.\n"
+send "test123\r"
+expect "Retype password:"
+send_user " -> $test: retype passwd executed.\n"
+send "test123\r"
+expect "Password for test_busybox_passwd changed by root"
+send_user " -> $test: TEST-PASS\n"
+expect eof
+EOF
+
+userdel -r test_busybox_passwd
+if [ -e /etc/shadow.backup ]
+then
+    mv -f /etc/shadow.backup /etc/shadow
+fi
engine/tests/Functional.busybox/tests/busybox_pidof.sh new file +0 -0
new file mode 100644
index 0000000..38384b7

engine/tests/Functional.busybox/tests/busybox_pidof.sh line 8

Quoted 8 lines
engine/tests/Functional.busybox/tests/busybox_pidof.sh new file +8 -0
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command pidof
+#  1) Option none
+
+test="pidof"
+
+if busybox pidof $(ps -q 1 -o comm=) | grep 1

busybox ps doesn't support -q. This will fail on a busybox-only system. Also, the 'grep 1' would match any pid with a 1 in it (e.g. 11).

Actually, this should work:
proc1_cmd=$(cat /proc/1/comm)
if [ $(busybox pidof ${proc1_cmd}) | grep 1 ]

I ended up with a variant of this.

Quoted 19 lines
engine/tests/Functional.busybox/tests/busybox_pidof.sh new file +13 -0
+then
+    echo " -> $test: get pid from process name succedded."
+else
+    echo " -> $test: get pid from process name failed."
+    echo " -> $test: TEST-FAIL"
+fi;
+
+if busybox pidof test_for_pidof
+then
+    echo " -> $test: TEST-FAIL"
+else
+    echo " -> $test: TEST-PASS"
+fi;
engine/tests/Functional.busybox/tests/busybox_ping.sh new file +0 -0
new file mode 100644
index 0000000..1e746d2

engine/tests/Functional.busybox/tests/busybox_ping.sh line 8

Quoted 8 lines
engine/tests/Functional.busybox/tests/busybox_ping.sh new file +8 -0
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command ping
+#  1) Option none
+
+test="ping"
+
+busybox.suid ping -c 2 $test_ipaddr > log

busybox.suid didn't work on any of my systems.

Is this something local to a fujitsu environment?

I added a check for non-root, and try to execute the command using sudo if the test user is non-root.

engine/tests/Functional.busybox/tests/busybox_ping.sh line 10

Quoted 2 lines
engine/tests/Functional.busybox/tests/busybox_ping.sh new file +2 -0
+
+if head -n 1 log | grep "PING" && head -n 2 log | tail -n 1 | grep "seq=0." && head -n 3 log | tail -n 1 | grep "seq=1."

Ordering doesn't matter here. No need to use head and tail.

Some ping outputs start at seq=0 and some at seq=1, so I switched to doing 3 pings,
and checking for seq=1 and seq=2.

Quoted 31 lines
engine/tests/Functional.busybox/tests/busybox_ping.sh new file +6 -0
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
+rm log;
engine/tests/Functional.busybox/tests/busybox_ps.sh new file +13 -0
new file mode 100644
index 0000000..9f31fc8
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command ps
+#  1) Option none
+
+test="ps"
+
+if busybox ps | grep "[b]usybox ps"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
engine/tests/Functional.busybox/tests/busybox_pwd.sh new file +0 -0
new file mode 100644
index 0000000..a0034df

engine/tests/Functional.busybox/tests/busybox_pwd.sh line 8

Quoted 8 lines
engine/tests/Functional.busybox/tests/busybox_pwd.sh new file +8 -0
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command pwd
+#  1) Option none
+
+test="pwd"
+
+if busybox pwd

This could be enhanced. Maybe compare with /proc/$$/cwd ?

I added this comparison, to check the output of pwd.

Quoted 7 lines
engine/tests/Functional.busybox/tests/busybox_pwd.sh new file +5 -1
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
--

1.8.3.1

Thanks for the tests.

-- Tim Bird
Senior Staff Software Engineer, Sony Corporation Architecture Group Chair, Core Embedded Linux Project, Linux Foundation