]> www.infradead.org Git - users/hch/configfs.git/commitdiff
drm/xe/tests: Add helpers for use in live tests
authorMichal Wajdeczko <michal.wajdeczko@intel.com>
Sat, 20 Jul 2024 14:25:23 +0000 (16:25 +0200)
committerMichal Wajdeczko <michal.wajdeczko@intel.com>
Mon, 22 Jul 2024 10:20:08 +0000 (12:20 +0200)
Instead of iterating over available Xe devices within a testcase,
without being able to distinguish potential failures from different
devices on system with many Xe devices, introduce helpers that will
allow to treat each Xe device as a parameter for the testcase like:

static void bar(struct kunit *test)
{
struct xe_device *xe = test->priv;
...
}

struct kunit_case foo_live_tests[] = {
KUNIT_CASE_PARAM(bar, xe_pci_live_device_gen_param),
{}
};

struct kunit_suite foo_suite = {
.name = "foo_live",
.test_cases = foo_live_tests,
.init = xe_kunit_helper_xe_device_live_test_init,
};

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Reviewed-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240720142528.530-3-michal.wajdeczko@intel.com
drivers/gpu/drm/xe/tests/xe_kunit_helpers.c
drivers/gpu/drm/xe/tests/xe_kunit_helpers.h
drivers/gpu/drm/xe/tests/xe_pci.c
drivers/gpu/drm/xe/tests/xe_pci_test.h

index fefe79b3b75a42257519027955ce32d6ad1e3889..bc5156966ce9612edfcfa4e1909f32e137096e51 100644 (file)
@@ -12,7 +12,9 @@
 
 #include "tests/xe_kunit_helpers.h"
 #include "tests/xe_pci_test.h"
+#include "xe_device.h"
 #include "xe_device_types.h"
+#include "xe_pm.h"
 
 /**
  * xe_kunit_helper_alloc_xe_device - Allocate a &xe_device for a KUnit test.
@@ -88,3 +90,40 @@ int xe_kunit_helper_xe_device_test_init(struct kunit *test)
        return 0;
 }
 EXPORT_SYMBOL_IF_KUNIT(xe_kunit_helper_xe_device_test_init);
+
+KUNIT_DEFINE_ACTION_WRAPPER(put_xe_pm_runtime, xe_pm_runtime_put, struct xe_device *);
+
+/**
+ * xe_kunit_helper_xe_device_live_test_init - Prepare a &xe_device for
+ *                                            use in a live KUnit test.
+ * @test: the &kunit where live &xe_device will be used
+ *
+ * This function expects pointer to the &xe_device in the &test.param_value,
+ * like it is prepared by the &xe_pci_live_device_gen_param and stores that
+ * pointer as &kunit.priv to allow the test code to access it.
+ *
+ * This function makes sure that device is not wedged and then resumes it
+ * to avoid waking up the device inside the test. It uses deferred cleanup
+ * action to release a runtime_pm reference.
+ *
+ * This function can be used as custom implementation of &kunit_suite.init.
+ *
+ * This function uses KUNIT_ASSERT to detect any failures.
+ *
+ * Return: Always 0.
+ */
+int xe_kunit_helper_xe_device_live_test_init(struct kunit *test)
+{
+       struct xe_device *xe = xe_device_const_cast(test->param_value);
+
+       KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xe);
+       kunit_info(test, "running on %s device\n", xe->info.platform_name);
+
+       KUNIT_ASSERT_FALSE(test, xe_device_wedged(xe));
+       xe_pm_runtime_get(xe);
+       KUNIT_ASSERT_EQ(test, 0, kunit_add_action_or_reset(test, put_xe_pm_runtime, xe));
+
+       test->priv = xe;
+       return 0;
+}
+EXPORT_SYMBOL_IF_KUNIT(xe_kunit_helper_xe_device_live_test_init);
index 067a1babf0497c3271079d937f652b38487827fd..83665f7b1254e5e08de4285f889829ed0e5bc860 100644 (file)
@@ -14,4 +14,6 @@ struct xe_device *xe_kunit_helper_alloc_xe_device(struct kunit *test,
                                                  struct device *dev);
 int xe_kunit_helper_xe_device_test_init(struct kunit *test);
 
+int xe_kunit_helper_xe_device_live_test_init(struct kunit *test);
+
 #endif
index f62809ca8b51f56dd97985f9034df7f81f2ac192..577ee7d143818c223a622e54e71972f778c499f6 100644 (file)
@@ -167,3 +167,33 @@ done:
        return 0;
 }
 EXPORT_SYMBOL_IF_KUNIT(xe_pci_fake_device_init);
+
+/**
+ * xe_pci_live_device_gen_param - Helper to iterate Xe devices as KUnit parameters
+ * @prev: the previously returned value, or NULL for the first iteration
+ * @desc: the buffer for a parameter name
+ *
+ * Iterates over the available Xe devices on the system. Uses the device name
+ * as the parameter name.
+ *
+ * To be used only as a parameter generator function in &KUNIT_CASE_PARAM.
+ *
+ * Return: pointer to the next &struct xe_device ready to be used as a parameter
+ *         or NULL if there are no more Xe devices on the system.
+ */
+const void *xe_pci_live_device_gen_param(const void *prev, char *desc)
+{
+       const struct xe_device *xe = prev;
+       struct device *dev = xe ? xe->drm.dev : NULL;
+       struct device *next;
+
+       next = driver_find_next_device(&xe_pci_driver.driver, dev);
+       if (dev)
+               put_device(dev);
+       if (!next)
+               return NULL;
+
+       snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s", dev_name(next));
+       return pdev_to_xe_device(to_pci_dev(next));
+}
+EXPORT_SYMBOL_IF_KUNIT(xe_pci_live_device_gen_param);
index f40dcec8399291a737cc9200bc59ad4b3c3511c4..3e2558bc3c90ce2f78c9223470b09afbc7defbea 100644 (file)
@@ -35,4 +35,6 @@ struct xe_pci_fake_data {
 
 int xe_pci_fake_device_init(struct xe_device *xe);
 
+const void *xe_pci_live_device_gen_param(const void *prev, char *desc);
+
 #endif