162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * Copyright © 2016 Intel Corporation 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 562306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 662306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation 762306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 862306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 962306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 1062306a36Sopenharmony_ci * 1162306a36Sopenharmony_ci * The above copyright notice and this permission notice (including the next 1262306a36Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 1362306a36Sopenharmony_ci * Software. 1462306a36Sopenharmony_ci * 1562306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1662306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1762306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1862306a36Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1962306a36Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 2062306a36Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 2162306a36Sopenharmony_ci * IN THE SOFTWARE. 2262306a36Sopenharmony_ci */ 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci#ifndef __I915_SELFTEST_H__ 2562306a36Sopenharmony_ci#define __I915_SELFTEST_H__ 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci#include <linux/types.h> 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_cistruct pci_dev; 3062306a36Sopenharmony_cistruct drm_i915_private; 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_cistruct i915_selftest { 3362306a36Sopenharmony_ci unsigned long timeout_jiffies; 3462306a36Sopenharmony_ci unsigned int timeout_ms; 3562306a36Sopenharmony_ci unsigned int random_seed; 3662306a36Sopenharmony_ci char *filter; 3762306a36Sopenharmony_ci int mock; 3862306a36Sopenharmony_ci int live; 3962306a36Sopenharmony_ci int perf; 4062306a36Sopenharmony_ci}; 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) 4362306a36Sopenharmony_ci#include <linux/fault-inject.h> 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ciextern struct i915_selftest i915_selftest; 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ciint i915_mock_selftests(void); 4862306a36Sopenharmony_ciint i915_live_selftests(struct pci_dev *pdev); 4962306a36Sopenharmony_ciint i915_perf_selftests(struct pci_dev *pdev); 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci/* We extract the function declarations from i915_mock_selftests.h and 5262306a36Sopenharmony_ci * i915_live_selftests.h Add your unit test declarations there! 5362306a36Sopenharmony_ci * 5462306a36Sopenharmony_ci * Mock unit tests are run very early upon module load, before the driver 5562306a36Sopenharmony_ci * is probed. All hardware interactions, as well as other subsystems, must 5662306a36Sopenharmony_ci * be "mocked". 5762306a36Sopenharmony_ci * 5862306a36Sopenharmony_ci * Live unit tests are run after the driver is loaded - all hardware 5962306a36Sopenharmony_ci * interactions are real. 6062306a36Sopenharmony_ci */ 6162306a36Sopenharmony_ci#define selftest(name, func) int func(void); 6262306a36Sopenharmony_ci#include "selftests/i915_mock_selftests.h" 6362306a36Sopenharmony_ci#undef selftest 6462306a36Sopenharmony_ci#define selftest(name, func) int func(struct drm_i915_private *i915); 6562306a36Sopenharmony_ci#include "selftests/i915_live_selftests.h" 6662306a36Sopenharmony_ci#include "selftests/i915_perf_selftests.h" 6762306a36Sopenharmony_ci#undef selftest 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_cistruct i915_subtest { 7062306a36Sopenharmony_ci int (*func)(void *data); 7162306a36Sopenharmony_ci const char *name; 7262306a36Sopenharmony_ci}; 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ciint __i915_nop_setup(void *data); 7562306a36Sopenharmony_ciint __i915_nop_teardown(int err, void *data); 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ciint __i915_live_setup(void *data); 7862306a36Sopenharmony_ciint __i915_live_teardown(int err, void *data); 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ciint __intel_gt_live_setup(void *data); 8162306a36Sopenharmony_ciint __intel_gt_live_teardown(int err, void *data); 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ciint __i915_subtests(const char *caller, 8462306a36Sopenharmony_ci int (*setup)(void *data), 8562306a36Sopenharmony_ci int (*teardown)(int err, void *data), 8662306a36Sopenharmony_ci const struct i915_subtest *st, 8762306a36Sopenharmony_ci unsigned int count, 8862306a36Sopenharmony_ci void *data); 8962306a36Sopenharmony_ci#define i915_subtests(T, data) \ 9062306a36Sopenharmony_ci __i915_subtests(__func__, \ 9162306a36Sopenharmony_ci __i915_nop_setup, __i915_nop_teardown, \ 9262306a36Sopenharmony_ci T, ARRAY_SIZE(T), data) 9362306a36Sopenharmony_ci#define i915_live_subtests(T, data) ({ \ 9462306a36Sopenharmony_ci typecheck(struct drm_i915_private *, data); \ 9562306a36Sopenharmony_ci (data)->gt[0]->uc.guc.submission_state.sched_disable_delay_ms = 0; \ 9662306a36Sopenharmony_ci __i915_subtests(__func__, \ 9762306a36Sopenharmony_ci __i915_live_setup, __i915_live_teardown, \ 9862306a36Sopenharmony_ci T, ARRAY_SIZE(T), data); \ 9962306a36Sopenharmony_ci}) 10062306a36Sopenharmony_ci#define intel_gt_live_subtests(T, data) ({ \ 10162306a36Sopenharmony_ci typecheck(struct intel_gt *, data); \ 10262306a36Sopenharmony_ci (data)->uc.guc.submission_state.sched_disable_delay_ms = 0; \ 10362306a36Sopenharmony_ci __i915_subtests(__func__, \ 10462306a36Sopenharmony_ci __intel_gt_live_setup, __intel_gt_live_teardown, \ 10562306a36Sopenharmony_ci T, ARRAY_SIZE(T), data); \ 10662306a36Sopenharmony_ci}) 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci#define SUBTEST(x) { x, #x } 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci#define I915_SELFTEST_DECLARE(x) x 11162306a36Sopenharmony_ci#define I915_SELFTEST_ONLY(x) unlikely(x) 11262306a36Sopenharmony_ci#define I915_SELFTEST_EXPORT 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci#else /* !IS_ENABLED(CONFIG_DRM_I915_SELFTEST) */ 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_cistatic inline int i915_mock_selftests(void) { return 0; } 11762306a36Sopenharmony_cistatic inline int i915_live_selftests(struct pci_dev *pdev) { return 0; } 11862306a36Sopenharmony_cistatic inline int i915_perf_selftests(struct pci_dev *pdev) { return 0; } 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci#define I915_SELFTEST_DECLARE(x) 12162306a36Sopenharmony_ci#define I915_SELFTEST_ONLY(x) 0 12262306a36Sopenharmony_ci#define I915_SELFTEST_EXPORT static 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci#endif 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci/* Using the i915_selftest_ prefix becomes a little unwieldy with the helpers. 12762306a36Sopenharmony_ci * Instead we use the igt_ shorthand, in reference to the intel-gpu-tools 12862306a36Sopenharmony_ci * suite of uabi test cases (which includes a test runner for our selftests). 12962306a36Sopenharmony_ci */ 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci#define IGT_TIMEOUT(name__) \ 13262306a36Sopenharmony_ci unsigned long name__ = jiffies + i915_selftest.timeout_jiffies 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci__printf(2, 3) 13562306a36Sopenharmony_cibool __igt_timeout(unsigned long timeout, const char *fmt, ...); 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ci#define igt_timeout(t, fmt, ...) \ 13862306a36Sopenharmony_ci __igt_timeout((t), KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_civoid igt_hexdump(const void *buf, size_t len); 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ci#endif /* !__I915_SELFTEST_H__ */ 143