[PATCH 09/12] tests: Update test suite to work on FreeBSD

Philip Withnall philip at tecnocode.co.uk
Fri Feb 15 04:57:12 PST 2013


 • Add missing #includes which FreeBSD needs.
 • Disable leak checking because malloc() and friends can’t be overridden.
 • Use waitpid() instead of waitid() (which doesn’t exist on FreeBSD).

Signed-off-by: Philip Withnall <philip at tecnocode.co.uk>
---
 configure.ac        |  7 +++++++
 tests/queue-test.c  |  5 +++++
 tests/test-runner.c | 44 ++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 35b89c8..a63b6b2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -56,6 +56,13 @@ AC_CHECK_HEADERS([sys/ucred.h])
 AC_CHECK_LIB([dl], [dlsym], [DL_LIBS=-ldl])
 AC_SUBST([DL_LIBS])
 
+# Defines __FreeBSD__ if we're on FreeBSD.
+AC_CHECK_HEADERS([sys/param.h])
+
+# waitid() and signal.h are needed for the test suite.
+AC_CHECK_FUNCS([waitid])
+AC_CHECK_HEADERS([signal.h])
+
 AC_ARG_ENABLE([scanner],
               [AC_HELP_STRING([--disable-scanner],
                               [Disable compilation of wayland-scanner])],
diff --git a/tests/queue-test.c b/tests/queue-test.c
index 3abb71f..c9d3668 100644
--- a/tests/queue-test.c
+++ b/tests/queue-test.c
@@ -20,6 +20,8 @@
  * OF THIS SOFTWARE.
  */
 
+#include "../config.h"
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdbool.h>
@@ -27,6 +29,9 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <assert.h>
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
 
 #include "wayland-client.h"
 #include "wayland-server.h"
diff --git a/tests/test-runner.c b/tests/test-runner.c
index 9c6865a..27e72ed 100644
--- a/tests/test-runner.c
+++ b/tests/test-runner.c
@@ -22,6 +22,12 @@
 
 #define _GNU_SOURCE
 
+#include "../config.h"
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -34,15 +40,18 @@
 #include "test-runner.h"
 
 static int num_alloc;
+int leak_check_enabled;
+
+extern const struct test __start_test_section, __stop_test_section;
+
+/* This is all disabled for FreeBSD because it gives "can't allocate initial
+ * thread" aborts otherwise. */
+#ifndef __FreeBSD__
 static void* (*sys_malloc)(size_t);
 static void (*sys_free)(void*);
 static void* (*sys_realloc)(void*, size_t);
 static void* (*sys_calloc)(size_t, size_t);
 
-int leak_check_enabled;
-
-extern const struct test __start_test_section, __stop_test_section;
-
 __attribute__ ((visibility("default"))) void *
 malloc(size_t size)
 {
@@ -76,6 +85,7 @@ calloc(size_t nmemb, size_t size)
 
 	return sys_calloc(nmemb, size);
 }
+#endif /* !__FreeBSD__ */
 
 static const struct test *
 find_test(const char *name)
@@ -127,8 +137,13 @@ int main(int argc, char *argv[])
 	const struct test *t;
 	pid_t pid;
 	int total, pass;
+#ifdef HAVE_WAITID
 	siginfo_t info;
+#else /* if HAVE_WAITPID */
+	int status;
+#endif /* HAVE_WAITPID */
 
+#ifndef __FreeBSD__
 	/* Load system malloc, free, and realloc */
 	sys_calloc = dlsym(RTLD_NEXT, "calloc");
 	sys_realloc = dlsym(RTLD_NEXT, "realloc");
@@ -136,6 +151,10 @@ int main(int argc, char *argv[])
 	sys_free = dlsym(RTLD_NEXT, "free");
 
 	leak_check_enabled = !getenv("NO_ASSERT_LEAK_CHECK");
+#else /* if !__FreeBSD__ */
+	/* Disable leak checking on FreeBSD since we can't override malloc(). */
+	leak_check_enabled = 0;
+#endif /* __FreeBSD__ */
 
 	if (argc == 2 && strcmp(argv[1], "--help") == 0)
 		usage(argv[0], EXIT_SUCCESS);
@@ -160,6 +179,7 @@ int main(int argc, char *argv[])
 		if (pid == 0)
 			run_test(t); /* never returns */
 
+#ifdef HAVE_WAITID
 		if (waitid(P_ALL, 0, &info, WEXITED)) {
 			fprintf(stderr, "waitid failed: %m\n");
 			abort();
@@ -177,6 +197,22 @@ int main(int argc, char *argv[])
 			fprintf(stderr, "signal %d", info.si_status);
 			break;
 		}
+#else /* if HAVE_WAITPID */
+		if (waitpid(-1, &status, 0) == -1) {
+			fprintf(stderr, "waitpid failed: %s\n",
+			        strerror(errno));
+			abort();
+		}
+
+		fprintf(stderr, "test \"%s\":\t", t->name);
+		if (WIFEXITED(status)) {
+			fprintf(stderr, "exit status %d", WEXITSTATUS(status));
+			if (WEXITSTATUS(status) == EXIT_SUCCESS)
+				success = 1;
+		} else if (WIFSIGNALED(status)) {
+			fprintf(stderr, "signal %d", WTERMSIG(status));
+		}
+#endif /* HAVE_WAITPID */
 
 		if (t->must_fail)
 			success = !success;
-- 
1.7.11.7

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 230 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20130215/105f8bf5/attachment-0001.pgp>


More information about the wayland-devel mailing list