2 * Copyright © 2016 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include <linux/random.h>
26 #include "../i915_drv.h"
27 #include "../i915_selftest.h"
29 struct i915_selftest i915_selftest __read_mostly
= {
33 int i915_mock_sanitycheck(void)
35 pr_info(DRIVER_NAME
": %s() - ok!\n", __func__
);
39 int i915_live_sanitycheck(struct drm_i915_private
*i915
)
41 pr_info("%s: %s() - ok!\n", i915
->drm
.driver
->name
, __func__
);
46 #define selftest(name, func) mock_##name,
47 #include "i915_mock_selftests.h"
52 #define selftest(name, func) live_##name,
53 #include "i915_live_selftests.h"
62 int (*live
)(struct drm_i915_private
*);
66 #define selftest(n, f) [mock_##n] = { .name = #n, { .mock = f } },
67 static struct selftest mock_selftests
[] = {
68 #include "i915_mock_selftests.h"
72 #define selftest(n, f) [live_##n] = { .name = #n, { .live = f } },
73 static struct selftest live_selftests
[] = {
74 #include "i915_live_selftests.h"
78 /* Embed the line number into the parameter name so that we can order tests */
79 #define selftest(n, func) selftest_0(n, func, param(n))
80 #define param(n) __PASTE(igt__, __PASTE(__LINE__, __mock_##n))
81 #define selftest_0(n, func, id) \
82 module_param_named(id, mock_selftests[mock_##n].enabled, bool, 0400);
83 #include "i915_mock_selftests.h"
87 #define param(n) __PASTE(igt__, __PASTE(__LINE__, __live_##n))
88 #define selftest_0(n, func, id) \
89 module_param_named(id, live_selftests[live_##n].enabled, bool, 0400);
90 #include "i915_live_selftests.h"
95 static void set_default_test_all(struct selftest
*st
, unsigned int count
)
99 for (i
= 0; i
< count
; i
++)
103 for (i
= 0; i
< count
; i
++)
104 st
[i
].enabled
= true;
107 static int __run_selftests(const char *name
,
114 while (!i915_selftest
.random_seed
)
115 i915_selftest
.random_seed
= get_random_int();
117 i915_selftest
.timeout_jiffies
=
118 i915_selftest
.timeout_ms
?
119 msecs_to_jiffies_timeout(i915_selftest
.timeout_ms
) :
120 MAX_SCHEDULE_TIMEOUT
;
122 set_default_test_all(st
, count
);
124 pr_info(DRIVER_NAME
": Performing %s selftests with st_random_seed=0x%x st_timeout=%u\n",
125 name
, i915_selftest
.random_seed
, i915_selftest
.timeout_ms
);
127 /* Tests are listed in order in i915_*_selftests.h */
128 for (; count
--; st
++) {
133 if (signal_pending(current
))
136 pr_debug(DRIVER_NAME
": Running %s\n", st
->name
);
138 err
= st
->live(data
);
141 if (err
== -EINTR
&& !signal_pending(current
))
147 if (WARN(err
> 0 || err
== -ENOTTY
,
148 "%s returned %d, conflicting with selftest's magic values!\n",
155 #define run_selftests(x, data) \
156 __run_selftests(#x, x##_selftests, ARRAY_SIZE(x##_selftests), data)
158 int i915_mock_selftests(void)
162 if (!i915_selftest
.mock
)
165 err
= run_selftests(mock
, NULL
);
167 i915_selftest
.mock
= err
;
171 if (i915_selftest
.mock
< 0) {
172 i915_selftest
.mock
= -ENOTTY
;
179 int i915_live_selftests(struct pci_dev
*pdev
)
183 if (!i915_selftest
.live
)
186 err
= run_selftests(live
, to_i915(pci_get_drvdata(pdev
)));
188 i915_selftest
.live
= err
;
192 if (i915_selftest
.live
< 0) {
193 i915_selftest
.live
= -ENOTTY
;
200 int __i915_subtests(const char *caller
,
201 const struct i915_subtest
*st
,
207 for (; count
--; st
++) {
209 if (signal_pending(current
))
212 pr_debug(DRIVER_NAME
": Running %s/%s\n", caller
, st
->name
);
213 err
= st
->func(data
);
214 if (err
&& err
!= -EINTR
) {
215 pr_err(DRIVER_NAME
"/%s: %s failed with error %d\n",
216 caller
, st
->name
, err
);
224 bool __igt_timeout(unsigned long timeout
, const char *fmt
, ...)
228 if (!signal_pending(current
)) {
230 if (time_before(jiffies
, timeout
))
243 module_param_named(st_random_seed
, i915_selftest
.random_seed
, uint
, 0400);
244 module_param_named(st_timeout
, i915_selftest
.timeout_ms
, uint
, 0400);
246 module_param_named_unsafe(mock_selftests
, i915_selftest
.mock
, int, 0400);
247 MODULE_PARM_DESC(mock_selftests
, "Run selftests before loading, using mock hardware (0:disabled [default], 1:run tests then load driver, -1:run tests then exit module)");
249 module_param_named_unsafe(live_selftests
, i915_selftest
.live
, int, 0400);
250 MODULE_PARM_DESC(live_selftests
, "Run selftests after driver initialisation on the live system (0:disabled [default], 1:run tests then continue, -1:run tests then exit module)");