CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Tue May 14 15:54:16 UTC 2024 Modified Files: src/tests/kernel: h_segv.c Log Message: tests/kernel/h_segv: Disable SIGFPE test on RISC-V. No floating-point exception traps on RISC-V. Also don't pass the result of divide-by-zero converted to integer to usleep. Although the floating-point result of divide-by-zero is well-defined by IEEE 754 (+/-infinity), the outcome of C conversion to integer is not. And while on some architectures this might return zero, on RISC-V it looks like it'll return all bits set. And as of PR 58184, usleep now honours sleeps longer than 1sec, which means this will be waiting at least two billion microseconds, or about half an hour... So instead, just write the result to a volatile variable. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/tests/kernel/h_segv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/h_segv.c diff -u src/tests/kernel/h_segv.c:1.14 src/tests/kernel/h_segv.c:1.15 --- src/tests/kernel/h_segv.c:1.14 Thu Apr 25 19:37:09 2019 +++ src/tests/kernel/h_segv.c Tue May 14 15:54:16 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: h_segv.c,v 1.14 2019/04/25 19:37:09 kamil Exp $ */ +/* $NetBSD: h_segv.c,v 1.15 2024/05/14 15:54:16 riastradh Exp $ */ /*- * Copyright (c) 2017 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: h_segv.c,v 1.14 2019/04/25 19:37:09 kamil Exp $"); +__RCSID("$NetBSD: h_segv.c,v 1.15 2024/05/14 15:54:16 riastradh Exp $"); #define __TEST_FENV @@ -121,10 +121,15 @@ check_fpe(void) printf("FPU does not implement traps on FP exceptions\n"); exit(EXIT_FAILURE); } +#elif defined __riscv__ + printf("RISC-V does not support floating-point exception traps\n"); + exit(EXIT_FAILURE); #endif exit(EXIT_SUCCESS); } +volatile int ignore_result; + static void trigger_fpe(void) { @@ -135,7 +140,13 @@ trigger_fpe(void) feenableexcept(FE_ALL_EXCEPT); #endif - usleep((int)(a/b)); + /* + * Try to trigger SIGFPE either by dividing by zero (which is + * defined to raise FE_DIVBYZERO, but may just return infinity + * without trapping the exception) or by converting infinity to + * integer. + */ + ignore_result = (int)(a/b); } static void
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Tue May 14 15:54:16 UTC 2024 Modified Files: src/tests/kernel: h_segv.c Log Message: tests/kernel/h_segv: Disable SIGFPE test on RISC-V. No floating-point exception traps on RISC-V. Also don't pass the result of divide-by-zero converted to integer to usleep. Although the floating-point result of divide-by-zero is well-defined by IEEE 754 (+/-infinity), the outcome of C conversion to integer is not. And while on some architectures this might return zero, on RISC-V it looks like it'll return all bits set. And as of PR 58184, usleep now honours sleeps longer than 1sec, which means this will be waiting at least two billion microseconds, or about half an hour... So instead, just write the result to a volatile variable. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/tests/kernel/h_segv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Fri Nov 24 16:36:23 UTC 2023 Modified Files: src/tests/kernel: t_rnd.c Log Message: t_rnd: Nix trailing whitespace. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/tests/kernel/t_rnd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Fri Nov 24 16:36:23 UTC 2023 Modified Files: src/tests/kernel: t_rnd.c Log Message: t_rnd: Nix trailing whitespace. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/tests/kernel/t_rnd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_rnd.c diff -u src/tests/kernel/t_rnd.c:1.12 src/tests/kernel/t_rnd.c:1.13 --- src/tests/kernel/t_rnd.c:1.12 Fri Nov 24 16:35:51 2023 +++ src/tests/kernel/t_rnd.c Fri Nov 24 16:36:23 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: t_rnd.c,v 1.12 2023/11/24 16:35:51 riastradh Exp $ */ +/* $NetBSD: t_rnd.c,v 1.13 2023/11/24 16:36:23 riastradh Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_rnd.c,v 1.12 2023/11/24 16:35:51 riastradh Exp $"); +__RCSID("$NetBSD: t_rnd.c,v 1.13 2023/11/24 16:36:23 riastradh Exp $"); #include #include @@ -81,7 +81,7 @@ ATF_TC_BODY(RNDADDDATA2, tc) fd = rump_sys_open("/dev/random", O_RDWR, 0); if (fd == -1) atf_tc_fail_errno("cannot open /dev/random"); - + rd.entropy = 1; rd.len = -1; ATF_REQUIRE_ERRNO(EINVAL, rump_sys_ioctl(fd, RNDADDDATA, ) == -1);
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Fri Nov 24 16:35:51 UTC 2023 Modified Files: src/tests/kernel: t_rnd.c Log Message: t_rnd: Fix misuse of RZ. Not likely to matter, but in the unlikely event that rump_sys_close fails, it will return -1 and set errno as RL expects, not return the error code as RZ expects. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/tests/kernel/t_rnd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_rnd.c diff -u src/tests/kernel/t_rnd.c:1.11 src/tests/kernel/t_rnd.c:1.12 --- src/tests/kernel/t_rnd.c:1.11 Sun Apr 16 18:24:23 2017 +++ src/tests/kernel/t_rnd.c Fri Nov 24 16:35:51 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: t_rnd.c,v 1.11 2017/04/16 18:24:23 riastradh Exp $ */ +/* $NetBSD: t_rnd.c,v 1.12 2023/11/24 16:35:51 riastradh Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_rnd.c,v 1.11 2017/04/16 18:24:23 riastradh Exp $"); +__RCSID("$NetBSD: t_rnd.c,v 1.12 2023/11/24 16:35:51 riastradh Exp $"); #include #include @@ -106,7 +106,7 @@ ATF_TC_BODY(read_random, tc) alarm(2); RL(fd = rump_sys_open("/dev/random", RUMP_O_RDONLY)); RL(rump_sys_read(fd, buf, sizeof(buf))); - RZ(rump_sys_close(fd)); + RL(rump_sys_close(fd)); } }
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Fri Nov 24 16:35:51 UTC 2023 Modified Files: src/tests/kernel: t_rnd.c Log Message: t_rnd: Fix misuse of RZ. Not likely to matter, but in the unlikely event that rump_sys_close fails, it will return -1 and set errno as RL expects, not return the error code as RZ expects. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/tests/kernel/t_rnd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Sat Nov 18 19:46:55 UTC 2023 Modified Files: src/tests/kernel: t_fdrestart.c Log Message: t_fdrestart: Mark some tests no longer xfail. Backing out ad's changes last month seemed to fix the symptoms (although I'm pretty sure this logic is still broken, more to come). PR kern/57659 To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/t_fdrestart.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_fdrestart.c diff -u src/tests/kernel/t_fdrestart.c:1.3 src/tests/kernel/t_fdrestart.c:1.4 --- src/tests/kernel/t_fdrestart.c:1.3 Sun Oct 15 15:18:17 2023 +++ src/tests/kernel/t_fdrestart.c Sat Nov 18 19:46:55 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: t_fdrestart.c,v 1.3 2023/10/15 15:18:17 riastradh Exp $ */ +/* $NetBSD: t_fdrestart.c,v 1.4 2023/11/18 19:46:55 riastradh Exp $ */ /*- * Copyright (c) 2023 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #define _KMEMUSER /* ERESTART */ #include -__RCSID("$NetBSD: t_fdrestart.c,v 1.3 2023/10/15 15:18:17 riastradh Exp $"); +__RCSID("$NetBSD: t_fdrestart.c,v 1.4 2023/11/18 19:46:55 riastradh Exp $"); #include #include @@ -198,7 +198,6 @@ ATF_TC_BODY(pipe_read, tc) memset(F, 0, sizeof(*F)); F->op = F->fd = fd[0]; - atf_tc_expect_fail("PR kern/57659"); testfdrestart(F); } @@ -240,7 +239,6 @@ ATF_TC_BODY(socketpair_read, tc) memset(F, 0, sizeof(*F)); F->op = F->fd = fd[0]; - atf_tc_expect_fail("PR kern/57659"); testfdrestart(F); } @@ -261,7 +259,6 @@ ATF_TC_BODY(socketpair_write, tc) memset(F, 0, sizeof(*F)); F->op = F->fd = fd[0]; - atf_tc_expect_fail("PR kern/57659"); testfdrestart(F); }
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Sat Nov 18 19:46:55 UTC 2023 Modified Files: src/tests/kernel: t_fdrestart.c Log Message: t_fdrestart: Mark some tests no longer xfail. Backing out ad's changes last month seemed to fix the symptoms (although I'm pretty sure this logic is still broken, more to come). PR kern/57659 To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/t_fdrestart.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Sun Oct 15 15:18:17 UTC 2023 Modified Files: src/tests/kernel: t_fdrestart.c Log Message: t_fdrestart: Rework this to be a little more robust. For the write test, need to make sure the pipe's buffer is full first before the write that blocks, so that it doesn't return partial progress rather than ERESTART if woken. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/t_fdrestart.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_fdrestart.c diff -u src/tests/kernel/t_fdrestart.c:1.2 src/tests/kernel/t_fdrestart.c:1.3 --- src/tests/kernel/t_fdrestart.c:1.2 Sun Oct 15 14:30:51 2023 +++ src/tests/kernel/t_fdrestart.c Sun Oct 15 15:18:17 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: t_fdrestart.c,v 1.2 2023/10/15 14:30:51 riastradh Exp $ */ +/* $NetBSD: t_fdrestart.c,v 1.3 2023/10/15 15:18:17 riastradh Exp $ */ /*- * Copyright (c) 2023 The NetBSD Foundation, Inc. @@ -29,8 +29,9 @@ #define _KMEMUSER /* ERESTART */ #include -__RCSID("$NetBSD: t_fdrestart.c,v 1.2 2023/10/15 14:30:51 riastradh Exp $"); +__RCSID("$NetBSD: t_fdrestart.c,v 1.3 2023/10/15 15:18:17 riastradh Exp $"); +#include #include #include @@ -51,18 +52,47 @@ struct fdrestart { }; static void +waitforbarrier(struct fdrestart *F, const char *caller) +{ + int error; + + error = pthread_barrier_wait(>barrier); + switch (error) { + case 0: + case PTHREAD_BARRIER_SERIAL_THREAD: + break; + default: + atf_tc_fail("%s: pthread_barrier_wait: %d, %s", caller, error, + strerror(error)); + } +} + +static void doread(struct fdrestart *F) { char c; ssize_t nread; int error; + /* + * Wait for the other thread to be ready. + */ + waitforbarrier(F, "reader"); + + /* + * Start a read. This should block, and then, when the other + * thread closes the fd, should be woken to fail with ERESTART. + */ nread = rump_sys_read(F->fd, , sizeof(c)); ATF_REQUIRE_EQ_MSG(nread, -1, "nread=%zd", nread); error = errno; ATF_REQUIRE_EQ_MSG(error, ERESTART, "errno=%d (%s)", error, strerror(error)); + /* + * Now further attempts at I/O should fail with EBADF because + * the fd has been closed. + */ nread = rump_sys_read(F->fd, , sizeof(c)); ATF_REQUIRE_EQ_MSG(nread, -1, "nread=%zd", nread); error = errno; @@ -77,14 +107,38 @@ dowrite(struct fdrestart *F) ssize_t nwrit; int error; + /* + * Make sure the pipe's buffer is full first. + */ + for (;;) { + int nspace; + + RL(rump_sys_ioctl(F->fd, FIONSPACE, )); + ATF_REQUIRE_MSG(nspace >= 0, "nspace=%d", nspace); + if (nspace == 0) + break; + RL(rump_sys_write(F->fd, buf, (size_t)nspace)); + } + + /* + * Wait for the other thread to be ready. + */ + waitforbarrier(F, "writer"); + + /* + * Start a write. This should block, and then, when the other + * thread closes the fd, should be woken to fail with ERESTART. + */ nwrit = rump_sys_write(F->fd, buf, sizeof(buf)); - if (nwrit != -1) /* filled buffer, try again */ - nwrit = rump_sys_write(F->fd, buf, sizeof(buf)); ATF_REQUIRE_EQ_MSG(nwrit, -1, "nwrit=%zd", nwrit); error = errno; ATF_REQUIRE_EQ_MSG(error, ERESTART, "errno=%d (%s)", error, strerror(error)); + /* + * Now further attempts at I/O should fail with EBADF because + * the fd has been closed. + */ nwrit = rump_sys_write(F->fd, buf, sizeof(buf)); ATF_REQUIRE_EQ_MSG(nwrit, -1, "nwrit=%zd", nwrit); error = errno; @@ -92,28 +146,11 @@ dowrite(struct fdrestart *F) strerror(error)); } -static void -waitforbarrier(struct fdrestart *F, const char *caller) -{ - int error; - - error = pthread_barrier_wait(>barrier); - switch (error) { - case 0: - case PTHREAD_BARRIER_SERIAL_THREAD: - break; - default: - atf_tc_fail("%s: pthread_barrier_wait: %d, %s", caller, error, - strerror(error)); - } -} - static void * doit(void *cookie) { struct fdrestart *F = cookie; - waitforbarrier(F, "user"); (*F->op)(F); return NULL; @@ -138,9 +175,10 @@ testfdrestart(struct fdrestart *F) RZ(pthread_create(, NULL, , F)); waitforbarrier(F, "closer"); /* wait for thread to start */ (void)sleep(1); /* wait for op to start */ - (void)alarm(1); - RL(rump_sys_close(F->fd)); - RZ(pthread_join(t, NULL)); + (void)alarm(1); /* set a deadline */ + RL(rump_sys_close(F->fd)); /* wake op in other thread */ + RZ(pthread_join(t, NULL)); /* wait for op to wake and fail */ + (void)alarm(0); /* clear the deadline */ } ATF_TC(pipe_read);
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Sun Oct 15 15:18:17 UTC 2023 Modified Files: src/tests/kernel: t_fdrestart.c Log Message: t_fdrestart: Rework this to be a little more robust. For the write test, need to make sure the pipe's buffer is full first before the write that blocks, so that it doesn't return partial progress rather than ERESTART if woken. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/t_fdrestart.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Sun Oct 15 14:30:52 UTC 2023 Modified Files: src/tests/kernel: t_fdrestart.c Log Message: t_fdrestart: Verify rump_sys_write failed second time around. PR kern/57659 To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_fdrestart.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_fdrestart.c diff -u src/tests/kernel/t_fdrestart.c:1.1 src/tests/kernel/t_fdrestart.c:1.2 --- src/tests/kernel/t_fdrestart.c:1.1 Sun Oct 15 13:22:52 2023 +++ src/tests/kernel/t_fdrestart.c Sun Oct 15 14:30:51 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: t_fdrestart.c,v 1.1 2023/10/15 13:22:52 riastradh Exp $ */ +/* $NetBSD: t_fdrestart.c,v 1.2 2023/10/15 14:30:51 riastradh Exp $ */ /*- * Copyright (c) 2023 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #define _KMEMUSER /* ERESTART */ #include -__RCSID("$NetBSD: t_fdrestart.c,v 1.1 2023/10/15 13:22:52 riastradh Exp $"); +__RCSID("$NetBSD: t_fdrestart.c,v 1.2 2023/10/15 14:30:51 riastradh Exp $"); #include #include @@ -86,6 +86,7 @@ dowrite(struct fdrestart *F) strerror(error)); nwrit = rump_sys_write(F->fd, buf, sizeof(buf)); + ATF_REQUIRE_EQ_MSG(nwrit, -1, "nwrit=%zd", nwrit); error = errno; ATF_REQUIRE_EQ_MSG(error, EBADF, "errno=%d (%s)", error, strerror(error));
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Sun Oct 15 14:30:52 UTC 2023 Modified Files: src/tests/kernel: t_fdrestart.c Log Message: t_fdrestart: Verify rump_sys_write failed second time around. PR kern/57659 To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_fdrestart.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Sat Aug 5 08:05:16 UTC 2023 Modified Files: src/tests/kernel: t_fcntl.c Log Message: memfd(2): Run all tests; don't stop after the first failure. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/t_fcntl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_fcntl.c diff -u src/tests/kernel/t_fcntl.c:1.3 src/tests/kernel/t_fcntl.c:1.4 --- src/tests/kernel/t_fcntl.c:1.3 Sat Jul 29 12:16:34 2023 +++ src/tests/kernel/t_fcntl.c Sat Aug 5 08:05:16 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: t_fcntl.c,v 1.3 2023/07/29 12:16:34 christos Exp $ */ +/* $NetBSD: t_fcntl.c,v 1.4 2023/08/05 08:05:16 riastradh Exp $ */ /*- * Copyright (c) 2019 The NetBSD Foundation, Inc. @@ -108,14 +108,18 @@ ATF_TC_BODY(getpath_memfd, tc) for (size_t i = 0; i < __arraycount(memfd_names); i++) { fd = memfd_create(memfd_names[i].bare, 0); - ATF_REQUIRE_MSG(fd != -1, "Failed to create memfd (%s)", + ATF_CHECK_MSG(fd != -1, "Failed to create memfd (%s)", strerror(errno)); + if (fd == -1) + continue; rv = fcntl(fd, F_GETPATH, path); - ATF_REQUIRE_MSG(rv != -1, "Can't get path `%s' (%s)", + ATF_CHECK_MSG(rv != -1, "Can't get path `%s' (%s)", memfd_names[i].bare, strerror(errno)); - ATF_REQUIRE_MSG(strcmp(memfd_names[i].prefixed, path) == 0, + if (rv == -1) + goto next; + ATF_CHECK_MSG(strcmp(memfd_names[i].prefixed, path) == 0, "Bad name `%s' != `%s'", path, memfd_names[i].prefixed); - close(fd); +next: close(fd); } }
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Sat Aug 5 08:05:16 UTC 2023 Modified Files: src/tests/kernel: t_fcntl.c Log Message: memfd(2): Run all tests; don't stop after the first failure. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/t_fcntl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: rin Date: Sat Jul 29 16:24:36 UTC 2023 Modified Files: src/tests/kernel: t_memfd_create.c Log Message: t_memfd_create: Fix printf-like format by using %zu for size_t, and %jd for off_t with cast to intmax_t, respectively. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_memfd_create.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_memfd_create.c diff -u src/tests/kernel/t_memfd_create.c:1.1 src/tests/kernel/t_memfd_create.c:1.2 --- src/tests/kernel/t_memfd_create.c:1.1 Sat Jul 29 12:16:34 2023 +++ src/tests/kernel/t_memfd_create.c Sat Jul 29 16:24:35 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: t_memfd_create.c,v 1.1 2023/07/29 12:16:34 christos Exp $ */ +/* $NetBSD: t_memfd_create.c,v 1.2 2023/07/29 16:24:35 rin Exp $ */ /*- * Copyright (c) 2023 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_memfd_create.c,v 1.1 2023/07/29 12:16:34 christos Exp $"); +__RCSID("$NetBSD: t_memfd_create.c,v 1.2 2023/07/29 16:24:35 rin Exp $"); #include #include @@ -106,7 +106,7 @@ ATF_TC_BODY(read_write, tc) RL(write(fd, write_buf, sizeof(write_buf))); offset = lseek(fd, 0, SEEK_CUR); ATF_REQUIRE_EQ_MSG(offset, sizeof(write_buf), - "File offset not set after write (%ld != %ld)", offset, + "File offset not set after write (%jd != %zu)", (intmax_t)offset, sizeof(write_buf)); RZ(lseek(fd, 0, SEEK_SET)); @@ -114,7 +114,7 @@ ATF_TC_BODY(read_write, tc) RL(read(fd, read_buf, sizeof(read_buf))); offset = lseek(fd, 0, SEEK_CUR); ATF_REQUIRE_EQ_MSG(offset, sizeof(read_buf), - "File offset not set after read (%ld != %ld)", offset, + "File offset not set after read (%jd != %zu)", (intmax_t)offset, sizeof(read_buf)); for (size_t i = 0; i < sizeof(read_buf); i++) @@ -143,20 +143,20 @@ ATF_TC_BODY(truncate, tc) RL(fstat(fd, )); ATF_REQUIRE_EQ_MSG(st.st_size, sizeof(write_buf), - "Write did not grow size to %ld (is %ld)", sizeof(write_buf), - st.st_size); + "Write did not grow size to %zu (is %jd)", sizeof(write_buf), + (intmax_t)st.st_size); RL(ftruncate(fd, sizeof(write_buf)/2)); RL(fstat(fd, )); ATF_REQUIRE_EQ_MSG(st.st_size, sizeof(write_buf)/2, - "Truncate did not shrink size to %ld (is %ld)", - sizeof(write_buf)/2, st.st_size); + "Truncate did not shrink size to %zu (is %jd)", + sizeof(write_buf)/2, (intmax_t)st.st_size); RL(ftruncate(fd, sizeof(read_buf))); RL(fstat(fd, )); ATF_REQUIRE_EQ_MSG(st.st_size, sizeof(read_buf), - "Truncate did not grow size to %ld (is %ld)", sizeof(read_buf), - st.st_size); + "Truncate did not grow size to %zu (is %jd)", sizeof(read_buf), + (intmax_t)st.st_size); RZ(lseek(fd, 0, SEEK_SET)); RL(read(fd, read_buf, sizeof(read_buf)));
CVS commit: src/tests/kernel
Module Name:src Committed By: rin Date: Sat Jul 29 16:24:36 UTC 2023 Modified Files: src/tests/kernel: t_memfd_create.c Log Message: t_memfd_create: Fix printf-like format by using %zu for size_t, and %jd for off_t with cast to intmax_t, respectively. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_memfd_create.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: mrg Date: Tue Jul 18 06:37:55 UTC 2023 Modified Files: src/tests/kernel: gen_t_subr_prf Log Message: provide more things needed by new subr_prf.c. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/kernel/gen_t_subr_prf Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/gen_t_subr_prf diff -u src/tests/kernel/gen_t_subr_prf:1.8 src/tests/kernel/gen_t_subr_prf:1.9 --- src/tests/kernel/gen_t_subr_prf:1.8 Tue May 21 04:10:20 2019 +++ src/tests/kernel/gen_t_subr_prf Tue Jul 18 06:37:55 2023 @@ -25,6 +25,16 @@ cat << _EOF > $2 #define kmem_alloc(n, f) malloc(n) +#define kprintf_lock() __nothing +#define kprintf_unlock() __nothing + +/* Arbitrary */ +#define TOCONS 1 +#define TOLOG 2 + +#define kprintf_internal(f, i1, i2, i3, ...) \ + printf(f, __VA_ARGS__) + static int putchar(char c, int foo, void *b) { return fputc(c, stderr);
CVS commit: src/tests/kernel
Module Name:src Committed By: mrg Date: Tue Jul 18 06:37:55 UTC 2023 Modified Files: src/tests/kernel: gen_t_subr_prf Log Message: provide more things needed by new subr_prf.c. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/kernel/gen_t_subr_prf Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: gutteridge Date: Fri May 5 01:27:18 UTC 2023 Modified Files: src/tests/kernel: t_trapsignal.sh Log Message: t_trapsignal.sh: fix head() function definitions of test cases To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/kernel/t_trapsignal.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_trapsignal.sh diff -u src/tests/kernel/t_trapsignal.sh:1.5 src/tests/kernel/t_trapsignal.sh:1.6 --- src/tests/kernel/t_trapsignal.sh:1.5 Sat Jan 26 16:44:30 2019 +++ src/tests/kernel/t_trapsignal.sh Fri May 5 01:27:18 2023 @@ -1,4 +1,4 @@ -# $NetBSD: t_trapsignal.sh,v 1.5 2019/01/26 16:44:30 martin Exp $ +# $NetBSD: t_trapsignal.sh,v 1.6 2023/05/05 01:27:18 gutteridge Exp $ # # Copyright (c) 2017 The NetBSD Foundation, Inc. # All rights reserved. @@ -33,7 +33,7 @@ HELPER=$(atf_get_srcdir)/h_segv # SIGSEGV atf_test_case segv_simple -segv_simple() +segv_simple_head() { atf_set "descr" "Test unhandled SIGSEGV with the right exit code" } @@ -44,7 +44,7 @@ segv_simple_body() } atf_test_case segv_handle -segv_handle() +segv_handle_head() { atf_set "descr" "Test handled SIGSEGV traps call the signal handler" } @@ -55,7 +55,7 @@ segv_handle_body() } atf_test_case segv_mask -segv_mask() +segv_mask_head() { atf_set "descr" "Test that masking SIGSEGV get reset" } @@ -66,7 +66,7 @@ segv_mask_body() } atf_test_case segv_handle_mask -segv_handle_mask() +segv_handle_mask_head() { atf_set "descr" "Test handled and masked SIGSEGV traps get reset" } @@ -77,7 +77,7 @@ segv_handle_mask_body() } atf_test_case segv_handle_recurse -segv_handle_recurse() +segv_handle_recurse_head() { atf_set "descr" "Test that receiving SIGSEGV in the handler resets" } @@ -89,7 +89,7 @@ segv_handle_recurse_body() } atf_test_case segv_ignore -segv_ignore() +segv_ignore_head() { atf_set "descr" "Test ignored SIGSEGV trap with right exit code" } @@ -103,7 +103,7 @@ segv_ignore_body() # SIGTRAP atf_test_case trap_simple -trap_simple() +trap_simple_head() { atf_set "descr" "Test unhandled SIGTRAP with the right exit code" } @@ -114,7 +114,7 @@ trap_simple_body() } atf_test_case trap_handle -trap_handle() +trap_handle_head() { atf_set "descr" "Test handled SIGTRAP traps call the signal handler" } @@ -125,7 +125,7 @@ trap_handle_body() } atf_test_case trap_mask -trap_mask() +trap_mask_head() { atf_set "descr" "Test that masking the trapped SIGTRAP signal get reset" } @@ -136,7 +136,7 @@ trap_mask_body() } atf_test_case trap_handle_mask -trap_handle_mask() +trap_handle_mask_head() { atf_set "descr" "Test handled and masked SIGTRAP traps get reset" } @@ -147,7 +147,7 @@ trap_handle_mask_body() } atf_test_case trap_handle_recurse -trap_handle_recurse() +trap_handle_recurse_head() { atf_set "descr" "Test that receiving SIGTRAP in the handler resets" } @@ -159,7 +159,7 @@ trap_handle_recurse_body() } atf_test_case trap_ignore -trap_ignore() +trap_ignore_head() { atf_set "descr" "Test ignored trap with right exit code" } @@ -185,7 +185,7 @@ fpe_available() } atf_test_case fpe_simple -fpe_simple() +fpe_simple_head() { atf_set "descr" "Test unhandled SIGFPE with the right exit code" } @@ -197,7 +197,7 @@ fpe_simple_body() } atf_test_case fpe_handle -fpe_handle() +fpe_handle_head() { atf_set "descr" "Test handled SIGFPE traps call the signal handler" } @@ -209,7 +209,7 @@ fpe_handle_body() } atf_test_case fpe_mask -fpe_mask() +fpe_mask_head() { atf_set "descr" "Test that masking the trapped SIGFPE signal get reset" } @@ -221,7 +221,7 @@ fpe_mask_body() } atf_test_case fpe_handle_mask -fpe_handle_mask() +fpe_handle_mask_head() { atf_set "descr" "Test handled and masked SIGFPE traps get reset" } @@ -233,7 +233,7 @@ fpe_handle_mask_body() } atf_test_case fpe_handle_recurse -fpe_handle_recurse() +fpe_handle_recurse_head() { atf_set "descr" "Test that receiving SIGFPE in the handler resets" } @@ -246,7 +246,7 @@ fpe_handle_recurse_body() } atf_test_case fpe_ignore -fpe_ignore() +fpe_ignore_head() { atf_set "descr" "Test ignored trap with right exit code" } @@ -261,7 +261,7 @@ fpe_ignore_body() # SIGBUS atf_test_case bus_simple -bus_simple() +bus_simple_head() { atf_set "descr" "Test unhandled SIGBUS with the right exit code" } @@ -272,7 +272,7 @@ bus_simple_body() } atf_test_case bus_handle -bus_handle() +bus_handle_head() { atf_set "descr" "Test handled SIGBUS traps call the signal handler" } @@ -283,7 +283,7 @@ bus_handle_body() } atf_test_case bus_mask -bus_mask() +bus_mask_head() { atf_set "descr" "Test that masking the trapped SIGBUS signal get reset" } @@ -294,7 +294,7 @@ bus_mask_body() } atf_test_case bus_handle_mask -bus_handle_mask() +bus_handle_mask_head() { atf_set "descr" "Test handled and masked SIGBUS
CVS commit: src/tests/kernel
Module Name:src Committed By: gutteridge Date: Fri May 5 01:27:18 UTC 2023 Modified Files: src/tests/kernel: t_trapsignal.sh Log Message: t_trapsignal.sh: fix head() function definitions of test cases To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/kernel/t_trapsignal.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: gutteridge Date: Thu May 4 00:02:10 UTC 2023 Modified Files: src/tests/kernel: t_fexecve.sh Log Message: t_fexecve.sh: fix head() function definitions of test cases To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_fexecve.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_fexecve.sh diff -u src/tests/kernel/t_fexecve.sh:1.1 src/tests/kernel/t_fexecve.sh:1.2 --- src/tests/kernel/t_fexecve.sh:1.1 Sun Sep 15 16:53:58 2019 +++ src/tests/kernel/t_fexecve.sh Thu May 4 00:02:10 2023 @@ -1,4 +1,4 @@ -# $NetBSD: t_fexecve.sh,v 1.1 2019/09/15 16:53:58 christos Exp $ +# $NetBSD: t_fexecve.sh,v 1.2 2023/05/04 00:02:10 gutteridge Exp $ # # Copyright (c) 2019 The NetBSD Foundation, Inc. # All rights reserved. @@ -31,7 +31,7 @@ HELPER=$(atf_get_srcdir)/h_fexecve atf_test_case fexecve_elf -fexecve_elf() +fexecve_elf_head() { atf_set "descr" "Test fexecve with ELF executables" } @@ -50,7 +50,7 @@ EOF } atf_test_case fexecve_script -fexecve_script() +fexecve_script_head() { atf_set "descr" "Test fexecve with a shell script" }
CVS commit: src/tests/kernel
Module Name:src Committed By: gutteridge Date: Thu May 4 00:02:10 UTC 2023 Modified Files: src/tests/kernel: t_fexecve.sh Log Message: t_fexecve.sh: fix head() function definitions of test cases To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_fexecve.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: gutteridge Date: Sun Apr 23 00:46:46 UTC 2023 Modified Files: src/tests/kernel: t_open_pr_57260.c Log Message: t_open_pr_57260.c: KNF a block (spaces to tabs) To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_open_pr_57260.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_open_pr_57260.c diff -u src/tests/kernel/t_open_pr_57260.c:1.1 src/tests/kernel/t_open_pr_57260.c:1.2 --- src/tests/kernel/t_open_pr_57260.c:1.1 Fri Apr 21 21:50:05 2023 +++ src/tests/kernel/t_open_pr_57260.c Sun Apr 23 00:46:46 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: t_open_pr_57260.c,v 1.1 2023/04/21 21:50:05 gutteridge Exp $ */ +/* $NetBSD: t_open_pr_57260.c,v 1.2 2023/04/23 00:46:46 gutteridge Exp $ */ /*- * Copyright (c) 2023 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: t_open_pr_57260.c,v 1.1 2023/04/21 21:50:05 gutteridge Exp $"); +__RCSID("$NetBSD: t_open_pr_57260.c,v 1.2 2023/04/23 00:46:46 gutteridge Exp $"); #include @@ -49,12 +49,12 @@ static void on_alarm(int sig) { -if (!alarmed) { -alarmed = 1; -alarm(1); -} else { -longjmp(env, 1); -} + if (!alarmed) { + alarmed = 1; + alarm(1); + } else { + longjmp(env, 1); + } } ATF_TC(openrestartsignal);
CVS commit: src/tests/kernel
Module Name:src Committed By: gutteridge Date: Sun Apr 23 00:46:46 UTC 2023 Modified Files: src/tests/kernel: t_open_pr_57260.c Log Message: t_open_pr_57260.c: KNF a block (spaces to tabs) To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_open_pr_57260.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: gutteridge Date: Mon Apr 3 21:35:59 UTC 2023 Modified Files: src/tests/kernel: t_magic_symlinks.sh Log Message: t_magic_symlinks.sh: fix line continuation in realpath head() This wasn't noticed before because the name of the head() itself was wrong, and was being ignored. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/t_magic_symlinks.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_magic_symlinks.sh diff -u src/tests/kernel/t_magic_symlinks.sh:1.3 src/tests/kernel/t_magic_symlinks.sh:1.4 --- src/tests/kernel/t_magic_symlinks.sh:1.3 Mon Apr 3 20:08:38 2023 +++ src/tests/kernel/t_magic_symlinks.sh Mon Apr 3 21:35:59 2023 @@ -1,4 +1,4 @@ -# $NetBSD: t_magic_symlinks.sh,v 1.3 2023/04/03 20:08:38 gutteridge Exp $ +# $NetBSD: t_magic_symlinks.sh,v 1.4 2023/04/03 21:35:59 gutteridge Exp $ # # Copyright (c) 2020 The NetBSD Foundation, Inc. # All rights reserved. @@ -221,7 +221,7 @@ gid_cleanup() { atf_test_case realpath cleanup realpath_head() { atf_set "require.user" "root" - atf_set "descr" "Check that realpath(1) agrees with the " + atf_set "descr" "Check that realpath(1) agrees with the " \ "kernel on magic symlink(7)'s (PR lib/55361)" }
CVS commit: src/tests/kernel
Module Name:src Committed By: gutteridge Date: Mon Apr 3 21:35:59 UTC 2023 Modified Files: src/tests/kernel: t_magic_symlinks.sh Log Message: t_magic_symlinks.sh: fix line continuation in realpath head() This wasn't noticed before because the name of the head() itself was wrong, and was being ignored. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/t_magic_symlinks.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: gutteridge Date: Mon Apr 3 20:08:38 UTC 2023 Modified Files: src/tests/kernel: t_magic_symlinks.sh Log Message: t_magic_symlinks.sh: fix naming of head() of realpath test case Addresses part of PR kern/57319 from Jim Spath. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/t_magic_symlinks.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: gutteridge Date: Mon Apr 3 20:08:38 UTC 2023 Modified Files: src/tests/kernel: t_magic_symlinks.sh Log Message: t_magic_symlinks.sh: fix naming of head() of realpath test case Addresses part of PR kern/57319 from Jim Spath. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/t_magic_symlinks.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_magic_symlinks.sh diff -u src/tests/kernel/t_magic_symlinks.sh:1.2 src/tests/kernel/t_magic_symlinks.sh:1.3 --- src/tests/kernel/t_magic_symlinks.sh:1.2 Thu Dec 9 06:38:23 2021 +++ src/tests/kernel/t_magic_symlinks.sh Mon Apr 3 20:08:38 2023 @@ -1,4 +1,4 @@ -# $NetBSD: t_magic_symlinks.sh,v 1.2 2021/12/09 06:38:23 rillig Exp $ +# $NetBSD: t_magic_symlinks.sh,v 1.3 2023/04/03 20:08:38 gutteridge Exp $ # # Copyright (c) 2020 The NetBSD Foundation, Inc. # All rights reserved. @@ -219,7 +219,7 @@ gid_cleanup() { # realpath(1) # atf_test_case realpath cleanup -nointerpreter_head() { +realpath_head() { atf_set "require.user" "root" atf_set "descr" "Check that realpath(1) agrees with the " "kernel on magic symlink(7)'s (PR lib/55361)"
CVS commit: src/tests/kernel
Module Name:src Committed By: christos Date: Sat May 14 14:02:03 UTC 2022 Modified Files: src/tests/kernel: t_sysv.c Log Message: PR/56831: Eric van Gyzen: race condition in tests/kernel/t_sysv.c https://cgit.freebsd.org/src/commit/?id=20917cac7bcf216225a7b66f7b3a56f3764c5acc To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/kernel/t_sysv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_sysv.c diff -u src/tests/kernel/t_sysv.c:1.5 src/tests/kernel/t_sysv.c:1.6 --- src/tests/kernel/t_sysv.c:1.5 Fri Feb 2 21:57:15 2018 +++ src/tests/kernel/t_sysv.c Sat May 14 10:02:03 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: t_sysv.c,v 1.5 2018/02/03 02:57:15 pgoyette Exp $ */ +/* $NetBSD: t_sysv.c,v 1.6 2022/05/14 14:02:03 christos Exp $ */ /*- * Copyright (c) 1999, 2007 The NetBSD Foundation, Inc. @@ -53,11 +53,9 @@ #include #include -volatile int did_sigsys, did_sigchild; -volatile int child_status, child_count; +volatile int did_sigsys; void sigsys_handler(int); -void sigchld_handler(int); key_t get_ftok(int); @@ -120,16 +118,14 @@ write_int(const char *path, const int va static int read_int(const char *path) { - int input; + int input, value; input = open(path, O_RDONLY); if (input == -1) return -1; - else { - int value; - read(input, , sizeof(value)); - return value; - } + + read(input, , sizeof(value)); + return value; } @@ -140,23 +136,6 @@ sigsys_handler(int signo) did_sigsys = 1; } -void -sigchld_handler(int signo) -{ - int c_status; - - did_sigchild = 1; - /* - * Reap the child and return its status - */ - if (wait(_status) == -1) - child_status = -errno; - else - child_status = c_status; - - child_count--; -} - key_t get_ftok(int id) { int fd; @@ -179,8 +158,9 @@ key_t get_ftok(int id) rmdir(tmpdir); atf_tc_fail("open() of temp file failed: %d", errno); return (key_t)-1; - } else - close(fd); + } + + close(fd); key = ftok(token_key, id); ATF_REQUIRE_MSG(key != (key_t)-1, "ftok() failed"); @@ -204,10 +184,10 @@ ATF_TC_BODY(msg, tc) struct sigaction sa; struct msqid_ds m_ds; struct testmsg m; - sigset_t sigmask; int sender_msqid; int loop; int c_status; + pid_t wait_result; /* * Install a SIGSYS handler so that we can exit gracefully if @@ -220,18 +200,6 @@ ATF_TC_BODY(msg, tc) ATF_REQUIRE_MSG(sigaction(SIGSYS, , NULL) != -1, "sigaction SIGSYS: %d", errno); - /* - * Install a SIGCHLD handler to deal with all possible exit - * conditions of the receiver. - */ - did_sigchild = 0; - child_count = 0; - sa.sa_handler = sigchld_handler; - sigemptyset(_mask); - sa.sa_flags = 0; - ATF_REQUIRE_MSG(sigaction(SIGCHLD, , NULL) != -1, - "sigaction SIGCHLD: %d", errno); - msgkey = get_ftok(4160); ATF_REQUIRE_MSG(msgkey != (key_t)-1, "get_ftok failed"); @@ -264,13 +232,14 @@ ATF_TC_BODY(msg, tc) print_msqid_ds(_ds, 0600); + fflush(stdout); + switch ((child_pid = fork())) { case -1: atf_tc_fail("fork: %d", errno); return; case 0: - child_count++; receiver(); break; @@ -288,7 +257,7 @@ ATF_TC_BODY(msg, tc) 0) != -1, "sender: msgsnd 1: %d", errno); ATF_REQUIRE_MSG(msgrcv(sender_msqid, , MESSAGE_TEXT_LEN, - MTYPE_1_ACK, 0) == MESSAGE_TEXT_LEN, + MTYPE_1_ACK, 0) == MESSAGE_TEXT_LEN, "sender: msgrcv 1 ack: %d", errno); print_msqid_ds(_ds, 0600); @@ -298,40 +267,29 @@ ATF_TC_BODY(msg, tc) */ m.mtype = MTYPE_2; strcpy(m.mtext, m2_str); - ATF_REQUIRE_MSG(msgsnd(sender_msqid, , MESSAGE_TEXT_LEN, 0) != -1, - "sender: msgsnd 2: %d", errno); + ATF_REQUIRE_MSG(msgsnd(sender_msqid, , MESSAGE_TEXT_LEN, 0) + != -1, "sender: msgsnd 2: %d", errno); ATF_REQUIRE_MSG(msgrcv(sender_msqid, , MESSAGE_TEXT_LEN, - MTYPE_2_ACK, 0) == MESSAGE_TEXT_LEN, + MTYPE_2_ACK, 0) == MESSAGE_TEXT_LEN, "sender: msgrcv 2 ack: %d", errno); } /* * Wait for child to finish */ - sigemptyset(); - (void) sigsuspend(); + wait_result = wait(_status); + ATF_REQUIRE_EQ_MSG(wait_result, child_pid, "wait returned %d (%s)", + wait_result, wait_result == -1 ? strerror(errno) : ""); + ATF_REQUIRE_MSG(WIFEXITED(c_status), "child abnormal exit: %d (sig %d)", + c_status, WTERMSIG(c_status)); + ATF_REQUIRE_EQ_MSG(WEXITSTATUS(c_status), 0, "child status: %d", + WEXITSTATUS(c_status)); - /* - * ...and any other signal is an unexpected error. - */ - if (did_sigchild) { - c_status = child_status; - if (c_status < 0) - atf_tc_fail("waitpid: %d", -c_status); - else if (WIFEXITED(c_status) == 0) - atf_tc_fail("child abnormal exit: %d", c_status); - else if (WEXITSTATUS(c_status) != 0) - atf_tc_fail("c status: %d", WEXITSTATUS(c_status)); - else { - ATF_REQUIRE_MSG(msgctl(sender_msqid, IPC_STAT, _ds) - != -1, "msgctl IPC_STAT: %d", errno); + ATF_REQUIRE_MSG(msgctl(sender_msqid,
CVS commit: src/tests/kernel
Module Name:src Committed By: christos Date: Sat May 14 14:02:03 UTC 2022 Modified Files: src/tests/kernel: t_sysv.c Log Message: PR/56831: Eric van Gyzen: race condition in tests/kernel/t_sysv.c https://cgit.freebsd.org/src/commit/?id=20917cac7bcf216225a7b66f7b3a56f3764c5acc To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/kernel/t_sysv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: rillig Date: Thu Dec 9 06:38:23 UTC 2021 Modified Files: src/tests/kernel: t_magic_symlinks.sh Log Message: tests/t_magic_symlinks: remove duplicate word in test description To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_magic_symlinks.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_magic_symlinks.sh diff -u src/tests/kernel/t_magic_symlinks.sh:1.1 src/tests/kernel/t_magic_symlinks.sh:1.2 --- src/tests/kernel/t_magic_symlinks.sh:1.1 Wed Jul 1 13:49:26 2020 +++ src/tests/kernel/t_magic_symlinks.sh Thu Dec 9 06:38:23 2021 @@ -1,4 +1,4 @@ -# $NetBSD: t_magic_symlinks.sh,v 1.1 2020/07/01 13:49:26 jruoho Exp $ +# $NetBSD: t_magic_symlinks.sh,v 1.2 2021/12/09 06:38:23 rillig Exp $ # # Copyright (c) 2020 The NetBSD Foundation, Inc. # All rights reserved. @@ -222,7 +222,7 @@ atf_test_case realpath cleanup nointerpreter_head() { atf_set "require.user" "root" atf_set "descr" "Check that realpath(1) agrees with the " - "the kernel on magic symlink(7)'s (PR lib/55361)" + "kernel on magic symlink(7)'s (PR lib/55361)" } realpath_body() {
CVS commit: src/tests/kernel
Module Name:src Committed By: rillig Date: Thu Dec 9 06:38:23 UTC 2021 Modified Files: src/tests/kernel: t_magic_symlinks.sh Log Message: tests/t_magic_symlinks: remove duplicate word in test description To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_magic_symlinks.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel/kqueue
Module Name:src Committed By: hannken Date: Sun Nov 21 09:35:39 UTC 2021 Modified Files: src/tests/kernel/kqueue: Makefile t_timer.c Log Message: Test kernel/kqueue/t_timer, subtests abstime, basic_timer and timer_units often fail when run on QEMU because QEMU misses clock interrupts. Always check timespec against expected "tv_sec" and use an "4 * tv_sec" upper bound when run under QEMU. Now becomes part of PR kern/43997 "Kernel timer discrepancies". To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/tests/kernel/kqueue/Makefile cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/kqueue/t_timer.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/kqueue/Makefile diff -u src/tests/kernel/kqueue/Makefile:1.9 src/tests/kernel/kqueue/Makefile:1.10 --- src/tests/kernel/kqueue/Makefile:1.9 Sat Oct 23 18:46:26 2021 +++ src/tests/kernel/kqueue/Makefile Sun Nov 21 09:35:39 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.9 2021/10/23 18:46:26 thorpej Exp $ +# $NetBSD: Makefile,v 1.10 2021/11/21 09:35:39 hannken Exp $ WARNS?=6 NOMAN= # defined @@ -24,4 +24,6 @@ TESTS_C+= t_vnode LDADD.t_scan+= -lpthread +CPPFLAGS.t_timer.c+= -I${.CURDIR}/../../lib/libc/gen + .include Index: src/tests/kernel/kqueue/t_timer.c diff -u src/tests/kernel/kqueue/t_timer.c:1.3 src/tests/kernel/kqueue/t_timer.c:1.4 --- src/tests/kernel/kqueue/t_timer.c:1.3 Fri Oct 22 13:53:20 2021 +++ src/tests/kernel/kqueue/t_timer.c Sun Nov 21 09:35:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: t_timer.c,v 1.3 2021/10/22 13:53:20 thorpej Exp $ */ +/* $NetBSD: t_timer.c,v 1.4 2021/11/21 09:35:39 hannken Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_timer.c,v 1.3 2021/10/22 13:53:20 thorpej Exp $"); +__RCSID("$NetBSD: t_timer.c,v 1.4 2021/11/21 09:35:39 hannken Exp $"); #include #include @@ -39,6 +39,36 @@ __RCSID("$NetBSD: t_timer.c,v 1.3 2021/1 #include +#include "isqemu.h" + +static bool +check_timespec(struct timespec *ts, time_t seconds) +{ + time_t upper = seconds; + bool result = true; + + /* + * If running under QEMU make sure the upper bound is large + * enough for the effect of kern/43997 + */ + if (isQEMU()) { + upper *= 4; + } + + if (ts->tv_sec < seconds - 1 || + (ts->tv_sec == seconds - 1 && ts->tv_nsec < 5)) + result = false; + else if (ts->tv_sec > upper || + (ts->tv_sec == upper && ts->tv_nsec >= 5)) + result = false; + + printf("time %" PRId64 ".%09ld %sin [ %" PRId64 ".5, %" PRId64 ".5 )\n", + ts->tv_sec, ts->tv_nsec, (result ? "" : "not "), + seconds - 1, upper); + + return result; +} + ATF_TC(basic_timer); ATF_TC_HEAD(basic_timer, tc) { @@ -83,13 +113,8 @@ ATF_TC_BODY(basic_timer, tc) ATF_REQUIRE(clock_gettime(CLOCK_MONOTONIC, ) == 0); timespecsub(, , ); -ATF_REQUIRE(ts.tv_sec == - (TIME1_TOTAL_SEC - 1) || -ts.tv_sec == TIME1_TOTAL_SEC); -if (ts.tv_sec == TIME1_TOTAL_SEC - 1) { - ATF_REQUIRE(ts.tv_nsec >= - 9); -} +ATF_REQUIRE(check_timespec(, +TIME1_TOTAL_SEC)); EV_SET([0], 1, EVFILT_TIMER, EV_DELETE, 0, 0, NULL); ATF_REQUIRE(kevent(kq, event, 1, NULL, 0, @@ -106,12 +131,7 @@ ATF_TC_BODY(basic_timer, tc) ATF_REQUIRE(clock_gettime(CLOCK_MONOTONIC, ) == 0); timespecsub(, , ); - ATF_REQUIRE(ts.tv_sec == -(TIME2_TOTAL_SEC - 1) || - ts.tv_sec == TIME2_TOTAL_SEC); - if (ts.tv_sec == TIME2_TOTAL_SEC - 1) { -ATF_REQUIRE(ts.tv_nsec >= 9); - } + ATF_REQUIRE(check_timespec(, TIME2_TOTAL_SEC)); EV_SET([0], 2, EVFILT_TIMER, EV_DELETE, 0, 0, NULL); ATF_REQUIRE_ERRNO(ENOENT, @@ -130,14 +150,7 @@ ATF_TC_BODY(basic_timer, tc) ATF_REQUIRE(kevent(kq, NULL, 0, event, 1, ) == 0); ATF_REQUIRE(clock_gettime(CLOCK_MONOTONIC, ) == 0); timespecsub(, , ); - ATF_REQUIRE(ts.tv_sec == (TIME2_TOTAL_SEC - 1) || - ts.tv_sec == TIME2_TOTAL_SEC || - ts.tv_sec == (TIME2_TOTAL_SEC + 1)); - if (ts.tv_sec == TIME2_TOTAL_SEC - 1) { - ATF_REQUIRE(ts.tv_nsec >= 9); - } else if (ts.tv_sec == TIME2_TOTAL_SEC + 1) { - ATF_REQUIRE(ts.tv_nsec < 5); - } + ATF_REQUIRE(check_timespec(, TIME2_TOTAL_SEC)); } ATF_TC(count_expirations); @@ -272,9 +285,6 @@ ATF_TC_BODY(abstime, tc) ATF_REQUIRE(ots.tv_sec < INTPTR_MAX - TIME1_TOTAL_SEC); seconds = ots.tv_sec + TIME1_TOTAL_SEC; - if (ots.tv_nsec >= 5) { - seconds++; - } EV_SET([0], 1, EVFILT_TIMER, EV_ADD, NOTE_ABSTIME | NOTE_SECONDS, seconds, NULL); @@ -287,10 +297,7 @@ ATF_TC_BODY(abstime, tc) * We're not going for precision here; just verify that it was * delivered anywhere between 4.5-6.whatever seconds later. */ - ATF_REQUIRE(ts.tv_sec >= 4 && ts.tv_sec <= 6); - if (ts.tv_sec == 4) { - ATF_REQUIRE(ts.tv_nsec >= 5); - } +
CVS commit: src/tests/kernel/kqueue
Module Name:src Committed By: hannken Date: Sun Nov 21 09:35:39 UTC 2021 Modified Files: src/tests/kernel/kqueue: Makefile t_timer.c Log Message: Test kernel/kqueue/t_timer, subtests abstime, basic_timer and timer_units often fail when run on QEMU because QEMU misses clock interrupts. Always check timespec against expected "tv_sec" and use an "4 * tv_sec" upper bound when run under QEMU. Now becomes part of PR kern/43997 "Kernel timer discrepancies". To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/tests/kernel/kqueue/Makefile cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/kqueue/t_timer.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel/kqueue
Module Name:src Committed By: thorpej Date: Fri Oct 22 13:53:20 UTC 2021 Modified Files: src/tests/kernel/kqueue: t_timer.c Log Message: In the "modify" test case, immediately after modifying the timer, validate that its associated knote in the kernel has actually been deactivated. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/kqueue/t_timer.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel/kqueue
Module Name:src Committed By: thorpej Date: Fri Oct 22 13:53:20 UTC 2021 Modified Files: src/tests/kernel/kqueue: t_timer.c Log Message: In the "modify" test case, immediately after modifying the timer, validate that its associated knote in the kernel has actually been deactivated. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/kqueue/t_timer.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/kqueue/t_timer.c diff -u src/tests/kernel/kqueue/t_timer.c:1.2 src/tests/kernel/kqueue/t_timer.c:1.3 --- src/tests/kernel/kqueue/t_timer.c:1.2 Fri Oct 22 04:49:24 2021 +++ src/tests/kernel/kqueue/t_timer.c Fri Oct 22 13:53:20 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: t_timer.c,v 1.2 2021/10/22 04:49:24 thorpej Exp $ */ +/* $NetBSD: t_timer.c,v 1.3 2021/10/22 13:53:20 thorpej Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_timer.c,v 1.2 2021/10/22 04:49:24 thorpej Exp $"); +__RCSID("$NetBSD: t_timer.c,v 1.3 2021/10/22 13:53:20 thorpej Exp $"); #include #include @@ -208,6 +208,12 @@ ATF_TC_BODY(modify, tc) EV_SET([0], 1, EVFILT_TIMER, EV_ADD, 0, 4000, NULL); ATF_REQUIRE(kevent(kq, event, 1, NULL, 0, NULL) == 0); + /* + * Before we sleep, verify that the knote for this timer is + * no longer activated. + */ + ATF_REQUIRE(kevent(kq, NULL, 0, event, 1, ) == 0); + sleepts.tv_sec = 5; sleepts.tv_nsec = 0; ATF_REQUIRE(nanosleep(, NULL) == 0);
CVS commit: src/tests/kernel/kqueue
Module Name:src Committed By: thorpej Date: Wed Oct 20 14:33:14 UTC 2021 Modified Files: src/tests/kernel/kqueue: t_vnode.c Log Message: Add a test case for PR kern/56460. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/kqueue/t_vnode.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/kqueue/t_vnode.c diff -u src/tests/kernel/kqueue/t_vnode.c:1.2 src/tests/kernel/kqueue/t_vnode.c:1.3 --- src/tests/kernel/kqueue/t_vnode.c:1.2 Wed Oct 20 03:08:19 2021 +++ src/tests/kernel/kqueue/t_vnode.c Wed Oct 20 14:33:14 2021 @@ -671,6 +671,53 @@ ATF_TC_CLEANUP(interest, tc) (void)unlink(testfile); } +ATF_TC_WITH_CLEANUP(rename_over_self_hardlink); +ATF_TC_HEAD(rename_over_self_hardlink, tc) +{ + atf_tc_set_md_var(tc, "descr", "This test case tests " + "renaming a file over a hard-link to itself"); +} +ATF_TC_BODY(rename_over_self_hardlink, tc) +{ + struct kevent event[2], *dir_ev, *file_ev; + int dir_fd, file_fd; + + ATF_REQUIRE((kq = kqueue()) != -1); + + ATF_REQUIRE((mkdir(dir_target, 0700)) == 0); + ATF_REQUIRE((dir_fd = open(dir_target, O_RDONLY)) != -1); + + ATF_REQUIRE((file_fd = open(file_inside1, O_RDONLY | O_CREAT, + 0600)) != -1); + ATF_REQUIRE(link(file_inside1, file_inside2) == 0); + + EV_SET([0], dir_fd, EVFILT_VNODE, EV_ADD, + NOTE_WRITE | NOTE_EXTEND | NOTE_LINK, 0, NULL); + EV_SET([1], file_fd, EVFILT_VNODE, EV_ADD, + NOTE_LINK | NOTE_DELETE, 0, NULL); + ATF_REQUIRE(kevent(kq, event, 2, NULL, 0, NULL) == 0); + + ATF_REQUIRE(rename(file_inside1, file_inside2) == 0); + + ATF_REQUIRE(kevent(kq, NULL, 0, event, 2, ) == 2); + ATF_REQUIRE(event[0].ident == (uintptr_t)dir_fd || + event[0].ident == (uintptr_t)file_fd); + ATF_REQUIRE(event[1].ident == (uintptr_t)dir_fd || + event[1].ident == (uintptr_t)file_fd); + if (event[0].ident == (uintptr_t)dir_fd) { + dir_ev = [0]; + file_ev = [1]; + } else { + dir_ev = [1]; + file_ev = [0]; + } + ATF_REQUIRE(dir_ev->fflags == NOTE_WRITE); + ATF_REQUIRE(file_ev->fflags == NOTE_LINK); +} +ATF_TC_CLEANUP(rename_over_self_hardlink, tc) +{ + cleanup(); +} ATF_TP_ADD_TCS(tp) { @@ -699,6 +746,8 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, dir_note_write_mv_file_out); ATF_TP_ADD_TC(tp, dir_note_write_mv_file_within); + ATF_TP_ADD_TC(tp, rename_over_self_hardlink); + ATF_TP_ADD_TC(tp, open_write_read_close); ATF_TP_ADD_TC(tp, interest);
CVS commit: src/tests/kernel/kqueue
Module Name:src Committed By: thorpej Date: Wed Oct 20 14:33:14 UTC 2021 Modified Files: src/tests/kernel/kqueue: t_vnode.c Log Message: Add a test case for PR kern/56460. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/kqueue/t_vnode.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel/kqueue
Module Name:src Committed By: wiz Date: Sun Oct 10 19:17:32 UTC 2021 Modified Files: src/tests/kernel/kqueue: t_scan.c Log Message: Fix typo in comment. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/kqueue/t_scan.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/kqueue/t_scan.c diff -u src/tests/kernel/kqueue/t_scan.c:1.1 src/tests/kernel/kqueue/t_scan.c:1.2 --- src/tests/kernel/kqueue/t_scan.c:1.1 Sun Oct 10 17:47:39 2021 +++ src/tests/kernel/kqueue/t_scan.c Sun Oct 10 19:17:31 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: t_scan.c,v 1.1 2021/10/10 17:47:39 thorpej Exp $ */ +/* $NetBSD: t_scan.c,v 1.2 2021/10/10 19:17:31 wiz Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_scan.c,v 1.1 2021/10/10 17:47:39 thorpej Exp $"); +__RCSID("$NetBSD: t_scan.c,v 1.2 2021/10/10 19:17:31 wiz Exp $"); #include #include @@ -44,7 +44,7 @@ __RCSID("$NetBSD: t_scan.c,v 1.1 2021/10 /* * Each kevent thread will make this many kevent() calls, and if it * achieves this mark, we assume the race condition has not occurred - * the delcare the test passes. + * the declare the test passes. */ #define NKEVENT_CALLS 1
CVS commit: src/tests/kernel/kqueue
Module Name:src Committed By: wiz Date: Sun Oct 10 19:17:32 UTC 2021 Modified Files: src/tests/kernel/kqueue: t_scan.c Log Message: Fix typo in comment. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/kqueue/t_scan.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel/kqueue
Module Name:src Committed By: thorpej Date: Sun Oct 10 18:11:31 UTC 2021 Modified Files: src/tests/kernel/kqueue: t_sig.c Log Message: The knotes for EVFILT_SIGNAL and EVFILT_PROC are maintained on a single per-process list, and kern_event.c,v 1.129 has several KASSERT()s in various code paths that process this list related to the mixing of these two knote types. This new unit test is designed specifically to exercise those KASSERT()s and thus validate their assumptions. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/kqueue/t_sig.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/kqueue/t_sig.c diff -u src/tests/kernel/kqueue/t_sig.c:1.3 src/tests/kernel/kqueue/t_sig.c:1.4 --- src/tests/kernel/kqueue/t_sig.c:1.3 Fri Jan 13 21:30:41 2017 +++ src/tests/kernel/kqueue/t_sig.c Sun Oct 10 18:11:31 2021 @@ -1,7 +1,7 @@ -/* $NetBSD: t_sig.c,v 1.3 2017/01/13 21:30:41 christos Exp $ */ +/* $NetBSD: t_sig.c,v 1.4 2021/10/10 18:11:31 thorpej Exp $ */ /*- - * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. + * Copyright (c) 2002, 2008, 2021 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_sig.c,v 1.3 2017/01/13 21:30:41 christos Exp $"); +__RCSID("$NetBSD: t_sig.c,v 1.4 2021/10/10 18:11:31 thorpej Exp $"); #include #include @@ -125,9 +125,87 @@ ATF_TC_BODY(sig, tc) (void)printf("sig: finished successfully\n"); } +/* + * This test case exercises code paths in the kernel that KASSERT() + * some assumptions about EVFILT_SIGNAL and EVFILT_PROC implementation + * details. + */ +ATF_TC(sig_and_proc); +ATF_TC_HEAD(sig_and_proc, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Validates implementation detail assumptions about " + "EVFILT_SIGNAL and EVFILT_PROC"); +} +ATF_TC_BODY(sig_and_proc, tc) +{ + struct kevent events[3]; + pid_t pid; + int kq; + + pid = fork(); + ATF_REQUIRE(pid != -1); + + if (pid == 0) { + /* + * Child: create a kqueue and attach signal knotes + * to curproc->p_klist. + */ + kq = kqueue(); + ATF_REQUIRE(kq >= 0); + + ATF_REQUIRE(signal(SIGUSR1, SIG_IGN) != SIG_ERR); + ATF_REQUIRE(signal(SIGUSR2, SIG_IGN) != SIG_ERR); + + EV_SET([0], SIGUSR1, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL); + EV_SET([1], SIGUSR2, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL); + + ATF_REQUIRE(kevent(kq, events, 2, [2], 1, NULL) == 1); + ATF_REQUIRE(events[2].filter == EVFILT_SIGNAL); + ATF_REQUIRE(events[2].ident == SIGUSR1); + + /* + * When we exit here, the kernel will close all of + * its file descriptors (including our kq), which + * will in turn remove the signal notes from + * curproc->p_klist. + * + * Then, later on, the kernel will post a NOTE_EXIT + * on our parent's kqueue using the proc note that + * our parent attached to (our) curproc->p_klist. + * That code path KASSERT()s that the signal knotes + * have already been removed. + */ + _exit(0); + } + + /* + * Parent: create a kqueue and attach a proc note to + * child->p_klist. + */ + kq = kqueue(); + ATF_REQUIRE(kq >= 0); + + EV_SET([0], pid, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL); + + ATF_REQUIRE(kevent(kq, events, 1, NULL, 0, NULL) == 0); + + /* Ensure we never see stale data. */ + memset(events, 0, sizeof(events)); + + /* Signal child to exit. */ + ATF_REQUIRE(kill(pid, SIGUSR1) == 0); + + ATF_REQUIRE(kevent(kq, NULL, 0, events, 1, NULL) == 1); + ATF_REQUIRE(events[0].filter == EVFILT_PROC); + ATF_REQUIRE(events[0].ident == (uintptr_t)pid); + ATF_REQUIRE(events[0].fflags = NOTE_EXIT); +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, sig); + ATF_TP_ADD_TC(tp, sig_and_proc); return atf_no_error(); }
CVS commit: src/tests/kernel/kqueue
Module Name:src Committed By: thorpej Date: Sun Oct 10 18:11:31 UTC 2021 Modified Files: src/tests/kernel/kqueue: t_sig.c Log Message: The knotes for EVFILT_SIGNAL and EVFILT_PROC are maintained on a single per-process list, and kern_event.c,v 1.129 has several KASSERT()s in various code paths that process this list related to the mixing of these two knote types. This new unit test is designed specifically to exercise those KASSERT()s and thus validate their assumptions. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/kqueue/t_sig.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel/kqueue/read
Module Name:src Committed By: thorpej Date: Sat Oct 2 18:21:05 UTC 2021 Modified Files: src/tests/kernel/kqueue/read: t_fifo.c Log Message: New EVFILT_READ test case for FIFOs; validates readability threshold and EV_EOF behavior. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/kernel/kqueue/read/t_fifo.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel/kqueue/read
Module Name:src Committed By: thorpej Date: Sat Oct 2 18:21:05 UTC 2021 Modified Files: src/tests/kernel/kqueue/read: t_fifo.c Log Message: New EVFILT_READ test case for FIFOs; validates readability threshold and EV_EOF behavior. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/kernel/kqueue/read/t_fifo.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/kqueue/read/t_fifo.c diff -u src/tests/kernel/kqueue/read/t_fifo.c:1.4 src/tests/kernel/kqueue/read/t_fifo.c:1.5 --- src/tests/kernel/kqueue/read/t_fifo.c:1.4 Fri Jan 13 21:30:41 2017 +++ src/tests/kernel/kqueue/read/t_fifo.c Sat Oct 2 18:21:05 2021 @@ -1,11 +1,11 @@ -/* $NetBSD: t_fifo.c,v 1.4 2017/01/13 21:30:41 christos Exp $ */ +/* $NetBSD: t_fifo.c,v 1.5 2021/10/02 18:21:05 thorpej Exp $ */ /*- - * Copyright (c) 2008 The NetBSD Foundation, Inc. + * Copyright (c) 2021 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Luke Mewburn and Jaromir Dolecek. + * by Jason R. Thorpe. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,13 +30,14 @@ */ #include -__COPYRIGHT("@(#) Copyright (c) 2008\ +__COPYRIGHT("@(#) Copyright (c) 2021\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_fifo.c,v 1.4 2017/01/13 21:30:41 christos Exp $"); +__RCSID("$NetBSD: t_fifo.c,v 1.5 2021/10/02 18:21:05 thorpej Exp $"); #include #include +#include #include #include #include @@ -46,48 +47,94 @@ __RCSID("$NetBSD: t_fifo.c,v 1.4 2017/01 #include -#include "h_macros.h" +static const char fifo_path[] = "fifo"; -#define FIFONAME "fifo" +static void +fifo_support(void) +{ + errno = 0; + if (mkfifo(fifo_path, 0600) == 0) { + ATF_REQUIRE(unlink(fifo_path) == 0); + return; + } + + if (errno == EOPNOTSUPP) { + atf_tc_skip("the kernel does not support FIFOs"); + } else { + atf_tc_fail("mkfifo(2) failed"); + } +} -ATF_TC(fifo); +ATF_TC_WITH_CLEANUP(fifo); ATF_TC_HEAD(fifo, tc) { atf_tc_set_md_var(tc, "descr", "Checks EVFILT_READ on fifo"); } ATF_TC_BODY(fifo, tc) { - int kq, n, fd; + const struct timespec to = { 0, 0 }; struct kevent event[1]; - char buffer[128]; - - RL(mkfifo(FIFONAME, 0644)); - RL(fd = open(FIFONAME, O_RDWR, 0644)); - - RL(kq = kqueue()); - - EV_SET([0], fd, EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, 0); - RL(kevent(kq, event, 1, NULL, 0, NULL)); - - /* make sure there is something in the fifo */ - RL(write(fd, "foo", 3)); - (void)printf("fifo: wrote 'foo'\n"); - - (void)memset(event, 0, sizeof(event)); - - RL(n = kevent(kq, NULL, 0, event, 1, NULL)); - - (void)printf("kevent num %d filt %d flags: %#x, fflags: %#x, " - "data: %" PRId64 "\n", n, event[0].filter, event[0].flags, - event[0].fflags, event[0].data); - - ATF_REQUIRE_EQ(event[0].filter, EVFILT_READ); - - RL(n = read(fd, buffer, event[0].data)); - buffer[n] = '\0'; - (void)printf("fifo: read '%s'\n", buffer); + char *buf; + int rfd, wfd, kq; + long pipe_buf; + + fifo_support(); + + ATF_REQUIRE(mkfifo(fifo_path, 0600) == 0); + ATF_REQUIRE((rfd = open(fifo_path, O_RDONLY | O_NONBLOCK)) >= 0); + ATF_REQUIRE((wfd = open(fifo_path, O_WRONLY | O_NONBLOCK)) >= 0); + ATF_REQUIRE((kq = kqueue()) >= 0); + + /* Get the maximum atomic pipe write size. */ + pipe_buf = fpathconf(wfd, _PC_PIPE_BUF); + ATF_REQUIRE(pipe_buf > 1); + + buf = malloc(pipe_buf); + ATF_REQUIRE(buf != NULL); + + EV_SET([0], rfd, EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, 0); + ATF_REQUIRE(kevent(kq, event, 1, NULL, 0, NULL) == 0); + + /* We expect the FIFO to not be readable. */ + ATF_REQUIRE(kevent(kq, NULL, 0, event, 1, ) == 0); + + /* Write a single byte of data into the FIFO. */ + ATF_REQUIRE(write(wfd, buf, 1) == 1); + + /* We expect the FIFO to be readable. */ + ATF_REQUIRE(kevent(kq, NULL, 0, event, 1, ) == 1); + ATF_REQUIRE(event[0].ident == (uintptr_t)rfd); + ATF_REQUIRE(event[0].filter == EVFILT_READ); + ATF_REQUIRE((event[0].flags & EV_EOF) == 0); + + /* Read that single byte back out. */ + ATF_REQUIRE(read(rfd, buf, 1) == 1); + + /* We expect the FIFO to not be readable. */ + ATF_REQUIRE(kevent(kq, NULL, 0, event, 1, ) == 0); + + /* Close the writer. We expect to get EV_EOF. */ + (void)close(wfd); + ATF_REQUIRE(kevent(kq, NULL, 0, event, 1, ) == 1); + ATF_REQUIRE(event[0].ident == (uintptr_t)rfd); + ATF_REQUIRE(event[0].filter == EVFILT_READ); + ATF_REQUIRE((event[0].flags & EV_EOF) != 0); + + /* + * Reconect the writer. We expect EV_EOF to be cleared and + * for the FIFO to no longer be readable once again. + */ + ATF_REQUIRE((wfd = open(fifo_path, O_WRONLY | O_NONBLOCK)) >= 0); + ATF_REQUIRE(kevent(kq, NULL, 0, event, 1, ) == 0); + + (void)close(wfd); + (void)close(rfd); + (void)close(kq); +} - RL(close(fd));
CVS commit: src/tests/kernel
Module Name:src Committed By: martin Date: Fri Oct 1 18:18:32 UTC 2021 Modified Files: src/tests/kernel: Makefile Log Message: t_simplehook requires RUMP To generate a diff of this commit: cvs rdiff -u -r1.69 -r1.70 src/tests/kernel/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/Makefile diff -u src/tests/kernel/Makefile:1.69 src/tests/kernel/Makefile:1.70 --- src/tests/kernel/Makefile:1.69 Thu Sep 30 02:00:20 2021 +++ src/tests/kernel/Makefile Fri Oct 1 18:18:32 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.69 2021/09/30 02:00:20 yamaguchi Exp $ +# $NetBSD: Makefile,v 1.70 2021/10/01 18:18:32 martin Exp $ NOMAN= # defined @@ -32,7 +32,9 @@ TESTS_SH+= t_origin TESTS_SH+= t_procpath TESTS_SH+= t_fexecve TESTS_SH+= t_fpufork +.if ${MKRUMP} != "no" TESTS_SH+= t_simplehook +.endif BINDIR= ${TESTSDIR} PROGS= h_fexecve
CVS commit: src/tests/kernel
Module Name:src Committed By: martin Date: Fri Oct 1 18:18:32 UTC 2021 Modified Files: src/tests/kernel: Makefile Log Message: t_simplehook requires RUMP To generate a diff of this commit: cvs rdiff -u -r1.69 -r1.70 src/tests/kernel/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel/kqueue
Module Name:src Committed By: christos Date: Sat Oct 31 14:57:02 UTC 2020 Modified Files: src/tests/kernel/kqueue: t_ioctl.c Log Message: Avoid hard-coding names and limits so this will not break again. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/kernel/kqueue/t_ioctl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/kqueue/t_ioctl.c diff -u src/tests/kernel/kqueue/t_ioctl.c:1.4 src/tests/kernel/kqueue/t_ioctl.c:1.5 --- src/tests/kernel/kqueue/t_ioctl.c:1.4 Tue Jan 9 12:35:29 2018 +++ src/tests/kernel/kqueue/t_ioctl.c Sat Oct 31 10:57:02 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ioctl.c,v 1.4 2018/01/09 17:35:29 martin Exp $ */ +/* $NetBSD: t_ioctl.c,v 1.5 2020/10/31 14:57:02 christos Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -32,8 +32,9 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_ioctl.c,v 1.4 2018/01/09 17:35:29 martin Exp $"); +__RCSID("$NetBSD: t_ioctl.c,v 1.5 2020/10/31 14:57:02 christos Exp $"); +#define EVFILT_NAMES #include #include @@ -61,13 +62,13 @@ ATF_TC_BODY(kfilter_byfilter, tc) km.name = buf; km.len = sizeof(buf) - 1; - for (i = 0; i < 8; ++i) { + for (i = 0; i < EVFILT_SYSCOUNT; ++i) { km.filter = i; RL(ioctl(kq, KFILTER_BYFILTER, )); (void)printf(" map %d -> %s\n", km.filter, km.name); } - km.filter = 8; + km.filter = EVFILT_SYSCOUNT; ATF_REQUIRE_EQ(ioctl(kq, KFILTER_BYFILTER, ), -1); } @@ -78,28 +79,16 @@ ATF_TC_HEAD(kfilter_byname, tc) } ATF_TC_BODY(kfilter_byname, tc) { - const char *tests[] = { - "EVFILT_READ", - "EVFILT_WRITE", - "EVFILT_AIO", - "EVFILT_VNODE", - "EVFILT_PROC", - "EVFILT_SIGNAL", - "EVFILT_TIMER", - "EVFILT_FS", - NULL - }; char buf[32]; struct kfilter_mapping km; - const char **test; int kq; RL(kq = kqueue()); km.name = buf; - for (test = [0]; *test != NULL; ++test) { - (void)strlcpy(buf, *test, sizeof(buf)); + for (size_t i = 0; i < EVFILT_SYSCOUNT; i++) { + (void)strlcpy(buf, evfiltnames[i], sizeof(buf)); RL(ioctl(kq, KFILTER_BYNAME, )); (void)printf(" map %s -> %d\n", km.name, km.filter); }
CVS commit: src/tests/kernel/kqueue
Module Name:src Committed By: christos Date: Sat Oct 31 14:57:02 UTC 2020 Modified Files: src/tests/kernel/kqueue: t_ioctl.c Log Message: Avoid hard-coding names and limits so this will not break again. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/kernel/kqueue/t_ioctl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: rin Date: Wed Jun 24 07:02:57 UTC 2020 Modified Files: src/tests/kernel: t_pty.c Log Message: errno is irrelevant here. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/kernel/t_pty.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: rin Date: Wed Jun 24 07:02:57 UTC 2020 Modified Files: src/tests/kernel: t_pty.c Log Message: errno is irrelevant here. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/kernel/t_pty.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_pty.c diff -u src/tests/kernel/t_pty.c:1.4 src/tests/kernel/t_pty.c:1.5 --- src/tests/kernel/t_pty.c:1.4 Wed Jun 24 06:15:40 2020 +++ src/tests/kernel/t_pty.c Wed Jun 24 07:02:57 2020 @@ -1,4 +1,4 @@ -/* $Id: t_pty.c,v 1.4 2020/06/24 06:15:40 rin Exp $ */ +/* $Id: t_pty.c,v 1.5 2020/06/24 07:02:57 rin Exp $ */ /* * Allocates a pty(4) device, and sends the specified number of packets of the @@ -9,7 +9,7 @@ */ #include -__RCSID("$NetBSD: t_pty.c,v 1.4 2020/06/24 06:15:40 rin Exp $"); +__RCSID("$NetBSD: t_pty.c,v 1.5 2020/06/24 07:02:57 rin Exp $"); #include #include @@ -119,7 +119,7 @@ condition(int fd) if (ioctl(fd, TIOCGQSIZE, ) == -1) atf_tc_fail_errno("Couldn't get tty(4) buffer size"); if (opt != qsize) - atf_tc_fail_errno("Wrong qsize %d != %d\n", qsize, opt); + atf_tc_fail("Wrong qsize %d != %d\n", qsize, opt); } if (tcgetattr(fd, ) == -1) atf_tc_fail_errno("tcgetattr()");
CVS commit: src/tests/kernel
Module Name:src Committed By: rin Date: Wed Jun 24 06:15:40 UTC 2020 Modified Files: src/tests/kernel: t_pty.c Log Message: Fix random failures for pty_queue test. Setting queue size by TIOCSQSIZE ioctl does not guarantee that data of that size can be read by single shot of read(2). Remove assertion based on this assertion, while total amount of data read from child process is still checked appropriately. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/t_pty.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_pty.c diff -u src/tests/kernel/t_pty.c:1.3 src/tests/kernel/t_pty.c:1.4 --- src/tests/kernel/t_pty.c:1.3 Wed Jun 24 05:59:18 2020 +++ src/tests/kernel/t_pty.c Wed Jun 24 06:15:40 2020 @@ -1,4 +1,4 @@ -/* $Id: t_pty.c,v 1.3 2020/06/24 05:59:18 rin Exp $ */ +/* $Id: t_pty.c,v 1.4 2020/06/24 06:15:40 rin Exp $ */ /* * Allocates a pty(4) device, and sends the specified number of packets of the @@ -9,7 +9,7 @@ */ #include -__RCSID("$NetBSD: t_pty.c,v 1.3 2020/06/24 05:59:18 rin Exp $"); +__RCSID("$NetBSD: t_pty.c,v 1.4 2020/06/24 06:15:40 rin Exp $"); #include #include @@ -231,11 +231,6 @@ child_spawn(const char *ttydev) break; err(EXIT_FAILURE, "child: read()"); } -if (qsize && size < qsize && -(size_t)size < buffer_size) - errx(EXIT_FAILURE, "read returned %zd " - "less than the queue size %d", - size, qsize); if (verbose) (void)printf( "child: read %zd bytes from TTY\n",
CVS commit: src/tests/kernel
Module Name:src Committed By: rin Date: Wed Jun 24 06:15:40 UTC 2020 Modified Files: src/tests/kernel: t_pty.c Log Message: Fix random failures for pty_queue test. Setting queue size by TIOCSQSIZE ioctl does not guarantee that data of that size can be read by single shot of read(2). Remove assertion based on this assertion, while total amount of data read from child process is still checked appropriately. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/t_pty.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: rin Date: Wed Jun 24 05:59:18 UTC 2020 Modified Files: src/tests/kernel: t_pty.c Log Message: Turn err() into atf_tc_fail_errno() for parent process, so that atf can catch failures correctly. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/t_pty.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_pty.c diff -u src/tests/kernel/t_pty.c:1.2 src/tests/kernel/t_pty.c:1.3 --- src/tests/kernel/t_pty.c:1.2 Fri Jan 13 21:30:41 2017 +++ src/tests/kernel/t_pty.c Wed Jun 24 05:59:18 2020 @@ -1,4 +1,4 @@ -/* $Id: t_pty.c,v 1.2 2017/01/13 21:30:41 christos Exp $ */ +/* $Id: t_pty.c,v 1.3 2020/06/24 05:59:18 rin Exp $ */ /* * Allocates a pty(4) device, and sends the specified number of packets of the @@ -9,7 +9,7 @@ */ #include -__RCSID("$NetBSD: t_pty.c,v 1.2 2017/01/13 21:30:41 christos Exp $"); +__RCSID("$NetBSD: t_pty.c,v 1.3 2020/06/24 05:59:18 rin Exp $"); #include #include @@ -31,6 +31,8 @@ __RCSID("$NetBSD: t_pty.c,v 1.2 2017/01/ #include #ifdef STANDALONE +#define atf_tc_fail_errno(fmt, ...) err(EXIT_FAILURE, fmt, ## __VA_ARGS__) +#define atf_tc_fail(fmt, ...) errx(EXIT_FAILURE, fmt, ## __VA_ARGS__) static __dead void usage(const char *); static void parse_args(int, char **); #else @@ -59,7 +61,7 @@ void run(void) int status; pid_t child; if ((dbuf = calloc(1, buffer_size)) == NULL) - err(EXIT_FAILURE, "malloc(%zu)", buffer_size); + atf_tc_fail_errno("malloc(%zu)", buffer_size); if (verbose) (void)printf( @@ -84,7 +86,7 @@ void run(void) "parent: attempting to write %zu bytes to PTY\n", buffer_size); if ((size = write(pty, dbuf, buffer_size)) == -1) { - err(EXIT_FAILURE, "parent: write()"); + atf_tc_fail_errno("parent: write()"); break; } if (verbose) @@ -94,9 +96,9 @@ void run(void) if (verbose) (void)printf("parent: waiting for child to exit\n"); if (waitpid(child, , 0) == -1) - err(EXIT_FAILURE, "waitpid"); + atf_tc_fail_errno("waitpid"); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) - errx(EXIT_FAILURE, "child failed"); + atf_tc_fail("child failed"); if (verbose) (void)printf("parent: closing PTY\n"); @@ -113,19 +115,18 @@ condition(int fd) if (qsize) { int opt = qsize; if (ioctl(fd, TIOCSQSIZE, ) == -1) - err(EXIT_FAILURE, "Couldn't set tty(4) buffer size"); + atf_tc_fail_errno("Couldn't set tty(4) buffer size"); if (ioctl(fd, TIOCGQSIZE, ) == -1) - err(EXIT_FAILURE, "Couldn't get tty(4) buffer size"); + atf_tc_fail_errno("Couldn't get tty(4) buffer size"); if (opt != qsize) - errx(EXIT_FAILURE, "Wrong qsize %d != %d\n", - qsize, opt); + atf_tc_fail_errno("Wrong qsize %d != %d\n", qsize, opt); } if (tcgetattr(fd, ) == -1) - err(EXIT_FAILURE, "tcgetattr()"); + atf_tc_fail_errno("tcgetattr()"); cfmakeraw(); cfsetspeed(, B921600); if (tcsetattr(fd, TCSANOW, ) == -1) - err(EXIT_FAILURE, "tcsetattr()"); + atf_tc_fail_errno("tcsetattr()"); } static int @@ -134,17 +135,17 @@ pty_open(void) int fd; if ((fd = posix_openpt(O_RDWR)) == -1) - err(EXIT_FAILURE, "Couldn't pty(4) device"); + atf_tc_fail_errno("Couldn't pty(4) device"); condition(fd); if (grantpt(fd) == -1) - err(EXIT_FAILURE, + atf_tc_fail_errno( "Couldn't grant permissions on tty(4) device"); condition(fd); if (unlockpt(fd) == -1) - err(EXIT_FAILURE, "unlockpt()"); + atf_tc_fail_errno("unlockpt()"); return fd; } @@ -155,13 +156,13 @@ tty_open(const char *ttydev) int fd; if ((fd = open(ttydev, O_RDWR, 0)) == -1) - err(EXIT_FAILURE, "Couldn't open tty(4) device"); + atf_tc_fail_errno("Couldn't open tty(4) device"); #ifdef USE_PPP_DISCIPLINE { int opt = PPPDISC; if (ioctl(fd, TIOCSETD, ) == -1) - err(EXIT_FAILURE, + atf_tc_fail_errno( "Couldn't set tty(4) discipline to PPP"); } #endif @@ -177,9 +178,9 @@ fd_nonblock(int fd) int opt; if ((opt = fcntl(fd, F_GETFL, NULL)) == -1) - err(EXIT_FAILURE, "fcntl()"); + atf_tc_fail_errno("fcntl()"); if (fcntl(fd, F_SETFL, opt | O_NONBLOCK) == -1) - err(EXIT_FAILURE, "fcntl()"); + atf_tc_fail_errno("fcntl()"); } static pid_t @@ -191,7 +192,7 @@ child_spawn(const char *ttydev) size_t total = 0; if ((pid = fork()) == -1) - err(EXIT_FAILURE, "fork()"); + atf_tc_fail_errno("fork()"); (void)setsid(); if (pid != 0) return pid;
CVS commit: src/tests/kernel
Module Name:src Committed By: rin Date: Wed Jun 24 05:59:18 UTC 2020 Modified Files: src/tests/kernel: t_pty.c Log Message: Turn err() into atf_tc_fail_errno() for parent process, so that atf can catch failures correctly. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/t_pty.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Mon Feb 10 16:51:49 UTC 2020 Modified Files: src/tests/kernel: t_kauth_pr_47598.c Log Message: Show errno on failure. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/t_kauth_pr_47598.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Mon Feb 10 16:51:49 UTC 2020 Modified Files: src/tests/kernel: t_kauth_pr_47598.c Log Message: Show errno on failure. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/t_kauth_pr_47598.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_kauth_pr_47598.c diff -u src/tests/kernel/t_kauth_pr_47598.c:1.3 src/tests/kernel/t_kauth_pr_47598.c:1.4 --- src/tests/kernel/t_kauth_pr_47598.c:1.3 Mon Apr 28 08:34:16 2014 +++ src/tests/kernel/t_kauth_pr_47598.c Mon Feb 10 16:51:48 2020 @@ -27,7 +27,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2013\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_kauth_pr_47598.c,v 1.3 2014/04/28 08:34:16 martin Exp $"); +__RCSID("$NetBSD: t_kauth_pr_47598.c,v 1.4 2020/02/10 16:51:48 riastradh Exp $"); #include #include @@ -120,21 +120,23 @@ ATF_TC_BODY(kauth_curtain, tc) * create a socket and bind it to some arbitray free port */ s = socket(PF_INET, SOCK_STREAM|SOCK_NONBLOCK, 0); - ATF_REQUIRE(s != -1); + ATF_REQUIRE_MSG(s != -1, "socket: %d", errno); memset(, 0, sizeof(sa)); sa.sin_family = AF_INET; sa.sin_len = sizeof(sa); sa.sin_addr.s_addr = inet_addr("127.0.0.1"); - ATF_REQUIRE(bind(s, (struct sockaddr *), sizeof(sa))==0); - ATF_REQUIRE(listen(s, 16)==0); + ATF_REQUIRE_MSG(bind(s, (struct sockaddr *), sizeof(sa)) == 0, + "bind: %d", errno); + ATF_REQUIRE_MSG(listen(s, 16) == 0, "listen: %d", errno); /* * extract address and open a connection to the port */ slen = sizeof(sa); - ATF_REQUIRE(getsockname(s, (struct sockaddr *), )==0); + ATF_REQUIRE_MSG(getsockname(s, (struct sockaddr *), ) == 0, + "getsockname: %d", errno); s2 = socket(PF_INET, SOCK_STREAM|SOCK_NONBLOCK, 0); - ATF_REQUIRE(s2 != -1); + ATF_REQUIRE_MSG(s2 != -1, "socket: %d", errno); printf("port is %d\n", ntohs(sa.sin_port)); err = connect(s2, (struct sockaddr *), sizeof(sa)); ATF_REQUIRE_MSG(err == -1 && errno == EINPROGRESS,
CVS commit: src/tests/kernel
Module Name:src Committed By: christos Date: Sun Oct 20 16:02:11 UTC 2019 Modified Files: src/tests/kernel: t_fcntl.c Log Message: opening a symlink with O_NOFOLLOW is expected to fail. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_fcntl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: christos Date: Sun Oct 20 16:02:11 UTC 2019 Modified Files: src/tests/kernel: t_fcntl.c Log Message: opening a symlink with O_NOFOLLOW is expected to fail. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_fcntl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_fcntl.c diff -u src/tests/kernel/t_fcntl.c:1.1 src/tests/kernel/t_fcntl.c:1.2 --- src/tests/kernel/t_fcntl.c:1.1 Sun Sep 15 12:25:58 2019 +++ src/tests/kernel/t_fcntl.c Sun Oct 20 12:02:11 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: t_fcntl.c,v 1.1 2019/09/15 16:25:58 christos Exp $ */ +/* $NetBSD: t_fcntl.c,v 1.2 2019/10/20 16:02:11 christos Exp $ */ /*- * Copyright (c) 2019 The NetBSD Foundation, Inc. @@ -53,7 +53,7 @@ static const struct { { "/bin/sh", 0 }, { "/dev/zero", 0 }, { "/dev/null", 0 }, - { "/bin/chgrp", 0 }, + { "/sbin/chown", 0 }, { "/", ENOENT }, }; @@ -64,7 +64,7 @@ ATF_TC_BODY(getpath, tc) for (size_t i = 0; i < __arraycount(files); i++) { fd = open(files[i].name, O_RDONLY|O_NOFOLLOW); - ATF_REQUIRE(fd != -1); + ATF_REQUIRE_MSG(fd != -1, "Cannot open `%s'", files[i].name); rv = fcntl(fd, F_GETPATH, path); if (files[i].rv) { ATF_REQUIRE_MSG(errno == files[i].rv,
Re: CVS commit: src/tests/kernel
While there, it does not build for me: /usr/src/tests/kernel/h_fexecve.c: In function 'main': /usr/src/tests/kernel/h_fexecve.c:48:6: error: implicit declaration of function 'fexecve'; did you mean 'execve'? [-Werror=implicit-function-declaration] if (fexecve(fd, args, NULL) == -1) ^~~ execve cc1: all warnings being treated as errors On 15.09.2019 22:37, Kamil Rytarowski wrote: > I have got no opinion, but merging them is good. Personally I prefer > src/libc/* path as fexecve(2) is a libc public symbol. > > On 15.09.2019 20:06, Christos Zoulas wrote: >> The tests are a different. Should we keep them both, or try to merge them? >> I think that merging them is probably better. It is also the case that >> perhaps >> we need to get rid of the kernel tests directory and move them to the >> respective bin and lib directories to avoid confusion? >> >> christos >> >>> On Sep 15, 2019, at 1:02 PM, Kamil Rytarowski wrote: >>> >>> Signed PGP part >>> On 15.09.2019 18:53, Christos Zoulas wrote: Module Name: src Committed By: christos Date: Sun Sep 15 16:53:58 UTC 2019 Modified Files: src/tests/kernel: Makefile Added Files: src/tests/kernel: h_fexecve.c t_fexecve.sh Log Message: Add tests for fexecve(2) >>> >>> For the reference, there were already tests in: >>> >>> ./lib/libc/c063/t_fexecve >>> >>> >>> >> > > signature.asc Description: OpenPGP digital signature
Re: CVS commit: src/tests/kernel
I have got no opinion, but merging them is good. Personally I prefer src/libc/* path as fexecve(2) is a libc public symbol. On 15.09.2019 20:06, Christos Zoulas wrote: > The tests are a different. Should we keep them both, or try to merge them? > I think that merging them is probably better. It is also the case that perhaps > we need to get rid of the kernel tests directory and move them to the > respective bin and lib directories to avoid confusion? > > christos > >> On Sep 15, 2019, at 1:02 PM, Kamil Rytarowski wrote: >> >> Signed PGP part >> On 15.09.2019 18:53, Christos Zoulas wrote: >>> Module Name:src >>> Committed By: christos >>> Date: Sun Sep 15 16:53:58 UTC 2019 >>> >>> Modified Files: >>> src/tests/kernel: Makefile >>> Added Files: >>> src/tests/kernel: h_fexecve.c t_fexecve.sh >>> >>> Log Message: >>> Add tests for fexecve(2) >> >> For the reference, there were already tests in: >> >> ./lib/libc/c063/t_fexecve >> >> >> > signature.asc Description: OpenPGP digital signature
Re: CVS commit: src/tests/kernel
The tests are a different. Should we keep them both, or try to merge them? I think that merging them is probably better. It is also the case that perhaps we need to get rid of the kernel tests directory and move them to the respective bin and lib directories to avoid confusion? christos > On Sep 15, 2019, at 1:02 PM, Kamil Rytarowski wrote: > > Signed PGP part > On 15.09.2019 18:53, Christos Zoulas wrote: >> Module Name: src >> Committed By:christos >> Date:Sun Sep 15 16:53:58 UTC 2019 >> >> Modified Files: >> src/tests/kernel: Makefile >> Added Files: >> src/tests/kernel: h_fexecve.c t_fexecve.sh >> >> Log Message: >> Add tests for fexecve(2) > > For the reference, there were already tests in: > > ./lib/libc/c063/t_fexecve > > >
Re: CVS commit: src/tests/kernel
On 15.09.2019 18:53, Christos Zoulas wrote: > Module Name: src > Committed By: christos > Date: Sun Sep 15 16:53:58 UTC 2019 > > Modified Files: > src/tests/kernel: Makefile > Added Files: > src/tests/kernel: h_fexecve.c t_fexecve.sh > > Log Message: > Add tests for fexecve(2) For the reference, there were already tests in: ./lib/libc/c063/t_fexecve signature.asc Description: OpenPGP digital signature
CVS commit: src/tests/kernel
Module Name:src Committed By: christos Date: Sun Sep 15 16:53:58 UTC 2019 Modified Files: src/tests/kernel: Makefile Added Files: src/tests/kernel: h_fexecve.c t_fexecve.sh Log Message: Add tests for fexecve(2) To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 src/tests/kernel/Makefile cvs rdiff -u -r0 -r1.1 src/tests/kernel/h_fexecve.c \ src/tests/kernel/t_fexecve.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: christos Date: Sun Sep 15 16:53:58 UTC 2019 Modified Files: src/tests/kernel: Makefile Added Files: src/tests/kernel: h_fexecve.c t_fexecve.sh Log Message: Add tests for fexecve(2) To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 src/tests/kernel/Makefile cvs rdiff -u -r0 -r1.1 src/tests/kernel/h_fexecve.c \ src/tests/kernel/t_fexecve.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/Makefile diff -u src/tests/kernel/Makefile:1.62 src/tests/kernel/Makefile:1.63 --- src/tests/kernel/Makefile:1.62 Sun Sep 15 12:25:58 2019 +++ src/tests/kernel/Makefile Sun Sep 15 12:53:58 2019 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.62 2019/09/15 16:25:58 christos Exp $ +# $NetBSD: Makefile,v 1.63 2019/09/15 16:53:58 christos Exp $ NOMAN= # defined @@ -28,9 +28,11 @@ TESTS_SH+= t_trapsignal TESTS_SH+= t_interp TESTS_SH+= t_origin TESTS_SH+= t_procpath +TESTS_SH+= t_fexecve BINDIR= ${TESTSDIR} -PROGS= h_ps_strings1 +PROGS= h_fexecve +PROGS+= h_ps_strings1 PROGS+= h_ps_strings2 PROGS+= h_segv PROGS+= h_getprocpath Added files: Index: src/tests/kernel/h_fexecve.c diff -u /dev/null src/tests/kernel/h_fexecve.c:1.1 --- /dev/null Sun Sep 15 12:53:58 2019 +++ src/tests/kernel/h_fexecve.c Sun Sep 15 12:53:58 2019 @@ -0,0 +1,51 @@ +/* $NetBSD: h_fexecve.c,v 1.1 2019/09/15 16:53:58 christos Exp $ */ + +/*- + * Copyright (c) 2019 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include +__RCSID("$NetBSD: h_fexecve.c,v 1.1 2019/09/15 16:53:58 christos Exp $"); + +#include +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + char *args[] = { argv[1], NULL }; + int fd = open(args[0], O_RDONLY); + if (fd == -1) + err(EXIT_FAILURE, "open %s", args[0]); + if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) + err(EXIT_FAILURE, "fcntl"); + if (fexecve(fd, args, NULL) == -1) + err(EXIT_FAILURE, "fexecve"); + return EXIT_SUCCESS; +} Index: src/tests/kernel/t_fexecve.sh diff -u /dev/null src/tests/kernel/t_fexecve.sh:1.1 --- /dev/null Sun Sep 15 12:53:58 2019 +++ src/tests/kernel/t_fexecve.sh Sun Sep 15 12:53:58 2019 @@ -0,0 +1,72 @@ +# $NetBSD: t_fexecve.sh,v 1.1 2019/09/15 16:53:58 christos Exp $ +# +# Copyright (c) 2019 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Christos Zoulas. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +#notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +#notice, this list of conditions and the following disclaimer in the +#documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
CVS commit: src/tests/kernel
Module Name:src Committed By: kamil Date: Thu Aug 15 08:46:09 UTC 2019 Modified Files: src/tests/kernel: Makefile Log Message: Adapt tests/kernel/t_subr_prf for MKSANITIZER Allow to rename snprintf-like functions to avoid clashes with a sanitizer. This tests needs a fixup to remove 'undef symbol' from the test code generator. To generate a diff of this commit: cvs rdiff -u -r1.60 -r1.61 src/tests/kernel/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: kamil Date: Thu Aug 15 08:46:09 UTC 2019 Modified Files: src/tests/kernel: Makefile Log Message: Adapt tests/kernel/t_subr_prf for MKSANITIZER Allow to rename snprintf-like functions to avoid clashes with a sanitizer. This tests needs a fixup to remove 'undef symbol' from the test code generator. To generate a diff of this commit: cvs rdiff -u -r1.60 -r1.61 src/tests/kernel/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/Makefile diff -u src/tests/kernel/Makefile:1.60 src/tests/kernel/Makefile:1.61 --- src/tests/kernel/Makefile:1.60 Fri Jun 7 21:18:16 2019 +++ src/tests/kernel/Makefile Thu Aug 15 08:46:09 2019 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.60 2019/06/07 21:18:16 christos Exp $ +# $NetBSD: Makefile,v 1.61 2019/08/15 08:46:09 kamil Exp $ NOMAN= # defined @@ -66,6 +66,11 @@ CPPFLAGS.subr_extent.c= -D_EXTENT_TESTIN t_subr_prf.c: gen_t_subr_prf ${NETBSDSRCDIR}/sys/kern/subr_prf.c ${HOST_SH} ${.ALLSRC} ${.TARGET} +.if ${MKSANITIZER:Uno} == "yes" + # These symbols will be redefined by MKSANITIZER + ${TOOL_SED} -i '/undef .*printf/d' ${.TARGET} +.endif + CPPFLAGS.t_subr_prf.c= -Wno-pointer-sign # XXX platform vs kernel SHA2 .if defined(HAVE_GCC) && ${HAVE_GCC} == 7 && ${ACTIVE_CC} == "gcc" @@ -73,6 +78,14 @@ CPPFLAGS.t_subr_prf.c= -Wno-pointer-sign CPPFLAGS.t_subr_prf.c+= -Wno-error=format-truncation .endif +SANITIZER_RENAME_CLASSES+= t_subr_prf +SANITIZER_RENAME_FILES.t_subr_prf+= t_subr_prf.c +SANITIZER_RENAME_SYMBOL.t_subr_prf+= snprintf +SANITIZER_RENAME_SYMBOL.t_subr_prf+= vsnprintf +SANITIZER_RENAME_SYMBOL.t_subr_prf+= sprintf +SANITIZER_RENAME_SYMBOL.t_subr_prf+= vsnprintf +SANITIZER_RENAME_SYMBOL.t_subr_prf+= vasprintf + CLEANFILES+= t_subr_prf.c LDADD.h_segv+= -lm
CVS commit: src/tests/kernel
Module Name:src Committed By: christos Date: Fri Jun 7 21:18:16 UTC 2019 Modified Files: src/tests/kernel: Makefile Added Files: src/tests/kernel: t_origin.sh Log Message: Add a $ORIGIN test To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 src/tests/kernel/Makefile cvs rdiff -u -r0 -r1.1 src/tests/kernel/t_origin.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/Makefile diff -u src/tests/kernel/Makefile:1.59 src/tests/kernel/Makefile:1.60 --- src/tests/kernel/Makefile:1.59 Sat Jun 1 15:49:02 2019 +++ src/tests/kernel/Makefile Fri Jun 7 17:18:16 2019 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.59 2019/06/01 19:49:02 kamil Exp $ +# $NetBSD: Makefile,v 1.60 2019/06/07 21:18:16 christos Exp $ NOMAN= # defined @@ -25,6 +25,7 @@ TESTS_SH+= t_umountstress TESTS_SH+= t_ps_strings TESTS_SH+= t_trapsignal TESTS_SH+= t_interp +TESTS_SH+= t_origin TESTS_SH+= t_procpath BINDIR= ${TESTSDIR} Added files: Index: src/tests/kernel/t_origin.sh diff -u /dev/null src/tests/kernel/t_origin.sh:1.1 --- /dev/null Fri Jun 7 17:18:16 2019 +++ src/tests/kernel/t_origin.sh Fri Jun 7 17:18:16 2019 @@ -0,0 +1,122 @@ +# $NetBSD: t_origin.sh,v 1.1 2019/06/07 21:18:16 christos Exp $ +# +# Copyright (c) 2019 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Christos Zoulas. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +#notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +#notice, this list of conditions and the following disclaimer in the +#documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +atf_test_case origin_simple +origin_simple_head() { + atf_set "descr" 'test native $ORIGIN support' + atf_set "require.progs" "cc" +} + +atf_test_case origin_simple_32 +origin_simple_32_head() { + atf_set "descr" 'test $ORIGIN support in 32 bit mode' + atf_set "require.progs" "cc" +} + +make_code() { + cat > origin$1.c << _EOF +#include +#include +#include +#include + +static const char lib[] = "libfoo$1.so"; +int +main(void) +{ + void *h = dlopen(lib, RTLD_NOW); + if (h == NULL) + errx(EXIT_FAILURE, "dlopen: %s", dlerror()); + dlclose(h); + return EXIT_SUCCESS; +} +_EOF + +cat > libfoo$1.c << EOF +void foo(void); +void foo(void) +{ +} +EOF +} + +test_code() { + local m32 + if [ -z "$1" ]; then + m32= + else + m32=-m32 + fi + atf_check -s exit:0 -o empty -e empty \ + cc -fPIC $m32 -o origin$1 origin$1.c -Wl,-R'$ORIGIN' + atf_check -s exit:0 -o empty -e empty \ + cc -shared -fPIC $m32 -o libfoo$1.so libfoo$1.c + atf_check -s exit:0 -o empty -e empty ./origin$1 +} + +check32() { + # check whether this arch is 64bit + if ! cc -dM -E - < /dev/null | fgrep -q _LP64; then + atf_skip "this is not a 64 bit architecture" + return 1 + fi + if ! cc -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then + atf_skip "c++ -m32 not supported on this architecture" + return 1 + else + if fgrep -q _LP64 ./def32; then + atf_fail "c++ -m32 does not generate netbsd32 binaries" + return 1 + fi + return 0 + fi +} + +origin_simple_body() { + make_code "" + test_code "" + +} + +origin_simple_32_body() { + if ! check32; then + return + fi + make_code "32" + test_code "32" +} + + +atf_init_test_cases() +{ + + atf_add_test_case origin_simple + atf_add_test_case origin_simple_32 +}
CVS commit: src/tests/kernel
Module Name:src Committed By: christos Date: Fri Jun 7 21:18:16 UTC 2019 Modified Files: src/tests/kernel: Makefile Added Files: src/tests/kernel: t_origin.sh Log Message: Add a $ORIGIN test To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 src/tests/kernel/Makefile cvs rdiff -u -r0 -r1.1 src/tests/kernel/t_origin.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: kamil Date: Sat Jun 1 22:18:23 UTC 2019 Modified Files: src/tests/kernel: t_proccwd.c Log Message: Fix a mistake in a test for KERN_PROC_CWD Emit properly ENOENT scenario in chroot. For some reason the final patch did not hit the tree. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_proccwd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_proccwd.c diff -u src/tests/kernel/t_proccwd.c:1.1 src/tests/kernel/t_proccwd.c:1.2 --- src/tests/kernel/t_proccwd.c:1.1 Sat Jun 1 19:49:02 2019 +++ src/tests/kernel/t_proccwd.c Sat Jun 1 22:18:23 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: t_proccwd.c,v 1.1 2019/06/01 19:49:02 kamil Exp $ */ +/* $NetBSD: t_proccwd.c,v 1.2 2019/06/01 22:18:23 kamil Exp $ */ /*- * Copyright (c) 2019 The NetBSD Foundation, Inc. * All rights reserved. @@ -28,7 +28,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2019\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_proccwd.c,v 1.1 2019/06/01 19:49:02 kamil Exp $"); +__RCSID("$NetBSD: t_proccwd.c,v 1.2 2019/06/01 22:18:23 kamil Exp $"); #include #include @@ -84,7 +84,7 @@ ATF_TC_BODY(prompt_pid, tc) ATF_REQUIRE_EQ(strlen(buf) + 1, prompted_len); ATF_REQUIRE(strlen(buf) > 0); - if (t[i] == -1 || t[i] == getpid() || t[i] == getppid()) { + if (t[i] == -1 || t[i] == getpid()) { getcwd(cwdbuf, MAXPATHLEN); ATF_REQUIRE_EQ(strcmp(buf, cwdbuf), 0); ATF_REQUIRE(strlen(buf) > strlen("/")); @@ -133,7 +133,7 @@ ATF_TC_BODY(chroot, tc) ASSERT(chroot(buf) == 0); errno = 0; - rv = getproccwd(NULL, , pid_one); + rv = getproccwd(buf, , pid_one); ASSERT(rv == -1); ASSERT(errno == ENOENT);
CVS commit: src/tests/kernel
Module Name:src Committed By: kamil Date: Sat Jun 1 22:18:23 UTC 2019 Modified Files: src/tests/kernel: t_proccwd.c Log Message: Fix a mistake in a test for KERN_PROC_CWD Emit properly ENOENT scenario in chroot. For some reason the final patch did not hit the tree. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_proccwd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: christos Date: Tue May 21 04:09:46 UTC 2019 Modified Files: src/tests/kernel: gen_t_subr_prf Log Message: add printf attribute To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/kernel/gen_t_subr_prf Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: christos Date: Tue May 21 04:10:20 UTC 2019 Modified Files: src/tests/kernel: gen_t_subr_prf Log Message: unexpand To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/kernel/gen_t_subr_prf Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: christos Date: Tue May 21 04:09:46 UTC 2019 Modified Files: src/tests/kernel: gen_t_subr_prf Log Message: add printf attribute To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/kernel/gen_t_subr_prf Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/gen_t_subr_prf diff -u src/tests/kernel/gen_t_subr_prf:1.6 src/tests/kernel/gen_t_subr_prf:1.7 --- src/tests/kernel/gen_t_subr_prf:1.6 Mon May 20 23:46:45 2019 +++ src/tests/kernel/gen_t_subr_prf Tue May 21 00:09:46 2019 @@ -122,9 +122,7 @@ ATF_TC_HEAD(vasprintf_print, tc) atf_tc_set_md_var(tc, "descr", "checks vasprintf works"); } -int vasp_helper(char **, const char *, ...); - -int +static int __printflike(2, 3) vasp_helper(char **buf, const char *fmt, ...) { va_list ap;
CVS commit: src/tests/kernel
Module Name:src Committed By: christos Date: Tue May 21 04:10:20 UTC 2019 Modified Files: src/tests/kernel: gen_t_subr_prf Log Message: unexpand To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/kernel/gen_t_subr_prf Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/gen_t_subr_prf diff -u src/tests/kernel/gen_t_subr_prf:1.7 src/tests/kernel/gen_t_subr_prf:1.8 --- src/tests/kernel/gen_t_subr_prf:1.7 Tue May 21 00:09:46 2019 +++ src/tests/kernel/gen_t_subr_prf Tue May 21 00:10:20 2019 @@ -23,7 +23,7 @@ cat << _EOF > $2 #undef putchar #define putchar xputchar -#define kmem_alloc(n, f) malloc(n) +#define kmem_alloc(n, f) malloc(n) static int putchar(char c, int foo, void *b) { @@ -57,7 +57,7 @@ static void (*v_flush)(void) = empty; ATF_TC(snprintf_print); ATF_TC_HEAD(snprintf_print, tc) { -atf_tc_set_md_var(tc, "descr", "checks snprintf print"); + atf_tc_set_md_var(tc, "descr", "checks snprintf print"); } ATF_TC_BODY(snprintf_print, tc) @@ -74,7 +74,7 @@ ATF_TC_BODY(snprintf_print, tc) ATF_TC(snprintf_print_overflow); ATF_TC_HEAD(snprintf_print_overflow, tc) { -atf_tc_set_md_var(tc, "descr", "checks snprintf print with overflow"); + atf_tc_set_md_var(tc, "descr", "checks snprintf print with overflow"); } ATF_TC_BODY(snprintf_print_overflow, tc) @@ -91,7 +91,7 @@ ATF_TC_BODY(snprintf_print_overflow, tc) ATF_TC(snprintf_count); ATF_TC_HEAD(snprintf_count, tc) { -atf_tc_set_md_var(tc, "descr", "checks snprintf count"); + atf_tc_set_md_var(tc, "descr", "checks snprintf count"); } ATF_TC_BODY(snprintf_count, tc) @@ -105,7 +105,7 @@ ATF_TC_BODY(snprintf_count, tc) ATF_TC(snprintf_count_overflow); ATF_TC_HEAD(snprintf_count_overflow, tc) { -atf_tc_set_md_var(tc, "descr", "checks snprintf count with overflow"); + atf_tc_set_md_var(tc, "descr", "checks snprintf count with overflow"); } ATF_TC_BODY(snprintf_count_overflow, tc) @@ -119,7 +119,7 @@ ATF_TC_BODY(snprintf_count_overflow, tc) ATF_TC(vasprintf_print); ATF_TC_HEAD(vasprintf_print, tc) { -atf_tc_set_md_var(tc, "descr", "checks vasprintf works"); + atf_tc_set_md_var(tc, "descr", "checks vasprintf works"); } static int __printflike(2, 3) @@ -149,13 +149,13 @@ ATF_TC_BODY(vasprintf_print, tc) ATF_TP_ADD_TCS(tp) { -ATF_TP_ADD_TC(tp, snprintf_print); -ATF_TP_ADD_TC(tp, snprintf_print_overflow); -ATF_TP_ADD_TC(tp, snprintf_count); -ATF_TP_ADD_TC(tp, snprintf_count_overflow); + ATF_TP_ADD_TC(tp, snprintf_print); + ATF_TP_ADD_TC(tp, snprintf_print_overflow); + ATF_TP_ADD_TC(tp, snprintf_count); + ATF_TP_ADD_TC(tp, snprintf_count_overflow); ATF_TP_ADD_TC(tp, vasprintf_print); -return atf_no_error(); + return atf_no_error(); } _EOF
CVS commit: src/tests/kernel
Module Name:src Committed By: kre Date: Tue May 21 03:46:45 UTC 2019 Modified Files: src/tests/kernel: gen_t_subr_prf Log Message: Make the t_subr_prf test build after changes to sys/kern/subr_prf.c and while here add a simple test for the new kernel vasprintf(). To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/kernel/gen_t_subr_prf Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: kre Date: Tue May 21 03:46:45 UTC 2019 Modified Files: src/tests/kernel: gen_t_subr_prf Log Message: Make the t_subr_prf test build after changes to sys/kern/subr_prf.c and while here add a simple test for the new kernel vasprintf(). To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/kernel/gen_t_subr_prf Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/gen_t_subr_prf diff -u src/tests/kernel/gen_t_subr_prf:1.5 src/tests/kernel/gen_t_subr_prf:1.6 --- src/tests/kernel/gen_t_subr_prf:1.5 Sun Feb 3 10:48:47 2019 +++ src/tests/kernel/gen_t_subr_prf Tue May 21 03:46:45 2019 @@ -6,6 +6,7 @@ cat << _EOF > $2 #include #include #include +#include #include #include @@ -16,11 +17,14 @@ cat << _EOF > $2 #undef vsnprintf #undef sprintf #undef vsprintf +#undef vasprintf #define KPRINTF_BUFSIZE 1024 #undef putchar #define putchar xputchar +#define kmem_alloc(n, f) malloc(n) + static int putchar(char c, int foo, void *b) { return fputc(c, stderr); @@ -112,12 +116,46 @@ ATF_TC_BODY(snprintf_count_overflow, tc) ATF_CHECK_EQ(i, 16); } +ATF_TC(vasprintf_print); +ATF_TC_HEAD(vasprintf_print, tc) +{ +atf_tc_set_md_var(tc, "descr", "checks vasprintf works"); +} + +int vasp_helper(char **, const char *, ...); + +int +vasp_helper(char **buf, const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = vasprintf(buf, fmt, ap); + va_end(ap); + return ret; +} + +ATF_TC_BODY(vasprintf_print, tc) +{ + int i; + char *buf; + + buf = NULL; + i = vasp_helper(, "N=%d C=%c S=%s", 7, 'x', "abc"); + ATF_CHECK_EQ(i, 13); + ATF_CHECK(buf != NULL); + ATF_CHECK_STREQ(buf, "N=7 C=x S=abc"); + free(buf); +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, snprintf_print); ATF_TP_ADD_TC(tp, snprintf_print_overflow); ATF_TP_ADD_TC(tp, snprintf_count); ATF_TP_ADD_TC(tp, snprintf_count_overflow); + ATF_TP_ADD_TC(tp, vasprintf_print); return atf_no_error(); }
CVS commit: src/tests/kernel
Module Name:src Committed By: kamil Date: Thu Apr 25 19:37:10 UTC 2019 Modified Files: src/tests/kernel: h_segv.c Log Message: Fix typo To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/tests/kernel/h_segv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: kamil Date: Thu Apr 25 19:37:10 UTC 2019 Modified Files: src/tests/kernel: h_segv.c Log Message: Fix typo To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/tests/kernel/h_segv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/h_segv.c diff -u src/tests/kernel/h_segv.c:1.13 src/tests/kernel/h_segv.c:1.14 --- src/tests/kernel/h_segv.c:1.13 Wed Jan 30 12:16:28 2019 +++ src/tests/kernel/h_segv.c Thu Apr 25 19:37:09 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: h_segv.c,v 1.13 2019/01/30 12:16:28 martin Exp $ */ +/* $NetBSD: h_segv.c,v 1.14 2019/04/25 19:37:09 kamil Exp $ */ /*- * Copyright (c) 2017 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: h_segv.c,v 1.13 2019/01/30 12:16:28 martin Exp $"); +__RCSID("$NetBSD: h_segv.c,v 1.14 2019/04/25 19:37:09 kamil Exp $"); #define __TEST_FENV @@ -113,7 +113,7 @@ check_fpe(void) { #if (__arm__ && !__SOFTFP__) || __aarch64__ /* - * Some NEON fpus do not trap on IEEE 754 FP excpeptions. + * Some NEON fpus do not trap on IEEE 754 FP exceptions. * Skip these tests if running on them and compiled for * hard float. */
CVS commit: src/tests/kernel
Module Name:src Committed By: christos Date: Sun Jan 27 16:29:56 UTC 2019 Modified Files: src/tests/kernel: h_segv.c Log Message: vaxinate against ieeefp.h To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/tests/kernel/h_segv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/h_segv.c diff -u src/tests/kernel/h_segv.c:1.11 src/tests/kernel/h_segv.c:1.12 --- src/tests/kernel/h_segv.c:1.11 Sat Jan 26 11:44:30 2019 +++ src/tests/kernel/h_segv.c Sun Jan 27 11:29:56 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: h_segv.c,v 1.11 2019/01/26 16:44:30 martin Exp $ */ +/* $NetBSD: h_segv.c,v 1.12 2019/01/27 16:29:56 christos Exp $ */ /*- * Copyright (c) 2017 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: h_segv.c,v 1.11 2019/01/26 16:44:30 martin Exp $"); +__RCSID("$NetBSD: h_segv.c,v 1.12 2019/01/27 16:29:56 christos Exp $"); #define __TEST_FENV @@ -39,7 +39,9 @@ __RCSID("$NetBSD: h_segv.c,v 1.11 2019/0 #include #include +#if (__arm__ && !__SOFTFP__) || __aarch64__ #include /* only need for ARM Cortex/Neon hack */ +#endif #include #include #include
CVS commit: src/tests/kernel
Module Name:src Committed By: christos Date: Sun Jan 27 16:29:56 UTC 2019 Modified Files: src/tests/kernel: h_segv.c Log Message: vaxinate against ieeefp.h To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/tests/kernel/h_segv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: martin Date: Sat Jan 26 16:44:30 UTC 2019 Modified Files: src/tests/kernel: h_segv.c t_trapsignal.sh Log Message: Some arm CPUs do not implement traps on floating point exceptions. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/tests/kernel/h_segv.c cvs rdiff -u -r1.4 -r1.5 src/tests/kernel/t_trapsignal.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/h_segv.c diff -u src/tests/kernel/h_segv.c:1.10 src/tests/kernel/h_segv.c:1.11 --- src/tests/kernel/h_segv.c:1.10 Mon Nov 12 05:02:00 2018 +++ src/tests/kernel/h_segv.c Sat Jan 26 16:44:30 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: h_segv.c,v 1.10 2018/11/12 05:02:00 riastradh Exp $ */ +/* $NetBSD: h_segv.c,v 1.11 2019/01/26 16:44:30 martin Exp $ */ /*- * Copyright (c) 2017 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: h_segv.c,v 1.10 2018/11/12 05:02:00 riastradh Exp $"); +__RCSID("$NetBSD: h_segv.c,v 1.11 2019/01/26 16:44:30 martin Exp $"); #define __TEST_FENV @@ -39,6 +39,7 @@ __RCSID("$NetBSD: h_segv.c,v 1.10 2018/1 #include #include +#include /* only need for ARM Cortex/Neon hack */ #include #include #include @@ -50,6 +51,7 @@ static int flags; #define F_HANDLE 2 #define F_MASK 4 #define F_IGNORE 8 +#define F_CHECK 16 static struct { const char *n; @@ -58,7 +60,8 @@ static struct { { "recurse", F_RECURSE }, { "handle", F_HANDLE }, { "mask", F_MASK }, - { "ignore", F_IGNORE } + { "ignore", F_IGNORE }, + { "check", F_CHECK } }; static int sig; @@ -104,6 +107,23 @@ trigger_ill(void) } static void +check_fpe(void) +{ +#if (__arm__ && !__SOFTFP__) || __aarch64__ + /* + * Some NEON fpus do not implement IEEE exception handling, + * skip these tests if running on them and compiled for + * hard float. + */ + if (0 == fpsetmask(fpsetmask(FP_X_INV))) { + printf("FPU does not implement exception handling\n"); + exit(EXIT_FAILURE); + } +#endif + exit(EXIT_SUCCESS); +} + +static void trigger_fpe(void) { volatile double a = getpid(); @@ -185,7 +205,7 @@ usage(void) const char *pname = getprogname(); fprintf(stderr, "Usage: %s segv|trap|ill|fpe|bus " - "[recurse|mask|handle|ignore] ...\n", pname); + "[recurse|mask|handle|ignore|check] ...\n", pname); exit(EXIT_FAILURE); } @@ -221,6 +241,13 @@ main(int argc, char *argv[]) if (flags == 0 || sig == 0) usage(); + if (flags & F_CHECK && sig != SIGFPE) { + fprintf(stderr, "can only check for fpe support\n"); + return 1; + } + if (flags & F_CHECK) + check_fpe(); + if (flags & F_HANDLE) { struct sigaction sa; Index: src/tests/kernel/t_trapsignal.sh diff -u src/tests/kernel/t_trapsignal.sh:1.4 src/tests/kernel/t_trapsignal.sh:1.5 --- src/tests/kernel/t_trapsignal.sh:1.4 Sun May 27 17:04:45 2018 +++ src/tests/kernel/t_trapsignal.sh Sat Jan 26 16:44:30 2019 @@ -1,4 +1,4 @@ -# $NetBSD: t_trapsignal.sh,v 1.4 2018/05/27 17:04:45 kamil Exp $ +# $NetBSD: t_trapsignal.sh,v 1.5 2019/01/26 16:44:30 martin Exp $ # # Copyright (c) 2017 The NetBSD Foundation, Inc. # All rights reserved. @@ -172,6 +172,18 @@ trap_ignore_body() # SIGFPE +fpe_available() +{ + if ${HELPER} fpe check > msg.$$ + then + rm -f msg.$$ + else + msg=$( cat msg.$$ ) + rm -f msg.$$ + atf_skip "$msg" + fi +} + atf_test_case fpe_simple fpe_simple() { @@ -179,6 +191,7 @@ fpe_simple() } fpe_simple_body() { + fpe_available atf_check -s signal:8 -o "inline:" -e "inline:" \ ${HELPER} fpe recurse } @@ -190,6 +203,7 @@ fpe_handle() } fpe_handle_body() { + fpe_available atf_check -s exit:0 -o "inline:" -e "inline:got 8\n" \ ${HELPER} fpe handle } @@ -201,6 +215,7 @@ fpe_mask() } fpe_mask_body() { + fpe_available atf_check -s signal:8 -o "inline:" -e "inline:" \ ${HELPER} fpe mask } @@ -212,6 +227,7 @@ fpe_handle_mask() } fpe_handle_mask_body() { + fpe_available atf_check -s signal:8 -o "inline:" -e "inline:" \ ${HELPER} fpe mask handle } @@ -224,6 +240,7 @@ fpe_handle_recurse() fpe_handle_recurse_body() { + fpe_available atf_check -s signal:8 -o "inline:" -e "inline:got 8\n" \ ${HELPER} fpe handle recurse } @@ -236,6 +253,7 @@ fpe_ignore() fpe_ignore_body() { + fpe_available atf_check -s signal:8 -o "inline:" -e "inline:" \ ${HELPER} fpe ignore }
CVS commit: src/tests/kernel
Module Name:src Committed By: martin Date: Sat Jan 26 16:44:30 UTC 2019 Modified Files: src/tests/kernel: h_segv.c t_trapsignal.sh Log Message: Some arm CPUs do not implement traps on floating point exceptions. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/tests/kernel/h_segv.c cvs rdiff -u -r1.4 -r1.5 src/tests/kernel/t_trapsignal.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
re: CVS commit: src/tests/kernel
> Modified Files: > src/tests/kernel: t_timeleft.c > > Log Message: > add call error checks, requested by mrg@ thanks!
CVS commit: src/tests/kernel
Module Name:src Committed By: christos Date: Mon Jan 14 00:23:43 UTC 2019 Modified Files: src/tests/kernel: t_timeleft.c Log Message: add call error checks, requested by mrg@ To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/t_timeleft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_timeleft.c diff -u src/tests/kernel/t_timeleft.c:1.3 src/tests/kernel/t_timeleft.c:1.4 --- src/tests/kernel/t_timeleft.c:1.3 Sun Jan 13 10:36:57 2019 +++ src/tests/kernel/t_timeleft.c Sun Jan 13 19:23:43 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: t_timeleft.c,v 1.3 2019/01/13 15:36:57 christos Exp $ */ +/* $NetBSD: t_timeleft.c,v 1.4 2019/01/14 00:23:43 christos Exp $ */ /*- * Copyright (c) 2017 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_timeleft.c,v 1.3 2019/01/13 15:36:57 christos Exp $"); +__RCSID("$NetBSD: t_timeleft.c,v 1.4 2019/01/14 00:23:43 christos Exp $"); #include #include @@ -91,9 +91,9 @@ tester(void (*fun)(struct timespec *)) ATF_REQUIRE(signal(SIGINT, sighandler) == 0); ATF_REQUIRE(pthread_create(, NULL, runner, ) == 0); - nanosleep(, NULL); - pthread_kill(thr, SIGINT); - pthread_join(thr, NULL); + ATF_REQUIRE(nanosleep(, NULL) == 0); + ATF_REQUIRE(pthread_kill(thr, SIGINT) == 0); + ATF_REQUIRE(pthread_join(thr, NULL) == 0); printf("Orig time %ju.%lu\n", (intmax_t)ts.tv_sec, ts.tv_nsec); printf("Time left %ju.%lu\n", (intmax_t)i.ts.tv_sec, i.ts.tv_nsec); ATF_REQUIRE(timespeccmp(, , <));
CVS commit: src/tests/kernel
Module Name:src Committed By: christos Date: Mon Jan 14 00:23:43 UTC 2019 Modified Files: src/tests/kernel: t_timeleft.c Log Message: add call error checks, requested by mrg@ To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/t_timeleft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
re: CVS commit: src/tests/kernel
On Jan 14, 9:29am, m...@eterna.com.au (matthew green) wrote: -- Subject: re: CVS commit: src/tests/kernel | "Christos Zoulas" writes: | > Module Name:src | > Committed By: christos | > Date: Sun Jan 13 15:36:57 UTC 2019 | > | > Modified Files: | > src/tests/kernel: t_timeleft.c | > | > Log Message: | > Increase the timeout a bit, and make sure we join so that there is no | > race. | | i notice both pthread_kill() and pthread_join() calls here do | not have their return value checked. | | any particular reason? shouldn't their failiure also be a | test failure? Nope, I will add them. christos
re: CVS commit: src/tests/kernel
"Christos Zoulas" writes: > Module Name: src > Committed By: christos > Date: Sun Jan 13 15:36:57 UTC 2019 > > Modified Files: > src/tests/kernel: t_timeleft.c > > Log Message: > Increase the timeout a bit, and make sure we join so that there is no > race. i notice both pthread_kill() and pthread_join() calls here do not have their return value checked. any particular reason? shouldn't their failiure also be a test failure? .mrg.
CVS commit: src/tests/kernel
Module Name:src Committed By: christos Date: Sun Jan 13 15:36:57 UTC 2019 Modified Files: src/tests/kernel: t_timeleft.c Log Message: Increase the timeout a bit, and make sure we join so that there is no race. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/t_timeleft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_timeleft.c diff -u src/tests/kernel/t_timeleft.c:1.2 src/tests/kernel/t_timeleft.c:1.3 --- src/tests/kernel/t_timeleft.c:1.2 Sat Dec 30 12:06:27 2017 +++ src/tests/kernel/t_timeleft.c Sun Jan 13 10:36:57 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: t_timeleft.c,v 1.2 2017/12/30 17:06:27 martin Exp $ */ +/* $NetBSD: t_timeleft.c,v 1.3 2019/01/13 15:36:57 christos Exp $ */ /*- * Copyright (c) 2017 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_timeleft.c,v 1.2 2017/12/30 17:06:27 martin Exp $"); +__RCSID("$NetBSD: t_timeleft.c,v 1.3 2019/01/13 15:36:57 christos Exp $"); #include #include @@ -84,7 +84,7 @@ static void tester(void (*fun)(struct timespec *)) { const struct timespec ts = { 5, 0 }; - const struct timespec sts = { 0, 200 }; + const struct timespec sts = { 1, 0 }; struct info i = { fun, ts }; pthread_t thr; @@ -93,6 +93,7 @@ tester(void (*fun)(struct timespec *)) nanosleep(, NULL); pthread_kill(thr, SIGINT); + pthread_join(thr, NULL); printf("Orig time %ju.%lu\n", (intmax_t)ts.tv_sec, ts.tv_nsec); printf("Time left %ju.%lu\n", (intmax_t)i.ts.tv_sec, i.ts.tv_nsec); ATF_REQUIRE(timespeccmp(, , <));
CVS commit: src/tests/kernel
Module Name:src Committed By: christos Date: Sun Jan 13 15:36:57 UTC 2019 Modified Files: src/tests/kernel: t_timeleft.c Log Message: Increase the timeout a bit, and make sure we join so that there is no race. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/t_timeleft.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: thorpej Date: Fri Dec 28 16:01:53 UTC 2018 Modified Files: src/tests/kernel: t_threadpool.sh Log Message: kre@ notified me that the kernel/t_threadpool "rapid" test was occasionally tripping a KASSERT() failure in the i386-qemu test rig. It turns out this is due to "rapid" simply being a buggy test that makes assumptions that aren't always true, especially on slower / uniprocesor hardware. So, the right thing to do is just remove the test. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_threadpool.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/t_threadpool.sh diff -u src/tests/kernel/t_threadpool.sh:1.1 src/tests/kernel/t_threadpool.sh:1.2 --- src/tests/kernel/t_threadpool.sh:1.1 Mon Dec 24 16:58:54 2018 +++ src/tests/kernel/t_threadpool.sh Fri Dec 28 16:01:53 2018 @@ -1,4 +1,4 @@ -# $NetBSD: t_threadpool.sh,v 1.1 2018/12/24 16:58:54 thorpej Exp $ +# $NetBSD: t_threadpool.sh,v 1.2 2018/12/28 16:01:53 thorpej Exp $ # # Copyright (c) 2018 The NetBSD Foundation, Inc. # All rights reserved. @@ -133,37 +133,8 @@ percpu_cleanup() { modunload threadpool_tester >/dev/null 2>&1 } -atf_test_case rapid cleanup -rapid_head() { - atf_set "descr" "Test rapid get/schedule/put sequence" - atf_set "require.user" "root" -} -rapid_body() { - modload $(atf_get_srcdir)/threadpool_tester/threadpool_tester.kmod - if [ $? -ne 0 ]; then - atf_skip "cannot load threadpool_tester.kmod" - fi - - # Ensure that the state is clean. - read_sysctl kern.threadpool_tester.test_value 0 - - # Create an unbound pool. Immediatelty schedule a job on it - # and destroy it. - write_sysctl kern.threadpool_tester.get_unbound $tp_pri - write_sysctl kern.threadpool_tester.run_unbound $tp_pri - write_sysctl kern.threadpool_tester.put_unbound $tp_pri - - # Now ensure the job successfully ran. - sleep $job_delay - read_sysctl kern.threadpool_tester.test_value 1 -} -rapid_cleanup() { - modunload threadpool_tester >/dev/null 2>&1 -} - atf_init_test_cases() { atf_add_test_case unbound atf_add_test_case percpu - atf_add_test_case rapid }
CVS commit: src/tests/kernel
Module Name:src Committed By: thorpej Date: Fri Dec 28 16:01:53 UTC 2018 Modified Files: src/tests/kernel: t_threadpool.sh Log Message: kre@ notified me that the kernel/t_threadpool "rapid" test was occasionally tripping a KASSERT() failure in the i386-qemu test rig. It turns out this is due to "rapid" simply being a buggy test that makes assumptions that aren't always true, especially on slower / uniprocesor hardware. So, the right thing to do is just remove the test. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_threadpool.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel/threadpool_tester
Module Name:src Committed By: thorpej Date: Wed Dec 26 22:21:10 UTC 2018 Modified Files: src/tests/kernel/threadpool_tester: threadpool_tester.c Log Message: Fix spurios whitespace (thank you substandard vi clones). To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 \ src/tests/kernel/threadpool_tester/threadpool_tester.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/threadpool_tester/threadpool_tester.c diff -u src/tests/kernel/threadpool_tester/threadpool_tester.c:1.2 src/tests/kernel/threadpool_tester/threadpool_tester.c:1.3 --- src/tests/kernel/threadpool_tester/threadpool_tester.c:1.2 Wed Dec 26 18:54:19 2018 +++ src/tests/kernel/threadpool_tester/threadpool_tester.c Wed Dec 26 22:21:10 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: threadpool_tester.c,v 1.2 2018/12/26 18:54:19 thorpej Exp $ */ +/* $NetBSD: threadpool_tester.c,v 1.3 2018/12/26 22:21:10 thorpej Exp $ */ /*- * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: threadpool_tester.c,v 1.2 2018/12/26 18:54:19 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: threadpool_tester.c,v 1.3 2018/12/26 22:21:10 thorpej Exp $"); #include #include @@ -79,17 +79,17 @@ threadpool_tester_get_unbound(SYSCTLFN_A error = sysctl_lookup(SYSCTLFN_CALL()); if (error || newp == NULL) return error; - + if (! pri_is_valid(val)) return EINVAL; - + error = threadpool_get(, val); if (error) { TP_LOG(("%s: threadpool_get(..., %d) failed -> %d\n", __func__, val, error)); return error; } - + mutex_enter(>ctx_mutex); if (ctx->ctx_unbound[pri_to_idx(val)] == NULL) ctx->ctx_unbound[pri_to_idx(val)] = pool; @@ -128,10 +128,10 @@ threadpool_tester_put_unbound(SYSCTLFN_A error = sysctl_lookup(SYSCTLFN_CALL()); if (error || newp == NULL) return error; - + if (! pri_is_valid(val)) return EINVAL; - + mutex_enter(>ctx_mutex); /* We only ever maintain a single reference. */ pool = ctx->ctx_unbound[pri_to_idx(val)]; @@ -167,7 +167,7 @@ threadpool_tester_run_unbound(SYSCTLFN_A error = sysctl_lookup(SYSCTLFN_CALL()); if (error || newp == NULL) return error; - + if (! pri_is_valid(val)) return EINVAL; @@ -204,17 +204,17 @@ threadpool_tester_get_percpu(SYSCTLFN_AR error = sysctl_lookup(SYSCTLFN_CALL()); if (error || newp == NULL) return error; - + if (! pri_is_valid(val)) return EINVAL; - + error = threadpool_percpu_get(, val); if (error) { TP_LOG(("%s: threadpool_percpu_get(..., %d) failed -> %d\n", __func__, val, error)); return error; } - + mutex_enter(>ctx_mutex); if (ctx->ctx_percpu[pri_to_idx(val)] == NULL) ctx->ctx_percpu[pri_to_idx(val)] = pcpu; @@ -253,10 +253,10 @@ threadpool_tester_put_percpu(SYSCTLFN_AR error = sysctl_lookup(SYSCTLFN_CALL()); if (error || newp == NULL) return error; - + if (! pri_is_valid(val)) return EINVAL; - + mutex_enter(>ctx_mutex); /* We only ever maintain a single reference. */ pcpu = ctx->ctx_percpu[pri_to_idx(val)]; @@ -293,7 +293,7 @@ threadpool_tester_run_percpu(SYSCTLFN_AR error = sysctl_lookup(SYSCTLFN_CALL()); if (error || newp == NULL) return error; - + if (! pri_is_valid(val)) return EINVAL; @@ -475,7 +475,7 @@ threadpool_tester_fini(void) mutex_destroy(_ctx.ctx_mutex); sysctl_teardown(_ctx.ctx_sysctllog); - + return 0; } @@ -488,11 +488,11 @@ threadpool_tester_modcmd(modcmd_t cmd, v case MODULE_CMD_INIT: error = threadpool_tester_init(); break; - + case MODULE_CMD_FINI: error = threadpool_tester_fini(); break; - + case MODULE_CMD_STAT: default: error = ENOTTY;
CVS commit: src/tests/kernel/threadpool_tester
Module Name:src Committed By: thorpej Date: Wed Dec 26 22:21:10 UTC 2018 Modified Files: src/tests/kernel/threadpool_tester: threadpool_tester.c Log Message: Fix spurios whitespace (thank you substandard vi clones). To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 \ src/tests/kernel/threadpool_tester/threadpool_tester.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Mon Nov 12 05:02:00 UTC 2018 Modified Files: src/tests/kernel: h_segv.c Log Message: Make fenv.h optional for this test to unbreak the vax build. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/tests/kernel/h_segv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/h_segv.c diff -u src/tests/kernel/h_segv.c:1.9 src/tests/kernel/h_segv.c:1.10 --- src/tests/kernel/h_segv.c:1.9 Sun Nov 11 01:26:08 2018 +++ src/tests/kernel/h_segv.c Mon Nov 12 05:02:00 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: h_segv.c,v 1.9 2018/11/11 01:26:08 riastradh Exp $ */ +/* $NetBSD: h_segv.c,v 1.10 2018/11/12 05:02:00 riastradh Exp $ */ /*- * Copyright (c) 2017 The NetBSD Foundation, Inc. @@ -29,7 +29,9 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: h_segv.c,v 1.9 2018/11/11 01:26:08 riastradh Exp $"); +__RCSID("$NetBSD: h_segv.c,v 1.10 2018/11/12 05:02:00 riastradh Exp $"); + +#define __TEST_FENV #include #include @@ -107,7 +109,9 @@ trigger_fpe(void) volatile double a = getpid(); volatile double b = strtol("0", NULL, 0); +#ifdef __HAVE_FENV feenableexcept(FE_ALL_EXCEPT); +#endif usleep((int)(a/b)); }
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Mon Nov 12 05:02:00 UTC 2018 Modified Files: src/tests/kernel: h_segv.c Log Message: Make fenv.h optional for this test to unbreak the vax build. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/tests/kernel/h_segv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Sun Nov 11 01:26:00 UTC 2018 Modified Files: src/tests/kernel: h_segv.c Log Message: Sort #includes. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/kernel/h_segv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/h_segv.c diff -u src/tests/kernel/h_segv.c:1.7 src/tests/kernel/h_segv.c:1.8 --- src/tests/kernel/h_segv.c:1.7 Wed May 30 17:48:13 2018 +++ src/tests/kernel/h_segv.c Sun Nov 11 01:26:00 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: h_segv.c,v 1.7 2018/05/30 17:48:13 kamil Exp $ */ +/* $NetBSD: h_segv.c,v 1.8 2018/11/11 01:26:00 riastradh Exp $ */ /*- * Copyright (c) 2017 The NetBSD Foundation, Inc. @@ -29,17 +29,18 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: h_segv.c,v 1.7 2018/05/30 17:48:13 kamil Exp $"); +__RCSID("$NetBSD: h_segv.c,v 1.8 2018/11/11 01:26:00 riastradh Exp $"); #include #include #include + +#include +#include #include -#include #include +#include #include -#include -#include static int flags; #define F_RECURSE 1
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Sun Nov 11 01:26:08 UTC 2018 Modified Files: src/tests/kernel: Makefile h_segv.c Log Message: Use feenableexcept to trap fp exceptions, and trigger one, for SIGFPE. Not every CPU traps integer division by zero -- aarch64, powerpc, , just return zero. To generate a diff of this commit: cvs rdiff -u -r1.53 -r1.54 src/tests/kernel/Makefile cvs rdiff -u -r1.8 -r1.9 src/tests/kernel/h_segv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/Makefile diff -u src/tests/kernel/Makefile:1.53 src/tests/kernel/Makefile:1.54 --- src/tests/kernel/Makefile:1.53 Wed Mar 14 02:13:47 2018 +++ src/tests/kernel/Makefile Sun Nov 11 01:26:08 2018 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.53 2018/03/14 02:13:47 kamil Exp $ +# $NetBSD: Makefile,v 1.54 2018/11/11 01:26:08 riastradh Exp $ NOMAN= # defined @@ -67,4 +67,6 @@ CPPFLAGS.t_subr_prf.c= -Wno-pointer-sign CLEANFILES+= t_subr_prf.c +LDADD.h_segv+= -lm + .include Index: src/tests/kernel/h_segv.c diff -u src/tests/kernel/h_segv.c:1.8 src/tests/kernel/h_segv.c:1.9 --- src/tests/kernel/h_segv.c:1.8 Sun Nov 11 01:26:00 2018 +++ src/tests/kernel/h_segv.c Sun Nov 11 01:26:08 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: h_segv.c,v 1.8 2018/11/11 01:26:00 riastradh Exp $ */ +/* $NetBSD: h_segv.c,v 1.9 2018/11/11 01:26:08 riastradh Exp $ */ /*- * Copyright (c) 2017 The NetBSD Foundation, Inc. @@ -29,13 +29,14 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: h_segv.c,v 1.8 2018/11/11 01:26:00 riastradh Exp $"); +__RCSID("$NetBSD: h_segv.c,v 1.9 2018/11/11 01:26:08 riastradh Exp $"); #include #include #include #include +#include #include #include #include @@ -103,10 +104,12 @@ trigger_ill(void) static void trigger_fpe(void) { - volatile int a = getpid(); - volatile int b = strtol("0", NULL, 0); + volatile double a = getpid(); + volatile double b = strtol("0", NULL, 0); - usleep(a/b); + feenableexcept(FE_ALL_EXCEPT); + + usleep((int)(a/b)); } static void
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Sun Nov 11 01:26:08 UTC 2018 Modified Files: src/tests/kernel: Makefile h_segv.c Log Message: Use feenableexcept to trap fp exceptions, and trigger one, for SIGFPE. Not every CPU traps integer division by zero -- aarch64, powerpc, , just return zero. To generate a diff of this commit: cvs rdiff -u -r1.53 -r1.54 src/tests/kernel/Makefile cvs rdiff -u -r1.8 -r1.9 src/tests/kernel/h_segv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: riastradh Date: Sun Nov 11 01:26:00 UTC 2018 Modified Files: src/tests/kernel: h_segv.c Log Message: Sort #includes. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/kernel/h_segv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/kernel
Module Name:src Committed By: kamil Date: Sun May 27 17:04:45 UTC 2018 Modified Files: src/tests/kernel: h_segv.c t_trapsignal.sh Log Message: Handle FPE and BUS scenarios in the ATF t_trapsignal tests These crash signals are crucial for proper handling of abnormal conditions in a program. The additional purpose of these tests it to assure the proper handling of these signals for the coming ptrace(2)-related changes in the signal routing code. Add a stub for ILL scenarios. All tests pass (on amd64). The shell ATF script contains duplicated code. There should be a way to deduplicate it, without rewrite to C. Sponsored by To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/kernel/h_segv.c cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/t_trapsignal.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/kernel/h_segv.c diff -u src/tests/kernel/h_segv.c:1.4 src/tests/kernel/h_segv.c:1.5 --- src/tests/kernel/h_segv.c:1.4 Tue May 22 04:32:56 2018 +++ src/tests/kernel/h_segv.c Sun May 27 17:04:45 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: h_segv.c,v 1.4 2018/05/22 04:32:56 kamil Exp $ */ +/* $NetBSD: h_segv.c,v 1.5 2018/05/27 17:04:45 kamil Exp $ */ /*- * Copyright (c) 2017 The NetBSD Foundation, Inc. @@ -29,9 +29,10 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: h_segv.c,v 1.4 2018/05/22 04:32:56 kamil Exp $"); +__RCSID("$NetBSD: h_segv.c,v 1.5 2018/05/27 17:04:45 kamil Exp $"); #include +#include #include #include #include @@ -40,9 +41,6 @@ __RCSID("$NetBSD: h_segv.c,v 1.4 2018/05 #include #include -// A faulting address -static int *p = (int *) 0xfefefef0; - static int flags; #define F_RECURSE 1 #define F_HANDLE 2 @@ -65,27 +63,107 @@ static struct { int v; } sn[] = { { "segv", SIGSEGV }, - { "trap", SIGTRAP } + { "trap", SIGTRAP }, + { "ill", SIGILL }, + { "fpe", SIGFPE }, + { "bus", SIGBUS } }; static void -foo(int s) +trigger_segv(void) +{ + volatile int *p = (int *)(intptr_t)atoi("0"); + + *p = 1; +} + +static void +trigger_trap(void) { -char buf[64]; -int i = snprintf(buf, sizeof(buf), "got %d\n", s); -write(2, buf, i); - if (flags & F_RECURSE) { - if (sig == SIGSEGV) - *p = 0; - else if (sig == SIGTRAP) { + #ifdef PTRACE_BREAKPOINT_ASM - PTRACE_BREAKPOINT_ASM; + PTRACE_BREAKPOINT_ASM; #else - /* port me */ -#endif - } + /* port me */ +#endif +} + +static void +trigger_ill(void) +{ + +#ifdef PTRACE_ILLEGAL_ASM + PTRACE_ILLEGAL_ASM; +#else + /* port me */ +#endif +} + +static void +trigger_fpe(void) +{ + volatile int a = getpid(); + volatile int b = strtol("0", NULL, 0); + + usleep(a/b); +} + +static void +trigger_bus(void) +{ + FILE *fp; + char *p; + + /* Open an empty file for writing. */ + fp = tmpfile(); + if (fp == NULL) + err(EXIT_FAILURE, "tmpfile"); + + /* Map an empty file with mmap(2) to a pointer. */ + p = mmap(0, 1, PROT_WRITE, MAP_PRIVATE, fileno(fp), 0); + if (p == MAP_FAILED) + err(EXIT_FAILURE, "mmap"); + + /* Invalid memory access causes CPU trap, translated to SIGBUS */ + *p = 'a'; +} + +static void +trigger(void) +{ + + switch (sig) { + case SIGSEGV: + trigger_segv(); + break; + case SIGTRAP: + trigger_trap(); + break; + case SIGILL: + trigger_ill(); + break; + case SIGFPE: + trigger_fpe(); + break; + case SIGBUS: + trigger_bus(); + break; + default: + break; } -exit(EXIT_SUCCESS); +} + +static void +foo(int s) +{ + char buf[64]; + int i = snprintf(buf, sizeof(buf), "got %d\n", s); + write(2, buf, i); + + if (flags & F_RECURSE) + trigger(); + + exit(EXIT_SUCCESS); } static __dead void @@ -93,13 +171,16 @@ usage(void) { const char *pname = getprogname(); - fprintf(stderr, "Usage: %s recurse|mask|handle|ignore ...\n", pname); + fprintf(stderr, "Usage: %s segv|trap|ill|fpe|bus " + "[recurse|mask|handle|ignore] ...\n", pname); + exit(EXIT_FAILURE); } int main(int argc, char *argv[]) { + if (argc == 1) usage(); @@ -108,15 +189,20 @@ main(int argc, char *argv[]) for (j = 0; j < __arraycount(nv); j++) { if (strcmp(nv[j].n, argv[i]) == 0) { flags |= nv[j].v; -break; +goto consumed; } + } + for (j = 0; j < __arraycount(sn); j++) { if (strcmp(sn[j].n, argv[i]) == 0) { sig = sn[j].v; -break; +goto consumed; } } - if (j == __arraycount(nv)) - usage(); + + usage(); + + consumed: + continue; } if (flags == 0 || sig == 0) @@ -151,14 +237,7 @@ main(int argc, char *argv[]) err(EXIT_FAILURE, "sigaction"); } - if (sig == SIGSEGV) - *p = 1; - else if (sig == SIGTRAP) { -#ifdef PTRACE_BREAKPOINT_ASM - PTRACE_BREAKPOINT_ASM; -#else - /* port me */ -#endif - } + trigger(); + return EXIT_SUCCESS; } Index: src/tests/kernel/t_trapsignal.sh diff -u src/tests/kernel/t_trapsignal.sh:1.3 src/tests/kernel/t_trapsignal.sh:1.4 ---