diff mbox series

Bug: ROD_SILENT does not preserve its argument list

Message ID BN1P110MB067481F2145E0C1A6A34240CDFB7A@BN1P110MB0674.NAMP110.PROD.OUTLOOK.COM
State Accepted
Headers show
Series Bug: ROD_SILENT does not preserve its argument list | expand

Checks

Context Check Description
acer/alpine_latest_gcc fail failure
acer/ubuntu_jammy_gcc fail failure
acer/debian_testing_clang fail failure
acer/ubuntu_bionic_gcc fail failure
acer/debian_stable_gcc fail failure
acer/debian_testing_gcc fail failure
acer/fedora_latest_clang fail failure
acer/debian_stable_s390x-linux-gnu-gcc_s390x fail failure
acer/debian_stable_powerpc64le-linux-gnu-gcc_ppc64el fail failure
acer/debian_stable_gcc fail failure
acer/debian_stable_aarch64-linux-gnu-gcc_arm64 fail failure
acer/debian_oldstable_clang fail failure
acer/debian_oldstable_gcc fail failure
acer/opensuse_leap_latest_gcc fail failure

Commit Message

Jiaying Song via ltp April 10, 2025, 9:22 p.m. UTC
Hello:
Submitting bug against ROD_SILENT.
Sincerely,

  *   John Morin.

==== Bug in ROD_SILENT ====
Need to quote "$@" in ROD_SILENT so each parameter is individually quoted. Otherwise, the original structure of its arguments is lost.

==== Fix ====

==== Test showing bug ====
Test "test1" is an LTP tests. The runs the same command using ROD and ROD_SILENT. The command it runs simply greps for string "blah1 blah2" in file data2. When run, ROD passes while ROD_SILENT fails. This is because ROD_SILENT does not preserve quoted arguments.

% cat data2
--- blah1 blah2 blah3 ---

% cat test1
#!/bin/bash
TST_TESTFUNC="do_test"
do_test()
{
    ROD        grep "blah1 blah2" data2
    ROD_SILENT grep "blah1 blah2" data2
    tst_res TPASS "pass"
}
. tst_test.sh
tst_run

% ./test1 # Note ROD passes while ROD_SILENT fails
> ./test1
test1 1 TINFO: Running: test1
test1 1 TINFO: Tested kernel: ...
test1 1 TINFO: timeout per run is 0h 5m 0s
--- blah1 blah2 blah3 ---
grep: blah2: No such file or directory
data2:--- blah1 blah2 blah3 ---
test1 1 TBROK: grep blah1 blah2 data2 failed

Summary:
passed   0
failed   0
broken   1
skipped  0
warnings 0

Comments

Petr Vorel April 16, 2025, 12:15 p.m. UTC | #1
Hi John,

> Hello:
> Submitting bug against ROD_SILENT.
> Sincerely,

NOTE: if you put the above below first '---', we read it on the mailing list,
but it will not be part of the commit message, see example [1].

>   *   John Morin.

> ==== Bug in ROD_SILENT ====
> Need to quote "$@" in ROD_SILENT so each parameter is individually quoted. Otherwise, the original structure of its arguments is lost.

> ==== Fix ====
> diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
> index 718a6b0ca..cfa327a8a 100644
> --- a/testcases/lib/tst_test.sh
> +++ b/testcases/lib/tst_test.sh
> @@ -153,7 +153,7 @@ ROD_SILENT()
> {
>         local tst_out

> -       tst_out="$(tst_rod $@ 2>&1)"
> +       tst_out=$(tst_rod "$@" 2>&1)
>         if [ $? -ne 0 ]; then
>                 echo "$tst_out"
>                 tst_brk TBROK "$@ failed"

> ==== Test showing bug ====
> Test "test1" is an LTP tests. The runs the same command using ROD and ROD_SILENT. The command it runs simply greps for string "blah1 blah2" in file data2. When run, ROD passes while ROD_SILENT fails. This is because ROD_SILENT does not preserve quoted arguments.

> % cat data2
> --- blah1 blah2 blah3 ---

Thank you for a valid fix + example how to test, merged as [2].

IMHO this was broken from the original implementation
14cefa9 ("tst_test.sh: Implement ROD_BASE in C") [3].

FYI patch was not applicable neither to the current master nor to the latest
LTP release 20250130. It was not difficult to apply the patch manually, but for
bigger changes it's better when the patch apply.

Before merging I reworded the commit message and added your SBT:

Signed-off-by: John Morin <John.Morin@gd-ms.com>

> % cat test1
> #!/bin/bash

Also, LTP uses POSIX shell syntax [4] (FYI it's better to test against /bin/dash, or
use checkbashisms, to make sure there is no bashism).

Kind regards,
Petr

[1] https://lore.kernel.org/ltp/20250402224148.435022-1-pvorel@suse.cz/
[2] https://github.com/linux-test-project/ltp/commit/0c0076fbaf6e0059b470fadff6240fc56952c218
[3] https://github.com/linux-test-project/ltp/commit/14cefa9387de5c23174c1a013dc2a04bb3717d4d
[4] https://linux-test-project.readthedocs.io/en/latest/developers/writing_tests.html#shell-coding-style

> TST_TESTFUNC="do_test"
> do_test()
> {
>     ROD        grep "blah1 blah2" data2
>     ROD_SILENT grep "blah1 blah2" data2
>     tst_res TPASS "pass"
> }
> . tst_test.sh
> tst_run

> % ./test1 # Note ROD passes while ROD_SILENT fails
> > ./test1
> test1 1 TINFO: Running: test1
> test1 1 TINFO: Tested kernel: ...
> test1 1 TINFO: timeout per run is 0h 5m 0s
> --- blah1 blah2 blah3 ---
> grep: blah2: No such file or directory
> data2:--- blah1 blah2 blah3 ---
> test1 1 TBROK: grep blah1 blah2 data2 failed

> Summary:
> passed   0
> failed   0
> broken   1
> skipped  0
> warnings 0
diff mbox series

Patch

diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index 718a6b0ca..cfa327a8a 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -153,7 +153,7 @@  ROD_SILENT()
{
        local tst_out

-       tst_out="$(tst_rod $@ 2>&1)"
+       tst_out=$(tst_rod "$@" 2>&1)
        if [ $? -ne 0 ]; then
                echo "$tst_out"
                tst_brk TBROK "$@ failed"