i915_selftest.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. struct pci_dev;
  26. struct drm_i915_private;
  27. struct i915_selftest {
  28. unsigned long timeout_jiffies;
  29. unsigned int timeout_ms;
  30. unsigned int random_seed;
  31. int mock;
  32. int live;
  33. };
  34. #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
  35. #include <linux/fault-inject.h>
  36. extern struct i915_selftest i915_selftest;
  37. int i915_mock_selftests(void);
  38. int i915_live_selftests(struct pci_dev *pdev);
  39. /* We extract the function declarations from i915_mock_selftests.h and
  40. * i915_live_selftests.h Add your unit test declarations there!
  41. *
  42. * Mock unit tests are run very early upon module load, before the driver
  43. * is probed. All hardware interactions, as well as other subsystems, must
  44. * be "mocked".
  45. *
  46. * Live unit tests are run after the driver is loaded - all hardware
  47. * interactions are real.
  48. */
  49. #define selftest(name, func) int func(void);
  50. #include "selftests/i915_mock_selftests.h"
  51. #undef selftest
  52. #define selftest(name, func) int func(struct drm_i915_private *i915);
  53. #include "selftests/i915_live_selftests.h"
  54. #undef selftest
  55. struct i915_subtest {
  56. int (*func)(void *data);
  57. const char *name;
  58. };
  59. int __i915_subtests(const char *caller,
  60. const struct i915_subtest *st,
  61. unsigned int count,
  62. void *data);
  63. #define i915_subtests(T, data) \
  64. __i915_subtests(__func__, T, ARRAY_SIZE(T), data)
  65. #define SUBTEST(x) { x, #x }
  66. #define I915_SELFTEST_DECLARE(x) x
  67. #define I915_SELFTEST_ONLY(x) unlikely(x)
  68. #else /* !IS_ENABLED(CONFIG_DRM_I915_SELFTEST) */
  69. static inline int i915_mock_selftests(void) { return 0; }
  70. static inline int i915_live_selftests(struct pci_dev *pdev) { return 0; }
  71. #define I915_SELFTEST_DECLARE(x)
  72. #define I915_SELFTEST_ONLY(x) 0
  73. #endif
  74. /* Using the i915_selftest_ prefix becomes a little unwieldy with the helpers.
  75. * Instead we use the igt_ shorthand, in reference to the intel-gpu-tools
  76. * suite of uabi test cases (which includes a test runner for our selftests).
  77. */
  78. #define IGT_TIMEOUT(name__) \
  79. unsigned long name__ = jiffies + i915_selftest.timeout_jiffies
  80. __printf(2, 3)
  81. bool __igt_timeout(unsigned long timeout, const char *fmt, ...);
  82. #define igt_timeout(t, fmt, ...) \
  83. __igt_timeout((t), KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  84. #endif /* !__I915_SELFTEST_H__ */