No need to duplicate this all over the place.

Signed-off-by: Daniel Vetter <daniel.vet...@ffwll.ch>
---
 lib/igt_debugfs.c          | 18 ++++++++++++++++++
 lib/igt_debugfs.h          |  1 +
 tests/kms_cursor_crc.c     | 18 ++----------------
 tests/kms_fbc_crc.c        | 14 +-------------
 tests/kms_pipe_crc_basic.c | 25 ++++++++-----------------
 5 files changed, 30 insertions(+), 46 deletions(-)

diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 1ceaf59db11f..139be893f75b 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -205,6 +205,24 @@ static void pipe_crc_exit_handler(int sig)
        igt_pipe_crc_reset();
 }
 
+void igt_pipe_crc_check(igt_debugfs_t *debugfs)
+{
+       const char *cmd = "pipe A none";
+       FILE *ctl;
+       size_t written;
+       int ret;
+
+       ctl = igt_debugfs_fopen(debugfs, "i915_display_crc_ctl", "r+");
+       igt_require_f(ctl,
+                     "No display_crc_ctl found, kernel too old\n");
+       written = fwrite(cmd, 1, strlen(cmd), ctl);
+       ret = fflush(ctl);
+       igt_require_f((written == strlen(cmd) && ret == 0) || errno != ENODEV,
+                     "CRCs not supported on this platform\n");
+
+       fclose(ctl);
+}
+
 igt_pipe_crc_t *
 igt_pipe_crc_new(igt_debugfs_t *debugfs, int drm_fd, enum pipe pipe,
                 enum intel_pipe_crc_source source)
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index 40d9d28fd49b..393b5767adbe 100644
--- a/lib/igt_debugfs.h
+++ b/lib/igt_debugfs.h
@@ -70,6 +70,7 @@ bool igt_crc_is_null(igt_crc_t *crc);
 bool igt_crc_equal(igt_crc_t *a, igt_crc_t *b);
 char *igt_crc_to_string(igt_crc_t *crc);
 
+void igt_pipe_crc_check(igt_debugfs_t *debugfs);
 igt_pipe_crc_t *
 igt_pipe_crc_new(igt_debugfs_t *debugfs, int drm_fd, enum pipe pipe,
                 enum intel_pipe_crc_source source);
diff --git a/tests/kms_cursor_crc.c b/tests/kms_cursor_crc.c
index b78ea7863585..d80695f67e2f 100644
--- a/tests/kms_cursor_crc.c
+++ b/tests/kms_cursor_crc.c
@@ -53,7 +53,6 @@ typedef struct {
        int drm_fd;
        igt_debugfs_t debugfs;
        drmModeRes *resources;
-       FILE *ctl;
        uint32_t fb_id[NUM_CURSOR_TYPES];
        struct kmstest_fb fb[NUM_CURSOR_TYPES];
        igt_pipe_crc_t **pipe_crc;
@@ -333,23 +332,12 @@ igt_main
        igt_skip_on_simulation();
 
        igt_fixture {
-               size_t written;
-               int ret;
-               const char *cmd = "pipe A none";
-
                data.drm_fd = drm_open_any();
 
                igt_set_vt_graphics_mode();
 
                igt_debugfs_init(&data.debugfs);
-               data.ctl = igt_debugfs_fopen(&data.debugfs,
-                                            "i915_display_crc_ctl", "r+");
-               igt_require_f(data.ctl,
-                             "No display_crc_ctl found, kernel too old\n");
-               written = fwrite(cmd, 1, strlen(cmd), data.ctl);
-               ret = fflush(data.ctl);
-               igt_require_f((written == strlen(cmd) && ret == 0) || errno != 
ENODEV,
-                             "CRCs not supported on this platform\n");
+               igt_pipe_crc_check(&data.debugfs);
 
                display_init(&data);
 
@@ -376,8 +364,6 @@ igt_main
        igt_subtest("cursor-black-invisible-offscreen")
                run_test(&data, BLACK_INVISIBLE, false);
 
-       igt_fixture {
+       igt_fixture
                display_fini(&data);
-               fclose(data.ctl);
-       }
 }
diff --git a/tests/kms_fbc_crc.c b/tests/kms_fbc_crc.c
index 7a7f3903667b..4cddd27428d0 100644
--- a/tests/kms_fbc_crc.c
+++ b/tests/kms_fbc_crc.c
@@ -60,7 +60,6 @@ typedef struct {
        int drm_fd;
        igt_debugfs_t debugfs;
        drmModeRes *resources;
-       FILE *ctl;
        igt_crc_t ref_crc[2];
        igt_pipe_crc_t **pipe_crc;
        drm_intel_bufmgr *bufmgr;
@@ -485,9 +484,6 @@ igt_main
        igt_skip_on_simulation();
 
        igt_fixture {
-               size_t written;
-               int ret;
-               const char *cmd = "pipe A none";
                char buf[64];
                FILE *status;
 
@@ -497,14 +493,7 @@ igt_main
                data.devid = intel_get_drm_devid(data.drm_fd);
 
                igt_debugfs_init(&data.debugfs);
-               data.ctl = igt_debugfs_fopen(&data.debugfs,
-                                            "i915_display_crc_ctl", "r+");
-               igt_require_f(data.ctl,
-                             "No display_crc_ctl found, kernel too old\n");
-               written = fwrite(cmd, 1, strlen(cmd), data.ctl);
-               ret = fflush(data.ctl);
-               igt_require_f((written == strlen(cmd) && ret == 0) || errno != 
ENODEV,
-                             "CRCs not supported on this platform\n");
+               igt_pipe_crc_check(&data.debugfs);
 
                status = igt_debugfs_fopen(&data.debugfs, "i915_fbc_status", 
"r");
                igt_require_f(status, "No i915_fbc_status found\n");
@@ -532,6 +521,5 @@ igt_main
        igt_fixture {
                drm_intel_bufmgr_destroy(data.bufmgr);
                display_fini(&data);
-               fclose(data.ctl);
        }
 }
diff --git a/tests/kms_pipe_crc_basic.c b/tests/kms_pipe_crc_basic.c
index 0e793cdf617d..90d9b9404877 100644
--- a/tests/kms_pipe_crc_basic.c
+++ b/tests/kms_pipe_crc_basic.c
@@ -45,18 +45,21 @@ typedef struct {
        drmModeRes *resources;
        int n_connectors;
        connector_t *connectors;
-       FILE *ctl;
 } data_t;
 
 static void test_bad_command(data_t *data, const char *cmd)
 {
+       FILE *ctl;
        size_t written;
 
-       written = fwrite(cmd, 1, strlen(cmd), data->ctl);
-       fflush(data->ctl);
+       ctl = igt_debugfs_fopen(&data->debugfs, "i915_display_crc_ctl", "r+");
+       written = fwrite(cmd, 1, strlen(cmd), ctl);
+       fflush(ctl);
        igt_assert_cmpint(written, ==, (strlen(cmd)));
-       igt_assert(ferror(data->ctl));
+       igt_assert(ferror(ctl));
        igt_assert_cmpint(errno, ==, EINVAL);
+
+       fclose(ctl);
 }
 
 static void connector_init(data_t *data, connector_t *connector,
@@ -214,10 +217,6 @@ igt_main
        igt_skip_on_simulation();
 
        igt_fixture {
-               size_t written;
-               int ret;
-               const char *cmd = "pipe A none";
-
                data.drm_fd = drm_open_any();
 
                igt_set_vt_graphics_mode();
@@ -225,14 +224,7 @@ igt_main
                display_init(&data);
 
                igt_debugfs_init(&data.debugfs);
-               data.ctl = igt_debugfs_fopen(&data.debugfs,
-                                            "i915_display_crc_ctl", "r+");
-               igt_require_f(data.ctl,
-                             "No display_crc_ctl found, kernel too old\n");
-               written = fwrite(cmd, 1, strlen(cmd), data.ctl);
-               ret = fflush(data.ctl);
-               igt_require_f((written == strlen(cmd) && ret == 0) || errno != 
ENODEV,
-                             "CRCs not supported on this platform\n");
+               igt_pipe_crc_check(&data.debugfs);
        }
 
        igt_subtest("bad-pipe")
@@ -257,6 +249,5 @@ igt_main
 
        igt_fixture {
                display_fini(&data);
-               fclose(data.ctl);
        }
 }
-- 
1.8.4.3

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to