Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/ssp/h_memset.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/ssp/h_memset.c (revision 312294) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/ssp/h_memset.c (revision 312295) @@ -1,49 +1,45 @@ -/* $NetBSD: h_memset.c,v 1.1 2010/12/27 02:04:19 pgoyette Exp $ */ +/* $NetBSD: h_memset.c,v 1.2 2017/01/16 16:34:24 christos Exp $ */ /* * Copyright (c) 2008 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 __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: h_memset.c,v 1.1 2010/12/27 02:04:19 pgoyette Exp $"); +__RCSID("$NetBSD: h_memset.c,v 1.2 2017/01/16 16:34:24 christos Exp $"); #include #include #include int main(int argc, char *argv[]) { char b[10]; size_t len = atoi(argv[1]); (void)memset(b, 0, len); -#ifdef __FreeBSD__ return b[0]; /* keeps optimizer from zapping the call to memset() */ -#else - return 0; -#endif } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/ssp/h_read.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/ssp/h_read.c (revision 312294) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/ssp/h_read.c (revision 312295) @@ -1,67 +1,54 @@ -/* $NetBSD: h_read.c,v 1.1 2010/12/27 02:04:19 pgoyette Exp $ */ +/* $NetBSD: h_read.c,v 1.2 2017/01/16 16:35:57 christos Exp $ */ /* * Copyright (c) 2008 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 __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: h_read.c,v 1.1 2010/12/27 02:04:19 pgoyette Exp $"); +__RCSID("$NetBSD: h_read.c,v 1.2 2017/01/16 16:35:57 christos Exp $"); #include +#include +#include #include #include #include -#ifdef __FreeBSD__ -#include -#include - int main(int argc, char *argv[]) { char b[MAXPATHLEN]; int fd, n; size_t len = atoi(argv[1]); if ((fd = open(_PATH_DEVZERO, O_RDONLY)) == -1) abort(); if ((n = read(fd, b, len)) == -1) abort(); (void)printf("%s\n", b); return (0); } -#else -int -main(int argc, char *argv[]) -{ - char b[MAXPATHLEN]; - size_t len = atoi(argv[1]); - - (void)printf("%s\n", b); - return 0; -} -#endif 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 312294) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_mmap.c (revision 312295) @@ -1,599 +1,597 @@ -/* $NetBSD: t_mmap.c,v 1.11 2017/01/13 20:43:11 christos Exp $ */ +/* $NetBSD: t_mmap.c,v 1.12 2017/01/16 16:31:05 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 $"); +__RCSID("$NetBSD: t_mmap.c,v 1.12 2017/01/16 16:31:05 christos Exp $"); #include +#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include -#ifdef __NetBSD__ -#include -#else +#ifdef __FreeBSD__ #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_timer_create.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_timer_create.c (revision 312294) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_timer_create.c (revision 312295) @@ -1,330 +1,326 @@ -/* $NetBSD: t_timer_create.c,v 1.4 2012/03/18 07:00:52 jruoho Exp $ */ +/* $NetBSD: t_timer_create.c,v 1.5 2017/01/16 16:32:13 christos Exp $ */ /*- * Copyright (c) 2010 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 #include #include #include #include #include #include static timer_t t; static bool fail = true; static void -#ifdef __FreeBSD__ timer_signal_handler(int signo, siginfo_t *si, void *osi __unused) -#else -timer_signal_handler(int signo, siginfo_t *si, void *osi) -#endif { timer_t *tp; tp = si->si_value.sival_ptr; if (*tp == t && signo == SIGALRM) fail = false; (void)fprintf(stderr, "%s: %s\n", __func__, strsignal(signo)); } static void timer_signal_create(clockid_t cid, bool expire) { struct itimerspec tim; struct sigaction act; struct sigevent evt; sigset_t set; t = 0; fail = true; (void)memset(&evt, 0, sizeof(struct sigevent)); (void)memset(&act, 0, sizeof(struct sigaction)); (void)memset(&tim, 0, sizeof(struct itimerspec)); /* * Set handler. */ act.sa_flags = SA_SIGINFO; act.sa_sigaction = timer_signal_handler; ATF_REQUIRE(sigemptyset(&set) == 0); ATF_REQUIRE(sigemptyset(&act.sa_mask) == 0); /* * Block SIGALRM while configuring the timer. */ ATF_REQUIRE(sigaction(SIGALRM, &act, NULL) == 0); ATF_REQUIRE(sigaddset(&set, SIGALRM) == 0); ATF_REQUIRE(sigprocmask(SIG_SETMASK, &set, NULL) == 0); /* * Create the timer (SIGEV_SIGNAL). */ evt.sigev_signo = SIGALRM; evt.sigev_value.sival_ptr = &t; evt.sigev_notify = SIGEV_SIGNAL; ATF_REQUIRE(timer_create(cid, &evt, &t) == 0); /* * Start the timer. After this, unblock the signal. */ tim.it_value.tv_sec = expire ? 5 : 1; tim.it_value.tv_nsec = 0; ATF_REQUIRE(timer_settime(t, 0, &tim, NULL) == 0); (void)sigprocmask(SIG_UNBLOCK, &set, NULL); (void)sleep(2); if (expire) { if (!fail) atf_tc_fail("timer fired too soon"); } else { if (fail) atf_tc_fail("timer failed to fire"); } ATF_REQUIRE(timer_delete(t) == 0); } #ifdef __FreeBSD__ static void timer_callback(union sigval value) { timer_t *tp; tp = value.sival_ptr; if (*tp == t) fail = false; } static void timer_thread_create(clockid_t cid, bool expire) { struct itimerspec tim; struct sigevent evt; t = 0; fail = true; (void)memset(&evt, 0, sizeof(struct sigevent)); (void)memset(&tim, 0, sizeof(struct itimerspec)); /* * Create the timer (SIGEV_THREAD). */ evt.sigev_notify_function = timer_callback; evt.sigev_value.sival_ptr = &t; evt.sigev_notify = SIGEV_THREAD; ATF_REQUIRE(timer_create(cid, &evt, &t) == 0); /* * Start the timer. */ tim.it_value.tv_sec = expire ? 5 : 1; tim.it_value.tv_nsec = 0; ATF_REQUIRE(timer_settime(t, 0, &tim, NULL) == 0); (void)sleep(2); if (expire) { if (!fail) atf_tc_fail("timer fired too soon"); } else { if (fail) atf_tc_fail("timer failed to fire"); } ATF_REQUIRE(timer_delete(t) == 0); } #endif ATF_TC(timer_create_err); ATF_TC_HEAD(timer_create_err, tc) { atf_tc_set_md_var(tc, "descr", "Check errors from timer_create(2) (PR lib/42434"); } ATF_TC_BODY(timer_create_err, tc) { struct sigevent ev; (void)memset(&ev, 0, sizeof(struct sigevent)); errno = 0; ev.sigev_signo = -1; ev.sigev_notify = SIGEV_SIGNAL; ATF_REQUIRE_ERRNO(EINVAL, timer_create(CLOCK_REALTIME, &ev, &t) == -1); errno = 0; ev.sigev_signo = SIGUSR1; ev.sigev_notify = SIGEV_THREAD + 100; ATF_REQUIRE_ERRNO(EINVAL, timer_create(CLOCK_REALTIME, &ev, &t) == -1); } ATF_TC(timer_create_real); ATF_TC_HEAD(timer_create_real, tc) { atf_tc_set_md_var(tc, "descr", "Checks timer_create(2) with CLOCK_REALTIME and sigevent(3), " "SIGEV_SIGNAL"); } ATF_TC_BODY(timer_create_real, tc) { timer_signal_create(CLOCK_REALTIME, false); } ATF_TC(timer_create_mono); ATF_TC_HEAD(timer_create_mono, tc) { atf_tc_set_md_var(tc, "descr", "Checks timer_create(2) with CLOCK_MONOTONIC and sigevent(3), " "SIGEV_SIGNAL"); } ATF_TC_BODY(timer_create_mono, tc) { timer_signal_create(CLOCK_MONOTONIC, false); } ATF_TC(timer_create_real_expire); ATF_TC_HEAD(timer_create_real_expire, tc) { atf_tc_set_md_var(tc, "descr", "Checks timer_create(2) with CLOCK_REALTIME and sigevent(3), " "SIGEV_SIGNAL, with expiration"); } ATF_TC_BODY(timer_create_real_expire, tc) { timer_signal_create(CLOCK_REALTIME, true); } ATF_TC(timer_create_mono_expire); ATF_TC_HEAD(timer_create_mono_expire, tc) { atf_tc_set_md_var(tc, "descr", "Checks timer_create(2) with CLOCK_MONOTONIC and sigevent(3), " "SIGEV_SIGNAL, with expiration"); } ATF_TC_BODY(timer_create_mono_expire, tc) { timer_signal_create(CLOCK_MONOTONIC, true); } ATF_TC(timer_thread_create_real); ATF_TC_HEAD(timer_thread_create_real, tc) { atf_tc_set_md_var(tc, "descr", "Checks timer_create(2) with CLOCK_REALTIME and sigevent(3), " "SIGEV_THREAD"); } #ifdef __FreeBSD__ ATF_TC_BODY(timer_thread_create_real, tc) { timer_thread_create(CLOCK_REALTIME, false); } ATF_TC(timer_thread_create_mono); ATF_TC_HEAD(timer_thread_create_mono, tc) { atf_tc_set_md_var(tc, "descr", "Checks timer_create(2) with CLOCK_MONOTONIC and sigevent(3), " "SIGEV_THREAD"); } ATF_TC_BODY(timer_thread_create_mono, tc) { timer_thread_create(CLOCK_MONOTONIC, false); } ATF_TC(timer_thread_create_real_expire); ATF_TC_HEAD(timer_thread_create_real_expire, tc) { atf_tc_set_md_var(tc, "descr", "Checks timer_create(2) with CLOCK_REALTIME and sigevent(3), " "SIGEV_THREAD, with expiration"); } ATF_TC_BODY(timer_thread_create_real_expire, tc) { timer_thread_create(CLOCK_REALTIME, true); } ATF_TC(timer_thread_create_mono_expire); ATF_TC_HEAD(timer_thread_create_mono_expire, tc) { atf_tc_set_md_var(tc, "descr", "Checks timer_create(2) with CLOCK_MONOTONIC and sigevent(3), " "SIGEV_THREAD, with expiration"); } ATF_TC_BODY(timer_thread_create_mono_expire, tc) { timer_thread_create(CLOCK_MONOTONIC, true); } #endif ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, timer_create_err); ATF_TP_ADD_TC(tp, timer_create_real); ATF_TP_ADD_TC(tp, timer_create_mono); ATF_TP_ADD_TC(tp, timer_create_real_expire); ATF_TP_ADD_TC(tp, timer_create_mono_expire); #ifdef __FreeBSD__ ATF_TP_ADD_TC(tp, timer_thread_create_real); ATF_TP_ADD_TC(tp, timer_thread_create_mono); ATF_TP_ADD_TC(tp, timer_thread_create_real_expire); ATF_TP_ADD_TC(tp, timer_thread_create_mono_expire); #endif return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_condwait.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_condwait.c (revision 312294) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_condwait.c (revision 312295) @@ -1,153 +1,145 @@ -/* $NetBSD: t_condwait.c,v 1.4 2013/04/12 17:18:11 christos Exp $ */ +/* $NetBSD: t_condwait.c,v 1.5 2017/01/16 16:29:19 christos Exp $ */ /* * Copyright (c) 2013 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_condwait.c,v 1.4 2013/04/12 17:18:11 christos Exp $"); +__RCSID("$NetBSD: t_condwait.c,v 1.5 2017/01/16 16:29:19 christos Exp $"); +#include #include #include #include #include #include #include #include #include #include "isqemu.h" -#ifdef __FreeBSD__ -#include - #include "h_common.h" -#endif #define WAITTIME 2 /* Timeout wait secound */ static const int debug = 1; static void * run(void *param) { struct timespec ts, to, te; clockid_t clck; pthread_condattr_t attr; pthread_cond_t cond; pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; int ret = 0; clck = *(clockid_t *)param; -#ifdef __FreeBSD__ PTHREAD_REQUIRE(pthread_condattr_init(&attr)); PTHREAD_REQUIRE(pthread_condattr_setclock(&attr, clck)); -#else - pthread_condattr_init(&attr); - pthread_condattr_setclock(&attr, clck); /* MONOTONIC or MONOTONIC */ -#endif pthread_cond_init(&cond, &attr); ATF_REQUIRE_EQ((ret = pthread_mutex_lock(&m)), 0); ATF_REQUIRE_EQ(clock_gettime(clck, &ts), 0); to = ts; if (debug) printf("started: %lld.%09ld sec\n", (long long)to.tv_sec, to.tv_nsec); ts.tv_sec += WAITTIME; /* Timeout wait */ switch (ret = pthread_cond_timedwait(&cond, &m, &ts)) { case ETIMEDOUT: /* Timeout */ ATF_REQUIRE_EQ(clock_gettime(clck, &te), 0); timespecsub(&te, &to, &to); if (debug) { printf("timeout: %lld.%09ld sec\n", (long long)te.tv_sec, te.tv_nsec); printf("elapsed: %lld.%09ld sec\n", (long long)to.tv_sec, to.tv_nsec); } if (isQEMU()) { double to_seconds = to.tv_sec + 1e-9 * to.tv_nsec; ATF_REQUIRE(to_seconds >= WAITTIME * 0.9); /* Loose upper limit because of qemu timing bugs */ ATF_REQUIRE(to_seconds < WAITTIME * 2.5); } else { ATF_REQUIRE_EQ(to.tv_sec, WAITTIME); } break; default: ATF_REQUIRE_MSG(0, "pthread_cond_timedwait: %s", strerror(ret)); } ATF_REQUIRE_MSG(!(ret = pthread_mutex_unlock(&m)), "pthread_mutex_unlock: %s", strerror(ret)); pthread_exit(&ret); } static void cond_wait(clockid_t clck, const char *msg) { pthread_t child; if (debug) printf( "**** %s clock wait starting\n", msg); ATF_REQUIRE_EQ(pthread_create(&child, NULL, run, &clck), 0); ATF_REQUIRE_EQ(pthread_join(child, NULL), 0); /* wait for terminate */ if (debug) printf( "**** %s clock wait ended\n", msg); } ATF_TC(cond_wait_real); ATF_TC_HEAD(cond_wait_real, tc) { atf_tc_set_md_var(tc, "descr", "Checks pthread_cond_timedwait " "with CLOCK_REALTIME"); } ATF_TC_BODY(cond_wait_real, tc) { cond_wait(CLOCK_REALTIME, "CLOCK_REALTIME"); } ATF_TC(cond_wait_mono); ATF_TC_HEAD(cond_wait_mono, tc) { atf_tc_set_md_var(tc, "descr", "Checks pthread_cond_timedwait " "with CLOCK_MONOTONIC"); } ATF_TC_BODY(cond_wait_mono, tc) { cond_wait(CLOCK_MONOTONIC, "CLOCK_MONOTONIC"); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, cond_wait_real); ATF_TP_ADD_TC(tp, cond_wait_mono); return 0; } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_detach.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_detach.c (revision 312294) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_detach.c (revision 312295) @@ -1,109 +1,100 @@ -/* $NetBSD: t_detach.c,v 1.1 2011/03/24 13:52:04 jruoho Exp $ */ +/* $NetBSD: t_detach.c,v 1.2 2017/01/16 16:29:54 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. */ #include -__RCSID("$NetBSD: t_detach.c,v 1.1 2011/03/24 13:52:04 jruoho Exp $"); +__RCSID("$NetBSD: t_detach.c,v 1.2 2017/01/16 16:29:54 christos Exp $"); -#include #include +#include +#include #include #include "h_common.h" #ifdef __FreeBSD__ #include #endif static void *func(void *); static void * func(void *arg) { -#ifdef __FreeBSD__ sleep(2); -#endif return NULL; } ATF_TC(pthread_detach); ATF_TC_HEAD(pthread_detach, tc) { atf_tc_set_md_var(tc, "descr", "A test of pthread_detach(3)"); } ATF_TC_BODY(pthread_detach, tc) { const int state = PTHREAD_CREATE_JOINABLE; pthread_attr_t attr; pthread_t t; int rv; /* * Create a joinable thread. */ PTHREAD_REQUIRE(pthread_attr_init(&attr)); PTHREAD_REQUIRE(pthread_attr_setdetachstate(&attr, state)); PTHREAD_REQUIRE(pthread_create(&t, &attr, func, NULL)); /* * Detach the thread and try to * join it; EINVAL should follow. */ PTHREAD_REQUIRE(pthread_detach(t)); -#ifdef __FreeBSD__ sleep(1); -#endif rv = pthread_join(t, NULL); ATF_REQUIRE(rv == EINVAL); -#ifdef __FreeBSD__ sleep(3); -#endif /* * As usual, ESRCH should follow if * we try to detach an invalid thread. */ -#ifdef __NetBSD__ - rv = pthread_cancel(NULL); -#else rv = pthread_cancel(t); -#endif ATF_REQUIRE(rv == ESRCH); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, pthread_detach); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_fork.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_fork.c (revision 312294) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_fork.c (revision 312295) @@ -1,115 +1,107 @@ -/* $NetBSD: t_fork.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ +/* $NetBSD: t_fork.c,v 1.2 2017/01/16 16:28:27 christos Exp $ */ /* * Copyright (c) 2008 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 __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_fork.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); +__RCSID("$NetBSD: t_fork.c,v 1.2 2017/01/16 16:28:27 christos Exp $"); /* * Written by Love Hörnquist Åstrand , March 2003. * Public domain. */ #include #include #include #include #include #include #include #include #include #include #include "h_common.h" static pid_t parent; static int thread_survived = 0; static void * print_pid(void *arg) { sleep(3); thread_survived = 1; if (parent != getpid()) { -#ifdef __FreeBSD__ _exit(1); -#else - exit(1); -#endif } return NULL; } ATF_TC(fork); ATF_TC_HEAD(fork, tc) { atf_tc_set_md_var(tc, "descr", "Checks that child process doesn't get threads"); } ATF_TC_BODY(fork, tc) { pthread_t p; pid_t fork_pid; parent = getpid(); PTHREAD_REQUIRE(pthread_create(&p, NULL, print_pid, NULL)); fork_pid = fork(); ATF_REQUIRE(fork_pid != -1); if (fork_pid) { int status; PTHREAD_REQUIRE(pthread_join(p, NULL)); ATF_REQUIRE_MSG(thread_survived, "thread did not survive in parent"); waitpid(fork_pid, &status, 0); ATF_REQUIRE_MSG(WIFEXITED(status), "child died wrongly"); ATF_REQUIRE_EQ_MSG(WEXITSTATUS(status), 0, "thread survived in child"); } else { sleep(5); -#ifdef __FreeBSD__ _exit(thread_survived ? 1 : 0); -#else - exit(thread_survived ? 1 : 0); -#endif } } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, fork); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_fpu.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_fpu.c (revision 312294) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_fpu.c (revision 312295) @@ -1,171 +1,157 @@ -/* $NetBSD: t_fpu.c,v 1.2 2013/01/27 14:47:37 mbalmer Exp $ */ +/* $NetBSD: t_fpu.c,v 1.3 2017/01/16 16:27:43 christos Exp $ */ /* * Copyright (c) 2008 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 __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_fpu.c,v 1.2 2013/01/27 14:47:37 mbalmer Exp $"); +__RCSID("$NetBSD: t_fpu.c,v 1.3 2017/01/16 16:27:43 christos Exp $"); /* * This is adapted from part of csw/cstest of the MPD implementation by * the University of Arizona CS department (http://www.cs.arizona.edu/sr/) * which is in the public domain: * * "The MPD system is in the public domain and you may use and distribute it * as you wish. We ask that you retain credits referencing the University * of Arizona and that you identify any changes you make. * * We can't provide a warranty with MPD; it's up to you to determine its * suitability and reliability for your needs. We would like to hear of * any problems you encounter but we cannot promise a timely correction." * * It was changed to use pthread_create() and sched_yield() instead of * the internal MPD context switching primitives by Ignatios Souvatzis * . */ +#include #include #include #include #include +#include #include #include #include #ifdef __FreeBSD__ #include #include #endif #include "h_common.h" #define N_RECURSE 10 static void recurse(void); int recursion_depth = 0; pthread_mutex_t recursion_depth_lock; static void * stir(void *p) { double *q = (double *)p; double x = *q++; double y = *q++; double z = *q++; for (;;) { x = sin ((y = cos (x + y + .4)) - (z = cos (x + z + .6))); -#ifdef __FreeBSD__ ATF_REQUIRE_MSG(sched_yield() == 0, "sched_yield failed: %s", strerror(errno)); -#else - PTHREAD_REQUIRE(sched_yield()); -#endif } } static double mul3(double x, double y, double z) { -#ifdef __FreeBSD__ ATF_REQUIRE_MSG(sched_yield() == 0, "sched_yield failed: %s", strerror(errno)); -#else - PTHREAD_REQUIRE(sched_yield()); -#endif return x * y * z; } static void * bar(void *p) { double d; int rc; d = mul3(mul3(2., 3., 5.), mul3(7., 11., 13.), mul3(17., 19., 23.)); ATF_REQUIRE_EQ(d, 223092870.); PTHREAD_REQUIRE(pthread_mutex_lock(&recursion_depth_lock)); rc = recursion_depth++; PTHREAD_REQUIRE(pthread_mutex_unlock(&recursion_depth_lock)); if (rc < N_RECURSE) recurse(); else atf_tc_pass(); /* NOTREACHED */ return NULL; } static void recurse(void) { pthread_t s2; -#ifdef __FreeBSD__ PTHREAD_REQUIRE(pthread_create(&s2, 0, bar, 0)); -#else - pthread_create(&s2, 0, bar, 0); -#endif sleep(20); /* XXX must be long enough for our slowest machine */ } ATF_TC(fpu); ATF_TC_HEAD(fpu, tc) { atf_tc_set_md_var(tc, "descr", "Checks that thread context switches will leave the " "floating point computations unharmed"); } ATF_TC_BODY(fpu, tc) { double stirseed[] = { 1.7, 3.2, 2.4 }; pthread_t s5; printf("Testing threaded floating point computations...\n"); PTHREAD_REQUIRE(pthread_mutex_init(&recursion_depth_lock, 0)); -#ifdef __FreeBSD__ PTHREAD_REQUIRE(pthread_create(&s5, 0, stir, stirseed)); -#else - pthread_create(&s5, 0, stir, stirseed); -#endif recurse(); atf_tc_fail("exiting from main"); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, fpu); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_mutex.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_mutex.c (revision 312294) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_mutex.c (revision 312295) @@ -1,753 +1,747 @@ -/* $NetBSD: t_mutex.c,v 1.14 2016/10/31 23:51:20 christos Exp $ */ +/* $NetBSD: t_mutex.c,v 1.15 2017/01/16 16:23:41 christos Exp $ */ /* * Copyright (c) 2008 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 __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_mutex.c,v 1.14 2016/10/31 23:51:20 christos Exp $"); +__RCSID("$NetBSD: t_mutex.c,v 1.15 2017/01/16 16:23:41 christos Exp $"); -#ifdef __FreeBSD__ #include /* For timespecadd */ #include /* For UINT16_MAX */ -#endif #include #include #include #include #include #include #include #include #include #include "h_common.h" static pthread_mutex_t mutex; static pthread_mutex_t static_mutex = PTHREAD_MUTEX_INITIALIZER; static int global_x; #ifdef TIMEDMUTEX /* This code is used for verifying non-timed specific code */ static struct timespec ts_lengthy = { .tv_sec = UINT16_MAX, .tv_nsec = 0 }; /* This code is used for verifying timed-only specific code */ static struct timespec ts_shortlived = { .tv_sec = 0, .tv_nsec = 120 }; static int mutex_lock(pthread_mutex_t *m, const struct timespec *ts) { struct timespec ts_wait; ATF_REQUIRE(clock_gettime(CLOCK_REALTIME, &ts_wait) != -1); timespecadd(&ts_wait, ts, &ts_wait); return pthread_mutex_timedlock(m, &ts_wait); } #else #define mutex_lock(a, b) pthread_mutex_lock(a) #endif static void * mutex1_threadfunc(void *arg) { int *param; printf("2: Second thread.\n"); param = arg; printf("2: Locking mutex\n"); mutex_lock(&mutex, &ts_lengthy); printf("2: Got mutex. *param = %d\n", *param); ATF_REQUIRE_EQ(*param, 20); (*param)++; pthread_mutex_unlock(&mutex); return param; } ATF_TC(mutex1); ATF_TC_HEAD(mutex1, tc) { atf_tc_set_md_var(tc, "descr", "Checks mutexes"); } ATF_TC_BODY(mutex1, tc) { int x; pthread_t new; void *joinval; printf("1: Mutex-test 1\n"); PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); x = 1; PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy)); PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex1_threadfunc, &x)); printf("1: Before changing the value.\n"); sleep(2); x = 20; printf("1: Before releasing the mutex.\n"); sleep(2); PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); printf("1: After releasing the mutex.\n"); PTHREAD_REQUIRE(pthread_join(new, &joinval)); PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy)); printf("1: Thread joined. X was %d. Return value (int) was %d\n", x, *(int *)joinval); ATF_REQUIRE_EQ(x, 21); ATF_REQUIRE_EQ(*(int *)joinval, 21); PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); } static void * mutex2_threadfunc(void *arg) { long count = *(int *)arg; printf("2: Second thread (%p). Count is %ld\n", pthread_self(), count); while (count--) { PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy)); global_x++; PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); } return (void *)count; } ATF_TC(mutex2); ATF_TC_HEAD(mutex2, tc) { atf_tc_set_md_var(tc, "descr", "Checks mutexes"); #ifdef __NetBSD__ #if defined(__powerpc__) atf_tc_set_md_var(tc, "timeout", "40"); #endif #endif } ATF_TC_BODY(mutex2, tc) { int count, count2; pthread_t new; void *joinval; printf("1: Mutex-test 2\n"); #ifdef __NetBSD__ #if defined(__powerpc__) atf_tc_expect_timeout("PR port-powerpc/44387"); #endif #endif PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); global_x = 0; count = count2 = 10000000; PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy)); PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex2_threadfunc, &count2)); printf("1: Thread %p\n", pthread_self()); PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); while (count--) { PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy)); global_x++; PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); } PTHREAD_REQUIRE(pthread_join(new, &joinval)); PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy)); printf("1: Thread joined. X was %d. Return value (long) was %ld\n", global_x, (long)joinval); ATF_REQUIRE_EQ(global_x, 20000000); #ifdef __NetBSD__ #if defined(__powerpc__) /* XXX force a timeout in ppc case since an un-triggered race otherwise looks like a "failure" */ /* We sleep for longer than the timeout to make ATF not complain about unexpected success */ sleep(41); #endif #endif } static void * mutex3_threadfunc(void *arg) { long count = *(int *)arg; printf("2: Second thread (%p). Count is %ld\n", pthread_self(), count); while (count--) { PTHREAD_REQUIRE(mutex_lock(&static_mutex, &ts_lengthy)); global_x++; PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); } return (void *)count; } ATF_TC(mutex3); ATF_TC_HEAD(mutex3, tc) { atf_tc_set_md_var(tc, "descr", "Checks mutexes using a static " "initializer"); #ifdef __NetBSD__ #if defined(__powerpc__) atf_tc_set_md_var(tc, "timeout", "40"); #endif #endif } ATF_TC_BODY(mutex3, tc) { int count, count2; pthread_t new; void *joinval; printf("1: Mutex-test 3\n"); #ifdef __NetBSD__ #if defined(__powerpc__) atf_tc_expect_timeout("PR port-powerpc/44387"); #endif #endif global_x = 0; count = count2 = 10000000; PTHREAD_REQUIRE(mutex_lock(&static_mutex, &ts_lengthy)); PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex3_threadfunc, &count2)); printf("1: Thread %p\n", pthread_self()); PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); while (count--) { PTHREAD_REQUIRE(mutex_lock(&static_mutex, &ts_lengthy)); global_x++; PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); } PTHREAD_REQUIRE(pthread_join(new, &joinval)); PTHREAD_REQUIRE(mutex_lock(&static_mutex, &ts_lengthy)); printf("1: Thread joined. X was %d. Return value (long) was %ld\n", global_x, (long)joinval); ATF_REQUIRE_EQ(global_x, 20000000); #ifdef __NetBSD__ #if defined(__powerpc__) /* XXX force a timeout in ppc case since an un-triggered race otherwise looks like a "failure" */ /* We sleep for longer than the timeout to make ATF not complain about unexpected success */ sleep(41); #endif #endif } static void * mutex4_threadfunc(void *arg) { int *param; printf("2: Second thread.\n"); param = arg; printf("2: Locking mutex\n"); PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy)); printf("2: Got mutex. *param = %d\n", *param); (*param)++; PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); return param; } ATF_TC(mutex4); ATF_TC_HEAD(mutex4, tc) { atf_tc_set_md_var(tc, "descr", "Checks mutexes"); } ATF_TC_BODY(mutex4, tc) { int x; pthread_t new; pthread_mutexattr_t mattr; void *joinval; printf("1: Mutex-test 4\n"); PTHREAD_REQUIRE(pthread_mutexattr_init(&mattr)); PTHREAD_REQUIRE(pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE)); PTHREAD_REQUIRE(pthread_mutex_init(&mutex, &mattr)); PTHREAD_REQUIRE(pthread_mutexattr_destroy(&mattr)); x = 1; PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy)); PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex4_threadfunc, &x)); printf("1: Before recursively acquiring the mutex.\n"); PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy)); printf("1: Before releasing the mutex once.\n"); sleep(2); PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); printf("1: After releasing the mutex once.\n"); x = 20; printf("1: Before releasing the mutex twice.\n"); sleep(2); PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); printf("1: After releasing the mutex twice.\n"); PTHREAD_REQUIRE(pthread_join(new, &joinval)); PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy)); printf("1: Thread joined. X was %d. Return value (int) was %d\n", x, *(int *)joinval); ATF_REQUIRE_EQ(x, 21); ATF_REQUIRE_EQ(*(int *)joinval, 21); PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); } #ifdef __NetBSD__ static pthread_mutexattr_t attr5; static pthread_mutex_t mutex5; static int min_fifo_prio, max_fifo_prio; static void * child_func(void* arg) { int res; printf("child is waiting\n"); res = _sched_protect(-2); ATF_REQUIRE_EQ_MSG(res, -1, "sched_protect returned %d", res); ATF_REQUIRE_EQ(errno, ENOENT); PTHREAD_REQUIRE(mutex_lock(&mutex5, &ts_lengthy)); printf("child is owning resource\n"); res = _sched_protect(-2); ATF_REQUIRE_EQ(res, max_fifo_prio); PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex5)); printf("child is done\n"); return 0; } ATF_TC(mutex5); ATF_TC_HEAD(mutex5, tc) { atf_tc_set_md_var(tc, "descr", "Checks mutexes for priority setting"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(mutex5, tc) { int res; struct sched_param param; pthread_t child; min_fifo_prio = sched_get_priority_min(SCHED_FIFO); max_fifo_prio = sched_get_priority_max(SCHED_FIFO); printf("min prio for FIFO = %d\n", min_fifo_prio); param.sched_priority = min_fifo_prio; /* = 0 OTHER, 1 FIFO, 2 RR, -1 NONE */ res = sched_setscheduler(getpid(), SCHED_FIFO, ¶m); printf("previous policy used = %d\n", res); res = sched_getscheduler(getpid()); ATF_REQUIRE_EQ_MSG(res, SCHED_FIFO, "sched %d != FIFO %d", res, SCHED_FIFO); PTHREAD_REQUIRE(pthread_mutexattr_init(&attr5)); PTHREAD_REQUIRE(pthread_mutexattr_setprotocol(&attr5, PTHREAD_PRIO_PROTECT)); PTHREAD_REQUIRE(pthread_mutexattr_setprioceiling(&attr5, max_fifo_prio)); PTHREAD_REQUIRE(pthread_mutex_init(&mutex5, &attr5)); PTHREAD_REQUIRE(mutex_lock(&mutex5, &ts_lengthy)); printf("enter critical section for main\n"); PTHREAD_REQUIRE(pthread_create(&child, NULL, child_func, NULL)); printf("main starts to sleep\n"); sleep(10); printf("main completes\n"); PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex5)); PTHREAD_REQUIRE(pthread_join(child, NULL)); } static pthread_mutex_t mutex6; static int start = 0; static uintmax_t high_cnt = 0, low_cnt = 0, MAX_LOOP = 100000000; static void * high_prio(void* arg) { struct sched_param param; int policy; param.sched_priority = min_fifo_prio + 10; pthread_t childid = pthread_self(); PTHREAD_REQUIRE(pthread_setschedparam(childid, 1, ¶m)); PTHREAD_REQUIRE(pthread_getschedparam(childid, &policy, ¶m)); printf("high protect = %d, prio = %d\n", _sched_protect(-2), param.sched_priority); ATF_REQUIRE_EQ(policy, 1); printf("high prio = %d\n", param.sched_priority); sleep(1); long tmp = 0; for (int i = 0; i < 20; i++) { while (high_cnt < MAX_LOOP) { tmp += (123456789 % 1234) * (987654321 % 54321); high_cnt += 1; } high_cnt = 0; sleep(1); } PTHREAD_REQUIRE(mutex_lock(&mutex6, &ts_lengthy)); if (start == 0) start = 2; PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex6)); return 0; } static void * low_prio(void* arg) { struct sched_param param; int policy; param.sched_priority = min_fifo_prio; pthread_t childid = pthread_self(); int res = _sched_protect(max_fifo_prio); ATF_REQUIRE_EQ(res, 0); PTHREAD_REQUIRE(pthread_setschedparam(childid, 1, ¶m)); PTHREAD_REQUIRE(pthread_getschedparam(childid, &policy, ¶m)); printf("low protect = %d, prio = %d\n", _sched_protect(-2), param.sched_priority); ATF_REQUIRE_EQ(policy, 1); printf("low prio = %d\n", param.sched_priority); sleep(1); long tmp = 0; for (int i = 0; i < 20; i++) { while (low_cnt < MAX_LOOP) { tmp += (123456789 % 1234) * (987654321 % 54321); low_cnt += 1; } low_cnt = 0; sleep(1); } PTHREAD_REQUIRE(mutex_lock(&mutex6, &ts_lengthy)); if (start == 0) start = 1; PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex6)); return 0; } ATF_TC(mutex6); ATF_TC_HEAD(mutex6, tc) { atf_tc_set_md_var(tc, "descr", "Checks scheduling for priority ceiling"); atf_tc_set_md_var(tc, "require.user", "root"); } /* * 1. main thread sets itself to be a realtime task and launched two tasks, * one has higher priority and the other has lower priority. * 2. each child thread(low and high priority thread) sets its scheduler and * priority. * 3. each child thread did several rounds of computation, after each round it * sleep 1 second. * 4. the child thread with low priority will call _sched_protect to increase * its protect priority. * 5. We verify the thread with low priority runs first. * * Why does it work? From the main thread, we launched the high * priority thread first. This gives this thread the benefit of * starting first. The low priority thread did not call _sched_protect(2). * The high priority thread should finish the task first. After each * round of computation, we call sleep, to put the task into the * sleep queue, and wake up again after the timer expires. This * gives the scheduler the chance to decide which task to run. So, * the thread with real high priority will always block the thread * with real low priority. * */ ATF_TC_BODY(mutex6, tc) { struct sched_param param; int res; pthread_t high, low; min_fifo_prio = sched_get_priority_min(SCHED_FIFO); max_fifo_prio = sched_get_priority_max(SCHED_FIFO); PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); printf("min_fifo_prio = %d, max_fifo_info = %d\n", min_fifo_prio, max_fifo_prio); param.sched_priority = min_fifo_prio; res = sched_setscheduler(getpid(), SCHED_FIFO, ¶m); printf("previous policy used = %d\n", res); res = sched_getscheduler(getpid()); ATF_REQUIRE_EQ(res, 1); PTHREAD_REQUIRE(pthread_create(&high, NULL, high_prio, NULL)); PTHREAD_REQUIRE(pthread_create(&low, NULL, low_prio, NULL)); sleep(5); PTHREAD_REQUIRE(pthread_join(low, NULL)); PTHREAD_REQUIRE(pthread_join(high, NULL)); ATF_REQUIRE_EQ(start, 1); } #endif ATF_TC(mutexattr1); ATF_TC_HEAD(mutexattr1, tc) { atf_tc_set_md_var(tc, "descr", "Checks mutexattr"); } ATF_TC_BODY(mutexattr1, tc) { pthread_mutexattr_t mattr; int protocol, target; PTHREAD_REQUIRE(pthread_mutexattr_init(&mattr)); target = PTHREAD_PRIO_NONE; PTHREAD_REQUIRE(pthread_mutexattr_setprotocol(&mattr, target)); PTHREAD_REQUIRE(pthread_mutexattr_getprotocol(&mattr, &protocol)); ATF_REQUIRE_EQ(protocol, target); /* target = PTHREAD_PRIO_INHERIT; PTHREAD_REQUIRE(pthread_mutexattr_setprotocol(&mattr, target)); PTHREAD_REQUIRE(pthread_mutexattr_getprotocol(&mattr, &protocol)); ATF_REQUIRE_EQ(protocol, target); */ target = PTHREAD_PRIO_PROTECT; PTHREAD_REQUIRE(pthread_mutexattr_setprotocol(&mattr, target)); PTHREAD_REQUIRE(pthread_mutexattr_getprotocol(&mattr, &protocol)); ATF_REQUIRE_EQ(protocol, target); } ATF_TC(mutexattr2); ATF_TC_HEAD(mutexattr2, tc) { atf_tc_set_md_var(tc, "descr", "Checks mutexattr"); } ATF_TC_BODY(mutexattr2, tc) { pthread_mutexattr_t mattr; #ifdef __FreeBSD__ atf_tc_expect_fail("fails on i == 0 with: " "pthread_mutexattr_setprioceiling(&mattr, i): Invalid argument " "-- PR # 211802"); #endif PTHREAD_REQUIRE(pthread_mutexattr_init(&mattr)); int max_prio = sched_get_priority_max(SCHED_FIFO); int min_prio = sched_get_priority_min(SCHED_FIFO); for (int i = min_prio; i <= max_prio; i++) { int prioceiling; -#ifdef __FreeBSD__ int protocol; PTHREAD_REQUIRE(pthread_mutexattr_getprotocol(&mattr, &protocol)); printf("priority: %d\nprotocol: %d\n", i, protocol); -#endif PTHREAD_REQUIRE(pthread_mutexattr_setprioceiling(&mattr, i)); PTHREAD_REQUIRE(pthread_mutexattr_getprioceiling(&mattr, &prioceiling)); -#ifdef __FreeBSD__ printf("prioceiling: %d\n", prioceiling); -#endif ATF_REQUIRE_EQ(i, prioceiling); } } #ifdef TIMEDMUTEX ATF_TC(timedmutex1); ATF_TC_HEAD(timedmutex1, tc) { atf_tc_set_md_var(tc, "descr", "Checks timeout on selflock"); } ATF_TC_BODY(timedmutex1, tc) { printf("Timed mutex-test 1\n"); PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); printf("Before acquiring mutex\n"); PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); printf("Before endeavor to reacquire timed-mutex (timeout expected)\n"); PTHREAD_REQUIRE_STATUS(mutex_lock(&mutex, &ts_shortlived), ETIMEDOUT); printf("Unlocking mutex\n"); PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); } ATF_TC(timedmutex2); ATF_TC_HEAD(timedmutex2, tc) { atf_tc_set_md_var(tc, "descr", "Checks timeout on selflock with timedlock"); } ATF_TC_BODY(timedmutex2, tc) { printf("Timed mutex-test 2\n"); PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); printf("Before acquiring mutex with timedlock\n"); PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy)); printf("Before endeavor to reacquire timed-mutex (timeout expected)\n"); PTHREAD_REQUIRE_STATUS(mutex_lock(&mutex, &ts_shortlived), ETIMEDOUT); printf("Unlocking mutex\n"); PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); } ATF_TC(timedmutex3); ATF_TC_HEAD(timedmutex3, tc) { atf_tc_set_md_var(tc, "descr", "Checks timeout on selflock in a new thread"); } static void * timedmtx_thrdfunc(void *arg) { printf("Before endeavor to reacquire timed-mutex (timeout expected)\n"); PTHREAD_REQUIRE_STATUS(mutex_lock(&mutex, &ts_shortlived), ETIMEDOUT); return NULL; } ATF_TC_BODY(timedmutex3, tc) { pthread_t new; printf("Timed mutex-test 3\n"); PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); printf("Before acquiring mutex with timedlock\n"); PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); printf("Before creating new thread\n"); PTHREAD_REQUIRE(pthread_create(&new, NULL, timedmtx_thrdfunc, NULL)); printf("Before joining the mutex\n"); PTHREAD_REQUIRE(pthread_join(new, NULL)); printf("Unlocking mutex\n"); PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); } ATF_TC(timedmutex4); ATF_TC_HEAD(timedmutex4, tc) { atf_tc_set_md_var(tc, "descr", "Checks timeout on selflock with timedlock in a new thread"); } ATF_TC_BODY(timedmutex4, tc) { pthread_t new; printf("Timed mutex-test 4\n"); PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); printf("Before acquiring mutex with timedlock\n"); PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy)); printf("Before creating new thread\n"); PTHREAD_REQUIRE(pthread_create(&new, NULL, timedmtx_thrdfunc, NULL)); printf("Before joining the mutex\n"); PTHREAD_REQUIRE(pthread_join(new, NULL)); printf("Unlocking mutex\n"); PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); } #endif ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, mutex1); ATF_TP_ADD_TC(tp, mutex2); ATF_TP_ADD_TC(tp, mutex3); ATF_TP_ADD_TC(tp, mutex4); #ifdef __NetBSD__ ATF_TP_ADD_TC(tp, mutex5); ATF_TP_ADD_TC(tp, mutex6); #endif ATF_TP_ADD_TC(tp, mutexattr1); ATF_TP_ADD_TC(tp, mutexattr2); #ifdef TIMEDMUTEX ATF_TP_ADD_TC(tp, timedmutex1); ATF_TP_ADD_TC(tp, timedmutex2); ATF_TP_ADD_TC(tp, timedmutex3); ATF_TP_ADD_TC(tp, timedmutex4); #endif return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_sem.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_sem.c (revision 312294) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_sem.c (revision 312295) @@ -1,310 +1,311 @@ -/* $NetBSD: t_sem.c,v 1.8 2014/11/04 00:20:19 justin Exp $ */ +/* $NetBSD: t_sem.c,v 1.9 2017/01/16 16:22:22 christos Exp $ */ /* * Copyright (c) 2008, 2010 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. */ /*- * 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. */ /**************************************************************************** * * Copyright (C) 2000 Jason Evans . * 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(s), this list of conditions and the following disclaimer as * the first lines of this file unmodified other than the possible * addition of one or more copyright notices. * 2. Redistributions in binary form must reproduce the above copyright * notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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, 2010\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_sem.c,v 1.8 2014/11/04 00:20:19 justin Exp $"); +__RCSID("$NetBSD: t_sem.c,v 1.9 2017/01/16 16:22:22 christos Exp $"); +#include #include #include #include #include #include #include #include #include #include #include #include "h_common.h" #define NTHREADS 10 #define _LIBC_R_ #define SEM_REQUIRE(x) \ ATF_REQUIRE_EQ_MSG(x, 0, "%s", strerror(errno)) static sem_t sem; #ifdef __FreeBSD__ #include #endif ATF_TC(named); ATF_TC_HEAD(named, tc) { atf_tc_set_md_var(tc, "descr", "Checks named semaphores"); } ATF_TC_BODY(named, tc) { sem_t *semp; ATF_REQUIRE_MSG(-1 != sysconf(_SC_SEMAPHORES), "%s", strerror(errno)); printf("Test begin\n"); (void) sem_unlink("/foo"); semp = sem_open("/foo", O_CREAT | O_EXCL, 0644, 0); ATF_REQUIRE_MSG(semp != SEM_FAILED, "%s", strerror(errno)); SEM_REQUIRE(sem_close(semp)); SEM_REQUIRE(sem_unlink("/foo")); printf("Test end\n"); } ATF_TC(unnamed); ATF_TC_HEAD(unnamed, tc) { atf_tc_set_md_var(tc, "descr", "Checks unnamed semaphores"); } static void * entry(void * a_arg) { pthread_t self = pthread_self(); sem_t *semp = (sem_t *) a_arg; printf("Thread %p waiting for semaphore...\n", self); sem_wait(semp); printf("Thread %p got semaphore\n", self); return NULL; } ATF_TC_BODY(unnamed, tc) { sem_t sem_a, sem_b; pthread_t threads[NTHREADS]; unsigned i, j; int val; ATF_REQUIRE_MSG(-1 != sysconf(_SC_SEMAPHORES), "%s", strerror(errno)); printf("Test begin\n"); SEM_REQUIRE(sem_init(&sem_b, 0, 0)); SEM_REQUIRE(sem_getvalue(&sem_b, &val)); ATF_REQUIRE_EQ(0, val); SEM_REQUIRE(sem_post(&sem_b)); SEM_REQUIRE(sem_getvalue(&sem_b, &val)); ATF_REQUIRE_EQ(1, val); SEM_REQUIRE(sem_wait(&sem_b)); ATF_REQUIRE_EQ(sem_trywait(&sem_b), -1); ATF_REQUIRE_EQ(errno, EAGAIN); SEM_REQUIRE(sem_post(&sem_b)); SEM_REQUIRE(sem_trywait(&sem_b)); SEM_REQUIRE(sem_post(&sem_b)); SEM_REQUIRE(sem_wait(&sem_b)); SEM_REQUIRE(sem_post(&sem_b)); SEM_REQUIRE(sem_destroy(&sem_b)); SEM_REQUIRE(sem_init(&sem_a, 0, 0)); for (j = 0; j < 2; j++) { for (i = 0; i < NTHREADS; i++) { PTHREAD_REQUIRE(pthread_create(&threads[i], NULL, entry, (void *) &sem_a)); } for (i = 0; i < NTHREADS; i++) { usleep(10000); printf("main loop %u: posting...\n", j+1); SEM_REQUIRE(sem_post(&sem_a)); } for (i = 0; i < NTHREADS; i++) { PTHREAD_REQUIRE(pthread_join(threads[i], NULL)); } } SEM_REQUIRE(sem_destroy(&sem_a)); printf("Test end\n"); } static void sighandler(int signo) { /* printf("signal %d\n", signo); */ ATF_REQUIRE_EQ_MSG(signo, SIGALRM, "unexpected signal"); SEM_REQUIRE(sem_post(&sem)); } static void alarm_ms(const int ms) { struct itimerval timer; timer.it_interval.tv_sec = 0; timer.it_interval.tv_usec = 0; timer.it_value.tv_sec = 0; timer.it_value.tv_usec = ms * 1000; ATF_REQUIRE(setitimer(ITIMER_REAL, &timer, NULL) == 0); } static void * threadfunc(void *arg) { int i, ret; printf("Entering loop\n"); for (i = 0; i < 500; ) { if ((i & 1) != 0) { do { ret = sem_wait(&sem); } while (ret == -1 && errno == EINTR); ATF_REQUIRE(ret == 0); } else { ret = sem_trywait(&sem); if (ret == -1) { ATF_REQUIRE(errno == EAGAIN); continue; } } printf("%s: %d\n", __func__, i); alarm_ms(5); i++; } return NULL; } static void before_start_test(const bool use_pthread) { pthread_t t; SEM_REQUIRE(sem_init(&sem, 0, 0)); ATF_REQUIRE(SIG_ERR != signal(SIGALRM, sighandler)); alarm_ms(5); if (use_pthread) { PTHREAD_REQUIRE(pthread_create(&t, NULL, threadfunc, NULL)); PTHREAD_REQUIRE(pthread_join(t, NULL)); } else { threadfunc(NULL); } } ATF_TC(before_start_no_threads); ATF_TC_HEAD(before_start_no_threads, tc) { atf_tc_set_md_var(tc, "descr", "Checks using semaphores without any " "thread running"); atf_tc_set_md_var(tc, "timeout", "40"); } ATF_TC_BODY(before_start_no_threads, tc) { before_start_test(false); } ATF_TC(before_start_one_thread); ATF_TC_HEAD(before_start_one_thread, tc) { atf_tc_set_md_var(tc, "descr", "Checks using semaphores before " "starting one thread"); atf_tc_set_md_var(tc, "timeout", "40"); } ATF_TC_BODY(before_start_one_thread, tc) { before_start_test(true); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, named); ATF_TP_ADD_TC(tp, unnamed); ATF_TP_ADD_TC(tp, before_start_no_threads); ATF_TP_ADD_TC(tp, before_start_one_thread); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_swapcontext.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_swapcontext.c (revision 312294) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libpthread/t_swapcontext.c (revision 312295) @@ -1,136 +1,126 @@ -/* $NetBSD: t_swapcontext.c,v 1.2 2014/08/25 16:31:15 bouyer Exp $ */ +/* $NetBSD: t_swapcontext.c,v 1.3 2017/01/16 16:27:06 christos Exp $ */ /* * Copyright (c) 2012 Emmanuel Dreyfus. 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"); -#ifdef __FreeBSD__ #include #include -#include -#endif #include -#include #include #include +#include +#include #include #include "h_common.h" #define STACKSIZE 65536 char stack[STACKSIZE]; ucontext_t nctx; ucontext_t octx; void *oself; void *nself; int val1, val2; /* ARGSUSED0 */ static void swapfunc(void *arg) { /* * If the test fails, we are very likely to crash * without the opportunity to report */ nself = (void *)pthread_self(); printf("after swapcontext self = %p\n", nself); ATF_REQUIRE_EQ(oself, nself); printf("Test succeeded\n"); /* Go back in main */ ATF_REQUIRE(swapcontext(&nctx, &octx)); /* NOTREACHED */ return; } /* ARGSUSED0 */ static void * threadfunc(void *arg) { nctx.uc_stack.ss_sp = stack; nctx.uc_stack.ss_size = sizeof(stack); makecontext(&nctx, (void *)*swapfunc, 0); oself = (void *)pthread_self(); printf("before swapcontext self = %p\n", oself); -#ifdef __FreeBSD__ ATF_REQUIRE_MSG(swapcontext(&octx, &nctx) != -1, "swapcontext failed: %s", strerror(errno)); -#else - PTHREAD_REQUIRE(swapcontext(&octx, &nctx)); -#endif /* NOTREACHED */ return NULL; } ATF_TC(swapcontext1); ATF_TC_HEAD(swapcontext1, tc) { atf_tc_set_md_var(tc, "descr", "Testing if swapcontext() " "alters pthread_self()"); } ATF_TC_BODY(swapcontext1, tc) { pthread_t thread; #if defined(__FreeBSD__) && defined(__mips__) /* * MIPS modifies TLS pointer in set_mcontext(), so * swapping contexts obtained from different threads * gives us different pthread_self() return value. */ atf_tc_skip("Platform is not supported."); #endif oself = (void *)&val1; nself = (void *)&val2; printf("Testing if swapcontext() alters pthread_self()\n"); -#ifdef __FreeBSD__ ATF_REQUIRE_MSG(getcontext(&nctx) != -1, "getcontext failed: %s", strerror(errno)); -#else - PTHREAD_REQUIRE(getcontext(&nctx)); -#endif PTHREAD_REQUIRE(pthread_create(&thread, NULL, threadfunc, NULL)); PTHREAD_REQUIRE(pthread_join(thread, NULL)); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, swapcontext1); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/net/carp/t_basic.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/net/carp/t_basic.c (revision 312294) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/net/carp/t_basic.c (nonexistent) @@ -1,221 +0,0 @@ -/* $NetBSD: t_basic.c,v 1.6 2017/01/13 21:30:42 christos Exp $ */ - -/*- - * Copyright (c) 2010 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 -#ifndef lint -__RCSID("$NetBSD: t_basic.c,v 1.6 2017/01/13 21:30:42 christos Exp $"); -#endif /* not lint */ - -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "../config/netconfig.c" -#include "h_macros.h" - -static bool oknow = false; - -static void -sighnd(int sig) -{ - - ATF_REQUIRE_EQ(sig, SIGCHLD); - if (oknow) - return; - - atf_tc_fail("child died unexpectedly"); -} - -ATF_TC(handover); -ATF_TC_HEAD(handover, tc) -{ - - atf_tc_set_md_var(tc, "descr", "check that carp handover works if " - "the master dies"); -} - -#define THEBUS "buuuuuuus,etherbus" - -static void -child(bool master) -{ - char ifname[IFNAMSIZ]; - struct carpreq cr; - struct ifreq ifr; - const char *carpif; - int s; - - /* helps reading carp debug output */ - if (master) - carpif = "carp0"; - else - carpif = "carp1"; - - /* - * Should use sysctl, bug debug is dabug. - */ - { - //extern int rumpns_carp_opts[]; /* XXX */ - //rumpns_carp_opts[CARPCTL_LOG] = 1; - } - - - rump_init(); - - memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, carpif, sizeof(ifr.ifr_name)); - - RL(s = rump_sys_socket(PF_INET, SOCK_DGRAM, 0)); - RL(rump_sys_ioctl(s, SIOCIFCREATE, &ifr)); - - netcfg_rump_makeshmif(THEBUS, ifname); - - if (master) - netcfg_rump_if(ifname, "10.1.1.1", "255.255.255.0"); - else - netcfg_rump_if(ifname, "10.1.1.2", "255.255.255.0"); - - /* configure the carp interface */ - ifr.ifr_data = &cr; - RL(rump_sys_ioctl(s, SIOCGVH, &ifr)); - - strlcpy(cr.carpr_carpdev, ifname, sizeof(cr.carpr_carpdev)); - cr.carpr_vhid = 175; - if (master) - cr.carpr_advskew = 0; - else - cr.carpr_advskew = 200; - cr.carpr_advbase = 1; - strcpy((char *)cr.carpr_key, "s3cret"); - - RL(rump_sys_ioctl(s, SIOCSVH, &ifr)); - netcfg_rump_if(carpif, "10.1.1.100", "255.255.255.0"); - - /* tassa pause()en enka muuta voi */ - pause(); -} - -ATF_TC_BODY(handover, tc) -{ - char ifname[IFNAMSIZ]; - pid_t mpid, cpid; - int i, status; - - signal(SIGCHLD, sighnd); - - /* fork master */ - switch (mpid = fork()) { - case -1: - atf_tc_fail_errno("fork failed"); - /*NOTREACHED*/ - case 0: - child(true); - /*NOTREACHED*/ - default: - break; - } - - usleep(500000); - - /* fork backup */ - switch (cpid = fork()) { - case -1: - kill(mpid, SIGKILL); - atf_tc_fail_errno("fork failed"); - /*NOTREACHED*/ - case 0: - child(false); - /*NOTREACHED*/ - default: - break; - } - - usleep(500000); - - rump_init(); - netcfg_rump_makeshmif(THEBUS, ifname); - netcfg_rump_if(ifname, "10.1.1.240", "255.255.255.0"); - - /* check that the primary addresses are up */ - ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.1", 1000), true); - ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.2", 1000), true); - - /* give carp a while to croak */ - sleep(4); - - /* check that the shared IP works */ - ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.100", 500), true); - - /* KILLING SPREE */ - oknow = true; - kill(mpid, SIGKILL); - wait(&status); - usleep(10000); /* just in case */ - oknow = false; - - /* check that primary is now dead */ - ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.1", 100), false); - - /* do it in installments. carp will cluck meanwhile */ - for (i = 0; i < 5; i++) { - if (netcfg_rump_pingtest("10.1.1.100", 1000) == true) - break; - } - if (i == 5) - atf_tc_fail("failed to failover"); - - /* to kill the child */ - oknow = true; - kill(cpid, SIGKILL); - - /* clean & done */ -} - -ATF_TP_ADD_TCS(tp) -{ - - ATF_TP_ADD_TC(tp, handover); - - return atf_no_error(); -} Property changes on: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/net/carp/t_basic.c ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/net/carp/t_basic.sh =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/net/carp/t_basic.sh (nonexistent) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/net/carp/t_basic.sh (revision 312295) @@ -0,0 +1,165 @@ +# $NetBSD: t_basic.sh,v 1.1 2017/01/16 08:18:11 ozaki-r Exp $ +# +# Copyright (c) 2017 Internet Initiative Japan 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. +# + +SOCK_CLIENT=unix://carp_client +SOCK_MASTER=unix://carp_master +SOCK_BACKUP=unix://carp_backup +BUS=bus_carp +IP_CLIENT=10.1.1.240 +IP_MASTER=10.1.1.1 +IP_BACKUP=10.1.1.2 +IP_CARP=10.1.1.100 +TIMEOUT=3 + +atf_test_case carp_handover cleanup + +carp_handover_head() +{ + + atf_set "descr" "Tests for CARP handover" + atf_set "require.progs" "rump_server" +} + +setup_carp() +{ + local sock=$1 + local master=$2 + local carpif= ip= advskew= + + if $master; then + carpif=carp0 + ip=$IP_MASTER + advskew=0 + else + carpif=carp1 + ip=$IP_BACKUP + advskew=200 + fi + + export RUMP_SERVER=$sock + atf_check -s exit:0 rump.ifconfig $carpif create + atf_check -s exit:0 rump.ifconfig shmif0 $ip/24 up + atf_check -s exit:0 rump.ifconfig $carpif \ + vhid 175 advskew $advskew advbase 1 pass s3cret \ + $IP_CARP netmask 255.255.255.0 + atf_check -s exit:0 rump.ifconfig -w 10 +} + +wait_handover() +{ + local i=0 + + export RUMP_SERVER=$SOCK_CLIENT + + while [ $i -ne 5 ]; do + $DEBUG && echo "Trying ping $IP_CARP" + rump.ping -n -w 1 -c 1 $IP_CARP >/dev/null + if [ $? = 0 ]; then + $DEBUG && echo "Passed ping $IP_CARP" + break; + fi + $DEBUG && echo "Failed ping $IP_CARP" + i=$((i + 1)) + done + + if [ $i -eq 5 ]; then + atf_fail "Failed to failover (5 sec)" + fi +} + +carp_handover_body() +{ + + rump_server_start $SOCK_CLIENT + rump_server_start $SOCK_MASTER + rump_server_start $SOCK_BACKUP + + rump_server_add_iface $SOCK_CLIENT shmif0 $BUS + rump_server_add_iface $SOCK_MASTER shmif0 $BUS + rump_server_add_iface $SOCK_BACKUP shmif0 $BUS + + setup_carp $SOCK_MASTER true + setup_carp $SOCK_BACKUP false + + export RUMP_SERVER=$SOCK_CLIENT + atf_check -s exit:0 rump.ifconfig shmif0 $IP_CLIENT/24 up + atf_check -s exit:0 rump.ifconfig -w 10 + + # Check that the primary addresses are up + atf_check -s exit:0 -o ignore \ + rump.ping -n -w $TIMEOUT -c 1 $IP_MASTER + atf_check -s exit:0 -o ignore \ + rump.ping -n -w $TIMEOUT -c 1 $IP_BACKUP + + # Give carp a while to croak + sleep 4 + + # Check state + export RUMP_SERVER=$SOCK_MASTER + $DEBUG && rump.ifconfig + atf_check -s exit:0 -o match:'carp: MASTER carpdev shmif0' \ + rump.ifconfig carp0 + export RUMP_SERVER=$SOCK_BACKUP + $DEBUG && rump.ifconfig + atf_check -s exit:0 -o match:'carp: BACKUP carpdev shmif0' \ + rump.ifconfig carp1 + export RUMP_SERVER=$SOCK_CLIENT + + # Check that the shared IP works + atf_check -s exit:0 -o ignore \ + rump.ping -n -w $TIMEOUT -c 1 $IP_CARP + + # KILLING SPREE + env RUMP_SERVER=$SOCK_MASTER rump.halt + sleep 1 + + # Check that primary is now dead + atf_check -s not-exit:0 -o ignore \ + rump.ping -n -w $TIMEOUT -c 1 $IP_MASTER + + # Do it in installments. carp will cluck meanwhile + wait_handover + + # Check state + export RUMP_SERVER=$SOCK_BACKUP + $DEBUG && rump.ifconfig + atf_check -s exit:0 -o match:'carp: MASTER carpdev shmif0' \ + rump.ifconfig carp1 +} + +carp_handover_cleanup() +{ + + $DEBUG && dump + cleanup +} + +atf_init_test_cases() +{ + + atf_add_test_case carp_handover +} Property changes on: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/net/carp/t_basic.sh ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests (revision 312294) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests (revision 312295) Property changes on: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /vendor/NetBSD/tests/dist:r312294