[Fuego] [PATCH] Add clear cmp cp and cut to busybox

Tim.Bird at sony.com Tim.Bird at sony.com
Tue Jun 5 23:20:15 UTC 2018


Please see comments inline below.  Some of the issues for
this patch are similar to the issues raised on the last patch.

> -----Original Message-----
> From: Wang Mingyu
> 
> Signed-off-by: Wang Mingyu <wangmy at cn.fujitsu.com>
> ---
>  .../Functional.busybox/tests/busybox_clear.sh      | 14 ++++++++++
>  .../tests/Functional.busybox/tests/busybox_cmp.sh  | 17 ++++++++++++
>  .../tests/Functional.busybox/tests/busybox_cp.sh   | 31
> ++++++++++++++++++++++
>  .../tests/Functional.busybox/tests/busybox_cut.sh  | 13 +++++++++
>  4 files changed, 75 insertions(+)
>  create mode 100644
> engine/tests/Functional.busybox/tests/busybox_clear.sh
>  create mode 100644
> engine/tests/Functional.busybox/tests/busybox_cmp.sh
>  create mode 100644 engine/tests/Functional.busybox/tests/busybox_cp.sh
>  create mode 100644
> engine/tests/Functional.busybox/tests/busybox_cut.sh
> 
> diff --git a/engine/tests/Functional.busybox/tests/busybox_clear.sh
> b/engine/tests/Functional.busybox/tests/busybox_clear.sh
> new file mode 100644
> index 0000000..aaa1d06
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_clear.sh
> @@ -0,0 +1,14 @@
> +#!/bin/sh
> +
> +#  The testscript checks the following options of the command clear
> +#  1) Option none
> +
> +test="clear"
> +
> +busybox clear
Is there any way to test the actual functionality of the command, rather
than just its exit code?

> +if [ $? = 0 ]
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> diff --git a/engine/tests/Functional.busybox/tests/busybox_cmp.sh
> b/engine/tests/Functional.busybox/tests/busybox_cmp.sh
> new file mode 100644
> index 0000000..919c03c
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_cmp.sh
> @@ -0,0 +1,17 @@
> +#!/bin/sh
> +
> +#  The testscript checks the following options of the command cmp
> +#  1) Option: -l -s
> +
> +test="cmp"
> +
> +busybox mkdir test_dir
> +busybox echo "This is test file 1." > ./test_dir/test1
> +busybox echo "This is test file 2." > ./test_dir/test2
Please only use the 'busybox' prefix, when it is the command under test.
For these, please just use 'mkdir' and 'echo'.

Also, there's no need to prefix the paths with './'.  test_dir will
be in the current directory.  This should be changed throughout the
test.

> +if [ "$(busybox cmp ./test_dir/test1 ./test_dir/test2)" = "./test_dir/test1
> ./test_dir/test2 differ: char 19, line 1" ] && [ "$(busybox cmp -l
> ./test_dir/test1 ./test_dir/test2)" = "19  61  62" ] && [ "$(busybox cmp -s
> ./test_dir/test1 ./test_dir/test2)" = "" ]
Some shell line continuations would be nice here, to avoid overly
long lines.

> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> +busybox rm -rf test_dir
Please use 'rm' here, instead of 'busybox rm'.

> diff --git a/engine/tests/Functional.busybox/tests/busybox_cp.sh
> b/engine/tests/Functional.busybox/tests/busybox_cp.sh
> new file mode 100644
> index 0000000..5f85e49
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_cp.sh
> @@ -0,0 +1,31 @@
> +#!/bin/sh
> +
> +#  The testscript checks the following options of the command cp
> +#  1) Option: -i
> +
> +test="cp"
> +
> +mkdir test_dir_src
> +mkdir test_dir_dest
> +echo "cp test" > test_dir_src/test1
> +busybox cp test_dir_src/test1 test_dir_dest/
> +if [ "$(cat test_dir_dest/test1)" = "cp test" ]
> +then
> +    echo " -> $test: cp succeed."
> +else
> +    echo " -> &test: TEST-FAIL"
> +    rm -rf test_dir_src
> +    rm -rf test_dir_dest
> +    exit
> +fi;
> +
> +expect <<-EOF
> +spawn busybox cp -i test_dir_dest/test1 test_dir_src/
> +expect "cp: overwrite 'test_dir_src/test1'?"
> +send_user " -> $test: overwite succeeded.\n"
"overwite" should be "overwrite"

> +send "exit\r"
> +send_user " -> $test: TEST-PASS\n"
> +expect eof
> +EOF
Can this be structured without the use of 'expect'?
I know you are doing a 'cp -I' (interactive).  But you
could provide stdin for the test.  You are only checking
that you saw the prompt, which it seems like you
could have placed in a file and checked with grep.

Something like this:?
yes | busybox cp -i test_dir_dest/test1 test_dir_src/ 2>cp.log
if cat cp.log | grep "cp: overwrite 'test_dir_src/test1'?" >/dev/null ;
then
    echo "-> $test: overwrite succeeded."
    exit
else
    echo " -> $test: TEST-PASS"
fi

And actually, this doesn't test that the overwrite succeeded - just
that the test provided the expected prompt.  Maybe you should
check both.  That is, check for a valid prompt and issue a failure
if not seen, as well as check that the file contents in test_dir_src
are as expected.  This would require changing the file contents
in test_dir_src/test1 prior to doing the overwrite, and a test
of test1 contents, to verify that the content was changed as expected.


> +rm -rf test_dir_src;
> +rm -rf test_dir_dest;
> diff --git a/engine/tests/Functional.busybox/tests/busybox_cut.sh
> b/engine/tests/Functional.busybox/tests/busybox_cut.sh
> new file mode 100644
> index 0000000..a732521
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_cut.sh
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +
> +#  The testscript checks the following options of the command cut
> +#  1) Option: -f -d
> +
> +test="cut"
> +
> +if [ "$(busybox echo "Hello world" | /bin/busybox cut -f 1 -d ' ')" = "Hello" ]
This can be 'echo' instead of 'busybox echo'

> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> --
> 1.8.3.1

These look good.  Please respond to the issues raised
and re-submit.

Thanks,
 -- Tim



More information about the Fuego mailing list