From 06eafb3fccc9c2c924d796c8cab542ac2dd761c0 Mon Sep 17 00:00:00 2001 From: Steven Murdoch Date: Mon, 11 Oct 2010 23:22:52 +0100 Subject: Fix running unit tests from outside of the build directory (fixes bug #2051) Currently the unit tests test_util_spawn_background_* assume that they are run from the Tor build directory. This is not the case when running make distcheck, so the test will fail. This problem is fixed by autoconf setting BUILDDIR to be the root of the Tor build directory, and this preprocessor variable being used to specify the absolute path to test-child. Also, in test-child, do not print out argv[0] because this will no longer be predictable. Found by Sebastian Hahn. --- configure.in | 7 +++++++ src/test/test-child.c | 2 +- src/test/test_util.c | 6 +++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/configure.in b/configure.in index ae5ed207e..dddc4b8c6 100644 --- a/configure.in +++ b/configure.in @@ -931,6 +931,13 @@ if test "x$exec_prefix" = "xNONE"; then exec_prefix=$prefix fi +if test "x$BUILDDIR" = "x"; then + BUILDDIR=`pwd` +fi +AC_SUBST(BUILDDIR) +AH_TEMPLATE([BUILDDIR],[tor's build directory]) +AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR") + if test "x$CONFDIR" = "x"; then CONFDIR=`eval echo $sysconfdir/tor` fi diff --git a/src/test/test-child.c b/src/test/test-child.c index 100e8c0f3..ca52750c2 100644 --- a/src/test/test-child.c +++ b/src/test/test-child.c @@ -9,7 +9,7 @@ main(int argc, char **argv) fprintf(stdout, "OUT\n"); fprintf(stderr, "ERR\n"); - for (i = 0; i < argc; i++) + for (i = 1; i < argc; i++) fprintf(stdout, "%s\n", argv[i]); fprintf(stdout, "DONE\n"); diff --git a/src/test/test_util.c b/src/test/test_util.c index e33a6df88..c4428f5ea 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -1393,8 +1393,8 @@ run_util_spawn_background(const char *argv[], const char *expected_out, static void test_util_spawn_background_ok(void *ptr) { - const char *argv[] = {"src/test/test-child", "--test", NULL}; - const char *expected_out = "OUT\nsrc/test/test-child\n--test\nDONE\n"; + const char *argv[] = {BUILDDIR "/src/test/test-child", "--test", NULL}; + const char *expected_out = "OUT\n--test\nDONE\n"; const char *expected_err = "ERR\n"; (void)ptr; @@ -1406,7 +1406,7 @@ test_util_spawn_background_ok(void *ptr) static void test_util_spawn_background_fail(void *ptr) { - const char *argv[] = {"src/test/no-such-file", "--test", NULL}; + const char *argv[] = {BUILDDIR "/src/test/no-such-file", "--test", NULL}; const char *expected_out = "ERR: Failed to spawn background process " "- code 9/2\n"; const char *expected_err = ""; -- cgit v1.2.3