Skip to contentSkip to conversation

tests/tools_test: Make sure l3_parity is supported

PATCH In review Abdiel Janulgue 2 participants 3 messages Sep 13, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/tools_test: Make sure l3_parity is supported

v3: Don't pipe the output of intel_l3_parity, parse it's output
directly. (Petri)

v2: Check support before executing test.
Skip test only if intel_l3_parity tool tells us to skip. (Petri)

bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=101650

---
 tests/tools_test.c | 64 ++++++++++++++++++++++++++++++------------------------
 1 file changed, 36 insertions(+), 28 deletions(-)
tests/tools_test.c +36 -28
index 1baf60b..572d5f4 100644
@@ -27,23 +27,26 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
+struct line_check {
+	bool found;
+	const char *substr;
+};
+
 /**
- * Parse the r-value of a [cmd] string.
+ * Our igt_log_buffer_inspect handler. Checks the output of the
+ * intel_l3_parity tool and returns true if a specific substring
+ * is found.
  */
-static bool check_cmd_return_value(const char *s, void *data)
+static bool check_cmd_return_value(const char *line, void *data)
 {
-	int *val = data;
-	char *cmd, *found;
-	const char *delim = "[cmd]";
-	const int delim_len = strlen(delim);
+	struct line_check *check = data;
 
-	if (!(cmd = strstr(s, delim)))
+	if (!strstr(line, check->substr)) {
+		check->found = false;
 		return false;
+	}
 
-	found = cmd + delim_len + 1;
-	igt_assert(delim_len + strlen(found) < strlen(cmd));
-
-	*val = atoi(found);
+	check->found = true;
 	return true;
 }
 
@@ -57,37 +60,42 @@ igt_main
 		igt_system_cmd(exec_return,
 			       "../tools/intel_l3_parity -r 0 -b 0 "
 			       "-s 0 -e");
-		igt_assert(exec_return == IGT_EXIT_SUCCESS);
+		igt_skip_on_f(exec_return == IGT_EXIT_SKIP,
+			      "intel_l3_parity not supported\n");
+		igt_assert_eq(exec_return, IGT_EXIT_SUCCESS);
 
-		igt_system_cmd(exec_return,
-			       "../tools/intel_l3_parity -l | "
-			       "grep -c 'Row 0, Bank 0, Subbank 0 "
-			       "is disabled'");
+		igt_system_cmd(exec_return, "../tools/intel_l3_parity -l");
 		if (exec_return == IGT_EXIT_SUCCESS) {
-			int val = -1;
+			struct line_check line;
+			line.substr = "Row 0, Bank 0, Subbank 0 is disabled";
 			igt_log_buffer_inspect(check_cmd_return_value,
-					       &val);
-			igt_assert(val == 1);
-		} else {
-			igt_fail(IGT_EXIT_FAILURE);
+					       &line);
+			igt_assert_eq(line.found, true);
 		}
 
 		igt_system_cmd(exec_return,
 			       "../tools/intel_l3_parity -r 0 -b 0 "
 			       "-s 0 -e");
-		igt_assert(exec_return == IGT_EXIT_SUCCESS);
+		igt_skip_on_f(exec_return == IGT_EXIT_SKIP,
+			      "intel_l3_parity not supported\n");
+		igt_assert_eq(exec_return, IGT_EXIT_SUCCESS);
 
-		/* Check that we can clear remaps */
+		/* Check that we can clear remaps:
+		 * In the original shell script, the output of intel_l3_parity -l
+		 * was piped thru wc -l to check if the tool would at least
+		 * return a line. Just watch for one of the expected output
+		 * string as an alternative.
+		 * ("is disabled" unique only to intel_l3_parity.c:dumpit())
+		 */
 		igt_system_cmd(exec_return,
 			       "../tools/intel_l3_parity -l | "
 			       "wc -l");
 		if (exec_return == IGT_EXIT_SUCCESS) {
-			int val = -1;
+			struct line_check line;
+			line.substr = "is disabled";
 			igt_log_buffer_inspect(check_cmd_return_value,
-					       &val);
-			igt_assert(val == 1);
-		} else {
-			igt_fail(IGT_EXIT_FAILURE);
+					       &line);
+			igt_assert_eq(line.found, true);
 		}
 	}
 
Signature · 6 lines
2.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Abdiel Janulgue

v3: Don't pipe the output of intel_l3_parity, parse it's output
directly. (Petri)

v2: Check support before executing test.
Skip test only if intel_l3_parity tool tells us to skip. (Petri)

bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=101650

---
 tests/tools_test.c | 64 ++++++++++++++++++++++++++++++------------------------
 1 file changed, 36 insertions(+), 28 deletions(-)
tests/tools_test.c +0 -0
index 1baf60b..572d5f4 100644
@@ -27,23 +27,26 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 

tests/tools_test.c line 38

Quoted 10 lines
tests/tools_test.c +8 -1
+struct line_check {
+	bool found;
+	const char *substr;
+};
+
 /**
- * Parse the r-value of a [cmd] string.
+ * Our igt_log_buffer_inspect handler. Checks the output of the
+ * intel_l3_parity tool and returns true if a specific substring
+ * is found.

The return value is for the log_buffer_inspect interface, isn't it? This rather sets line_check::found to true.

Quoted 55 lines
tests/tools_test.c +14 -21
  */
-static bool check_cmd_return_value(const char *s, void *data)
+static bool check_cmd_return_value(const char *line, void *data)
 {
-	int *val = data;
-	char *cmd, *found;
-	const char *delim = "[cmd]";
-	const int delim_len = strlen(delim);
+	struct line_check *check = data;
 
-	if (!(cmd = strstr(s, delim)))
+	if (!strstr(line, check->substr)) {
+		check->found = false;
 		return false;
+	}
 
-	found = cmd + delim_len + 1;
-	igt_assert(delim_len + strlen(found) < strlen(cmd));
-
-	*val = atoi(found);
+	check->found = true;
 	return true;
 }
 
@@ -57,37 +60,42 @@ igt_main
 		igt_system_cmd(exec_return,
 			       "../tools/intel_l3_parity -r 0 -b 0 "
 			       "-s 0 -e");
-		igt_assert(exec_return == IGT_EXIT_SUCCESS);
+		igt_skip_on_f(exec_return == IGT_EXIT_SKIP,
+			      "intel_l3_parity not supported\n");
+		igt_assert_eq(exec_return, IGT_EXIT_SUCCESS);
 
-		igt_system_cmd(exec_return,
-			       "../tools/intel_l3_parity -l | "
-			       "grep -c 'Row 0, Bank 0, Subbank 0 "
-			       "is disabled'");
+		igt_system_cmd(exec_return, "../tools/intel_l3_parity -l");
 		if (exec_return == IGT_EXIT_SUCCESS) {
-			int val = -1;
+			struct line_check line;
+			line.substr = "Row 0, Bank 0, Subbank 0 is disabled";
 			igt_log_buffer_inspect(check_cmd_return_value,
-					       &val);
-			igt_assert(val == 1);
-		} else {
-			igt_fail(IGT_EXIT_FAILURE);
+					       &line);
+			igt_assert_eq(line.found, true);
 		}
 
 		igt_system_cmd(exec_return,
 			       "../tools/intel_l3_parity -r 0 -b 0 "
 			       "-s 0 -e");
-		igt_assert(exec_return == IGT_EXIT_SUCCESS);

tests/tools_test.c igt_main · line 87

Quoted 10 lines
tests/tools_test.c +8 -1
+		igt_skip_on_f(exec_return == IGT_EXIT_SKIP,
+			      "intel_l3_parity not supported\n");
+		igt_assert_eq(exec_return, IGT_EXIT_SUCCESS);
 
-		/* Check that we can clear remaps */
+		/* Check that we can clear remaps:
+		 * In the original shell script, the output of intel_l3_parity -l
+		 * was piped thru wc -l to check if the tool would at least
+		 * return a line. Just watch for one of the expected output
+		 * string as an alternative.

This is an excellent change.

tests/tools_test.c igt_main · line 92

Quoted 5 lines
tests/tools_test.c +2 -0
+		 * ("is disabled" unique only to intel_l3_parity.c:dumpit())
+		 */
 		igt_system_cmd(exec_return,
 			       "../tools/intel_l3_parity -l | "
 			       "wc -l");

...but you still left the piping to wc -l here. :P

With those fixed, this is

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#2 lore raw
Quoted 108 lines · Petri Latvala
Quoted 21 lines · Abdiel Janulgue

v3: Don't pipe the output of intel_l3_parity, parse it's output
directly. (Petri)

v2: Check support before executing test.
Skip test only if intel_l3_parity tool tells us to skip. (Petri)

bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=101650

---
 tests/tools_test.c | 64 ++++++++++++++++++++++++++++++------------------------
 1 file changed, 36 insertions(+), 28 deletions(-)
tests/tools_test.c +0 -0
index 1baf60b..572d5f4 100644
@@ -27,23 +27,26 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 

tests/tools_test.c line 38

Quoted 10 lines
tests/tools_test.c +8 -1
+struct line_check {
+	bool found;
+	const char *substr;
+};
+
 /**
- * Parse the r-value of a [cmd] string.
+ * Our igt_log_buffer_inspect handler. Checks the output of the
+ * intel_l3_parity tool and returns true if a specific substring
+ * is found.

The return value is for the log_buffer_inspect interface, isn't it? This rather sets line_check::found to true.

Quoted 55 lines
tests/tools_test.c +14 -21
  */
-static bool check_cmd_return_value(const char *s, void *data)
+static bool check_cmd_return_value(const char *line, void *data)
 {
-	int *val = data;
-	char *cmd, *found;
-	const char *delim = "[cmd]";
-	const int delim_len = strlen(delim);
+	struct line_check *check = data;
 
-	if (!(cmd = strstr(s, delim)))
+	if (!strstr(line, check->substr)) {
+		check->found = false;
 		return false;
+	}
 
-	found = cmd + delim_len + 1;
-	igt_assert(delim_len + strlen(found) < strlen(cmd));
-
-	*val = atoi(found);
+	check->found = true;
 	return true;
 }
 
@@ -57,37 +60,42 @@ igt_main
 		igt_system_cmd(exec_return,
 			       "../tools/intel_l3_parity -r 0 -b 0 "
 			       "-s 0 -e");
-		igt_assert(exec_return == IGT_EXIT_SUCCESS);
+		igt_skip_on_f(exec_return == IGT_EXIT_SKIP,
+			      "intel_l3_parity not supported\n");
+		igt_assert_eq(exec_return, IGT_EXIT_SUCCESS);
 
-		igt_system_cmd(exec_return,
-			       "../tools/intel_l3_parity -l | "
-			       "grep -c 'Row 0, Bank 0, Subbank 0 "
-			       "is disabled'");
+		igt_system_cmd(exec_return, "../tools/intel_l3_parity -l");
 		if (exec_return == IGT_EXIT_SUCCESS) {
-			int val = -1;
+			struct line_check line;
+			line.substr = "Row 0, Bank 0, Subbank 0 is disabled";
 			igt_log_buffer_inspect(check_cmd_return_value,
-					       &val);
-			igt_assert(val == 1);
-		} else {
-			igt_fail(IGT_EXIT_FAILURE);
+					       &line);
+			igt_assert_eq(line.found, true);
 		}
 
 		igt_system_cmd(exec_return,
 			       "../tools/intel_l3_parity -r 0 -b 0 "
 			       "-s 0 -e");
-		igt_assert(exec_return == IGT_EXIT_SUCCESS);

tests/tools_test.c igt_main · line 87

Quoted 10 lines
tests/tools_test.c +8 -1
+		igt_skip_on_f(exec_return == IGT_EXIT_SKIP,
+			      "intel_l3_parity not supported\n");
+		igt_assert_eq(exec_return, IGT_EXIT_SUCCESS);
 
-		/* Check that we can clear remaps */
+		/* Check that we can clear remaps:
+		 * In the original shell script, the output of intel_l3_parity -l
+		 * was piped thru wc -l to check if the tool would at least
+		 * return a line. Just watch for one of the expected output
+		 * string as an alternative.

This is an excellent change.

Quoted 8 lines

tests/tools_test.c igt_main · line 92

Quoted 5 lines
tests/tools_test.c +2 -0
+		 * ("is disabled" unique only to intel_l3_parity.c:dumpit())
+		 */
 		igt_system_cmd(exec_return,
 			       "../tools/intel_l3_parity -l | "
 			       "wc -l");

...but you still left the piping to wc -l here. :P

Oops. Fix coming, thanks for the review!

Quoted 7 lines

With those fixed, this is

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx