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