[LTP] [PATCH v4 2/2] metaparse: Explicitly parse essential headers for macros

Li Wang li.wang@linux.dev
Thu May 21 05:27:59 CEST 2026


The metadata parser misses important path definition macros located in
tst_path_defs.h. This occurs because the file is included via
tst_test.h, which is intentionally ignored by the skip_includes[]
array to reduce parsing overhead. As a result, the dependency chain
is broken, and the underlying macros are never extracted.

To fix this without parsing the entirety of tst_test.h, this patch
introduces a must_includes[] array and a parse_must_files() function.
This allows the parser to explicitly locate and extract '#define' macros
from specific foundational headers directly from the include paths.

This data driven approach keeps the logic clean and provides an easily
extensible way to handle future headers that might face the same
include-skip issue.

Fixes: da3088183a ("metadata: metaparse: Implement recursive include")
Signed-off-by: Li Wang <li.wang@linux.dev>
---
 metadata/metaparse.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/metadata/metaparse.c b/metadata/metaparse.c
index c495d2eb5..6d50919c3 100644
--- a/metadata/metaparse.c
+++ b/metadata/metaparse.c
@@ -968,6 +968,33 @@ static struct data_node *parse_file(const char *fname)
 	return res;
 }
 
+static const char *must_includes[] = {
+       "tst_path_defs.h",
+       NULL
+};
+
+static void parse_must_files(void)
+{
+       unsigned int i, j;
+       FILE *f;
+       const char *token;
+
+       for (i = 0; must_includes[i]; i++) {
+               for (j = 0; j < cmdline_includepaths; j++) {
+                       f = open_file(cmdline_includepath[j], must_includes[i]);
+                       if (!f)
+                               continue;
+
+                       while ((token = next_token(f, NULL))) {
+                               if (!strcmp(token, "define"))
+                                       parse_macro(f);
+                       }
+                       fclose(f);
+                       break;
+               }
+       }
+}
+
 struct typemap {
 	const char *id;
 	enum data_type type;
@@ -1176,6 +1203,8 @@ int main(int argc, char *argv[])
 		return 1;
 	}
 
+	parse_must_files();
+
 	res = parse_file(argv[optind]);
 	if (!res)
 		return 0;
-- 
2.54.0



More information about the ltp mailing list