[PATCH i-g-t v12 01/11] include/android: Add stub for procps and glib

Kamil Konieczny kamil.konieczny at linux.intel.com
Tue Jun 3 15:34:41 UTC 2025


Hi Jeevaka,
On 2025-06-02 at 19:25:05 +0000, Jeevaka Prabu Badrappan wrote:
> From: Sapna Singh <sapna1.singh at intel.com>
> 
> As procps, glib are not available in Android, not able to build igt
> for Android.
> 
> Provided stub implementations so igt can be compiled for both Android
> and linux from same code base. Incase of linux systems, system libraries

s/Incase/In case/

> will be used whereas for Android stubs will be used with reduced
> test coverage.
> 
> Signed-off-by: Sapna Singh <sapna1.singh at intel.com>
> Signed-off-by: Jeevaka Prabu Badrappan <jeevaka.badrappan at intel.com>
> ---
>  include/android/glib.h   | 42 ++++++++++++++++++++++++++++++++++++
>  include/android/procps.h | 46 ++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 88 insertions(+)
>  create mode 100644 include/android/glib.h
>  create mode 100644 include/android/procps.h
> 
> diff --git a/include/android/glib.h b/include/android/glib.h
> new file mode 100644
> index 000000000..4d0a63098
> --- /dev/null
> +++ b/include/android/glib.h
> @@ -0,0 +1,42 @@

Add SPDX MIT here. Imho you could use MIT as you are only adding stubs.
In case you will copy-paste any code you should use same licence as
original, so:

/* SPDX-License-Identifier: MIT */

> +#ifndef _IGT_ANDROID_GLIB_H
> +#define _IGT_ANDROID_GLIB_H
> +
> +#include <stdbool.h>
> +#include <stdlib.h>
> +
> +#define G_KEY_FILE_NONE 0
> +#define G_REGEX_OPTIMIZE 0
> +
> +typedef struct _GError {
> +	int code;
> +	char *message;
> +} GError;
> +
> +typedef struct _GKeyFile {
> +	char *key;
> +	char *value;
> +} GKeyFile;
> +
> +typedef int gint;
> +typedef size_t gsize;
> +typedef char gchar;
> +typedef unsigned char guchar;
> +typedef void GRegex;
> +
> +static inline void g_clear_error(GError **error) { }
> +static inline void g_error_free(GError *error) { }
> +static inline const char *g_get_home_dir(void) { return "/data/local/tmp/igt"; }
> +static inline void g_key_file_free(GKeyFile *file) { }
> +static inline GKeyFile *g_key_file_new(void) { return NULL; }
> +static inline int g_key_file_get_integer(GKeyFile *key_file,
> +	const char *group_name, const char *key, GError **error) { return 0; }
> +static inline char *g_key_file_get_string(GKeyFile *key_file,
> +	const char *group_name, const char *key, GError **error) { return NULL; }
> +static inline bool g_key_file_load_from_file(GKeyFile *key_file,
> +	const char *file, int flags, GError **error) { return false; }
> +static inline GRegex *g_regex_new(const char *pattern, int compile_options,
> +	int match_options, GError **error) { return NULL; }
> +static inline void g_regex_unref(GRegex *pattern) { };
> +static gchar *g_base64_encode(const guchar *data, gsize len) { return NULL; }
> +
> +#endif /* _IGT_ANDROID_GLIB_H */
> diff --git a/include/android/procps.h b/include/android/procps.h
> new file mode 100644
> index 000000000..327c9bcc5
> --- /dev/null
> +++ b/include/android/procps.h
> @@ -0,0 +1,46 @@

Same here, add SPDX MIT here.

> +#ifndef _IGT_ANDROID_PROCPS_H
> +#define _IGT_ANDROID_PROCPS_H
> +
> +enum pids_item {
> +	PIDS_CMD     = 13, /* str stat: comm or status: Name */
> +	PIDS_ID_EGID = 29, /* u_int status: Gid */
> +	PIDS_ID_EUID = 31, /* u_int status: Uid */
> +	PIDS_ID_PID  = 39, /* s_int from /proc/<pid> */

No need for this as this is stub only, add some dummy,
for example:

	PIDS_NOT_IMPLEMENTED = 0

> +};

Add newline.

> +enum pids_fetch_type {
> +	PIDS_FETCH_TASKS_ONLY,
> +	PIDS_FETCH_THREADS_TOO
> +};
> +
> +struct pids_result {
> +	enum pids_item item;
> +	union {
> +		signed char s_ch;
> +		signed int s_int;
> +		unsigned int u_int;
> +		unsigned long ul_int;
> +		unsigned long long ull_int;
> +		char *str;
> +		char **strv;
> +		double real;

Do you really need this? imho use largest ones like:
	union {
		unsigned long long ull_int;
		double real;
	} result;

> +	} result;
> +};
> +
> +struct pids_stack {
> +	struct pids_result *head;
> +};
> +
> +struct pids_info;
> +
> +#define PIDS_VAL(relative_enum, type, stack, info) \
> +	stack->head[relative_enum].result.type
> +

This emits compiler warning so make a workaround like:
	((info & 0) | (stack)->head[relative_enum].result.type)


Regards,
Kamil

> +int procps_pids_new(struct pids_info **info, enum pids_item *items, int numitems) { return 0; }
> +int procps_pids_unref(struct pids_info **info) { return 0; }
> +
> +struct pids_stack *procps_pids_get(struct pids_info *info, enum pids_fetch_type which)
> +{
> +	return NULL;
> +}
> +
> +#endif /* _IGT_ANDROID_PROCPS_H */
> -- 
> 2.49.0
> 


More information about the igt-dev mailing list