<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hi,<br>
</p>
<div class="moz-cite-prefix">On 3/16/23 07:46, Lucas De Marchi
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:20230316064643.fu5thzu4pf7htisq@ldmartin-desk2.lan">On
Mon, Mar 13, 2023 at 07:18:34PM +0100, Michal Wajdeczko wrote:
<br>
<blockquote type="cite">
<br>
<br>
On 13.03.2023 17:23, Lucas De Marchi wrote:
<br>
<blockquote type="cite">On Mon, Mar 13, 2023 at 09:13:12AM
+0100, Michal Wajdeczko wrote:
<br>
<blockquote type="cite">Our initial attempt to run Kunit based
tests on live devices is hard
<br>
to use and will not work well with multiple devices
attached.
<br>
<br>
Instead of relying on separate test module and duplicating
support
<br>
for multiple live devices in every test entry point, create
new set
<br>
of helpers and use test->priv to pass reference of the
device under
<br>
test (DUT) directly to every test function.
<br>
<br>
The same use pattern is supported for both mock and live
selftests.
<br>
<br>
By using bus_notifier we can start testing each new bound
device
<br>
separatelly, subject to filtering using dut_filter modparam.
<br>
<br>
All test cases can be included directly from .c file,
allowing test
<br>
code to access and use any private functions.
<br>
<br>
As Kunit will attempt to run all suites on module load,
including
<br>
our new live test suites, we may want to allow to execute
them on
<br>
any available device. This is controlled by anonymous_dut
modparam.
<br>
<br>
Support for either mock or live selftests, only one at time,
is
<br>
controlled by new Kconfig options.
<br>
<br>
Signed-off-by: Michal Wajdeczko
<a class="moz-txt-link-rfc2396E" href="mailto:michal.wajdeczko@intel.com"><michal.wajdeczko@intel.com></a>
<br>
---
<br>
drivers/gpu/drm/xe/Kconfig.debug | 22 ++++
<br>
drivers/gpu/drm/xe/Makefile | 11 ++
<br>
drivers/gpu/drm/xe/selftests/xe_selftests.h | 35 ++++++
<br>
.../gpu/drm/xe/selftests/xe_selftests_auto.c | 46 +++++++
<br>
.../drm/xe/selftests/xe_selftests_executor.c | 118
++++++++++++++++++
<br>
.../drm/xe/selftests/xe_selftests_helpers.c | 101
+++++++++++++++
<br>
.../drm/xe/selftests/xe_selftests_internal.h | 22 ++++
<br>
.../gpu/drm/xe/selftests/xe_selftests_mock.c | 32 +++++
<br>
.../drm/xe/selftests/xe_selftests_params.c | 23 ++++
<br>
drivers/gpu/drm/xe/xe_module.c | 2 +
<br>
10 files changed, 412 insertions(+)
<br>
create mode 100644
drivers/gpu/drm/xe/selftests/xe_selftests.h
<br>
create mode 100644
drivers/gpu/drm/xe/selftests/xe_selftests_auto.c
<br>
create mode 100644
drivers/gpu/drm/xe/selftests/xe_selftests_executor.c
<br>
create mode 100644
drivers/gpu/drm/xe/selftests/xe_selftests_helpers.c
<br>
create mode 100644
drivers/gpu/drm/xe/selftests/xe_selftests_internal.h
<br>
create mode 100644
drivers/gpu/drm/xe/selftests/xe_selftests_mock.c
<br>
create mode 100644
drivers/gpu/drm/xe/selftests/xe_selftests_params.c
<br>
<br>
diff --git a/drivers/gpu/drm/xe/Kconfig.debug
<br>
b/drivers/gpu/drm/xe/Kconfig.debug
<br>
index 93b284cdd0a2..aeba43977dca 100644
<br>
--- a/drivers/gpu/drm/xe/Kconfig.debug
<br>
+++ b/drivers/gpu/drm/xe/Kconfig.debug
<br>
@@ -61,6 +61,28 @@ config DRM_XE_SIMPLE_ERROR_CAPTURE
<br>
<br>
If in doubt, say "N".
<br>
<br>
+config DRM_XE_SELFTESTS_MOCK
<br>
+ bool "Mock selftests for Xe" if !KUNIT_ALL_TESTS
<br>
+ depends on DRM_XE && KUNIT
<br>
+ default KUNIT_ALL_TESTS
<br>
+ help
<br>
+ Choose this option to allow the driver to perform
mock
<br>
+ selftests based on the Kunit framework.
<br>
+
<br>
+ Recommended for driver developers only.
<br>
+ If in doubt, say "N".
<br>
+
<br>
+config DRM_XE_SELFTESTS_LIVE
<br>
+ bool "Live selftests for Xe" if !DRM_XE_SELFTESTS_MOCK
<br>
</blockquote>
<br>
why? I think we should aim to run live tests in *addition* to
<br>
mock ones. The mock tests are more testing our SW infra and
can be used
<br>
in a true "unit test" sense. While the live ones are testing
the
<br>
integration with the HW and making sure they work together.
<br>
</blockquote>
<br>
I've added that just to simplify the code logic as I assumed we
will be
<br>
running mock tests only in "true kunit" fashion as part of the
build.
<br>
<br>
So then we could avoid mixing mock/live "kunit suites" in single
driver
<br>
module, especially that as of today there is no nice support to
filter
<br>
out undesired suites from the execution. Thus adding compile
time flag
<br>
to only have one category of selftests at time was looking
promising.
<br>
</blockquote>
<br>
I'm using this in the patches I'm sending to unit test rtp and wa
parts:
<br>
<br>
./tools/testing/kunit/kunit.py run --raw_output \
<br>
--kunitconfig drivers/gpu/drm/xe/.kunitconfig
xe_rtp
<br>
<br>
<blockquote type="cite">
<br>
So I was using .kunitconfig with
<br>
CONFIG_DRM_XE_SELFTESTS_MOCK=y
<br>
and normal .config with
<br>
CONFIG_DRM_XE_SELFTESTS_LIVE=y
<br>
<br>
<blockquote type="cite">
<br>
I have changes pending to test some WA and RTP infra we added,
<br>
regardless of the HW. But I don't want to have to choose
either one or
<br>
the other.
<br>
</blockquote>
<br>
And I guess you still can do that, just it wont be automatically
<br>
compiled out, nor you be able to benefit from the helpers, but
they will
<br>
be executed
<br>
<br>
<blockquote type="cite">
<br>
Also Cc Thomas as original author of the kunit integration.
<br>
<br>
We also have some overloaded terms that need better
explanation:
<br>
mock, selftest, live.
<br>
</blockquote>
<br>
I reused terms from i915, assumed everyone is familiar with
that.
<br>
<br>
"mock selftest" - a kunit test suite to be run on abstract xe
device
<br>
"live selftest" - a kunit test suite to be executed on real xe
device
<br>
</blockquote>
<br>
Things I like on the current kunit integration we have in xe:
<br>
<br>
1) The ability to move unit test code out to a separate module
<br>
2) Not having a big infra that is xe-only
<br>
3) Share terminology with the rest of drm subsystem
<br>
<br>
This patch series is basically killing (1) and (3). And for (2) it
seems
<br>
to be heading another direction. Looking at the current available
<br>
drivers, I think we should be more like the drm tests and the vc4
tests
<br>
rather than the i915 ones. If we need more helpers we may
probably
<br>
extend the ones in DRM_KUNIT_TEST_HELPERS
<br>
<br>
I'd love to hear others' opinions though.
<br>
</blockquote>
<p>I basically agree with Lucas here. Some points:</p>
<ul>
<li>For mock selftests IMO we don't need anything on top of what
we already have, except perhaps consolidate initialization of a
mock device as a helper each test can optionally use. I think,
though, that Mauro's suggestion of coalescing multiple mock
tests together in a single separate kernel module with multiple
test suites to avoid too many separate kernel module might be
worth considering if needed.</li>
<li>For live selftests it seems like where the big disconnect is.
I still believe that we should have separate modules, and
depending on how the IGT runner end up working have enough
information in that module for IGT to execute the tests with the
--run-subtest and --dynamic-subtest options.</li>
<li>Admiddedly the xe_for_each_device() helper is very limited,
but couldn't we just make a more elaborate helper that can add
functionality like filter out devices if needed? I'm thinking if
we enforce a middle layer that tells each test what device it
should be testing, things like testing PCI p2p dma between
devices will become awkward (but still possible I guess).</li>
<li>Do we really need to support compiled-in live selftests that
run a device on device binding? I guess the use-case isn't fully
clear to me.</li>
<li>And yes the test parameters shouldn't be needing the
test->priv, but neither should we need to pass the device
here, right?</li>
</ul>
<p>/Thomas</p>
<p><br>
</p>
<p><br>
</p>
<p><br>
</p>
<p><br>
</p>
<blockquote type="cite"
cite="mid:20230316064643.fu5thzu4pf7htisq@ldmartin-desk2.lan">
<br>
Lucas De Marchi
<br>
<br>
<blockquote type="cite">
<br>
If you have better suggestions, then you're welcomed
<br>
<br>
<blockquote type="cite">
<br>
<blockquote type="cite">+ depends on DRM_XE &&
KUNIT && EXPERT
<br>
+ default n
<br>
+ help
<br>
+ Choose this option to allow the driver to perform
live
<br>
+ selftests based on the Kunit framework.
<br>
+
<br>
+ Recommended for driver developers only.
<br>
+ If in doubt, say "N".
<br>
+
<br>
config DRM_XE_KUNIT_TEST
<br>
tristate "KUnit tests for the drm xe driver" if
!KUNIT_ALL_TESTS
<br>
depends on DRM_XE && KUNIT && DEBUG_FS
<br>
diff --git a/drivers/gpu/drm/xe/Makefile
b/drivers/gpu/drm/xe/Makefile
<br>
index b94e65c91101..b193af2d9930 100644
<br>
--- a/drivers/gpu/drm/xe/Makefile
<br>
+++ b/drivers/gpu/drm/xe/Makefile
<br>
@@ -211,6 +211,17 @@ ifeq ($(CONFIG_DRM_FBDEV_EMULATION),y)
<br>
xe-$(CONFIG_DRM_XE_DISPLAY) += display/intel_fbdev.o
<br>
endif
<br>
<br>
+xe-$(CONFIG_DRM_XE_SELFTESTS_MOCK) += \
<br>
+ selftests/xe_selftests_mock.o \
<br>
+
<br>
+xe-$(CONFIG_DRM_XE_SELFTESTS_LIVE) += \
<br>
+ selftests/xe_selftests_auto.o \
<br>
+ selftests/xe_selftests_executor.o \
<br>
+ selftests/xe_selftests_params.o \
<br>
+
<br>
+xe-$(CONFIG_KUNIT) += \
<br>
+ selftests/xe_selftests_helpers.o \
<br>
+
<br>
obj-$(CONFIG_DRM_XE) += xe.o
<br>
obj-$(CONFIG_DRM_XE_KUNIT_TEST) += tests/
<br>
<br>
diff --git a/drivers/gpu/drm/xe/selftests/xe_selftests.h
<br>
b/drivers/gpu/drm/xe/selftests/xe_selftests.h
<br>
new file mode 100644
<br>
index 000000000000..6b13b998e789
<br>
--- /dev/null
<br>
+++ b/drivers/gpu/drm/xe/selftests/xe_selftests.h
<br>
@@ -0,0 +1,35 @@
<br>
+/* SPDX-License-Identifier: MIT */
<br>
+/*
<br>
+ * Copyright © 2023 Intel Corporation
<br>
+ */
<br>
+
<br>
+#ifndef _XE_SELFTESTS_H_
<br>
+#define _XE_SELFTESTS_H_
<br>
+
<br>
+struct kunit_suite;
<br>
+struct kunit;
<br>
+
<br>
+int xe_selftests_run(const char *dev_name);
<br>
+
<br>
+#if IS_ENABLED(CONFIG_DRM_XE_SELFTESTS_LIVE)
<br>
+int init_xe_live_selftest_suite(struct kunit_suite *suite);
<br>
+#endif
<br>
+
<br>
+int init_xe_device_selftest(struct kunit *test);
<br>
+void exit_xe_device_selftest(struct kunit *test);
<br>
+
<br>
+int init_xe_gt_selftest(struct kunit *test);
<br>
+void exit_xe_gt_selftest(struct kunit *test);
<br>
+
<br>
+int init_xe_guc_selftest(struct kunit *test);
<br>
+void exit_xe_guc_selftest(struct kunit *test);
<br>
+
<br>
+#if IS_ENABLED(CONFIG_DRM_XE_SELFTESTS_LIVE)
<br>
+int xe_selftests_module_init(void);
<br>
+void xe_selftests_module_exit(void);
<br>
+#else
<br>
+static inline int xe_selftests_module_init(void) { return
0; }
<br>
+static inline void xe_selftests_module_exit(void) { }
<br>
+#endif
<br>
+
<br>
+#endif /* _XE_SELFTESTS_H_ */
<br>
diff --git
a/drivers/gpu/drm/xe/selftests/xe_selftests_auto.c
<br>
b/drivers/gpu/drm/xe/selftests/xe_selftests_auto.c
<br>
new file mode 100644
<br>
index 000000000000..ef98f3599eac
<br>
--- /dev/null
<br>
+++ b/drivers/gpu/drm/xe/selftests/xe_selftests_auto.c
<br>
@@ -0,0 +1,46 @@
<br>
+// SPDX-License-Identifier: MIT
<br>
+/*
<br>
+ * Copyright © 2023 Intel Corporation
<br>
+ */
<br>
+
<br>
+#include <linux/device.h>
<br>
+#include <linux/glob.h>
<br>
+#include <linux/pci.h>
<br>
+
<br>
+#include "xe_drv.h"
<br>
+#include "selftests/xe_selftests.h"
<br>
+#include "selftests/xe_selftests_internal.h"
<br>
+
<br>
+static int bus_cb(struct notifier_block *nb, unsigned long
action,
<br>
void *data)
<br>
+{
<br>
+ struct device *dev = data;
<br>
+ struct device_driver *drv = dev->driver;
<br>
+
<br>
+ if (action != BUS_NOTIFY_BOUND_DRIVER)
<br>
+ return 0;
<br>
+
<br>
+ if (strcmp(DRIVER_NAME, drv->name))
<br>
+ return 0;
<br>
+
<br>
+ /* only matching DUT names will be tested */
<br>
+ if (!dut_filter || !glob_match(dut_filter,
dev_name(dev)))
<br>
</blockquote>
<br>
"DUT" name could be avoided and just use what exactly it
means.
<br>
When I see "DUT" I'm wondering... is this the platform name,
the pci ID,
<br>
the pci slot, the device node?
<br>
</blockquote>
<br>
will rename to "dut_name_filter" do the trick ?
<br>
<br>
or do you want to drop "dut" completely and have
"device_name_filter" ?
<br>
but then we would need to add "selftest" or similar word
somewhere to
<br>
give context and then full modparam name will no longer be that
friendly
<br>
<br>
Thanks,
<br>
Michal
<br>
</blockquote>
</blockquote>
</body>
</html>