summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2015-06-13 22:40:40 +0000
committerngie <ngie@FreeBSD.org>2015-06-13 22:40:40 +0000
commit7e38af37a862b5aee2beeb733179329391542a9e (patch)
tree7ea934103baee7a77ae2dd920a714feb9fa3ce3e /tests
parent012598429178440158305ff4f36cf89ca8809ac7 (diff)
parent80afc77e639e2939d012ad431e45c254cbb0d9d4 (diff)
downloadFreeBSD-src-7e38af37a862b5aee2beeb733179329391542a9e.zip
FreeBSD-src-7e38af37a862b5aee2beeb733179329391542a9e.tar.gz
MF head @ r284358
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile4
-rw-r--r--tests/sys/kern/ptrace_test.c78
-rw-r--r--tests/sys/pjdfstest/pjdfstest/Makefile2
3 files changed, 54 insertions, 30 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 12c1509..7fdc5d7 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -2,8 +2,8 @@
.include <bsd.own.mk>
-SUBDIR= etc
-SUBDIR= sys
+SUBDIR+= etc
+SUBDIR+= sys
TESTSDIR= ${TESTSBASE}
KYUAFILE= yes
diff --git a/tests/sys/kern/ptrace_test.c b/tests/sys/kern/ptrace_test.c
index 321dc82..a64262a 100644
--- a/tests/sys/kern/ptrace_test.c
+++ b/tests/sys/kern/ptrace_test.c
@@ -34,11 +34,33 @@ __FBSDID("$FreeBSD$");
#include <sys/wait.h>
#include <errno.h>
#include <signal.h>
+#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <atf-c.h>
/*
+ * A variant of ATF_REQUIRE that is suitable for use in child
+ * processes. This only works if the parent process is tripped up by
+ * the early exit and fails some requirement itself.
+ */
+#define CHILD_REQUIRE(exp) do { \
+ if (!(exp)) \
+ child_fail_require(__FILE__, __LINE__, \
+ #exp " not met"); \
+ } while (0)
+
+static void __dead2
+child_fail_require(const char *file, int line, const char *str)
+{
+ char buf[128];
+
+ snprintf(buf, sizeof(buf), "%s:%d: %s\n", file, line, str);
+ write(2, buf, strlen(buf));
+ _exit(32);
+}
+
+/*
* Verify that a parent debugger process "sees" the exit of a debugged
* process exactly once when attached via PT_TRACE_ME.
*/
@@ -51,7 +73,7 @@ ATF_TC_BODY(ptrace__parent_wait_after_trace_me, tc)
ATF_REQUIRE((child = fork()) != -1);
if (child == 0) {
/* Child process. */
- ATF_REQUIRE(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
+ CHILD_REQUIRE(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
/* Trigger a stop. */
raise(SIGSTOP);
@@ -100,7 +122,7 @@ ATF_TC_BODY(ptrace__parent_wait_after_attach, tc)
close(cpipe[0]);
/* Wait for the parent to attach. */
- ATF_REQUIRE(read(cpipe[1], &c, sizeof(c)) == 0);
+ CHILD_REQUIRE(read(cpipe[1], &c, sizeof(c)) == 0);
exit(1);
}
@@ -154,7 +176,7 @@ ATF_TC_BODY(ptrace__parent_sees_exit_after_child_debugger, tc)
close(cpipe[0]);
/* Wait for parent to be ready. */
- ATF_REQUIRE(read(cpipe[1], &c, sizeof(c)) == sizeof(c));
+ CHILD_REQUIRE(read(cpipe[1], &c, sizeof(c)) == sizeof(c));
exit(1);
}
@@ -167,25 +189,25 @@ ATF_TC_BODY(ptrace__parent_sees_exit_after_child_debugger, tc)
/* Debugger process. */
close(dpipe[0]);
- ATF_REQUIRE(ptrace(PT_ATTACH, child, NULL, 0) != -1);
+ CHILD_REQUIRE(ptrace(PT_ATTACH, child, NULL, 0) != -1);
wpid = waitpid(child, &status, 0);
- ATF_REQUIRE(wpid == child);
- ATF_REQUIRE(WIFSTOPPED(status));
- ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
+ CHILD_REQUIRE(wpid == child);
+ CHILD_REQUIRE(WIFSTOPPED(status));
+ CHILD_REQUIRE(WSTOPSIG(status) == SIGSTOP);
- ATF_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
+ CHILD_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
/* Signal parent that debugger is attached. */
- ATF_REQUIRE(write(dpipe[1], &c, sizeof(c)) == sizeof(c));
+ CHILD_REQUIRE(write(dpipe[1], &c, sizeof(c)) == sizeof(c));
/* Wait for parent's failed wait. */
- ATF_REQUIRE(read(dpipe[1], &c, sizeof(c)) == 0);
+ CHILD_REQUIRE(read(dpipe[1], &c, sizeof(c)) == 0);
wpid = waitpid(child, &status, 0);
- ATF_REQUIRE(wpid == child);
- ATF_REQUIRE(WIFEXITED(status));
- ATF_REQUIRE(WEXITSTATUS(status) == 1);
+ CHILD_REQUIRE(wpid == child);
+ CHILD_REQUIRE(WIFEXITED(status));
+ CHILD_REQUIRE(WEXITSTATUS(status) == 1);
exit(0);
}
@@ -268,7 +290,7 @@ ATF_TC_BODY(ptrace__parent_sees_exit_after_unrelated_debugger, tc)
close(cpipe[0]);
/* Wait for parent to be ready. */
- ATF_REQUIRE(read(cpipe[1], &c, sizeof(c)) == sizeof(c));
+ CHILD_REQUIRE(read(cpipe[1], &c, sizeof(c)) == sizeof(c));
exit(1);
}
@@ -284,35 +306,36 @@ ATF_TC_BODY(ptrace__parent_sees_exit_after_unrelated_debugger, tc)
* Fork again and drop the debugger parent so that the
* debugger is not a child of the main parent.
*/
- ATF_REQUIRE((fpid = fork()) != -1);
+ CHILD_REQUIRE((fpid = fork()) != -1);
if (fpid != 0)
exit(2);
/* Debugger process. */
close(dpipe[0]);
- ATF_REQUIRE(ptrace(PT_ATTACH, child, NULL, 0) != -1);
+ CHILD_REQUIRE(ptrace(PT_ATTACH, child, NULL, 0) != -1);
wpid = waitpid(child, &status, 0);
- ATF_REQUIRE(wpid == child);
- ATF_REQUIRE(WIFSTOPPED(status));
- ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
+ CHILD_REQUIRE(wpid == child);
+ CHILD_REQUIRE(WIFSTOPPED(status));
+ CHILD_REQUIRE(WSTOPSIG(status) == SIGSTOP);
- ATF_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
+ CHILD_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
/* Signal parent that debugger is attached. */
- ATF_REQUIRE(write(dpipe[1], &c, sizeof(c)) == sizeof(c));
+ CHILD_REQUIRE(write(dpipe[1], &c, sizeof(c)) == sizeof(c));
/* Wait for parent's failed wait. */
- ATF_REQUIRE(read(dpipe[1], &c, sizeof(c)) == 0);
+ CHILD_REQUIRE(read(dpipe[1], &c, sizeof(c)) == sizeof(c));
wpid = waitpid(child, &status, 0);
- ATF_REQUIRE(wpid == child);
- ATF_REQUIRE(WIFEXITED(status));
- ATF_REQUIRE(WEXITSTATUS(status) == 1);
+ CHILD_REQUIRE(wpid == child);
+ CHILD_REQUIRE(WIFEXITED(status));
+ CHILD_REQUIRE(WEXITSTATUS(status) == 1);
exit(0);
}
+ close(dpipe[1]);
/* Parent process. */
@@ -365,10 +388,11 @@ ATF_TC_BODY(ptrace__parent_sees_exit_after_unrelated_debugger, tc)
ATF_REQUIRE(wpid == 0);
/* Signal the debugger to wait for the child. */
- close(dpipe[0]);
+ ATF_REQUIRE(write(dpipe[0], &c, sizeof(c)) == sizeof(c));
/* Wait for the debugger. */
- ATF_REQUIRE(read(dpipe[1], &c, sizeof(c)) == 0);
+ ATF_REQUIRE(read(dpipe[0], &c, sizeof(c)) == 0);
+ close(dpipe[0]);
/* The child process should now be ready. */
wpid = waitpid(child, &status, WNOHANG);
diff --git a/tests/sys/pjdfstest/pjdfstest/Makefile b/tests/sys/pjdfstest/pjdfstest/Makefile
index c0e82a4..29bee82 100644
--- a/tests/sys/pjdfstest/pjdfstest/Makefile
+++ b/tests/sys/pjdfstest/pjdfstest/Makefile
@@ -8,7 +8,7 @@ BINDIR= ${TESTSBASE}/sys/pjdfstest
PROG= pjdfstest
MAN=
-CFLAGS= -D__OS_FreeBSD__ -DHAS_LCHMOD -DHAS_CHFLAGS -DHAS_FCHFLAGS
+CFLAGS+= -D__OS_FreeBSD__ -DHAS_LCHMOD -DHAS_CHFLAGS -DHAS_FCHFLAGS
CFLAGS+= -DHAS_CHFLAGSAT -DHAS_LCHFLAGS -DHAS_FREEBSD_ACL -DHAS_BINDAT
CFLAGS+= -DHAS_CONNECTAT
OpenPOWER on IntegriCloud