[PATCH i-g-t v2] igt/drv_hangman: Fix clear_error_state

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



clear_error_state was not doing anything (igt_sysfs_set was not writing to
the error file because strlen was 0).

Also fix assert_entry to catch this issue; strcasecmp returns 0 when
there's a match, or an integer in a mismatch.

v2: Use new igt_sysfs_write, add len > 0 assert in igt_sysfs_set to
catch future errors, clean-up strcasecmp logic (Chris).

Cc: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
Fixes: 79c6a84ca85b ("igt/drv_hangman: Migrate to sysfs")
Signed-off-by: Michel Thierry <michel.thierry@xxxxxxxxx>
---
 lib/igt_sysfs.c     | 26 ++++++++++++++++++++++++++
 lib/igt_sysfs.h     |  1 +
 tests/drv_hangman.c |  4 ++--
 3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index ded10a67..d244d9b6 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -172,6 +172,31 @@ int igt_sysfs_open_parameters(int device)
 
 	return params;
 }
+
+/**
+ * igt_sysfs_write:
+ * @dir: directory for the device from igt_sysfs_open()
+ * @attr: name of the sysfs node to open
+ *
+ * This writes a single byte to the sysfs file.
+ *
+ * Returns:
+ * True on success, false on failure.
+ */
+bool igt_sysfs_write(int dir, const char *attr)
+{
+	int fd, ret;
+
+	fd = openat(dir, attr, O_WRONLY);
+	if (fd < 0)
+		return false;
+
+	ret = write(fd, "\0", 1);
+	close(fd);
+
+	return ret;
+}
+
 /**
  * igt_sysfs_set:
  * @dir: directory for the device from igt_sysfs_open()
@@ -192,6 +217,7 @@ bool igt_sysfs_set(int dir, const char *attr, const char *value)
 		return false;
 
 	len = strlen(value);
+	igt_assert(len > 0);
 	ret = writeN(fd, value, len);
 	close(fd);
 
diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
index 69b2e5ec..145a9be6 100644
--- a/lib/igt_sysfs.h
+++ b/lib/igt_sysfs.h
@@ -29,6 +29,7 @@
 
 int igt_sysfs_open(int device, int *idx);
 int igt_sysfs_open_parameters(int device);
+bool igt_sysfs_write(int dir, const char *attr);
 bool igt_sysfs_set(int dir, const char *attr, const char *value);
 char *igt_sysfs_get(int dir, const char *attr);
 
diff --git a/tests/drv_hangman.c b/tests/drv_hangman.c
index cafdf4c1..df9c763f 100644
--- a/tests/drv_hangman.c
+++ b/tests/drv_hangman.c
@@ -58,7 +58,7 @@ static void assert_entry(const char *s, bool expect)
 	error = igt_sysfs_get(sysfs, "error");
 	igt_assert(error);
 
-	igt_assert_f(strcasecmp(error, s) != expect,
+	igt_assert_f(!!strcasecmp(error, s) != expect,
 		     "contents of error: '%s' (expected %s '%s')\n",
 		     error, expect ? "": "not", s);
 
@@ -77,7 +77,7 @@ static void assert_error_state_collected(void)
 
 static void clear_error_state(void)
 {
-	igt_sysfs_set(sysfs, "error", "");
+	igt_sysfs_write(sysfs, "error");
 }
 
 static void test_error_state_basic(void)
-- 
2.11.0

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




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux