[PATCH igt v2] igt/tools_test: Check the tools exist before executing

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

 



As a simple fail-safe against a bad installation, check the tools exist
before testing whether they work.

v2: Check intel_l3_parity as well

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102935
Signed-off-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
Reviewed-by: Petri Latvala <petri.latvala@xxxxxxxxx>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@xxxxxxxxxxxxxxx>
---
 tests/tools_test.c | 48 +++++++++++++++++++++++++++++-------------------
 1 file changed, 29 insertions(+), 19 deletions(-)

diff --git a/tests/tools_test.c b/tests/tools_test.c
index 6aea7a8a4..4183456e2 100644
--- a/tests/tools_test.c
+++ b/tests/tools_test.c
@@ -26,6 +26,10 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <libgen.h>
+#include <unistd.h>
+
+#define TOOLS "../tools/"
 
 struct line_check {
 	int found;
@@ -59,10 +63,19 @@ igt_main
 {
 	igt_skip_on_simulation();
 
+	igt_fixture {
+		char path[4096];
+
+		if (readlink("/proc/self/exe", path, sizeof(path)) > 0)
+			chdir(dirname(path));
+	}
+
 	igt_subtest("sysfs_l3_parity") {
 		int exec_return;
 		struct line_check line;
 
+		igt_require(access(TOOLS "intel_l3_parity", X_OK) == 0);
+
 		/* Sanity check that l3 parity tool is usable: Enable
 		 * row,bank,subbank 0,0,0.
 		 *
@@ -71,27 +84,28 @@ igt_main
 		 * piglit.
 		 */
 		igt_system_cmd(exec_return,
-			       "../tools/intel_l3_parity -r 0 -b 0 "
+			       TOOLS "intel_l3_parity -r 0 -b 0 "
 			       "-s 0 -e");
 		assert_cmd_success(exec_return);
 
 		/* Disable row,bank,subbank 0,0,0. */
-		igt_system_cmd(exec_return, "../tools/intel_l3_parity -r 0 -b 0 "
+		igt_system_cmd(exec_return,
+			       TOOLS "intel_l3_parity -r 0 -b 0 "
 			       "-s 0 -d");
 		assert_cmd_success(exec_return);
 
 		/* Check that disabling was successful */
-		igt_system_cmd(exec_return, "../tools/intel_l3_parity -l");
+		igt_system_cmd(exec_return,
+			       TOOLS "intel_l3_parity -l");
 		assert_cmd_success(exec_return);
 		line.substr = "Row 0, Bank 0, Subbank 0 is disabled";
 		line.found = 0;
-		igt_log_buffer_inspect(check_cmd_output,
-				       &line);
+		igt_log_buffer_inspect(check_cmd_output, &line);
 		igt_assert_eq(line.found, 1);
 
 		/* Re-enable row,bank,subbank 0,0,0 */
 		igt_system_cmd(exec_return,
-			       "../tools/intel_l3_parity -r 0 -b 0 "
+			       TOOLS "intel_l3_parity -r 0 -b 0 "
 			       "-s 0 -e");
 		assert_cmd_success(exec_return);
 
@@ -102,7 +116,8 @@ igt_main
 		 * The previously printed line is already in the log
 		 * buffer so we check for count 1.
 		 */
-		igt_system_cmd(exec_return, "../tools/intel_l3_parity -l");
+		igt_system_cmd(exec_return,
+			       TOOLS "intel_l3_parity -l");
 		assert_cmd_success(exec_return);
 		line.substr = "Row 0, Bank 0, Subbank 0 is disabled";
 		line.found = 0;
@@ -112,17 +127,12 @@ igt_main
 	}
 
 	igt_subtest("tools_test") {
-		char *cmd;
-
-		igt_assert(asprintf(&cmd,
-				    "../tools/intel_reg read 0x4030")
-			   != -1);
-		igt_assert(igt_system_quiet(cmd) == IGT_EXIT_SUCCESS);
-		free(cmd);
-
-		igt_assert(asprintf(&cmd, "../tools/intel_reg dump")
-			   != -1);
-		igt_assert(igt_system_quiet(cmd) == IGT_EXIT_SUCCESS);
-		free(cmd);
+		igt_require(access(TOOLS "intel_reg", X_OK) == 0);
+
+		igt_assert_eq(igt_system_quiet(TOOLS "intel_reg read 0x4030"),
+			      IGT_EXIT_SUCCESS);
+
+		igt_assert_eq(igt_system_quiet(TOOLS "intel_reg dump"),
+			      IGT_EXIT_SUCCESS);
 	}
 }
-- 
2.15.1

_______________________________________________
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