[v4,2/5] Support running tests from different build directories

Submitted by Daniel Stone on Aug. 28, 2018, 10:19 p.m.

Details

Message ID 20180828221919.18208-2-daniels@collabora.com
State New
Series "Series without cover letter"
Headers show

Commit Message

Daniel Stone Aug. 28, 2018, 10:19 p.m.
From: Emmanuele Bassi <ebassi@gnome.org>

The tests that run exec-fd-leak-checker expect the binary to be located
in the current directory. This is not always the case; for instance, the
binaries could be built under `tests`, but be invoked under the
top-level build directory.

We can use an environment variable to control what's the location of the
test binaries, and fall back to the current directory if the variable is
unset.

Reviewed-by: Daniel Stone <daniels@collabora.com>
---
 tests/test-helpers.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/tests/test-helpers.c b/tests/test-helpers.c
index b2189d8e..20b66903 100644
--- a/tests/test-helpers.c
+++ b/tests/test-helpers.c
@@ -29,6 +29,7 @@ 
 #include <errno.h>
 #include <dirent.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <unistd.h>
 #include <time.h>
 #include <sys/time.h>
@@ -67,11 +68,19 @@  count_open_fds(void)
 void
 exec_fd_leak_check(int nr_expected_fds)
 {
-	const char *exe = "./exec-fd-leak-checker";
+	const char *exe = "exec-fd-leak-checker";
 	char number[16] = { 0 };
+	const char *test_build_dir = getenv("TEST_BUILD_DIR");
+	char exe_path[256] = { 0 };
+
+	if (test_build_dir == NULL || test_build_dir[0] == 0) {
+	        test_build_dir = ".";
+	}
+
+	snprintf(exe_path, sizeof exe_path - 1, "%s/%s", test_build_dir, exe);
 
 	snprintf(number, sizeof number - 1, "%d", nr_expected_fds);
-	execl(exe, exe, number, (char *)NULL);
+	execl(exe_path, exe, number, (char *)NULL);
 	assert(0 && "execing fd leak checker failed");
 }
 

Comments

Pekka Paalanen Aug. 29, 2018, 9:20 a.m.
On Tue, 28 Aug 2018 23:19:16 +0100
Daniel Stone <daniels@collabora.com> wrote:

> From: Emmanuele Bassi <ebassi@gnome.org>
> 
> The tests that run exec-fd-leak-checker expect the binary to be located
> in the current directory. This is not always the case; for instance, the
> binaries could be built under `tests`, but be invoked under the
> top-level build directory.

Hi,

saying Meson will need this would have been nice.

> 
> We can use an environment variable to control what's the location of the
> test binaries, and fall back to the current directory if the variable is
> unset.
> 
> Reviewed-by: Daniel Stone <daniels@collabora.com>
> ---
>  tests/test-helpers.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/test-helpers.c b/tests/test-helpers.c
> index b2189d8e..20b66903 100644
> --- a/tests/test-helpers.c
> +++ b/tests/test-helpers.c
> @@ -29,6 +29,7 @@
>  #include <errno.h>
>  #include <dirent.h>
>  #include <stdio.h>
> +#include <stdlib.h>
>  #include <unistd.h>
>  #include <time.h>
>  #include <sys/time.h>
> @@ -67,11 +68,19 @@ count_open_fds(void)
>  void
>  exec_fd_leak_check(int nr_expected_fds)
>  {
> -	const char *exe = "./exec-fd-leak-checker";
> +	const char *exe = "exec-fd-leak-checker";
>  	char number[16] = { 0 };
> +	const char *test_build_dir = getenv("TEST_BUILD_DIR");
> +	char exe_path[256] = { 0 };

256 bytes is very short for various build systems that really like long
paths
like /var/tmp/buildbuilder/packages/dev-lib/wayland/wayland-1.123/tmp/work/install-prefix/sysroot/tmp/build/...

Use PATH_MAX instead?

Otherwise looks good to me, so
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>


Thanks,
pq

> +
> +	if (test_build_dir == NULL || test_build_dir[0] == 0) {
> +	        test_build_dir = ".";
> +	}
> +
> +	snprintf(exe_path, sizeof exe_path - 1, "%s/%s", test_build_dir, exe);
>  
>  	snprintf(number, sizeof number - 1, "%d", nr_expected_fds);
> -	execl(exe, exe, number, (char *)NULL);
> +	execl(exe_path, exe, number, (char *)NULL);
>  	assert(0 && "execing fd leak checker failed");
>  }
>