Home | History | Annotate | Line # | Download | only in i915
      1  1.1  riastrad /*	$NetBSD: i915_selftest.h,v 1.2 2021/12/18 23:45:28 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright  2016 Intel Corporation
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      8  1.1  riastrad  * to deal in the Software without restriction, including without limitation
      9  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     11  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     12  1.1  riastrad  *
     13  1.1  riastrad  * The above copyright notice and this permission notice (including the next
     14  1.1  riastrad  * paragraph) shall be included in all copies or substantial portions of the
     15  1.1  riastrad  * Software.
     16  1.1  riastrad  *
     17  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     18  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     19  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     20  1.1  riastrad  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     21  1.1  riastrad  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     22  1.1  riastrad  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
     23  1.1  riastrad  * IN THE SOFTWARE.
     24  1.1  riastrad  */
     25  1.1  riastrad 
     26  1.1  riastrad #ifndef __I915_SELFTEST_H__
     27  1.1  riastrad #define __I915_SELFTEST_H__
     28  1.1  riastrad 
     29  1.1  riastrad #include <linux/types.h>
     30  1.1  riastrad 
     31  1.1  riastrad struct pci_dev;
     32  1.1  riastrad struct drm_i915_private;
     33  1.1  riastrad 
     34  1.1  riastrad struct i915_selftest {
     35  1.1  riastrad 	unsigned long timeout_jiffies;
     36  1.1  riastrad 	unsigned int timeout_ms;
     37  1.1  riastrad 	unsigned int random_seed;
     38  1.1  riastrad 	char *filter;
     39  1.1  riastrad 	int mock;
     40  1.1  riastrad 	int live;
     41  1.1  riastrad 	int perf;
     42  1.1  riastrad };
     43  1.1  riastrad 
     44  1.1  riastrad #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
     45  1.1  riastrad #include <linux/fault-inject.h>
     46  1.1  riastrad 
     47  1.1  riastrad extern struct i915_selftest i915_selftest;
     48  1.1  riastrad 
     49  1.1  riastrad int i915_mock_selftests(void);
     50  1.1  riastrad int i915_live_selftests(struct pci_dev *pdev);
     51  1.1  riastrad int i915_perf_selftests(struct pci_dev *pdev);
     52  1.1  riastrad 
     53  1.1  riastrad /* We extract the function declarations from i915_mock_selftests.h and
     54  1.1  riastrad  * i915_live_selftests.h Add your unit test declarations there!
     55  1.1  riastrad  *
     56  1.1  riastrad  * Mock unit tests are run very early upon module load, before the driver
     57  1.1  riastrad  * is probed. All hardware interactions, as well as other subsystems, must
     58  1.1  riastrad  * be "mocked".
     59  1.1  riastrad  *
     60  1.1  riastrad  * Live unit tests are run after the driver is loaded - all hardware
     61  1.1  riastrad  * interactions are real.
     62  1.1  riastrad  */
     63  1.1  riastrad #define selftest(name, func) int func(void);
     64  1.1  riastrad #include "selftests/i915_mock_selftests.h"
     65  1.1  riastrad #undef selftest
     66  1.1  riastrad #define selftest(name, func) int func(struct drm_i915_private *i915);
     67  1.1  riastrad #include "selftests/i915_live_selftests.h"
     68  1.1  riastrad #include "selftests/i915_perf_selftests.h"
     69  1.1  riastrad #undef selftest
     70  1.1  riastrad 
     71  1.1  riastrad struct i915_subtest {
     72  1.1  riastrad 	int (*func)(void *data);
     73  1.1  riastrad 	const char *name;
     74  1.1  riastrad };
     75  1.1  riastrad 
     76  1.1  riastrad int __i915_nop_setup(void *data);
     77  1.1  riastrad int __i915_nop_teardown(int err, void *data);
     78  1.1  riastrad 
     79  1.1  riastrad int __i915_live_setup(void *data);
     80  1.1  riastrad int __i915_live_teardown(int err, void *data);
     81  1.1  riastrad 
     82  1.1  riastrad int __intel_gt_live_setup(void *data);
     83  1.1  riastrad int __intel_gt_live_teardown(int err, void *data);
     84  1.1  riastrad 
     85  1.1  riastrad int __i915_subtests(const char *caller,
     86  1.1  riastrad 		    int (*setup)(void *data),
     87  1.1  riastrad 		    int (*teardown)(int err, void *data),
     88  1.1  riastrad 		    const struct i915_subtest *st,
     89  1.1  riastrad 		    unsigned int count,
     90  1.1  riastrad 		    void *data);
     91  1.1  riastrad #define i915_subtests(T, data) \
     92  1.1  riastrad 	__i915_subtests(__func__, \
     93  1.1  riastrad 			__i915_nop_setup, __i915_nop_teardown, \
     94  1.1  riastrad 			T, ARRAY_SIZE(T), data)
     95  1.1  riastrad #define i915_live_subtests(T, data) ({ \
     96  1.1  riastrad 	typecheck(struct drm_i915_private *, data); \
     97  1.1  riastrad 	__i915_subtests(__func__, \
     98  1.1  riastrad 			__i915_live_setup, __i915_live_teardown, \
     99  1.1  riastrad 			T, ARRAY_SIZE(T), data); \
    100  1.1  riastrad })
    101  1.1  riastrad #define intel_gt_live_subtests(T, data) ({ \
    102  1.1  riastrad 	typecheck(struct intel_gt *, data); \
    103  1.1  riastrad 	__i915_subtests(__func__, \
    104  1.1  riastrad 			__intel_gt_live_setup, __intel_gt_live_teardown, \
    105  1.1  riastrad 			T, ARRAY_SIZE(T), data); \
    106  1.1  riastrad })
    107  1.1  riastrad 
    108  1.1  riastrad #define SUBTEST(x) { x, #x }
    109  1.1  riastrad 
    110  1.1  riastrad #define I915_SELFTEST_DECLARE(x) x
    111  1.1  riastrad #define I915_SELFTEST_ONLY(x) unlikely(x)
    112  1.1  riastrad 
    113  1.1  riastrad #else /* !IS_ENABLED(CONFIG_DRM_I915_SELFTEST) */
    114  1.1  riastrad 
    115  1.1  riastrad static inline int i915_mock_selftests(void) { return 0; }
    116  1.1  riastrad static inline int i915_live_selftests(struct pci_dev *pdev) { return 0; }
    117  1.1  riastrad static inline int i915_perf_selftests(struct pci_dev *pdev) { return 0; }
    118  1.1  riastrad 
    119  1.1  riastrad #define I915_SELFTEST_DECLARE(x)
    120  1.1  riastrad #define I915_SELFTEST_ONLY(x) 0
    121  1.1  riastrad 
    122  1.1  riastrad #endif
    123  1.1  riastrad 
    124  1.1  riastrad /* Using the i915_selftest_ prefix becomes a little unwieldy with the helpers.
    125  1.1  riastrad  * Instead we use the igt_ shorthand, in reference to the intel-gpu-tools
    126  1.1  riastrad  * suite of uabi test cases (which includes a test runner for our selftests).
    127  1.1  riastrad  */
    128  1.1  riastrad 
    129  1.1  riastrad #define IGT_TIMEOUT(name__) \
    130  1.1  riastrad 	unsigned long name__ = jiffies + i915_selftest.timeout_jiffies
    131  1.1  riastrad 
    132  1.1  riastrad __printf(2, 3)
    133  1.1  riastrad bool __igt_timeout(unsigned long timeout, const char *fmt, ...);
    134  1.1  riastrad 
    135  1.1  riastrad #define igt_timeout(t, fmt, ...) \
    136  1.1  riastrad 	__igt_timeout((t), KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
    137  1.1  riastrad 
    138  1.1  riastrad #endif /* !__I915_SELFTEST_H__ */
    139