i915_selftest.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. #ifndef __I915_SELFTEST_H__
  24. #define __I915_SELFTEST_H__
  25. #include <linux/types.h>
  26. struct pci_dev;
  27. struct drm_i915_private;
  28. struct i915_selftest {
  29. unsigned long timeout_jiffies;
  30. unsigned int timeout_ms;
  31. unsigned int random_seed;
  32. char *filter;
  33. int mock;
  34. int live;
  35. int perf;
  36. };
  37. #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
  38. #include <linux/fault-inject.h>
  39. extern struct i915_selftest i915_selftest;
  40. int i915_mock_selftests(void);
  41. int i915_live_selftests(struct pci_dev *pdev);
  42. int i915_perf_selftests(struct pci_dev *pdev);
  43. /* We extract the function declarations from i915_mock_selftests.h and
  44. * i915_live_selftests.h Add your unit test declarations there!
  45. *
  46. * Mock unit tests are run very early upon module load, before the driver
  47. * is probed. All hardware interactions, as well as other subsystems, must
  48. * be "mocked".
  49. *
  50. * Live unit tests are run after the driver is loaded - all hardware
  51. * interactions are real.
  52. */
  53. #define selftest(name, func) int func(void);
  54. #include "selftests/i915_mock_selftests.h"
  55. #undef selftest
  56. #define selftest(name, func) int func(struct drm_i915_private *i915);
  57. #include "selftests/i915_live_selftests.h"
  58. #include "selftests/i915_perf_selftests.h"
  59. #undef selftest
  60. struct i915_subtest {
  61. int (*func)(void *data);
  62. const char *name;
  63. };
  64. int __i915_nop_setup(void *data);
  65. int __i915_nop_teardown(int err, void *data);
  66. int __i915_live_setup(void *data);
  67. int __i915_live_teardown(int err, void *data);
  68. int __intel_gt_live_setup(void *data);
  69. int __intel_gt_live_teardown(int err, void *data);
  70. int __i915_subtests(const char *caller,
  71. int (*setup)(void *data),
  72. int (*teardown)(int err, void *data),
  73. const struct i915_subtest *st,
  74. unsigned int count,
  75. void *data);
  76. #define i915_subtests(T, data) \
  77. __i915_subtests(__func__, \
  78. __i915_nop_setup, __i915_nop_teardown, \
  79. T, ARRAY_SIZE(T), data)
  80. #define i915_live_subtests(T, data) ({ \
  81. typecheck(struct drm_i915_private *, data); \
  82. __i915_subtests(__func__, \
  83. __i915_live_setup, __i915_live_teardown, \
  84. T, ARRAY_SIZE(T), data); \
  85. })
  86. #define intel_gt_live_subtests(T, data) ({ \
  87. typecheck(struct intel_gt *, data); \
  88. __i915_subtests(__func__, \
  89. __intel_gt_live_setup, __intel_gt_live_teardown, \
  90. T, ARRAY_SIZE(T), data); \
  91. })
  92. #define SUBTEST(x) { x, #x }
  93. #define I915_SELFTEST_DECLARE(x) x
  94. #define I915_SELFTEST_ONLY(x) unlikely(x)
  95. #define I915_SELFTEST_EXPORT
  96. #else /* !IS_ENABLED(CONFIG_DRM_I915_SELFTEST) */
  97. static inline int i915_mock_selftests(void) { return 0; }
  98. static inline int i915_live_selftests(struct pci_dev *pdev) { return 0; }
  99. static inline int i915_perf_selftests(struct pci_dev *pdev) { return 0; }
  100. #define I915_SELFTEST_DECLARE(x)
  101. #define I915_SELFTEST_ONLY(x) 0
  102. #define I915_SELFTEST_EXPORT static
  103. #endif
  104. /* Using the i915_selftest_ prefix becomes a little unwieldy with the helpers.
  105. * Instead we use the igt_ shorthand, in reference to the intel-gpu-tools
  106. * suite of uabi test cases (which includes a test runner for our selftests).
  107. */
  108. #define IGT_TIMEOUT(name__) \
  109. unsigned long name__ = jiffies + i915_selftest.timeout_jiffies
  110. __printf(2, 3)
  111. bool __igt_timeout(unsigned long timeout, const char *fmt, ...);
  112. #define igt_timeout(t, fmt, ...) \
  113. __igt_timeout((t), KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  114. void igt_hexdump(const void *buf, size_t len);
  115. #endif /* !__I915_SELFTEST_H__ */