From: Mauro Carvalho Chehab <mchehab@kernel.org>
To: unlisted-recipients:; (no To-header on input)
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
"Daniel Latypov" <dlatypov@google.com>,
"Isabella Basso" <isabbasso@riseup.net>,
Daniel Vetter <daniel@ffwll.ch>, David Airlie <airlied@gmail.com>,
Jani Nikula <jani.nikula@linux.intel.com>,
Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
Rodrigo Vivi <rodrigo.vivi@intel.com>,
Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
dri-devel@lists.freedesktop.org, igt-dev@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, skhan@linuxfoundation.org
Subject: [PATCH RFC v2 4/8] drm/i915: add support to run KUnit tests on bare metal
Date: Thu, 3 Nov 2022 14:51:34 +0000 [thread overview]
Message-ID: <df4fd92968cb7442dd2778f1c6f3e69935c5796b.1667486144.git.mchehab@kernel.org> (raw)
In-Reply-To: <cover.1667486144.git.mchehab@kernel.org>
Add a logic to seek for PCI devices and to run tests on
them, if the tests are willing to run on physical hardware,
instead of using Qemu.
Later patches will add the KUnit tests. So, for now, mark
such functions with __maybe_unused, to avoid build issues
with WERROR.
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
---
To avoid mailbombing on a large number of people, only mailing lists were C/C on the cover.
See [PATCH RFC v2 0/8] at: https://lore.kernel.org/all/cover.1667486144.git.mchehab@kernel.org/
drivers/gpu/drm/i915/selftests/i915_kunit.c | 100 ++++++++++++++++++++
1 file changed, 100 insertions(+)
diff --git a/drivers/gpu/drm/i915/selftests/i915_kunit.c b/drivers/gpu/drm/i915/selftests/i915_kunit.c
index 731b84a1fdc3..430610864f6e 100644
--- a/drivers/gpu/drm/i915/selftests/i915_kunit.c
+++ b/drivers/gpu/drm/i915/selftests/i915_kunit.c
@@ -8,9 +8,109 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#include <linux/pci.h>
#include <kunit/test.h>
+#include "i915_drv.h"
#include "i915_selftest.h"
+#define MAX_PCI_BOARDS 8
+
+/*
+ * PCI selftest support
+ *
+ * It is possible to run tests that demands hardware in bare metal.
+ *
+ * Add a logic to detect and get PCI devices using i915 driver, up to
+ * MAX_PCI_BOARDS devices.
+ */
+
+static int n_boards;
+static struct pci_dev *dev_i915[MAX_PCI_BOARDS];
+static int __maybe_unused i915_pci_init_suite(struct kunit_suite *suite)
+{
+ struct pci_dev *pdev = NULL;
+ int i;
+
+ /* Check for PCI devices with i915 driver */
+ do {
+ /*
+ * Let's search all devices at the PCI ID. We could, instead,
+ * use include/drm/i915_pciids.h, but that would mean a much
+ * more complex code, and won't still warrant that the device
+ * was bound to i915 driver. So, let's check the driver's
+ * name instead.
+ */
+ pdev = pci_get_device(PCI_VENDOR_ID_INTEL, PCI_ANY_ID, pdev);
+ if (pdev) {
+ if (pdev->driver && !strcmp(pdev->driver->name, "i915")) {
+ pr_info("%s: it is a i915 device.\n",
+ pci_name(pdev));
+
+ for (i = 0; i < n_boards; i++) {
+ if (pdev == dev_i915[i]) {
+ pci_dev_put(pdev);
+ continue;
+ }
+ }
+ dev_i915[n_boards++] = pdev;
+ if (n_boards >= MAX_PCI_BOARDS)
+ break;
+ } else {
+ pci_dev_put(pdev);
+ }
+ }
+ } while (pdev);
+
+ return 0;
+}
+
+static void __maybe_unused i915_pci_exit_suite(struct kunit_suite *suite)
+{
+ int i;
+
+ for (i = 0; i < n_boards; i++)
+ pci_dev_put(dev_i915[i]);
+
+ n_boards = 0;
+}
+
+static void __maybe_unused run_pci_test(struct kunit *test,
+ int (*f)(struct drm_i915_private *i915))
+{
+ struct drm_i915_private *i915;
+ int i, ret, disable_display;
+
+ if (!n_boards)
+ kunit_skip(test, "runs only on i915 hardware\n");
+
+ for (i = 0; i < n_boards; i++) {
+ i915 = pdev_to_i915(dev_i915[i]);
+
+ cond_resched();
+ if (signal_pending(current))
+ return;
+
+ pr_info("Running %s on %s\n",
+ test->name, pci_name(dev_i915[i]));
+
+ /* FIXME: is it ok to disable_display here? */
+ disable_display = i915->params.disable_display;
+ i915->params.disable_display = 1;
+ ret = f(i915);
+ i915->params.disable_display = disable_display;
+
+ if (ret == -EINTR && !signal_pending(current))
+ ret = 0;
+
+ if (WARN(ret > 0 || ret == -ENOTTY,
+ "%s returned %d, conflicting with selftest's magic values!\n",
+ test->name, ret))
+ ret = -EINVAL;
+
+ KUNIT_EXPECT_EQ(test, ret, 0);
+ }
+}
+
/*
* Test run logic, similar to what i915 selftest does
*/
--
2.38.1
next prev parent reply other threads:[~2022-11-03 14:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-03 14:51 [PATCH RFC v2 0/8] Add KUnit support for i915 driver Mauro Carvalho Chehab
2022-11-03 14:51 ` [PATCH RFC v2 1/8] drm/i915: export all selftest functions Mauro Carvalho Chehab
2022-11-03 14:51 ` [PATCH RFC v2 2/8] drm/i915: place selftest preparation on a separate function Mauro Carvalho Chehab
2022-11-03 14:51 ` [PATCH RFC v2 3/8] drm/i915: allow running mock selftests via Kunit Mauro Carvalho Chehab
2022-11-03 14:51 ` Mauro Carvalho Chehab [this message]
2022-11-03 14:51 ` [PATCH RFC v2 5/8] drm/i915: add live selftests to KUnit Mauro Carvalho Chehab
2022-11-03 14:51 ` [PATCH RFC v2 6/8] drm/i915: add perf " Mauro Carvalho Chehab
2022-11-03 14:51 ` [PATCH RFC v2 7/8] drm/i915: now that all functions are used, remove __maybe_unused Mauro Carvalho Chehab
2022-11-03 14:51 ` [PATCH RFC v2 8/8] drm/i915: check if current->mm is not NULL Mauro Carvalho Chehab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=df4fd92968cb7442dd2778f1c6f3e69935c5796b.1667486144.git.mchehab@kernel.org \
--to=mchehab@kernel.org \
--cc=airlied@gmail.com \
--cc=daniel@ffwll.ch \
--cc=dlatypov@google.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=igt-dev@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=isabbasso@riseup.net \
--cc=jani.nikula@linux.intel.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=rodrigo.vivi@intel.com \
--cc=skhan@linuxfoundation.org \
--cc=tvrtko.ursulin@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®