18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright © 2016 Intel Corporation 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next 128c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 138c2ecf20Sopenharmony_ci * Software. 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 168c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 178c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 188c2ecf20Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 198c2ecf20Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 208c2ecf20Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 218c2ecf20Sopenharmony_ci * IN THE SOFTWARE. 228c2ecf20Sopenharmony_ci */ 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#include <linux/compiler.h> 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#define selftest(name, func) __idx_##name, 278c2ecf20Sopenharmony_cienum { 288c2ecf20Sopenharmony_ci#include TESTS 298c2ecf20Sopenharmony_ci}; 308c2ecf20Sopenharmony_ci#undef selftest 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#define selftest(n, f) [__idx_##n] = { .name = #n, .func = f }, 338c2ecf20Sopenharmony_cistatic struct drm_selftest { 348c2ecf20Sopenharmony_ci bool enabled; 358c2ecf20Sopenharmony_ci const char *name; 368c2ecf20Sopenharmony_ci int (*func)(void *); 378c2ecf20Sopenharmony_ci} selftests[] = { 388c2ecf20Sopenharmony_ci#include TESTS 398c2ecf20Sopenharmony_ci}; 408c2ecf20Sopenharmony_ci#undef selftest 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci/* Embed the line number into the parameter name so that we can order tests */ 438c2ecf20Sopenharmony_ci#define param(n) __PASTE(igt__, __PASTE(__PASTE(__LINE__, __), n)) 448c2ecf20Sopenharmony_ci#define selftest_0(n, func, id) \ 458c2ecf20Sopenharmony_cimodule_param_named(id, selftests[__idx_##n].enabled, bool, 0400); 468c2ecf20Sopenharmony_ci#define selftest(n, func) selftest_0(n, func, param(n)) 478c2ecf20Sopenharmony_ci#include TESTS 488c2ecf20Sopenharmony_ci#undef selftest 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistatic void set_default_test_all(struct drm_selftest *st, unsigned long count) 518c2ecf20Sopenharmony_ci{ 528c2ecf20Sopenharmony_ci unsigned long i; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci for (i = 0; i < count; i++) 558c2ecf20Sopenharmony_ci if (st[i].enabled) 568c2ecf20Sopenharmony_ci return; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci for (i = 0; i < count; i++) 598c2ecf20Sopenharmony_ci st[i].enabled = true; 608c2ecf20Sopenharmony_ci} 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cistatic int run_selftests(struct drm_selftest *st, 638c2ecf20Sopenharmony_ci unsigned long count, 648c2ecf20Sopenharmony_ci void *data) 658c2ecf20Sopenharmony_ci{ 668c2ecf20Sopenharmony_ci int err = 0; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci set_default_test_all(st, count); 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci /* Tests are listed in natural order in drm_*_selftests.h */ 718c2ecf20Sopenharmony_ci for (; count--; st++) { 728c2ecf20Sopenharmony_ci if (!st->enabled) 738c2ecf20Sopenharmony_ci continue; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci pr_debug("drm: Running %s\n", st->name); 768c2ecf20Sopenharmony_ci err = st->func(data); 778c2ecf20Sopenharmony_ci if (err) 788c2ecf20Sopenharmony_ci break; 798c2ecf20Sopenharmony_ci } 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci if (WARN(err > 0 || err == -ENOTTY, 828c2ecf20Sopenharmony_ci "%s returned %d, conflicting with selftest's magic values!\n", 838c2ecf20Sopenharmony_ci st->name, err)) 848c2ecf20Sopenharmony_ci err = -1; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci rcu_barrier(); 878c2ecf20Sopenharmony_ci return err; 888c2ecf20Sopenharmony_ci} 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_cistatic int __maybe_unused 918c2ecf20Sopenharmony_ci__drm_subtests(const char *caller, 928c2ecf20Sopenharmony_ci const struct drm_subtest *st, 938c2ecf20Sopenharmony_ci int count, 948c2ecf20Sopenharmony_ci void *data) 958c2ecf20Sopenharmony_ci{ 968c2ecf20Sopenharmony_ci int err; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci for (; count--; st++) { 998c2ecf20Sopenharmony_ci pr_debug("Running %s/%s\n", caller, st->name); 1008c2ecf20Sopenharmony_ci err = st->func(data); 1018c2ecf20Sopenharmony_ci if (err) { 1028c2ecf20Sopenharmony_ci pr_err("%s: %s failed with error %d\n", 1038c2ecf20Sopenharmony_ci caller, st->name, err); 1048c2ecf20Sopenharmony_ci return err; 1058c2ecf20Sopenharmony_ci } 1068c2ecf20Sopenharmony_ci } 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci return 0; 1098c2ecf20Sopenharmony_ci} 110