1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <linux/compiler.h>
25
26#define selftest(name, func) __idx_##name,
27enum {
28#include TESTS
29};
30#undef selftest
31
32#define selftest(n, f) [__idx_##n] = { .name = #n, .func = f },
33static struct drm_selftest {
34 bool enabled;
35 const char *name;
36 int (*func)(void *);
37} selftests[] = {
38#include TESTS
39};
40#undef selftest
41
42
43#define param(n) __PASTE(igt__, __PASTE(__PASTE(__LINE__, __), n))
44#define selftest_0(n, func, id) \
45module_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
49
50static void set_default_test_all(struct drm_selftest *st, unsigned long count)
51{
52 unsigned long i;
53
54 for (i = 0; i < count; i++)
55 if (st[i].enabled)
56 return;
57
58 for (i = 0; i < count; i++)
59 st[i].enabled = true;
60}
61
62static int run_selftests(struct drm_selftest *st,
63 unsigned long count,
64 void *data)
65{
66 int err = 0;
67
68 set_default_test_all(st, count);
69
70
71 for (; count--; st++) {
72 if (!st->enabled)
73 continue;
74
75 pr_debug("drm: Running %s\n", st->name);
76 err = st->func(data);
77 if (err)
78 break;
79 }
80
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;
85
86 rcu_barrier();
87 return err;
88}
89
90static int __maybe_unused
91__drm_subtests(const char *caller,
92 const struct drm_subtest *st,
93 int count,
94 void *data)
95{
96 int err;
97
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;
105 }
106 }
107
108 return 0;
109}
110