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 #ifndef __I915_SELFTEST_H__
0025 #define __I915_SELFTEST_H__
0026 
0027 #include <linux/types.h>
0028 
0029 struct pci_dev;
0030 struct drm_i915_private;
0031 
0032 struct i915_selftest {
0033     unsigned long timeout_jiffies;
0034     unsigned int timeout_ms;
0035     unsigned int random_seed;
0036     char *filter;
0037     int mock;
0038     int live;
0039     int perf;
0040 };
0041 
0042 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
0043 #include <linux/fault-inject.h>
0044 
0045 extern struct i915_selftest i915_selftest;
0046 
0047 int i915_mock_selftests(void);
0048 int i915_live_selftests(struct pci_dev *pdev);
0049 int i915_perf_selftests(struct pci_dev *pdev);
0050 
0051 /* We extract the function declarations from i915_mock_selftests.h and
0052  * i915_live_selftests.h Add your unit test declarations there!
0053  *
0054  * Mock unit tests are run very early upon module load, before the driver
0055  * is probed. All hardware interactions, as well as other subsystems, must
0056  * be "mocked".
0057  *
0058  * Live unit tests are run after the driver is loaded - all hardware
0059  * interactions are real.
0060  */
0061 #define selftest(name, func) int func(void);
0062 #include "selftests/i915_mock_selftests.h"
0063 #undef selftest
0064 #define selftest(name, func) int func(struct drm_i915_private *i915);
0065 #include "selftests/i915_live_selftests.h"
0066 #include "selftests/i915_perf_selftests.h"
0067 #undef selftest
0068 
0069 struct i915_subtest {
0070     int (*func)(void *data);
0071     const char *name;
0072 };
0073 
0074 int __i915_nop_setup(void *data);
0075 int __i915_nop_teardown(int err, void *data);
0076 
0077 int __i915_live_setup(void *data);
0078 int __i915_live_teardown(int err, void *data);
0079 
0080 int __intel_gt_live_setup(void *data);
0081 int __intel_gt_live_teardown(int err, void *data);
0082 
0083 int __i915_subtests(const char *caller,
0084             int (*setup)(void *data),
0085             int (*teardown)(int err, void *data),
0086             const struct i915_subtest *st,
0087             unsigned int count,
0088             void *data);
0089 #define i915_subtests(T, data) \
0090     __i915_subtests(__func__, \
0091             __i915_nop_setup, __i915_nop_teardown, \
0092             T, ARRAY_SIZE(T), data)
0093 #define i915_live_subtests(T, data) ({ \
0094     typecheck(struct drm_i915_private *, data); \
0095     __i915_subtests(__func__, \
0096             __i915_live_setup, __i915_live_teardown, \
0097             T, ARRAY_SIZE(T), data); \
0098 })
0099 #define intel_gt_live_subtests(T, data) ({ \
0100     typecheck(struct intel_gt *, data); \
0101     __i915_subtests(__func__, \
0102             __intel_gt_live_setup, __intel_gt_live_teardown, \
0103             T, ARRAY_SIZE(T), data); \
0104 })
0105 
0106 #define SUBTEST(x) { x, #x }
0107 
0108 #define I915_SELFTEST_DECLARE(x) x
0109 #define I915_SELFTEST_ONLY(x) unlikely(x)
0110 #define I915_SELFTEST_EXPORT
0111 
0112 #else /* !IS_ENABLED(CONFIG_DRM_I915_SELFTEST) */
0113 
0114 static inline int i915_mock_selftests(void) { return 0; }
0115 static inline int i915_live_selftests(struct pci_dev *pdev) { return 0; }
0116 static inline int i915_perf_selftests(struct pci_dev *pdev) { return 0; }
0117 
0118 #define I915_SELFTEST_DECLARE(x)
0119 #define I915_SELFTEST_ONLY(x) 0
0120 #define I915_SELFTEST_EXPORT static
0121 
0122 #endif
0123 
0124 /* Using the i915_selftest_ prefix becomes a little unwieldy with the helpers.
0125  * Instead we use the igt_ shorthand, in reference to the intel-gpu-tools
0126  * suite of uabi test cases (which includes a test runner for our selftests).
0127  */
0128 
0129 #define IGT_TIMEOUT(name__) \
0130     unsigned long name__ = jiffies + i915_selftest.timeout_jiffies
0131 
0132 __printf(2, 3)
0133 bool __igt_timeout(unsigned long timeout, const char *fmt, ...);
0134 
0135 #define igt_timeout(t, fmt, ...) \
0136     __igt_timeout((t), KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
0137 
0138 void igt_hexdump(const void *buf, size_t len);
0139 
0140 #endif /* !__I915_SELFTEST_H__ */