From 181439425f0bb490970e4e7022295f139d9988ad Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Sun, 15 Jan 2017 09:35:49 +0000 Subject: [PATCH 01/22] Pull in additional test changes accepted upstream as well as some additional testcases added in .../kernel/t_ptrace_wait.c --- kernel/t_mqueue.c | 10 +- kernel/t_ptrace_wait.c | 322 +++++++++++++++++++++++++++++++++- lib/libc/c063/t_mkfifoat.c | 17 +- lib/libc/gen/t_glob.c | 6 +- lib/libc/regex/t_regex_att.c | 17 +- lib/libc/setjmp/t_setjmp.c | 6 +- lib/libc/setjmp/t_threadjmp.c | 6 +- lib/libc/string/t_strlen.c | 7 +- lib/libc/sys/t_mincore.c | 11 +- lib/libc/sys/t_msync.c | 29 +-- lib/libc/sys/t_unlink.c | 9 +- lib/librt/t_sem.c | 18 +- usr.bin/grep/d_binary.out | 2 +- usr.bin/grep/t_grep.sh | 8 +- usr.sbin/mtree/t_mtree.sh | 16 +- 15 files changed, 408 insertions(+), 76 deletions(-) diff --git a/kernel/t_mqueue.c b/kernel/t_mqueue.c index 7206bc6ef917..c5c7ce3be0f2 100644 --- a/kernel/t_mqueue.c +++ b/kernel/t_mqueue.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_mqueue.c,v 1.5 2017/01/10 22:10:22 christos Exp $ */ +/* $NetBSD: t_mqueue.c,v 1.6 2017/01/14 20:57:24 christos Exp $ */ /* * Test for POSIX message queue priority handling. @@ -6,17 +6,17 @@ * This file is in the Public Domain. */ -#include #include +#include +#include +#include +#include #include #include #include -#include #include -#include - #define MQ_PRIO_BASE 24 static void diff --git a/kernel/t_ptrace_wait.c b/kernel/t_ptrace_wait.c index b1b4d1bef2c2..9d2edff4c3ec 100644 --- a/kernel/t_ptrace_wait.c +++ b/kernel/t_ptrace_wait.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.58 2017/01/14 04:37:55 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.60 2017/01/14 19:17:10 kamil Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.58 2017/01/14 04:37:55 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.60 2017/01/14 19:17:10 kamil Exp $"); #include #include @@ -39,6 +39,7 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.58 2017/01/14 04:37:55 kamil Exp $"); #include #include #include +#include #include #include #include @@ -1184,6 +1185,116 @@ ATF_TC_BODY(eventmask4, tc) TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); } +ATF_TC(eventmask5); +ATF_TC_HEAD(eventmask5, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Verify that PTRACE_LWP_CREATE in EVENT_MASK is preserved"); +} + +ATF_TC_BODY(eventmask5, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + ptrace_event_t set_event, get_event; + const int len = sizeof(ptrace_event_t); + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + set_event.pe_set_event = PTRACE_LWP_CREATE; + ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &set_event, len) != -1); + ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, child, &get_event, len) != -1); + ATF_REQUIRE(memcmp(&set_event, &get_event, len) == 0); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} + +ATF_TC(eventmask6); +ATF_TC_HEAD(eventmask6, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Verify that PTRACE_LWP_EXIT in EVENT_MASK is preserved"); +} + +ATF_TC_BODY(eventmask6, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + ptrace_event_t set_event, get_event; + const int len = sizeof(ptrace_event_t); + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + set_event.pe_set_event = PTRACE_LWP_EXIT; + ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &set_event, len) != -1); + ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, child, &get_event, len) != -1); + ATF_REQUIRE(memcmp(&set_event, &get_event, len) == 0); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} + #if defined(TWAIT_HAVE_PID) ATF_TC(fork1); ATF_TC_HEAD(fork1, tc) @@ -5286,6 +5397,207 @@ ATF_TC_BODY(siginfo6, tc) } #endif +volatile lwpid_t the_lwp_id = 0; + +static void +lwp_main_func(void *arg) +{ + the_lwp_id = _lwp_self(); + _lwp_exit(); +} + +ATF_TC(lwp_create1); +ATF_TC_HEAD(lwp_create1, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Verify that 1 LWP creation is intercepted by ptrace(2) with " + "EVENT_MASK set to PTRACE_LWP_CREATE"); +} + +ATF_TC_BODY(lwp_create1, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + ptrace_state_t state; + const int slen = sizeof(state); + ptrace_event_t event; + const int elen = sizeof(event); + ucontext_t uc; + lwpid_t lid; + static const size_t ssize = 16*1024; + void *stack; + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("Before allocating memory for stack in child\n"); + FORKEE_ASSERT((stack = malloc(ssize)) != NULL); + + printf("Before making context for new lwp in child\n"); + _lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize); + + printf("Before creating new in child\n"); + FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0); + + printf("Before waiting for lwp %d to exit\n", lid); + FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0); + + printf("Before verifying that reported %d and running lid %d " + "are the same\n", lid, the_lwp_id); + FORKEE_ASSERT_EQ(lid, the_lwp_id); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Set empty EVENT_MASK for the child %d\n", child); + event.pe_set_event = PTRACE_LWP_CREATE; + ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child - expected stopped " + "SIGTRAP\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, SIGTRAP); + + ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); + + ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_CREATE); + + lid = state.pe_lwp; + printf("Reported PTRACE_LWP_CREATE event with lid %d\n", lid); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child - expected exited\n", + TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child - expected no process\n", + TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} + +ATF_TC(lwp_exit1); +ATF_TC_HEAD(lwp_exit1, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Verify that 1 LWP creation is intercepted by ptrace(2) with " + "EVENT_MASK set to PTRACE_LWP_EXIT"); +} + +ATF_TC_BODY(lwp_exit1, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + ptrace_state_t state; + const int slen = sizeof(state); + ptrace_event_t event; + const int elen = sizeof(event); + ucontext_t uc; + lwpid_t lid; + static const size_t ssize = 16*1024; + void *stack; + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("Before allocating memory for stack in child\n"); + FORKEE_ASSERT((stack = malloc(ssize)) != NULL); + + printf("Before making context for new lwp in child\n"); + _lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize); + + printf("Before creating new in child\n"); + FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0); + + printf("Before waiting for lwp %d to exit\n", lid); + FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0); + + printf("Before verifying that reported %d and running lid %d " + "are the same\n", lid, the_lwp_id); + FORKEE_ASSERT_EQ(lid, the_lwp_id); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Set empty EVENT_MASK for the child %d\n", child); + event.pe_set_event = PTRACE_LWP_EXIT; + ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child - expected stopped " + "SIGTRAP\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, SIGTRAP); + + ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); + + ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_EXIT); + + lid = state.pe_lwp; + printf("Reported PTRACE_LWP_EXIT event with lid %d\n", lid); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child - expected exited\n", + TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child - expected no process\n", + TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} + ATF_TP_ADD_TCS(tp) { setvbuf(stdout, NULL, _IONBF, 0); @@ -5307,6 +5619,8 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, eventmask2); ATF_TP_ADD_TC(tp, eventmask3); ATF_TP_ADD_TC(tp, eventmask4); + ATF_TP_ADD_TC(tp, eventmask5); + ATF_TP_ADD_TC(tp, eventmask6); ATF_TP_ADD_TC_HAVE_PID(tp, fork1); ATF_TP_ADD_TC(tp, fork2); @@ -5380,5 +5694,9 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC_HAVE_PID(tp, siginfo5); ATF_TP_ADD_TC_PT_STEP(tp, siginfo6); + ATF_TP_ADD_TC(tp, lwp_create1); + + ATF_TP_ADD_TC(tp, lwp_exit1); + return atf_no_error(); } diff --git a/lib/libc/c063/t_mkfifoat.c b/lib/libc/c063/t_mkfifoat.c index 5c496c8d0987..4f91afd979a7 100644 --- a/lib/libc/c063/t_mkfifoat.c +++ b/lib/libc/c063/t_mkfifoat.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_mkfifoat.c,v 1.3 2017/01/10 15:15:09 christos Exp $ */ +/* $NetBSD: t_mkfifoat.c,v 1.4 2017/01/14 20:55:26 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_mkfifoat.c,v 1.3 2017/01/10 15:15:09 christos Exp $"); +__RCSID("$NetBSD: t_mkfifoat.c,v 1.4 2017/01/14 20:55:26 christos Exp $"); #include #include @@ -55,13 +55,11 @@ ATF_TC_HEAD(mkfifoat_fd, tc) ATF_TC_BODY(mkfifoat_fd, tc) { int dfd; - int fd; mode_t mode = 0600; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); - ATF_REQUIRE((fd = mkfifoat(dfd, BASEFIFO, mode)) != -1); - ATF_REQUIRE(close(fd) == 0); + ATF_REQUIRE(mkfifoat(dfd, BASEFIFO, mode) != -1); ATF_REQUIRE(access(FIFO, F_OK) == 0); (void)close(dfd); } @@ -74,12 +72,10 @@ ATF_TC_HEAD(mkfifoat_fdcwd, tc) } ATF_TC_BODY(mkfifoat_fdcwd, tc) { - int fd; mode_t mode = 0600; ATF_REQUIRE(mkdir(DIR, 0755) == 0); - ATF_REQUIRE((fd = mkfifoat(AT_FDCWD, FIFO, mode)) != -1); - ATF_REQUIRE(close(fd) == 0); + ATF_REQUIRE(mkfifoat(AT_FDCWD, FIFO, mode) != -1); ATF_REQUIRE(access(FIFO, F_OK) == 0); } @@ -91,10 +87,9 @@ ATF_TC_HEAD(mkfifoat_fdcwderr, tc) } ATF_TC_BODY(mkfifoat_fdcwderr, tc) { - int fd; mode_t mode = 0600; - ATF_REQUIRE((fd = mkfifoat(AT_FDCWD, FIFOERR, mode)) == -1); + ATF_REQUIRE(mkfifoat(AT_FDCWD, FIFOERR, mode) == -1); } ATF_TC(mkfifoat_fderr); @@ -110,7 +105,7 @@ ATF_TC_BODY(mkfifoat_fderr, tc) ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE((fd = open(FIFO, O_CREAT|O_RDWR, 0644)) != -1); ATF_REQUIRE(close(fd) == 0); - ATF_REQUIRE((fd = mkfifoat(-1, FIFO, mode)) == -1); + ATF_REQUIRE(mkfifoat(-1, FIFO, mode) == -1); } ATF_TP_ADD_TCS(tp) diff --git a/lib/libc/gen/t_glob.c b/lib/libc/gen/t_glob.c index d741d939a43d..7eed624b4aef 100644 --- a/lib/libc/gen/t_glob.c +++ b/lib/libc/gen/t_glob.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_glob.c,v 1.4 2017/01/13 21:30:41 christos Exp $ */ +/* $NetBSD: t_glob.c,v 1.5 2017/01/14 20:47:41 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. * All rights reserved. @@ -32,7 +32,7 @@ */ #include -__RCSID("$NetBSD: t_glob.c,v 1.4 2017/01/13 21:30:41 christos Exp $"); +__RCSID("$NetBSD: t_glob.c,v 1.5 2017/01/14 20:47:41 christos Exp $"); #include @@ -146,7 +146,7 @@ gl_stat(const char *name , __gl_stat_t *st) memset(st, 0, sizeof(*st)); if (strcmp(buf, "a") == 0 || strcmp(buf, "a/b") == 0) { - st->st_mode |= _S_IFDIR; + st->st_mode |= S_IFDIR; return 0; } diff --git a/lib/libc/regex/t_regex_att.c b/lib/libc/regex/t_regex_att.c index 0425b6f2c58c..dd5b818a1ef3 100644 --- a/lib/libc/regex/t_regex_att.c +++ b/lib/libc/regex/t_regex_att.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_regex_att.c,v 1.2 2017/01/14 00:50:56 christos Exp $ */ +/* $NetBSD: t_regex_att.c,v 1.3 2017/01/14 20:59:23 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -37,17 +37,18 @@ */ #include -__RCSID("$NetBSD: t_regex_att.c,v 1.2 2017/01/14 00:50:56 christos Exp $"); +__RCSID("$NetBSD: t_regex_att.c,v 1.3 2017/01/14 20:59:23 christos Exp $"); #include -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include static const char sep[] = "\r\n\t"; static const char delim[3] = "\\\\\0"; diff --git a/lib/libc/setjmp/t_setjmp.c b/lib/libc/setjmp/t_setjmp.c index 4d2a93bab004..1f0f1ed5ea89 100644 --- a/lib/libc/setjmp/t_setjmp.c +++ b/lib/libc/setjmp/t_setjmp.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_setjmp.c,v 1.1 2010/12/27 19:35:31 pgoyette Exp $ */ +/* $NetBSD: t_setjmp.c,v 1.2 2017/01/14 21:08:17 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_setjmp.c,v 1.1 2010/12/27 19:35:31 pgoyette Exp $"); +__RCSID("$NetBSD: t_setjmp.c,v 1.2 2017/01/14 21:08:17 christos Exp $"); #include @@ -87,7 +87,7 @@ __RCSID("$NetBSD: t_setjmp.c,v 1.1 2010/12/27 19:35:31 pgoyette Exp $"); static int expectsignal; static void -aborthandler(int signo) +aborthandler(int signo __unused) { ATF_REQUIRE_MSG(expectsignal, "kill(SIGABRT) succeeded"); atf_tc_pass(); diff --git a/lib/libc/setjmp/t_threadjmp.c b/lib/libc/setjmp/t_threadjmp.c index 4437c927214e..44d7555c0b16 100644 --- a/lib/libc/setjmp/t_threadjmp.c +++ b/lib/libc/setjmp/t_threadjmp.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_threadjmp.c,v 1.1 2011/04/21 18:58:20 martin Exp $ */ +/* $NetBSD: t_threadjmp.c,v 1.2 2017/01/14 21:08:17 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_threadjmp.c,v 1.1 2011/04/21 18:58:20 martin Exp $"); +__RCSID("$NetBSD: t_threadjmp.c,v 1.2 2017/01/14 21:08:17 christos Exp $"); #include @@ -91,7 +91,7 @@ static pthread_t myself = NULL; static int expectsignal; static void -aborthandler(int signo) +aborthandler(int signo __unused) { ATF_REQUIRE(myself == pthread_self()); ATF_REQUIRE_MSG(expectsignal, "kill(SIGABRT) succeeded"); diff --git a/lib/libc/string/t_strlen.c b/lib/libc/string/t_strlen.c index 66158fd7113f..9899e6d5944c 100644 --- a/lib/libc/string/t_strlen.c +++ b/lib/libc/string/t_strlen.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_strlen.c,v 1.5 2011/07/14 07:33:20 jruoho Exp $ */ +/* $NetBSD: t_strlen.c,v 1.6 2017/01/14 20:49:24 christos Exp $ */ /* * Written by J.T. Conklin @@ -40,6 +40,7 @@ ATF_TC_HEAD(strlen_basic, tc) ATF_TC_BODY(strlen_basic, tc) { + void *dl_handle; /* try to trick the compiler */ size_t (*strlen_fn)(const char *); @@ -107,7 +108,8 @@ ATF_TC_BODY(strlen_basic, tc) * During testing it is useful have the rest of the program * use a known good version! */ - strlen_fn = dlsym(dlopen(NULL, RTLD_LAZY), "test_strlen"); + dl_handle = dlopen(NULL, RTLD_LAZY); + strlen_fn = dlsym(dl_handle, "test_strlen"); if (!strlen_fn) strlen_fn = strlen; @@ -134,6 +136,7 @@ ATF_TC_BODY(strlen_basic, tc) } } } + (void)dlclose(dl_handle); } ATF_TC(strlen_huge); diff --git a/lib/libc/sys/t_mincore.c b/lib/libc/sys/t_mincore.c index 431970953e19..e61c80e938ee 100644 --- a/lib/libc/sys/t_mincore.c +++ b/lib/libc/sys/t_mincore.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_mincore.c,v 1.9 2017/01/10 22:36:29 christos Exp $ */ +/* $NetBSD: t_mincore.c,v 1.10 2017/01/14 20:51:13 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -59,7 +59,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_mincore.c,v 1.9 2017/01/10 22:36:29 christos Exp $"); +__RCSID("$NetBSD: t_mincore.c,v 1.10 2017/01/14 20:51:13 christos Exp $"); #include #include @@ -139,6 +139,7 @@ ATF_TC_WITH_CLEANUP(mincore_resid); ATF_TC_HEAD(mincore_resid, tc) { atf_tc_set_md_var(tc, "descr", "Test page residency with mincore(2)"); + atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(mincore_resid, tc) @@ -150,6 +151,11 @@ ATF_TC_BODY(mincore_resid, tc) struct rlimit rlim; ATF_REQUIRE(getrlimit(RLIMIT_MEMLOCK, &rlim) == 0); + /* + * Bump the mlock limit to unlimited so the rest of the testcase + * passes instead of failing on the mlock call. + */ + rlim.rlim_max = RLIM_INFINITY; rlim.rlim_cur = rlim.rlim_max; ATF_REQUIRE(setrlimit(RLIMIT_MEMLOCK, &rlim) == 0); @@ -250,6 +256,7 @@ ATF_TC_BODY(mincore_resid, tc) (void)munmap(addr2, npgs * page); (void)munmap(addr3, npgs * page); (void)unlink(path); + free(buf); } ATF_TC_CLEANUP(mincore_resid, tc) diff --git a/lib/libc/sys/t_msync.c b/lib/libc/sys/t_msync.c index 974330080604..5dfc2f0c56f1 100644 --- a/lib/libc/sys/t_msync.c +++ b/lib/libc/sys/t_msync.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_msync.c,v 1.2 2012/03/16 06:15:17 matt Exp $ */ +/* $NetBSD: t_msync.c,v 1.3 2017/01/14 20:52:42 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_msync.c,v 1.2 2012/03/16 06:15:17 matt Exp $"); +__RCSID("$NetBSD: t_msync.c,v 1.3 2017/01/14 20:52:42 christos Exp $"); #include @@ -52,8 +52,7 @@ msync_sync(const char *garbage, int flags) { char *buf, *map = MAP_FAILED; const char *str = NULL; - size_t i, len; - ssize_t tot; + size_t len; int fd, rv; /* @@ -65,29 +64,17 @@ msync_sync(const char *garbage, int flags) if (buf == NULL) return NULL; - for (i = 0; i < (size_t)page; i++) - buf[i] = 'x'; + memset(buf, 'x', page); fd = open(path, O_RDWR | O_CREAT, 0700); if (fd < 0) { - str = "failed to open"; - goto out; + free(buf); + return "failed to open"; } - tot = 0; - - while (tot < page) { - - rv = write(fd, buf, sizeof(buf)); - - if (rv < 0) { - str = "failed to write"; - goto out; - } - - tot += rv; - } + ATF_REQUIRE_MSG(write(fd, buf, page) != -1, "write(2) failed: %s", + strerror(errno)); map = mmap(NULL, page, PROT_READ | PROT_WRITE, MAP_FILE|MAP_PRIVATE, fd, 0); diff --git a/lib/libc/sys/t_unlink.c b/lib/libc/sys/t_unlink.c index 6b05a0859b08..aee665c8a2e2 100644 --- a/lib/libc/sys/t_unlink.c +++ b/lib/libc/sys/t_unlink.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_unlink.c,v 1.3 2017/01/13 19:33:03 christos Exp $ */ +/* $NetBSD: t_unlink.c,v 1.4 2017/01/14 20:55:26 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_unlink.c,v 1.3 2017/01/13 19:33:03 christos Exp $"); +__RCSID("$NetBSD: t_unlink.c,v 1.4 2017/01/14 20:55:26 christos Exp $"); #include @@ -107,11 +107,8 @@ ATF_TC_HEAD(unlink_fifo, tc) ATF_TC_BODY(unlink_fifo, tc) { - int fd; - ATF_REQUIRE_MSG((fd = mkfifo(path, 0666)) == 0, - "mkfifo failed: %s", strerror(errno)); - (void)close(fd); + ATF_REQUIRE(mkfifo(path, 0666) == 0); ATF_REQUIRE(unlink(path) == 0); errno = 0; diff --git a/lib/librt/t_sem.c b/lib/librt/t_sem.c index b6fc4dbf197b..0541ae57113a 100644 --- a/lib/librt/t_sem.c +++ b/lib/librt/t_sem.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_sem.c,v 1.2 2010/11/08 13:05:49 njoly Exp $ */ +/* $NetBSD: t_sem.c,v 1.3 2017/01/14 20:58:20 christos Exp $ */ /* * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. @@ -58,7 +58,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008, 2010\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_sem.c,v 1.2 2010/11/08 13:05:49 njoly Exp $"); +__RCSID("$NetBSD: t_sem.c,v 1.3 2017/01/14 20:58:20 christos Exp $"); #include @@ -72,7 +72,7 @@ __RCSID("$NetBSD: t_sem.c,v 1.2 2010/11/08 13:05:49 njoly Exp $"); #define NCHILDREN 10 -ATF_TC(basic); +ATF_TC_WITH_CLEANUP(basic); ATF_TC_HEAD(basic, tc) { atf_tc_set_md_var(tc, "descr", "Checks basic functionality of POSIX " @@ -108,8 +108,12 @@ ATF_TC_BODY(basic, tc) ATF_REQUIRE_EQ(sem_close(sem_b), 0); ATF_REQUIRE_EQ(sem_unlink("/sem_b"), 0); } +ATF_TC_CLEANUP(basic, tc) +{ + (void)sem_unlink("/sem_b"); +} -ATF_TC(child); +ATF_TC_WITH_CLEANUP(child); ATF_TC_HEAD(child, tc) { atf_tc_set_md_var(tc, "descr", "Checks using semaphores to synchronize " @@ -124,7 +128,7 @@ ATF_TC_BODY(child, tc) pid_t pid; - if (sysconf(_SC_SEMAPHORES) == -1) + if (sysconf(_SC_SEMAPHORES) == -1) atf_tc_skip("POSIX semaphores not supported"); sem_a = sem_open("/sem_a", O_CREAT | O_EXCL, 0644, 0); @@ -164,6 +168,10 @@ ATF_TC_BODY(child, tc) ATF_REQUIRE_EQ(sem_close(sem_a), 0); ATF_REQUIRE_EQ(sem_unlink("/sem_a"), 0); } +ATF_TC_CLEANUP(child, tc) +{ + (void)sem_unlink("/sem_a"); +} ATF_TP_ADD_TCS(tp) { diff --git a/usr.bin/grep/d_binary.out b/usr.bin/grep/d_binary.out index ce030561340d..f0ef9880d6d5 100644 --- a/usr.bin/grep/d_binary.out +++ b/usr.bin/grep/d_binary.out @@ -1 +1 @@ -Binary file /bin/sh matches +Binary file test.file matches diff --git a/usr.bin/grep/t_grep.sh b/usr.bin/grep/t_grep.sh index f2d70f08bded..558b074ad4b3 100755 --- a/usr.bin/grep/t_grep.sh +++ b/usr.bin/grep/t_grep.sh @@ -1,4 +1,4 @@ -# $NetBSD: t_grep.sh,v 1.2 2013/05/17 15:39:17 christos Exp $ +# $NetBSD: t_grep.sh,v 1.3 2017/01/14 20:43:52 christos Exp $ # # Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. # All rights reserved. @@ -43,7 +43,9 @@ binary_head() } binary_body() { - atf_check -o file:"$(atf_get_srcdir)/d_binary.out" grep $(uname) /bin/sh + dd if=/dev/zero count=1 of=test.file + echo -n "foobar" >> test.file + atf_check -o file:"$(atf_get_srcdir)/d_binary.out" grep foobar test.file } atf_test_case recurse @@ -57,7 +59,7 @@ recurse_body() echo -e "cod\ndover sole\nhaddock\nhalibut\npilchard" > recurse/d/fish echo -e "cod\nhaddock\nplaice" > recurse/a/f/favourite-fish - atf_check -o file:"$(atf_get_srcdir)/d_recurse.out" grep -r haddock recurse + atf_check -o file:"$(atf_get_srcdir)/d_recurse.out" -x "grep -r haddock recurse | sort" } atf_test_case recurse_symlink diff --git a/usr.sbin/mtree/t_mtree.sh b/usr.sbin/mtree/t_mtree.sh index 20fda75e02ea..58fc7db6155b 100755 --- a/usr.sbin/mtree/t_mtree.sh +++ b/usr.sbin/mtree/t_mtree.sh @@ -1,4 +1,4 @@ -# $NetBSD: t_mtree.sh,v 1.6 2013/02/05 16:49:42 christos Exp $ +# $NetBSD: t_mtree.sh,v 1.7 2017/01/14 20:45:16 christos Exp $ # # Copyright (c) 2009, 2012 The NetBSD Foundation, Inc. # All rights reserved. @@ -284,6 +284,13 @@ ignore_head() ignore_body() { + # Kyua 0.11 and above point TMPDIR to our work directory and atf-check + # generates a temporary file, which confuses mtree. Put the mtree files + # into a subdirectory. + # + # See https://github.com/jmmv/kyua/issues/133 for details. + mkdir root && cd root + mkdir newdir mtree -F ${FLAVOR} -c | mtree -F ${FLAVOR} -Ck uid,gid,mode > mtree.spec ln -s newdir otherdir @@ -313,6 +320,13 @@ mtree_ignore_body() } netbsd6_ignore_body() { + # Kyua 0.11 and above point TMPDIR to our work directory and atf-check + # generates a temporary file, which confuses mtree. Put the mtree files + # into a subdirectory. + # + # See https://github.com/jmmv/kyua/issues/133 for details. + mkdir root && cd root + FLAVOR=netbsd6 ignore_body } From be996c05224c3d82f26f94315c760776c3f2896c Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Sun, 15 Jan 2017 10:03:03 +0000 Subject: [PATCH 02/22] Add -DSKIP_LEFTASSOC to CFLAGS so leftassoc is skipped, like on NetBSD --- lib/libc/tests/regex/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/libc/tests/regex/Makefile b/lib/libc/tests/regex/Makefile index c4f43512623d..b16f503c65f1 100644 --- a/lib/libc/tests/regex/Makefile +++ b/lib/libc/tests/regex/Makefile @@ -6,7 +6,8 @@ PACKAGE= tests BINDIR= ${TESTSDIR} -IMPLEMENTATION?= -DREGEX_SPENCER +# SKIP_LEFTASSOC -> these testcases fail on FreeBSD. +IMPLEMENTATION?= -DREGEX_SPENCER -DSKIP_LEFTASSOC CFLAGS.h_regex+=-I${TESTSRC} -I${.CURDIR:H:H}/regex PROGS+= h_regex From 6b0a2ac186612568bfcd459666df30ad4c1e8aec Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Sun, 15 Jan 2017 10:16:20 +0000 Subject: [PATCH 03/22] libnetbsd: add compat header for glob.h This is to diff reduce unnecessary additions to contrib/netbsd-tests/lib/libc/gen/t_glob.c --- lib/libnetbsd/glob.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lib/libnetbsd/glob.h diff --git a/lib/libnetbsd/glob.h b/lib/libnetbsd/glob.h new file mode 100644 index 000000000000..ac33716775e7 --- /dev/null +++ b/lib/libnetbsd/glob.h @@ -0,0 +1,42 @@ +/* $FreeBSD$ */ + +/*- + * Copyright (c) 2012 SRI International + * All rights reserved. + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) + * ("CTSRD"), as part of the DARPA CRASH research programme. + * + * 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. + */ + +#ifndef _LIBNETBSD_GLOB_H_ +#define _LIBNETBSD_GLOB_H_ + +#include_next + +#ifndef __gl_stat_t +#define __gl_stat_t struct stat +#endif + +#endif /* _SHA1_H_ */ From caeb04e465518fd938ccb73a899eb99c64934b9b Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Sun, 15 Jan 2017 10:17:15 +0000 Subject: [PATCH 04/22] lib/libc/gen/t_glob.c: diff reduce with NetBSD's copy --- contrib/netbsd-tests/lib/libc/gen/t_glob.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/contrib/netbsd-tests/lib/libc/gen/t_glob.c b/contrib/netbsd-tests/lib/libc/gen/t_glob.c index 573ba7fb4b9d..a2d9bcfba707 100644 --- a/contrib/netbsd-tests/lib/libc/gen/t_glob.c +++ b/contrib/netbsd-tests/lib/libc/gen/t_glob.c @@ -48,10 +48,6 @@ __RCSID("$NetBSD: t_glob.c,v 1.5 2017/01/14 20:47:41 christos Exp $"); #include "h_macros.h" -#ifdef __FreeBSD__ -#define __gl_stat_t struct stat -#endif - #ifdef DEBUG #define DPRINTF(a) printf a From 9a2036bd1db8cc528762c6356bbdfecc146b36c0 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Sun, 15 Jan 2017 10:24:45 +0000 Subject: [PATCH 05/22] Fix copy-pasted copyright - Add Dell instead of "SRI International" - Use standard BSD 2-clause copyright - Remove DARPA sponsorship advertisement --- lib/libnetbsd/glob.h | 45 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/lib/libnetbsd/glob.h b/lib/libnetbsd/glob.h index ac33716775e7..580038b24531 100644 --- a/lib/libnetbsd/glob.h +++ b/lib/libnetbsd/glob.h @@ -1,33 +1,30 @@ -/* $FreeBSD$ */ - /*- - * Copyright (c) 2012 SRI International + * Copyright (c) 2017 Dell, Inc. * All rights reserved. * - * This software was developed by SRI International and the University of - * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) - * ("CTSRD"), as part of the DARPA CRASH research programme. - * * 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. + * modification, are permitted provided that the following conditions are met: * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * 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 COPYRIGHT HOLDERS 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. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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. + * + * $FreeBSD$ */ #ifndef _LIBNETBSD_GLOB_H_ From eec0029f966ca194862bbcec3b1b8b8de701fd24 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Sun, 15 Jan 2017 21:18:58 +0000 Subject: [PATCH 06/22] libnetbsd: more portability fixes with stdio.h and util.h - stdio.h needs to pull in stdio.h/util.h for fparseln, not util.h - util.h needs to #include sys/types.h for flags_to_string, etc as flags_to_string uses u_long, which is typedef'ed in sys/types.h on FreeBSD --- lib/libnetbsd/stdio.h | 37 +++++++++++++++++++++++++++++++++++++ lib/libnetbsd/util.h | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 lib/libnetbsd/stdio.h diff --git a/lib/libnetbsd/stdio.h b/lib/libnetbsd/stdio.h new file mode 100644 index 000000000000..ccd97cd7c8a0 --- /dev/null +++ b/lib/libnetbsd/stdio.h @@ -0,0 +1,37 @@ +/*- + * Copyright (c) 2017 Dell, 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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. + * + * $FreeBSD$ + */ + +#ifndef _LIBNETBSD_STDIO_H_ +#define _LIBNETBSD_STDIO_H_ + +#include_next + +#include "util.h" + +#endif /* _SHA1_H_ */ diff --git a/lib/libnetbsd/util.h b/lib/libnetbsd/util.h index a2e59b0ed52e..5cb017cebe3b 100644 --- a/lib/libnetbsd/util.h +++ b/lib/libnetbsd/util.h @@ -33,7 +33,7 @@ #ifndef _LIBNETBSD_UTIL_H_ #define _LIBNETBSD_UTIL_H_ -#include /* for fparseln(3) */ +#include #include char *flags_to_string(u_long flags, const char *def); From bfb8e4c9c4f79aab962f9982acc62e7fcc1da9a3 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Sun, 15 Jan 2017 21:38:19 +0000 Subject: [PATCH 07/22] Remove libutil.h #include on FreeBSD and instead favor stdio.h from libnetbsd --- contrib/netbsd-tests/lib/libc/stdlib/h_getopt.c | 3 --- contrib/netbsd-tests/lib/libc/stdlib/h_getopt_long.c | 3 --- 2 files changed, 6 deletions(-) diff --git a/contrib/netbsd-tests/lib/libc/stdlib/h_getopt.c b/contrib/netbsd-tests/lib/libc/stdlib/h_getopt.c index ec2b9bbf3d52..074e4ddf3b2d 100644 --- a/contrib/netbsd-tests/lib/libc/stdlib/h_getopt.c +++ b/contrib/netbsd-tests/lib/libc/stdlib/h_getopt.c @@ -34,9 +34,6 @@ #include #include #include -#ifdef __FreeBSD__ -#include -#endif #define WS "\t\n " #define debug 0 diff --git a/contrib/netbsd-tests/lib/libc/stdlib/h_getopt_long.c b/contrib/netbsd-tests/lib/libc/stdlib/h_getopt_long.c index 2293e2cc9576..17258f5fef91 100644 --- a/contrib/netbsd-tests/lib/libc/stdlib/h_getopt_long.c +++ b/contrib/netbsd-tests/lib/libc/stdlib/h_getopt_long.c @@ -36,9 +36,6 @@ #include #include #include -#ifdef __FreeBSD__ -#include -#endif #define SKIPWS(p) while (isspace((int)(*p))) p++ #define WS "\t\n " From 6b9e8e4eb210551e46142ccd7eed9d7c29902d67 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Sun, 15 Jan 2017 21:52:33 +0000 Subject: [PATCH 08/22] libnetbsd: add sys/wait.h compat header This just defines wrusage to __wrusage for now (they're both structs). --- lib/libnetbsd/sys/wait.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 lib/libnetbsd/sys/wait.h diff --git a/lib/libnetbsd/sys/wait.h b/lib/libnetbsd/sys/wait.h new file mode 100644 index 000000000000..a9369808d8e5 --- /dev/null +++ b/lib/libnetbsd/sys/wait.h @@ -0,0 +1,37 @@ +/*- + * Copyright (c) 2017 Dell, 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 REGENTS 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 REGENTS 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. + * + * $FreeBSD$ * + */ + +#ifndef _LIBNETBSD_SYS_WAIT_H_ +#define _LIBNETBSD_SYS_WAIT_H_ + +#include_next + +#define wrusage __wrusage + +#endif From 897afca52c514b5c09569a7e1af5036a97db3eb7 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Sun, 15 Jan 2017 21:53:11 +0000 Subject: [PATCH 09/22] libnetbsd: add sys/types.h header which pollutes itself with sys/param.h to pick up NBBY, etc --- lib/libnetbsd/sys/types.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 lib/libnetbsd/sys/types.h diff --git a/lib/libnetbsd/sys/types.h b/lib/libnetbsd/sys/types.h new file mode 100644 index 000000000000..e14dd498fe4b --- /dev/null +++ b/lib/libnetbsd/sys/types.h @@ -0,0 +1,37 @@ +/*- + * Copyright (c) 2017 Dell, 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 REGENTS 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 REGENTS 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. + * + * $FreeBSD$ * + */ + +#ifndef _LIBNETBSD_SYS_TYPES_H_ +#define _LIBNETBSD_SYS_TYPES_H_ + +#include_next + +#include /* For NBBY */ + +#endif From 8a979e7ad72d9e37843740f7b54dd487f8bdfc6d Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Sun, 15 Jan 2017 22:00:30 +0000 Subject: [PATCH 10/22] libnetbsd: add sys/event.h compat header This adds in necessary sys/types.h pollution for uintptr_t used in sys/event.h, which according to kqueue(2) on NetBSD isn't necessary. --- lib/libnetbsd/sys/event.h | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lib/libnetbsd/sys/event.h diff --git a/lib/libnetbsd/sys/event.h b/lib/libnetbsd/sys/event.h new file mode 100644 index 000000000000..88a363c8bfc5 --- /dev/null +++ b/lib/libnetbsd/sys/event.h @@ -0,0 +1,42 @@ +/*- + * Copyright (c) 2017 Dell, 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 REGENTS 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 REGENTS 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. + * + * $FreeBSD$ * + */ + +#ifndef _LIBNETBSD_SYS_EVENT_H_ +#define _LIBNETBSD_SYS_EVENT_H_ + +/* + * kqueue on FreeBSD requires sys/event.h, which in turn uses uintptr_t + * (defined in sys/types.h), so in order to accomodate their requirements, + * pull in sys/types.h as part of event.h. + */ +#include + +#include_next + +#endif From 6a93de28a67b95982bef04718a63eb90739e31cc Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Sun, 15 Jan 2017 22:00:59 +0000 Subject: [PATCH 11/22] Diff reduce with upstream and consolidate #ifdefs where possible --- contrib/netbsd-tests/kernel/kqueue/t_proc2.c | 3 --- contrib/netbsd-tests/kernel/kqueue/t_proc3.c | 3 --- contrib/netbsd-tests/kernel/kqueue/t_sig.c | 3 --- contrib/netbsd-tests/kernel/kqueue/t_vnode.c | 3 --- contrib/netbsd-tests/lib/libc/gen/t_sleep.c | 4 ---- contrib/netbsd-tests/lib/libc/sys/t_kevent.c | 6 ++---- contrib/netbsd-tests/lib/libc/sys/t_mmap.c | 6 ++---- contrib/netbsd-tests/lib/libc/sys/t_wait.c | 4 ---- contrib/netbsd-tests/lib/libc/sys/t_wait_noproc.c | 3 --- 9 files changed, 4 insertions(+), 31 deletions(-) diff --git a/contrib/netbsd-tests/kernel/kqueue/t_proc2.c b/contrib/netbsd-tests/kernel/kqueue/t_proc2.c index 5630df7bcd6c..2d905ed740d9 100644 --- a/contrib/netbsd-tests/kernel/kqueue/t_proc2.c +++ b/contrib/netbsd-tests/kernel/kqueue/t_proc2.c @@ -34,9 +34,6 @@ __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 diff --git a/contrib/netbsd-tests/kernel/kqueue/t_proc3.c b/contrib/netbsd-tests/kernel/kqueue/t_proc3.c index 4822957868e4..6def4094b1bf 100644 --- a/contrib/netbsd-tests/kernel/kqueue/t_proc3.c +++ b/contrib/netbsd-tests/kernel/kqueue/t_proc3.c @@ -32,9 +32,6 @@ #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 diff --git a/contrib/netbsd-tests/kernel/kqueue/t_sig.c b/contrib/netbsd-tests/kernel/kqueue/t_sig.c index dd6bc3e4355e..12e3d6115586 100644 --- a/contrib/netbsd-tests/kernel/kqueue/t_sig.c +++ b/contrib/netbsd-tests/kernel/kqueue/t_sig.c @@ -34,9 +34,6 @@ __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 diff --git a/contrib/netbsd-tests/kernel/kqueue/t_vnode.c b/contrib/netbsd-tests/kernel/kqueue/t_vnode.c index abb75743071d..e87c2b2c2d6f 100644 --- a/contrib/netbsd-tests/kernel/kqueue/t_vnode.c +++ b/contrib/netbsd-tests/kernel/kqueue/t_vnode.c @@ -1,6 +1,3 @@ -#ifdef __FreeBSD__ -#include /* for kqueue(2) */ -#endif #include #include #include diff --git a/contrib/netbsd-tests/lib/libc/gen/t_sleep.c b/contrib/netbsd-tests/lib/libc/gen/t_sleep.c index e85867a3f4c1..d4bd2713e520 100644 --- a/contrib/netbsd-tests/lib/libc/gen/t_sleep.c +++ b/contrib/netbsd-tests/lib/libc/gen/t_sleep.c @@ -26,10 +26,6 @@ * 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 diff --git a/contrib/netbsd-tests/lib/libc/sys/t_kevent.c b/contrib/netbsd-tests/lib/libc/sys/t_kevent.c index 8b649ca39dfc..5bddea5db746 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_kevent.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_kevent.c @@ -45,16 +45,14 @@ __RCSID("$NetBSD: t_kevent.c,v 1.7 2015/02/05 13:55:37 isaki Exp $"); #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) { diff --git a/contrib/netbsd-tests/lib/libc/sys/t_mmap.c b/contrib/netbsd-tests/lib/libc/sys/t_mmap.c index 33adcf2e0fee..2d46448f30e1 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_mmap.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_mmap.c @@ -75,11 +75,9 @@ __RCSID("$NetBSD: t_mmap.c,v 1.11 2017/01/13 20:43:11 christos Exp $"); #include #ifdef __NetBSD__ #include -#endif - -#ifdef __FreeBSD__ -#include +#else #include +#include #endif static long page = 0; diff --git a/contrib/netbsd-tests/lib/libc/sys/t_wait.c b/contrib/netbsd-tests/lib/libc/sys/t_wait.c index 9f749cb2daae..91bbaf1f3dd1 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_wait.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_wait.c @@ -45,10 +45,6 @@ __RCSID("$NetBSD: t_wait.c,v 1.8 2017/01/13 19:28:55 christos Exp $"); #include -#ifdef __FreeBSD__ -#define wrusage __wrusage -#endif - ATF_TC(wait6_invalid); ATF_TC_HEAD(wait6_invalid, tc) { diff --git a/contrib/netbsd-tests/lib/libc/sys/t_wait_noproc.c b/contrib/netbsd-tests/lib/libc/sys/t_wait_noproc.c index e5ddcbd5aa3b..c529f17e8b20 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_wait_noproc.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_wait_noproc.c @@ -29,9 +29,6 @@ #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 From 5ca85583098f2506a34ef7ddec764f841cedadb4 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Mon, 16 Jan 2017 07:34:45 +0000 Subject: [PATCH 12/22] Drop unnecessary diff rewriting dict(..) function This is already being properly handled via ATF config require.files call --- contrib/netbsd-tests/lib/libc/db/t_db.sh | 7 ------- 1 file changed, 7 deletions(-) diff --git a/contrib/netbsd-tests/lib/libc/db/t_db.sh b/contrib/netbsd-tests/lib/libc/db/t_db.sh index 1cf040c0de3b..93a7b1ec0bb0 100755 --- a/contrib/netbsd-tests/lib/libc/db/t_db.sh +++ b/contrib/netbsd-tests/lib/libc/db/t_db.sh @@ -46,13 +46,6 @@ dict() fi } -# Begin FreeBSD -dict() -{ - echo /usr/share/dict/words -} -# End FreeBSD - SEVEN_SEVEN="abcdefg|abcdefg|abcdefg|abcdefg|abcdefg|abcdefg|abcdefg" atf_test_case small_btree From f467f63cbb5063ff62496d79752f7563db42e02a Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Mon, 16 Jan 2017 07:39:08 +0000 Subject: [PATCH 13/22] Remove sys/param.h It was used for nitems, but I converted it to __arraycount later, and is already pulled in by header pollution on FreeBSD as well as NetBSD ala sys/cdefs.h --- contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c | 1 - 1 file changed, 1 deletion(-) diff --git a/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c b/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c index 2085b9e06394..8e4d30d037d4 100644 --- a/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c +++ b/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c @@ -30,7 +30,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include #include From 89964aab17713339821622b41dfc6f7ffc9af5dc Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Mon, 16 Jan 2017 07:41:39 +0000 Subject: [PATCH 14/22] Add GLOB_STAR #ifdef to testcases which require GLOB_STAR support --- contrib/netbsd-tests/lib/libc/gen/t_glob.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/netbsd-tests/lib/libc/gen/t_glob.c b/contrib/netbsd-tests/lib/libc/gen/t_glob.c index a2d9bcfba707..c53e183b3441 100644 --- a/contrib/netbsd-tests/lib/libc/gen/t_glob.c +++ b/contrib/netbsd-tests/lib/libc/gen/t_glob.c @@ -85,7 +85,7 @@ static struct gl_dir d[] = { { "a/b", b, __arraycount(b), 0 }, }; -#ifndef __FreeBSD__ +#ifdef GLOB_STAR static const char *glob_star[] = { "a/1", "a/3", "a/4", "a/b", "a/b/w", "a/b/x", "a/b/y", "a/b/z", }; @@ -219,7 +219,7 @@ run(const char *p, int flags, const char **res, size_t len) } -#ifndef __FreeBSD__ +#ifdef GLOB_STAR ATF_TC(glob_star); ATF_TC_HEAD(glob_star, tc) { @@ -268,7 +268,7 @@ ATF_TC_BODY(glob_nocheck, tc) ATF_TP_ADD_TCS(tp) { -#ifndef __FreeBSD__ +#ifdef GLOB_STAR ATF_TP_ADD_TC(tp, glob_star); #endif ATF_TP_ADD_TC(tp, glob_star_not); From 03c41ac965df56079c04c1750c684b942e27c59a Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Mon, 16 Jan 2017 17:25:48 +0000 Subject: [PATCH 15/22] Sync from NetBSD again to pick up more test fixes/enhancements pushed upstream --- lib/libc/ssp/h_memset.c | 6 +- lib/libc/ssp/h_read.c | 15 ++- lib/libc/sys/t_mmap.c | 6 +- lib/libc/sys/t_timer_create.c | 4 +- lib/libpthread/t_condwait.c | 11 +- lib/libpthread/t_detach.c | 13 +- lib/libpthread/t_fork.c | 8 +- lib/libpthread/t_fpu.c | 16 ++- lib/libpthread/t_mutex.c | 13 +- lib/libpthread/t_sem.c | 5 +- lib/libpthread/t_swapcontext.c | 13 +- net/carp/t_basic.c | 221 --------------------------------- net/carp/t_basic.sh | 165 ++++++++++++++++++++++++ 13 files changed, 237 insertions(+), 259 deletions(-) delete mode 100644 net/carp/t_basic.c create mode 100755 net/carp/t_basic.sh diff --git a/lib/libc/ssp/h_memset.c b/lib/libc/ssp/h_memset.c index 65ed5f2ee7d2..f1acbbd4e311 100644 --- a/lib/libc/ssp/h_memset.c +++ b/lib/libc/ssp/h_memset.c @@ -1,4 +1,4 @@ -/* $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. @@ -29,7 +29,7 @@ #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 @@ -41,5 +41,5 @@ main(int argc, char *argv[]) char b[10]; size_t len = atoi(argv[1]); (void)memset(b, 0, len); - return 0; + return b[0]; /* keeps optimizer from zapping the call to memset() */ } diff --git a/lib/libc/ssp/h_read.c b/lib/libc/ssp/h_read.c index 5240af291eb7..046ac62199b8 100644 --- a/lib/libc/ssp/h_read.c +++ b/lib/libc/ssp/h_read.c @@ -1,4 +1,4 @@ -/* $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. @@ -29,9 +29,11 @@ #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 @@ -40,8 +42,13 @@ int main(int argc, char *argv[]) { char b[MAXPATHLEN]; + int fd, n; size_t len = atoi(argv[1]); - (void)read(0, b, len); + + if ((fd = open(_PATH_DEVZERO, O_RDONLY)) == -1) + abort(); + if ((n = read(fd, b, len)) == -1) + abort(); (void)printf("%s\n", b); - return 0; + return (0); } diff --git a/lib/libc/sys/t_mmap.c b/lib/libc/sys/t_mmap.c index 3dc1e7f92fe3..f01ed76315b5 100644 --- a/lib/libc/sys/t_mmap.c +++ b/lib/libc/sys/t_mmap.c @@ -1,4 +1,4 @@ -/* $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. @@ -55,9 +55,10 @@ * 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 @@ -73,7 +74,6 @@ __RCSID("$NetBSD: t_mmap.c,v 1.11 2017/01/13 20:43:11 christos Exp $"); #include #include #include -#include static long page = 0; static char path[] = "mmap"; diff --git a/lib/libc/sys/t_timer_create.c b/lib/libc/sys/t_timer_create.c index ce1fb99eb1ad..e8a6acd08efc 100644 --- a/lib/libc/sys/t_timer_create.c +++ b/lib/libc/sys/t_timer_create.c @@ -1,4 +1,4 @@ -/* $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. @@ -38,7 +38,7 @@ static timer_t t; static bool fail = true; static void -timer_signal_handler(int signo, siginfo_t *si, void *osi) +timer_signal_handler(int signo, siginfo_t *si, void *osi __unused) { timer_t *tp; diff --git a/lib/libpthread/t_condwait.c b/lib/libpthread/t_condwait.c index 9b79587104cf..58b4a8bc155a 100644 --- a/lib/libpthread/t_condwait.c +++ b/lib/libpthread/t_condwait.c @@ -1,4 +1,4 @@ -/* $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. @@ -26,8 +26,9 @@ * 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 @@ -40,6 +41,8 @@ __RCSID("$NetBSD: t_condwait.c,v 1.4 2013/04/12 17:18:11 christos Exp $"); #include "isqemu.h" +#include "h_common.h" + #define WAITTIME 2 /* Timeout wait secound */ static const int debug = 1; @@ -56,8 +59,8 @@ run(void *param) clck = *(clockid_t *)param; - pthread_condattr_init(&attr); - pthread_condattr_setclock(&attr, clck); /* MONOTONIC or MONOTONIC */ + PTHREAD_REQUIRE(pthread_condattr_init(&attr)); + PTHREAD_REQUIRE(pthread_condattr_setclock(&attr, clck)); pthread_cond_init(&cond, &attr); ATF_REQUIRE_EQ((ret = pthread_mutex_lock(&m)), 0); diff --git a/lib/libpthread/t_detach.c b/lib/libpthread/t_detach.c index 21db871a70da..b30cb029d578 100644 --- a/lib/libpthread/t_detach.c +++ b/lib/libpthread/t_detach.c @@ -1,4 +1,4 @@ -/* $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. @@ -29,10 +29,11 @@ * 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 @@ -43,6 +44,7 @@ static void *func(void *); static void * func(void *arg) { + sleep(2); return NULL; } @@ -72,14 +74,17 @@ ATF_TC_BODY(pthread_detach, tc) */ PTHREAD_REQUIRE(pthread_detach(t)); + sleep(1); rv = pthread_join(t, NULL); ATF_REQUIRE(rv == EINVAL); + sleep(3); + /* * As usual, ESRCH should follow if * we try to detach an invalid thread. */ - rv = pthread_cancel(NULL); + rv = pthread_cancel(t); ATF_REQUIRE(rv == ESRCH); } diff --git a/lib/libpthread/t_fork.c b/lib/libpthread/t_fork.c index ab8806d25641..936c7decaecf 100644 --- a/lib/libpthread/t_fork.c +++ b/lib/libpthread/t_fork.c @@ -1,4 +1,4 @@ -/* $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. @@ -29,7 +29,7 @@ #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. @@ -61,7 +61,7 @@ print_pid(void *arg) thread_survived = 1; if (parent != getpid()) { - exit(1); + _exit(1); } return NULL; } @@ -95,7 +95,7 @@ ATF_TC_BODY(fork, tc) ATF_REQUIRE_EQ_MSG(WEXITSTATUS(status), 0, "thread survived in child"); } else { sleep(5); - exit(thread_survived ? 1 : 0); + _exit(thread_survived ? 1 : 0); } } diff --git a/lib/libpthread/t_fpu.c b/lib/libpthread/t_fpu.c index 4047b1fa6195..dd47fb8067e7 100644 --- a/lib/libpthread/t_fpu.c +++ b/lib/libpthread/t_fpu.c @@ -1,4 +1,4 @@ -/* $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. @@ -29,7 +29,7 @@ #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 @@ -49,10 +49,12 @@ __RCSID("$NetBSD: t_fpu.c,v 1.2 2013/01/27 14:47:37 mbalmer Exp $"); * . */ +#include #include #include #include #include +#include #include #include @@ -77,14 +79,16 @@ stir(void *p) for (;;) { x = sin ((y = cos (x + y + .4)) - (z = cos (x + z + .6))); - PTHREAD_REQUIRE(sched_yield()); + ATF_REQUIRE_MSG(sched_yield() == 0, + "sched_yield failed: %s", strerror(errno)); } } static double mul3(double x, double y, double z) { - PTHREAD_REQUIRE(sched_yield()); + ATF_REQUIRE_MSG(sched_yield() == 0, + "sched_yield failed: %s", strerror(errno)); return x * y * z; } @@ -114,7 +118,7 @@ bar(void *p) static void recurse(void) { pthread_t s2; - pthread_create(&s2, 0, bar, 0); + PTHREAD_REQUIRE(pthread_create(&s2, 0, bar, 0)); sleep(20); /* XXX must be long enough for our slowest machine */ } @@ -134,7 +138,7 @@ ATF_TC_BODY(fpu, tc) PTHREAD_REQUIRE(pthread_mutex_init(&recursion_depth_lock, 0)); - pthread_create(&s5, 0, stir, stirseed); + PTHREAD_REQUIRE(pthread_create(&s5, 0, stir, stirseed)); recurse(); atf_tc_fail("exiting from main"); diff --git a/lib/libpthread/t_mutex.c b/lib/libpthread/t_mutex.c index e9ba2fc5754a..b706e462f3db 100644 --- a/lib/libpthread/t_mutex.c +++ b/lib/libpthread/t_mutex.c @@ -1,4 +1,4 @@ -/* $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. @@ -29,8 +29,10 @@ #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 $"); +#include /* For timespecadd */ +#include /* For UINT16_MAX */ #include #include #include @@ -570,9 +572,16 @@ ATF_TC_BODY(mutexattr2, tc) int min_prio = sched_get_priority_min(SCHED_FIFO); for (int i = min_prio; i <= max_prio; i++) { int prioceiling; + int protocol; + + PTHREAD_REQUIRE(pthread_mutexattr_getprotocol(&mattr, + &protocol)); + + printf("priority: %d\nprotocol: %d\n", i, protocol); PTHREAD_REQUIRE(pthread_mutexattr_setprioceiling(&mattr, i)); PTHREAD_REQUIRE(pthread_mutexattr_getprioceiling(&mattr, &prioceiling)); + printf("prioceiling: %d\n", prioceiling); ATF_REQUIRE_EQ(i, prioceiling); } } diff --git a/lib/libpthread/t_sem.c b/lib/libpthread/t_sem.c index a4e03ae9c605..3d15eddab64b 100644 --- a/lib/libpthread/t_sem.c +++ b/lib/libpthread/t_sem.c @@ -1,4 +1,4 @@ -/* $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. @@ -86,8 +86,9 @@ #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 diff --git a/lib/libpthread/t_swapcontext.c b/lib/libpthread/t_swapcontext.c index 8fd231404542..677c51fc8601 100644 --- a/lib/libpthread/t_swapcontext.c +++ b/lib/libpthread/t_swapcontext.c @@ -1,4 +1,4 @@ -/* $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. @@ -28,10 +28,13 @@ #include __RCSID("$NetBSD"); +#include +#include #include -#include #include #include +#include +#include #include @@ -77,7 +80,8 @@ threadfunc(void *arg) oself = (void *)pthread_self(); printf("before swapcontext self = %p\n", oself); - PTHREAD_REQUIRE(swapcontext(&octx, &nctx)); + ATF_REQUIRE_MSG(swapcontext(&octx, &nctx) != -1, "swapcontext failed: %s", + strerror(errno)); /* NOTREACHED */ return NULL; @@ -99,7 +103,8 @@ ATF_TC_BODY(swapcontext1, tc) printf("Testing if swapcontext() alters pthread_self()\n"); - PTHREAD_REQUIRE(getcontext(&nctx)); + ATF_REQUIRE_MSG(getcontext(&nctx) != -1, "getcontext failed: %s", + strerror(errno)); PTHREAD_REQUIRE(pthread_create(&thread, NULL, threadfunc, NULL)); PTHREAD_REQUIRE(pthread_join(thread, NULL)); } diff --git a/net/carp/t_basic.c b/net/carp/t_basic.c deleted file mode 100644 index 681b8bb179a7..000000000000 --- a/net/carp/t_basic.c +++ /dev/null @@ -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(); -} diff --git a/net/carp/t_basic.sh b/net/carp/t_basic.sh new file mode 100755 index 000000000000..94ada1cbb6d0 --- /dev/null +++ b/net/carp/t_basic.sh @@ -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 +} From 267f10b14c0d94152288c81ffb4b2fb942b49283 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Mon, 16 Jan 2017 17:49:53 +0000 Subject: [PATCH 16/22] Use _SED to rewrite mknod ... p command as mkfifo instead of adding an unnecessary diff to the test --- contrib/netbsd-tests/fs/tmpfs/t_readdir.sh | 8 -------- tests/sys/fs/tmpfs/Makefile | 1 + 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/contrib/netbsd-tests/fs/tmpfs/t_readdir.sh b/contrib/netbsd-tests/fs/tmpfs/t_readdir.sh index 272c7493a204..6f5dc3ef2bde 100755 --- a/contrib/netbsd-tests/fs/tmpfs/t_readdir.sh +++ b/contrib/netbsd-tests/fs/tmpfs/t_readdir.sh @@ -59,15 +59,7 @@ types_body() { atf_check -s eq:0 -o empty -e empty ln -s reg lnk atf_check -s eq:0 -o empty -e empty mknod blk b 0 0 atf_check -s eq:0 -o empty -e empty mknod chr c 0 0 - # Begin FreeBSD - if true; then - atf_check -s eq:0 -o empty -e empty mkfifo fifo - else - # End FreeBSD atf_check -s eq:0 -o empty -e empty mknod fifo p - # Begin FreeBSD - fi - # End FreeBSD atf_check -s eq:0 -o empty -e empty \ $(atf_get_srcdir)/h_tools sockets sock diff --git a/tests/sys/fs/tmpfs/Makefile b/tests/sys/fs/tmpfs/Makefile index 63facd1d02fb..154d2da8af8d 100644 --- a/tests/sys/fs/tmpfs/Makefile +++ b/tests/sys/fs/tmpfs/Makefile @@ -47,6 +47,7 @@ ATF_TESTS_SH_SED_mount_test= \ -e 's,-o -s,-o size=,g' \ -e 's,-o -u,-o uid=,g' \ -e 's,mount_${FILESYSTEM},mount -t ${FILESYSTEM},g' +ATF_TESTS_SH_SED_readdir_test= -e 's,mknod fifo p,mkfifo fifo,g' ATF_TESTS_SH_SED_sizes_test= -e 's,-o -s,-o size=,g' ATF_TESTS_SH_SED_statvfs_test= -e 's,-o -s,-o size=,g' ATF_TESTS_SH_SED_vnode_leak_test= -e 's,-o -s,-o size=,g' From 183ae521e5796272070594b031f1849b6a8a2cf5 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Mon, 16 Jan 2017 17:53:58 +0000 Subject: [PATCH 17/22] Use _SED instead of hacking tests rewriting mknod ... p as mkfifo Similar to r312297 --- contrib/netbsd-tests/fs/tmpfs/t_mknod.sh | 16 ---------------- tests/sys/fs/tmpfs/Makefile | 4 ++++ 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/contrib/netbsd-tests/fs/tmpfs/t_mknod.sh b/contrib/netbsd-tests/fs/tmpfs/t_mknod.sh index 037dc16ce3b2..62c7cce22834 100755 --- a/contrib/netbsd-tests/fs/tmpfs/t_mknod.sh +++ b/contrib/netbsd-tests/fs/tmpfs/t_mknod.sh @@ -106,15 +106,7 @@ pipe_body() { test_mount umask 022 - # Begin FreeBSD - if true; then - atf_check -s eq:0 -o empty -e empty mkfifo pipe - else - # End FreeBSD atf_check -s eq:0 -o empty -e empty mknod pipe p - # Begin FreeBSD - fi - # End FreeBSD eval $(stat -s pipe) [ ${st_mode} = 010644 ] || atf_fail "Invalid mode" @@ -132,15 +124,7 @@ pipe_kqueue_body() { umask 022 atf_check -s eq:0 -o empty -e empty mkdir dir - # Begin FreeBSD - if true; then - echo 'mkfifo dir/pipe' | kqueue_monitor 1 dir - else - # End FreeBSD echo 'mknod dir/pipe p' | kqueue_monitor 1 dir - # Begin FreeBSD - fi - # End FreeBSD kqueue_check dir NOTE_WRITE test_unmount diff --git a/tests/sys/fs/tmpfs/Makefile b/tests/sys/fs/tmpfs/Makefile index 154d2da8af8d..388d9115c5c8 100644 --- a/tests/sys/fs/tmpfs/Makefile +++ b/tests/sys/fs/tmpfs/Makefile @@ -41,6 +41,10 @@ ${PACKAGE}FILESDIR= ${TESTSDIR} PROGS+= h_tools BINDIR.h_tools= ${TESTSDIR} +ATF_TESTS_SH_SED_mknod_test= \ + -e 's,mknod pipe p,mkfifo pipe,g' \ + -e 's,mknod dir/pipe p,mkfifo dir/pipe,g' + ATF_TESTS_SH_SED_mount_test= \ -e 's,-o -g,-o gid=,g' \ -e 's,-o -m,-o mode=,g' \ From e2a4e9c68234beb48ecc651a8159d63d393df502 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Mon, 16 Jan 2017 18:04:14 +0000 Subject: [PATCH 18/22] Remove unnecessary whitespace diff --- contrib/netbsd-tests/lib/libc/sys/t_mmap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/netbsd-tests/lib/libc/sys/t_mmap.c b/contrib/netbsd-tests/lib/libc/sys/t_mmap.c index d3a66b718ea9..f8f4caa36d80 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_mmap.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_mmap.c @@ -377,6 +377,7 @@ ATF_TC_BODY(mmap_prot_3, tc) * 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", From 39a3103b411951e49f6fae2b0145f34ac582dc80 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Mon, 16 Jan 2017 18:17:53 +0000 Subject: [PATCH 19/22] Use sys/param.h instead of sys/types.h to prep for upstreaming to NetBSD --- contrib/netbsd-tests/lib/libc/sys/t_mlock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/netbsd-tests/lib/libc/sys/t_mlock.c b/contrib/netbsd-tests/lib/libc/sys/t_mlock.c index c5d02eb202fc..0a3a40da6d5e 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_mlock.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_mlock.c @@ -32,7 +32,7 @@ __RCSID("$NetBSD: t_mlock.c,v 1.6 2016/08/09 12:02:44 kre Exp $"); #ifdef __FreeBSD__ -#include +#include /* NetBSD requires sys/param.h for sysctl(3), unlike FreeBSD */ #endif #include #include From 4acf8d706e36dba0a51abf45def6c31c3fe7bac5 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Mon, 16 Jan 2017 18:36:38 +0000 Subject: [PATCH 20/22] Diff reduce with upstream by using macros and logic integrated in later revisions of the test --- contrib/netbsd-tests/lib/libc/rpc/t_rpc.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/contrib/netbsd-tests/lib/libc/rpc/t_rpc.c b/contrib/netbsd-tests/lib/libc/rpc/t_rpc.c index bce363375be5..e5d4321625f2 100644 --- a/contrib/netbsd-tests/lib/libc/rpc/t_rpc.c +++ b/contrib/netbsd-tests/lib/libc/rpc/t_rpc.c @@ -24,13 +24,6 @@ __RCSID("$NetBSD: t_rpc.c,v 1.10 2016/08/27 14:36:22 christos Exp $"); return ev; \ } while(/*CONSTCOND*/0) -#ifdef __FreeBSD__ -#define SKIPXI(ev, msg, ...) do { \ - atf_tc_skip(msg, __VA_ARGS__); \ - return ev; \ -} while(/*CONSTCOND*/0) -#endif - #else #define ERRX(ev, msg, ...) errx(EXIT_FAILURE, msg, __VA_ARGS__) #define SKIPX(ev, msg, ...) errx(EXIT_FAILURE, msg, __VA_ARGS__) @@ -196,7 +189,7 @@ regtest(const char *hostname, const char *transp, const char *arg, int p) #endif if (!svc_create(server, PROGNUM, VERSNUM, transp)) { - SKIPXI(EXIT_FAILURE, "Cannot create server %d", num); + SKIPX(EXIT_FAILURE, "Cannot create server %d", num); } switch ((pid = fork())) { From ea498175b952c38a29c9b2174d2509a62ec5285e Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Mon, 16 Jan 2017 18:44:40 +0000 Subject: [PATCH 21/22] Diff reduce with upstream and prep for next set of content pushes --- contrib/netbsd-tests/lib/libpthread/t_detach.c | 4 ---- contrib/netbsd-tests/lib/libpthread/t_fpu.c | 5 ----- contrib/netbsd-tests/lib/libpthread/t_once.c | 7 +++---- contrib/netbsd-tests/lib/libpthread/t_sem.c | 4 ---- 4 files changed, 3 insertions(+), 17 deletions(-) diff --git a/contrib/netbsd-tests/lib/libpthread/t_detach.c b/contrib/netbsd-tests/lib/libpthread/t_detach.c index 22ca4149ad38..b30cb029d578 100644 --- a/contrib/netbsd-tests/lib/libpthread/t_detach.c +++ b/contrib/netbsd-tests/lib/libpthread/t_detach.c @@ -39,10 +39,6 @@ __RCSID("$NetBSD: t_detach.c,v 1.2 2017/01/16 16:29:54 christos Exp $"); #include "h_common.h" -#ifdef __FreeBSD__ -#include -#endif - static void *func(void *); static void * diff --git a/contrib/netbsd-tests/lib/libpthread/t_fpu.c b/contrib/netbsd-tests/lib/libpthread/t_fpu.c index 16109064d4ad..dd47fb8067e7 100644 --- a/contrib/netbsd-tests/lib/libpthread/t_fpu.c +++ b/contrib/netbsd-tests/lib/libpthread/t_fpu.c @@ -60,11 +60,6 @@ __RCSID("$NetBSD: t_fpu.c,v 1.3 2017/01/16 16:27:43 christos Exp $"); #include -#ifdef __FreeBSD__ -#include -#include -#endif - #include "h_common.h" #define N_RECURSE 10 diff --git a/contrib/netbsd-tests/lib/libpthread/t_once.c b/contrib/netbsd-tests/lib/libpthread/t_once.c index e87907721a61..e2f209b3e897 100644 --- a/contrib/netbsd-tests/lib/libpthread/t_once.c +++ b/contrib/netbsd-tests/lib/libpthread/t_once.c @@ -31,6 +31,9 @@ __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); __RCSID("$NetBSD: t_once.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); +#ifdef __FreeBSD__ +#include /* For itimer*, etc. */ +#endif #include #include #include @@ -46,10 +49,6 @@ static int x; #define NTHREADS 25 -#ifdef __FreeBSD__ -#include -#endif - static void ofunc(void) { diff --git a/contrib/netbsd-tests/lib/libpthread/t_sem.c b/contrib/netbsd-tests/lib/libpthread/t_sem.c index bffaf667ed10..3d15eddab64b 100644 --- a/contrib/netbsd-tests/lib/libpthread/t_sem.c +++ b/contrib/netbsd-tests/lib/libpthread/t_sem.c @@ -112,10 +112,6 @@ __RCSID("$NetBSD: t_sem.c,v 1.9 2017/01/16 16:22:22 christos Exp $"); static sem_t sem; -#ifdef __FreeBSD__ -#include -#endif - ATF_TC(named); ATF_TC_HEAD(named, tc) { From 800a0e267276d0a59f1de2ba9bc3e3ec1bfb0d7a Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Mon, 16 Jan 2017 18:51:27 +0000 Subject: [PATCH 22/22] libnetbsd: add pthread.h compat header FreeBSD has pthread_np.h, which is used for consolidating all non-POSIX functions, but NetBSD doesn't have this concept. Make _np functions work seamlessly when ported from NetBSD to FreeBSD --- lib/libnetbsd/pthread.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 lib/libnetbsd/pthread.h diff --git a/lib/libnetbsd/pthread.h b/lib/libnetbsd/pthread.h new file mode 100644 index 000000000000..13bf0444a2ca --- /dev/null +++ b/lib/libnetbsd/pthread.h @@ -0,0 +1,36 @@ +/*- + * Copyright (c) 2017 Dell, 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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. + * + * $FreeBSD$ + */ + +#ifndef _LIBNETBSD_PTHREAD_H_ +#define _LIBNETBSD_PTHREAD_H_ + +#include_next +#include + +#endif /* _SHA1_H_ */