First new shell library converted test
v2 cover First new shell library converted test
This patchset contains a few fixes for the new shell library and first converted test.
Changes in v2:
- The save_restore parser now matches the C metadata format (after the metadata metaparse fixes I've send in another patchset)
- Added one more patch to make the tst_test structure in tst_res_ static
- the vma05.sh now uses the second argument for the values that are supposed to be written to these files
- restored the unset DEBUGINFOD_URLS in vma05.sh added by an accident (this may possibly fix the timeouts reported by pvorel)
Cyril Hrubis (6):
tst_run_shell: Add save_restore parser
tst_run_shell: Make the tst_test struct static libs/ujson: Fix "Garbage after JSON string!" in strict mode
tst_run_shell: Better errors for metadata extractor lib/tst_res_.c: Add TBROK handler + more verbose errors mem/vma05.sh: Convert to the new shell library
libs/ujson/ujson_reader.c | 6 +- testcases/kernel/mem/vma/vma05.sh | 96 +++++++++++++------------ testcases/lib/tst_res_.c | 22 +++--- testcases/lib/tst_run_shell.c | 114 ++++++++++++++++++++++++++++-- 4 files changed, 177 insertions(+), 61 deletions(-)
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/6 tst_run_shell: Add save_restore parser
--- testcases/lib/tst_run_shell.c | 87 +++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+)
testcases/lib/tst_run_shell.c +87 -0
@@ -74,6 +74,7 @@ enum test_attr_ids {NEEDS_ROOT ,NEEDS_TMPDIR ,RESTORE_WALLCLOCK , +SAVE_RESTORE ,SKIP_FILESYSTEMS ,SKIP_IN_COMPAT , SKIP_IN_LOCKDOWN,
@@ -106,6 +107,7 @@ static ujson_obj_attr test_attrs[] = {UJSON_OBJ_ATTR_IDX (NEEDS_ROOT ,"needs_root" ,UJSON_BOOL ),UJSON_OBJ_ATTR_IDX (NEEDS_TMPDIR ,"needs_tmpdir" ,UJSON_BOOL ),UJSON_OBJ_ATTR_IDX (RESTORE_WALLCLOCK ,"restore_wallclock" ,UJSON_BOOL ), +UJSON_OBJ_ATTR_IDX (SAVE_RESTORE ,"save_restore" ,UJSON_ARR ),UJSON_OBJ_ATTR_IDX (SKIP_FILESYSTEMS ,"skip_filesystems" ,UJSON_ARR ),UJSON_OBJ_ATTR_IDX (SKIP_IN_COMPAT ,"skip_in_compat" ,UJSON_BOOL ), UJSON_OBJ_ATTR_IDX(SKIP_IN_LOCKDOWN, "skip_in_lockdown", UJSON_BOOL),
@@ -299,6 +301,88 @@ static struct tst_tag *parse_tags(ujson_reader *reader, ujson_val *val)return ret; } +static struct tst_path_val *parse_save_restore (ujson_reader *reader,ujson_val *val) +{ +unsigned int i =0 , cnt =0 ; +struct tst_path_val *ret; + +ujson_reader_state state =ujson_reader_state_save (reader); + + UJSON_ARR_FOREACH(reader, val) { +if (val->type !=UJSON_ARR ) { +ujson_err (reader,"Expected array!" ); +return NULL ; + } +ujson_arr_skip (reader); + cnt++; + } + +ujson_reader_state_load (reader, state); + + ret =SAFE_MALLOC (sizeof (struct tst_path_val ) * (cnt +1 )); +memset (&ret[cnt],0 ,sizeof (ret[cnt])); + + UJSON_ARR_FOREACH(reader, val) { +char *path =NULL ; +char *pval =NULL ; +int flags_set =0 ; +int val_set =0 ; +unsigned int flags =0 ; + + UJSON_ARR_FOREACH(reader, val) { +if (!path) { +if (val->type !=UJSON_STR ) { +ujson_err (reader,"Expected string!" ); +return NULL ; + } + + path =strdup (val->val_str); + }else if (!val_set) { +if (val->type ==UJSON_STR ) { + pval =strdup (val->val_str); + }else if (val->type !=UJSON_NULL ) { +ujson_err (reader,"Expected string or NULL!" ); +return NULL ; + } + val_set =1 ; + }else if (!flags_set) { +if (val->type !=UJSON_STR ) { +ujson_err (reader,"Expected string!" ); +return NULL ; + } + +if (!strcmp (val->val_str,"TCONF" )) { + flags =TST_SR_TCONF ; + }else if (!strcmp (val->val_str,"TBROK" )) { + flags =TST_SR_TBROK ; + }else if (!strcmp (val->val_str,"SKIP" )) { + flags =TST_SR_SKIP ; + }else { +ujson_err (reader,"Invalid flags!" ); +return NULL ; + } + + flags_set =1 ; + }else { +ujson_err (reader,"Expected only two members!" ); +return NULL ; + } + } + +if (!path || !flags_set) { +ujson_err (reader,"Expected [\"/{proc,sys}/path\", {\"TCONF\", \"TBROK\", \"TSKIP\"}]!" ); +return NULL ; + } + + ret[i].path = path; + ret[i].val = pval; + ret[i].flags = flags; + i++; + } + +return ret; +} +static void parse_metadata (void ) {ujson_reader reader =UJSON_READER_INIT (metadata, metadata_used,UJSON_READER_STRICT );
@@ -385,6 +469,9 @@ static void parse_metadata(void)case RESTORE_WALLCLOCK : test.restore_wallclock = val.val_bool;break ; +case SAVE_RESTORE : + test.save_restore =parse_save_restore (&reader, &val); +break ;case SKIP_FILESYSTEMS : test.skip_filesystems =parse_strarr (&reader, &val);break ;
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/6 tst_run_shell: Make the tst_test struct static
In reply to Cyril Hrubis--- testcases/lib/tst_run_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/lib/tst_run_shell.c +1 -1
@@ -26,7 +26,7 @@ static void run_shell_tcnt(unsigned int n)tst_run_script (shell_filename, params); } -struct tst_test test = { +static struct tst_test test = { .runs_script =1 , };
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/6] tst_run_shell: Make the tst_test struct static
Hi Cyril,
Quoted 11 lines
Signed-off-by Cyril Hrubis <[email protected]>Suggested-by Petr Vorel <[email protected]>--- testcases/lib/tst_run_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)testcases/lib/tst_run_shell.c +0
-0
testcases/lib/tst_run_shell.c static void run_shell_tcnt(unsigned int n) · line 29
Quoted 5 lines
testcases/lib/tst_run_shell.c +1
-1@@ -26,7 +26,7 @@ static void run_shell_tcnt(unsigned int n)tst_run_script (shell_filename, params); } -struct tst_test test = { +static struct tst_test test = {
Thanks!
Could you please before merge also fix formatting error?
tst_run_shell.c:144: ERROR: "(foo*)" should be "(foo *)"
Kind regards,
Petr
Quoted 2 lines
testcases/lib/tst_run_shell.c +0
-0.runs_script = 1, };
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/6] tst_run_shell: Make the tst_test struct static
Hi!
I've fixed all the minor things you pointed out and pushed this patchset. Thanks for the reviews.
There is also one more patch that addes license and copyright to the newest shell library that I've pushed without prior review as it falls into the obvious fixes category.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 3/6 libs/ujson: Fix "Garbage after JSON string!" in strict mode
In reply to Cyril HrubisIn strict mode warnings are converted into errors and filled into the error buffer rather than being printed right away. That means that we have to print error buffer after we issue a warning so that it's printed in the strict mode (UJSON_READER_STRICT) as well.
--- libs/ujson/ujson_reader.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libs/ujson/ujson_reader.c +5 -1
@@ -1049,8 +1049,12 @@ void ujson_reader_finish(ujson_reader *self) {if (ujson_reader_err (self))ujson_err_print (self); -else if (!ujson_reader_consumed (self)) +else if (!ujson_reader_consumed (self)) {ujson_warn (self,"Garbage after JSON string!" ); + +if (ujson_reader_err (self)) +ujson_err_print (self); + } }void ujson_reader_free (ujson_reader *buf)
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 4/6 tst_run_shell: Better errors for metadata extractor
In reply to Cyril Hrubis- Add filename and lineno to error messages
- Make sure that we are still in the comment part and TBROK if any of the block wasn't terminated properly
--- testcases/lib/tst_run_shell.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)
testcases/lib/tst_run_shell.c +21 -4
@@ -521,6 +521,7 @@ static void extract_metadata(void)char line[4096 ];char path[4096 ];enum parser_state state =PAR_NONE ; +unsigned int lineno =1 ;if (tst_get_path (shell_filename, path,sizeof (path)) ==-1 )tst_brk (TBROK ,"Failed to find %s in $PATH" , shell_filename);
@@ -534,24 +535,40 @@ static void extract_metadata(void) state =PAR_ESC ;break ;case PAR_ESC : -if (!strcmp (line,"# env\n" )) +if (!strcmp (line,"# env\n" )) { state =PAR_ENV ; -else if (!strcmp (line,"# doc\n" )) + }else if (!strcmp (line,"# doc\n" )) { state =PAR_DOC ; -else -tst_brk (TBROK ,"Unknown comment block %s" , line); + }else { +tst_brk (TBROK ,"%s: %u: Unknown comment block %s" , + path, lineno, line); + }break ;case PAR_ENV : +if (line[0 ] !='#' ) { +tst_brk (TBROK , +"%s: %u: Unexpected end of comment block!" , + path, lineno); + } +if (!strcmp (line,"# ---\n" )) state =PAR_NONE ;else metadata_append (line +2 );break ;case PAR_DOC : +if (line[0 ] !='#' ) { +tst_brk (TBROK , +"%s: %u: Unexpected end of comment block!" , + path, lineno); + } +if (!strcmp (line,"# ---\n" )) state =PAR_NONE ;break ; } + + lineno++; }fclose (f);
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 5/6 lib/tst_res_.c: Add TBROK handler + more verbose errors
In reply to Cyril HrubisWe use the tst_res_ helper for tst_brk_ as well so we need to be able to handle TBROK type as well.
Note that we pass TBROK to the tst_res() here deliberately here because we want to return back to the shell library, which is the process that reports the TBROK to the test library by doing 'exit 2'. This works because we pass the value by a variable as compiler cannot evaluate it's value at a compile time.
--- testcases/lib/tst_res_.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
testcases/lib/tst_res_.c +14 -8
@@ -8,28 +8,34 @@static void print_help (void ) { -printf ("Usage: tst_res_ filename lineno [TPASS|TFAIL|TCONF|TINFO|TDEBUG] 'A short description'\n" ); +printf ("Usage: tst_{res,brk} filename lineno [TPASS|TBROK|TFAIL|TCONF|TINFO|TDEBUG] 'A short description'\n" ); }int main (int argc,char *argv[]) {int type, i; -if (argc <5 ) +if (argc <5 ) { +printf ("argc = %i expected 5\n" , argc); goto help; + } -if (!strcmp (argv[3 ],"TPASS" )) +if (!strcmp (argv[3 ],"TPASS" )) { type =TPASS ; -else if (!strcmp (argv[3 ],"TFAIL" )) + }else if (!strcmp (argv[3 ],"TFAIL" )) { type =TFAIL ; -else if (!strcmp (argv[3 ],"TCONF" )) + }else if (!strcmp (argv[3 ],"TCONF" )) { type =TCONF ; -else if (!strcmp (argv[3 ],"TINFO" )) + }else if (!strcmp (argv[3 ],"TINFO" )) { type =TINFO ; -else if (!strcmp (argv[3 ],"TDEBUG" )) + }else if (!strcmp (argv[3 ],"TDEBUG" )) { type =TDEBUG ; -else + }else if (!strcmp (argv[3 ],"TBROK" )) { + type =TBROK ; + }else { +printf ("Wrong type '%s'\n" , argv[3 ]); goto help; + }size_t len =0 ;
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 6/6 mem/vma05.sh: Convert to the new shell library
In reply to Cyril HrubisTo run the test from the test directory do:
PATH=$PATH:$PWD/../../../lib/:$PWD/testcases/lib/:: ./vma05.sh
--- testcases/kernel/mem/vma/vma05.sh | 96 ++++++++++++++++--------------- 1 file changed, 49 insertions(+), 47 deletions(-)
testcases/kernel/mem/vma/vma05.sh +49 -47
@@ -1,6 +1,15 @@ #!/bin/sh +# # SPDX-License-Identifier: GPL-2.0-or-later +# # Copyright (C) 2017 Red Hat, Inc. +# Copyright (C) 2024 Cyril Hrubis <[email protected]> +# +# --- +# doc +# +# [Description] +# # Regression test if the vsyscall and vdso VMA regions are reported correctly. # # While [vsyscall] is mostly deprecated with newer systems, there is
@@ -15,58 +24,51 @@ # VM_ALWAYSDUMP)). As a consequence of this bug, VMAs were not included # in core dumps which resulted in eg. incomplete backtraces and invalid # core dump files created by gdb. +# --- +# +# --- +# env +# { +# "needs_root": true, +# "needs_tmpdir": true, +# "needs_cmds": ["gdb"], +# "save_restore": [ +# ["/proc/sys/kernel/core_pattern", "core", "TBROK"], +# ["/proc/sys/kernel/core_uses_pid", "0", "TBROK"] +# ], +# "tags": [ +# ["linux-git", "103efcd9aac1"], +# ["linux-git", "b6558c4a2378"], +# ["linux-git", "e5b97dde514f"] +# ] +# } +# --- -TST_SETUP=setup -TST_CLEANUP=cleanup -TST_TESTFUNC=vma_report_check -TST_NEEDS_ROOT=1 -TST_NEEDS_TMPDIR=1 -TST_NEEDS_CMDS="gdb" - -CORE_LIMIT=$(ulimit -c) -CORE_PATTERN=$(cat /proc/sys/kernel/core_pattern) -CORE_USES_PID=$(cat /proc/sys/kernel/core_uses_pid) - -setup() -{ - ulimit -c unlimited - echo "core" > /proc/sys/kernel/core_pattern - echo 0 > /proc/sys/kernel/core_uses_pid - unset DEBUGINFOD_URLS -} +. tst_loader.sh -cleanup() -{ - ulimit -c "$CORE_LIMIT" - echo "$CORE_PATTERN" > /proc/sys/kernel/core_pattern - echo $CORE_USES_PID > /proc/sys/kernel/core_uses_pid -} +ulimit -c unlimited +unset DEBUGINFOD_URLS -vma_report_check() -{ - if [ $(uname -m) = "x86_64" ]; then - if LINE=$(grep "vsyscall" /proc/self/maps); then - RIGHT="ffffffffff600000-ffffffffff601000[[:space:]][r-]-xp" - if echo "$LINE" | grep -q "$RIGHT"; then - tst_res TPASS "[vsyscall] reported correctly" - else - tst_res TFAIL "[vsyscall] reporting wrong" - fi +if [ $(uname -m) = "x86_64" ]; then + if LINE=$(grep "vsyscall" /proc/self/maps); then + RIGHT="ffffffffff600000-ffffffffff601000[[:space:]][r-]-xp" + if echo "$LINE" | grep -q "$RIGHT"; then + tst_res TPASS "[vsyscall] reported correctly" + else + tst_res TFAIL "[vsyscall] reporting wrong" fi fi +fi - rm -rf core* - { vma05_vdso; } > /dev/null 2>&1 - [ -f core ] || tst_brk TBROK "missing core file" +rm -rf core* +{ vma05_vdso; } > /dev/null 2>&1 +[ -f core ] || tst_brk TBROK "missing core file" - TRACE=$(gdb -silent -ex="thread apply all backtrace" -ex="quit"\ - vma05_vdso ./core* 2> /dev/null) - if echo "$TRACE" | grep -qF "??"; then - tst_res TFAIL "[vdso] bug not patched" - else - tst_res TPASS "[vdso] backtrace complete" - fi -} +TRACE=$(gdb -silent -ex="thread apply all backtrace" -ex="quit"\ + vma05_vdso ./core* 2> /dev/null) -. tst_test.sh -tst_run +if echo "$TRACE" | grep -qF "??"; then + tst_res TFAIL "[vdso] bug not patched" +else + tst_res TPASS "[vdso] backtrace complete" +fi
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 6/6] mem/vma05.sh: Convert to the new shell library
Hi Cyril,
Thanks for these improvements. Few notes below.
Quoted 3 lines
To run the test from the test directory do:
PATH=$PATH:$PWD/../../../lib/:$PWD/testcases/lib/:: ./vma05.sh
very nit: safer example would be to have $PATH at the end of the list.
Quoted 10 lines
Signed-off-by Cyril Hrubis <[email protected]>--- testcases/kernel/mem/vma/vma05.sh | 96 ++++++++++++++++--------------- 1 file changed, 49 insertions(+), 47 deletions(-)testcases/kernel/mem/vma/vma05.sh +0
-0
testcases/kernel/mem/vma/vma05.sh line 4
Quoted 4 lines
testcases/kernel/mem/vma/vma05.sh +2
-0@@ -1,6 +1,15 @@ #!/bin/sh +# # SPDX-License-Identifier: GPL-2.0-or-later +#
very nit: I would not add these new lines.
Quoted 13 lines
testcases/kernel/mem/vma/vma05.sh +7
-0# Copyright (C) 2017 Red Hat, Inc. +# Copyright (C) 2024 Cyril Hrubis <[email protected]> +# +# --- +# doc +# +# [Description] +# # Regression test if the vsyscall and vdso VMA regions are reported correctly. # While [vsyscall] is mostly deprecated with newer systems, there is@@ -15,58 +24,51 @@ # VM_ALWAYSDUMP)). As a consequence of this bug, VMAs were not included
testcases/kernel/mem/vma/vma05.sh line 34
Quoted 10 lines
testcases/kernel/mem/vma/vma05.sh +8
-0# in core dumps which resulted in eg. incomplete backtraces and invalid # core dump files created by gdb. +# --- +# +# --- +# env +# { +# "needs_root": true, +# "needs_tmpdir": true, +# "needs_cmds": ["gdb"],
Maybe also "uname"?
testcases/kernel/mem/vma/vma05.sh line 42
Quoted 8 lines
testcases/kernel/mem/vma/vma05.sh +8
-0+# "save_restore": [ +# ["/proc/sys/kernel/core_pattern", "core", "TBROK"], +# ["/proc/sys/kernel/core_uses_pid", "0", "TBROK"] +# ], +# "tags": [ +# ["linux-git", "103efcd9aac1"], +# ["linux-git", "b6558c4a2378"], +# ["linux-git", "e5b97dde514f"]
I wonder how hard to add shell support (with help of ujson) to metadata/metaparse.c.
I created a ticket for it:
https://github.com/linux-test-project/ltp/issues/1216
Quoted 14 lines
testcases/kernel/mem/vma/vma05.sh +3
-8+# ] +# } +# --- -TST_SETUP=setup -TST_CLEANUP=cleanup -TST_TESTFUNC=vma_report_check -TST_NEEDS_ROOT=1 -TST_NEEDS_TMPDIR=1 -TST_NEEDS_CMDS="gdb" - -CORE_LIMIT=$(ulimit -c)
testcases/kernel/mem/vma/vma05.sh line 38
Quoted 10 lines
testcases/kernel/mem/vma/vma05.sh +0
-10-CORE_PATTERN=$(cat /proc/sys/kernel/core_pattern) -CORE_USES_PID=$(cat /proc/sys/kernel/core_uses_pid) - -setup() -{ - ulimit -c unlimited - echo "core" > /proc/sys/kernel/core_pattern - echo 0 > /proc/sys/kernel/core_uses_pid - unset DEBUGINFOD_URLS -}
We don't need setup and cleanup at all. But I see we don't have a support for them in testcases/lib/tst_run_shell.c yet. I might need to add it for netstress.c.
...
FYI testcases/lib/tests/shell_loader*.sh would deserve SPDX and copyright.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 6/6] mem/vma05.sh: Convert to the new shell library
Hi!
As for the minor adjustements I will fix them before merge if the patchset gets accepted.
Quoted 4 lines
I wonder how hard to add shell support (with help of ujson) to
metadata/metaparse.c.I created a ticket for it:
https://github.com/linux-test-project/ltp/issues/1216
The metadata are in the right format already, so the extraction will be easy. I've commented that issue and asigned it to myself.
Quoted 7 lines
testcases/kernel/mem/vma/vma05.sh line 45
Quoted 3 lines
testcases/kernel/mem/vma/vma05.sh +3
-0+# ] +# } +# ---We don't need setup and cleanup at all. But I see we don't have a support for them in
testcases/lib/tst_run_shell.cyet. I might need to add it fornetstress.c.
I will look into that later on. In this case we have to repeate the ulimit and unset on each test iteration because the shell script is re-executed for each -i value. So setup and cleanup are only useful for things that outlive the shell script itself e.g. starting and stopping a NFS sever.
Quoted 3 lines
...
FYI
testcases/lib/tests/shell_loader*.shwould deserve SPDX and copyright.
I guess that I will just commit this as an obvius fix.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp