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