From 74f4c1cf51a4c215a83e40e91b7104dcb087e5cc Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Wed, 17 Aug 2016 06:41:05 +0000 Subject: [PATCH 1/5] Expect :mmap_truncate_signal to fail on FreeBSD Additional investigation is being done as part of bug 211924 PR: 211924 Sponsored by: EMC / Isilon Storage Division --- contrib/netbsd-tests/lib/libc/sys/t_mmap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/netbsd-tests/lib/libc/sys/t_mmap.c b/contrib/netbsd-tests/lib/libc/sys/t_mmap.c index 5cb99d0dcf1f..9e74d41fd6c6 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_mmap.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_mmap.c @@ -475,6 +475,10 @@ ATF_TC_BODY(mmap_truncate_signal, tc) 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) From 1ffd722a80a9a6e14683da8b02db6ad6185cb5e9 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Thu, 25 Aug 2016 19:17:16 +0000 Subject: [PATCH 2/5] Don't test `size[i] % align[i] == 0` case on FreeBSD Per jemalloc(3)/aligned_alloc(3), the behavior is undefined if the size isn't an integral multiple of the alignment. Thus, this is a NetBSD-specific test. Sponsored by: EMC / Isilon Storage Division --- .../netbsd-tests/lib/libc/stdlib/t_posix_memalign.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_posix_memalign.c b/contrib/netbsd-tests/lib/libc/stdlib/t_posix_memalign.c index 697638e204e1..8db788075fc1 100644 --- a/contrib/netbsd-tests/lib/libc/stdlib/t_posix_memalign.c +++ b/contrib/netbsd-tests/lib/libc/stdlib/t_posix_memalign.c @@ -121,9 +121,19 @@ ATF_TC_BODY(aligned_alloc_basic, tc) ATF_REQUIRE_EQ_MSG((align[i] - 1) & align[i], 0, "aligned_alloc: success when alignment was not " "a power of 2"); +#ifdef __NetBSD__ + /* + * NetBSD-specific invariant + * + * From aligned_alloc(3) on FreeBSD: + * + * Behavior is undefined if size is not an integral + * multiple of alignment. + */ ATF_REQUIRE_EQ_MSG(size[i] % align[i], 0, "aligned_alloc: success when size was not an " "integer multiple of alignment"); +#endif ATF_REQUIRE_EQ_MSG(((intptr_t)p) & (align[i] - 1), 0, "p = %p", p); free(p); From aaf3e744fd4e63742027d09d2eee91b1912ce8e2 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Fri, 26 Aug 2016 03:46:43 +0000 Subject: [PATCH 3/5] Detect virtual machines on FreeBSD using the kern.vm_guest sysctl kern.vm_guest == none -> not a virtual machine It's a bit of a misnomer with the function being named `isQEMU`... but FreeBSD's support seems to be a bit more all-encompassing than NetBSD's is today. Sponsored by: EMC / Isilon Storage Division --- contrib/netbsd-tests/lib/libc/gen/isqemu.h | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/contrib/netbsd-tests/lib/libc/gen/isqemu.h b/contrib/netbsd-tests/lib/libc/gen/isqemu.h index e5e5ea4b5867..c44ffda082a0 100644 --- a/contrib/netbsd-tests/lib/libc/gen/isqemu.h +++ b/contrib/netbsd-tests/lib/libc/gen/isqemu.h @@ -41,6 +41,30 @@ static __inline bool isQEMU(void) { +#ifdef __FreeBSD__ + char *vm_guest_name_buf; + size_t len; + bool is_vm; + + if (sysctlbyname("kern.vm_guest", NULL, &len, NULL, 0) == -1) + err(EXIT_FAILURE, "sysctl"); + + if ((vm_guest_name_buf = malloc(len)) == NULL) + err(EXIT_FAILURE, "malloc"); + + if (sysctlbyname("kern.vm_guest", vm_guest_name_buf, &len, NULL, 0) + == -1) + err(EXIT_FAILURE, "sysctl"); + + if (strcmp(vm_guest_name_buf, "none") == 0) + is_vm = false; + else + is_vm = true; + + free(vm_guest_name_buf); + + return is_vm; +#else #if defined(__i386__) || defined(__x86_64__) char name[1024]; size_t len = sizeof(name); @@ -54,6 +78,7 @@ isQEMU(void) { #else return false; #endif +#endif } #ifdef TEST From 6e122b96101bfcb0168c613447c37817d4e02196 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Fri, 26 Aug 2016 04:31:19 +0000 Subject: [PATCH 4/5] Add copious debugging to aid in determining why :sigqueue_rt is currently failing For some odd reason SIGINT is only being delivered once, as opposed to multiple times. Disclaimer: this test was run on a kernel built on 08/14/2016. Need to build a new kernel and rerun the test. --- .../netbsd-tests/lib/libc/sys/t_sigqueue.c | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c b/contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c index 80191b7665bd..8ff36f628b93 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c @@ -32,7 +32,6 @@ #include __RCSID("$NetBSD: t_sigqueue.c,v 1.6 2016/08/04 06:43:43 christos Exp $"); - #include #include #include @@ -40,6 +39,11 @@ __RCSID("$NetBSD: t_sigqueue.c,v 1.6 2016/08/04 06:43:43 christos Exp $"); #include #include +#ifdef __FreeBSD__ +#include +#include +#endif + static void handler(int, siginfo_t *, void *); #define VALUE (int)0xc001dad1 @@ -77,7 +81,7 @@ ATF_TC_BODY(sigqueue_basic, tc) sv.sival_int = VALUE; #ifdef __FreeBSD__ - /* + /* * From kern_sig.c: * Specification says sigqueue can only send signal to single process. */ @@ -122,6 +126,9 @@ static void myhandler(int signo, siginfo_t *info, void *context) { delivered[count++] = signo; +#ifdef __FreeBSD__ + printf("Signal #%zu: signo: %d\n", (size_t)count, signo); +#endif } static int @@ -188,7 +195,12 @@ ATF_TC_BODY(sigqueue_rt, tc) sigset_t mask, orig; sigemptyset(&mask); for (size_t i = 0; i < CNT; i++) +#ifdef __FreeBSD__ + if (sigaddset(&mask, signals[i]) == -1) + warn("sigaddset"); +#else sigaddset(&mask, signals[i]); +#endif ATF_REQUIRE(sigprocmask(SIG_BLOCK, &mask, &orig) != -1); @@ -197,13 +209,24 @@ ATF_TC_BODY(sigqueue_rt, tc) ATF_REQUIRE(sigprocmask(SIG_UNBLOCK, &mask, &orig) != -1); sleep(1); +#ifdef __FreeBSD__ + ATF_CHECK_MSG((size_t)count == ndelivered, + "count %zu != ndelivered %zu", (size_t)count, ndelivered); +#else ATF_REQUIRE_MSG((size_t)count == ndelivered, "count %zu != ndelivered %zu", (size_t)count, ndelivered); +#endif for (size_t i = 0; i < ndelivered; i++) ATF_REQUIRE_MSG(ordered[i] == delivered[i], "%zu: ordered %d != delivered %d", i, ordered[i], delivered[i]); +#ifdef __FreeBSD__ + if (count > ndelivered) + for (size_t i = ndelivered; i < count; i++) + printf("Undelivered signal #%zu: %d\n", i, ordered[i]); +#endif + for (size_t i = 0; i < ndelivered; i++) ATF_REQUIRE(sigaction(signals[i], &oact[i], NULL) != -1); } From 9c73efe89c234855b7c7d705171488a62291181a Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Mon, 29 Aug 2016 22:34:31 +0000 Subject: [PATCH 5/5] Fix typo atf_tc_expect_fail should have been atf_expect_fail per atf-sh-api(3) PR: 212193 Pointyhat to: ngie Sponsored by: EMC / Isilon Storage Division --- contrib/netbsd-tests/usr.bin/dirname/t_dirname.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/netbsd-tests/usr.bin/dirname/t_dirname.sh b/contrib/netbsd-tests/usr.bin/dirname/t_dirname.sh index 31204045b42e..171fb13ab610 100755 --- a/contrib/netbsd-tests/usr.bin/dirname/t_dirname.sh +++ b/contrib/netbsd-tests/usr.bin/dirname/t_dirname.sh @@ -33,7 +33,7 @@ basic_head() basic_body() { # Begin FreeBSD - atf_tc_expect_fail "dirname //usr//bin doesn't return //usr like it used to; bug # 212193" + atf_expect_fail "dirname //usr//bin doesn't return //usr like it used to; bug # 212193" # End FreeBSD atf_check -o inline:"/\n" dirname / atf_check -o inline:"/\n" dirname //