[PATCH RESEND i-g-t v4 05/31] lib/igt_tools_stub: add stubs needed by tools
Sebastian Brzezinka <[email protected]> Wed, 29 Jul 2026 13:03:22 +0200
| Newsgroups | org.freedesktop.lists.igt-dev |
|---|---|
| Message-ID | <5b816cfd3243824e2a3363a22e13c6d8fb3f880d.1785152675.git.sebastian.brzezinka@intel.com> |
Add stubs for functions used by tools when linking without the full libigt.so: __igt_skip_check, igt_exit, igt_debugfs_open and igt_open_forcewake_handle_for_pcidev. Signed-off-by: Sebastian Brzezinka <[email protected]> Acked-by: Ashutosh Dixit <[email protected]> Reviewed-by: Krzysztof Karas <[email protected]> --- lib/igt_tools_stub.c | 83 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 76 insertions(+), 7 deletions(-) diff --git a/lib/igt_tools_stub.c b/lib/igt_tools_stub.c index 9a0ec6217..21dc53f3f 100644 --- a/lib/igt_tools_stub.c +++ b/lib/igt_tools_stub.c @@ -21,12 +21,27 @@ * IN THE SOFTWARE. * */ +#include <fcntl.h> +#include <limits.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <sys/sysmacros.h> +#include <unistd.h> + #include "igt_core.h" +#include "igt_debugfs.h" -/* Stub for igt_log, this stub will simply print the msg on stderr device. - * Domain and log level are ignored. +/* + * Forward declaration only - avoids pulling in the heavy igt_gt.h header. + * The type is used as an opaque pointer; this stub always returns -1. */ +struct pci_device; +int igt_open_forcewake_handle_for_pcidev(const struct pci_device *pci_dev); + +/* Stub for igt_log: print message to stderr; domain and log level are ignored. */ void igt_log(const char *domain, enum igt_log_level level, const char *format, ...) { va_list args; @@ -36,11 +51,7 @@ void igt_log(const char *domain, enum igt_log_level level, const char *format, . va_end(args); } - -/* Stub for __igt_fail_assert, this stub will simply print the msg on stderr device and - * exit the application, domain and log level are ignored. - */ - +/* Stub for __igt_fail_assert: print failed assertion to stderr and exit. */ void __igt_fail_assert(const char *domain, const char *file, const int line, const char *func, const char *assertion, const char *format, ...) @@ -49,3 +60,61 @@ void __igt_fail_assert(const char *domain, const char *file, func, assertion); exit(1); } + +/* Stub for __igt_skip_check: print skip reason to stderr and exit with skip code. */ +void __igt_skip_check(const char *file, const int line, + const char *func, const char *check, const char *format, ...) +{ + fprintf(stderr, "%s: %d %s Skipped: %s", file, line, func, check); + if (format) { + va_list args; + + fprintf(stderr, ": "); + va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); + } + + fprintf(stderr, "\n"); + /* IGT_EXIT_SKIP (77) is the exit code igt_core.c uses for skipped tests. */ + exit(IGT_EXIT_SKIP); +} + +/* Stub for igt_exit: tools use exit(0) rather than the full igt teardown sequence. */ +__noreturn void igt_exit(void) +{ + exit(0); +} + +/* + * Stub for igt_debugfs_open: open a debugfs entry for a DRM device directly + * by path. device == -1 follows the igt_debugfs_path() convention of + * defaulting to the first DRM device (dri/0). When a valid fd is given, the + * DRM minor is resolved via fstat() so the correct dri/<minor> directory is + * used. + */ +int igt_debugfs_open(int device, const char *filename, int mode) +{ + char path[PATH_MAX]; + int drm_minor = 0; + + if (device >= 0) { + struct stat st; + + if (fstat(device, &st) == 0 && S_ISCHR(st.st_mode)) + drm_minor = minor(st.st_rdev); + } + + snprintf(path, sizeof(path), + "/sys/kernel/debug/dri/%d/%s", drm_minor, filename); + return open(path, mode); +} + +/* + * Stub for igt_open_forcewake_handle_for_pcidev: in tool context the driver + * keeps the GPU awake; no forcewake handle needed. + */ +int igt_open_forcewake_handle_for_pcidev(const struct pci_device *pci_dev) +{ + return -1; +} -- 2.53.0