[Intel-gfx] [PATCH] tests/gem_seqno_wrap: skip if debugfs entry is not there

Mika Kuoppala mika.kuoppala at linux.intel.com
Tue Jan 8 12:16:06 CET 2013


Return error code 77 to skip test if debugfs entry is not
available.

Signed-off-by: Mika Kuoppala <mika.kuoppala at intel.com>
---
 tests/gem_seqno_wrap.c |   43 +++++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/tests/gem_seqno_wrap.c b/tests/gem_seqno_wrap.c
index 76a1723..43e3851 100644
--- a/tests/gem_seqno_wrap.c
+++ b/tests/gem_seqno_wrap.c
@@ -49,6 +49,7 @@
 #include "rendercopy.h"
 
 static int devid;
+static int card_index = 0;
 static uint32_t last_seqno = 0;
 
 static struct intel_batchbuffer *batch_blt;
@@ -355,7 +356,27 @@ static int run_cmd(char *s)
 	return r;
 }
 
-static const char *debug_fs_entry = "/sys/kernel/debug/dri/0/i915_next_seqno";
+static const char *dfs_base = "/sys/kernel/debug/dri";
+static const char *dfs_entry = "i915_next_seqno";
+
+static int dfs_open(int mode)
+{
+	char fname[FILENAME_MAX];
+	int fh;
+
+	snprintf(fname, FILENAME_MAX, "%s/%i/%s",
+		 dfs_base, card_index, dfs_entry);
+
+	fh = open(fname, mode);
+	if (fh == -1) {
+		fprintf(stderr,
+			"error %d opening '%s/%d/%s'. too old kernel?\n",
+			errno, dfs_base, card_index, dfs_entry);
+		exit(77);
+	}
+
+	return fh;
+}
 
 static int __read_seqno(uint32_t *seqno)
 {
@@ -365,12 +386,7 @@ static int __read_seqno(uint32_t *seqno)
 	char *p;
 	unsigned long int tmp;
 
-	fh = open(debug_fs_entry, O_RDWR);
-	if (fh == -1) {
-		perror("open");
-		fprintf(stderr, "no %s found, too old kernel?\n", debug_fs_entry);
-		return -errno;
-	}
+	fh = dfs_open(O_RDONLY);
 
 	r = read(fh, buf, sizeof(buf) - 1);
 	close(fh);
@@ -385,8 +401,9 @@ static int __read_seqno(uint32_t *seqno)
 	if (!p)
 		p = buf;
 
+	errno = 0;
 	tmp = strtoul(p, NULL, 0);
-	if (tmp == ULONG_MAX) {
+	if (tmp == ULONG_MAX && errno) {
 		perror("strtoul");
 		return -errno;
 	}
@@ -425,12 +442,7 @@ static int write_seqno(uint32_t seqno)
 	if (options.dontwrap)
 		return 0;
 
-	fh = open(debug_fs_entry, O_RDWR);
-	if (fh == -1) {
-		perror("open");
-		return -errno;
-	}
-
+	fh = dfs_open(O_RDWR);
 	assert(snprintf(buf, sizeof(buf), "0x%x", seqno) > 0);
 
 	r = write(fh, buf, strnlen(buf, sizeof(buf)));
@@ -627,6 +639,9 @@ int main(int argc, char **argv)
 
 	parse_options(argc, argv);
 
+	card_index = drm_get_card(0);
+	assert(card_index != -1);
+
 	srandom(time(NULL));
 
 	while(options.rounds == 0 || wcount < options.rounds) {
-- 
1.7.9.5




More information about the Intel-gfx mailing list