Re: [PATCH i-g-t v4 30/31] lib/igt_core: move igt_load_igtrc to igt_rc

Kamil Konieczny <[email protected]> Wed, 29 Jul 2026 15:37:22 +0200
Newsgroups org.freedesktop.lists.igt-dev
Message-ID <[email protected]>
Hi Sebastian,
On 2026-07-27 at 15:22:58 +0200, Sebastian Brzezinka wrote:
> 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]>
> ---
>  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 +
>  6 files changed, 68 insertions(+), 50 deletions(-)
>  create mode 100644 lib/igt_rc.c

I applied 1...29, thank you all!

Btw this one patch didn't compile when I used:

git rebase origin -x ./compile.sh

I got an error:
168 |         GKeyFile *key_file = igt_load_igtrc();
    |                              ^~~~~~~~~~~~~~
../tools/lsgpu.c:168:30: warning: nested extern declaration of 'igt_load_igtrc' [-Wnested-externs]
../tools/lsgpu.c:168:30: error: initialization of 'GKeyFile *' {aka 'struct _GKeyFile *'} from 'int' makes pointer from integer without a cast [-Werror=int-conversion]
cc1: some warnings being treated as errors

git status
interactive rebase in progress; onto 2613ddf77
Last commands done (60 commands done):
	pick 393be03c9 # lib/igt_core: move igt_load_igtrc to igt_rc
	exec ./compile.sh
(see more in file .git/rebase-merge/done)
Next commands to do (2 remaining commands):
	pick f1ecd9dd0 # tools/lsgpu: link with minimal sub-libraries
	exec ./compile.sh
(use "git rebase --edit-todo" to view and edit)

Regards,
Kamil

> 
> 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 aa8eae68b..9bd484c98 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',
> @@ -379,8 +380,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"
> -- 
> 2.53.0
>