Skip to contentSkip to conversation

busybox: add support for command head/hexdump/hostname/id/ifconfig/install

PATCH In review Wang Mingyu 2 participants 3 messages Jul 24, 2018 – Jul 31, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 busybox: add support for command head/hexdump/hostname/id/ifconfig/install

---
 .../tests/Functional.busybox/tests/busybox_head.sh  | 21 +++++++++++++++++++++
 .../Functional.busybox/tests/busybox_hexdump.sh     | 19 +++++++++++++++++++
 .../Functional.busybox/tests/busybox_hostname.sh    | 13 +++++++++++++
 engine/tests/Functional.busybox/tests/busybox_id.sh | 13 +++++++++++++
 .../Functional.busybox/tests/busybox_ifconfig.sh    | 13 +++++++++++++
 .../Functional.busybox/tests/busybox_install.sh     | 17 +++++++++++++++++
 6 files changed, 96 insertions(+)
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_head.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_hexdump.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_hostname.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_id.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_ifconfig.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_install.sh
engine/tests/Functional.busybox/tests/busybox_head.sh new file +21 -0
new file mode 100644
index 0000000..8bd7c9d
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command head
+#  1) Option -n
+
+test="head"
+
+mkdir test_dir
+echo "This is the 1st line." > test_dir/test1
+echo "This is the 2nd line." >> test_dir/test1
+echo "This is the 3rd line." >> test_dir/test1
+busybox head -n 2 test_dir/test1 > log
+
+if [ "$(busybox head -n 1 log)" = "This is the 1st line." ] && [ "$(tail -n 1 log)" = "This is the 2nd line." ]
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
+rm log
+rm -rf test_dir
engine/tests/Functional.busybox/tests/busybox_hexdump.sh new file +19 -0
new file mode 100644
index 0000000..524262a
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command hexdump
+#  1) Option: -c
+
+test="hexdump"
+
+mkdir test_dir
+touch test_dir/test1
+echo "HELLO WORLD" > test_dir/test1
+busybox hexdump -c test_dir/test1 > log
+if head -n 1 log | grep "0000000   H   E   L   L   O       W   O   R   L   D  \\\n" && [ "$(tail -n 1 log)" = "000000c" ]
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
+rm log
+rm -rf test_dir
engine/tests/Functional.busybox/tests/busybox_hostname.sh new file +13 -0
new file mode 100644
index 0000000..fce0b04
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command hostname
+#  1) Option none
+
+test="hostname"
+
+if [ $(busybox hostname) = $(cat /etc/hostname) ]
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
engine/tests/Functional.busybox/tests/busybox_id.sh new file +13 -0
new file mode 100644
index 0000000..14ef385
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command id
+#  1) Option none
+
+test="id"
+
+if grep "^$(whoami)" /etc/passwd | grep "$(id -u):$(id -g)" 
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
engine/tests/Functional.busybox/tests/busybox_ifconfig.sh new file +13 -0
new file mode 100644
index 0000000..31b07d2
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command ifconfig
+#  1) Option none
+
+test="ifconfig"
+
+if busybox ifconfig
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
engine/tests/Functional.busybox/tests/busybox_install.sh new file +17 -0
new file mode 100644
index 0000000..6b1f83e
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command install
+#  1) Option none
+
+test="install"
+
+mkdir test_dir test_install_dir
+echo "test install" > test_dir/test1
+busybox install test_dir/test1 test_install_dir
+if [ "$(ls test_install_dir)" = "test1" ] && [ "$(cat test_install_dir/test1)" = "test install" ] 
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
+rm -rf test_dir test_install_dir;
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 busybox: modify the code of option g+x in chmod1 test

Change the cut to retrieve the group permission bytes, to check that they are executable.

---
 engine/tests/Functional.busybox/tests/busybox_chmod1.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
engine/tests/Functional.busybox/tests/busybox_chmod1.sh +1 -1
index cdc7d18..2eef95a 100644
@@ -21,7 +21,7 @@ else
 fi;
 
 busybox chmod g+x ./test_dir/test1
-if [ "$(busybox ls -l ./test_dir | grep -v "total" | cut -b 1-3)" = "-rw" ]
+if [ "$(busybox ls -l ./test_dir | grep -v "total" | cut -b 5-7)" = "r-x" ]
 then
     echo " -> $test: Changed file permissions verification#2 succeeded."
 else
Signature · 1 line
1.8.3.1
#2 lore raw
In reply to Wang Mingyu
Quoted 113 lines

-----Original Message-----
From: Wang Mingyu

---
 .../tests/Functional.busybox/tests/busybox_head.sh  | 21
+++++++++++++++++++++
 .../Functional.busybox/tests/busybox_hexdump.sh     | 19
+++++++++++++++++++
 .../Functional.busybox/tests/busybox_hostname.sh    | 13 +++++++++++++
 engine/tests/Functional.busybox/tests/busybox_id.sh | 13
+++++++++++++
 .../Functional.busybox/tests/busybox_ifconfig.sh    | 13 +++++++++++++
 .../Functional.busybox/tests/busybox_install.sh     | 17
+++++++++++++++++
 6 files changed, 96 insertions(+)
 create mode 100644
engine/tests/Functional.busybox/tests/busybox_head.sh
 create mode 100644
engine/tests/Functional.busybox/tests/busybox_hexdump.sh
 create mode 100644
engine/tests/Functional.busybox/tests/busybox_hostname.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_id.sh
 create mode 100644
engine/tests/Functional.busybox/tests/busybox_ifconfig.sh
 create mode 100644

engine/tests/Functional.busybox/tests/busybox_install.sh

engine/tests/Functional.busybox/tests/busybox_head.sh new file +14 -0
new file mode 100644
index 0000000..8bd7c9d
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command head
+#  1) Option -n
+
+test="head"
+
+mkdir test_dir
+echo "This is the 1st line." > test_dir/test1
+echo "This is the 2nd line." >> test_dir/test1
+echo "This is the 3rd line." >> test_dir/test1
+busybox head -n 2 test_dir/test1 > log
+
+if [ "$(busybox head -n 1 log)" = "This is the 1st line." ] && [ "$(tail -n 1 log)"

= "This is the 2nd line." ]

engine/tests/Functional.busybox/tests/busybox_head.sh new file +7 -0
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
+rm log
+rm -rf test_dir
engine/tests/Functional.busybox/tests/busybox_hexdump.sh new file +12 -0
new file mode 100644
index 0000000..524262a
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command hexdump
+#  1) Option: -c
+
+test="hexdump"
+
+mkdir test_dir
+touch test_dir/test1
+echo "HELLO WORLD" > test_dir/test1
+busybox hexdump -c test_dir/test1 > log
+if head -n 1 log | grep "0000000   H   E   L   L   O       W   O   R   L   D  \\\n" && [

"$(tail -n 1 log)" = "000000c" ]

engine/tests/Functional.busybox/tests/busybox_hexdump.sh new file +7 -0
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
+rm log
+rm -rf test_dir
engine/tests/Functional.busybox/tests/busybox_hostname.sh new file +13 -0
new file mode 100644
index 0000000..fce0b04
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command hostname
+#  1) Option none
+
+test="hostname"
+
+if [ $(busybox hostname) = $(cat /etc/hostname) ]
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
engine/tests/Functional.busybox/tests/busybox_id.sh new file +0 -0
new file mode 100644
index 0000000..14ef385

engine/tests/Functional.busybox/tests/busybox_id.sh line 4

Quoted 4 lines
engine/tests/Functional.busybox/tests/busybox_id.sh new file +4 -0
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command id
+#  1) Option none

It seems like you are testing the -u and -g options of id below.

I'm going to just fix this comment rather than ask you to re-submit the patch. Please check my master branch and review my fixes.

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

Quoted 4 lines
engine/tests/Functional.busybox/tests/busybox_id.sh new file +4 -0
+
+test="id"
+
+if grep "^$(whoami)" /etc/passwd | grep "$(id -u):$(id -g)"

OK - this is better than the first iteration of this patch. It's conceivable that busybox might be compiled
with support for 'id' but not 'whoami', but it's a rare enough case that I think it's OK to use $(whoami) here, without additional checks or processing to catch that weird case.

I think it would be good to add a colon in the first grep, to avoid matching an incorrect name. e.g. if there were users in /etc/passwd named 'tester' and 'test', then 'grep test' would match then both. This weird case is probably caught by the colon in the second grep, but I think adding some extra specificity to the first grep is still good. So, I'm changing this to:
if grep "^$(whoami):" /etc/passwd ...

Separate from the above,
I think if you plan to keep the same style as used in other tests, you should be doing
... | grep "$(busybox id -u):$(busybox id -g)"

That is, using 'busybox id' rather than just 'id'

I'll also make this change. Please let me know if you object to any of these changes.

Quoted 51 lines
engine/tests/Functional.busybox/tests/busybox_id.sh new file +5 -0
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
engine/tests/Functional.busybox/tests/busybox_ifconfig.sh new file +13 -0
new file mode 100644
index 0000000..31b07d2
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command ifconfig
+#  1) Option none
+
+test="ifconfig"
+
+if busybox ifconfig
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
engine/tests/Functional.busybox/tests/busybox_install.sh new file +11 -0
new file mode 100644
index 0000000..6b1f83e
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command install
+#  1) Option none
+
+test="install"
+
+mkdir test_dir test_install_dir
+echo "test install" > test_dir/test1
+busybox install test_dir/test1 test_install_dir
+if [ "$(ls test_install_dir)" = "test1" ] && [ "$(cat test_install_dir/test1)" =

"test install" ]

engine/tests/Functional.busybox/tests/busybox_install.sh new file +6 -1
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
+rm -rf test_dir test_install_dir;
--
Quoted 1 line

1.8.3.1

Just a comment. I have busybox on 4 out of 5 of my systems, and on none of them is 'install' a command that is compiled in. I assume that 'install' is not turned on in
busybox's default config. I get the following running busybox_install.sh:

install: applet not found
cat: test_install_dir/test1: No such file or directory
-> install: TEST-FAIL

This is OK - but it means that the test fails on all of my systems.

It would be nice to add a skiplist feature to this test, that could be specified in the board file, like so:
BUSYBOX_SKIPLIST=chvt install
(chvt also fails on all my boards, due to the ssh session not being on a changeable vt)

Can you please add this feature to the Functional.busybox test (in fuegotest.sh)?

Thanks,
-- Tim