Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jeevaka Prabu Badrappan <jeevaka.badrappan@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: jeevaka.badrappan@intel.com, sapna1.singh@intel.com,
	markyacoub@google.com, seanpaul@google.com,
	carlos.santa@intel.com
Subject: [PATCH 1/5] Add stub for libunwind, procps and glib
Date: Tue, 29 Apr 2025 19:57:41 +0000	[thread overview]
Message-ID: <20250429195745.40982-2-jeevaka.badrappan@intel.com> (raw)
In-Reply-To: <20250429195745.40982-1-jeevaka.badrappan@intel.com>

From: Sapna <sapna1.singh@intel.com>

As libunwind, 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@intel.com>
---
 include/stub/glib.h      | 43 ++++++++++++++++++++++++++++++++++++++++
 include/stub/libunwind.h | 20 +++++++++++++++++++
 include/stub/pids.h      | 41 ++++++++++++++++++++++++++++++++++++++
 lib/igt_aux.c            |  2 +-
 4 files changed, 105 insertions(+), 1 deletion(-)
 create mode 100644 include/stub/glib.h
 create mode 100644 include/stub/libunwind.h
 create mode 100644 include/stub/pids.h

diff --git a/include/stub/glib.h b/include/stub/glib.h
new file mode 100644
index 000000000..0bd862fa2
--- /dev/null
+++ b/include/stub/glib.h
@@ -0,0 +1,43 @@
+#pragma once
+#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) {
+    gchar* str = (gchar*)malloc(1);  // Allocate memory for an empty string
+    if (str) {
+        str[0] = '\0';  // Set the string to be empty
+    }
+    return str;
+}
diff --git a/include/stub/libunwind.h b/include/stub/libunwind.h
new file mode 100644
index 000000000..168c31c14
--- /dev/null
+++ b/include/stub/libunwind.h
@@ -0,0 +1,20 @@
+#define UNW_TDEP_CURSOR_LEN     127
+typedef struct unw_cursor
+{
+   int opaque[UNW_TDEP_CURSOR_LEN];
+}
+unw_cursor_t;
+
+
+typedef struct unw_context
+{
+   int ctx;
+}
+unw_context_t;
+
+typedef uint32_t unw_word_t;
+
+int unw_getcontext(unw_context_t *uc) { return 0; }
+int unw_init_local (unw_cursor_t *cur, unw_context_t *uc) { return 0; }
+int unw_step (unw_cursor_t *cur) { return 0; }
+int unw_get_proc_name (unw_cursor_t *cur, char *ch, size_t size, unw_word_t *word) { return 0; }
diff --git a/include/stub/pids.h b/include/stub/pids.h
new file mode 100644
index 000000000..bcdd095e0
--- /dev/null
+++ b/include/stub/pids.h
@@ -0,0 +1,41 @@
+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) {
+    struct pids_stack *ps = NULL;
+    return ps;
+}
diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index f5bf48da6..78bae7542 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -56,7 +56,7 @@
 #ifdef HAVE_LIBPROCPS
 #  include <proc/readproc.h>
 #else
-#  include <libproc2/pids.h>
+#include "pids.h"
 #endif
 
 #include <dirent.h>
-- 
2.49.0


  reply	other threads:[~2025-04-29 19:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-29 19:57 [RFC] [PATCH 0/5] Extend IGT to support Android Jeevaka Prabu Badrappan
2025-04-29 19:57 ` Jeevaka Prabu Badrappan [this message]
2025-04-29 19:57 ` [PATCH 2/5] Replace program_invocation_short_name with prog_name from command line Jeevaka Prabu Badrappan
2025-04-29 19:57 ` [PATCH 3/5] Avoid use of pthread_cancel by introducing an exit flag Jeevaka Prabu Badrappan
2025-04-29 20:29   ` Dixit, Ashutosh
2025-04-29 19:57 ` [PATCH 4/5] Replace glib hash table with c specific implementation Jeevaka Prabu Badrappan
2025-04-29 20:33   ` Dixit, Ashutosh
2025-04-29 19:57 ` [PATCH 5/5] igt-gpu-tools: Changes to compile for Android Jeevaka Prabu Badrappan
2025-04-29 20:12 ` [RFC] [PATCH 0/5] Extend IGT to support Android Dixit, Ashutosh
  -- strict thread matches above, loose matches on Subject: below --
2025-04-29 20:39 [PATCH v2 " Jeevaka Prabu Badrappan
2025-04-29 20:39 ` [PATCH 1/5] Add stub for libunwind, procps and glib Jeevaka Prabu Badrappan
2025-04-29 20:39 [PATCH v2 0/5] Extend IGT to support Android Jeevaka Prabu Badrappan
2025-04-29 20:39 ` [PATCH 1/5] Add stub for libunwind, procps and glib Jeevaka Prabu Badrappan
2025-04-30 17:04   ` Kamil Konieczny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250429195745.40982-2-jeevaka.badrappan@intel.com \
    --to=jeevaka.badrappan@intel.com \
    --cc=carlos.santa@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=markyacoub@google.com \
    --cc=sapna1.singh@intel.com \
    --cc=seanpaul@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox