[PATCH i-g-t v4 3/5] runner/settings: Add function to set IGT_DATA_PATH environment variable

Naladala Ramanaidu ramanaidu.naladala at intel.com
Tue Mar 25 21:01:44 UTC 2025


Add environment variable to obtain absolute path for PNG files
at runtime.

v2: Fix review comments. (Kamil)
v3: Fix review comments. (kamil)
V4: Fix review comments. (kamil)

Signed-off-by: Naladala Ramanaidu <ramanaidu.naladala at intel.com>
---
 runner/settings.c | 22 ++++++++++++++++++++++
 runner/settings.h |  1 +
 2 files changed, 23 insertions(+)

diff --git a/runner/settings.c b/runner/settings.c
index 1ccf345d9..94c95f26e 100644
--- a/runner/settings.c
+++ b/runner/settings.c
@@ -612,6 +612,21 @@ char *absolute_path(const char *path)
 	return result;
 }
 
+int set_tests_datadir(void)
+{
+	const char *datapath = "../share/igt-gpu-tools";
+	char *abpath;
+
+	abpath = absolute_path(datapath);
+
+	if (getenv("IGT_DATA_PATH") == NULL)
+		return setenv("IGT_DATA_PATH", abpath, 1);
+
+	return 0;
+}
+
+
+
 static char *bin_path(char *fname)
 {
 	char *path, *p;
@@ -654,6 +669,10 @@ void init_settings(struct settings *settings)
 {
 	memset(settings, 0, sizeof(*settings));
 	IGT_INIT_LIST_HEAD(&settings->env_vars);
+
+	if (set_tests_datadir())
+		fprintf(stderr, "Data dir path not set\n");
+
 	igt_vec_init(&settings->hook_strs, sizeof(char *));
 }
 
@@ -671,6 +690,9 @@ void clear_settings(struct settings *settings)
 	free_hook_strs(&settings->hook_strs);
 	free_array_deep((void **)settings->cmdline.argv, settings->cmdline.argc);
 
+	if (getenv("IGT_DATA_PATH") != NULL)
+		unsetenv("IGT_DATA_PATH");
+
 	init_settings(settings);
 }
 
diff --git a/runner/settings.h b/runner/settings.h
index 30743fc40..cbcf624b0 100644
--- a/runner/settings.h
+++ b/runner/settings.h
@@ -156,5 +156,6 @@ bool serialize_settings(struct settings *settings);
 
 bool read_settings_from_file(struct settings *settings, FILE* f);
 bool read_settings_from_dir(struct settings *settings, int dirfd);
+int set_tests_datadir(void);
 
 #endif
-- 
2.43.0



More information about the igt-dev mailing list