[PATCH i-g-t v11 1/7] Add stub for procps and glib
Jeevaka Prabu Badrappan
jeevaka.badrappan at intel.com
Thu May 29 17:12:40 UTC 2025
From: Sapna <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
will be used whereas for Android stubs will be used with reduced
test coverage.
Signed-off-by: Sapna <sapna1.singh at intel.com>
---
include/android/glib.h | 42 ++++++++++++++++++++++++++++++++++
include/android/procps.h | 46 ++++++++++++++++++++++++++++++++++++++
lib/intel_batchbuffer.c | 3 +++
tests/intel/api_intel_bb.c | 3 +++
tests/intel/xe_intel_bb.c | 3 +++
5 files changed, 97 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 @@
+#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 @@
+#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> */
+};
+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;
+ } 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
+
+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 */
diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
index f7569e768..03ce65ded 100644
--- a/lib/intel_batchbuffer.c
+++ b/lib/intel_batchbuffer.c
@@ -2348,6 +2348,9 @@ static void intel_bb_dump_base64(struct intel_bb *ibb, int linelen)
igt_info("--- bb ---\n");
pos = str = g_base64_encode((const guchar *) ibb->batch, ibb->size);
+ if (str == NULL)
+ return;
+
outsize = strlen(str);
while (outsize > 0) {
diff --git a/tests/intel/api_intel_bb.c b/tests/intel/api_intel_bb.c
index 4a1c9be91..39bc2525c 100644
--- a/tests/intel/api_intel_bb.c
+++ b/tests/intel/api_intel_bb.c
@@ -944,7 +944,10 @@ static int dump_base64(const char *name, struct intel_buf *buf)
igt_info("--- %s ---\n", name);
pos = str = g_base64_encode(destbuf, outsize);
+ if (str == NULL)
+ return -1;
outsize = strlen(str);
+
while (pos) {
char line[LINELEN + 1];
int to_copy = min(LINELEN, outsize);
diff --git a/tests/intel/xe_intel_bb.c b/tests/intel/xe_intel_bb.c
index d8bd7b519..caa17498f 100644
--- a/tests/intel/xe_intel_bb.c
+++ b/tests/intel/xe_intel_bb.c
@@ -595,7 +595,10 @@ static int dump_base64(const char *name, struct intel_buf *buf)
igt_info("--- %s ---\n", name);
pos = str = g_base64_encode(destbuf, outsize);
+ if (str == NULL)
+ return -1;
outsize = strlen(str);
+
while (pos) {
char line[LINELEN + 1];
int to_copy = min(LINELEN, outsize);
--
2.49.0
More information about the igt-dev
mailing list