test_sw_sendto.o test_sw_recvfrom.o \
test_sw_sendmsg.o test_sw_recvmsg.o \
test_sw_setsockopt.o test_sw_getsockopt.o \
- test_sw_close.o test_dummy.o
+ test_sw_close.o test_dummy.o test_common.o \
../swift_raw.o ../swift_list.o
clean:
#include <stdio.h>
#include <string.h>
+/* Test function type. */
+typedef void (*test_fn)(void);
+
+/* Run test function f in another process. */
+void run_as_child_process(test_fn f);
+
/*
* uncommend EXIT_IF_FAIL macro in order to stop test execution
* at first failed test
--- /dev/null
+/*
+ * Test suite functions.
+ *
+ * 2011, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+#include "util.h"
+#include "test.h"
+
+/* Run test function f in another process. */
+void run_as_child_process(test_fn f)
+{
+ pid_t pid;
+ int status;
+ int rc;
+
+ pid = fork();
+ switch (pid) {
+ case -1: /* error */
+ ERR("fork");
+ exit(EXIT_FAILURE);
+
+ case 0: /* child process */
+ /* Run test function. */
+ f();
+ exit(EXIT_SUCCESS);
+ break;
+
+ default: /* parent process */
+ break;
+ }
+
+ /* Wait for child process. */
+ rc = waitpid(pid, &status, 0);
+ DIE(rc < 0, "waitpid");
+}