Re: [Intel-gfx] [RFC] drm/i915: Provide a hook for selftests

2016-12-01 Thread Chris Wilson
On Thu, Dec 01, 2016 at 11:32:44PM +, Chris Wilson wrote:
> To facilitate integration with igt, any parameter beginning with
> i915.subtest__ is interpreted as a selftest subtest executable
> independently via igt/drv_selftest.
> 
> +#define selftest(name, func) \
> +module_param_named(subtest__##name, i915_selftests[name].enabled, bool, 
> 0400);
> +#include "i915_selftests.h"
> +#undef selftest

Maybe igt__ is more useful as a prefix for the subtests? Shorter at
least.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [RFC] drm/i915: Provide a hook for selftests

2016-12-01 Thread Chris Wilson
Some pieces of code are independent of hardware but are very tricky to
exercise through the normal userspace ABI or via debugfs hooks. Being
able to create mock unit tests and execute them through CI is vital.
Start by adding a central point where we can execute unit tests from and
a parameter to enable them. This is disabled by default as the
expectation is that these tests will occasionally explode.

To facilitate integration with igt, any parameter beginning with
i915.subtest__ is interpreted as a selftest subtest executable
independently via igt/drv_selftest.

Signed-off-by: Chris Wilson 
---
 drivers/gpu/drm/i915/Kconfig.debug| 15 ++
 drivers/gpu/drm/i915/Makefile |  1 +
 drivers/gpu/drm/i915/i915_params.c|  5 ++
 drivers/gpu/drm/i915/i915_params.h|  3 ++
 drivers/gpu/drm/i915/i915_pci.c   |  6 +++
 drivers/gpu/drm/i915/i915_selftest.c  | 92 +++
 drivers/gpu/drm/i915/i915_selftest.h  | 40 +++
 drivers/gpu/drm/i915/i915_selftests.h | 11 +
 8 files changed, 173 insertions(+)
 create mode 100644 drivers/gpu/drm/i915/i915_selftest.c
 create mode 100644 drivers/gpu/drm/i915/i915_selftest.h
 create mode 100644 drivers/gpu/drm/i915/i915_selftests.h

diff --git a/drivers/gpu/drm/i915/Kconfig.debug 
b/drivers/gpu/drm/i915/Kconfig.debug
index a6c69b8cb1d2..b48822288e22 100644
--- a/drivers/gpu/drm/i915/Kconfig.debug
+++ b/drivers/gpu/drm/i915/Kconfig.debug
@@ -23,6 +23,7 @@ config DRM_I915_DEBUG
 select DRM_VGEM # used by igt/prime_vgem (dmabuf interop checks)
 select DRM_DEBUG_MM if DRM=y
 select DRM_I915_SW_FENCE_DEBUG_OBJECTS if DRM_I915=y
+   select DRM_I915_SELFTEST
 default n
 help
   Choose this option to turn on extra driver debugging that may affect
@@ -56,3 +57,17 @@ config DRM_I915_SW_FENCE_DEBUG_OBJECTS
   Recommended for driver developers only.
 
   If in doubt, say "N".
+
+config DRM_I915_SELFTEST
+   bool "Enable selftests upon driver load"
+   depends on DRM_I915
+   default n
+   help
+ Choose this option to allow the driver to perform selftests upon
+ loading; also requires the i915.selftest=1 module parameter. To
+ exit the module after running the selftests (i.e. to prevent normal
+ module initialisation afterwards) use i915.selftest=-1.
+
+ Recommended for driver developers only.
+
+ If in doubt, say "N".
diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
index 3c30916727fb..7c3b4f0c836c 100644
--- a/drivers/gpu/drm/i915/Makefile
+++ b/drivers/gpu/drm/i915/Makefile
@@ -114,6 +114,7 @@ i915-y += dvo_ch7017.o \
 
 # Post-mortem debug and GPU hang state capture
 i915-$(CONFIG_DRM_I915_CAPTURE_ERROR) += i915_gpu_error.o
+i915-$(CONFIG_DRM_I915_SELFTEST) += i915_selftest.o
 
 # virtual gpu code
 i915-y += i915_vgpu.o
diff --git a/drivers/gpu/drm/i915/i915_params.c 
b/drivers/gpu/drm/i915/i915_params.c
index 0e280fbd52f1..b66e38e66833 100644
--- a/drivers/gpu/drm/i915/i915_params.c
+++ b/drivers/gpu/drm/i915/i915_params.c
@@ -243,3 +243,8 @@ MODULE_PARM_DESC(enable_dpcd_backlight,
 module_param_named(enable_gvt, i915.enable_gvt, bool, 0400);
 MODULE_PARM_DESC(enable_gvt,
"Enable support for Intel GVT-g graphics virtualization host 
support(default:false)");
+
+#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
+module_param_named_unsafe(selftest, i915.selftest, int, 0400);
+MODULE_PARM_DESC(selftest, "Run selftests when loading (0:disabled [default], 
1 run tests then load module, -1 run tests then exit module)");
+#endif
diff --git a/drivers/gpu/drm/i915/i915_params.h 
b/drivers/gpu/drm/i915/i915_params.h
index 8e433de04679..49ca8a6f9407 100644
--- a/drivers/gpu/drm/i915/i915_params.h
+++ b/drivers/gpu/drm/i915/i915_params.h
@@ -28,6 +28,9 @@
 #include  /* for __read_mostly */
 
 struct i915_params {
+#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
+   int selftest;
+#endif
int modeset;
int panel_ignore_lid;
int semaphores;
diff --git a/drivers/gpu/drm/i915/i915_pci.c b/drivers/gpu/drm/i915/i915_pci.c
index 389a33090707..1683adb845ee 100644
--- a/drivers/gpu/drm/i915/i915_pci.c
+++ b/drivers/gpu/drm/i915/i915_pci.c
@@ -27,6 +27,7 @@
 #include 
 
 #include "i915_drv.h"
+#include "i915_selftest.h"
 
 #define GEN_DEFAULT_PIPEOFFSETS \
.pipe_offsets = { PIPE_A_OFFSET, PIPE_B_OFFSET, \
@@ -496,6 +497,11 @@ static struct pci_driver i915_pci_driver = {
 static int __init i915_init(void)
 {
bool use_kms = true;
+   int ret;
+
+   ret = i915_selftest();
+   if (ret)
+   return ret;
 
/*
 * Enable KMS by default, unless explicitly overriden by
diff --git a/drivers/gpu/drm/i915/i915_selftest.c 
b/drivers/gpu/drm/i915/i915_selftest.c
new file mode 100644
index ..2a8337dd6549
--- /dev/null
+++ b/drivers/gpu/drm/i915/i915_selftest.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright ©