1 /* SPDX-License-Identifier: GPL-2.0 AND MIT */
3 * Copyright © 2022 Intel Corporation
9 #include <linux/types.h>
11 #if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST)
12 #include <linux/sched.h>
13 #include <kunit/test.h>
16 * Each test that provides a kunit private test structure, place a test id
17 * here and point the kunit->priv to an embedded struct xe_test_priv.
19 enum xe_test_priv_id {
24 * struct xe_test_priv - Base class for test private info
25 * @id: enum xe_test_priv_id to identify the subclass.
28 enum xe_test_priv_id id;
31 #define XE_TEST_DECLARE(x) x
32 #define XE_TEST_ONLY(x) unlikely(x)
33 #define XE_TEST_EXPORT
34 #define xe_cur_kunit() current->kunit_test
37 * xe_cur_kunit_priv - Obtain the struct xe_test_priv pointed to by
38 * current->kunit->priv if it exists and is embedded in the expected subclass.
39 * @id: Id of the expected subclass.
41 * Return: NULL if the process is not a kunit test, and NULL if the
42 * current kunit->priv pointer is not pointing to an object of the expected
43 * subclass. A pointer to the embedded struct xe_test_priv otherwise.
45 static inline struct xe_test_priv *
46 xe_cur_kunit_priv(enum xe_test_priv_id id)
48 struct xe_test_priv *priv;
53 priv = xe_cur_kunit()->priv;
54 return priv->id == id ? priv : NULL;
57 #else /* if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST) */
59 #define XE_TEST_DECLARE(x)
60 #define XE_TEST_ONLY(x) 0
61 #define XE_TEST_EXPORT static
62 #define xe_cur_kunit() NULL
63 #define xe_cur_kunit_priv(_id) NULL