Re: [Intel-gfx] [PATCH 1/2] tests/kms_sink_crc_basic: Basic test to verify Sink CRC debugfs.

2014-05-16 Thread Daniel Vetter
On Thu, May 15, 2014 at 08:13:57PM -0400, Rodrigo Vivi wrote:
 v2: rebase after a long time.
 
 Signed-off-by: Rodrigo Vivi rodrigo.v...@gmail.com

Oh dear, the basic test was completely lost when we've merged the sink_crc
debugfs support :( Applied now, thanks for the patch.

One comment below.

 ---
  tests/Android.mk   |   1 +
  tests/Makefile.sources |   1 +
  tests/kms_sink_crc_basic.c | 201 
 +
  3 files changed, 203 insertions(+)
  create mode 100644 tests/kms_sink_crc_basic.c
 
 diff --git a/tests/Android.mk b/tests/Android.mk
 index 1cda9a5..b7bf51e 100644
 --- a/tests/Android.mk
 +++ b/tests/Android.mk
 @@ -66,6 +66,7 @@ else
  kms_pipe_crc_basic \
  kms_fbc_crc \
  kms_setmode \
 +kms_sink_crc_basic \
  gem_render_copy \
  pm_lpsp \
  kms_fence_pin_leak
 diff --git a/tests/Makefile.sources b/tests/Makefile.sources
 index 4bdef36..c3d8720 100644
 --- a/tests/Makefile.sources
 +++ b/tests/Makefile.sources
 @@ -68,6 +68,7 @@ TESTS_progs_M = \
   kms_plane \
   kms_render \
   kms_setmode \
 + kms_sink_crc_basic \
   pm_lpsp \
   pm_pc8 \
   pm_rps \
 diff --git a/tests/kms_sink_crc_basic.c b/tests/kms_sink_crc_basic.c
 new file mode 100644
 index 000..924aada
 --- /dev/null
 +++ b/tests/kms_sink_crc_basic.c
 @@ -0,0 +1,201 @@
 +/*
 + * Copyright © 2013 Intel Corporation
 + *
 + * Permission is hereby granted, free of charge, to any person obtaining a
 + * copy of this software and associated documentation files (the Software),
 + * to deal in the Software without restriction, including without limitation
 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 + * and/or sell copies of the Software, and to permit persons to whom the
 + * Software is furnished to do so, subject to the following conditions:
 + *
 + * The above copyright notice and this permission notice (including the next
 + * paragraph) shall be included in all copies or substantial portions of the
 + * Software.
 + *
 + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 DEALINGS
 + * IN THE SOFTWARE.
 + *
 + */
 +
 +#include errno.h
 +#include limits.h
 +#include stdbool.h
 +#include stdio.h
 +#include string.h
 +
 +#include drm_fourcc.h
 +
 +#include drmtest.h
 +#include igt_debugfs.h
 +#include igt_kms.h
 +
 +enum color {
 + WHITE,
 + BLACK,
 + NUM_COLORS,
 +};
 +
 +typedef struct {
 + struct kmstest_connector_config config;
 + struct igt_fb fb;
 +} connector_t;
 +
 +typedef struct {
 + int drm_fd;
 + drmModeRes *resources;
 +} data_t;
 +
 +static void get_crc(char *crc) {
 + int ret;
 + FILE *file = fopen(/sys/kernel/debug/dri/0/i915_sink_crc_eDP1, r);
 + igt_require(file);
 +
 + ret = fscanf(file, %s\n, crc);
 + igt_require(ret  0);
 +
 + fclose(file);
 +}
 +
 +static uint32_t create_fb(data_t *data,
 +   int w, int h,
 +   double r, double g, double b,
 +   struct igt_fb *fb)
 +{
 + cairo_t *cr;
 + uint32_t fb_id;
 +
 + fb_id = igt_create_fb(data-drm_fd, w, h,
 +   DRM_FORMAT_XRGB, false, fb);
 + igt_assert(fb_id);
 +
 + cr = igt_get_cairo_ctx(data-drm_fd, fb);
 + igt_paint_color(cr, 0, 0, w, h, r, g, b);
 + igt_assert(cairo_status(cr) == 0);
 +
 + return fb_id;
 +}
 +
 +static bool
 +connector_set_mode(data_t *data, connector_t *connector, drmModeModeInfo 
 *mode,
 +enum color crtc_color)
 +{
 + struct kmstest_connector_config *config = connector-config;
 + unsigned int fb_id;
 + int ret;
 +
 + if (crtc_color == WHITE)
 + fb_id = create_fb(data, mode-hdisplay, mode-vdisplay,
 +   1.0, 1.0, 1.0, connector-fb);
 + else
 + fb_id = create_fb(data, mode-hdisplay, mode-vdisplay,
 +   0.0, 0.0, 0.0, connector-fb);
 + igt_assert(fb_id);
 +
 + ret = drmModeSetCrtc(data-drm_fd,
 +  config-crtc-crtc_id,
 +  connector-fb.fb_id,
 +  0, 0, /* x, y */
 +  config-connector-connector_id,
 +  1,
 +  mode);
 + igt_assert(ret == 0);
 +
 + return 0;
 +}
 +
 +static void basic_sink_crc_check(data_t *data, uint32_t connector_id)
 +{
 + connector_t connector;
 + int ret;
 + char ref_crc_white[12];
 + char ref_crc_black[12];
 + char crc_check[12];
 +

[Intel-gfx] [PATCH 1/2] tests/kms_sink_crc_basic: Basic test to verify Sink CRC debugfs.

2014-05-15 Thread Rodrigo Vivi
v2: rebase after a long time.

Signed-off-by: Rodrigo Vivi rodrigo.v...@gmail.com
---
 tests/Android.mk   |   1 +
 tests/Makefile.sources |   1 +
 tests/kms_sink_crc_basic.c | 201 +
 3 files changed, 203 insertions(+)
 create mode 100644 tests/kms_sink_crc_basic.c

diff --git a/tests/Android.mk b/tests/Android.mk
index 1cda9a5..b7bf51e 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -66,6 +66,7 @@ else
 kms_pipe_crc_basic \
 kms_fbc_crc \
 kms_setmode \
+kms_sink_crc_basic \
 gem_render_copy \
 pm_lpsp \
 kms_fence_pin_leak
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 4bdef36..c3d8720 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -68,6 +68,7 @@ TESTS_progs_M = \
kms_plane \
kms_render \
kms_setmode \
+   kms_sink_crc_basic \
pm_lpsp \
pm_pc8 \
pm_rps \
diff --git a/tests/kms_sink_crc_basic.c b/tests/kms_sink_crc_basic.c
new file mode 100644
index 000..924aada
--- /dev/null
+++ b/tests/kms_sink_crc_basic.c
@@ -0,0 +1,201 @@
+/*
+ * Copyright © 2013 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the Software),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#include errno.h
+#include limits.h
+#include stdbool.h
+#include stdio.h
+#include string.h
+
+#include drm_fourcc.h
+
+#include drmtest.h
+#include igt_debugfs.h
+#include igt_kms.h
+
+enum color {
+   WHITE,
+   BLACK,
+   NUM_COLORS,
+};
+
+typedef struct {
+   struct kmstest_connector_config config;
+   struct igt_fb fb;
+} connector_t;
+
+typedef struct {
+   int drm_fd;
+   drmModeRes *resources;
+} data_t;
+
+static void get_crc(char *crc) {
+   int ret;
+   FILE *file = fopen(/sys/kernel/debug/dri/0/i915_sink_crc_eDP1, r);
+   igt_require(file);
+
+   ret = fscanf(file, %s\n, crc);
+   igt_require(ret  0);
+
+   fclose(file);
+}
+
+static uint32_t create_fb(data_t *data,
+ int w, int h,
+ double r, double g, double b,
+ struct igt_fb *fb)
+{
+   cairo_t *cr;
+   uint32_t fb_id;
+
+   fb_id = igt_create_fb(data-drm_fd, w, h,
+ DRM_FORMAT_XRGB, false, fb);
+   igt_assert(fb_id);
+
+   cr = igt_get_cairo_ctx(data-drm_fd, fb);
+   igt_paint_color(cr, 0, 0, w, h, r, g, b);
+   igt_assert(cairo_status(cr) == 0);
+
+   return fb_id;
+}
+
+static bool
+connector_set_mode(data_t *data, connector_t *connector, drmModeModeInfo *mode,
+  enum color crtc_color)
+{
+   struct kmstest_connector_config *config = connector-config;
+   unsigned int fb_id;
+   int ret;
+
+   if (crtc_color == WHITE)
+   fb_id = create_fb(data, mode-hdisplay, mode-vdisplay,
+ 1.0, 1.0, 1.0, connector-fb);
+   else
+   fb_id = create_fb(data, mode-hdisplay, mode-vdisplay,
+ 0.0, 0.0, 0.0, connector-fb);
+   igt_assert(fb_id);
+
+   ret = drmModeSetCrtc(data-drm_fd,
+config-crtc-crtc_id,
+connector-fb.fb_id,
+0, 0, /* x, y */
+config-connector-connector_id,
+1,
+mode);
+   igt_assert(ret == 0);
+
+   return 0;
+}
+
+static void basic_sink_crc_check(data_t *data, uint32_t connector_id)
+{
+   connector_t connector;
+   int ret;
+   char ref_crc_white[12];
+   char ref_crc_black[12];
+   char crc_check[12];
+
+   ret = kmstest_get_connector_config(data-drm_fd,
+  connector_id,
+  1  0,
+  connector.config);
+   igt_require(ret == 0);
+
+