drm/xe/kunit: Restore test->priv when done with fake xe device
authorMichal Wajdeczko <michal.wajdeczko@intel.com>
Mon, 18 Dec 2023 19:06:25 +0000 (20:06 +0100)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Thu, 21 Dec 2023 21:31:30 +0000 (16:31 -0500)
Current KUnit implementation does not reset test->priv in case of
parametrized tests and that may lead to wrongly treat our output
pointer to fake xe_device from first call as input pointer with
xe_pci_fake_data on subsequent calls.  Restore test->priv to
original value to avoid invalid access.

Acked-by: Lucas De Marchi <lucas.demarchi@intel.com>
Link: https://lore.kernel.org/r/20231218190629.502-7-michal.wajdeczko@intel.com
Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
drivers/gpu/drm/xe/tests/xe_kunit_helpers.c

index 6d72dbf061393e31bcaa924088daa7a7ee8eeb6e..fefe79b3b75a42257519027955ce32d6ad1e3889 100644 (file)
@@ -41,6 +41,13 @@ struct xe_device *xe_kunit_helper_alloc_xe_device(struct kunit *test,
 }
 EXPORT_SYMBOL_IF_KUNIT(xe_kunit_helper_alloc_xe_device);
 
+static void kunit_action_restore_priv(void *priv)
+{
+       struct kunit *test = kunit_get_current_test();
+
+       test->priv = priv;
+}
+
 /**
  * xe_kunit_helper_xe_device_test_init - Prepare a &xe_device for a KUnit test.
  * @test: the &kunit where this fake &xe_device will be used
@@ -74,6 +81,9 @@ int xe_kunit_helper_xe_device_test_init(struct kunit *test)
        err = xe_pci_fake_device_init(xe);
        KUNIT_ASSERT_EQ(test, err, 0);
 
+       err = kunit_add_action_or_reset(test, kunit_action_restore_priv, test->priv);
+       KUNIT_ASSERT_EQ(test, err, 0);
+
        test->priv = xe;
        return 0;
 }