From eed7f1bcd9cdfbc4f011e05ed27e4f6e9ba4b69f Mon Sep 17 00:00:00 2001 From: ngie Date: Mon, 27 Apr 2015 17:53:09 +0000 Subject: Move tests/sys/kern/mmap_test to tests/sys/vm/mmap_test As jhb noted, the actual mmap(2) implementation is under sys/vm, not sys/kern/, so the correct logical place is tests/sys/vm/, not tests/sys/kern/ X-MFC with: r282076 MFC after: 6 days --- tests/sys/Makefile | 1 + tests/sys/kern/Makefile | 1 - tests/sys/kern/mmap_test.c | 105 --------------------------------------------- tests/sys/vm/Makefile | 7 +++ tests/sys/vm/mmap_test.c | 105 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 113 insertions(+), 106 deletions(-) delete mode 100644 tests/sys/kern/mmap_test.c create mode 100644 tests/sys/vm/Makefile create mode 100644 tests/sys/vm/mmap_test.c (limited to 'tests') diff --git a/tests/sys/Makefile b/tests/sys/Makefile index e67f609..066c918 100644 --- a/tests/sys/Makefile +++ b/tests/sys/Makefile @@ -12,6 +12,7 @@ TESTS_SUBDIRS+= kqueue TESTS_SUBDIRS+= mqueue TESTS_SUBDIRS+= netinet TESTS_SUBDIRS+= opencrypto +TESTS_SUBDIRS+= vm # Items not integrated into kyua runs by default SUBDIR+= pjdfstest diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile index 3d2127f..d366aa1 100644 --- a/tests/sys/kern/Makefile +++ b/tests/sys/kern/Makefile @@ -3,7 +3,6 @@ TESTSDIR= ${TESTSBASE}/sys/kern ATF_TESTS_C+= kern_descrip_test -TAP_TESTS_C+= mmap_test ATF_TESTS_C+= unix_seqpacket_test TEST_METADATA.unix_seqpacket_test+= timeout="15" diff --git a/tests/sys/kern/mmap_test.c b/tests/sys/kern/mmap_test.c deleted file mode 100644 index 7591a09..0000000 --- a/tests/sys/kern/mmap_test.c +++ /dev/null @@ -1,105 +0,0 @@ -/*- - * Copyright (c) 2009 Simon L. Nielsen , - * Bjoern A. Zeeb - * - * 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. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include - -#include -#include -#include - -static const struct { - void *addr; - int ok[2]; /* Depending on security.bsd.map_at_zero {0, !=0}. */ -} tests[] = { - { (void *)0, { 0, 1 } }, /* Test sysctl. */ - { (void *)1, { 0, 0 } }, - { (void *)(PAGE_SIZE - 1), { 0, 0 } }, - { (void *)PAGE_SIZE, { 1, 1 } }, - { (void *)-1, { 0, 0 } }, - { (void *)(-PAGE_SIZE), { 0, 0 } }, - { (void *)(-1 - PAGE_SIZE), { 0, 0 } }, - { (void *)(-1 - PAGE_SIZE - 1), { 0, 0 } }, - { (void *)(0x1000 * PAGE_SIZE), { 1, 1 } }, -}; - -#define MAP_AT_ZERO "security.bsd.map_at_zero" - -int -main(void) -{ - void *p; - size_t len; - int i, error, mib[3], map_at_zero; - - error = 0; - - /* Get the current sysctl value of security.bsd.map_at_zero. */ - len = sizeof(mib) / sizeof(*mib); - if (sysctlnametomib(MAP_AT_ZERO, mib, &len) == -1) { - printf("1..0 # SKIP: sysctlnametomib(\"%s\") failed: %s\n", - MAP_AT_ZERO, strerror(errno)); - return (0); - } - - len = sizeof(map_at_zero); - if (sysctl(mib, 3, &map_at_zero, &len, NULL, 0) == -1) { - printf("1..0 # SKIP: sysctl for %s failed: %s\n", MAP_AT_ZERO, - strerror(errno)); - return (0); - } - - /* Normalize to 0 or 1 for array access. */ - map_at_zero = !!map_at_zero; - - printf("1..%zu\n", nitems(tests)); - for (i = 0; i < (int)nitems(tests); i++) { - p = mmap((void *)tests[i].addr, PAGE_SIZE, - PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_FIXED, - -1, 0); - if (p == MAP_FAILED) { - if (tests[i].ok[map_at_zero] != 0) - error++; - printf("%sok %d # mmap(%p, ...) failed\n", - tests[i].ok[map_at_zero] == 0 ? "" : "not ", - i + 1, - tests[i].addr); - } else { - if (tests[i].ok[map_at_zero] != 1) - error++; - printf("%sok %d # mmap(%p, ...) succeeded: p=%p\n", - tests[i].ok[map_at_zero] == 1 ? "" : "not ", - i + 1, - tests[i].addr, p); - } - } - - return (error != 0); -} diff --git a/tests/sys/vm/Makefile b/tests/sys/vm/Makefile new file mode 100644 index 0000000..1795eef --- /dev/null +++ b/tests/sys/vm/Makefile @@ -0,0 +1,7 @@ +# $FreeBSD$ + +TESTSDIR= ${TESTSBASE}/sys/vm + +TAP_TESTS_C+= mmap_test + +.include diff --git a/tests/sys/vm/mmap_test.c b/tests/sys/vm/mmap_test.c new file mode 100644 index 0000000..7591a09 --- /dev/null +++ b/tests/sys/vm/mmap_test.c @@ -0,0 +1,105 @@ +/*- + * Copyright (c) 2009 Simon L. Nielsen , + * Bjoern A. Zeeb + * + * 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. + * + * $FreeBSD$ + */ + +#include +#include +#include +#include + +#include +#include +#include + +static const struct { + void *addr; + int ok[2]; /* Depending on security.bsd.map_at_zero {0, !=0}. */ +} tests[] = { + { (void *)0, { 0, 1 } }, /* Test sysctl. */ + { (void *)1, { 0, 0 } }, + { (void *)(PAGE_SIZE - 1), { 0, 0 } }, + { (void *)PAGE_SIZE, { 1, 1 } }, + { (void *)-1, { 0, 0 } }, + { (void *)(-PAGE_SIZE), { 0, 0 } }, + { (void *)(-1 - PAGE_SIZE), { 0, 0 } }, + { (void *)(-1 - PAGE_SIZE - 1), { 0, 0 } }, + { (void *)(0x1000 * PAGE_SIZE), { 1, 1 } }, +}; + +#define MAP_AT_ZERO "security.bsd.map_at_zero" + +int +main(void) +{ + void *p; + size_t len; + int i, error, mib[3], map_at_zero; + + error = 0; + + /* Get the current sysctl value of security.bsd.map_at_zero. */ + len = sizeof(mib) / sizeof(*mib); + if (sysctlnametomib(MAP_AT_ZERO, mib, &len) == -1) { + printf("1..0 # SKIP: sysctlnametomib(\"%s\") failed: %s\n", + MAP_AT_ZERO, strerror(errno)); + return (0); + } + + len = sizeof(map_at_zero); + if (sysctl(mib, 3, &map_at_zero, &len, NULL, 0) == -1) { + printf("1..0 # SKIP: sysctl for %s failed: %s\n", MAP_AT_ZERO, + strerror(errno)); + return (0); + } + + /* Normalize to 0 or 1 for array access. */ + map_at_zero = !!map_at_zero; + + printf("1..%zu\n", nitems(tests)); + for (i = 0; i < (int)nitems(tests); i++) { + p = mmap((void *)tests[i].addr, PAGE_SIZE, + PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_FIXED, + -1, 0); + if (p == MAP_FAILED) { + if (tests[i].ok[map_at_zero] != 0) + error++; + printf("%sok %d # mmap(%p, ...) failed\n", + tests[i].ok[map_at_zero] == 0 ? "" : "not ", + i + 1, + tests[i].addr); + } else { + if (tests[i].ok[map_at_zero] != 1) + error++; + printf("%sok %d # mmap(%p, ...) succeeded: p=%p\n", + tests[i].ok[map_at_zero] == 1 ? "" : "not ", + i + 1, + tests[i].addr, p); + } + } + + return (error != 0); +} -- cgit v1.1 From e16b0a44bfdc1193c6246f5f22caa156b8f85370 Mon Sep 17 00:00:00 2001 From: ngie Date: Tue, 28 Apr 2015 10:29:42 +0000 Subject: Fill in the copyright boilerplate for the test program MFC after: 6 days --- tests/sys/mqueue/mqueue_test.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests') diff --git a/tests/sys/mqueue/mqueue_test.sh b/tests/sys/mqueue/mqueue_test.sh index dd2469e..4841418 100755 --- a/tests/sys/mqueue/mqueue_test.sh +++ b/tests/sys/mqueue/mqueue_test.sh @@ -1,3 +1,30 @@ +# +# Copyright (c) 2015 EMC / Isilon Storage Division +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# mqtest1_head() { -- cgit v1.1 From cad543ea759cc7f4bf0a854f9204bcf36d26bb50 Mon Sep 17 00:00:00 2001 From: ngie Date: Tue, 28 Apr 2015 10:50:31 +0000 Subject: Add initial (unpolished) macros for interfacing with the FreeBSD test suite This is very rough, but will be replaced/redesigned some time soon after I fix the Jenkins breakage I introduced MFC after: 6 days --- tests/freebsd_test_suite/macros.h | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/freebsd_test_suite/macros.h (limited to 'tests') diff --git a/tests/freebsd_test_suite/macros.h b/tests/freebsd_test_suite/macros.h new file mode 100644 index 0000000..755a994 --- /dev/null +++ b/tests/freebsd_test_suite/macros.h @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 2015 EMC / Isilon Storage Division + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _FREEBSD_TEST_MACROS_H_ +#define _FREEBSD_TEST_MACROS_H_ + +#include +#include +#include +#include +#include + +#include + +#define ATF_REQUIRE_KERNEL_MODULE(_mod_name) do { \ + ATF_REQUIRE_MSG(modfind(_mod_name) != -1, \ + "module %s could not be resolved: %s", \ + _mod_name, strerror(errno)); \ +} while(0) + +#define PLAIN_REQUIRE_KERNEL_MODULE(_mod_name, _exit_code) do { \ + if (modfind(_mod_name) == -1) { \ + err(_exit_code, "module %s could not be resolved", \ + _mod_name); \ + } \ +} while(0) + +#endif -- cgit v1.1 From 7dc04ed65cb85128953fbb7aa0b26cfc59e327fb Mon Sep 17 00:00:00 2001 From: ngie Date: Tue, 28 Apr 2015 10:51:12 +0000 Subject: Use ATF_REQUIRE_KERNEL_MODULE instead of aio_available function MFC after: 6 days --- tests/sys/aio/aio_test.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/sys/aio/aio_test.c b/tests/sys/aio/aio_test.c index 6975bcb..4134e78 100644 --- a/tests/sys/aio/aio_test.c +++ b/tests/sys/aio/aio_test.c @@ -59,6 +59,8 @@ #include +#include "freebsd_test_suite/macros.h" + #define PATH_TEMPLATE "aio.XXXXXXXXXX" /* @@ -82,15 +84,6 @@ struct aio_context { static int aio_timedout; -static void -aio_available(void) -{ - - if (modfind("aio") == -1) - atf_tc_skip("aio support not available in the kernel; " - "skipping testcases"); -} - /* * Each test run specifies a timeout in seconds. Use the somewhat obsoleted * signal(3) and alarm(3) APIs to set this up. @@ -211,7 +204,7 @@ aio_write_test(struct aio_context *ac) struct aiocb aio, *aiop; ssize_t len; - aio_available(); + ATF_REQUIRE_KERNEL_MODULE("aio"); bzero(&aio, sizeof(aio)); aio.aio_buf = ac->ac_buffer; @@ -263,7 +256,7 @@ aio_read_test(struct aio_context *ac) struct aiocb aio, *aiop; ssize_t len; - aio_available(); + ATF_REQUIRE_KERNEL_MODULE("aio"); bzero(ac->ac_buffer, ac->ac_buflen); bzero(&aio, sizeof(aio)); @@ -346,7 +339,7 @@ ATF_TC_BODY(aio_file_test, tc) struct aio_context ac; int fd; - aio_available(); + ATF_REQUIRE_KERNEL_MODULE("aio"); strcpy(pathname, PATH_TEMPLATE); fd = mkstemp(pathname); @@ -392,7 +385,7 @@ ATF_TC_BODY(aio_fifo_test, tc) char pathname[PATH_MAX]; struct aio_context ac; - aio_available(); + ATF_REQUIRE_KERNEL_MODULE("aio"); /* * In theory, mkstemp() can return a name that is then collided with. @@ -461,7 +454,7 @@ ATF_TC_BODY(aio_unix_socketpair_test, tc) struct aio_context ac; int sockets[2]; - aio_available(); + ATF_REQUIRE_KERNEL_MODULE("aio"); ATF_REQUIRE_MSG(socketpair(PF_UNIX, SOCK_STREAM, 0, sockets) != -1, "socketpair failed: %s", strerror(errno)); @@ -503,7 +496,7 @@ ATF_TC_BODY(aio_pty_test, tc) struct termios ts; int error; - aio_available(); + ATF_REQUIRE_KERNEL_MODULE("aio"); ATF_REQUIRE_MSG(openpty(&read_fd, &write_fd, NULL, NULL, NULL) == 0, "openpty failed: %s", strerror(errno)); @@ -550,7 +543,7 @@ ATF_TC_BODY(aio_pipe_test, tc) struct aio_context ac; int pipes[2]; - aio_available(); + ATF_REQUIRE_KERNEL_MODULE("aio"); ATF_REQUIRE_MSG(pipe(pipes) != -1, "pipe failed: %s", strerror(errno)); @@ -613,7 +606,7 @@ ATF_TC_BODY(aio_md_test, tc) struct aio_context ac; struct md_ioctl mdio; - aio_available(); + ATF_REQUIRE_KERNEL_MODULE("aio"); mdctl_fd = open("/dev/" MDCTL_NAME, O_RDWR, 0); ATF_REQUIRE_MSG(mdctl_fd != -1, -- cgit v1.1 From 934db4e3400cb8369b8aae0e0822f462be873672 Mon Sep 17 00:00:00 2001 From: ngie Date: Tue, 28 Apr 2015 10:53:06 +0000 Subject: - Use ATF_REQUIRE_KERNEL_MDOULE to require aio(4) - Don't use /tmp as a basis for temporary files as it's outside of the ATF sandbox - Don't override MAX macro in sys/param.h MFC after: 6 days --- tests/sys/aio/aio_kqueue_test.c | 36 ++++++++++++++++++++---------------- tests/sys/aio/lio_kqueue_test.c | 22 +++++++++++++--------- 2 files changed, 33 insertions(+), 25 deletions(-) (limited to 'tests') diff --git a/tests/sys/aio/aio_kqueue_test.c b/tests/sys/aio/aio_kqueue_test.c index 87b4125..14e4729 100644 --- a/tests/sys/aio/aio_kqueue_test.c +++ b/tests/sys/aio/aio_kqueue_test.c @@ -46,25 +46,29 @@ #include #include -#define PATH_TEMPLATE "/tmp/aio.XXXXXXXXXX" +#include "freebsd_test_suite/macros.h" -#define MAX 128 +#define PATH_TEMPLATE "aio.XXXXXXXXXX" + +#define MAX_IOCBS 128 #define MAX_RUNS 300 /* #define DEBUG */ int main (int argc, char *argv[]) { - int fd; - struct aiocb *iocb[MAX], *kq_iocb; - int i, result, run, error, j; - char buffer[32768]; - int kq = kqueue(); + struct aiocb *iocb[MAX_IOCBS], *kq_iocb; + char *file, pathname[sizeof(PATH_TEMPLATE)+1]; struct kevent ke, kq_returned; struct timespec ts; - int cancel, pending, tmp_file = 0, failed = 0; - char *file, pathname[sizeof(PATH_TEMPLATE)+1]; + char buffer[32768]; + int cancel, error, failed = 0, fd, kq, pending, result, run; + int tmp_file = 0; + unsigned i, j; + + PLAIN_REQUIRE_KERNEL_MODULE("aio", 0); + kq = kqueue(); if (kq < 0) { perror("No kqeueue\n"); exit(1); @@ -86,7 +90,7 @@ main (int argc, char *argv[]) #ifdef DEBUG printf("Run %d\n", run); #endif - for (i = 0; i < MAX; i++) { + for (i = 0; i < nitems(iocb); i++) { iocb[i] = (struct aiocb *)calloc(1, sizeof(struct aiocb)); if (iocb[i] == NULL) @@ -94,7 +98,7 @@ main (int argc, char *argv[]) } pending = 0; - for (i = 0; i < MAX; i++) { + for (i = 0; i < nitems(iocb); i++) { pending++; iocb[i]->aio_nbytes = sizeof(buffer); iocb[i]->aio_buf = buffer; @@ -129,8 +133,8 @@ main (int argc, char *argv[]) } } } - cancel = MAX - pending; - + cancel = nitems(iocb) - pending; + i = 0; while (pending) { @@ -159,11 +163,11 @@ main (int argc, char *argv[]) break; #ifdef DEBUG printf("Try again left %d out of %d %d\n", - pending, MAX, cancel); + pending, nitems(iocb), cancel); #endif } - for (j = 0; j < MAX && iocb[j] != kq_iocb; + for (j = 0; j < nitems(iocb) && iocb[j] != kq_iocb; j++) ; #ifdef DEBUG printf("kq_iocb %p\n", kq_iocb); @@ -190,7 +194,7 @@ main (int argc, char *argv[]) i++; } - for (i = 0; i < MAX; i++) + for (i = 0; i < nitems(iocb); i++) free(iocb[i]); } diff --git a/tests/sys/aio/lio_kqueue_test.c b/tests/sys/aio/lio_kqueue_test.c index ad7fc68..5cc87b3 100644 --- a/tests/sys/aio/lio_kqueue_test.c +++ b/tests/sys/aio/lio_kqueue_test.c @@ -48,16 +48,18 @@ #include #include -#define PATH_TEMPLATE "/tmp/aio.XXXXXXXXXX" +#include "freebsd_test_suite/macros.h" + +#define PATH_TEMPLATE "aio.XXXXXXXXXX" #define LIO_MAX 5 -#define MAX LIO_MAX * 16 +#define MAX_IOCBS LIO_MAX * 16 #define MAX_RUNS 300 int main(int argc, char *argv[]){ int fd; - struct aiocb *iocb[MAX]; + struct aiocb *iocb[MAX_IOCBS]; struct aiocb **lio[LIO_MAX], **lio_element, **kq_lio; int i, result, run, error, j, k; char buffer[32768]; @@ -69,6 +71,8 @@ main(int argc, char *argv[]){ char *file, pathname[sizeof(PATH_TEMPLATE)-1]; int tmp_file = 0, failed = 0; + PLAIN_REQUIRE_KERNEL_MODULE("aio", 0); + if (kq < 0) { perror("No kqeueue\n"); exit(1); @@ -99,9 +103,9 @@ main(int argc, char *argv[]){ #endif for (j = 0; j < LIO_MAX; j++) { lio[j] = (struct aiocb **) - malloc(sizeof(struct aiocb *) * MAX/LIO_MAX); - for(i = 0; i < MAX / LIO_MAX; i++) { - k = (MAX / LIO_MAX * j) + i; + malloc(sizeof(struct aiocb *) * MAX_IOCBS/LIO_MAX); + for(i = 0; i < MAX_IOCBS / LIO_MAX; i++) { + k = (MAX_IOCBS / LIO_MAX * j) + i; lio_element = lio[j]; lio[j][i] = iocb[k] = (struct aiocb *) malloc(sizeof(struct aiocb)); @@ -123,7 +127,7 @@ main(int argc, char *argv[]){ sig.sigev_notify = SIGEV_KEVENT; time(&time1); result = lio_listio(LIO_NOWAIT, lio[j], - MAX / LIO_MAX, &sig); + MAX_IOCBS / LIO_MAX, &sig); error = errno; time(&time2); #ifdef DEBUG @@ -203,7 +207,7 @@ main(int argc, char *argv[]){ } else { printf("PASS: run %d, operation %d result %d \n", run, LIO_MAX - i -1, result); } - for(k = 0; k < MAX / LIO_MAX; k++){ + for(k = 0; k < MAX_IOCBS / LIO_MAX; k++){ result = aio_return(kq_lio[k]); #ifdef DEBUG printf("Return Resulto for %d %d is %d\n", j, k, result); @@ -220,7 +224,7 @@ main(int argc, char *argv[]){ printf("\n"); #endif - for(k = 0; k < MAX / LIO_MAX; k++) { + for(k = 0; k < MAX_IOCBS / LIO_MAX; k++) { free(lio[j][k]); } free(lio[j]); -- cgit v1.1 From 7c41d36452b84a6e92e0d5a1139a048ddc58ed5e Mon Sep 17 00:00:00 2001 From: ngie Date: Tue, 28 Apr 2015 10:56:59 +0000 Subject: Use PLAIN_REQUIRE_KERNEL_MODULE to require "mqueuefs" MFC after: 6 days --- tests/sys/mqueue/Makefile | 2 ++ tests/sys/mqueue/mqtest1.c | 4 ++++ tests/sys/mqueue/mqtest2.c | 4 ++++ tests/sys/mqueue/mqtest3.c | 4 ++++ tests/sys/mqueue/mqtest4.c | 4 ++++ tests/sys/mqueue/mqtest5.c | 4 ++++ 6 files changed, 22 insertions(+) (limited to 'tests') diff --git a/tests/sys/mqueue/Makefile b/tests/sys/mqueue/Makefile index 230fcb7..5af8b25 100644 --- a/tests/sys/mqueue/Makefile +++ b/tests/sys/mqueue/Makefile @@ -6,6 +6,8 @@ ATF_TESTS_SH= mqueue_test BINDIR= ${TESTSDIR} +CFLAGS+= -I${.CURDIR:H:H} + PROGS+= mqtest1 PROGS+= mqtest2 PROGS+= mqtest3 diff --git a/tests/sys/mqueue/mqtest1.c b/tests/sys/mqueue/mqtest1.c index 5590b87..3accb28 100644 --- a/tests/sys/mqueue/mqtest1.c +++ b/tests/sys/mqueue/mqtest1.c @@ -7,6 +7,8 @@ #include #include +#include "freebsd_test_suite/macros.h" + #define MQNAME "/mytstqueue1" int @@ -17,6 +19,8 @@ main(void) mqd_t mq; int status; + PLAIN_REQUIRE_KERNEL_MODULE("mqueuefs", 0); + attr.mq_maxmsg = 2; attr.mq_msgsize = 100; mq = mq_open(MQNAME, O_CREAT | O_RDWR | O_EXCL, 0666, &attr); diff --git a/tests/sys/mqueue/mqtest2.c b/tests/sys/mqueue/mqtest2.c index aaef43b..067e619 100644 --- a/tests/sys/mqueue/mqtest2.c +++ b/tests/sys/mqueue/mqtest2.c @@ -10,6 +10,8 @@ #include #include +#include "freebsd_test_suite/macros.h" + #define MQNAME "/mytstqueue2" #define LOOPS 1000 #define PRIO 10 @@ -29,6 +31,8 @@ main(void) int status; pid_t pid; + PLAIN_REQUIRE_KERNEL_MODULE("mqueuefs", 0); + mq_unlink(MQNAME); attr.mq_maxmsg = 5; diff --git a/tests/sys/mqueue/mqtest3.c b/tests/sys/mqueue/mqtest3.c index 4ee812c..c4b849e 100644 --- a/tests/sys/mqueue/mqtest3.c +++ b/tests/sys/mqueue/mqtest3.c @@ -11,6 +11,8 @@ #include #include +#include "freebsd_test_suite/macros.h" + #define MQNAME "/mytstqueue3" #define LOOPS 1000 #define PRIO 10 @@ -31,6 +33,8 @@ main(void) mqd_t mq; pid_t pid; + PLAIN_REQUIRE_KERNEL_MODULE("mqueuefs", 0); + mq_unlink(MQNAME); attr.mq_maxmsg = 5; diff --git a/tests/sys/mqueue/mqtest4.c b/tests/sys/mqueue/mqtest4.c index d249cf6..474d212 100644 --- a/tests/sys/mqueue/mqtest4.c +++ b/tests/sys/mqueue/mqtest4.c @@ -12,6 +12,8 @@ #include #include +#include "freebsd_test_suite/macros.h" + #define MQNAME "/mytstqueue4" #define LOOPS 1000 #define PRIO 10 @@ -32,6 +34,8 @@ main(void) int kq, status; pid_t pid; + PLAIN_REQUIRE_KERNEL_MODULE("mqueuefs", 0); + mq_unlink(MQNAME); attr.mq_maxmsg = 5; diff --git a/tests/sys/mqueue/mqtest5.c b/tests/sys/mqueue/mqtest5.c index 7f4d554..0c8aa89 100644 --- a/tests/sys/mqueue/mqtest5.c +++ b/tests/sys/mqueue/mqtest5.c @@ -12,6 +12,8 @@ #include #include +#include "freebsd_test_suite/macros.h" + #define MQNAME "/mytstqueue5" #define LOOPS 1000 #define PRIO 10 @@ -34,6 +36,8 @@ main(void) mqd_t mq; pid_t pid; + PLAIN_REQUIRE_KERNEL_MODULE("mqueuefs", 0); + mq_unlink(MQNAME); sigemptyset(&set); -- cgit v1.1 From f26a36793ea2217339e115c402f856916a482007 Mon Sep 17 00:00:00 2001 From: ngie Date: Tue, 28 Apr 2015 10:59:06 +0000 Subject: Adjust CFLAGS to find freebsd_test_suite/macros.h MFC after: 6 days --- tests/sys/aio/Makefile | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/sys/aio/Makefile b/tests/sys/aio/Makefile index 972059c..851252d 100644 --- a/tests/sys/aio/Makefile +++ b/tests/sys/aio/Makefile @@ -9,6 +9,8 @@ ATF_TESTS_C+= aio_test DPADD.aio_test+= ${LIBUTIL} LDADD.aio_test+= -lutil +CFLAGS+= -I${.CURDIR:H:H} + WARNS?= 6 .include -- cgit v1.1 From 699d6a9776809c40d52be400e3bb86875c38d859 Mon Sep 17 00:00:00 2001 From: ngie Date: Wed, 29 Apr 2015 08:56:56 +0000 Subject: ATF_REQUIRE_KERNEL_MODULE: use atf_skip, not ATF_REQUIRE_MSG so the testcase no longer bombs out PLAIN_REQUIRE_KERNEL_MODULE: use printf + _exit, no err so the testcase no longer bombs out if it prints to stderr MFC after: 5 days --- tests/freebsd_test_suite/macros.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/freebsd_test_suite/macros.h b/tests/freebsd_test_suite/macros.h index 755a994..bc0b610 100644 --- a/tests/freebsd_test_suite/macros.h +++ b/tests/freebsd_test_suite/macros.h @@ -32,21 +32,24 @@ #include #include #include -#include #include +#include +#include #include #define ATF_REQUIRE_KERNEL_MODULE(_mod_name) do { \ - ATF_REQUIRE_MSG(modfind(_mod_name) != -1, \ - "module %s could not be resolved: %s", \ - _mod_name, strerror(errno)); \ + if (modfind(_mod_name) == -1) { \ + atf_skip("module %s could not be resolved: %s", \ + _mod_name, strerror(errno)); \ + } \ } while(0) -#define PLAIN_REQUIRE_KERNEL_MODULE(_mod_name, _exit_code) do { \ +#define PLAIN_REQUIRE_KERNEL_MODULE(_mod_name, _exit_code) do { \ if (modfind(_mod_name) == -1) { \ - err(_exit_code, "module %s could not be resolved", \ - _mod_name); \ + printf("module %s could not be resolved: %s\n", \ + _mod_name, strerror(errno)); \ + _exit(_exit_code); \ } \ } while(0) -- cgit v1.1 From 0207f9a85e26c41b09c9186bd357bddbb82361bf Mon Sep 17 00:00:00 2001 From: ngie Date: Wed, 29 Apr 2015 19:08:11 +0000 Subject: Fix typo. It should have been atf_tc_skip, not atf_skip Reported by: many, Jenkins Pointyhat to: ngie MFC after: 4 days --- tests/freebsd_test_suite/macros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/freebsd_test_suite/macros.h b/tests/freebsd_test_suite/macros.h index bc0b610..8d95f05 100644 --- a/tests/freebsd_test_suite/macros.h +++ b/tests/freebsd_test_suite/macros.h @@ -40,7 +40,7 @@ #define ATF_REQUIRE_KERNEL_MODULE(_mod_name) do { \ if (modfind(_mod_name) == -1) { \ - atf_skip("module %s could not be resolved: %s", \ + atf_tc_skip("module %s could not be resolved: %s", \ _mod_name, strerror(errno)); \ } \ } while(0) -- cgit v1.1 From 110cd2db75fc5951e5df85c6e7ccd20126ab6e29 Mon Sep 17 00:00:00 2001 From: ngie Date: Mon, 18 May 2015 11:02:43 +0000 Subject: Move all test integration pieces for etc/ from etc/ to tests/ This is being done to fix breakage with make distribution with read-only source trees as make distribution doesn't use make obj like building tests/ does in all cases Reported by: Wolfgang Zenker Suggested by: jhb X-MFC with: r282059 MFC after: 1 week --- tests/Makefile | 1 + tests/etc/Makefile | 12 ++++ tests/etc/rc.d/Makefile | 7 +++ tests/etc/rc.d/routing_test.sh | 138 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 tests/etc/Makefile create mode 100644 tests/etc/rc.d/Makefile create mode 100755 tests/etc/rc.d/routing_test.sh (limited to 'tests') diff --git a/tests/Makefile b/tests/Makefile index 89da82d..12c1509 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -2,6 +2,7 @@ .include +SUBDIR= etc SUBDIR= sys TESTSDIR= ${TESTSBASE} diff --git a/tests/etc/Makefile b/tests/etc/Makefile new file mode 100644 index 0000000..9aad25c --- /dev/null +++ b/tests/etc/Makefile @@ -0,0 +1,12 @@ +# $FreeBSD$ + +.include + +TESTSDIR= ${TESTSBASE}/etc + +.PATH: ${.CURDIR:H} +KYUAFILE= yes + +SUBDIR+= rc.d + +.include diff --git a/tests/etc/rc.d/Makefile b/tests/etc/rc.d/Makefile new file mode 100644 index 0000000..368e8f4 --- /dev/null +++ b/tests/etc/rc.d/Makefile @@ -0,0 +1,7 @@ +# $FreeBSD$ + +TESTSDIR= ${TESTSBASE}/etc/rc.d + +ATF_TESTS_SH+= routing_test + +.include diff --git a/tests/etc/rc.d/routing_test.sh b/tests/etc/rc.d/routing_test.sh new file mode 100755 index 0000000..693af23 --- /dev/null +++ b/tests/etc/rc.d/routing_test.sh @@ -0,0 +1,138 @@ +# +# Copyright (c) 2014 Spectra Logic Corporation +# 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, +# without modification. +# 2. Redistributions in binary form must reproduce at minimum a disclaimer +# substantially similar to the "NO WARRANTY" disclaimer below +# ("Disclaimer") and any redistribution must be conditioned upon +# including a substantially similar Disclaimer requirement for further +# binary redistribution. +# +# NO WARRANTY +# 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 MERCHANTIBILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDERS OR CONTRIBUTORS BE LIABLE FOR 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 DAMAGES. +# +# Authors: Alan Somers (Spectra Logic Corporation) +# +# $FreeBSD$ + +atf_test_case static_ipv6_loopback_route_for_each_fib cleanup +static_ipv6_loopback_route_for_each_fib_head() +{ + atf_set "descr" "Every FIB should have a static IPv6 loopback route" + atf_set "require.user" "root" + atf_set "require.config" "fibs" + atf_set "require.progs" "sysrc" +} +static_ipv6_loopback_route_for_each_fib_body() +{ + # Configure the TAP interface to use an RFC5737 nonrouteable address + # and a non-default fib + ADDR="192.0.2.2" + SUBNET="192.0.2.0" + MASK="24" + + # Check system configuration + if [ 0 != `sysctl -n net.add_addr_allfibs` ]; then + atf_skip "This test requires net.add_addr_allfibs=0" + fi + + get_fibs 1 + get_tap + + # Configure a TAP interface in /etc/rc.conf. Register the sysrc + # variable for cleanup. + echo "ifconfig_${TAP}" >> "sysrc_vars_to_cleanup" + sysrc ifconfig_${TAP}="${ADDR}/${MASK} fib ${FIB0}" + + # Start the interface + service netif start ${TAP} + # Check for an IPv6 loopback route + setfib ${FIB0} netstat -rn -f inet6 | grep -q "^::1.*lo0$" + if [ 0 -eq $? ]; then + atf_pass + else + setfib ${FIB0} netstat -rn -f inet6 + atf_fail "Did not find an IPv6 loopback route" + fi +} +static_ipv6_loopback_route_for_each_fib_cleanup() +{ + cleanup_sysrc + cleanup_tap +} + +atf_init_test_cases() +{ + atf_add_test_case static_ipv6_loopback_route_for_each_fib +} + +# Looks up one or more fibs from the configuration data and validates them. +# Returns the results in the env varilables FIB0, FIB1, etc. +# parameter numfibs The number of fibs to lookup +get_fibs() +{ + NUMFIBS=$1 + net_fibs=`sysctl -n net.fibs` + i=0 + while [ $i -lt "$NUMFIBS" ]; do + fib=`atf_config_get "fibs" | \ + awk -v i=$(( i + 1 )) '{print $i}'` + echo "fib is ${fib}" + eval FIB${i}=${fib} + if [ "$fib" -ge "$net_fibs" ]; then + msg="The ${i}th configured fib is ${fub}, which is " + msg="$msg not less than net.fibs (${net_fibs})" + atf_skip "$msg" + fi + i=$(( $i + 1 )) + done +} + + +# Creates a new tap(4) interface, registers it for cleanup, and returns the +# name via the environment variable TAP +get_tap() +{ + local TAPN=0 + while ! ifconfig tap${TAPN} create > /dev/null 2>&1; do + if [ "$TAPN" -ge 8 ]; then + atf_skip "Could not create a tap(4) interface" + else + TAPN=$(($TAPN + 1)) + fi + done + local TAPD=tap${TAPN} + # Record the TAP device so we can clean it up later + echo ${TAPD} >> "tap_devices_to_cleanup" + TAP=${TAPD} +} + +cleanup_sysrc() +{ + for var in `cat "sysrc_vars_to_cleanup"`; do + sysrc -x $var + done +} + +cleanup_tap() +{ + for TAPD in `cat "tap_devices_to_cleanup"`; do + ifconfig ${TAPD} destroy + done +} -- cgit v1.1 From 5ad66fe3b2ec48024e4b2a87477228443a9e414b Mon Sep 17 00:00:00 2001 From: jhb Date: Fri, 22 May 2015 11:04:54 +0000 Subject: Only reparent a traced process to its old parent if the tracing process is not the old parent. Otherwise, proc_reap() will leave the zombie in place resulting in the process' status being returned twice to its parent. Add test cases for PT_TRACE_ME and PT_ATTACH which are fixed by this change. Differential Revision: https://reviews.freebsd.org/D2594 Reviewed by: kib MFC after: 2 weeks --- tests/sys/kern/Makefile | 1 + tests/sys/kern/ptrace_test.c | 143 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 tests/sys/kern/ptrace_test.c (limited to 'tests') diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile index d366aa1..bf6aa0d 100644 --- a/tests/sys/kern/Makefile +++ b/tests/sys/kern/Makefile @@ -3,6 +3,7 @@ TESTSDIR= ${TESTSBASE}/sys/kern ATF_TESTS_C+= kern_descrip_test +ATF_TESTS_C+= ptrace_test ATF_TESTS_C+= unix_seqpacket_test TEST_METADATA.unix_seqpacket_test+= timeout="15" diff --git a/tests/sys/kern/ptrace_test.c b/tests/sys/kern/ptrace_test.c new file mode 100644 index 0000000..28b0592 --- /dev/null +++ b/tests/sys/kern/ptrace_test.c @@ -0,0 +1,143 @@ +/*- + * Copyright (c) 2015 John Baldwin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Verify that a parent debugger process "sees" the exit of a debugged + * process exactly once when attached via PT_TRACE_ME. + */ +ATF_TC_WITHOUT_HEAD(ptrace__parent_wait_after_trace_me); +ATF_TC_BODY(ptrace__parent_wait_after_trace_me, tc) +{ + pid_t child, wpid; + int status; + + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + /* Child process. */ + ATF_REQUIRE(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + /* Trigger a stop. */ + raise(SIGSTOP); + + exit(1); + } + + /* Parent process. */ + + /* The first wait() should report the stop from SIGSTOP. */ + wpid = waitpid(child, &status, 0); + ATF_REQUIRE(wpid == child); + ATF_REQUIRE(WIFSTOPPED(status)); + ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP); + + /* Continue the child ignoring the SIGSTOP. */ + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1); + + /* The second wait() should report the exit status. */ + wpid = waitpid(child, &status, 0); + ATF_REQUIRE(wpid == child); + ATF_REQUIRE(WIFEXITED(status)); + ATF_REQUIRE(WEXITSTATUS(status) == 1); + + /* The child should no longer exist. */ + wpid = waitpid(child, &status, 0); + ATF_REQUIRE(wpid == -1); + ATF_REQUIRE(errno == ECHILD); +} + +/* + * Verify that a parent debugger process "sees" the exit of a debugged + * process exactly once when attached via PT_ATTACH. + */ +ATF_TC_WITHOUT_HEAD(ptrace__parent_wait_after_attach); +ATF_TC_BODY(ptrace__parent_wait_after_attach, tc) +{ + pid_t child, wpid; + int cpipe[2], status; + char c; + + ATF_REQUIRE(pipe(cpipe) == 0); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + /* Child process. */ + close(cpipe[0]); + + /* Wait for the parent to attach. */ + ATF_REQUIRE(read(cpipe[1], &c, sizeof(c)) == 0); + + exit(1); + } + close(cpipe[1]); + + /* Parent process. */ + + /* Attach to the child process. */ + ATF_REQUIRE(ptrace(PT_ATTACH, child, NULL, 0) == 0); + + /* The first wait() should report the SIGSTOP from PT_ATTACH. */ + wpid = waitpid(child, &status, 0); + ATF_REQUIRE(wpid == child); + ATF_REQUIRE(WIFSTOPPED(status)); + ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP); + + /* Continue the child ignoring the SIGSTOP. */ + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1); + + /* Signal the child to exit. */ + close(cpipe[0]); + + /* The second wait() should report the exit status. */ + wpid = waitpid(child, &status, 0); + ATF_REQUIRE(wpid == child); + ATF_REQUIRE(WIFEXITED(status)); + ATF_REQUIRE(WEXITSTATUS(status) == 1); + + /* The child should no longer exist. */ + wpid = waitpid(child, &status, 0); + ATF_REQUIRE(wpid == -1); + ATF_REQUIRE(errno == ECHILD); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, ptrace__parent_wait_after_trace_me); + ATF_TP_ADD_TC(tp, ptrace__parent_wait_after_attach); + + return (atf_no_error()); +} -- cgit v1.1