Skip to contentSkip to conversation

Kernel selftest plumbing

PATCH Superseded Petri Latvala 1 participant 3 messages Mar 10, 2017 Library code

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Kernel selftest plumbing

IGT subtest enumeration must work regardless of what the running environment is. Kernel selftest launchers want to expose everything the running kernel can execute.

These two things are mutually exclusive. This series is an attempt for a best-of-both-worlds approach: After constructing subtests for selftests the running kernel supports (if any), go through the list of known kernel selftests and set up a subtest for any such test that is missing.

This will still violate the IGT rule of list enumeration on tests that are not present in the selftest headers copied from the kernel sources, but we can live with that. Generating static testlists for CI use is now possible, and running new selftests without IGT changes stays possible.

Petri Latvala (2):
lib: Add i915 and drm-mm selftest headers from the kernel Always expose IGT subtests for known kernel selftests

 lib/drm_mm_selftests.h    | 24 ++++++++++++++++++++++
 lib/i915_live_selftests.h | 19 +++++++++++++++++
 lib/i915_mock_selftests.h | 20 ++++++++++++++++++
 lib/igt_kmod.c            | 52 ++++++++++++++++++++++++++++++++++-------------
 lib/igt_kmod.h            |  8 +++++++-
 tests/drm_mm.c            | 17 +++++++++++++++-
 tests/drv_selftest.c      | 25 +++++++++++++++++++++--
 7 files changed, 147 insertions(+), 18 deletions(-)
 create mode 100644 lib/drm_mm_selftests.h
 create mode 100644 lib/i915_live_selftests.h
 create mode 100644 lib/i915_mock_selftests.h
Signature · 6 lines
2.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH 1/2 lib: Add i915 and drm-mm selftest headers from the kernel

Copied as of commit

commit 496b575e3ccbf6fbe57a674c721af43dc8826361
Author: Chris Wilson <[email protected]>
Date: Mon Feb 13 17:15:58 2017 +0000

drm/i915: Add initial selftests for hang detection and resets

The headers are used to enumerate available tests when the running kernel does not support selftests.

---
 lib/drm_mm_selftests.h    | 24 ++++++++++++++++++++++++
 lib/i915_live_selftests.h | 19 +++++++++++++++++++
 lib/i915_mock_selftests.h | 20 ++++++++++++++++++++
 3 files changed, 63 insertions(+)
 create mode 100644 lib/drm_mm_selftests.h
 create mode 100644 lib/i915_live_selftests.h
 create mode 100644 lib/i915_mock_selftests.h
lib/drm_mm_selftests.h new file +24 -0
new file mode 100644
index 0000000..37bbdac
@@ -0,0 +1,24 @@
+/* List each unit test as selftest(name, function)
+ *
+ * The name is used as both an enum and expanded as igt__name to create
+ * a module parameter. It must be unique and legal for a C identifier.
+ *
+ * Tests are executed in order by igt/drm_mm
+ */
+selftest(sanitycheck, igt_sanitycheck) /* keep first (selfcheck for igt) */
+selftest(init, igt_init)
+selftest(debug, igt_debug)
+selftest(reserve, igt_reserve)
+selftest(insert, igt_insert)
+selftest(replace, igt_replace)
+selftest(insert_range, igt_insert_range)
+selftest(align, igt_align)
+selftest(align32, igt_align32)
+selftest(align64, igt_align64)
+selftest(evict, igt_evict)
+selftest(evict_range, igt_evict_range)
+selftest(bottomup, igt_bottomup)
+selftest(topdown, igt_topdown)
+selftest(color, igt_color)
+selftest(color_evict, igt_color_evict)
+selftest(color_evict_range, igt_color_evict_range)
lib/i915_live_selftests.h new file +19 -0
new file mode 100644
index 0000000..18b174d
@@ -0,0 +1,19 @@
+/* List each unit test as selftest(name, function)
+ *
+ * The name is used as both an enum and expanded as subtest__name to create
+ * a module parameter. It must be unique and legal for a C identifier.
+ *
+ * The function should be of type int function(void). It may be conditionally
+ * compiled using #if IS_ENABLED(DRM_I915_SELFTEST).
+ *
+ * Tests are executed in order by igt/drv_selftest
+ */
+selftest(sanitycheck, i915_live_sanitycheck) /* keep first (igt selfcheck) */
+selftest(uncore, intel_uncore_live_selftests)
+selftest(requests, i915_gem_request_live_selftests)
+selftest(objects, i915_gem_object_live_selftests)
+selftest(dmabuf, i915_gem_dmabuf_live_selftests)
+selftest(coherency, i915_gem_coherency_live_selftests)
+selftest(gtt, i915_gem_gtt_live_selftests)
+selftest(contexts, i915_gem_context_live_selftests)
+selftest(hangcheck, intel_hangcheck_live_selftests)
lib/i915_mock_selftests.h new file +20 -0
new file mode 100644
index 0000000..be9a9eb
@@ -0,0 +1,20 @@
+/* List each unit test as selftest(name, function)
+ *
+ * The name is used as both an enum and expanded as subtest__name to create
+ * a module parameter. It must be unique and legal for a C identifier.
+ *
+ * The function should be of type int function(void). It may be conditionally
+ * compiled using #if IS_ENABLED(DRM_I915_SELFTEST).
+ *
+ * Tests are executed in order by igt/drv_selftest
+ */
+selftest(sanitycheck, i915_mock_sanitycheck) /* keep first (igt selfcheck) */
+selftest(scatterlist, scatterlist_mock_selftests)
+selftest(uncore, intel_uncore_mock_selftests)
+selftest(breadcrumbs, intel_breadcrumbs_mock_selftests)
+selftest(requests, i915_gem_request_mock_selftests)
+selftest(objects, i915_gem_object_mock_selftests)
+selftest(dmabuf, i915_gem_dmabuf_mock_selftests)
+selftest(vma, i915_vma_mock_selftests)
+selftest(evict, i915_gem_evict_mock_selftests)
+selftest(gtt, i915_gem_gtt_mock_selftests)
Signature · 6 lines
2.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

PATCH 2/2 Always expose IGT subtests for known kernel selftests

In reply to Petri Latvala

Even when the running kernel does not support selftests, make subtest enumeration list known kselftests. The list is generated using selftest listing headers copied from the kernel.

If the running kernel gains new selftest subtests, they are listed even without copying the headers over and rebuilding IGT.

---
 lib/igt_kmod.c       | 52 ++++++++++++++++++++++++++++++++++++++--------------
 lib/igt_kmod.h       |  8 +++++++-
 tests/drm_mm.c       | 17 ++++++++++++++++-
 tests/drv_selftest.c | 25 +++++++++++++++++++++++--
 4 files changed, 84 insertions(+), 18 deletions(-)
lib/igt_kmod.c +38 -14
index 4b8ea81..86b7896 100644
@@ -493,30 +493,54 @@ void igt_kselftest_fini(struct igt_kselftest *tst)
 	kmod_module_unref(tst->kmod);
 }
 
+static void mocklist_mark_entry(struct igt_kselftest_mockentry *mocklist,
+				const char *name)
+{
+	struct igt_kselftest_mockentry *me;
+
+	for (me = mocklist; me->name != NULL; ++me) {
+		if (!strcmp(me->name, name)) {
+			me->do_mock = false;
+			return;
+		}
+	}
+}
+
 void igt_kselftests(const char *module_name,
 		    const char *options,
 		    const char *result,
-		    const char *filter)
+		    const char *filter,
+		    struct igt_kselftest_mockentry *mocklist)
 {
 	struct igt_kselftest tst;
 	IGT_LIST(tests);
 	struct igt_kselftest_list *tl, *tn;
+	struct igt_kselftest_mockentry *me;
 
-	igt_require(igt_kselftest_init(&tst, module_name) == 0);
-	igt_fixture
-		igt_require(igt_kselftest_begin(&tst) == 0);
+	if (igt_kselftest_init(&tst, module_name) == 0) {
+		igt_fixture
+			igt_require(igt_kselftest_begin(&tst) == 0);
 
-	igt_kselftest_get_tests(tst.kmod, filter, &tests);
-	igt_list_for_each_safe(tl, tn, &tests, link) {
-		igt_subtest_f("%s", tl->name)
-			igt_kselftest_execute(&tst, tl, options, result);
-		free(tl);
-	}
+		igt_kselftest_get_tests(tst.kmod, filter, &tests);
+		igt_list_for_each_safe(tl, tn, &tests, link) {
+			igt_subtest_f("%s", tl->name)
+				igt_kselftest_execute(&tst, tl, options, result);
+			mocklist_mark_entry(mocklist, tl->name);
+			free(tl);
+		}
 
-	igt_fixture {
-		igt_kselftest_end(&tst);
-		igt_require(!igt_list_empty(&tests));
+		igt_fixture {
+			igt_kselftest_end(&tst);
+			igt_require(!igt_list_empty(&tests));
+		}
+
+		igt_kselftest_fini(&tst);
 	}
 
-	igt_kselftest_fini(&tst);
+	/* Expose subtests for anything the above didn't already generate. */
+	for (me = mocklist; me->name != NULL; ++me) {
+		if (me->do_mock)
+			igt_subtest(me->name)
+				igt_skip("Kernel selftest not present");
+	}
 }
lib/igt_kmod.h +7 -1
index 10cd3a2..d49e9d4 100644
@@ -35,10 +35,16 @@ int igt_kmod_unload(const char *mod_name, unsigned int flags);
 int igt_i915_driver_load(const char *opts);
 int igt_i915_driver_unload(void);
 
+struct igt_kselftest_mockentry {
+	const char *name;
+	bool do_mock;
+};
+
 void igt_kselftests(const char *module_name,
 		    const char *module_options,
 		    const char *result_option,
-		    const char *filter);
+		    const char *filter,
+		    struct igt_kselftest_mockentry* mocklist);
 
 struct igt_kselftest {
 	struct kmod_module *kmod;
tests/drm_mm.c +16 -1
index 2052b11..2a3212e 100644
@@ -28,5 +28,20 @@ IGT_TEST_DESCRIPTION("Basic sanity check of DRM's range manager (struct drm_mm)"
 
 igt_main
 {
-	igt_kselftests("test-drm_mm", NULL, NULL, NULL);
+	/*
+	 * Set of subtest names that are always exposed by IGT,
+	 * regardless of the running kernel's capabilities. Selftests
+	 * that the kernel has but are not on these lists are also
+	 * exposed. This is a known intentional violation of the
+	 * general rule that subtest enumeration must not change
+	 * depending on the runtime environment.
+	 */
+	struct igt_kselftest_mockentry drm_mm_testlist[] = {
+#define selftest(n, x) { .name = #n, .do_mock = true },
+#include "drm_mm_selftests.h"
+#undef selftest
+		{ NULL, false }
+	};
+
+	igt_kselftests("test-drm_mm", NULL, NULL, NULL, drm_mm_testlist);
 }
tests/drv_selftest.c +23 -2
index 96dd8bf..eb34fdf 100644
@@ -28,6 +28,27 @@ IGT_TEST_DESCRIPTION("Basic unit tests for i915.ko");
 
 igt_main
 {
-	igt_kselftests("i915", "mock_selftests=-1", NULL, "mock");
-	igt_kselftests("i915", "live_selftests=-1", "live_selftests", "live");
+	/*
+	 * Set of subtest names that are always exposed by IGT,
+	 * regardless of the running kernel's capabilities. Selftests
+	 * that the kernel has but are not on these lists are also
+	 * exposed. This is a known intentional violation of the
+	 * general rule that subtest enumeration must not change
+	 * depending on the runtime environment.
+	 */
+	struct igt_kselftest_mockentry i915_mock_testlist[] = {
+#define selftest(n, x) { .name = #n, .do_mock = true },
+#include "i915_mock_selftests.h"
+#undef selftest
+		{ NULL, false }
+	};
+	struct igt_kselftest_mockentry i915_live_testlist[] = {
+#define selftest(n, x) { .name = #n, .do_mock = true },
+#include "i915_mock_selftests.h"
+#undef selftest
+		{ NULL, false }
+	};
+
+	igt_kselftests("i915", "mock_selftests=-1", NULL, "mock", i915_mock_testlist);
+	igt_kselftests("i915", "live_selftests=-1", "live_selftests", "live", i915_live_testlist);
 }
Signature · 6 lines
2.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx