Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright © 2016 Intel Corporation
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice (including the next
0012  * paragraph) shall be included in all copies or substantial portions of the
0013  * Software.
0014  *
0015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0018  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0020  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
0021  * IN THE SOFTWARE.
0022  */
0023 
0024 #include <linux/compiler.h>
0025 
0026 #define selftest(name, func) __idx_##name,
0027 enum {
0028 #include TESTS
0029 };
0030 #undef selftest
0031 
0032 #define selftest(n, f) [__idx_##n] = { .name = #n, .func = f },
0033 static struct drm_selftest {
0034     bool enabled;
0035     const char *name;
0036     int (*func)(void *);
0037 } selftests[] = {
0038 #include TESTS
0039 };
0040 #undef selftest
0041 
0042 /* Embed the line number into the parameter name so that we can order tests */
0043 #define param(n) __PASTE(igt__, __PASTE(__PASTE(__LINE__, __), n))
0044 #define selftest_0(n, func, id) \
0045 module_param_named(id, selftests[__idx_##n].enabled, bool, 0400);
0046 #define selftest(n, func) selftest_0(n, func, param(n))
0047 #include TESTS
0048 #undef selftest
0049 
0050 static void set_default_test_all(struct drm_selftest *st, unsigned long count)
0051 {
0052     unsigned long i;
0053 
0054     for (i = 0; i < count; i++)
0055         if (st[i].enabled)
0056             return;
0057 
0058     for (i = 0; i < count; i++)
0059         st[i].enabled = true;
0060 }
0061 
0062 static int run_selftests(struct drm_selftest *st,
0063              unsigned long count,
0064              void *data)
0065 {
0066     int err = 0;
0067 
0068     set_default_test_all(st, count);
0069 
0070     /* Tests are listed in natural order in drm_*_selftests.h */
0071     for (; count--; st++) {
0072         if (!st->enabled)
0073             continue;
0074 
0075         pr_debug("drm: Running %s\n", st->name);
0076         err = st->func(data);
0077         if (err)
0078             break;
0079     }
0080 
0081     if (WARN(err > 0 || err == -ENOTTY,
0082          "%s returned %d, conflicting with selftest's magic values!\n",
0083          st->name, err))
0084         err = -1;
0085 
0086     rcu_barrier();
0087     return err;
0088 }
0089 
0090 static int __maybe_unused
0091 __drm_subtests(const char *caller,
0092            const struct drm_subtest *st,
0093            int count,
0094            void *data)
0095 {
0096     int err;
0097 
0098     for (; count--; st++) {
0099         pr_debug("Running %s/%s\n", caller, st->name);
0100         err = st->func(data);
0101         if (err) {
0102             pr_err("%s: %s failed with error %d\n",
0103                    caller, st->name, err);
0104             return err;
0105         }
0106     }
0107 
0108     return 0;
0109 }