drm_selftest.c 2.9 KB

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