xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/i915/i915_selftest.h (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: i915_selftest.h,v 1.2 2021/12/18 23:45:28 riastradh Exp $	*/
2 
3 /*
4  * Copyright © 2016 Intel Corporation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23  * IN THE SOFTWARE.
24  */
25 
26 #ifndef __I915_SELFTEST_H__
27 #define __I915_SELFTEST_H__
28 
29 #include <linux/types.h>
30 
31 struct pci_dev;
32 struct drm_i915_private;
33 
34 struct i915_selftest {
35 	unsigned long timeout_jiffies;
36 	unsigned int timeout_ms;
37 	unsigned int random_seed;
38 	char *filter;
39 	int mock;
40 	int live;
41 	int perf;
42 };
43 
44 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
45 #include <linux/fault-inject.h>
46 
47 extern struct i915_selftest i915_selftest;
48 
49 int i915_mock_selftests(void);
50 int i915_live_selftests(struct pci_dev *pdev);
51 int i915_perf_selftests(struct pci_dev *pdev);
52 
53 /* We extract the function declarations from i915_mock_selftests.h and
54  * i915_live_selftests.h Add your unit test declarations there!
55  *
56  * Mock unit tests are run very early upon module load, before the driver
57  * is probed. All hardware interactions, as well as other subsystems, must
58  * be "mocked".
59  *
60  * Live unit tests are run after the driver is loaded - all hardware
61  * interactions are real.
62  */
63 #define selftest(name, func) int func(void);
64 #include "selftests/i915_mock_selftests.h"
65 #undef selftest
66 #define selftest(name, func) int func(struct drm_i915_private *i915);
67 #include "selftests/i915_live_selftests.h"
68 #include "selftests/i915_perf_selftests.h"
69 #undef selftest
70 
71 struct i915_subtest {
72 	int (*func)(void *data);
73 	const char *name;
74 };
75 
76 int __i915_nop_setup(void *data);
77 int __i915_nop_teardown(int err, void *data);
78 
79 int __i915_live_setup(void *data);
80 int __i915_live_teardown(int err, void *data);
81 
82 int __intel_gt_live_setup(void *data);
83 int __intel_gt_live_teardown(int err, void *data);
84 
85 int __i915_subtests(const char *caller,
86 		    int (*setup)(void *data),
87 		    int (*teardown)(int err, void *data),
88 		    const struct i915_subtest *st,
89 		    unsigned int count,
90 		    void *data);
91 #define i915_subtests(T, data) \
92 	__i915_subtests(__func__, \
93 			__i915_nop_setup, __i915_nop_teardown, \
94 			T, ARRAY_SIZE(T), data)
95 #define i915_live_subtests(T, data) ({ \
96 	typecheck(struct drm_i915_private *, data); \
97 	__i915_subtests(__func__, \
98 			__i915_live_setup, __i915_live_teardown, \
99 			T, ARRAY_SIZE(T), data); \
100 })
101 #define intel_gt_live_subtests(T, data) ({ \
102 	typecheck(struct intel_gt *, data); \
103 	__i915_subtests(__func__, \
104 			__intel_gt_live_setup, __intel_gt_live_teardown, \
105 			T, ARRAY_SIZE(T), data); \
106 })
107 
108 #define SUBTEST(x) { x, #x }
109 
110 #define I915_SELFTEST_DECLARE(x) x
111 #define I915_SELFTEST_ONLY(x) unlikely(x)
112 
113 #else /* !IS_ENABLED(CONFIG_DRM_I915_SELFTEST) */
114 
i915_mock_selftests(void)115 static inline int i915_mock_selftests(void) { return 0; }
i915_live_selftests(struct pci_dev * pdev)116 static inline int i915_live_selftests(struct pci_dev *pdev) { return 0; }
i915_perf_selftests(struct pci_dev * pdev)117 static inline int i915_perf_selftests(struct pci_dev *pdev) { return 0; }
118 
119 #define I915_SELFTEST_DECLARE(x)
120 #define I915_SELFTEST_ONLY(x) 0
121 
122 #endif
123 
124 /* Using the i915_selftest_ prefix becomes a little unwieldy with the helpers.
125  * Instead we use the igt_ shorthand, in reference to the intel-gpu-tools
126  * suite of uabi test cases (which includes a test runner for our selftests).
127  */
128 
129 #define IGT_TIMEOUT(name__) \
130 	unsigned long name__ = jiffies + i915_selftest.timeout_jiffies
131 
132 __printf(2, 3)
133 bool __igt_timeout(unsigned long timeout, const char *fmt, ...);
134 
135 #define igt_timeout(t, fmt, ...) \
136 	__igt_timeout((t), KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
137 
138 #endif /* !__I915_SELFTEST_H__ */
139