[Fuego] [PATCH] ltrace: Add test cases for command ltrace.

Tim.Bird at sony.com Tim.Bird at sony.com
Wed Sep 11 17:28:42 UTC 2019


Sorry for the slow response.  I'm traveling at the moment, and my
processes for handling patches while I'm traveling are not good yet.
I hope I can improve these in the near future.

See inline comments below.

> -----Original Message-----
> From: Wang Mingyu
> 
> ltrace is a program that simply runs the specified command until it exits.
> This test set is used to check the ountput syscall/time/count/help of
> command to trace and check if can be saved to file.
> 
> Signed-off-by: Wang Mingyu <wangmy at cn.fujitsu.com>
> ---
>  tests/Functional.ltrace/fuego_test.sh           | 17 +++++++++++++++++
>  tests/Functional.ltrace/ltrace_test.sh          |  4 ++++
>  tests/Functional.ltrace/spec.json               |  6 ++++++
>  tests/Functional.ltrace/tests/ltrace_count.sh   | 15 +++++++++++++++
>  tests/Functional.ltrace/tests/ltrace_help.sh    | 13 +++++++++++++
>  tests/Functional.ltrace/tests/ltrace_output.sh  | 15 +++++++++++++++
>  tests/Functional.ltrace/tests/ltrace_syscall.sh | 15 +++++++++++++++
>  tests/Functional.ltrace/tests/ltrace_time.sh    | 15 +++++++++++++++
>  8 files changed, 100 insertions(+)
>  create mode 100644 tests/Functional.ltrace/fuego_test.sh
>  create mode 100755 tests/Functional.ltrace/ltrace_test.sh
>  create mode 100644 tests/Functional.ltrace/spec.json
>  create mode 100644 tests/Functional.ltrace/tests/ltrace_count.sh
>  create mode 100644 tests/Functional.ltrace/tests/ltrace_help.sh
>  create mode 100644 tests/Functional.ltrace/tests/ltrace_output.sh
>  create mode 100644 tests/Functional.ltrace/tests/ltrace_syscall.sh
>  create mode 100644 tests/Functional.ltrace/tests/ltrace_time.sh
> 
> diff --git a/tests/Functional.ltrace/fuego_test.sh
> b/tests/Functional.ltrace/fuego_test.sh
> new file mode 100644
> index 0000000..ecfc4e7
> --- /dev/null
> +++ b/tests/Functional.ltrace/fuego_test.sh
> @@ -0,0 +1,17 @@
> +function test_pre_check {
> +    assert_has_program ltrace
> +}
> +
> +function test_deploy {
> +    put $TEST_HOME/ltrace_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
> +    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
> +}
> +
> +function test_run {
> +    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
> +    ./ltrace_test.sh"
> +}
> +
> +function test_processing {
> +    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
> +}
> diff --git a/tests/Functional.ltrace/ltrace_test.sh
> b/tests/Functional.ltrace/ltrace_test.sh
> new file mode 100755
> index 0000000..dd5ce37
> --- /dev/null
> +++ b/tests/Functional.ltrace/ltrace_test.sh
> @@ -0,0 +1,4 @@
> +#!/bin/sh
> +for i in tests/*.sh; do
> +    sh $i
> +done
> diff --git a/tests/Functional.ltrace/spec.json
> b/tests/Functional.ltrace/spec.json
> new file mode 100644
> index 0000000..fce7a19
> --- /dev/null
> +++ b/tests/Functional.ltrace/spec.json
> @@ -0,0 +1,6 @@
> +{
> +    "testName": "Functional.ltrace",
> +    "specs": {
> +        "default": {}
> +    }
> +}
> diff --git a/tests/Functional.ltrace/tests/ltrace_count.sh
> b/tests/Functional.ltrace/tests/ltrace_count.sh
> new file mode 100644
> index 0000000..5a277fc
> --- /dev/null
> +++ b/tests/Functional.ltrace/tests/ltrace_count.sh
> @@ -0,0 +1,15 @@
> +#!/bin/sh
> +
> +#  In target, run comannd ltrace to count time and calls.
> +#  option: -c
> +
> +test="count"
> +
> +ltrace -c dd if=/dev/urandom of=/dev/null count=1000 > log 2>&1
> +if cat log | grep "usecs/call"
This can be 'if grep "usecs/call" log', and avoid the use of 'cat' and extra process invocation.

Please do this here, and for the other uses of 'grep' below.

> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +rm log
> diff --git a/tests/Functional.ltrace/tests/ltrace_help.sh
> b/tests/Functional.ltrace/tests/ltrace_help.sh
> new file mode 100644
> index 0000000..ea45a7e
> --- /dev/null
> +++ b/tests/Functional.ltrace/tests/ltrace_help.sh
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +
> +#  In target, run comannd ltrace to display help message.
> +#  option: -h/--help
> +
> +test="help"
> +
> +if ltrace -h | grep [uU]sage
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> diff --git a/tests/Functional.ltrace/tests/ltrace_output.sh
> b/tests/Functional.ltrace/tests/ltrace_output.sh
> new file mode 100644
> index 0000000..2d941b0
> --- /dev/null
> +++ b/tests/Functional.ltrace/tests/ltrace_output.sh
> @@ -0,0 +1,15 @@
> +#!/bin/sh
> +
> +#  Write the trace output to the file filename rather than to stderr.
> +#  option: -o/--output
> +
> +test="output"

I would put 'rm log || true' here, to eliminate any
pre-existing 'log' file (and ignore the error if there is no 'log' file).

> +
> +ltrace -o log ls
> +if cat log | grep "+++ exited (status 0) +++"
Please remove the 'cat' here, as described above.

> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +rm log
> diff --git a/tests/Functional.ltrace/tests/ltrace_syscall.sh
> b/tests/Functional.ltrace/tests/ltrace_syscall.sh
> new file mode 100644
> index 0000000..34d1dc5
> --- /dev/null
> +++ b/tests/Functional.ltrace/tests/ltrace_syscall.sh
> @@ -0,0 +1,15 @@
> +#!/bin/sh
> +
> +#  In target, run comannd ltrace to display system calls.
> +#  option: -S
> +
> +test="syscall"
> +
> +ltrace -S ls > log 2>&1
> +if cat log | grep "+++ exited (status 0) +++"
Please remove the 'cat' here, as described above.

Also, can you please check that the trace has some piece
of valid data related to syscall tracing here (maybe in addition 
to the check of the final line that you already have).

For example, you could do a grep for SYS_getdents, and that would
show that the -S option worked and syscalls were showing
up in the log.

> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +rm log
> diff --git a/tests/Functional.ltrace/tests/ltrace_time.sh
> b/tests/Functional.ltrace/tests/ltrace_time.sh
> new file mode 100644
> index 0000000..fc09108
> --- /dev/null
> +++ b/tests/Functional.ltrace/tests/ltrace_time.sh
> @@ -0,0 +1,15 @@
> +#!/bin/sh
> +
> +#  In target, run comannd ltrace to show the time spent inside each call.
> +#  option: -T
> +
> +test="time"
> +
> +ltrace -T ls > log 2>&1
> +if cat log | grep "<[0-9].[0-9]\{6\}>"
Please avoid use of 'cat', as described above.

> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +rm log
> --
> 2.17.1


Thanks.  This looks good.  Please address my comments and resubmit.
 -- Tim


More information about the Fuego mailing list