[Fuego] [PATCH] busybox: add support for command for sed/sh/sleep/sort/strings/swap/sync

Tim Bird tbird20d at gmail.com
Sat Aug 18 05:26:14 UTC 2018


Comments inline below.

On Wed, Aug 8, 2018 at 7:57 PM, Wang Mingyu <wangmy at cn.fujitsu.com> wrote:
> Signed-off-by: Wang Mingyu <wangmy at cn.fujitsu.com>
> ---
>  engine/tests/Functional.busybox/fuego_test.sh      |  2 +-
>  .../tests/Functional.busybox/tests/busybox_sed.sh  | 13 ++++++++
>  .../tests/Functional.busybox/tests/busybox_sh.sh   | 21 ++++++++++++
>  .../Functional.busybox/tests/busybox_sleep.sh      | 22 +++++++++++++
>  .../tests/Functional.busybox/tests/busybox_sort.sh | 24 ++++++++++++++
>  .../Functional.busybox/tests/busybox_strings.sh    | 24 ++++++++++++++
>  .../tests/Functional.busybox/tests/busybox_swap.sh | 38 ++++++++++++++++++++++
>  .../tests/Functional.busybox/tests/busybox_sync.sh | 13 ++++++++
>  8 files changed, 156 insertions(+), 1 deletion(-)
>  create mode 100644 engine/tests/Functional.busybox/tests/busybox_sed.sh
>  create mode 100644 engine/tests/Functional.busybox/tests/busybox_sh.sh
>  create mode 100644 engine/tests/Functional.busybox/tests/busybox_sleep.sh
>  create mode 100644 engine/tests/Functional.busybox/tests/busybox_sort.sh
>  create mode 100644 engine/tests/Functional.busybox/tests/busybox_strings.sh
>  create mode 100644 engine/tests/Functional.busybox/tests/busybox_swap.sh
>  create mode 100644 engine/tests/Functional.busybox/tests/busybox_sync.sh
>
> diff --git a/engine/tests/Functional.busybox/fuego_test.sh b/engine/tests/Functional.busybox/fuego_test.sh
> index 8bf04e5..759f2c5 100755
> --- a/engine/tests/Functional.busybox/fuego_test.sh
> +++ b/engine/tests/Functional.busybox/fuego_test.sh
> @@ -53,7 +53,7 @@ function test_pre_check {
>      touch ${LOGDIR}/skiplist.txt
>      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 busybox_passwd.sh"
> +    skip_if_not_root "busybox_chgrp1.sh busybox_chgrp2.sh busybox_chown1.sh busybox_chown2.sh busybox_chroot.sh busybox_passwd.sh busybox_swap.sh"
>      skip_if_subcommand_unsupported "$BUSYBOX_SKIPLIST"
>  }
>
> diff --git a/engine/tests/Functional.busybox/tests/busybox_sed.sh b/engine/tests/Functional.busybox/tests/busybox_sed.sh
> new file mode 100644
> index 0000000..c5af18f
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_sed.sh
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +
> +#  The testscript checks the following options of the command sed
> +#  1) Option -e
> +
> +test="sed"
> +
> +if [ "$(echo "test case" | busybox sed -e 's/case/result/g')" = "test result" ]
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> diff --git a/engine/tests/Functional.busybox/tests/busybox_sh.sh b/engine/tests/Functional.busybox/tests/busybox_sh.sh
> new file mode 100644
> index 0000000..1c16976
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_sh.sh
> @@ -0,0 +1,21 @@
> +#!/bin/sh
> +
> +#  The testscript checks the following options of the command sh
> +#  1) Option none
> +
> +test="sh"
> +
> +mkdir test_dir
> +touch test_dir/test1
> +
> +cat >> test_dir/test1 <<EOF
> +#!/bin/bash
> +echo "this is test bash!"
> +EOF

OK - that's kind of tricky - saying it's a bash script but executing it
with busybox sh.  I like it.

> +
> +if busybox sh test_dir/test1 | grep "this is test bash!"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> diff --git a/engine/tests/Functional.busybox/tests/busybox_sleep.sh b/engine/tests/Functional.busybox/tests/busybox_sleep.sh
> new file mode 100644
> index 0000000..68c2673
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_sleep.sh
> @@ -0,0 +1,22 @@
> +#!/bin/sh
> +
> +#  The testscript checks the following options of the command sleep
> +#  1) Option none
> +
> +test="sleep"
> +
> +if sleep 0 | ps aux | grep "[s]leep 0"
> +then
> +    echo " -> $test: sleep 0 failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +else
> +    echo " -> $test: sleep 0 succeeded."
> +fi;
> +
> +if sleep 1 | ps aux | grep "[s]leep 1"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> diff --git a/engine/tests/Functional.busybox/tests/busybox_sort.sh b/engine/tests/Functional.busybox/tests/busybox_sort.sh
> new file mode 100644
> index 0000000..18ca0e7
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_sort.sh
> @@ -0,0 +1,24 @@
> +#!/bin/sh
> +
> +#  The testscript checks the following options of the command sort
> +#  1) Option none
> +
> +test="sort"
> +
> +echo "e" > test1
> +echo "f" >> test1
> +echo "b" >> test1
> +echo "d" >> test1
> +echo "c" >> test1
> +echo "a" >> test1
> +
> +busybox sort test1 > log
> +if [ "$(head -n 1 log)" = "a" ] && [ "$(head -n 2 log | tail -n 1)" = "b" ] && [ "$(head -n 3 log | tail -n 1)" = "c" ] \
> +&& [ "$(head -n 4 log | tail -n 1)" = "d" ] && [ "$(head -n 5 log | tail -n 1)" = "e" ] && [ "$(tail -n 1 log)" = "f" ]
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> +rm -rf test1;
> +rm log;
> diff --git a/engine/tests/Functional.busybox/tests/busybox_strings.sh b/engine/tests/Functional.busybox/tests/busybox_strings.sh
> new file mode 100644
> index 0000000..5ffe63d
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_strings.sh
> @@ -0,0 +1,24 @@
> +#!/bin/sh
> +
> +#  The testscript checks the following options of the command strings
> +#  1) Option none
> +
> +test="strings"
> +
> +cat >> test1.c <<EOF
> +#include <stdio.h>
> +void main()
> +{
> +    printf("Hello World \n");
> +}
> +EOF
> +
> +gcc test1.c -o test1
It's unlikely there will be 'gcc' on the board.  You need to use a
different method of
creating the data file.

I manually created on using printf on the host.  I'll put some code to generate
a file with binary data, as well a "Hello World\n" on the host, and transfer
it to the board in deploy.

> +
> +if busybox strings test1 | grep "Hello World"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> +rm test1 test1.c;
> diff --git a/engine/tests/Functional.busybox/tests/busybox_swap.sh b/engine/tests/Functional.busybox/tests/busybox_swap.sh
> new file mode 100644
> index 0000000..1b23d51
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_swap.sh
> @@ -0,0 +1,38 @@
> +#!/bin/sh
> +
> +#  The testscript checks the following options of the command swapon&swapoff
> +#  1) Option -a
> +
> +test="swapon/swapoff"
> +
> +function check_if_succeeded {
> +    if $1
> +    then
> +        echo " -> $test: $1 succeeded."
> +    else
> +        echo " -> $test: $1 failed."
> +        echo " -> $test: TEST-FAIL"
> +    fi
> +}
> +
> +if [ $(cat /proc/swaps | wc -l) = 1 ]
> +then
> +    check_if_succeeded "busybox swapon -a"
> +    check_if_succeeded "busybox swapoff -a"
> +    if [ $(cat /proc/swaps | wc -l) = 1 ]
> +    then
> +        echo " -> $test: TEST-PASS"
> +    else
> +        echo " -> $test: TEST-FAIL"
> +    fi
> +else
> +    swap_name=$(cat /proc/swaps | tail -n 1| tr -s " " | cut -d ' ' -f1)
> +    check_if_succeeded "busybox swapoff $swap_name"
> +    check_if_succeeded "busybox swapon $swap_name"
> +    if cat /proc/swaps | grep $swap_name
> +    then
> +        echo " -> $test: TEST-PASS"
> +    else
> +        echo " -> $test: TEST-FAIL"
> +    fi
> +fi;
> diff --git a/engine/tests/Functional.busybox/tests/busybox_sync.sh b/engine/tests/Functional.busybox/tests/busybox_sync.sh
> new file mode 100644
> index 0000000..39c269b
> --- /dev/null
> +++ b/engine/tests/Functional.busybox/tests/busybox_sync.sh
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +
> +#  The testscript checks the following options of the command sync
> +#  1) Option none
> +
> +test="sync"
> +
> +if busybox sync
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> --
> 1.8.3.1
>
>
>
> _______________________________________________
> Fuego mailing list
> Fuego at lists.linuxfoundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/fuego



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


More information about the Fuego mailing list