diff mbox series

[1/1] tools: Fix syntax error caused by "; ; " in create_dmesg_entry awk script

Message ID 20231227065118.209595-1-shichen@redhat.com
State Superseded
Headers show
Series [1/1] tools: Fix syntax error caused by "; ; " in create_dmesg_entry awk script | expand

Commit Message

Shizhao Chen Dec. 27, 2023, 6:51 a.m. UTC
When running runltp with both -S and -K provided, tests that are supposed to be
"skipped" and report TCONF results were failing due to an unexpected semicolon
at the end of the constructed command.

`-S` replace the test command with `exit 32;`
`-K` appends another semicolon to the command then we get `exit 32;;`

For example:

  >>> 780:madvise06__with_dmesg_entry BROK <<<

       1	<<<test_start>>>
       2	tag=madvise06__with_dmesg_entry stime=1703556061
       3	cmdline="dmesg -c 1>/dev/null 2>&1; exit 32;; dmesg > /mnt/testarea/ltp/output/DMESG_DIR_RHELKT1LITE.FILTERED-dmesg-output-53127-08:48:23PM/madvise06.dmesg.log"
       4	contacts=""
       5	analysis=exit
       6	<<<test_output>>>
       7	sh: -c: line 1: syntax error near unexpected token `;;'
       8	sh: -c: line 1: `dmesg -c 1>/dev/null 2>&1; exit 32;; dmesg > /mnt/testarea/ltp/output/DMESG_DIR_RHELKT1LITE.FILTERED-dmesg-output-53127-08:48:23PM/madvise06.dmesg.log'
       9	<<<execution_status>>>
      10	initiation_status="ok"
      11	duration=0 termination_type=exited termination_id=2 corefile=no
      12	cutime=0 cstime=1
      13	<<<test_end>>>

Signed-off-by: Shizhao Chen <shichen@redhat.com>
---
 tools/create_dmesg_entries_for_each_test.awk | 1 +
 1 file changed, 1 insertion(+)

Comments

Petr Vorel Dec. 27, 2023, 9:10 a.m. UTC | #1
Hi Shizhao,

> When running runltp with both -S and -K provided, tests that are supposed to be
> "skipped" and report TCONF results were failing due to an unexpected semicolon
> at the end of the constructed command.

> `-S` replace the test command with `exit 32;`
> `-K` appends another semicolon to the command then we get `exit 32;;`

> For example:

>   >>> 780:madvise06__with_dmesg_entry BROK <<<

>        1	<<<test_start>>>
>        2	tag=madvise06__with_dmesg_entry stime=1703556061
>        3	cmdline="dmesg -c 1>/dev/null 2>&1; exit 32;; dmesg > /mnt/testarea/ltp/output/DMESG_DIR_RHELKT1LITE.FILTERED-dmesg-output-53127-08:48:23PM/madvise06.dmesg.log"
>        4	contacts=""
>        5	analysis=exit
>        6	<<<test_output>>>
>        7	sh: -c: line 1: syntax error near unexpected token `;;'
>        8	sh: -c: line 1: `dmesg -c 1>/dev/null 2>&1; exit 32;; dmesg > /mnt/testarea/ltp/output/DMESG_DIR_RHELKT1LITE.FILTERED-dmesg-output-53127-08:48:23PM/madvise06.dmesg.log'
>        9	<<<execution_status>>>
>       10	initiation_status="ok"
>       11	duration=0 termination_type=exited termination_id=2 corefile=no
>       12	cutime=0 cstime=1
>       13	<<<test_end>>>

> Signed-off-by: Shizhao Chen <shichen@redhat.com>
> ---
>  tools/create_dmesg_entries_for_each_test.awk | 1 +
>  1 file changed, 1 insertion(+)

> diff --git a/tools/create_dmesg_entries_for_each_test.awk b/tools/create_dmesg_entries_for_each_test.awk
> index 25d750a55..7a22bb4a6 100644
> --- a/tools/create_dmesg_entries_for_each_test.awk
> +++ b/tools/create_dmesg_entries_for_each_test.awk
> @@ -27,6 +27,7 @@ NF && ! /^#/ {
>  	for (i = 2; i <= NF; i++) {
>  		s = s " " $i
>  	}
> +	sub(/;$/, "", s)

From the above context are you sure that there will not be missing semicolon?
(e.g. between dmesg and exit)

Wouldn't it be safe to make sure there is only only single semicolon at the end?

sub(/[;]+$/, ";")

Reviewed-by: Petr Vorel <pvorel@suse.cz>

FYI: runltp has been deprecated, we suggest to use python based kirk.
https://github.com/linux-test-project/kirk

Kind regards,
Petr

>  	s = s "; dmesg > " DMESG_DIR "/" $1 ".dmesg.log"
>  	print s
>  }
Li Wang Dec. 27, 2023, 12:01 p.m. UTC | #2
Hi Petr, Shizhao,

On Wed, Dec 27, 2023 at 5:10 PM Petr Vorel <pvorel@suse.cz> wrote:

> Hi Shizhao,
>
> > When running runltp with both -S and -K provided, tests that are
> supposed to be
> > "skipped" and report TCONF results were failing due to an unexpected
> semicolon
> > at the end of the constructed command.
>
> > `-S` replace the test command with `exit 32;`
> > `-K` appends another semicolon to the command then we get `exit 32;;`
>
> > For example:
>
> >   >>> 780:madvise06__with_dmesg_entry BROK <<<
>
> >        1      <<<test_start>>>
> >        2      tag=madvise06__with_dmesg_entry stime=1703556061
> >        3      cmdline="dmesg -c 1>/dev/null 2>&1; exit 32;; dmesg >
> /mnt/testarea/ltp/output/DMESG_DIR_RHELKT1LITE.FILTERED-dmesg-output-53127-08:48:23PM/madvise06.dmesg.log"
> >        4      contacts=""
> >        5      analysis=exit
> >        6      <<<test_output>>>
> >        7      sh: -c: line 1: syntax error near unexpected token `;;'
> >        8      sh: -c: line 1: `dmesg -c 1>/dev/null 2>&1; exit 32;;
> dmesg >
> /mnt/testarea/ltp/output/DMESG_DIR_RHELKT1LITE.FILTERED-dmesg-output-53127-08:48:23PM/madvise06.dmesg.log'
> >        9      <<<execution_status>>>
> >       10      initiation_status="ok"
> >       11      duration=0 termination_type=exited termination_id=2
> corefile=no
> >       12      cutime=0 cstime=1
> >       13      <<<test_end>>>
>
> > Signed-off-by: Shizhao Chen <shichen@redhat.com>
> > ---
> >  tools/create_dmesg_entries_for_each_test.awk | 1 +
> >  1 file changed, 1 insertion(+)
>
> > diff --git a/tools/create_dmesg_entries_for_each_test.awk
> b/tools/create_dmesg_entries_for_each_test.awk
> > index 25d750a55..7a22bb4a6 100644
> > --- a/tools/create_dmesg_entries_for_each_test.awk
> > +++ b/tools/create_dmesg_entries_for_each_test.awk
> > @@ -27,6 +27,7 @@ NF && ! /^#/ {
> >       for (i = 2; i <= NF; i++) {
> >               s = s " " $i
> >       }
> > +     sub(/;$/, "", s)
>
> From the above context are you sure that there will not be missing
> semicolon?
> (e.g. between dmesg and exit)
>
> Wouldn't it be safe to make sure there is only only single semicolon at
> the end?


> sub(/[;]+$/, ";")


Hmm, that would not work as expected because in the next line
forces adding a semicolon.

    s = s "; dmesg > " DMESG_DIR "/" $1 ".dmesg.log"

Unless we make a minor adjustments to your version:

    sub(/[;]+$/, "", s)


Otherwise LGTM:
Reviewed-by: Li Wang <liwang@redhat.com>
Petr Vorel Dec. 27, 2023, 2:28 p.m. UTC | #3
> Hi Petr, Shizhao,

> On Wed, Dec 27, 2023 at 5:10 PM Petr Vorel <pvorel@suse.cz> wrote:

> > Hi Shizhao,

> > > When running runltp with both -S and -K provided, tests that are
> > supposed to be
> > > "skipped" and report TCONF results were failing due to an unexpected
> > semicolon
> > > at the end of the constructed command.

> > > `-S` replace the test command with `exit 32;`
> > > `-K` appends another semicolon to the command then we get `exit 32;;`

> > > For example:

> > >   >>> 780:madvise06__with_dmesg_entry BROK <<<

> > >        1      <<<test_start>>>
> > >        2      tag=madvise06__with_dmesg_entry stime=1703556061
> > >        3      cmdline="dmesg -c 1>/dev/null 2>&1; exit 32;; dmesg >
> > /mnt/testarea/ltp/output/DMESG_DIR_RHELKT1LITE.FILTERED-dmesg-output-53127-08:48:23PM/madvise06.dmesg.log"
> > >        4      contacts=""
> > >        5      analysis=exit
> > >        6      <<<test_output>>>
> > >        7      sh: -c: line 1: syntax error near unexpected token `;;'
> > >        8      sh: -c: line 1: `dmesg -c 1>/dev/null 2>&1; exit 32;;
> > dmesg >
> > /mnt/testarea/ltp/output/DMESG_DIR_RHELKT1LITE.FILTERED-dmesg-output-53127-08:48:23PM/madvise06.dmesg.log'
> > >        9      <<<execution_status>>>
> > >       10      initiation_status="ok"
> > >       11      duration=0 termination_type=exited termination_id=2
> > corefile=no
> > >       12      cutime=0 cstime=1
> > >       13      <<<test_end>>>

> > > Signed-off-by: Shizhao Chen <shichen@redhat.com>
> > > ---
> > >  tools/create_dmesg_entries_for_each_test.awk | 1 +
> > >  1 file changed, 1 insertion(+)

> > > diff --git a/tools/create_dmesg_entries_for_each_test.awk
> > b/tools/create_dmesg_entries_for_each_test.awk
> > > index 25d750a55..7a22bb4a6 100644
> > > --- a/tools/create_dmesg_entries_for_each_test.awk
> > > +++ b/tools/create_dmesg_entries_for_each_test.awk
> > > @@ -27,6 +27,7 @@ NF && ! /^#/ {
> > >       for (i = 2; i <= NF; i++) {
> > >               s = s " " $i
> > >       }
> > > +     sub(/;$/, "", s)

> > From the above context are you sure that there will not be missing
> > semicolon?
> > (e.g. between dmesg and exit)

> > Wouldn't it be safe to make sure there is only only single semicolon at
> > the end?


> > sub(/[;]+$/, ";")


> Hmm, that would not work as expected because in the next line
> forces adding a semicolon.

>     s = s "; dmesg > " DMESG_DIR "/" $1 ".dmesg.log"

> Unless we make a minor adjustments to your version:

>     sub(/[;]+$/, "", s)

Ah, thanks Li!

I'm ok to merge your suggestion, just wait little longer for Shizhao, in case we
overlooked something.

Kind regards,
Petr

> Otherwise LGTM:
> Reviewed-by: Li Wang <liwang@redhat.com>
Shizhao Chen Dec. 28, 2023, 4:48 a.m. UTC | #4
Thanks for the review! I will send a v2 shortly.


On Wed, Dec 27, 2023 at 10:29 PM Petr Vorel <pvorel@suse.cz> wrote:
>
> > Hi Petr, Shizhao,
>
> > On Wed, Dec 27, 2023 at 5:10 PM Petr Vorel <pvorel@suse.cz> wrote:
>
> > > Hi Shizhao,
>
> > > > When running runltp with both -S and -K provided, tests that are
> > > supposed to be
> > > > "skipped" and report TCONF results were failing due to an unexpected
> > > semicolon
> > > > at the end of the constructed command.
>
> > > > `-S` replace the test command with `exit 32;`
> > > > `-K` appends another semicolon to the command then we get `exit 32;;`
>
> > > > For example:
>
> > > >   >>> 780:madvise06__with_dmesg_entry BROK <<<
>
> > > >        1      <<<test_start>>>
> > > >        2      tag=madvise06__with_dmesg_entry stime=1703556061
> > > >        3      cmdline="dmesg -c 1>/dev/null 2>&1; exit 32;; dmesg >
> > > /mnt/testarea/ltp/output/DMESG_DIR_RHELKT1LITE.FILTERED-dmesg-output-53127-08:48:23PM/madvise06.dmesg.log"
> > > >        4      contacts=""
> > > >        5      analysis=exit
> > > >        6      <<<test_output>>>
> > > >        7      sh: -c: line 1: syntax error near unexpected token `;;'
> > > >        8      sh: -c: line 1: `dmesg -c 1>/dev/null 2>&1; exit 32;;
> > > dmesg >
> > > /mnt/testarea/ltp/output/DMESG_DIR_RHELKT1LITE.FILTERED-dmesg-output-53127-08:48:23PM/madvise06.dmesg.log'
> > > >        9      <<<execution_status>>>
> > > >       10      initiation_status="ok"
> > > >       11      duration=0 termination_type=exited termination_id=2
> > > corefile=no
> > > >       12      cutime=0 cstime=1
> > > >       13      <<<test_end>>>
>
> > > > Signed-off-by: Shizhao Chen <shichen@redhat.com>
> > > > ---
> > > >  tools/create_dmesg_entries_for_each_test.awk | 1 +
> > > >  1 file changed, 1 insertion(+)
>
> > > > diff --git a/tools/create_dmesg_entries_for_each_test.awk
> > > b/tools/create_dmesg_entries_for_each_test.awk
> > > > index 25d750a55..7a22bb4a6 100644
> > > > --- a/tools/create_dmesg_entries_for_each_test.awk
> > > > +++ b/tools/create_dmesg_entries_for_each_test.awk
> > > > @@ -27,6 +27,7 @@ NF && ! /^#/ {
> > > >       for (i = 2; i <= NF; i++) {
> > > >               s = s " " $i
> > > >       }
> > > > +     sub(/;$/, "", s)
>
> > > From the above context are you sure that there will not be missing
> > > semicolon?
> > > (e.g. between dmesg and exit)
>
> > > Wouldn't it be safe to make sure there is only only single semicolon at
> > > the end?
>
>
> > > sub(/[;]+$/, ";")
>
>
> > Hmm, that would not work as expected because in the next line
> > forces adding a semicolon.
>
> >     s = s "; dmesg > " DMESG_DIR "/" $1 ".dmesg.log"
>
> > Unless we make a minor adjustments to your version:
>
> >     sub(/[;]+$/, "", s)
>
> Ah, thanks Li!
>
> I'm ok to merge your suggestion, just wait little longer for Shizhao, in case we
> overlooked something.
>
> Kind regards,
> Petr
>
> > Otherwise LGTM:
> > Reviewed-by: Li Wang <liwang@redhat.com>
>
diff mbox series

Patch

diff --git a/tools/create_dmesg_entries_for_each_test.awk b/tools/create_dmesg_entries_for_each_test.awk
index 25d750a55..7a22bb4a6 100644
--- a/tools/create_dmesg_entries_for_each_test.awk
+++ b/tools/create_dmesg_entries_for_each_test.awk
@@ -27,6 +27,7 @@  NF && ! /^#/ {
 	for (i = 2; i <= NF; i++) {
 		s = s " " $i
 	}
+	sub(/;$/, "", s)
 	s = s "; dmesg > " DMESG_DIR "/" $1 ".dmesg.log"
 	print s
 }