From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>,
Lucas De Marchi <lucas.demarchi@intel.com>
Subject: [PATCH 05/12] drm/xe/tests: Allow deferred function call during KUnit test
Date: Fri, 9 Aug 2024 18:51:52 +0200 [thread overview]
Message-ID: <20240809165159.662-6-michal.wajdeczko@intel.com> (raw)
In-Reply-To: <20240809165159.662-1-michal.wajdeczko@intel.com>
For some advanced test cases we might want to simulate external
activity that will stimulate function under test. Add set of
helper functions to implement such requirement. Usage example:
static void foo(struct xe_device *xe)
{
WRITE_ONCE(xe->foo, 1);
}
static void foo_test(struct kunit *test)
{
struct xe_device *xe = test->priv;
xe_kunit_helper_delayed_call(test, HZ / 2, foo, xe);
KUNIT_EXPECT_EQ(test, 0, READ_ONCE(xe->foo));
schedule_timeout_uninterruptible(HZ);
KUNIT_EXPECT_EQ(test, 1, READ_ONCE(xe->foo));
}
Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
---
drivers/gpu/drm/xe/tests/xe_kunit_helpers.c | 148 ++++++++++++++++++++
drivers/gpu/drm/xe/tests/xe_kunit_helpers.h | 38 +++++
2 files changed, 186 insertions(+)
diff --git a/drivers/gpu/drm/xe/tests/xe_kunit_helpers.c b/drivers/gpu/drm/xe/tests/xe_kunit_helpers.c
index bc5156966ce9..8fe1a0918b32 100644
--- a/drivers/gpu/drm/xe/tests/xe_kunit_helpers.c
+++ b/drivers/gpu/drm/xe/tests/xe_kunit_helpers.c
@@ -127,3 +127,151 @@ int xe_kunit_helper_xe_device_live_test_init(struct kunit *test)
return 0;
}
EXPORT_SYMBOL_IF_KUNIT(xe_kunit_helper_xe_device_live_test_init);
+
+struct xe_kunit_call {
+ struct delayed_work work;
+ struct kunit *test;
+ struct {
+ int (*int_gt)(struct xe_gt *gt);
+ int (*int_gt_uint)(struct xe_gt *gt, unsigned int n);
+ void (*void_gt)(struct xe_gt *gt);
+ void (*void_gt_uint)(struct xe_gt *gt, unsigned int n);
+ void (*void_xe)(struct xe_device *xe);
+ } func;
+ struct {
+ struct xe_device *xe;
+ struct xe_gt *gt;
+ unsigned int n;
+ } args;
+};
+
+static void call_work_func(struct work_struct *work)
+{
+ struct xe_kunit_call *call = container_of(work, typeof(*call), work.work);
+
+ if (call->func.void_xe) {
+ kunit_info(call->test, "calling %ps(xe)\n", call->func.void_xe);
+ call->func.void_xe(call->args.xe);
+ kunit_info(call->test, "%ps(xe) completed\n", call->func.void_xe);
+ } else if (call->func.void_gt) {
+ kunit_info(call->test, "%ps(gt)\n", call->func.void_gt);
+ call->func.void_gt(call->args.gt);
+ kunit_info(call->test, "%ps(gt) completed\n", call->func.void_gt);
+ } else if (call->func.int_gt_uint) {
+ int ret;
+
+ kunit_info(call->test, "calling %ps(gt,%u)\n",
+ call->func.int_gt_uint, call->args.n);
+ ret = call->func.int_gt_uint(call->args.gt, call->args.n);
+ if (ret < 0) {
+ kunit_info(call->test, "%ps(gt,%u) reported error %pe\n",
+ call->func.int_gt_uint, call->args.n, ERR_PTR(ret));
+ } else {
+ kunit_info(call->test, "%ps(gt,%u) returned %d\n",
+ call->func.int_gt_uint, call->args.n, ret);
+ }
+ }
+}
+
+static struct xe_kunit_call *prepare_call(struct kunit *test)
+{
+ struct xe_kunit_call *call;
+
+ call = kunit_kzalloc(test, sizeof(*call), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, call);
+
+ INIT_DELAYED_WORK(&call->work, call_work_func);
+ call->test = test;
+
+ return call;
+}
+
+KUNIT_DEFINE_ACTION_WRAPPER(cancel_call, cancel_delayed_work_sync, struct delayed_work *);
+
+static void queue_call(struct kunit *test, struct xe_kunit_call *call, unsigned long delay)
+{
+ queue_delayed_work(system_wq, &call->work, delay);
+ KUNIT_ASSERT_EQ(test, 0, kunit_add_action_or_reset(test, cancel_call, &call->work));
+}
+
+/**
+ * xe_kunit_helper_delayed_call_void_xe_device - Queue a function call during KUnit test
+ * @test: the &kunit test case
+ * @delay: number of jiffies to wait before queueing
+ * @func: the &xe_device function to call
+ * @xe: the &xe_device argument
+ *
+ * This function uses KUNIT_ASSERT to detect any failures.
+ */
+void xe_kunit_helper_delayed_call_void_xe_device(struct kunit *test,
+ unsigned long delay,
+ void (*func)(struct xe_device *xe),
+ struct xe_device *xe)
+{
+ struct xe_kunit_call *call = prepare_call(test);
+
+ KUNIT_ASSERT_NOT_NULL(test, func);
+ KUNIT_ASSERT_NOT_NULL(test, xe);
+
+ call->func.void_xe = func;
+ call->args.xe = xe;
+
+ return queue_call(test, call, delay);
+}
+EXPORT_SYMBOL_IF_KUNIT(xe_kunit_helper_delayed_call_void_xe_device);
+
+/**
+ * xe_kunit_helper_delayed_call_void_xe_gt - Queue a function call during KUnit test
+ * @test: the &kunit test case
+ * @delay: number of jiffies to wait before queueing
+ * @func: the &xe_gt function to call
+ * @gt: the &xe_gt function argument
+ *
+ * This function uses KUNIT_ASSERT to detect any failures.
+ */
+void xe_kunit_helper_delayed_call_void_xe_gt(struct kunit *test,
+ unsigned long delay,
+ void (*func)(struct xe_gt *gt),
+ struct xe_gt *gt)
+{
+ struct xe_kunit_call *call = prepare_call(test);
+
+ KUNIT_ASSERT_NOT_NULL(test, func);
+ KUNIT_ASSERT_NOT_NULL(test, gt);
+
+ call->func.void_gt = func;
+ call->args.gt = gt;
+
+ return queue_call(test, call, delay);
+}
+EXPORT_SYMBOL_IF_KUNIT(xe_kunit_helper_delayed_call_void_xe_gt);
+
+/**
+ * xe_kunit_helper_delayed_call_int_xe_gt_uint - Queue a function call during KUnit test
+ * @test: the &kunit test case
+ * @delay: number of jiffies to wait before queueing
+ * @func: the &xe_gt function to call
+ * @gt: the &xe_gt function argument
+ * @n: the function argument
+ *
+ * This function uses KUNIT_ASSERT to detect any failures.
+ */
+void xe_kunit_helper_delayed_call_int_xe_gt_uint(struct kunit *test,
+ unsigned long delay,
+ int (*func)(struct xe_gt *gt,
+ unsigned int vfid),
+ struct xe_gt *gt,
+ unsigned int n)
+{
+ struct xe_kunit_call *call = prepare_call(test);
+
+ KUNIT_ASSERT_NOT_NULL(test, func);
+ KUNIT_ASSERT_NOT_NULL(test, gt);
+
+ call->func.int_gt_uint = func;
+ call->args.gt = gt;
+ call->args.n = n;
+
+ return queue_call(test, call, delay);
+}
+EXPORT_SYMBOL_IF_KUNIT(xe_kunit_helper_delayed_call_int_xe_gt_uint);
diff --git a/drivers/gpu/drm/xe/tests/xe_kunit_helpers.h b/drivers/gpu/drm/xe/tests/xe_kunit_helpers.h
index 83665f7b1254..ec5287947ee4 100644
--- a/drivers/gpu/drm/xe/tests/xe_kunit_helpers.h
+++ b/drivers/gpu/drm/xe/tests/xe_kunit_helpers.h
@@ -9,6 +9,7 @@
struct device;
struct kunit;
struct xe_device;
+struct xe_gt;
struct xe_device *xe_kunit_helper_alloc_xe_device(struct kunit *test,
struct device *dev);
@@ -16,4 +17,41 @@ int xe_kunit_helper_xe_device_test_init(struct kunit *test);
int xe_kunit_helper_xe_device_live_test_init(struct kunit *test);
+void xe_kunit_helper_delayed_call_void_xe_device(struct kunit *test,
+ unsigned long delay,
+ void (*func)(struct xe_device *xe),
+ struct xe_device *xe);
+
+void xe_kunit_helper_delayed_call_void_xe_gt(struct kunit *test,
+ unsigned long delay,
+ void (*func)(struct xe_gt *gt),
+ struct xe_gt *gt);
+
+void xe_kunit_helper_delayed_call_int_xe_gt_uint(struct kunit *test,
+ unsigned long delay,
+ int (*func)(struct xe_gt *gt,
+ unsigned int vfid),
+ struct xe_gt *gt,
+ unsigned int n);
+
+/**
+ * xe_kunit_helper_delayed_call - Queue a function call during KUnit test
+ * @test: the &kunit test case
+ * @delay: number of jiffies to wait before queueing
+ * @func: the &xe_device or &xe_gt function to call
+ * @args: the &xe_device or &xe_gt and other function arguments
+ *
+ * This is a helper macro that compiles into dedicated function call based on
+ * the provided argument types.
+ */
+#define xe_kunit_helper_delayed_call(test, delay, func, args...) \
+ _Generic(func, \
+ void (*)(struct xe_device *) : \
+ xe_kunit_helper_delayed_call_void_xe_device, \
+ void (*)(struct xe_gt *) : \
+ xe_kunit_helper_delayed_call_void_xe_gt, \
+ int (*)(struct xe_gt *, unsigned int) : \
+ xe_kunit_helper_delayed_call_int_xe_gt_uint \
+ )(test, delay, func, args)
+
#endif
--
2.43.0
next prev parent reply other threads:[~2024-08-09 16:52 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-09 16:51 [PATCH 00/12] PF: Improve VF control Michal Wajdeczko
2024-08-09 16:51 ` [PATCH 01/12] drm/xe/pf: Add function to sanitize VF resources Michal Wajdeczko
2024-08-16 12:58 ` Piotr Piórkowski
2024-08-19 20:47 ` Lucas De Marchi
2024-08-20 9:38 ` Michal Wajdeczko
2024-08-20 13:16 ` Lucas De Marchi
2024-09-05 18:07 ` Rodrigo Vivi
2024-08-09 16:51 ` [PATCH 02/12] drm/xe/pf: Fix documentation formatting Michal Wajdeczko
2024-08-16 12:59 ` Piotr Piórkowski
2024-08-09 16:51 ` [PATCH 03/12] drm/xe/pf: Drop GuC notifications for non-existing VF Michal Wajdeczko
2024-08-16 13:01 ` Piotr Piórkowski
2024-08-19 17:51 ` Michal Wajdeczko
2024-08-22 10:48 ` Piotr Piórkowski
2024-08-09 16:51 ` [PATCH 04/12] drm/xe/pf: Improve VF control Michal Wajdeczko
2024-08-16 13:06 ` Piotr Piórkowski
2024-08-19 17:52 ` Michal Wajdeczko
2024-08-20 7:56 ` Piotr Piórkowski
2024-08-20 10:04 ` Michal Wajdeczko
2024-08-09 16:51 ` Michal Wajdeczko [this message]
2024-08-19 21:38 ` [PATCH 05/12] drm/xe/tests: Allow deferred function call during KUnit test Lucas De Marchi
2024-08-20 10:23 ` Michal Wajdeczko
2024-08-20 13:21 ` Lucas De Marchi
2024-08-20 13:27 ` Lucas De Marchi
2024-08-09 16:51 ` [PATCH 06/12] drm/xe/tests: Add helper macro to detect if KUnit is running Michal Wajdeczko
2024-08-09 16:51 ` [PATCH 07/12] drm/xe/tests: Add helpers to call stubs out of KUnit context Michal Wajdeczko
2024-08-19 21:52 ` Lucas De Marchi
2024-08-20 10:31 ` Michal Wajdeczko
2024-08-09 16:51 ` [PATCH 08/12] drm/xe/guc: Define stub for xe_guc_ct_send_recv() Michal Wajdeczko
2024-08-09 16:51 ` [PATCH 09/12] drm/xe/pf: Define stub for pf_sanitize_vf_resources() Michal Wajdeczko
2024-08-09 16:51 ` [PATCH 10/12] drm/xe/pf: Define stub for pf_send_vf_control_cmd() Michal Wajdeczko
2024-08-09 16:51 ` [PATCH 11/12] drm/xe/tests: Add KUnit tests for VF control state machines Michal Wajdeczko
2024-08-09 17:23 ` [PATCH v2 " Michal Wajdeczko
2024-08-22 10:51 ` Piotr Piórkowski
2024-08-22 10:47 ` [PATCH " Piotr Piórkowski
2024-08-09 16:51 ` [PATCH 12/12] drm/xe/tests: Add KUnit tests for VF control GuC messages Michal Wajdeczko
2024-08-23 13:18 ` Piotr Piórkowski
2024-08-09 16:57 ` ✓ CI.Patch_applied: success for PF: Improve VF control Patchwork
2024-08-09 16:58 ` ✗ CI.checkpatch: warning " Patchwork
2024-08-09 16:58 ` ✗ CI.KUnit: failure " Patchwork
2024-08-09 17:28 ` ✓ CI.Patch_applied: success for PF: Improve VF control (rev2) Patchwork
2024-08-09 17:29 ` ✗ CI.checkpatch: warning " Patchwork
2024-08-09 17:30 ` ✓ CI.KUnit: success " Patchwork
2024-08-09 17:42 ` ✓ CI.Build: " Patchwork
2024-08-09 17:44 ` ✗ CI.Hooks: failure " Patchwork
2024-08-09 17:46 ` ✓ CI.checksparse: success " Patchwork
2024-08-09 18:06 ` ✓ CI.BAT: " Patchwork
2024-08-09 20:35 ` ✗ CI.FULL: failure " Patchwork
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=20240809165159.662-6-michal.wajdeczko@intel.com \
--to=michal.wajdeczko@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=lucas.demarchi@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