Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/kernel/kqueue/t_proc2.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/kernel/kqueue/t_proc2.c (revision 312242) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/kernel/kqueue/t_proc2.c (revision 312243) @@ -1,142 +1,139 @@ /* $NetBSD: t_proc2.c,v 1.3 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Peter Werner . * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); __RCSID("$NetBSD: t_proc2.c,v 1.3 2017/01/13 21:30:41 christos Exp $"); -#ifdef __FreeBSD__ -#include /* for kqueue(2) */ -#endif #include #include #include #include #include #include #include #include #include #include #include "h_macros.h" static void child_two(void) { _exit(EXIT_SUCCESS); } static void child_one(void) { pid_t pid; struct passwd *pwd; const char *nam = "nobody"; pwd = getpwnam(nam); if (pwd == NULL) err(EXIT_FAILURE, "getpwnam(\"%s\")", nam); if ((setuid(pwd->pw_uid)) == -1) err(EXIT_FAILURE, "setuid(%d)", pwd->pw_uid); pid = fork(); if (pid == -1) err(EXIT_FAILURE, "fork()"); if (pid == 0) child_two(); _exit(EXIT_SUCCESS); } ATF_TC(proc2); ATF_TC_HEAD(proc2, tc) { atf_tc_set_md_var(tc, "require.user", "root"); atf_tc_set_md_var(tc, "descr", "Checks EVFILT_PROC for NOTE_FORK|NOTE_TRACK error path problem " "fixed in rev. 1.1.1.1.2.17 of sys/kern/kern_event.c"); } ATF_TC_BODY(proc2, tc) { pid_t pid = 0; int kq, status; struct kevent ke; struct timespec timeout; RL(kq = kqueue()); timeout.tv_sec = 0; timeout.tv_nsec = 0; RL(pid = fork()); if (pid == 0) { (void)sleep(1); /* let parent set kevent */ child_one(); /* NOTREACHED */ } EV_SET(&ke, (uintptr_t)pid, EVFILT_PROC, EV_ADD, NOTE_FORK|NOTE_TRACK, 0, 0); RL(kevent(kq, &ke, 1, NULL, 0, &timeout)); (void)sleep(2); ke.ident = 0; ke.fflags = 0; ke.flags = EV_ENABLE; RL(kevent(kq, NULL, 0, &ke, 1, &timeout)); RL(close(kq)); RL(waitpid(pid, &status, 0)); ATF_REQUIRE(WIFEXITED(status)); ATF_REQUIRE_EQ(WEXITSTATUS(status), EXIT_SUCCESS); /* * we are expecting an error here as we should not have * been able to add a knote to child 2. */ ATF_REQUIRE(ke.fflags & NOTE_TRACKERR); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, proc2); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/kernel/kqueue/t_proc3.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/kernel/kqueue/t_proc3.c (revision 312242) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/kernel/kqueue/t_proc3.c (revision 312243) @@ -1,102 +1,99 @@ /* $NetBSD: t_proc3.c,v 1.3 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Joerg Sonnenberger. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __RCSID("$NetBSD: t_proc3.c,v 1.3 2017/01/13 21:30:41 christos Exp $"); -#ifdef __FreeBSD__ -#include /* for kqueue(2) */ -#endif #include #include #include #include #include #include #include #include #include #include #include "h_macros.h" ATF_TC(proc3); ATF_TC_HEAD(proc3, tc) { atf_tc_set_md_var(tc, "descr", "Checks EVFILT_PROC for NOTE_TRACK on self bug "); } ATF_TC_BODY(proc3, tc) { pid_t pid = 0; int kq, status; struct kevent ke; struct timespec timeout; RL(kq = kqueue()); EV_SET(&ke, (uintptr_t)getpid(), EVFILT_PROC, EV_ADD, NOTE_TRACK, 0, 0); RL(kevent(kq, &ke, 1, NULL, 0, NULL)); RL(pid = fork()); if (pid == 0) { _exit(EXIT_SUCCESS); /* NOTREACHED */ } RL(waitpid(pid, &status, 0)); ATF_REQUIRE(WIFEXITED(status)); ATF_REQUIRE_EQ(WEXITSTATUS(status), EXIT_SUCCESS); timeout.tv_sec = 0; timeout.tv_nsec = 0; ke.ident = 0; ke.fflags = 0; ke.flags = EV_ENABLE; RL(kevent(kq, NULL, 0, &ke, 1, &timeout)); RL(close(kq)); ATF_REQUIRE(ke.fflags & NOTE_CHILD); ATF_REQUIRE((ke.fflags & NOTE_TRACKERR) == 0); ATF_REQUIRE_EQ((pid_t)ke.ident, pid); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, proc3); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/kernel/kqueue/t_sig.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/kernel/kqueue/t_sig.c (revision 312242) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/kernel/kqueue/t_sig.c (revision 312243) @@ -1,150 +1,147 @@ /* $NetBSD: t_sig.c,v 1.3 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Luke Mewburn and Jaromir Dolecek. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); __RCSID("$NetBSD: t_sig.c,v 1.3 2017/01/13 21:30:41 christos Exp $"); -#ifdef __FreeBSD__ -#include /* for kqueue(2) */ -#endif #include #include #include #include #include #include #include #include #include #include #include #include "h_macros.h" #define NSIGNALS 5 ATF_TC(sig); ATF_TC_HEAD(sig, tc) { atf_tc_set_md_var(tc, "descr", "Checks EVFILT_SIGNAL"); } ATF_TC_BODY(sig, tc) { struct timespec timeout; #ifdef __NetBSD__ struct kfilter_mapping km; #endif struct kevent event[1]; #ifdef __NetBSD__ char namebuf[32]; #endif pid_t pid, child; int kq, n, num, status; pid = getpid(); (void)printf("my pid: %d\n", pid); /* fork a child to send signals */ RL(child = fork()); if (child == 0) { int i; (void)sleep(2); for(i = 0; i < NSIGNALS; ++i) { (void)kill(pid, SIGUSR1); (void)sleep(2); } _exit(0); /* NOTREACHED */ } RL(kq = kqueue()); #ifdef __NetBSD__ (void)strlcpy(namebuf, "EVFILT_SIGNAL", sizeof(namebuf)); km.name = namebuf; RL(ioctl(kq, KFILTER_BYNAME, &km)); (void)printf("got %d as filter number for `%s'.\n", km.filter, km.name); #endif /* ignore the signal to avoid taking it for real */ REQUIRE_LIBC(signal(SIGUSR1, SIG_IGN), SIG_ERR); event[0].ident = SIGUSR1; #ifdef __NetBSD__ event[0].filter = km.filter; #else event[0].filter = EVFILT_SIGNAL; #endif event[0].flags = EV_ADD | EV_ENABLE; RL(kevent(kq, event, 1, NULL, 0, NULL)); (void)sleep(1); timeout.tv_sec = 1; timeout.tv_nsec = 0; for (num = 0; num < NSIGNALS; num += n) { struct timeval then, now, diff; RL(gettimeofday(&then, NULL)); RL(n = kevent(kq, NULL, 0, event, 1, &timeout)); RL(gettimeofday(&now, NULL)); timersub(&now, &then, &diff); (void)printf("sig: kevent returned %d in %lld.%06ld\n", n, (long long)diff.tv_sec, (long)diff.tv_usec); if (n == 0) continue; #ifdef __FreeBSD__ (void)printf("sig: kevent flags: 0x%x, data: %" PRIdPTR " (# " #else (void)printf("sig: kevent flags: 0x%x, data: %" PRId64 " (# " #endif "times signal posted)\n", event[0].flags, event[0].data); } (void)waitpid(child, &status, 0); (void)printf("sig: finished successfully\n"); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, sig); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/kernel/kqueue/t_vnode.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/kernel/kqueue/t_vnode.c (revision 312242) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/kernel/kqueue/t_vnode.c (revision 312243) @@ -1,536 +1,533 @@ -#ifdef __FreeBSD__ -#include /* for kqueue(2) */ -#endif #include #include #include #include #include #include #include /* * Test cases for events triggered by manipulating a target directory * content. Using EVFILT_VNODE filter on the target directory descriptor. * */ static const char *dir_target = "foo"; static const char *dir_inside1 = "foo/bar1"; static const char *dir_inside2 = "foo/bar2"; static const char *dir_outside = "bar"; static const char *file_inside1 = "foo/baz1"; static const char *file_inside2 = "foo/baz2"; static const char *file_outside = "qux"; static const struct timespec ts = {0, 0}; static int kq = -1; static int target = -1; int init_target(void); int init_kqueue(void); int create_file(const char *); void cleanup(void); int init_target(void) { if (mkdir(dir_target, S_IRWXU) < 0) { return -1; } target = open(dir_target, O_RDONLY, 0); return target; } int init_kqueue(void) { struct kevent eventlist[1]; kq = kqueue(); if (kq < 0) { return -1; } EV_SET(&eventlist[0], (uintptr_t)target, EVFILT_VNODE, EV_ADD | EV_ONESHOT, NOTE_DELETE | NOTE_WRITE | NOTE_EXTEND | NOTE_ATTRIB | NOTE_LINK | NOTE_RENAME | NOTE_REVOKE, 0, 0); return kevent(kq, eventlist, 1, NULL, 0, NULL); } int create_file(const char *file) { int fd; fd = open(file, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); if (fd < 0) { return -1; } return close(fd); } void cleanup(void) { (void)unlink(file_inside1); (void)unlink(file_inside2); (void)unlink(file_outside); (void)rmdir(dir_inside1); (void)rmdir(dir_inside2); (void)rmdir(dir_outside); (void)rmdir(dir_target); (void)close(kq); (void)close(target); } ATF_TC_WITH_CLEANUP(dir_no_note_link_create_file_in); ATF_TC_HEAD(dir_no_note_link_create_file_in, tc) { atf_tc_set_md_var(tc, "descr", "This test case ensures " "that kevent(2) does not return NOTE_LINK for the directory " "'foo' if a file 'foo/baz' is created."); } ATF_TC_BODY(dir_no_note_link_create_file_in, tc) { struct kevent changelist[1]; ATF_REQUIRE(init_target() != -1); ATF_REQUIRE(init_kqueue() != -1); ATF_REQUIRE(create_file(file_inside1) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1); ATF_CHECK_EQ(changelist[0].fflags & NOTE_LINK, 0); } ATF_TC_CLEANUP(dir_no_note_link_create_file_in, tc) { cleanup(); } ATF_TC_WITH_CLEANUP(dir_no_note_link_delete_file_in); ATF_TC_HEAD(dir_no_note_link_delete_file_in, tc) { atf_tc_set_md_var(tc, "descr", "This test case ensures " "that kevent(2) does not return NOTE_LINK for the directory " "'foo' if a file 'foo/baz' is deleted."); } ATF_TC_BODY(dir_no_note_link_delete_file_in, tc) { struct kevent changelist[1]; ATF_REQUIRE(init_target() != -1); ATF_REQUIRE(create_file(file_inside1) != -1); ATF_REQUIRE(init_kqueue() != -1); ATF_REQUIRE(unlink(file_inside1) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1); ATF_CHECK_EQ(changelist[0].fflags & NOTE_LINK, 0); } ATF_TC_CLEANUP(dir_no_note_link_delete_file_in, tc) { cleanup(); } ATF_TC_WITH_CLEANUP(dir_no_note_link_mv_dir_within); ATF_TC_HEAD(dir_no_note_link_mv_dir_within, tc) { atf_tc_set_md_var(tc, "descr", "This test case ensures " "that kevent(2) does not return NOTE_LINK for the directory " "'foo' if a directory 'foo/bar' is renamed to 'foo/baz'."); } ATF_TC_BODY(dir_no_note_link_mv_dir_within, tc) { struct kevent changelist[1]; ATF_REQUIRE(init_target() != -1); ATF_REQUIRE(mkdir(dir_inside1, S_IRWXU) != -1); ATF_REQUIRE(init_kqueue() != -1); ATF_REQUIRE(rename(dir_inside1, dir_inside2) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1); ATF_CHECK_EQ(changelist[0].fflags & NOTE_LINK, 0); } ATF_TC_CLEANUP(dir_no_note_link_mv_dir_within, tc) { cleanup(); } ATF_TC_WITH_CLEANUP(dir_no_note_link_mv_file_within); ATF_TC_HEAD(dir_no_note_link_mv_file_within, tc) { atf_tc_set_md_var(tc, "descr", "This test case ensures " "that kevent(2) does not return NOTE_LINK for the directory " "'foo' if a file 'foo/baz' is renamed to 'foo/qux'."); } ATF_TC_BODY(dir_no_note_link_mv_file_within, tc) { struct kevent changelist[1]; ATF_REQUIRE(init_target() != -1); ATF_REQUIRE(create_file(file_inside1) != -1); ATF_REQUIRE(init_kqueue() != -1); ATF_REQUIRE(rename(file_inside1, file_inside2) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1); ATF_CHECK_EQ(changelist[0].fflags & NOTE_LINK, 0); } ATF_TC_CLEANUP(dir_no_note_link_mv_file_within, tc) { cleanup(); } ATF_TC_WITH_CLEANUP(dir_note_link_create_dir_in); ATF_TC_HEAD(dir_note_link_create_dir_in, tc) { atf_tc_set_md_var(tc, "descr", "This test case ensures " "that kevent(2) returns NOTE_LINK for the directory " "'foo' if a directory 'foo/bar' is created."); } ATF_TC_BODY(dir_note_link_create_dir_in, tc) { struct kevent changelist[1]; ATF_REQUIRE(init_target() != -1); ATF_REQUIRE(init_kqueue() != -1); ATF_REQUIRE(mkdir(dir_inside1, S_IRWXU) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1); ATF_CHECK_EQ(changelist[0].fflags & NOTE_LINK, NOTE_LINK); } ATF_TC_CLEANUP(dir_note_link_create_dir_in, tc) { cleanup(); } ATF_TC_WITH_CLEANUP(dir_note_link_delete_dir_in); ATF_TC_HEAD(dir_note_link_delete_dir_in, tc) { atf_tc_set_md_var(tc, "descr", "This test case ensures " "that kevent(2) returns NOTE_LINK for the directory " "'foo' if a directory 'foo/bar' is deleted."); } ATF_TC_BODY(dir_note_link_delete_dir_in, tc) { struct kevent changelist[1]; ATF_REQUIRE(init_target() != -1); ATF_REQUIRE(mkdir(dir_inside1, S_IRWXU) != -1); ATF_REQUIRE(init_kqueue() != -1); ATF_REQUIRE(rmdir(dir_inside1) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1); ATF_CHECK_EQ(changelist[0].fflags & NOTE_LINK, NOTE_LINK); } ATF_TC_CLEANUP(dir_note_link_delete_dir_in, tc) { cleanup(); } ATF_TC_WITH_CLEANUP(dir_note_link_mv_dir_in); ATF_TC_HEAD(dir_note_link_mv_dir_in, tc) { atf_tc_set_md_var(tc, "descr", "This test case ensures " "that kevent(2) returns NOTE_LINK for the directory " "'foo' if a directory 'bar' is renamed to 'foo/bar'."); } ATF_TC_BODY(dir_note_link_mv_dir_in, tc) { struct kevent changelist[1]; ATF_REQUIRE(init_target() != -1); ATF_REQUIRE(mkdir(dir_outside, S_IRWXU) != -1); ATF_REQUIRE(init_kqueue() != -1); ATF_REQUIRE(rename(dir_outside, dir_inside1) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1); ATF_CHECK_EQ(changelist[0].fflags & NOTE_LINK, NOTE_LINK); } ATF_TC_CLEANUP(dir_note_link_mv_dir_in, tc) { cleanup(); } ATF_TC_WITH_CLEANUP(dir_note_link_mv_dir_out); ATF_TC_HEAD(dir_note_link_mv_dir_out, tc) { atf_tc_set_md_var(tc, "descr", "This test case ensures " "that kevent(2) returns NOTE_LINK for the directory " "'foo' if a directory 'foo/bar' is renamed to 'bar'."); } ATF_TC_BODY(dir_note_link_mv_dir_out, tc) { struct kevent changelist[1]; ATF_REQUIRE(init_target() != -1); ATF_REQUIRE(mkdir(dir_inside1, S_IRWXU) != -1); ATF_REQUIRE(init_kqueue() != -1); ATF_REQUIRE(rename(dir_inside1, dir_outside) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1); ATF_CHECK_EQ(changelist[0].fflags & NOTE_LINK, NOTE_LINK); } ATF_TC_CLEANUP(dir_note_link_mv_dir_out, tc) { cleanup(); } ATF_TC_WITH_CLEANUP(dir_note_write_create_dir_in); ATF_TC_HEAD(dir_note_write_create_dir_in, tc) { atf_tc_set_md_var(tc, "descr", "This test case ensures " "that kevent(2) returns NOTE_WRITE for the directory " "'foo' if a directory 'foo/bar' is created."); } ATF_TC_BODY(dir_note_write_create_dir_in, tc) { struct kevent changelist[1]; ATF_REQUIRE(init_target() != -1); ATF_REQUIRE(init_kqueue() != -1); ATF_REQUIRE(mkdir(dir_inside1, S_IRWXU) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1); ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE); } ATF_TC_CLEANUP(dir_note_write_create_dir_in, tc) { cleanup(); } ATF_TC_WITH_CLEANUP(dir_note_write_create_file_in); ATF_TC_HEAD(dir_note_write_create_file_in, tc) { atf_tc_set_md_var(tc, "descr", "This test case ensures " "that kevent(2) returns NOTE_WRITE for the directory " "'foo' if a file 'foo/baz' is created."); } ATF_TC_BODY(dir_note_write_create_file_in, tc) { struct kevent changelist[1]; ATF_REQUIRE(init_target() != -1); ATF_REQUIRE(init_kqueue() != -1); ATF_REQUIRE(create_file(file_inside1) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1); ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE); } ATF_TC_CLEANUP(dir_note_write_create_file_in, tc) { cleanup(); } ATF_TC_WITH_CLEANUP(dir_note_write_delete_dir_in); ATF_TC_HEAD(dir_note_write_delete_dir_in, tc) { atf_tc_set_md_var(tc, "descr", "This test case ensures " "that kevent(2) returns NOTE_WRITE for the directory " "'foo' if a directory 'foo/bar' is deleted."); } ATF_TC_BODY(dir_note_write_delete_dir_in, tc) { struct kevent changelist[1]; ATF_REQUIRE(init_target() != -1); ATF_REQUIRE(mkdir(dir_inside1, S_IRWXU) != -1); ATF_REQUIRE(init_kqueue() != -1); ATF_REQUIRE(rmdir(dir_inside1) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1); ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE); } ATF_TC_CLEANUP(dir_note_write_delete_dir_in, tc) { cleanup(); } ATF_TC_WITH_CLEANUP(dir_note_write_delete_file_in); ATF_TC_HEAD(dir_note_write_delete_file_in, tc) { atf_tc_set_md_var(tc, "descr", "This test case ensures " "that kevent(2) returns NOTE_WRITE for the directory " "'foo' if a file 'foo/baz' is deleted."); } ATF_TC_BODY(dir_note_write_delete_file_in, tc) { struct kevent changelist[1]; ATF_REQUIRE(init_target() != -1); ATF_REQUIRE(create_file(file_inside1) != -1); ATF_REQUIRE(init_kqueue() != -1); ATF_REQUIRE(unlink(file_inside1) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1); ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE); } ATF_TC_CLEANUP(dir_note_write_delete_file_in, tc) { cleanup(); } ATF_TC_WITH_CLEANUP(dir_note_write_mv_dir_in); ATF_TC_HEAD(dir_note_write_mv_dir_in, tc) { atf_tc_set_md_var(tc, "descr", "This test case ensures " "that kevent(2) returns NOTE_WRITE for the directory " "'foo' if a directory 'bar' is renamed to 'foo/bar'."); } ATF_TC_BODY(dir_note_write_mv_dir_in, tc) { struct kevent changelist[1]; ATF_REQUIRE(init_target() != -1); ATF_REQUIRE(mkdir(dir_outside, S_IRWXU) != -1); ATF_REQUIRE(init_kqueue() != -1); ATF_REQUIRE(rename(dir_outside, dir_inside1) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1); ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE); } ATF_TC_CLEANUP(dir_note_write_mv_dir_in, tc) { cleanup(); } ATF_TC_WITH_CLEANUP(dir_note_write_mv_dir_out); ATF_TC_HEAD(dir_note_write_mv_dir_out, tc) { atf_tc_set_md_var(tc, "descr", "This test case ensures " "that kevent(2) returns NOTE_WRITE for the directory " "'foo' if a directory 'foo/bar' is renamed to 'bar'."); } ATF_TC_BODY(dir_note_write_mv_dir_out, tc) { struct kevent changelist[1]; ATF_REQUIRE(init_target() != -1); ATF_REQUIRE(mkdir(dir_inside1, S_IRWXU) != -1); ATF_REQUIRE(init_kqueue() != -1); ATF_REQUIRE(rename(dir_inside1, dir_outside) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1); ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE); } ATF_TC_CLEANUP(dir_note_write_mv_dir_out, tc) { cleanup(); } ATF_TC_WITH_CLEANUP(dir_note_write_mv_dir_within); ATF_TC_HEAD(dir_note_write_mv_dir_within, tc) { atf_tc_set_md_var(tc, "descr", "This test case ensures " "that kevent(2) returns NOTE_WRITE for the directory " "'foo' if a directory 'foo/bar' is renamed to 'foo/baz'."); } ATF_TC_BODY(dir_note_write_mv_dir_within, tc) { struct kevent changelist[1]; ATF_REQUIRE(init_target() != -1); ATF_REQUIRE(mkdir(dir_inside1, S_IRWXU) != -1); ATF_REQUIRE(init_kqueue() != -1); ATF_REQUIRE(rename(dir_inside1, dir_inside2) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1); ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE); } ATF_TC_CLEANUP(dir_note_write_mv_dir_within, tc) { cleanup(); } ATF_TC_WITH_CLEANUP(dir_note_write_mv_file_in); ATF_TC_HEAD(dir_note_write_mv_file_in, tc) { atf_tc_set_md_var(tc, "descr", "This test case ensures " "that kevent(2) returns NOTE_WRITE for the directory " "'foo' if a file 'qux' is renamed to 'foo/baz'."); } ATF_TC_BODY(dir_note_write_mv_file_in, tc) { struct kevent changelist[1]; ATF_REQUIRE(init_target() != -1); ATF_REQUIRE(create_file(file_outside) != -1); ATF_REQUIRE(init_kqueue() != -1); ATF_REQUIRE(rename(file_outside, file_inside1) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1); ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE); } ATF_TC_CLEANUP(dir_note_write_mv_file_in, tc) { cleanup(); } ATF_TC_WITH_CLEANUP(dir_note_write_mv_file_out); ATF_TC_HEAD(dir_note_write_mv_file_out, tc) { atf_tc_set_md_var(tc, "descr", "This test case ensures " "that kevent(2) returns NOTE_WRITE for the directory " "'foo' if a file 'foo/baz' is renamed to 'qux'."); } ATF_TC_BODY(dir_note_write_mv_file_out, tc) { struct kevent changelist[1]; ATF_REQUIRE(init_target() != -1); ATF_REQUIRE(create_file(file_inside1) != -1); ATF_REQUIRE(init_kqueue() != -1); ATF_REQUIRE(rename(file_inside1, file_outside) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1); ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE); } ATF_TC_CLEANUP(dir_note_write_mv_file_out, tc) { cleanup(); } ATF_TC_WITH_CLEANUP(dir_note_write_mv_file_within); ATF_TC_HEAD(dir_note_write_mv_file_within, tc) { atf_tc_set_md_var(tc, "descr", "This test case ensures " "that kevent(2) returns NOTE_WRITE for the directory " "'foo' if a file 'foo/baz' is renamed to 'foo/qux'."); } ATF_TC_BODY(dir_note_write_mv_file_within, tc) { struct kevent changelist[1]; ATF_REQUIRE(init_target() != -1); ATF_REQUIRE(create_file(file_inside1) != -1); ATF_REQUIRE(init_kqueue() != -1); ATF_REQUIRE(rename(file_inside1, file_inside2) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1); ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE); } ATF_TC_CLEANUP(dir_note_write_mv_file_within, tc) { cleanup(); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, dir_no_note_link_create_file_in); ATF_TP_ADD_TC(tp, dir_no_note_link_delete_file_in); ATF_TP_ADD_TC(tp, dir_no_note_link_mv_dir_within); ATF_TP_ADD_TC(tp, dir_no_note_link_mv_file_within); ATF_TP_ADD_TC(tp, dir_note_link_create_dir_in); ATF_TP_ADD_TC(tp, dir_note_link_delete_dir_in); ATF_TP_ADD_TC(tp, dir_note_link_mv_dir_in); ATF_TP_ADD_TC(tp, dir_note_link_mv_dir_out); ATF_TP_ADD_TC(tp, dir_note_write_create_dir_in); ATF_TP_ADD_TC(tp, dir_note_write_create_file_in); ATF_TP_ADD_TC(tp, dir_note_write_delete_dir_in); ATF_TP_ADD_TC(tp, dir_note_write_delete_file_in); ATF_TP_ADD_TC(tp, dir_note_write_mv_dir_in); ATF_TP_ADD_TC(tp, dir_note_write_mv_dir_out); ATF_TP_ADD_TC(tp, dir_note_write_mv_dir_within); ATF_TP_ADD_TC(tp, dir_note_write_mv_file_in); ATF_TP_ADD_TC(tp, dir_note_write_mv_file_out); ATF_TP_ADD_TC(tp, dir_note_write_mv_file_within); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/gen/t_sleep.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/gen/t_sleep.c (revision 312242) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/gen/t_sleep.c (revision 312243) @@ -1,352 +1,348 @@ /* $NetBSD: t_sleep.c,v 1.11 2017/01/10 15:43:59 maya Exp $ */ /*- * Copyright (c) 2006 Frank Kardel * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#ifdef __FreeBSD__ -/* kqueue(2) on FreeBSD requires sys/types.h for uintptr_t; NetBSD doesn't. */ -#include -#endif #include #include #include #include /* for TIMESPEC_TO_TIMEVAL on FreeBSD */ #include #include #include #include #include #include #include #include #include #include "isqemu.h" #define BILLION 1000000000LL /* nano-seconds per second */ #define MILLION 1000000LL /* nano-seconds per milli-second */ #define ALARM 6 /* SIGALRM after this many seconds */ #define MAXSLEEP 22 /* Maximum delay in seconds */ #define KEVNT_TIMEOUT 10300 /* measured in milli-seconds */ #define FUZZ (40 * MILLION) /* scheduling fuzz accepted - 40 ms */ /* * Timer notes * * Most tests use FUZZ as their initial delay value, but 'sleep' * starts at 1sec (since it cannot handle sub-second intervals). * Subsequent passes double the previous interval, up to MAXSLEEP. * * The current values result in 5 passes for the 'sleep' test (at 1, * 2, 4, 8, and 16 seconds) and 10 passes for the other tests (at * 0.04, 0.08, 0.16, 0.32, 0.64, 1.28, 2.56, 5.12, 10.24, and 20.48 * seconds). * * The ALARM is only set if the current pass's delay is longer, and * only if the ALARM has not already been triggered. * * The 'kevent' test needs the ALARM to be set on a different pass * from when the KEVNT_TIMEOUT fires. So set ALARM to fire on the * penultimate pass, and the KEVNT_TIMEOUT on the final pass. We * set KEVNT_TIMEOUT just barely long enough to put it into the * last test pass, and set MAXSLEEP a couple seconds longer than * necessary, in order to avoid a QEMU bug which nearly doubles * some timers. */ static volatile int sig; int sleeptest(int (*)(struct timespec *, struct timespec *), bool, bool); int do_nanosleep(struct timespec *, struct timespec *); int do_select(struct timespec *, struct timespec *); #ifdef __NetBSD__ int do_poll(struct timespec *, struct timespec *); #endif int do_sleep(struct timespec *, struct timespec *); int do_kevent(struct timespec *, struct timespec *); void sigalrm(int); void sigalrm(int s) { sig++; } int do_nanosleep(struct timespec *delay, struct timespec *remain) { int ret; if (nanosleep(delay, remain) == -1) ret = (errno == EINTR ? 0 : errno); else ret = 0; return ret; } int do_select(struct timespec *delay, struct timespec *remain) { int ret; struct timeval tv; TIMESPEC_TO_TIMEVAL(&tv, delay); if (select(0, NULL, NULL, NULL, &tv) == -1) ret = (errno == EINTR ? 0 : errno); else ret = 0; return ret; } #ifdef __NetBSD__ int do_poll(struct timespec *delay, struct timespec *remain) { int ret; struct timeval tv; TIMESPEC_TO_TIMEVAL(&tv, delay); if (pollts(NULL, 0, delay, NULL) == -1) ret = (errno == EINTR ? 0 : errno); else ret = 0; return ret; } #endif int do_sleep(struct timespec *delay, struct timespec *remain) { struct timeval tv; TIMESPEC_TO_TIMEVAL(&tv, delay); remain->tv_sec = sleep(delay->tv_sec); remain->tv_nsec = 0; return 0; } int do_kevent(struct timespec *delay, struct timespec *remain) { struct kevent ktimer; struct kevent kresult; int rtc, kq, kerrno; int tmo; ATF_REQUIRE_MSG((kq = kqueue()) != -1, "kqueue: %s", strerror(errno)); tmo = KEVNT_TIMEOUT; /* * If we expect the KEVNT_TIMEOUT to fire, and we're running * under QEMU, make sure the delay is long enough to account * for the effects of PR kern/43997 ! */ if (isQEMU() && tmo/1000 < delay->tv_sec && tmo/500 > delay->tv_sec) delay->tv_sec = MAXSLEEP; EV_SET(&ktimer, 1, EVFILT_TIMER, EV_ADD, 0, tmo, 0); rtc = kevent(kq, &ktimer, 1, &kresult, 1, delay); kerrno = errno; (void)close(kq); if (rtc == -1) { ATF_REQUIRE_MSG(kerrno == EINTR, "kevent: %s", strerror(kerrno)); return 0; } if (delay->tv_sec * BILLION + delay->tv_nsec > tmo * MILLION) ATF_REQUIRE_MSG(rtc > 0, "kevent: KEVNT_TIMEOUT did not cause EVFILT_TIMER event"); return 0; } ATF_TC(nanosleep); ATF_TC_HEAD(nanosleep, tc) { atf_tc_set_md_var(tc, "descr", "Test nanosleep(2) timing"); atf_tc_set_md_var(tc, "timeout", "65"); } ATF_TC_BODY(nanosleep, tc) { sleeptest(do_nanosleep, true, false); } ATF_TC(select); ATF_TC_HEAD(select, tc) { atf_tc_set_md_var(tc, "descr", "Test select(2) timing"); atf_tc_set_md_var(tc, "timeout", "65"); } ATF_TC_BODY(select, tc) { sleeptest(do_select, true, true); } #ifdef __NetBSD__ ATF_TC(poll); ATF_TC_HEAD(poll, tc) { atf_tc_set_md_var(tc, "descr", "Test poll(2) timing"); atf_tc_set_md_var(tc, "timeout", "65"); } ATF_TC_BODY(poll, tc) { sleeptest(do_poll, true, true); } #endif ATF_TC(sleep); ATF_TC_HEAD(sleep, tc) { atf_tc_set_md_var(tc, "descr", "Test sleep(3) timing"); atf_tc_set_md_var(tc, "timeout", "65"); } ATF_TC_BODY(sleep, tc) { sleeptest(do_sleep, false, false); } ATF_TC(kevent); ATF_TC_HEAD(kevent, tc) { atf_tc_set_md_var(tc, "descr", "Test kevent(2) timing"); atf_tc_set_md_var(tc, "timeout", "65"); } ATF_TC_BODY(kevent, tc) { sleeptest(do_kevent, true, true); } int sleeptest(int (*test)(struct timespec *, struct timespec *), bool subsec, bool sim_remain) { struct timespec tsa, tsb, tslp, tremain; int64_t delta1, delta2, delta3, round; sig = 0; signal(SIGALRM, sigalrm); if (subsec) { round = 1; delta3 = FUZZ; } else { round = 1000000000; delta3 = round; } tslp.tv_sec = delta3 / 1000000000; tslp.tv_nsec = delta3 % 1000000000; while (tslp.tv_sec <= MAXSLEEP) { /* * disturb sleep by signal on purpose */ if (tslp.tv_sec > ALARM && sig == 0) alarm(ALARM); clock_gettime(CLOCK_REALTIME, &tsa); (*test)(&tslp, &tremain); clock_gettime(CLOCK_REALTIME, &tsb); if (sim_remain) { timespecsub(&tsb, &tsa, &tremain); timespecsub(&tslp, &tremain, &tremain); } delta1 = (int64_t)tsb.tv_sec - (int64_t)tsa.tv_sec; delta1 *= BILLION; delta1 += (int64_t)tsb.tv_nsec - (int64_t)tsa.tv_nsec; delta2 = (int64_t)tremain.tv_sec * BILLION; delta2 += (int64_t)tremain.tv_nsec; delta3 = (int64_t)tslp.tv_sec * BILLION; delta3 += (int64_t)tslp.tv_nsec - delta1 - delta2; delta3 /= round; delta3 *= round; if (delta3 > FUZZ || delta3 < -FUZZ) { if (!sim_remain) atf_tc_expect_fail("Long reschedule latency " "due to PR kern/43997"); atf_tc_fail("Reschedule latency %"PRId64" exceeds " "allowable fuzz %lld", delta3, FUZZ); } delta3 = (int64_t)tslp.tv_sec * 2 * BILLION; delta3 += (int64_t)tslp.tv_nsec * 2; delta3 /= round; delta3 *= round; if (delta3 < FUZZ) break; tslp.tv_sec = delta3 / BILLION; tslp.tv_nsec = delta3 % BILLION; } ATF_REQUIRE_MSG(sig == 1, "Alarm did not fire!"); atf_tc_pass(); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, nanosleep); ATF_TP_ADD_TC(tp, select); #ifdef __NetBSD__ ATF_TP_ADD_TC(tp, poll); #endif ATF_TP_ADD_TC(tp, sleep); ATF_TP_ADD_TC(tp, kevent); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_kevent.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_kevent.c (revision 312242) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_kevent.c (revision 312243) @@ -1,200 +1,198 @@ /* $NetBSD: t_kevent.c,v 1.7 2015/02/05 13:55:37 isaki Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundatiom * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __RCSID("$NetBSD: t_kevent.c,v 1.7 2015/02/05 13:55:37 isaki Exp $"); #include #include #include #include #include #include #include #include #include #include #include #ifdef __NetBSD__ #include +#else +#define DRVCTLDEV "/nonexistent" #endif #include #include #include #include - -#ifdef __FreeBSD__ -#define DRVCTLDEV "/nonexistent" -#endif ATF_TC(kevent_zerotimer); ATF_TC_HEAD(kevent_zerotimer, tc) { atf_tc_set_md_var(tc, "descr", "Checks that kevent with a 0 timer " "does not crash the system (PR lib/45618)"); } ATF_TC_BODY(kevent_zerotimer, tc) { struct kevent ev; int kq; ATF_REQUIRE((kq = kqueue()) != -1); EV_SET(&ev, 1, EVFILT_TIMER, EV_ADD|EV_ENABLE, 0, 1, 0); ATF_REQUIRE(kevent(kq, &ev, 1, NULL, 0, NULL) != -1); ATF_REQUIRE(kevent(kq, NULL, 0, &ev, 1, NULL) == 1); } ATF_TC(kqueue_desc_passing); ATF_TC_HEAD(kqueue_desc_passing, tc) { atf_tc_set_md_var(tc, "descr", "Checks that passing a kqueue to " "another process does not crash the kernel (PR 46463)"); } ATF_TC_BODY(kqueue_desc_passing, tc) { pid_t child; int s[2], storage, status, kq; struct cmsghdr *msg; struct iovec iov; struct msghdr m; struct kevent ev; ATF_REQUIRE((kq = kqueue()) != -1); // atf_tc_skip("crashes kernel (PR 46463)"); ATF_REQUIRE(socketpair(AF_LOCAL, SOCK_STREAM, 0, s) != -1); msg = malloc(CMSG_SPACE(sizeof(int))); m.msg_iov = &iov; m.msg_iovlen = 1; m.msg_name = NULL; m.msg_namelen = 0; m.msg_control = msg; m.msg_controllen = CMSG_SPACE(sizeof(int)); #ifdef __FreeBSD__ m.msg_flags = 0; #endif child = fork(); if (child == 0) { close(s[0]); iov.iov_base = &storage; iov.iov_len = sizeof(int); m.msg_iov = &iov; m.msg_iovlen = 1; if (recvmsg(s[1], &m, 0) == -1) err(1, "child: could not recvmsg"); kq = *(int *)CMSG_DATA(msg); printf("child (pid %d): received kq fd %d\n", getpid(), kq); exit(0); } close(s[1]); iov.iov_base = &storage; iov.iov_len = sizeof(int); #ifdef __FreeBSD__ msg = CMSG_FIRSTHDR(&m); #endif msg->cmsg_level = SOL_SOCKET; msg->cmsg_type = SCM_RIGHTS; msg->cmsg_len = CMSG_LEN(sizeof(int)); #ifdef __NetBSD__ *(int *)CMSG_DATA(msg) = kq; #endif EV_SET(&ev, 1, EVFILT_TIMER, EV_ADD|EV_ENABLE, 0, 1, 0); ATF_CHECK(kevent(kq, &ev, 1, NULL, 0, NULL) != -1); printf("parent (pid %d): sending kq fd %d\n", getpid(), kq); if (sendmsg(s[0], &m, 0) == -1) { ATF_REQUIRE_EQ_MSG(errno, EBADF, "errno is %d", errno); atf_tc_skip("PR kern/46523"); } close(kq); waitpid(child, &status, 0); ATF_CHECK(WIFEXITED(status) && WEXITSTATUS(status)==0); } ATF_TC(kqueue_unsupported_fd); ATF_TC_HEAD(kqueue_unsupported_fd, tc) { atf_tc_set_md_var(tc, "descr", "Checks that watching an fd whose" " type is not supported does not crash the kernel"); } ATF_TC_BODY(kqueue_unsupported_fd, tc) { /* mqueue and semaphore use fnullop_kqueue also */ int fd, kq; struct kevent ev; fd = open(DRVCTLDEV, O_RDONLY); if (fd == -1) { switch (errno) { case ENOENT: case ENXIO: atf_tc_skip("no " DRVCTLDEV " available for testing"); break; } } ATF_REQUIRE(fd != -1); ATF_REQUIRE((kq = kqueue()) != -1); EV_SET(&ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK| NOTE_RENAME|NOTE_REVOKE, 0, 0); ATF_REQUIRE(kevent(kq, &ev, 1, NULL, 0, NULL) == -1); ATF_REQUIRE_ERRNO(EOPNOTSUPP, true); (void)close(fd); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, kevent_zerotimer); ATF_TP_ADD_TC(tp, kqueue_desc_passing); ATF_TP_ADD_TC(tp, kqueue_unsupported_fd); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_mmap.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_mmap.c (revision 312242) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_mmap.c (revision 312243) @@ -1,601 +1,599 @@ /* $NetBSD: t_mmap.c,v 1.11 2017/01/13 20:43:11 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /*- * Copyright (c)2004 YAMAMOTO Takashi, * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __RCSID("$NetBSD: t_mmap.c,v 1.11 2017/01/13 20:43:11 christos Exp $"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef __NetBSD__ #include -#endif - -#ifdef __FreeBSD__ -#include +#else #include +#include #endif static long page = 0; static char path[] = "mmap"; static void map_check(void *, int); static void map_sighandler(int); static void testloan(void *, void *, char, int); #define BUFSIZE (32 * 1024) /* enough size to trigger sosend_loan */ static void map_check(void *map, int flag) { if (flag != 0) { ATF_REQUIRE(map == MAP_FAILED); return; } ATF_REQUIRE(map != MAP_FAILED); ATF_REQUIRE(munmap(map, page) == 0); } void testloan(void *vp, void *vp2, char pat, int docheck) { char buf[BUFSIZE]; char backup[BUFSIZE]; ssize_t nwritten; ssize_t nread; int fds[2]; int val; val = BUFSIZE; if (docheck != 0) (void)memcpy(backup, vp, BUFSIZE); if (socketpair(AF_LOCAL, SOCK_STREAM, PF_UNSPEC, fds) != 0) atf_tc_fail("socketpair() failed"); val = BUFSIZE; if (setsockopt(fds[1], SOL_SOCKET, SO_RCVBUF, &val, sizeof(val)) != 0) atf_tc_fail("setsockopt() failed, SO_RCVBUF"); val = BUFSIZE; if (setsockopt(fds[0], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val)) != 0) atf_tc_fail("setsockopt() failed, SO_SNDBUF"); if (fcntl(fds[0], F_SETFL, O_NONBLOCK) != 0) atf_tc_fail("fcntl() failed"); nwritten = write(fds[0], (char *)vp + page, BUFSIZE - page); if (nwritten == -1) atf_tc_fail("write() failed"); /* Break loan. */ (void)memset(vp2, pat, BUFSIZE); nread = read(fds[1], buf + page, BUFSIZE - page); if (nread == -1) atf_tc_fail("read() failed"); if (nread != nwritten) atf_tc_fail("too short read"); if (docheck != 0 && memcmp(backup, buf + page, nread) != 0) atf_tc_fail("data mismatch"); ATF_REQUIRE(close(fds[0]) == 0); ATF_REQUIRE(close(fds[1]) == 0); } static void map_sighandler(int signo) { _exit(signo); } #ifdef __NetBSD__ ATF_TC(mmap_block); ATF_TC_HEAD(mmap_block, tc) { atf_tc_set_md_var(tc, "descr", "Test mmap(2) with a block device"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(mmap_block, tc) { static const int mib[] = { CTL_HW, HW_DISKNAMES }; static const unsigned int miblen = __arraycount(mib); char *map, *dk, *drives, dev[PATH_MAX]; size_t len; int fd = -1; atf_tc_skip("The test case causes a panic (PR kern/38889, kern/46592)"); ATF_REQUIRE(sysctl(mib, miblen, NULL, &len, NULL, 0) == 0); drives = malloc(len); ATF_REQUIRE(drives != NULL); ATF_REQUIRE(sysctl(mib, miblen, drives, &len, NULL, 0) == 0); for (dk = strtok(drives, " "); dk != NULL; dk = strtok(NULL, " ")) { sprintf(dev, _PATH_DEV "%s%c", dk, 'a'+RAW_PART); fprintf(stderr, "trying: %s\n", dev); if ((fd = open(dev, O_RDONLY)) >= 0) { (void)fprintf(stderr, "using %s\n", dev); break; } } free(drives); if (fd < 0) atf_tc_skip("failed to find suitable block device"); map = mmap(NULL, 4096, PROT_READ, MAP_FILE, fd, 0); ATF_REQUIRE(map != MAP_FAILED); (void)fprintf(stderr, "first byte %x\n", *map); ATF_REQUIRE(close(fd) == 0); (void)fprintf(stderr, "first byte %x\n", *map); ATF_REQUIRE(munmap(map, 4096) == 0); } #endif ATF_TC(mmap_err); ATF_TC_HEAD(mmap_err, tc) { atf_tc_set_md_var(tc, "descr", "Test error conditions of mmap(2)"); } ATF_TC_BODY(mmap_err, tc) { size_t addr = SIZE_MAX; void *map; errno = 0; map = mmap(NULL, 3, PROT_READ, MAP_FILE|MAP_PRIVATE, -1, 0); ATF_REQUIRE(map == MAP_FAILED); ATF_REQUIRE(errno == EBADF); errno = 0; map = mmap(&addr, page, PROT_READ, MAP_FIXED|MAP_PRIVATE, -1, 0); ATF_REQUIRE(map == MAP_FAILED); ATF_REQUIRE(errno == EINVAL); errno = 0; map = mmap(NULL, page, PROT_READ, MAP_ANON|MAP_PRIVATE, INT_MAX, 0); ATF_REQUIRE(map == MAP_FAILED); ATF_REQUIRE(errno == EINVAL); } ATF_TC_WITH_CLEANUP(mmap_loan); ATF_TC_HEAD(mmap_loan, tc) { atf_tc_set_md_var(tc, "descr", "Test uvm page loanout with mmap(2)"); } ATF_TC_BODY(mmap_loan, tc) { char buf[BUFSIZE]; char *vp, *vp2; int fd; fd = open(path, O_RDWR | O_CREAT, 0600); ATF_REQUIRE(fd >= 0); (void)memset(buf, 'x', sizeof(buf)); (void)write(fd, buf, sizeof(buf)); vp = mmap(NULL, BUFSIZE, PROT_READ | PROT_WRITE, MAP_FILE | MAP_PRIVATE, fd, 0); ATF_REQUIRE(vp != MAP_FAILED); vp2 = vp; testloan(vp, vp2, 'A', 0); testloan(vp, vp2, 'B', 1); ATF_REQUIRE(munmap(vp, BUFSIZE) == 0); vp = mmap(NULL, BUFSIZE, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0); vp2 = mmap(NULL, BUFSIZE, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0); ATF_REQUIRE(vp != MAP_FAILED); ATF_REQUIRE(vp2 != MAP_FAILED); testloan(vp, vp2, 'E', 1); ATF_REQUIRE(munmap(vp, BUFSIZE) == 0); ATF_REQUIRE(munmap(vp2, BUFSIZE) == 0); } ATF_TC_CLEANUP(mmap_loan, tc) { (void)unlink(path); } ATF_TC_WITH_CLEANUP(mmap_prot_1); ATF_TC_HEAD(mmap_prot_1, tc) { atf_tc_set_md_var(tc, "descr", "Test mmap(2) protections, #1"); } ATF_TC_BODY(mmap_prot_1, tc) { void *map; int fd; /* * Open a file write-only and try to * map it read-only. This should fail. */ fd = open(path, O_WRONLY | O_CREAT, 0700); if (fd < 0) return; ATF_REQUIRE(write(fd, "XXX", 3) == 3); map = mmap(NULL, 3, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0); map_check(map, 1); map = mmap(NULL, 3, PROT_WRITE, MAP_FILE|MAP_PRIVATE, fd, 0); map_check(map, 0); ATF_REQUIRE(close(fd) == 0); } ATF_TC_CLEANUP(mmap_prot_1, tc) { (void)unlink(path); } ATF_TC(mmap_prot_2); ATF_TC_HEAD(mmap_prot_2, tc) { atf_tc_set_md_var(tc, "descr", "Test mmap(2) protections, #2"); } ATF_TC_BODY(mmap_prot_2, tc) { char buf[2]; void *map; pid_t pid; int sta; /* * Make a PROT_NONE mapping and try to access it. * If we catch a SIGSEGV, all works as expected. */ map = mmap(NULL, page, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0); ATF_REQUIRE(map != MAP_FAILED); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { ATF_REQUIRE(signal(SIGSEGV, map_sighandler) != SIG_ERR); ATF_REQUIRE(strlcpy(buf, map, sizeof(buf)) != 0); } (void)wait(&sta); ATF_REQUIRE(WIFEXITED(sta) != 0); ATF_REQUIRE(WEXITSTATUS(sta) == SIGSEGV); ATF_REQUIRE(munmap(map, page) == 0); } ATF_TC_WITH_CLEANUP(mmap_prot_3); ATF_TC_HEAD(mmap_prot_3, tc) { atf_tc_set_md_var(tc, "descr", "Test mmap(2) protections, #3"); } ATF_TC_BODY(mmap_prot_3, tc) { char buf[2]; int fd, sta; void *map; pid_t pid; /* * Open a file, change the permissions * to read-only, and try to map it as * PROT_NONE. This should succeed, but * the access should generate SIGSEGV. */ fd = open(path, O_RDWR | O_CREAT, 0700); if (fd < 0) #ifdef __FreeBSD__ atf_tc_skip("opening %s failed; skipping testcase: %s", path, strerror(errno)); #else return; #endif ATF_REQUIRE(write(fd, "XXX", 3) == 3); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(chmod(path, 0444) == 0); fd = open(path, O_RDONLY); ATF_REQUIRE(fd != -1); map = mmap(NULL, 3, PROT_NONE, MAP_FILE | MAP_SHARED, fd, 0); ATF_REQUIRE(map != MAP_FAILED); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { ATF_REQUIRE(signal(SIGSEGV, map_sighandler) != SIG_ERR); ATF_REQUIRE(strlcpy(buf, map, sizeof(buf)) != 0); } (void)wait(&sta); ATF_REQUIRE(WIFEXITED(sta) != 0); ATF_REQUIRE(WEXITSTATUS(sta) == SIGSEGV); ATF_REQUIRE(munmap(map, 3) == 0); #ifdef __FreeBSD__ (void)close(fd); #endif } ATF_TC_CLEANUP(mmap_prot_3, tc) { (void)unlink(path); } ATF_TC_WITH_CLEANUP(mmap_truncate); ATF_TC_HEAD(mmap_truncate, tc) { atf_tc_set_md_var(tc, "descr", "Test mmap(2) and ftruncate(2)"); } ATF_TC_BODY(mmap_truncate, tc) { char *map; long i; int fd; fd = open(path, O_RDWR | O_CREAT, 0700); if (fd < 0) return; /* * See that ftruncate(2) works * while the file is mapped. */ ATF_REQUIRE(ftruncate(fd, page) == 0); map = mmap(NULL, page, PROT_READ | PROT_WRITE, MAP_FILE|MAP_PRIVATE, fd, 0); ATF_REQUIRE(map != MAP_FAILED); for (i = 0; i < page; i++) map[i] = 'x'; ATF_REQUIRE(ftruncate(fd, 0) == 0); ATF_REQUIRE(ftruncate(fd, page / 8) == 0); ATF_REQUIRE(ftruncate(fd, page / 4) == 0); ATF_REQUIRE(ftruncate(fd, page / 2) == 0); ATF_REQUIRE(ftruncate(fd, page / 12) == 0); ATF_REQUIRE(ftruncate(fd, page / 64) == 0); (void)munmap(map, page); ATF_REQUIRE(close(fd) == 0); } ATF_TC_CLEANUP(mmap_truncate, tc) { (void)unlink(path); } ATF_TC_WITH_CLEANUP(mmap_truncate_signal); ATF_TC_HEAD(mmap_truncate_signal, tc) { atf_tc_set_md_var(tc, "descr", "Test mmap(2) ftruncate(2) causing signal"); } ATF_TC_BODY(mmap_truncate_signal, tc) { char *map; long i; int fd, sta; pid_t pid; #ifdef __FreeBSD__ atf_tc_expect_fail("testcase fails with SIGSEGV on FreeBSD; bug # 211924"); #endif fd = open(path, O_RDWR | O_CREAT, 0700); if (fd < 0) return; ATF_REQUIRE(write(fd, "foo\n", 5) == 5); map = mmap(NULL, page, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0); ATF_REQUIRE(map != MAP_FAILED); sta = 0; for (i = 0; i < 5; i++) sta += map[i]; ATF_REQUIRE(sta == 334); ATF_REQUIRE(ftruncate(fd, 0) == 0); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { ATF_REQUIRE(signal(SIGBUS, map_sighandler) != SIG_ERR); ATF_REQUIRE(signal(SIGSEGV, map_sighandler) != SIG_ERR); sta = 0; for (i = 0; i < page; i++) sta += map[i]; /* child never will get this far, but the compiler will not know, so better use the values calculated to prevent the access to be optimized out */ ATF_REQUIRE(i == 0); ATF_REQUIRE(sta == 0); (void)munmap(map, page); (void)close(fd); return; } (void)wait(&sta); ATF_REQUIRE(WIFEXITED(sta) != 0); if (WEXITSTATUS(sta) == SIGSEGV) atf_tc_fail("child process got SIGSEGV instead of SIGBUS"); ATF_REQUIRE(WEXITSTATUS(sta) == SIGBUS); ATF_REQUIRE(munmap(map, page) == 0); ATF_REQUIRE(close(fd) == 0); } ATF_TC_CLEANUP(mmap_truncate_signal, tc) { (void)unlink(path); } ATF_TC(mmap_va0); ATF_TC_HEAD(mmap_va0, tc) { atf_tc_set_md_var(tc, "descr", "Test mmap(2) and vm.user_va0_disable"); } ATF_TC_BODY(mmap_va0, tc) { int flags = MAP_ANON | MAP_FIXED | MAP_PRIVATE; size_t len = sizeof(int); void *map; int val; /* * Make an anonymous fixed mapping at zero address. If the address * is restricted as noted in security(7), the syscall should fail. */ #ifdef __FreeBSD__ if (sysctlbyname("security.bsd.map_at_zero", &val, &len, NULL, 0) != 0) atf_tc_fail("failed to read security.bsd.map_at_zero"); val = !val; /* 1 == enable map at zero */ #endif #ifdef __NetBSD__ if (sysctlbyname("vm.user_va0_disable", &val, &len, NULL, 0) != 0) atf_tc_fail("failed to read vm.user_va0_disable"); #endif map = mmap(NULL, page, PROT_EXEC, flags, -1, 0); map_check(map, val); map = mmap(NULL, page, PROT_READ, flags, -1, 0); map_check(map, val); map = mmap(NULL, page, PROT_WRITE, flags, -1, 0); map_check(map, val); map = mmap(NULL, page, PROT_READ|PROT_WRITE, flags, -1, 0); map_check(map, val); map = mmap(NULL, page, PROT_EXEC|PROT_READ|PROT_WRITE, flags, -1, 0); map_check(map, val); } ATF_TP_ADD_TCS(tp) { page = sysconf(_SC_PAGESIZE); ATF_REQUIRE(page >= 0); #ifdef __NetBSD__ ATF_TP_ADD_TC(tp, mmap_block); #endif ATF_TP_ADD_TC(tp, mmap_err); ATF_TP_ADD_TC(tp, mmap_loan); ATF_TP_ADD_TC(tp, mmap_prot_1); ATF_TP_ADD_TC(tp, mmap_prot_2); ATF_TP_ADD_TC(tp, mmap_prot_3); ATF_TP_ADD_TC(tp, mmap_truncate); ATF_TP_ADD_TC(tp, mmap_truncate_signal); ATF_TP_ADD_TC(tp, mmap_va0); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_wait.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_wait.c (revision 312242) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_wait.c (revision 312243) @@ -1,324 +1,320 @@ /* $NetBSD: t_wait.c,v 1.8 2017/01/13 19:28:55 christos Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __RCSID("$NetBSD: t_wait.c,v 1.8 2017/01/13 19:28:55 christos Exp $"); #include #include #include #include #include #include #include #include #include #include #include -#ifdef __FreeBSD__ -#define wrusage __wrusage -#endif - ATF_TC(wait6_invalid); ATF_TC_HEAD(wait6_invalid, tc) { atf_tc_set_md_var(tc, "descr", "Test that wait6(2) returns EINVAL with 0 options"); } ATF_TC_BODY(wait6_invalid, tc) { siginfo_t si; struct wrusage wru; int st; ATF_REQUIRE(wait6(P_ALL, 0, &st, 0, &wru, &si) == -1 && errno == EINVAL); } ATF_TC(wait6_exited); ATF_TC_HEAD(wait6_exited, tc) { atf_tc_set_md_var(tc, "descr", "Test that wait6(2) handled exiting process and code"); } ATF_TC_BODY(wait6_exited, tc) { siginfo_t si; struct wrusage wru; int st; pid_t pid; switch (pid = fork()) { case -1: ATF_REQUIRE(pid > 0); case 0: exit(0x5a5a5a5a); /*NOTREACHED*/ default: ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid); ATF_REQUIRE(WIFEXITED(st) && WEXITSTATUS(st) == 0x5a); ATF_REQUIRE(si.si_status = 0x5a5a5a5a); ATF_REQUIRE(si.si_pid == pid); ATF_REQUIRE(si.si_uid == getuid()); ATF_REQUIRE(si.si_code == CLD_EXITED); #ifdef __NetBSD__ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, (uintmax_t)si.si_utime); #endif break; } } ATF_TC(wait6_terminated); ATF_TC_HEAD(wait6_terminated, tc) { atf_tc_set_md_var(tc, "descr", "Test that wait6(2) handled terminated process and code"); } ATF_TC_BODY(wait6_terminated, tc) { siginfo_t si; struct wrusage wru; int st; pid_t pid; switch (pid = fork()) { case 0: sleep(100); /*FALLTHROUGH*/ case -1: ATF_REQUIRE(pid > 0); default: ATF_REQUIRE(kill(pid, SIGTERM) == 0); ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid); ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGTERM); ATF_REQUIRE(si.si_status == SIGTERM); ATF_REQUIRE(si.si_pid == pid); ATF_REQUIRE(si.si_uid == getuid()); ATF_REQUIRE(si.si_code == CLD_KILLED); #ifdef __NetBSD__ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, (uintmax_t)si.si_utime); #endif break; } } ATF_TC(wait6_coredumped); ATF_TC_HEAD(wait6_coredumped, tc) { atf_tc_set_md_var(tc, "descr", "Test that wait6(2) handled coredumped process and code"); } ATF_TC_BODY(wait6_coredumped, tc) { siginfo_t si; struct wrusage wru; int st; pid_t pid; static const struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY }; switch (pid = fork()) { case 0: ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0); *(char *)8 = 0; /*FALLTHROUGH*/ case -1: ATF_REQUIRE(pid > 0); default: ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid); ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGSEGV && WCOREDUMP(st)); ATF_REQUIRE(si.si_status == SIGSEGV); ATF_REQUIRE(si.si_pid == pid); ATF_REQUIRE(si.si_uid == getuid()); ATF_REQUIRE(si.si_code == CLD_DUMPED); #ifdef __NetBSD__ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, (uintmax_t)si.si_utime); #endif break; } } ATF_TC(wait6_stop_and_go); ATF_TC_HEAD(wait6_stop_and_go, tc) { atf_tc_set_md_var(tc, "descr", "Test that wait6(2) handled stopped/continued process and code"); } ATF_TC_BODY(wait6_stop_and_go, tc) { siginfo_t si; struct wrusage wru; int st; pid_t pid; static const struct rlimit rl = { 0, 0 }; ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0); switch (pid = fork()) { case 0: sleep(100); /*FALLTHROUGH*/ case -1: ATF_REQUIRE(pid > 0); default: ATF_REQUIRE(kill(pid, SIGSTOP) == 0); ATF_REQUIRE(wait6(P_PID, pid, &st, WSTOPPED, &wru, &si) == pid); ATF_REQUIRE(!WIFEXITED(st)); ATF_REQUIRE(!WIFSIGNALED(st)); ATF_REQUIRE(WIFSTOPPED(st) && WSTOPSIG(st) == SIGSTOP); ATF_REQUIRE(!WIFCONTINUED(st)); ATF_REQUIRE(si.si_status == SIGSTOP); ATF_REQUIRE(si.si_pid == pid); ATF_REQUIRE(si.si_uid == getuid()); ATF_REQUIRE(si.si_code == CLD_STOPPED); #ifdef __NetBSD__ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, (uintmax_t)si.si_utime); #endif ATF_REQUIRE(kill(pid, SIGCONT) == 0); ATF_REQUIRE(wait6(P_PID, pid, &st, WCONTINUED, &wru, &si) == pid); ATF_REQUIRE(!WIFEXITED(st)); ATF_REQUIRE(!WIFSIGNALED(st)); ATF_REQUIRE(WIFCONTINUED(st)); ATF_REQUIRE(!WIFSTOPPED(st)); ATF_REQUIRE(si.si_status == SIGCONT); ATF_REQUIRE(si.si_pid == pid); ATF_REQUIRE(si.si_uid == getuid()); ATF_REQUIRE(si.si_code == CLD_CONTINUED); #ifdef __NetBSD__ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, (uintmax_t)si.si_utime); #endif ATF_REQUIRE(kill(pid, SIGQUIT) == 0); ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid); ATF_REQUIRE(!WIFEXITED(st)); ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGQUIT); ATF_REQUIRE(!WIFSTOPPED(st)); ATF_REQUIRE(!WIFCONTINUED(st)); ATF_REQUIRE(si.si_status == SIGQUIT); ATF_REQUIRE(si.si_pid == pid); ATF_REQUIRE(si.si_uid == getuid()); ATF_REQUIRE(si.si_code == CLD_KILLED); #ifdef __NetBSD__ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, (uintmax_t)si.si_utime); #endif break; } } ATF_TC(wait6_stopgo_loop); ATF_TC_HEAD(wait6_stopgo_loop, tc) { atf_tc_set_md_var(tc, "descr", "Test that wait6(2) handled stopped/continued process loop"); } ATF_TC_BODY(wait6_stopgo_loop, tc) { siginfo_t si; struct wrusage wru; int st; pid_t pid; static const struct rlimit rl = { 0, 0 }; size_t N = 100; ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0); switch (pid = fork()) { case 0: sleep(100); /*FALLTHROUGH*/ case -1: ATF_REQUIRE(pid > 0); } printf("Before loop of SIGSTOP/SIGCONT sequence %zu times\n", N); while (N --> 0) { ATF_REQUIRE(kill(pid, SIGSTOP) == 0); ATF_REQUIRE(wait6(P_PID, pid, &st, WSTOPPED, &wru, &si) == pid); ATF_REQUIRE(!WIFEXITED(st)); ATF_REQUIRE(!WIFSIGNALED(st)); ATF_REQUIRE(WIFSTOPPED(st) && WSTOPSIG(st) == SIGSTOP); ATF_REQUIRE(!WIFCONTINUED(st)); ATF_REQUIRE(si.si_status == SIGSTOP); ATF_REQUIRE(si.si_pid == pid); ATF_REQUIRE(si.si_uid == getuid()); ATF_REQUIRE(si.si_code == CLD_STOPPED); ATF_REQUIRE(kill(pid, SIGCONT) == 0); ATF_REQUIRE(wait6(P_PID, pid, &st, WCONTINUED, &wru, &si) == pid); ATF_REQUIRE(!WIFEXITED(st)); ATF_REQUIRE(!WIFSIGNALED(st)); ATF_REQUIRE(WIFCONTINUED(st)); ATF_REQUIRE(!WIFSTOPPED(st)); ATF_REQUIRE(si.si_status == SIGCONT); ATF_REQUIRE(si.si_pid == pid); ATF_REQUIRE(si.si_uid == getuid()); ATF_REQUIRE(si.si_code == CLD_CONTINUED); } ATF_REQUIRE(kill(pid, SIGQUIT) == 0); ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid); ATF_REQUIRE(!WIFEXITED(st)); ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGQUIT); ATF_REQUIRE(!WIFSTOPPED(st)); ATF_REQUIRE(!WIFCONTINUED(st)); ATF_REQUIRE(si.si_status == SIGQUIT); ATF_REQUIRE(si.si_pid == pid); ATF_REQUIRE(si.si_uid == getuid()); ATF_REQUIRE(si.si_code == CLD_KILLED); #ifdef __NetBSD__ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime, (uintmax_t)si.si_utime); #endif } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, wait6_invalid); ATF_TP_ADD_TC(tp, wait6_exited); ATF_TP_ADD_TC(tp, wait6_terminated); ATF_TP_ADD_TC(tp, wait6_coredumped); ATF_TP_ADD_TC(tp, wait6_stop_and_go); ATF_TP_ADD_TC(tp, wait6_stopgo_loop); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_wait_noproc.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_wait_noproc.c (revision 312242) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_wait_noproc.c (revision 312243) @@ -1,345 +1,342 @@ /* $NetBSD: t_wait_noproc.c,v 1.5 2016/11/09 17:50:19 kamil Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __RCSID("$NetBSD: t_wait_noproc.c,v 1.5 2016/11/09 17:50:19 kamil Exp $"); -#ifdef __FreeBSD__ -#include /* For NBBY -- it's in sys/types.h on NetBSD */ -#endif #include #include #include #include #include #ifndef TWAIT_OPTION #define TWAIT_OPTION 0 #endif #if TWAIT_OPTION == 0 ATF_TC(wait); ATF_TC_HEAD(wait, tc) { atf_tc_set_md_var(tc, "descr", "Test that wait(2) returns ECHILD for no child"); } ATF_TC_BODY(wait, tc) { ATF_REQUIRE_ERRNO(ECHILD, wait(NULL) == -1); } #endif ATF_TC(waitpid); ATF_TC_HEAD(waitpid, tc) { atf_tc_set_md_var(tc, "descr", "Test that waitpid(2) returns ECHILD for WAIT_ANY and option %s", ___STRING(TWAIT_OPTION)); } ATF_TC_BODY(waitpid, tc) { ATF_REQUIRE_ERRNO(ECHILD, waitpid(WAIT_ANY, NULL, TWAIT_OPTION) == -1); } ATF_TC(waitid); ATF_TC_HEAD(waitid, tc) { atf_tc_set_md_var(tc, "descr", "Test that waitid(2) returns ECHILD for P_ALL and option %s", ___STRING(TWAIT_OPTION)); } ATF_TC_BODY(waitid, tc) { ATF_REQUIRE_ERRNO(ECHILD, waitid(P_ALL, 0, NULL, WTRAPPED | WEXITED | TWAIT_OPTION) == -1); } ATF_TC(wait3); ATF_TC_HEAD(wait3, tc) { atf_tc_set_md_var(tc, "descr", "Test that wait3(2) returns ECHILD for no child"); } ATF_TC_BODY(wait3, tc) { ATF_REQUIRE_ERRNO(ECHILD, wait3(NULL, TWAIT_OPTION, NULL) == -1); } ATF_TC(wait4); ATF_TC_HEAD(wait4, tc) { atf_tc_set_md_var(tc, "descr", "Test that wait4(2) returns ECHILD for WAIT_ANY and option %s", ___STRING(TWAIT_OPTION)); } ATF_TC_BODY(wait4, tc) { ATF_REQUIRE_ERRNO(ECHILD, wait4(WAIT_ANY, NULL, TWAIT_OPTION, NULL) == -1); } ATF_TC(wait6); ATF_TC_HEAD(wait6, tc) { atf_tc_set_md_var(tc, "descr", "Test that wait6(2) returns ECHILD for P_ALL and option %s", ___STRING(TWAIT_OPTION)); } ATF_TC_BODY(wait6, tc) { ATF_REQUIRE_ERRNO(ECHILD, wait6(P_ALL, 0, NULL, WTRAPPED | WEXITED | TWAIT_OPTION, NULL, NULL) == -1); } /* * Generator of valid combinations of options * Usage: i = 0; while ((o = get_options_wait6(i++)) != -1) {} */ static int get_options6(size_t pos) { int rv = 0; size_t n; /* * waitid(2) must specify at least one of WEXITED, WUNTRACED, * WSTOPPED, WTRAPPED or WCONTINUED. Single option WNOWAIT * isn't valid. */ const int matrix[] = { WNOWAIT, /* First in order to blacklist it easily */ WEXITED, WUNTRACED, WSTOPPED, /* SUS compatibility, equal to WUNTRACED */ WTRAPPED, WCONTINUED }; const size_t M = (1 << __arraycount(matrix)) - 1; /* Skip empty and sole WNOWAIT option */ pos+=2; if (pos > M) return -1; for (n = 0; n < __arraycount(matrix); n++) { if (pos & __BIT(n)) rv |= matrix[n]; } return rv; } /* * Generator of valid combinations of options * Usage: i = 0; while ((o = get_options_wait4(i++)) != -1) {} */ static int get_options4(size_t pos) { int rv = 0; size_t n; const int special[] = { 0, #ifdef __NetBSD__ WALLSIG, WALTSIG, __WALL, /* Linux compatibility, equal to WALLSIG */ __WCLONE /* Linux compatibility, equal to WALTSIG */ #endif }; const int matrix[] = { WNOWAIT, WEXITED, WUNTRACED, WSTOPPED, /* SUS compatibility, equal to WUNTRACED */ WTRAPPED, WCONTINUED }; const size_t M = (1 << __arraycount(special)) - 1; if (pos < __arraycount(special)) return special[pos]; pos -= __arraycount(special); ++pos; /* Don't start with empty mask */ if (pos > M) return -1; for (n = 0; n < __arraycount(special); n++) { if (pos & __BIT(n)) rv |= matrix[n]; } return rv; } ATF_TC(waitpid_options); ATF_TC_HEAD(waitpid_options, tc) { atf_tc_set_md_var(tc, "descr", "Test that waitpid(2) returns ECHILD for WAIT_ANY and valid " "combination of options with%s WNOHANG", TWAIT_OPTION == 0 ? "out" : ""); } ATF_TC_BODY(waitpid_options, tc) { size_t i = 0; int o; while((o = get_options4(i++)) != -1) { printf("Testing waitpid(2) with options %x\n", o); ATF_REQUIRE_ERRNO(ECHILD, waitpid(WAIT_ANY, NULL, o | TWAIT_OPTION) == -1); } } ATF_TC(waitid_options); ATF_TC_HEAD(waitid_options, tc) { atf_tc_set_md_var(tc, "descr", "Test that waitid(2) returns ECHILD for P_ALL and valid " "combination of options with%s WNOHANG", TWAIT_OPTION == 0 ? "out" : ""); } ATF_TC_BODY(waitid_options, tc) { size_t i = 0; int o; while((o = get_options6(i++)) != -1) { printf("Testing waitid(2) with options %x\n", o); ATF_REQUIRE_ERRNO(ECHILD, waitid(P_ALL, 0, NULL, o | TWAIT_OPTION) == -1); } } ATF_TC(wait3_options); ATF_TC_HEAD(wait3_options, tc) { atf_tc_set_md_var(tc, "descr", "Test that wait3(2) returns ECHILD for no child"); } ATF_TC_BODY(wait3_options, tc) { size_t i = 0; int o; while((o = get_options4(i++)) != -1) { printf("Testing wait3(2) with options %x\n", o); ATF_REQUIRE_ERRNO(ECHILD, wait3(NULL, o | TWAIT_OPTION, NULL) == -1); } } ATF_TC(wait4_options); ATF_TC_HEAD(wait4_options, tc) { atf_tc_set_md_var(tc, "descr", "Test that wait4(2) returns ECHILD for WAIT_ANY and option %s", ___STRING(TWAIT_OPTION)); } ATF_TC_BODY(wait4_options, tc) { size_t i = 0; int o; while((o = get_options4(i++)) != -1) { printf("Testing wait4(2) with options %x\n", o); ATF_REQUIRE_ERRNO(ECHILD, wait4(WAIT_ANY, NULL, o | TWAIT_OPTION, NULL) == -1); } } ATF_TC(wait6_options); ATF_TC_HEAD(wait6_options, tc) { atf_tc_set_md_var(tc, "descr", "Test that wait6(2) returns ECHILD for P_ALL and option %s", ___STRING(TWAIT_OPTION)); } ATF_TC_BODY(wait6_options, tc) { size_t i = 0; int o; while((o = get_options6(i++)) != -1) { printf("Testing wait6(2) with options %x\n", o); ATF_REQUIRE_ERRNO(ECHILD, wait6(P_ALL, 0, NULL, o | TWAIT_OPTION, NULL, NULL) == -1); } } ATF_TP_ADD_TCS(tp) { #if TWAIT_OPTION == 0 ATF_TP_ADD_TC(tp, wait); #endif ATF_TP_ADD_TC(tp, waitpid); ATF_TP_ADD_TC(tp, waitid); ATF_TP_ADD_TC(tp, wait3); ATF_TP_ADD_TC(tp, wait4); ATF_TP_ADD_TC(tp, wait6); ATF_TP_ADD_TC(tp, waitpid_options); ATF_TP_ADD_TC(tp, waitid_options); ATF_TP_ADD_TC(tp, wait3_options); ATF_TP_ADD_TC(tp, wait4_options); ATF_TP_ADD_TC(tp, wait6_options); return atf_no_error(); }