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