[Fuego] [PATCH v2] busybox: add support for command openvt/passwd/pidof/ping/ps/pwd

Tim.Bird at sony.com Tim.Bird at sony.com
Wed Aug 1 00:18:19 UTC 2018


> -----Original Message-----
> From: Wang Mingyu
> 
> Signed-off-by: Wang Mingyu <wangmy at cn.fujitsu.com>
> ---
>  .../Functional.busybox/tests/busybox_openvt.sh     | 25
> ++++++++++++++++
>  .../Functional.busybox/tests/busybox_passwd.sh     | 34
> ++++++++++++++++++++++
>  .../Functional.busybox/tests/busybox_pidof.sh      | 15 ++++++++++
>  .../tests/Functional.busybox/tests/busybox_ping.sh | 22 ++++++++++++++
>  .../tests/Functional.busybox/tests/busybox_ps.sh   | 13 +++++++++
>  .../tests/Functional.busybox/tests/busybox_pwd.sh  | 13 +++++++++
>  6 files changed, 122 insertions(+)
>  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
> 
> diff --git a/engine/tests/Functional.busybox/tests/busybox_openvt.sh
> b/engine/tests/Functional.busybox/tests/busybox_openvt.sh
> new file mode 100644
> index 0000000..c596569
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_openvt.sh
> @@ -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 15000
> +if ps aux | grep sleep | grep -v grep | grep ".*sleep 15000"
This will work as is, but can be optimized.

There's a trick you can use to avoid seeing the 'grep' line when
grepping 'ps' output.  The trick is to use regular expression syntax
that doesn't match itself.  The following is simpler and faster than
what you have above.

if ps aux | grep "[s]leep 15000"

> +then
> +    echo " -> $test: ps aux | grep sleep | grep -v grep executed."
If you remove the grep -v, then this line should change.

> +else
> +    echo " -> $test: ps aux | grep sleep | grep -v grep failed."
if you remove the grep -v, then this line should change.

> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi;
> +
> +killall sleep
Whoah!  This is dangerous.  there might be something else using
sleep on the system, if the system is in a production configuration, or
there are other tests, monitors, tracers, or load-generators running.
It would be better to parse the process id for the sleep that is going
for 15000 seconds (and maybe use a weird value for seconds, so it's
unique in the system - like say, 15753 seconds), and only kill that id.

> +if ps aux | grep sleep | grep -v grep | grep ".*sleep.*"
> +then
> +    echo " -> $test: TEST-FAIL"
> +else
> +    echo " -> $test: TEST-PASS"
> +fi;
> diff --git a/engine/tests/Functional.busybox/tests/busybox_passwd.sh
> b/engine/tests/Functional.busybox/tests/busybox_passwd.sh
> new file mode 100644
> index 0000000..e383f56
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_passwd.sh
> @@ -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
This test should be added to the list for "skip_if_comamnd_unavailable expect ..." in fuego_test.sh

> +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
This requires root privileges.  This test should be added to the
list for "skip_if_not_root" in fuego_test.sh

> +fi
> diff --git a/engine/tests/Functional.busybox/tests/busybox_pidof.sh
> b/engine/tests/Functional.busybox/tests/busybox_pidof.sh
> new file mode 100644
> index 0000000..838864c
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_pidof.sh
> @@ -0,0 +1,15 @@
> +#!/bin/sh
> +
> +#  The testscript checks the following options of the command pidof
> +#  1) Option none
> +
> +test="pidof"
> +
> +busybox pidof `ps -e | awk '{if($1 == 1) print $4}'`
Can we use something besides awk here to parse the
command name for process 1.  Maybe cut -b?
In my experience, awk is often missing from embedded projects.

> +
> +if busybox pidof xyz || echo fail
I don't see how this can ever fail.
The if will use the exit code of the last command executed, which in this
case is "echo", which pretty much always succeeds (returns 0).

This needs to be restructured.

> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> diff --git a/engine/tests/Functional.busybox/tests/busybox_ping.sh
> b/engine/tests/Functional.busybox/tests/busybox_ping.sh
> new file mode 100644
> index 0000000..289f265
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_ping.sh
> @@ -0,0 +1,22 @@
> +#!/bin/sh
> +
> +#  The testscript checks the following options of the command ping
> +#  1) Option none
> +
> +test="ping"
> +
> +busybox.suid ping -c 2 $IPADDR > log
> +log1=$(head -n 1 log)
> +log2=$(head -n 2 log | head -n 1)
> +log3=$(tail -n 1 log)
> +pair1="PING"
> +pair2="seq=0."
> +pair3="seq=0."
> +
> +if [[ $log1 = *$pari1* ]] && [[ $log2 = *$pari2* ]] && [[ $log3 = *$pari3* ]]
"pair" is misspelled here.

Using [[ and wildcard matching is a bash-ism that should be removed.
Please replace this with 'grep' or some other mechanism.

> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> +rm log;
> diff --git a/engine/tests/Functional.busybox/tests/busybox_ps.sh
> b/engine/tests/Functional.busybox/tests/busybox_ps.sh
> new file mode 100644
> index 0000000..1dfe4e4
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_ps.sh
> @@ -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 -v grep | grep "busybox ps"
This can be simplified to:
if busybox ps | grep "[b]usybox ps"

> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> diff --git a/engine/tests/Functional.busybox/tests/busybox_pwd.sh
> b/engine/tests/Functional.busybox/tests/busybox_pwd.sh
> new file mode 100644
> index 0000000..a0034df
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_pwd.sh
> @@ -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;
> --
> 1.8.3.1

Thanks for the submission!

Please fix the issues listed above and resubmit.
 -- Tim



More information about the Fuego mailing list