1 /* $NetBSD: drm_selftest.c,v 1.2 2021/12/18 23:45:44 riastradh Exp $ */ 2 3 /* 4 * Copyright 2016 Intel Corporation 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice (including the next 14 * paragraph) shall be included in all copies or substantial portions of the 15 * Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23 * IN THE SOFTWARE. 24 */ 25 26 #include <sys/cdefs.h> 27 __KERNEL_RCSID(0, "$NetBSD: drm_selftest.c,v 1.2 2021/12/18 23:45:44 riastradh Exp $"); 28 29 #include <linux/compiler.h> 30 31 #define selftest(name, func) __idx_##name, 32 enum { 33 #include TESTS 34 }; 35 #undef selftest 36 37 #define selftest(n, f) [__idx_##n] = { .name = #n, .func = f }, 38 static struct drm_selftest { 39 bool enabled; 40 const char *name; 41 int (*func)(void *); 42 } selftests[] = { 43 #include TESTS 44 }; 45 #undef selftest 46 47 /* Embed the line number into the parameter name so that we can order tests */ 48 #define param(n) __PASTE(igt__, __PASTE(__PASTE(__LINE__, __), n)) 49 #define selftest_0(n, func, id) \ 50 module_param_named(id, selftests[__idx_##n].enabled, bool, 0400); 51 #define selftest(n, func) selftest_0(n, func, param(n)) 52 #include TESTS 53 #undef selftest 54 55 static void set_default_test_all(struct drm_selftest *st, unsigned long count) 56 { 57 unsigned long i; 58 59 for (i = 0; i < count; i++) 60 if (st[i].enabled) 61 return; 62 63 for (i = 0; i < count; i++) 64 st[i].enabled = true; 65 } 66 67 static int run_selftests(struct drm_selftest *st, 68 unsigned long count, 69 void *data) 70 { 71 int err = 0; 72 73 set_default_test_all(st, count); 74 75 /* Tests are listed in natural order in drm_*_selftests.h */ 76 for (; count--; st++) { 77 if (!st->enabled) 78 continue; 79 80 pr_debug("drm: Running %s\n", st->name); 81 err = st->func(data); 82 if (err) 83 break; 84 } 85 86 if (WARN(err > 0 || err == -ENOTTY, 87 "%s returned %d, conflicting with selftest's magic values!\n", 88 st->name, err)) 89 err = -1; 90 91 rcu_barrier(); 92 return err; 93 } 94 95 static int __maybe_unused 96 __drm_subtests(const char *caller, 97 const struct drm_subtest *st, 98 int count, 99 void *data) 100 { 101 int err; 102 103 for (; count--; st++) { 104 pr_debug("Running %s/%s\n", caller, st->name); 105 err = st->func(data); 106 if (err) { 107 pr_err("%s: %s failed with error %d\n", 108 caller, st->name, err); 109 return err; 110 } 111 } 112 113 return 0; 114 } 115