Previously under unbind_fbcon(), to disable/enable framebuffer console.
lib/igt_aux: Added helpers to help convert sh scripts to C version. libkmod
and procps interface.
v3:
- return -errno (igt_pkill()) in case of failure (Cris Wilson)
- return bool for igt_kmod_is_loaded(), replaced strncasecmp with strncmp
(Chris Wilson)
- use igt_debug() instead of igt_info() for igt_kmod_load()/
igt_kmod_unload() and return -err directly from libkmod (Chris Wilson)
v2:
- Renamed libkmod helpers (Chris Wilson)
- Removed SIGTERM/SIGKILL case where we repeatedly tried to terminate the
process: just call kill(2) once (Chris Wilson)
- Removed redundant check in igt_kmod_unload(), igt_module_in_use() (Chris
Wilson)
- Pass flags to igt_kmod_unload() from the caller (Chris Wilson)
- Removed useless function igt_kill() which acts just as kill(2) (Chris
Wilson)
Signed-off-by: Marius Vlad
---
configure.ac| 2 +
lib/Makefile.am | 2 +
lib/igt_aux.c | 177
lib/igt_aux.h | 6 ++
lib/igt_gvt.c | 43 +-
lib/igt_sysfs.c | 54 +
lib/igt_sysfs.h | 2 +
7 files changed, 245 insertions(+), 41 deletions(-)
diff --git a/configure.ac b/configure.ac
index 735cfd5..2c6e49d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -121,6 +121,8 @@ AC_SUBST(ASSEMBLER_WARN_CFLAGS)
PKG_CHECK_MODULES(DRM, [libdrm])
PKG_CHECK_MODULES(PCIACCESS, [pciaccess >= 0.10])
+PKG_CHECK_MODULES(KMOD, [libkmod])
+PKG_CHECK_MODULES(PROCPS, [libprocps])
case "$target_cpu" in
x86*|i?86)
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 4c0893d..e1737bd 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -34,6 +34,8 @@ AM_CFLAGS += $(CAIRO_CFLAGS)
libintel_tools_la_LIBADD = \
$(DRM_LIBS) \
$(PCIACCESS_LIBS) \
+ $(PROCPS_LIBS) \
+ $(KMOD_LIBS) \
$(CAIRO_LIBS) \
$(LIBUDEV_LIBS) \
$(LIBUNWIND_LIBS) \
diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index 421f6d4..d43ec8c 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -51,6 +51,9 @@
#include
#include
+#include
+#include
+
#include "drmtest.h"
#include "i915_drm.h"
#include "intel_chipset.h"
@@ -1193,6 +1196,180 @@ void igt_set_module_param_int(const char *name, int val)
igt_set_module_param(name, str);
}
+/**
+ * igt_pkill:
+ * @sig: Signal to send
+ * @name: Name of process in the form found in /proc/pid/comm (limited to 15
+ * chars)
+ * @returns: 0 in case the process is not found running or the signal has been
+ * sent successfully or -errno otherwise.
+ *
+ * This function sends the signal @sig for a process found in process table
+ * with name @comm.
+ */
+int
+igt_pkill(int sig, const char *comm)
+{
+ PROCTAB *proc;
+ proc_t *proc_info;
+ int err = 0;
+
+ proc = openproc(PROC_FILLCOM | PROC_FILLSTAT | PROC_FILLARG);
+ igt_assert(proc != NULL);
+
+ while ((proc_info = readproc(proc, NULL))) {
+ if (!strncasecmp(proc_info->cmd, comm, sizeof(proc_info->cmd)))
{
+
+ if (kill(proc_info->tid, sig) < 0)
+ err = -errno;
+
+ freeproc(proc_info);
+ break;
+ }
+ freeproc(proc_info);
+ }
+
+ closeproc(proc);
+ return err;
+}
+
+/**
+ * igt_kmod_is_loaded:
+ * @mod_name: The name of the module.
+ * @returns: True in case the module has been found or false otherwise.
+ *
+ * Function to check the existance of module @mod_name in list of loaded kernel
+ * modules.
+ *
+ */
+bool
+igt_kmod_is_loaded(const char *mod_name)
+{
+ struct kmod_list *mod, *list;
+ struct kmod_ctx *ctx;
+ bool ret = false;
+
+ ctx = kmod_new(NULL, NULL);
+ igt_assert(ctx != NULL);
+
+ if (kmod_module_new_from_loaded(ctx, &list) < 0) {
+ goto out;
+ }
+
+ kmod_list_foreach(mod, list) {
+ struct kmod_module *kmod = kmod_module_get_module(mod);
+ const char *kmod_name = kmod_module_get_name(kmod);
+
+ if (!strncmp(kmod_name, mod_name, strlen(kmod_name))) {
+ kmod_module_unref(kmod);
+ ret = true;
+ break;
+ }
+ kmod_module_unref(kmod);
+ }
+ kmod_module_unref_list(list);
+out:
+ kmod_unref(ctx);
+
+ return ret;
+}
+
+/**
+ * igt_kmod_load:
+ * @mod_name: The name of the module
+ * @opts: Parameters for the module. NULL in case no parameters
+ * are to be passed, or a '\0' terminated string otherwise.
+ * @returns: 0 in case of success or -errno in case the module could not
+ * be loaded.
+ *
+ * This function loads a kernel module using the name specified in @mod_name.
+ *
+ * @Note: This functions doesn't automatically resolve other module
+ * dependencies so make make sure you load the dependencies module(s) before
+ * this one.
+ */
+int
+igt_kmod_load(co