[LTP] [PATCH 2/9] metadata: metaparse: Implement recursive include
Cyril Hrubis
chrubis@suse.cz
Wed Dec 18 20:00:22 CET 2024
This is really needed in order to expand all relevant variables in the
tst_test structure. For example PATH_KSM is hidden in
kernel/include/ksm_helper.h which is included from
kernel/mem/include/mem.h which is included by ksm0*.c testcases.
We also have a list of headers to explicitly skip, that define many
macros that are not useful in tst_test structure expansion.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
metadata/metaparse.c | 42 ++++++++++++++++++++++++++++++++++++++++--
1 file changed, 40 insertions(+), 2 deletions(-)
diff --git a/metadata/metaparse.c b/metadata/metaparse.c
index bf9559712..486475780 100644
--- a/metadata/metaparse.c
+++ b/metadata/metaparse.c
@@ -237,6 +237,20 @@ static FILE *open_file(const char *dir, const char *fname)
return f;
}
+/**
+ * List of includes to be skipped.
+ *
+ * These define many macros or include many include files that are mostly
+ * useless to values expanded in tst_test structure. Or macros that shouldn't
+ * be expanded at all.
+ */
+static const char *skip_includes[] = {
+ "\"tst_test.h\"",
+ "\"config.h\"",
+ "\"tst_taint.h\"",
+ NULL
+};
+
static FILE *open_include(FILE *f)
{
char buf[256], *fname;
@@ -249,6 +263,20 @@ static FILE *open_include(FILE *f)
if (buf[0] != '"')
return NULL;
+ for (i = 0; skip_includes[i]; i++) {
+ if (!strcmp(skip_includes[i], buf)) {
+ if (verbose)
+ fprintf(stderr, "INCLUDE SKIP %s\n", buf);
+ return NULL;
+ }
+ }
+
+ if (!strncmp(buf, "\"lapi/", 6)) {
+ if (verbose)
+ fprintf(stderr, "INCLUDE SKIP %s\n", buf);
+ return NULL;
+ }
+
fname = buf + 1;
if (!buf[0])
@@ -641,12 +669,20 @@ static void parse_macro(FILE *f)
hsearch(e, ENTER);
}
-static void parse_include_macros(FILE *f)
+static void parse_include_macros(FILE *f, int level)
{
FILE *inc;
const char *token;
int hash = 0;
+ /**
+ * Allow only three levels of include indirection.
+ *
+ * Should be more than enough (TM).
+ */
+ if (level >= 3)
+ return;
+
inc = open_include(f);
if (!inc)
return;
@@ -662,6 +698,8 @@ static void parse_include_macros(FILE *f)
if (!strcmp(token, "define"))
parse_macro(inc);
+ else if (!strcmp(token, "include"))
+ parse_include_macros(inc, level+1);
hash = 0;
}
@@ -697,7 +735,7 @@ static struct data_node *parse_file(const char *fname)
parse_macro(f);
if (!strcmp(token, "include"))
- parse_include_macros(f);
+ parse_include_macros(f, 0);
}
}
--
2.45.2
More information about the ltp
mailing list