1 /* SPDX-License-Identifier: MIT */
4 * Copyright © 2019 Intel Corporation
7 #include <linux/compiler.h>
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/sched/signal.h>
11 #include <linux/slab.h>
16 #define selftest(n, func) __idx_##n,
17 #include "selftests.h"
21 #define selftest(n, f) [__idx_##n] = { .name = #n, .func = f },
22 static struct selftest {
27 #include "selftests.h"
31 /* Embed the line number into the parameter name so that we can order tests */
32 #define param(n) __PASTE(igt__, __PASTE(__PASTE(__LINE__, __), n))
33 #define selftest_0(n, func, id) \
34 module_param_named(id, selftests[__idx_##n].enabled, bool, 0400);
35 #define selftest(n, func) selftest_0(n, func, param(n))
36 #include "selftests.h"
39 int __sanitycheck__(void)
41 pr_debug("Hello World!\n");
45 static char *__st_filter;
47 static bool apply_subtest_filter(const char *caller, const char *name)
49 char *filter, *sep, *tok;
52 filter = kstrdup(__st_filter, GFP_KERNEL);
53 for (sep = filter; (tok = strsep(&sep, ","));) {
65 sl = strchr(tok, '/');
68 if (strcmp(tok, caller)) {
76 if (strcmp(tok, name)) {
91 __subtests(const char *caller, const struct subtest *st, int count, void *data)
95 for (; count--; st++) {
97 if (signal_pending(current))
100 if (!apply_subtest_filter(caller, st->name))
103 pr_info("dma-buf: Running %s/%s\n", caller, st->name);
105 err = st->func(data);
106 if (err && err != -EINTR) {
107 pr_err("dma-buf/%s: %s failed with error %d\n",
108 caller, st->name, err);
116 static void set_default_test_all(struct selftest *st, unsigned long count)
120 for (i = 0; i < count; i++)
124 for (i = 0; i < count; i++)
125 st[i].enabled = true;
128 static int run_selftests(struct selftest *st, unsigned long count)
132 set_default_test_all(st, count);
134 /* Tests are listed in natural order in selftests.h */
135 for (; count--; st++) {
139 pr_info("dma-buf: Running %s\n", st->name);
145 if (WARN(err > 0 || err == -ENOTTY,
146 "%s returned %d, conflicting with selftest's magic values!\n",
153 static int __init st_init(void)
155 return run_selftests(selftests, ARRAY_SIZE(selftests));
158 static void __exit st_exit(void)
162 module_param_named(st_filter, __st_filter, charp, 0400);
163 module_init(st_init);
164 module_exit(st_exit);
166 MODULE_DESCRIPTION("Self-test harness for dma-buf");
167 MODULE_LICENSE("GPL and additional rights");