Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / selftests / drm_selftest.c
blobe29ed9faef5bc84a20db9fb96664f31d1b12c3bf
1 /*
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
13 * Software.
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
21 * IN THE SOFTWARE.
24 #include <linux/compiler.h>
26 #define selftest(name, func) __idx_##name,
27 enum {
28 #include TESTS
30 #undef selftest
32 #define selftest(n, f) [__idx_##n] = { .name = #n, .func = f },
33 static struct drm_selftest {
34 bool enabled;
35 const char *name;
36 int (*func)(void *);
37 } selftests[] = {
38 #include TESTS
40 #undef selftest
42 /* Embed the line number into the parameter name so that we can order tests */
43 #define param(n) __PASTE(igt__, __PASTE(__PASTE(__LINE__, __), n))
44 #define selftest_0(n, func, id) \
45 module_param_named(id, selftests[__idx_##n].enabled, bool, 0400);
46 #define selftest(n, func) selftest_0(n, func, param(n))
47 #include TESTS
48 #undef selftest
50 static void set_default_test_all(struct drm_selftest *st, unsigned long count)
52 unsigned long i;
54 for (i = 0; i < count; i++)
55 if (st[i].enabled)
56 return;
58 for (i = 0; i < count; i++)
59 st[i].enabled = true;
62 static int run_selftests(struct drm_selftest *st,
63 unsigned long count,
64 void *data)
66 int err = 0;
68 set_default_test_all(st, count);
70 /* Tests are listed in natural order in drm_*_selftests.h */
71 for (; count--; st++) {
72 if (!st->enabled)
73 continue;
75 pr_debug("drm: Running %s\n", st->name);
76 err = st->func(data);
77 if (err)
78 break;
81 if (WARN(err > 0 || err == -ENOTTY,
82 "%s returned %d, conflicting with selftest's magic values!\n",
83 st->name, err))
84 err = -1;
86 rcu_barrier();
87 return err;
90 static int __maybe_unused
91 __drm_subtests(const char *caller,
92 const struct drm_subtest *st,
93 int count,
94 void *data)
96 int err;
98 for (; count--; st++) {
99 pr_debug("Running %s/%s\n", caller, st->name);
100 err = st->func(data);
101 if (err) {
102 pr_err("%s: %s failed with error %d\n",
103 caller, st->name, err);
104 return err;
108 return 0;