[Fuego] [PATCH] Add new test cases of echo, egrep, env and expr to busybox.

Tim.Bird at sony.com Tim.Bird at sony.com
Wed Jun 6 00:25:12 UTC 2018



> -----Original Message-----
> From: Wang Mingyu
> Sent: Tuesday, June 05, 2018 1:40 AM
> 
> Signed-off-by: Wang Mingyu <wangmy at cn.fujitsu.com>
> ---
>  .../tests/Functional.busybox/tests/busybox_echo.sh | 13 ++++++++
>  .../Functional.busybox/tests/busybox_egrep.sh      | 28 ++++++++++++++++
>  .../tests/Functional.busybox/tests/busybox_env.sh  | 39
> ++++++++++++++++++++++
>  .../tests/Functional.busybox/tests/busybox_expr.sh | 13 ++++++++
>  4 files changed, 93 insertions(+)
>  create mode 100644
> engine/tests/Functional.busybox/tests/busybox_echo.sh
>  create mode 100644
> engine/tests/Functional.busybox/tests/busybox_egrep.sh
>  create mode 100644
> engine/tests/Functional.busybox/tests/busybox_env.sh
>  create mode 100644
> engine/tests/Functional.busybox/tests/busybox_expr.sh
> 
> diff --git a/engine/tests/Functional.busybox/tests/busybox_echo.sh
> b/engine/tests/Functional.busybox/tests/busybox_echo.sh
> new file mode 100644
> index 0000000..c29ed2f
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_echo.sh
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +
> +#  The testscript checks the following options of the command echo
> +#  1) Option none
> +
> +test="echo"
> +
> +if [ "$(busybox echo "hello world")" = "hello world" ]
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> diff --git a/engine/tests/Functional.busybox/tests/busybox_egrep.sh
> b/engine/tests/Functional.busybox/tests/busybox_egrep.sh
> new file mode 100644
> index 0000000..278f470
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_egrep.sh
> @@ -0,0 +1,28 @@
> +#!/bin/sh
> +
> +#  The testscript checks the following options of the command egrep
> +#  1) Option: -i
> +
> +test="egrep"
> +
> +busybox echo -e "test file\nextended grep\nExtended Grep" >test1
Please use 'echo' with the busybox prefix here.

> +busybox egrep 'test|extended' ./test1 > log1
> +if [ "$(sed -n '1p' log1)" = "test file" ] && [ "$(sed -n '2p' log1)" = "extended
> grep" ]
Please use head and tail instead of 'sed' here.

> +then
> +    echo " -> $test: Egrep output verification#1 succedded."
> +else
> +    echo " -> $test: TEST-FAIL"
> +    busybox rm log1
> +    busybox rm -rf test1
> +    exit
> +fi;
> +
> +busybox egrep -i 'test|extended' ./test1 > log2
> +if [ "$(sed -n '1p' log2)" = "test file" ] && [ "$(sed -n '2p' log2)" = "extended
> grep" ] &&  [ "$(sed -n '3p' log2)" = "Extended Grep" ]
Please use head and tail instead of sed here.

sed -n 2p can be replaced with:
'head -n 2 log2 | tail -n 1'

> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> +busybox rm log1 log2;
> +busybox rm -rf test1;
> diff --git a/engine/tests/Functional.busybox/tests/busybox_env.sh
> b/engine/tests/Functional.busybox/tests/busybox_env.sh
> new file mode 100644
> index 0000000..4932c6d
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_env.sh
> @@ -0,0 +1,39 @@
> +#!/bin/sh
> +
> +#  The testscript checks the following options of the command env
> +#  1) Option: none
> +
> +test="env"
> +
> +if [ -f /home/test/test1_env ]
You can't use a hardcoded path like this.
Please use $pwd in all paths, to allow
this test to run anywhere in the file system.
e.g.
mydir="$(pwd)"
if [ -f "$mydir/test1_env" ]
...

> +then
> +    rm -f /home/test/test1_env
> +fi
> +
> +echo "echo "TEST_ENV = \$TEST_ENV"">/home/test/test1_env

Shouldn't these double-quotes be escaped?
e.g.
echo "echo \"TEST_ENV=\$TEST_ENV"" >$mydir/test1_env

> +chmod 777 /home/test/test1_env
> +if [ "$(/home/test/test1_env)" = "TEST_ENV =" ]
if [ "$($mydir/test1_env)" = "TEST_ENV=foo bar" ]

I don't see how this is working.  Does this execute correctly
if it doesn't specify an interpreter on its first
line (e.g. $!/bin/sh).  Am I missing something?

> +then
> +    echo " -> $test: chmod 777 /home/test/test1_env executed."
> +else
> +    echo " -> $test: TEST-FAIL"
> +    rm -f /home/test/test1_env
> +    exit
> +fi;
> +
> +if [ "$(busybox env TEST_ENV=1 /home/test/test1_env)" = "TEST_ENV = 1"
> ]
It appears that the string to compare should not have spaces:
"TEST_ENV=1" (not "TEST_ENV = 1").

> +then
> +    echo " -> $test: busybox env TEST_ENV=1 /home/test/test1_env
> executed."
> +else
> +    echo " -> $test: TEST-FAIL"
> +    rm -f /home/test/test1_env
> +    exit
> +fi;
> +
> +if [ "$(busybox env TEST_ENV=2 /home/test/test1_env)" = "TEST_ENV = 2"
> ]
It appears that the string to compare should not have spaces:
"TEST_ENV=2" (not "TEST_ENV = 2").

> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> +rm -f /home/test/test1_env
> diff --git a/engine/tests/Functional.busybox/tests/busybox_expr.sh
> b/engine/tests/Functional.busybox/tests/busybox_expr.sh
> new file mode 100644
> index 0000000..fa07462
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_expr.sh
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +
> +#  The testscript checks the following options of the command expr
> +#  1) Option none
> +
> +test="expr"
> +
> +if busybox expr 3 \< 5 == 1 && busybox expr 3 \< 2 = 0 && busybox expr
> length "HELLO WORLD" = 11
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> --
> 1.8.3.1
Please respond to comments and re-submit.

Thanks!
 --  Tim



More information about the Fuego mailing list