[igt-dev] [PATCH i-g-t 1/1] tests/tools_test: Find the tool binaries also from bindir

Petri Latvala petri.latvala at intel.com
Mon Oct 8 12:10:42 UTC 2018


Also print what directory gets used.

Signed-off-by: Petri Latvala <petri.latvala at intel.com>
---
 tests/tools_test.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/tests/tools_test.c b/tests/tools_test.c
index a0025bed..ac8717c5 100644
--- a/tests/tools_test.c
+++ b/tests/tools_test.c
@@ -59,20 +59,33 @@ static void assert_cmd_success(int exec_return)
 	igt_assert_eq(exec_return, IGT_EXIT_SUCCESS);
 }
 
+bool chdir_to_tools_dir()
+{
+	char path[4096];
+
+	/* Try TOOLS relative to cwd */
+	if (chdir(TOOLS) == 0)
+		return true;
+
+	/* Try TOOLS and install dir relative to test binary */
+	if (readlink("/proc/self/exe", path, sizeof(path)) > 0)
+		chdir(dirname(path));
+
+	return chdir(TOOLS) == 0 || chdir("../../bin") == 0;
+}
+
 igt_main
 {
 	igt_skip_on_simulation();
 
 	igt_fixture {
-		char path[4096];
-
-		/* Try to guess where the TOOLS are! */
-		if (access(TOOLS, F_OK) &&
-		    readlink("/proc/self/exe", path, sizeof(path)) > 0)
-			chdir(dirname(path));
+		char *path;
 
-		igt_require_f(chdir(TOOLS) == 0,
+		igt_require_f(chdir_to_tools_dir(),
 			      "Unable to determine the tools directory, expecting them in $cwd/" TOOLS " or $path/" TOOLS "\n");
+		path = get_current_dir_name();
+		igt_info("Using tools from %s\n", path);
+		free(path);
 	}
 
 	igt_subtest("sysfs_l3_parity") {
-- 
2.18.0



More information about the igt-dev mailing list