* [LTP] [PATCH 0/2] Add shell test metadata parser
@ 2025-02-12 13:16 Cyril Hrubis
2025-02-12 13:16 ` [LTP] [PATCH 1/2] metaparse: Add shell test parser Cyril Hrubis
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Cyril Hrubis @ 2025-02-12 13:16 UTC (permalink / raw)
To: ltp
As promised this adds metadata parser for the shell testcases. In the
end I wrote it in about 100 lines of C because the ekvivalent awk script
would be too complicated.
Cyril Hrubis (2):
metaparse: Add shell test parser
metaparse: data_storage: Fix warning
metadata/.gitignore | 1 +
metadata/Makefile | 4 +-
metadata/data_storage.h | 2 +-
metadata/metaparse-sh.c | 127 ++++++++++++++++++++++++++++++++++++++++
metadata/parse.sh | 13 ++++
5 files changed, 144 insertions(+), 3 deletions(-)
create mode 100644 metadata/metaparse-sh.c
--
2.45.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 9+ messages in thread* [LTP] [PATCH 1/2] metaparse: Add shell test parser 2025-02-12 13:16 [LTP] [PATCH 0/2] Add shell test metadata parser Cyril Hrubis @ 2025-02-12 13:16 ` Cyril Hrubis 2025-02-12 14:03 ` Petr Vorel 2025-02-13 12:48 ` Ricardo B. Marlière 2025-02-12 13:16 ` [LTP] [PATCH 2/2] metaparse: data_storage: Fix warning Cyril Hrubis ` (2 subsequent siblings) 3 siblings, 2 replies; 9+ messages in thread From: Cyril Hrubis @ 2025-02-12 13:16 UTC (permalink / raw) To: ltp Signed-off-by: Cyril Hrubis <chrubis@suse.cz> --- metadata/.gitignore | 1 + metadata/Makefile | 4 +- metadata/metaparse-sh.c | 127 ++++++++++++++++++++++++++++++++++++++++ metadata/parse.sh | 13 ++++ 4 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 metadata/metaparse-sh.c diff --git a/metadata/.gitignore b/metadata/.gitignore index 07d2fd6ff..bb6399e5c 100644 --- a/metadata/.gitignore +++ b/metadata/.gitignore @@ -1,2 +1,3 @@ metaparse +metaparse-sh ltp.json diff --git a/metadata/Makefile b/metadata/Makefile index 522af4270..641657318 100644 --- a/metadata/Makefile +++ b/metadata/Makefile @@ -7,12 +7,12 @@ include $(top_srcdir)/include/mk/env_pre.mk include $(top_srcdir)/include/mk/functions.mk MAKE_TARGETS := ltp.json -HOST_MAKE_TARGETS := metaparse +HOST_MAKE_TARGETS := metaparse metaparse-sh INSTALL_DIR = metadata .PHONY: ltp.json -ltp.json: metaparse +ltp.json: metaparse metaparse-sh $(abs_srcdir)/parse.sh > ltp.json ifeq ($(WITH_METADATA),yes) mkdir -p $(abs_top_builddir)/docparse diff --git a/metadata/metaparse-sh.c b/metadata/metaparse-sh.c new file mode 100644 index 000000000..9eb38f583 --- /dev/null +++ b/metadata/metaparse-sh.c @@ -0,0 +1,127 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2025 Cyril Hrubis <chrubis@suse.cz> + */ + +#include <stdio.h> +#include <string.h> +#include <libgen.h> + +#include "data_storage.h" + +static int started; + +static void json_start(char *path) +{ + if (started) + return; + + started = 1; + + printf(" \"%s\": {\n", basename(path)); +} + +static void json_finish(const char *path) +{ + if (!started) + return; + + printf(" \"fname\": \"%s\"\n", path); + printf(" }"); +} + +enum state { + NONE, + START, + DOC_FIRST, + DOC, + ENV_START, + ENV_FIRST, + ENV +}; + +static void parse_shell(char *path) +{ + char line[4096]; + FILE *f = fopen(path, "r"); + enum state state = NONE; + + while (fgets(line, sizeof(line), f)) { + /* Strip newline */ + line[strlen(line)-1] = 0; + + switch (state) { + case NONE: + if (!strcmp(line, "# ---")) + state = START; + break; + case START: + if (!strcmp(line, "# doc")) { + json_start(path); + state = DOC_FIRST; + printf(" \"doc\": [\n"); + } else if (!strcmp(line, "# env")) { + json_start(path); + state = ENV_START; + } else { + state = NONE; + } + break; + case DOC: + case DOC_FIRST: + if (!strcmp(line, "# ---")) { + state = NONE; + printf("\n ],\n"); + continue; + } + + if (state == DOC_FIRST) + state = DOC; + else + printf(",\n"); + + data_fprintf_esc(stdout, 4, line+2); + break; + case ENV_START: + if (!strcmp(line, "# {")) { + state = ENV_FIRST; + } else { + fprintf(stderr, + "%s: Invalid line in JSON block '%s'", + path, line); + } + break; + case ENV: + case ENV_FIRST: + if (!strcmp(line, "# }")) { + state = NONE; + printf(",\n"); + continue; + } + + + if (state == ENV_FIRST) + state = ENV; + else + printf("\n"); + + line[0] = ' '; + line[1] = ' '; + + printf("%s", line); + break; + } + } + + json_finish(path); +} + +int main(int argc, char *argv[]) +{ + int i; + + for (i = 1; i < argc; i++) + parse_shell(argv[i]); + + return 0; +} diff --git a/metadata/parse.sh b/metadata/parse.sh index 7db2e2415..45776e4d0 100755 --- a/metadata/parse.sh +++ b/metadata/parse.sh @@ -42,6 +42,19 @@ EOF fi done +for test in `find testcases/ -not -path "testcases/lib/*" -name '*.sh'|sort`; do + a=$($top_builddir/metadata/metaparse-sh "$test") + if [ -n "$a" ]; then + if [ -z "$first" ]; then + echo ',' + fi + first= + cat <<EOF +$a +EOF + fi +done + echo echo ' }' echo '}' -- 2.45.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH 1/2] metaparse: Add shell test parser 2025-02-12 13:16 ` [LTP] [PATCH 1/2] metaparse: Add shell test parser Cyril Hrubis @ 2025-02-12 14:03 ` Petr Vorel 2025-02-13 12:48 ` Ricardo B. Marlière 1 sibling, 0 replies; 9+ messages in thread From: Petr Vorel @ 2025-02-12 14:03 UTC (permalink / raw) To: Cyril Hrubis; +Cc: ltp Hi Cyril, Great, thank you! Reviewed-by: Petr Vorel <pvorel@suse.cz> Quick notes: * Implementing help under -h would be a bonus (it segfaults on -h, metadata.c has it). But this should not block you merging it. * Please merge with whitespace error $ make check-metaparse-sh CHECK metadata/metaparse-sh.c metaparse-sh.c:90: ERROR: code indent should use tabs where possible * Resulting JSON has true, 1 instead would be nice. Again, tiny detail. "vma05.sh": { "doc": [ "", "[Description]", "", "Regression test if the vsyscall and vdso VMA regions are reported correctly.", "", "While [vsyscall] is mostly deprecated with newer systems, there is", "still plenty of kernels compiled with CONFIG_LEGACY_VSYSCALL_NATIVE and", "CONFIG_LEGACY_VSYSCALL_EMULATE (see linux/arch/x86/Kconfig for option", "descriptions). First part of the test will check eligible kernels for", "regression for a bug fixed by commit 103efcd9aac1 (fix perms/range of", "vsyscall vma in /proc/*/maps).", "", "Second part of test checks [vdso] VMA permissions (fixed with commits", "b6558c4a2378 (fix [vdso] page permissions) and e5b97dde514f (Add", "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." ], "needs_root": true, "needs_tmpdir": true, "needs_cmds": ["gdb", "uname"], "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"] ], "fname": "testcases/kernel/mem/vma/vma05.sh" } Kind regards, Petr -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH 1/2] metaparse: Add shell test parser 2025-02-12 13:16 ` [LTP] [PATCH 1/2] metaparse: Add shell test parser Cyril Hrubis 2025-02-12 14:03 ` Petr Vorel @ 2025-02-13 12:48 ` Ricardo B. Marlière 1 sibling, 0 replies; 9+ messages in thread From: Ricardo B. Marlière @ 2025-02-13 12:48 UTC (permalink / raw) To: Cyril Hrubis, ltp; +Cc: ltp On Wed Feb 12, 2025 at 10:16 AM -03, Cyril Hrubis wrote: > Signed-off-by: Cyril Hrubis <chrubis@suse.cz> > --- > metadata/.gitignore | 1 + > metadata/Makefile | 4 +- > metadata/metaparse-sh.c | 127 ++++++++++++++++++++++++++++++++++++++++ > metadata/parse.sh | 13 ++++ > 4 files changed, 143 insertions(+), 2 deletions(-) > create mode 100644 metadata/metaparse-sh.c > > diff --git a/metadata/.gitignore b/metadata/.gitignore > index 07d2fd6ff..bb6399e5c 100644 > --- a/metadata/.gitignore > +++ b/metadata/.gitignore > @@ -1,2 +1,3 @@ > metaparse > +metaparse-sh > ltp.json > diff --git a/metadata/Makefile b/metadata/Makefile > index 522af4270..641657318 100644 > --- a/metadata/Makefile > +++ b/metadata/Makefile > @@ -7,12 +7,12 @@ include $(top_srcdir)/include/mk/env_pre.mk > include $(top_srcdir)/include/mk/functions.mk > > MAKE_TARGETS := ltp.json > -HOST_MAKE_TARGETS := metaparse > +HOST_MAKE_TARGETS := metaparse metaparse-sh > INSTALL_DIR = metadata > > .PHONY: ltp.json > > -ltp.json: metaparse > +ltp.json: metaparse metaparse-sh > $(abs_srcdir)/parse.sh > ltp.json > ifeq ($(WITH_METADATA),yes) > mkdir -p $(abs_top_builddir)/docparse > diff --git a/metadata/metaparse-sh.c b/metadata/metaparse-sh.c > new file mode 100644 > index 000000000..9eb38f583 > --- /dev/null > +++ b/metadata/metaparse-sh.c > @@ -0,0 +1,127 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2025 Cyril Hrubis <chrubis@suse.cz> > + */ > + > +#include <stdio.h> > +#include <string.h> > +#include <libgen.h> > + > +#include "data_storage.h" > + > +static int started; > + > +static void json_start(char *path) > +{ > + if (started) > + return; > + > + started = 1; > + > + printf(" \"%s\": {\n", basename(path)); > +} > + > +static void json_finish(const char *path) > +{ > + if (!started) > + return; > + > + printf(" \"fname\": \"%s\"\n", path); > + printf(" }"); > +} > + > +enum state { > + NONE, > + START, > + DOC_FIRST, > + DOC, > + ENV_START, > + ENV_FIRST, > + ENV > +}; > + > +static void parse_shell(char *path) > +{ > + char line[4096]; > + FILE *f = fopen(path, "r"); > + enum state state = NONE; > + > + while (fgets(line, sizeof(line), f)) { > + /* Strip newline */ > + line[strlen(line)-1] = 0; > + > + switch (state) { > + case NONE: > + if (!strcmp(line, "# ---")) > + state = START; > + break; > + case START: > + if (!strcmp(line, "# doc")) { > + json_start(path); > + state = DOC_FIRST; > + printf(" \"doc\": [\n"); > + } else if (!strcmp(line, "# env")) { > + json_start(path); > + state = ENV_START; > + } else { > + state = NONE; > + } > + break; > + case DOC: > + case DOC_FIRST: > + if (!strcmp(line, "# ---")) { > + state = NONE; > + printf("\n ],\n"); > + continue; > + } > + > + if (state == DOC_FIRST) > + state = DOC; > + else > + printf(",\n"); > + > + data_fprintf_esc(stdout, 4, line+2); > + break; > + case ENV_START: > + if (!strcmp(line, "# {")) { > + state = ENV_FIRST; > + } else { > + fprintf(stderr, > + "%s: Invalid line in JSON block '%s'", > + path, line); > + } > + break; > + case ENV: > + case ENV_FIRST: > + if (!strcmp(line, "# }")) { > + state = NONE; > + printf(",\n"); > + continue; > + } > + > + nit: double blank line here > + if (state == ENV_FIRST) > + state = ENV; > + else > + printf("\n"); > + > + line[0] = ' '; > + line[1] = ' '; > + > + printf("%s", line); > + break; > + } > + } > + > + json_finish(path); > +} > + > +int main(int argc, char *argv[]) > +{ > + int i; > + > + for (i = 1; i < argc; i++) > + parse_shell(argv[i]); > + > + return 0; > +} > diff --git a/metadata/parse.sh b/metadata/parse.sh > index 7db2e2415..45776e4d0 100755 > --- a/metadata/parse.sh > +++ b/metadata/parse.sh > @@ -42,6 +42,19 @@ EOF > fi > done > > +for test in `find testcases/ -not -path "testcases/lib/*" -name '*.sh'|sort`; do > + a=$($top_builddir/metadata/metaparse-sh "$test") > + if [ -n "$a" ]; then > + if [ -z "$first" ]; then > + echo ',' > + fi > + first= > + cat <<EOF > +$a > +EOF > + fi > +done > + > echo > echo ' }' > echo '}' -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 9+ messages in thread
* [LTP] [PATCH 2/2] metaparse: data_storage: Fix warning 2025-02-12 13:16 [LTP] [PATCH 0/2] Add shell test metadata parser Cyril Hrubis 2025-02-12 13:16 ` [LTP] [PATCH 1/2] metaparse: Add shell test parser Cyril Hrubis @ 2025-02-12 13:16 ` Cyril Hrubis 2025-02-12 14:04 ` Petr Vorel 2025-02-13 12:41 ` [LTP] [PATCH 0/2] Add shell test metadata parser Ricardo B. Marlière 2025-02-25 13:14 ` Cyril Hrubis 3 siblings, 1 reply; 9+ messages in thread From: Cyril Hrubis @ 2025-02-12 13:16 UTC (permalink / raw) To: ltp Make data_node_hash_get static inline in order to avoid unused warnings. Signed-off-by: Cyril Hrubis <chrubis@suse.cz> --- metadata/data_storage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata/data_storage.h b/metadata/data_storage.h index 6427ea1ed..82d67b829 100644 --- a/metadata/data_storage.h +++ b/metadata/data_storage.h @@ -212,7 +212,7 @@ static inline int data_node_hash_del(struct data_node *self, const char *id) return 1; } -static struct data_node *data_node_hash_get(struct data_node *self, const char *id) +static inline struct data_node *data_node_hash_get(struct data_node *self, const char *id) { unsigned int i; struct data_node_hash *hash = &self->hash; -- 2.45.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH 2/2] metaparse: data_storage: Fix warning 2025-02-12 13:16 ` [LTP] [PATCH 2/2] metaparse: data_storage: Fix warning Cyril Hrubis @ 2025-02-12 14:04 ` Petr Vorel 0 siblings, 0 replies; 9+ messages in thread From: Petr Vorel @ 2025-02-12 14:04 UTC (permalink / raw) To: Cyril Hrubis; +Cc: ltp Hi Cyril, > Make data_node_hash_get static inline in order to avoid unused warnings. Obviously correct, thanks! Reviewed-by: Petr Vorel <pvorel@suse.cz> Kind regards, Petr -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH 0/2] Add shell test metadata parser 2025-02-12 13:16 [LTP] [PATCH 0/2] Add shell test metadata parser Cyril Hrubis 2025-02-12 13:16 ` [LTP] [PATCH 1/2] metaparse: Add shell test parser Cyril Hrubis 2025-02-12 13:16 ` [LTP] [PATCH 2/2] metaparse: data_storage: Fix warning Cyril Hrubis @ 2025-02-13 12:41 ` Ricardo B. Marlière 2025-02-13 14:06 ` Cyril Hrubis 2025-02-25 13:14 ` Cyril Hrubis 3 siblings, 1 reply; 9+ messages in thread From: Ricardo B. Marlière @ 2025-02-13 12:41 UTC (permalink / raw) To: Cyril Hrubis, ltp; +Cc: ltp Hello! On Wed Feb 12, 2025 at 10:16 AM -03, Cyril Hrubis wrote: > As promised this adds metadata parser for the shell testcases. In the > end I wrote it in about 100 lines of C because the ekvivalent awk script > would be too complicated. > > Cyril Hrubis (2): > metaparse: Add shell test parser > metaparse: data_storage: Fix warning > > metadata/.gitignore | 1 + > metadata/Makefile | 4 +- > metadata/data_storage.h | 2 +- > metadata/metaparse-sh.c | 127 ++++++++++++++++++++++++++++++++++++++++ > metadata/parse.sh | 13 ++++ > 5 files changed, 144 insertions(+), 3 deletions(-) > create mode 100644 metadata/metaparse-sh.c For the series: Reviewed-by: Ricardo B. Marlière <ricardo@marliere.net> Tested-by: Ricardo B. Marlière <ricardo@marliere.net> So, currently there's only testcases/kernel/mem/vma/vma05.sh and the goal is to add metadata to all *.sh tests, correct? Thanks, - Ricardo. -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH 0/2] Add shell test metadata parser 2025-02-13 12:41 ` [LTP] [PATCH 0/2] Add shell test metadata parser Ricardo B. Marlière @ 2025-02-13 14:06 ` Cyril Hrubis 0 siblings, 0 replies; 9+ messages in thread From: Cyril Hrubis @ 2025-02-13 14:06 UTC (permalink / raw) To: Ricardo B. Marlière; +Cc: ltp, ltp Hi! > So, currently there's only testcases/kernel/mem/vma/vma05.sh and the > goal is to add metadata to all *.sh tests, correct? Indeed, now I'm looking at how to add setup and cleanup support to the shell library so that we can convert more tests to it. -- Cyril Hrubis chrubis@suse.cz -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH 0/2] Add shell test metadata parser 2025-02-12 13:16 [LTP] [PATCH 0/2] Add shell test metadata parser Cyril Hrubis ` (2 preceding siblings ...) 2025-02-13 12:41 ` [LTP] [PATCH 0/2] Add shell test metadata parser Ricardo B. Marlière @ 2025-02-25 13:14 ` Cyril Hrubis 3 siblings, 0 replies; 9+ messages in thread From: Cyril Hrubis @ 2025-02-25 13:14 UTC (permalink / raw) To: ltp Hi! I've fixed the problems pointed out in the review and pushed, thanks. - Fixed various whitespaces - Added check if file was opened succesfully -- Cyril Hrubis chrubis@suse.cz -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-02-25 13:15 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-02-12 13:16 [LTP] [PATCH 0/2] Add shell test metadata parser Cyril Hrubis 2025-02-12 13:16 ` [LTP] [PATCH 1/2] metaparse: Add shell test parser Cyril Hrubis 2025-02-12 14:03 ` Petr Vorel 2025-02-13 12:48 ` Ricardo B. Marlière 2025-02-12 13:16 ` [LTP] [PATCH 2/2] metaparse: data_storage: Fix warning Cyril Hrubis 2025-02-12 14:04 ` Petr Vorel 2025-02-13 12:41 ` [LTP] [PATCH 0/2] Add shell test metadata parser Ricardo B. Marlière 2025-02-13 14:06 ` Cyril Hrubis 2025-02-25 13:14 ` Cyril Hrubis
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox