00c8a3f9af8146ecb6d9938587d09c4d7be879f6
[linux-2.6-microblaze.git] / drivers / gpu / drm / xe / tests / xe_test.h
1 /* SPDX-License-Identifier: GPL-2.0 AND MIT */
2 /*
3  * Copyright © 2022 Intel Corporation
4  */
5
6 #ifndef _XE_TEST_H_
7 #define _XE_TEST_H_
8
9 #include <linux/types.h>
10
11 #if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST)
12 #include <linux/sched.h>
13 #include <kunit/test.h>
14
15 /*
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.
18  */
19 enum xe_test_priv_id {
20         XE_TEST_LIVE_DMA_BUF,
21 };
22
23 /**
24  * struct xe_test_priv - Base class for test private info
25  * @id: enum xe_test_priv_id to identify the subclass.
26  */
27 struct xe_test_priv {
28         enum xe_test_priv_id id;
29 };
30
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
35
36 /**
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.
40  *
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.
44  */
45 static inline struct xe_test_priv *
46 xe_cur_kunit_priv(enum xe_test_priv_id id)
47 {
48         struct xe_test_priv *priv;
49
50         if (!xe_cur_kunit())
51                 return NULL;
52
53         priv = xe_cur_kunit()->priv;
54         return priv->id == id ? priv : NULL;
55 }
56
57 #else /* if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST) */
58
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
64
65 #endif
66 #endif