summaryrefslogtreecommitdiff
path: root/lib/igt_kmod.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2016-12-01 21:53:48 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2016-12-01 23:10:12 +0000
commit8bb6135fa50c81abe77b80cf08fc8b45445160e3 (patch)
tree1153b785de2c3e975a129aa9044ec0ea97304269 /lib/igt_kmod.c
parent7a06e13ba1e3b2ac79699e835fde9652eac6f71f (diff)
igt: Add kselftest runner for i915
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'lib/igt_kmod.c')
-rw-r--r--lib/igt_kmod.c137
1 files changed, 64 insertions, 73 deletions
diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index 6f0a5910..a11bb547 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -47,6 +47,25 @@
* dynamically.
*/
+static void squelch(void *data, int priority,
+ const char *file, int line, const char *fn,
+ const char *format, va_list args)
+{
+}
+
+static struct kmod_ctx *kmod_ctx(void)
+{
+ static struct kmod_ctx *ctx;
+
+ if (!ctx) {
+ ctx = kmod_new(NULL, NULL);
+ igt_assert(ctx != NULL);
+
+ kmod_set_log_fn(ctx, squelch, NULL);
+ }
+
+ return ctx;
+}
/**
* igt_kmod_is_loaded:
@@ -61,16 +80,12 @@
bool
igt_kmod_is_loaded(const char *mod_name)
{
+ struct kmod_ctx *ctx = kmod_ctx();
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) {
+ 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);
@@ -85,11 +100,15 @@ igt_kmod_is_loaded(const char *mod_name)
}
kmod_module_unref_list(list);
out:
- kmod_unref(ctx);
-
return ret;
}
+static int modprobe(struct kmod_module *kmod, const char *options)
+{
+ return kmod_module_probe_insert_module(kmod, 0, options,
+ NULL, NULL, NULL);
+}
+
/**
* igt_kmod_load:
* @mod_name: The name of the module
@@ -108,40 +127,34 @@ out:
int
igt_kmod_load(const char *mod_name, const char *opts)
{
- struct kmod_ctx *ctx;
+ struct kmod_ctx *ctx = kmod_ctx();
struct kmod_module *kmod;
int err = 0;
- ctx = kmod_new(NULL, NULL);
- igt_assert(ctx != NULL);
-
err = kmod_module_new_from_name(ctx, mod_name, &kmod);
- if (err < 0) {
+ if (err < 0)
goto out;
- }
- err = kmod_module_insert_module(kmod, 0, opts);
+ err = modprobe(kmod, opts);
if (err < 0) {
switch (err) {
case -EEXIST:
igt_debug("Module %s already inserted\n",
- kmod_module_get_name(kmod));
+ kmod_module_get_name(kmod));
break;
case -ENOENT:
igt_debug("Unknown symbol in module %s or "
- "unknown parameter\n",
- kmod_module_get_name(kmod));
+ "unknown parameter\n",
+ kmod_module_get_name(kmod));
break;
default:
igt_debug("Could not insert %s (%s)\n",
- kmod_module_get_name(kmod), strerror(-err));
+ kmod_module_get_name(kmod), strerror(-err));
break;
}
}
out:
kmod_module_unref(kmod);
- kmod_unref(ctx);
-
return -err ? err < 0 : err;
}
@@ -160,30 +173,25 @@ out:
int
igt_kmod_unload(const char *mod_name, unsigned int flags)
{
- struct kmod_ctx *ctx;
+ struct kmod_ctx *ctx = kmod_ctx();
struct kmod_module *kmod;
- int err = 0;
-
- ctx = kmod_new(NULL, NULL);
- igt_assert(ctx != NULL);
+ int err;
err = kmod_module_new_from_name(ctx, mod_name, &kmod);
if (err < 0) {
igt_debug("Could not use module %s (%s)\n", mod_name,
- strerror(-err));
+ strerror(-err));
goto out;
}
err = kmod_module_remove_module(kmod, flags);
if (err < 0) {
igt_debug("Could not remove module %s (%s)\n", mod_name,
- strerror(-err));
+ strerror(-err));
}
out:
kmod_module_unref(kmod);
- kmod_unref(ctx);
-
return -err ? err < 0 : err;
}
@@ -195,16 +203,11 @@ out:
void
igt_kmod_list_loaded(void)
{
+ struct kmod_ctx *ctx = kmod_ctx();
struct kmod_list *module, *list;
- struct kmod_ctx *ctx;
- ctx = kmod_new(NULL, NULL);
- igt_assert(ctx != NULL);
-
- if (kmod_module_new_from_loaded(ctx, &list) < 0) {
- kmod_unref(ctx);
+ if (kmod_module_new_from_loaded(ctx, &list) < 0)
return;
- }
igt_info("Module\t\t Used by\n");
@@ -220,8 +223,7 @@ igt_kmod_list_loaded(void)
struct kmod_module *kmod_dep;
kmod_dep = kmod_module_get_module(module_deps);
- igt_info("%s",
- kmod_module_get_name(kmod_dep));
+ igt_info("%s", kmod_module_get_name(kmod_dep));
if (kmod_list_next(module_deps_list, module_deps))
igt_info(",");
@@ -236,7 +238,6 @@ igt_kmod_list_loaded(void)
}
kmod_module_unref_list(list);
- kmod_unref(ctx);
}
/**
@@ -252,10 +253,6 @@ igt_i915_driver_load(const char *opts)
if (opts)
igt_info("Reloading i915 with %s\n\n", opts);
- /* we do not have automatic loading of dependencies */
- igt_kmod_load("drm", NULL);
- igt_kmod_load("drm_kms_helper", NULL);
-
if (igt_kmod_load("i915", opts)) {
igt_warn("Could not load i915\n");
return IGT_EXIT_FAILURE;
@@ -294,9 +291,8 @@ igt_i915_driver_unload(void)
}
/* gen5 */
- if (igt_kmod_is_loaded("intel_ips")) {
+ if (igt_kmod_is_loaded("intel_ips"))
igt_kmod_unload("intel_ips", 0);
- }
if (igt_kmod_is_loaded("i915")) {
if (igt_kmod_unload("i915", 0)) {
@@ -304,14 +300,11 @@ igt_i915_driver_unload(void)
igt_kmod_list_loaded();
igt_lsof("/dev/dri");
return IGT_EXIT_SKIP;
- } else {
- igt_info("i915.ko has been unloaded!\n");
}
}
- if (igt_kmod_is_loaded("intel-gtt")) {
+ if (igt_kmod_is_loaded("intel-gtt"))
igt_kmod_unload("intel-gtt", 0);
- }
igt_kmod_unload("drm_kms_helper", 0);
igt_kmod_unload("drm", 0);
@@ -319,20 +312,11 @@ igt_i915_driver_unload(void)
if (igt_kmod_is_loaded("i915")) {
igt_warn("i915.ko still loaded!\n");
return IGT_EXIT_FAILURE;
- } else {
- igt_info("module successfully unloaded\n");
}
-
return IGT_EXIT_SUCCESS;
}
-static void squelch(void *data, int priority,
- const char *file, int line, const char *fn,
- const char *format, va_list args)
-{
-}
-
static void kmsg_dump(int fd)
{
FILE *file;
@@ -357,20 +341,19 @@ static void kmsg_dump(int fd)
}
}
-void igt_kselftests(const char *module_name)
+void igt_kselftests(const char *module_name, const char *module_options)
{
- struct kmod_ctx *ctx;
+ char options[1024];
+ struct kmod_ctx *ctx = kmod_ctx();
struct kmod_module *kmod;
struct kmod_list *d, *pre;
int err, kmsg = -1;
- ctx = kmod_new(NULL, NULL);
- igt_assert(ctx != NULL);
-
- kmod_set_log_fn(ctx, squelch, NULL);
-
igt_require(kmod_module_new_from_name(ctx, module_name, &kmod) == 0);
igt_fixture {
+ if (strcmp(module_name, "i915") == 0)
+ igt_i915_driver_unload();
+
err = kmod_module_remove_module(kmod, KMOD_REMOVE_FORCE);
igt_require(err == 0 || err == -ENOENT);
@@ -381,7 +364,7 @@ void igt_kselftests(const char *module_name)
if (kmod_module_get_info(kmod, &pre)) {
kmod_list_foreach(d, pre) {
const char *key, *val;
- char *option, *colon;
+ char *subtest, *colon;
key = kmod_module_info_get_key(d);
if (strcmp(key, "parmtype"))
@@ -391,25 +374,30 @@ void igt_kselftests(const char *module_name)
if (!val || strncmp(val, "subtest__", 9))
continue;
- option = strdup(val);
- colon = strchr(option, ':');
+ subtest = strdup(val);
+ colon = strchr(subtest, ':');
*colon = '\0';
- igt_subtest_f("%s", option + 9) {
+ igt_subtest_f("%s", subtest + 9) {
lseek(kmsg, 0, SEEK_END);
- strcpy(colon, "=1");
+
+ snprintf(options, sizeof(options), "%s=1 %s",
+ subtest, module_options ?: "");
err = 0;
- if (kmod_module_insert_module(kmod, 0, option))
+ if (modprobe(kmod, options))
err = -errno;
kmod_module_remove_module(kmod, 0);
+
+ if (err == -ENOTTY) /* special case */
+ err = 0;
if (err)
kmsg_dump(kmsg);
errno = 0;
igt_assert_f(err == 0,
"kselftest \"%s %s\" failed: %s [%d]\n",
- module_name, option,
+ module_name, options,
strerror(-err), -err);
}
}
@@ -419,5 +407,8 @@ void igt_kselftests(const char *module_name)
igt_fixture {
close(kmsg);
kmod_module_remove_module(kmod, KMOD_REMOVE_FORCE);
+
+ if (strcmp(module_name, "i915") == 0)
+ igt_i915_driver_load(NULL);
}
}