public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Subject: [PATCH 2/3] lib: add igt_pipe_crc_check
Date: Fri,  6 Dec 2013 10:48:43 +0100	[thread overview]
Message-ID: <1386323324-19196-2-git-send-email-daniel.vetter@ffwll.ch> (raw)
In-Reply-To: <1386323324-19196-1-git-send-email-daniel.vetter@ffwll.ch>

No need to duplicate this all over the place.

Signed-off-by: Daniel Vetter <daniel.vetter@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

  reply	other threads:[~2013-12-06  9:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-06  9:48 [PATCH 1/3] tests: drm_open_any doesn't fail Daniel Vetter
2013-12-06  9:48 ` Daniel Vetter [this message]
2013-12-06 12:56   ` [PATCH 2/3] lib: add igt_pipe_crc_check Damien Lespiau
2013-12-06  9:48 ` [PATCH 3/3] lib: make igt_pipe_crc_start never fail Daniel Vetter
2013-12-06 12:52   ` Damien Lespiau
2013-12-06 12:58 ` [PATCH 1/3] tests: drm_open_any doesn't fail Damien Lespiau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1386323324-19196-2-git-send-email-daniel.vetter@ffwll.ch \
    --to=daniel.vetter@ffwll.ch \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox