[PATCH i-g-t v5 1/2] lib/igt_core: move igt_load_igtrc to igt_rc

Sebastian Brzezinka <[email protected]> Tue, 4 Aug 2026 12:29:48 +0200
Newsgroups org.freedesktop.lists.igt-dev
Message-ID <[email protected]>
igt_load_igtrc() reads device configuration from the igtrc file and
is used by igt_core, igt_chamelium(_stream), the runner and lsgpu.
The associated global, igt_key_file, is already declared in lib/igt_rc.h,
so move the loader implementation there too instead of igt_core.c.

Signed-off-by: Sebastian Brzezinka <[email protected]>
Reviewed-by: Krzysztof Karas <[email protected]>
---
 lib/igt_core.c    | 47 -----------------------------------
 lib/igt_core.h    |  2 --
 lib/igt_rc.c      | 62 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_rc.h      |  2 ++
 lib/meson.build   |  4 ++-
 runner/executor.c |  1 +
 tools/lsgpu.c     |  1 +
 7 files changed, 69 insertions(+), 50 deletions(-)
 create mode 100644 lib/igt_rc.c

diff --git a/lib/igt_core.c b/lib/igt_core.c
index a7c097d9e..2f737b01a 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -972,53 +972,6 @@ static void oom_adjust_for_doom(void)
 
 }
 
-/**
- * load_igtrc:
- *
- * Load .igtrc from the path pointed to by #IGT_CONFIG_PATH or from
- * home directory if that is not set. The returned keyfile needs to be
- * deallocated using g_key_file_free().
- *
- * Returns: Pointer to the keyfile, NULL on error.
- */
-GKeyFile *igt_load_igtrc(void)
-{
-	char *key_file_env = NULL;
-	char *key_file_loc = NULL;
-	GError *error = NULL;
-	GKeyFile *file;
-	int ret;
-
-	/* Determine igt config path */
-	key_file_env = getenv("IGT_CONFIG_PATH");
-	if (key_file_env) {
-		key_file_loc = key_file_env;
-	} else {
-		key_file_loc = malloc(100);
-		snprintf(key_file_loc, 100, "%s/.igtrc", g_get_home_dir());
-	}
-
-	/* Load igt config file */
-	file = g_key_file_new();
-	ret = g_key_file_load_from_file(file, key_file_loc,
-					G_KEY_FILE_NONE, &error);
-	if (!ret) {
-		g_error_free(error);
-		g_key_file_free(file);
-		file = NULL;
-
-		goto out;
-	}
-
-	g_clear_error(&error);
-
- out:
-	if (!key_file_env && key_file_loc)
-		free(key_file_loc);
-
-	return file;
-}
-
 static void common_init_config(void)
 {
 	GError *error = NULL;
diff --git a/lib/igt_core.h b/lib/igt_core.h
index 3337293bc..afaf35aa8 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -95,8 +95,6 @@ extern const char* __igt_test_description __attribute__((weak));
 extern bool __igt_plain_output;
 extern char *igt_frame_dump_path;
 
-struct _GKeyFile *igt_load_igtrc(void);
-
 /**
  * IGT_TEST_DESCRIPTION:
  * @str: description string
diff --git a/lib/igt_rc.c b/lib/igt_rc.c
new file mode 100644
index 000000000..b7f1731fe
--- /dev/null
+++ b/lib/igt_rc.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2026 Intel Corporation
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifndef ANDROID
+#include <glib.h>
+#else
+#include "android/glib.h"
+#endif
+
+#include "igt_rc.h"
+
+/**
+ * igt_load_igtrc:
+ *
+ * Load .igtrc from the path pointed to by #IGT_CONFIG_PATH or from
+ * home directory if that is not set. The returned keyfile needs to be
+ * deallocated using g_key_file_free().
+ *
+ * Returns: Pointer to the keyfile, NULL on error.
+ */
+GKeyFile *igt_load_igtrc(void)
+{
+	char *key_file_env = NULL;
+	char *key_file_loc = NULL;
+	GError *error = NULL;
+	GKeyFile *file;
+	int ret;
+
+	/* Determine igt config path */
+	key_file_env = getenv("IGT_CONFIG_PATH");
+	if (key_file_env) {
+		key_file_loc = key_file_env;
+	} else {
+		key_file_loc = malloc(100);
+		snprintf(key_file_loc, 100, "%s/.igtrc", g_get_home_dir());
+	}
+
+	/* Load igt config file */
+	file = g_key_file_new();
+	ret = g_key_file_load_from_file(file, key_file_loc,
+					G_KEY_FILE_NONE, &error);
+	if (!ret) {
+		g_error_free(error);
+		g_key_file_free(file);
+		file = NULL;
+
+		goto out;
+	}
+
+	g_clear_error(&error);
+
+ out:
+	if (!key_file_env && key_file_loc)
+		free(key_file_loc);
+
+	return file;
+}
diff --git a/lib/igt_rc.h b/lib/igt_rc.h
index d871b3b26..3b7179808 100644
--- a/lib/igt_rc.h
+++ b/lib/igt_rc.h
@@ -33,4 +33,6 @@
 
 extern GKeyFile *igt_key_file;
 
+struct _GKeyFile *igt_load_igtrc(void);
+
 #endif /* IGT_RC_H */
diff --git a/lib/meson.build b/lib/meson.build
index 3001b473e..484cd4a55 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -37,6 +37,7 @@ lib_sources = [
 	'igt_os.c',
 	'igt_params.c',
 	'igt_perf.c',
+	'igt_rc.c',
 	'igt_pipe_crc.c',
 	'igt_power.c',
 	'igt_primes.c',
@@ -436,8 +437,9 @@ lib_igt_device_scan_build = static_library('igt_device_scan',
 	'igt_map.c',
 	'intel_device_info.c',
 	'intel_cmds_info.c',
+	'igt_rc.c',
 	],
-	dependencies : [scan_dep, lib_igt_drm_stub, lib_igt_tools_stub],
+	dependencies : [scan_dep, lib_igt_drm_stub, lib_igt_tools_stub, glib],
 	include_directories : inc)
 
 lib_igt_device_scan = declare_dependency(link_with : lib_igt_device_scan_build,
diff --git a/runner/executor.c b/runner/executor.c
index a8907c575..1592feee2 100644
--- a/runner/executor.c
+++ b/runner/executor.c
@@ -36,6 +36,7 @@
 #include "igt_aux.h"
 #include "igt_core.h"
 #include "igt_facts.h"
+#include "igt_rc.h"
 #include "igt_taints.h"
 #include "igt_vec.h"
 #include "executor.h"
diff --git a/tools/lsgpu.c b/tools/lsgpu.c
index 935371dea..3f8444187 100644
--- a/tools/lsgpu.c
+++ b/tools/lsgpu.c
@@ -36,6 +36,7 @@
 
 #include "igt.h"
 #include "igt_device_scan.h"
+#include "igt_rc.h"
 
 /**
  * SECTION:lsgpu
-- 
2.53.0