From c369d42df84f5bdabcac9041e6c5680a0cbfeaf9 Mon Sep 17 00:00:00 2001 From: bluhm <> Date: Mon, 9 Nov 2020 23:18:51 +0000 Subject: Sync libc syscall tests with changes in upstream NetBSD. Use #ifdef to document differences to NetBSD behaviour, this helps to track upstream. Mark currently failing test as expected failures. So test programs get compiled and executed, but it shows that further investigation is necceassry. --- src/regress/lib/libc/sys/Makefile | 43 ++++--- src/regress/lib/libc/sys/t_chroot.c | 14 +-- src/regress/lib/libc/sys/t_dup.c | 27 ++++- src/regress/lib/libc/sys/t_fsync.c | 9 +- src/regress/lib/libc/sys/t_getgroups.c | 6 +- src/regress/lib/libc/sys/t_getitimer.c | 4 +- src/regress/lib/libc/sys/t_getrusage.c | 30 ++++- src/regress/lib/libc/sys/t_gettimeofday.c | 10 +- src/regress/lib/libc/sys/t_mknod.c | 22 ++-- src/regress/lib/libc/sys/t_mlock.c | 31 ++++-- src/regress/lib/libc/sys/t_mmap.c | 17 +-- src/regress/lib/libc/sys/t_msgget.c | 10 +- src/regress/lib/libc/sys/t_pipe.c | 10 +- src/regress/lib/libc/sys/t_pipe2.c | 30 ++--- src/regress/lib/libc/sys/t_poll.c | 179 +++--------------------------- src/regress/lib/libc/sys/t_ptrace.c | 6 +- src/regress/lib/libc/sys/t_revoke.c | 23 ++-- src/regress/lib/libc/sys/t_select.c | 12 +- src/regress/lib/libc/sys/t_stat.c | 6 +- src/regress/lib/libc/sys/t_write.c | 6 +- 20 files changed, 212 insertions(+), 283 deletions(-) (limited to 'src/regress/lib/libc/sys') diff --git a/src/regress/lib/libc/sys/Makefile b/src/regress/lib/libc/sys/Makefile index c22d08da74..db67e9078a 100644 --- a/src/regress/lib/libc/sys/Makefile +++ b/src/regress/lib/libc/sys/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.5 2020/10/06 09:20:29 mpi Exp $ +# $OpenBSD: Makefile,v 1.6 2020/11/09 23:18:51 bluhm Exp $ # Copyright (c) 2019 Moritz Buhl # Copyright (c) 2019 Alexander Bluhm @@ -26,24 +26,35 @@ REGRESS_TARGETS = ${PROGS:S/^/run-/} .endif PROGS = -PROGS += t_access t_bind t_chroot t_clock_gettime t_dup t_fsync +PROGS += t_access +PROGS += t_bind +PROGS += t_chroot t_clock_gettime +PROGS += t_dup +PROGS += t_fsync PROGS += t_getgroups t_getitimer t_getlogin t_getpid t_getrusage -PROGS += t_getsid t_getsockname t_gettimeofday t_kill t_link t_listen -PROGS += t_mkdir t_mknod t_msgctl t_msgget t_msgsnd t_msync t_pipe -PROGS += t_poll t_ptrace t_revoke t_select t_sendrecv t_setuid -PROGS += t_socketpair t_sigaction t_truncate t_umask t_write +PROGS += t_getsid t_getsockname t_gettimeofday +PROGS += t_kill +PROGS += t_link t_listen +PROGS += t_mkdir t_mkfifo t_mknod t_mlock t_mmap +PROGS += t_msgctl t_msgget t_msgrcv t_msgsnd t_msync +PROGS += t_pipe t_pipe2 t_poll t_ptrace +PROGS += t_revoke +PROGS += t_select t_sendrecv t_setuid t_socketpair t_sigaction t_stat +PROGS += t_syscall +PROGS += t_truncate +PROGS += t_umask t_unlink +PROGS += t_write # failing tests -.if 0 -PROGS += t_mkfifo -PROGS += t_mlock -PROGS += t_mmap -PROGS += t_msgrcv -PROGS += t_pipe2 -PROGS += t_stat -PROGS += t_syscall -PROGS += t_unlink -.endif +REGRESS_EXPECTED_FAILURES = +REGRESS_EXPECTED_FAILURES += run-t_mlock-4 +REGRESS_EXPECTED_FAILURES += run-t_mmap-1 run-t_mmap-3 +REGRESS_EXPECTED_FAILURES += run-t_msgrcv-3 +REGRESS_EXPECTED_FAILURES += run-t_pipe2-2 +REGRESS_EXPECTED_FAILURES += run-t_stat-1 run-t_stat-4 run-t_stat-5 +REGRESS_EXPECTED_FAILURES += run-t_stat-6 run-t_stat-8 +REGRESS_EXPECTED_FAILURES += run-t_syscall-1 +REGRESS_EXPECTED_FAILURES += run-t_unlink-2 . for p in ${PROGS} SRCS_$p = $p.c atf-c.c diff --git a/src/regress/lib/libc/sys/t_chroot.c b/src/regress/lib/libc/sys/t_chroot.c index 1fbe392a88..b2bc16e49e 100644 --- a/src/regress/lib/libc/sys/t_chroot.c +++ b/src/regress/lib/libc/sys/t_chroot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: t_chroot.c,v 1.1.1.1 2019/11/19 19:57:03 bluhm Exp $ */ +/* $OpenBSD: t_chroot.c,v 1.2 2020/11/09 23:18:51 bluhm Exp $ */ /* $NetBSD: t_chroot.c,v 1.2 2017/01/10 22:36:29 christos Exp $ */ /*- @@ -310,12 +310,12 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, chroot_basic); ATF_TP_ADD_TC(tp, chroot_err); ATF_TP_ADD_TC(tp, chroot_perm); -/* - * Not available on OpenBSD - * ATF_TP_ADD_TC(tp, fchroot_basic); - * ATF_TP_ADD_TC(tp, fchroot_err); - * ATF_TP_ADD_TC(tp, fchroot_perm); - */ +#ifndef __OpenBSD__ + /* fchroot(2) not available */ + ATF_TP_ADD_TC(tp, fchroot_basic); + ATF_TP_ADD_TC(tp, fchroot_err); + ATF_TP_ADD_TC(tp, fchroot_perm); +#endif return atf_no_error(); } diff --git a/src/regress/lib/libc/sys/t_dup.c b/src/regress/lib/libc/sys/t_dup.c index 4021a4f6e4..c998c228b4 100644 --- a/src/regress/lib/libc/sys/t_dup.c +++ b/src/regress/lib/libc/sys/t_dup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: t_dup.c,v 1.1.1.1 2019/11/19 19:57:03 bluhm Exp $ */ +/* $OpenBSD: t_dup.c,v 1.2 2020/11/09 23:18:51 bluhm Exp $ */ /* $NetBSD: t_dup.c,v 1.9 2017/01/13 20:31:53 christos Exp $ */ /*- @@ -212,12 +212,18 @@ ATF_TC_BODY(dup3_err, tc) ATF_REQUIRE(fd >= 0); errno = 0; - /* Adjusted for OpenBSD, initially != -1 */ +#ifdef __OpenBSD__ ATF_REQUIRE(dup3(fd, fd, O_CLOEXEC) == -1); +#else + ATF_REQUIRE(dup3(fd, fd, O_CLOEXEC) != -1); +#endif errno = 0; - /* Adjusted for OpenBSD, initially EBADF */ +#ifdef __OpenBSD__ ATF_REQUIRE_ERRNO(EINVAL, dup3(-1, -1, O_CLOEXEC) == -1); +#else + ATF_REQUIRE_ERRNO(EBADF, dup3(-1, -1, O_CLOEXEC) == -1); +#endif errno = 0; ATF_REQUIRE_ERRNO(EBADF, dup3(fd, -1, O_CLOEXEC) == -1); @@ -302,8 +308,11 @@ ATF_TC_BODY(dup_max, tc) * reached. Ater that dup(2) family * should fail with EMFILE. */ - /* Adjusted for OpenBSD, initially 0 */ +#ifdef __OpenBSD__ (void)closefrom(STDERR_FILENO + 1); +#else + (void)closefrom(0); +#endif (void)memset(&res, 0, sizeof(struct rlimit)); n = 10; @@ -316,14 +325,20 @@ ATF_TC_BODY(dup_max, tc) if (buf == NULL) _exit(EX_OSERR); - /* Adjusted for OpenBSD, initially mkstemp(path) */ +#ifdef __OpenBSD__ buf[0] = open(path, O_CREAT|O_EXCL|O_RDWR, S_IRUSR|S_IWUSR); +#else + buf[0] = mkstemp(path); +#endif if (buf[0] < 0) _exit(EX_OSERR); - /* Adjusted for OpenBSD, initially i < n */ +#ifdef __OpenBSD__ for (i = 1; i < n - (STDERR_FILENO + 1); i++) { +#else + for (i = 1; i < n; i++) { +#endif buf[i] = open(path, O_RDONLY); diff --git a/src/regress/lib/libc/sys/t_fsync.c b/src/regress/lib/libc/sys/t_fsync.c index c6f24c0e85..bc3cd7939b 100644 --- a/src/regress/lib/libc/sys/t_fsync.c +++ b/src/regress/lib/libc/sys/t_fsync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: t_fsync.c,v 1.1.1.1 2019/11/19 19:57:03 bluhm Exp $ */ +/* $OpenBSD: t_fsync.c,v 1.2 2020/11/09 23:18:51 bluhm Exp $ */ /* $NetBSD: t_fsync.c,v 1.2 2012/03/18 07:00:52 jruoho Exp $ */ /*- @@ -103,8 +103,11 @@ ATF_TC_BODY(fsync_sync, tc) (void)snprintf(buf, sizeof(buf), "t_fsync-%d", i); - /* Adjusted for OpenBSD, initially mkstemp(buf) */ - fd = open(buf, O_CREAT|O_EXCL|O_RDWR, 0600); +#ifdef __OpenBSD__ + fd = open(buf, O_CREAT|O_EXCL|O_RDWR, 0600); +#else + fd = mkstemp(buf); +#endif ATF_REQUIRE(fd != -1); ATF_REQUIRE(write(fd, "0", 1) == 1); diff --git a/src/regress/lib/libc/sys/t_getgroups.c b/src/regress/lib/libc/sys/t_getgroups.c index dcef3c16f5..5cecd3031f 100644 --- a/src/regress/lib/libc/sys/t_getgroups.c +++ b/src/regress/lib/libc/sys/t_getgroups.c @@ -1,4 +1,4 @@ -/* $OpenBSD: t_getgroups.c,v 1.1.1.1 2019/11/19 19:57:03 bluhm Exp $ */ +/* $OpenBSD: t_getgroups.c,v 1.2 2020/11/09 23:18:51 bluhm Exp $ */ /* $NetBSD: t_getgroups.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $ */ /*- @@ -56,7 +56,11 @@ ATF_TC_BODY(getgroups_err, tc) errno = 0; +#if __OpenBSD__ ATF_REQUIRE(getgroups(NGROUPS_MAX, (gid_t *)-1) == -1); +#else + ATF_REQUIRE(getgroups(10, (gid_t *)-1) == -1); +#endif ATF_REQUIRE(errno == EFAULT); errno = 0; diff --git a/src/regress/lib/libc/sys/t_getitimer.c b/src/regress/lib/libc/sys/t_getitimer.c index fbf9c28ccc..9e5bd792ed 100644 --- a/src/regress/lib/libc/sys/t_getitimer.c +++ b/src/regress/lib/libc/sys/t_getitimer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: t_getitimer.c,v 1.2 2019/11/22 15:59:53 bluhm Exp $ */ +/* $OpenBSD: t_getitimer.c,v 1.3 2020/11/09 23:18:51 bluhm Exp $ */ /* $NetBSD: t_getitimer.c,v 1.3 2019/07/13 12:44:02 gson Exp $ */ /*- @@ -33,7 +33,7 @@ #include "macros.h" #include -__RCSID("$NetBSD: t_getitimer.c,v 1.2 2012/03/22 18:20:46 christos Exp $"); +__RCSID("$NetBSD: t_getitimer.c,v 1.3 2019/07/13 12:44:02 gson Exp $"); #include diff --git a/src/regress/lib/libc/sys/t_getrusage.c b/src/regress/lib/libc/sys/t_getrusage.c index 481d73431b..316377f8ce 100644 --- a/src/regress/lib/libc/sys/t_getrusage.c +++ b/src/regress/lib/libc/sys/t_getrusage.c @@ -1,4 +1,4 @@ -/* $OpenBSD: t_getrusage.c,v 1.1.1.1 2019/11/19 19:57:03 bluhm Exp $ */ +/* $OpenBSD: t_getrusage.c,v 1.2 2020/11/09 23:18:51 bluhm Exp $ */ /* $NetBSD: t_getrusage.c,v 1.8 2018/05/09 08:45:03 mrg Exp $ */ /*- @@ -208,6 +208,9 @@ ATF_TC_BODY(getrusage_utime_back, tc) /* * Test that two consecutive calls are sane. */ +#ifndef __OpenBSD__ + atf_tc_expect_fail("PR kern/30115"); +#endif for (i = 0; i < maxiter; i++) { @@ -225,6 +228,10 @@ ATF_TC_BODY(getrusage_utime_back, tc) if (timercmp(&ru2.ru_utime, &ru1.ru_utime, <) != 0) atf_tc_fail("user time went backwards"); } + +#ifndef __OpenBSD__ + atf_tc_fail("anticipated error did not occur"); +#endif } ATF_TC(getrusage_utime_zero); @@ -241,18 +248,31 @@ ATF_TC_BODY(getrusage_utime_zero, tc) /* * Test that getrusage(2) does not return * zero user time for the calling process. + * + * See also (duplicate) PR port-amd64/41734. */ +#ifndef __OpenBSD__ + atf_tc_expect_fail("PR kern/30115"); +#endif for (i = 0; i < maxiter; i++) { + work(); +#ifdef __OpenBSD__ } +#endif - (void)memset(&ru, 0, sizeof(struct rusage)); + (void)memset(&ru, 0, sizeof(struct rusage)); - ATF_REQUIRE(getrusage(RUSAGE_SELF, &ru) == 0); + ATF_REQUIRE(getrusage(RUSAGE_SELF, &ru) == 0); - if (ru.ru_utime.tv_sec == 0 && ru.ru_utime.tv_usec == 0) - atf_tc_fail("zero user time from getrusage(2)"); + if (ru.ru_utime.tv_sec == 0 && ru.ru_utime.tv_usec == 0) + atf_tc_fail("zero user time from getrusage(2)"); +#ifndef __OpenBSD__ + } + + atf_tc_fail("anticipated error did not occur"); +#endif } ATF_TP_ADD_TCS(tp) diff --git a/src/regress/lib/libc/sys/t_gettimeofday.c b/src/regress/lib/libc/sys/t_gettimeofday.c index ec4a72c63e..bb716ffdcc 100644 --- a/src/regress/lib/libc/sys/t_gettimeofday.c +++ b/src/regress/lib/libc/sys/t_gettimeofday.c @@ -1,4 +1,4 @@ -/* $OpenBSD: t_gettimeofday.c,v 1.2 2020/10/21 16:26:28 kettenis Exp $ */ +/* $OpenBSD: t_gettimeofday.c,v 1.3 2020/11/09 23:18:51 bluhm Exp $ */ /* $NetBSD: t_gettimeofday.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $ */ /*- @@ -41,6 +41,7 @@ __RCSID("$NetBSD: t_gettimeofday.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $"); #include #include +#ifdef __OpenBSD__ static void sighandler(int); static void @@ -48,6 +49,7 @@ sighandler(int signo) { _exit(0); } +#endif ATF_TC(gettimeofday_err); ATF_TC_HEAD(gettimeofday_err, tc) @@ -58,14 +60,16 @@ ATF_TC_HEAD(gettimeofday_err, tc) ATF_TC_BODY(gettimeofday_err, tc) { +#ifdef __OpenBSD__ /* * With userland timecounters we will generate SIGSEGV instead - * of failing with errno so to EFAULT. POSIX explicitly + * of failing with errno set to EFAULT. POSIX explicitly * allows this behaviour. */ ATF_REQUIRE(signal(SIGSEGV, sighandler) != SIG_ERR); - +#endif errno = 0; + ATF_REQUIRE_ERRNO(EFAULT, gettimeofday((void *)-1, NULL) != 0); } diff --git a/src/regress/lib/libc/sys/t_mknod.c b/src/regress/lib/libc/sys/t_mknod.c index 0a16124859..b1e412cb68 100644 --- a/src/regress/lib/libc/sys/t_mknod.c +++ b/src/regress/lib/libc/sys/t_mknod.c @@ -1,4 +1,4 @@ -/* $OpenBSD: t_mknod.c,v 1.1.1.1 2019/11/19 19:57:03 bluhm Exp $ */ +/* $OpenBSD: t_mknod.c,v 1.2 2020/11/09 23:18:51 bluhm Exp $ */ /* $NetBSD: t_mknod.c,v 1.2 2012/03/18 07:00:52 jruoho Exp $ */ /*- @@ -170,16 +170,16 @@ ATF_TC_BODY(mknod_stat, tc) (void)memset(&st, 0, sizeof(struct stat)); - /* - * Adjusted for OpenBSD, only supports FIFO and device special files - * ATF_REQUIRE(mknod(path, S_IFREG, 0) == 0); - * ATF_REQUIRE(stat(path, &st) == 0); - * - * if (S_ISREG(st.st_mode) == 0) - * atf_tc_fail_nonfatal("invalid mode from mknod(2) (S_IFREG)"); - * - * ATF_REQUIRE(unlink(path) == 0); - */ +#ifndef __OpenBSD__ + /* OpenBSD only supports FIFO and device special files */ + ATF_REQUIRE(mknod(path, S_IFREG, 0) == 0); + ATF_REQUIRE(stat(path, &st) == 0); + + if (S_ISREG(st.st_mode) == 0) + atf_tc_fail_nonfatal("invalid mode from mknod(2) (S_IFREG)"); + + ATF_REQUIRE(unlink(path) == 0); +#endif } ATF_TC_CLEANUP(mknod_stat, tc) diff --git a/src/regress/lib/libc/sys/t_mlock.c b/src/regress/lib/libc/sys/t_mlock.c index 1fd986383d..e41f52443c 100644 --- a/src/regress/lib/libc/sys/t_mlock.c +++ b/src/regress/lib/libc/sys/t_mlock.c @@ -1,5 +1,5 @@ -/* $OpenBSD: t_mlock.c,v 1.1.1.1 2019/11/19 19:57:04 bluhm Exp $ */ -/* $NetBSD: t_mlock.c,v 1.7 2019/03/13 08:50:12 kre Exp $ */ +/* $OpenBSD: t_mlock.c,v 1.2 2020/11/09 23:18:51 bluhm Exp $ */ +/* $NetBSD: t_mlock.c,v 1.8 2020/01/24 08:45:16 skrll Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -33,7 +33,7 @@ #include "macros.h" #include -__RCSID("$NetBSD: t_mlock.c,v 1.7 2019/03/13 08:50:12 kre Exp $"); +__RCSID("$NetBSD: t_mlock.c,v 1.8 2020/01/24 08:45:16 skrll Exp $"); #include #include @@ -108,8 +108,11 @@ ATF_TC_BODY(mlock_err, tc) ATF_REQUIRE_ERRNO(ENOMEM, mlock((char *)0, page) == -1); errno = 0; - /* Adjusted for OpenBSD, initially ENOMEM */ +#ifdef __OpenBSD__ ATF_REQUIRE_ERRNO(EINVAL, mlock((char *)-1, page) == -1); +#else + ATF_REQUIRE_ERRNO(ENOMEM, mlock((char *)-1, page) == -1); +#endif errno = 0; ATF_REQUIRE_ERRNO(ENOMEM, munlock(NULL, page) == -1); @@ -118,8 +121,11 @@ ATF_TC_BODY(mlock_err, tc) ATF_REQUIRE_ERRNO(ENOMEM, munlock((char *)0, page) == -1); errno = 0; - /* Adjusted for OpenBSD, initially ENOMEM */ +#ifdef __OpenBSD__ ATF_REQUIRE_ERRNO(EINVAL, munlock((char *)-1, page) == -1); +#else + ATF_REQUIRE_ERRNO(ENOMEM, munlock((char *)-1, page) == -1); +#endif buf = malloc(page); ATF_REQUIRE(buf != NULL); @@ -129,11 +135,10 @@ ATF_TC_BODY(mlock_err, tc) * unlocking memory that is not locked is an error... */ - /* - * Adjusted for OpenBSD - * errno = 0; - * ATF_REQUIRE_ERRNO(ENOMEM, munlock(buf, page) == -1); - */ +#ifndef __OpenBSD__ + errno = 0; + ATF_REQUIRE_ERRNO(ENOMEM, munlock(buf, page) == -1); +#endif /* * These are permitted to fail (EINVAL) but do not on NetBSD @@ -229,8 +234,11 @@ ATF_TC_HEAD(mlock_mmap, tc) ATF_TC_BODY(mlock_mmap, tc) { - /* Adjusted for OpenBSD, initially ... | MAP_WIRED */ +#ifdef __OpenBSD__ static const int flags = MAP_ANON | MAP_PRIVATE; +#else + static const int flags = MAP_ANON | MAP_PRIVATE | MAP_WIRED; +#endif void *buf; /* @@ -312,7 +320,6 @@ ATF_TP_ADD_TCS(tp) { page = sysconf(_SC_PAGESIZE); - fprintf(stderr, "t_mlock: pagesize %ld\n", page); ATF_REQUIRE(page >= 0); ATF_TP_ADD_TC(tp, mlock_clip); diff --git a/src/regress/lib/libc/sys/t_mmap.c b/src/regress/lib/libc/sys/t_mmap.c index 6dbfae5bb1..9da88fa9cc 100644 --- a/src/regress/lib/libc/sys/t_mmap.c +++ b/src/regress/lib/libc/sys/t_mmap.c @@ -1,5 +1,5 @@ -/* $OpenBSD: t_mmap.c,v 1.1.1.1 2019/11/19 19:57:04 bluhm Exp $ */ -/* $NetBSD: t_mmap.c,v 1.13 2017/05/23 13:04:29 christos Exp $ */ +/* $OpenBSD: t_mmap.c,v 1.2 2020/11/09 23:18:51 bluhm Exp $ */ +/* $NetBSD: t_mmap.c,v 1.14 2020/06/26 07:50:11 jruoho Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -59,7 +59,7 @@ #include "macros.h" #include -__RCSID("$NetBSD: t_mmap.c,v 1.13 2017/05/23 13:04:29 christos Exp $"); +__RCSID("$NetBSD: t_mmap.c,v 1.14 2020/06/26 07:50:11 jruoho Exp $"); #include #include @@ -175,7 +175,8 @@ ATF_TC_BODY(mmap_block, tc) size_t len; int fd = -1; - atf_tc_skip("The test case causes a panic (PR kern/38889, kern/46592)"); + atf_tc_skip("The test case causes a panic " \ + "(PR kern/38889, PR kern/46592)"); ATF_REQUIRE(sysctl(mib, miblen, NULL, &len, NULL, 0) == 0); drives = malloc(len); @@ -575,10 +576,10 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, mmap_prot_3); ATF_TP_ADD_TC(tp, mmap_truncate); ATF_TP_ADD_TC(tp, mmap_truncate_signal); - /* - * Adjusted for OpenBSD, not available - * ATF_TP_ADD_TC(tp, mmap_va0); - */ +#ifndef __OpenBSD__ + /* sysctl vm.user_va0_disable not available */ + ATF_TP_ADD_TC(tp, mmap_va0); +#endif return atf_no_error(); } diff --git a/src/regress/lib/libc/sys/t_msgget.c b/src/regress/lib/libc/sys/t_msgget.c index 2a9bb4cf3b..c5b7d97e15 100644 --- a/src/regress/lib/libc/sys/t_msgget.c +++ b/src/regress/lib/libc/sys/t_msgget.c @@ -1,4 +1,4 @@ -/* $OpenBSD: t_msgget.c,v 1.1.1.1 2019/11/19 19:57:04 bluhm Exp $ */ +/* $OpenBSD: t_msgget.c,v 1.2 2020/11/09 23:18:51 bluhm Exp $ */ /* $NetBSD: t_msgget.c,v 1.3 2017/10/08 08:31:05 kre Exp $ */ /*- @@ -328,10 +328,10 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, msgget_excl); ATF_TP_ADD_TC(tp, msgget_exit); ATF_TP_ADD_TC(tp, msgget_init); - /* - * Adjusted for OpenBSD, not available - * ATF_TP_ADD_TC(tp, msgget_limit); - */ +#ifndef __OpenBSD__ + /* sysctl kern.ipc.msgmni not available */ + ATF_TP_ADD_TC(tp, msgget_limit); +#endif ATF_TP_ADD_TC(tp, msgget_mode); } diff --git a/src/regress/lib/libc/sys/t_pipe.c b/src/regress/lib/libc/sys/t_pipe.c index bd9805a4b9..2fcb6d4b13 100644 --- a/src/regress/lib/libc/sys/t_pipe.c +++ b/src/regress/lib/libc/sys/t_pipe.c @@ -1,5 +1,5 @@ -/* $OpenBSD: t_pipe.c,v 1.1.1.1 2019/11/19 19:57:04 bluhm Exp $ */ -/* $NetBSD: t_pipe.c,v 1.5 2017/01/13 21:30:41 christos Exp $ */ +/* $OpenBSD: t_pipe.c,v 1.2 2020/11/09 23:18:51 bluhm Exp $ */ +/* $NetBSD: t_pipe.c,v 1.7 2020/06/26 07:50:11 jruoho Exp $ */ /*- * Copyright (c) 2001, 2008 The NetBSD Foundation, Inc. @@ -33,7 +33,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_pipe.c,v 1.5 2017/01/13 21:30:41 christos Exp $"); +__RCSID("$NetBSD: t_pipe.c,v 1.7 2020/06/26 07:50:11 jruoho Exp $"); #include #include @@ -74,7 +74,7 @@ ATF_TC_HEAD(pipe_restart, tc) { atf_tc_set_md_var(tc, "descr", "Checks that writing to pipe " "works correctly after being interrupted and restarted " - "(kern/14087)"); + "(PR kern/14087)"); } ATF_TC_BODY(pipe_restart, tc) @@ -103,7 +103,7 @@ ATF_TC_BODY(pipe_restart, tc) /* child */ RL(close(pp[1])); - /* Do inital write. This should succeed, make + /* Do initial write. This should succeed, make * the other side do partial write and wait for us to pick * rest up. */ diff --git a/src/regress/lib/libc/sys/t_pipe2.c b/src/regress/lib/libc/sys/t_pipe2.c index 4964be14ce..07991de455 100644 --- a/src/regress/lib/libc/sys/t_pipe2.c +++ b/src/regress/lib/libc/sys/t_pipe2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: t_pipe2.c,v 1.1.1.1 2019/11/19 19:57:04 bluhm Exp $ */ +/* $OpenBSD: t_pipe2.c,v 1.2 2020/11/09 23:18:51 bluhm Exp $ */ /* $NetBSD: t_pipe2.c,v 1.9 2017/01/13 21:19:45 christos Exp $ */ /*- @@ -81,16 +81,16 @@ run(int flags) ATF_REQUIRE((fcntl(fd[1], F_GETFL) & O_NONBLOCK) == 0); } - /* - * Adjusted for OpenBSD, not available - * if (flags & O_NOSIGPIPE) { - * ATF_REQUIRE(fcntl(fd[0], F_GETNOSIGPIPE) != 0); - * ATF_REQUIRE(fcntl(fd[1], F_GETNOSIGPIPE) != 0); - *} else { - * ATF_REQUIRE(fcntl(fd[0], F_GETNOSIGPIPE) == 0); - * ATF_REQUIRE(fcntl(fd[1], F_GETNOSIGPIPE) == 0); - *} - */ +#ifndef __OpenBSD__ + /* F_GETNOSIGPIPE not available */ + if (flags & O_NOSIGPIPE) { + ATF_REQUIRE(fcntl(fd[0], F_GETNOSIGPIPE) != 0); + ATF_REQUIRE(fcntl(fd[1], F_GETNOSIGPIPE) != 0); + } else { + ATF_REQUIRE(fcntl(fd[0], F_GETNOSIGPIPE) == 0); + ATF_REQUIRE(fcntl(fd[1], F_GETNOSIGPIPE) == 0); + } +#endif ATF_REQUIRE(close(fd[0]) != -1); ATF_REQUIRE(close(fd[1]) != -1); @@ -193,10 +193,10 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, pipe2_consume); ATF_TP_ADD_TC(tp, pipe2_nonblock); ATF_TP_ADD_TC(tp, pipe2_cloexec); - /* - * Adjusted for OpenBSD, not available - * ATF_TP_ADD_TC(tp, pipe2_nosigpipe); - */ +#ifndef __OpenBSD__ + /* O_NOSIGPIPE not available */ + ATF_TP_ADD_TC(tp, pipe2_nosigpipe); +#endif ATF_TP_ADD_TC(tp, pipe2_einval); return atf_no_error(); diff --git a/src/regress/lib/libc/sys/t_poll.c b/src/regress/lib/libc/sys/t_poll.c index bbb8dc2d14..d27fbf159f 100644 --- a/src/regress/lib/libc/sys/t_poll.c +++ b/src/regress/lib/libc/sys/t_poll.c @@ -1,5 +1,5 @@ -/* $OpenBSD: t_poll.c,v 1.1.1.1 2019/11/19 19:57:04 bluhm Exp $ */ -/* $NetBSD: t_poll.c,v 1.3 2012/03/18 07:00:52 jruoho Exp $ */ +/* $OpenBSD: t_poll.c,v 1.2 2020/11/09 23:18:51 bluhm Exp $ */ +/* $NetBSD: t_poll.c,v 1.4 2020/07/17 15:34:16 kamil Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -85,8 +85,8 @@ child3(void) (void)printf("child3 exit\n"); } -ATF_TC(poll_3way); -ATF_TC_HEAD(poll_3way, tc) +ATF_TC(3way); +ATF_TC_HEAD(3way, tc) { atf_tc_set_md_var(tc, "timeout", "15"); atf_tc_set_md_var(tc, "descr", @@ -97,7 +97,7 @@ ATF_TC_HEAD(poll_3way, tc) "both be awaken. (kern/17517)"); } -ATF_TC_BODY(poll_3way, tc) +ATF_TC_BODY(3way, tc) { int pf[2]; int status, i; @@ -148,15 +148,15 @@ ATF_TC_BODY(poll_3way, tc) (void)printf("parent terminated\n"); } -ATF_TC(poll_basic); -ATF_TC_HEAD(poll_basic, tc) +ATF_TC(basic); +ATF_TC_HEAD(basic, tc) { atf_tc_set_md_var(tc, "timeout", "10"); atf_tc_set_md_var(tc, "descr", "Basis functionality test for poll(2)"); } -ATF_TC_BODY(poll_basic, tc) +ATF_TC_BODY(basic, tc) { int fds[2]; struct pollfd pfds[2]; @@ -215,13 +215,13 @@ ATF_TC_BODY(poll_basic, tc) ATF_REQUIRE_EQ(close(fds[1]), 0); } -ATF_TC(poll_err); -ATF_TC_HEAD(poll_err, tc) +ATF_TC(err); +ATF_TC_HEAD(err, tc) { atf_tc_set_md_var(tc, "descr", "Check errors from poll(2)"); } -ATF_TC_BODY(poll_err, tc) +ATF_TC_BODY(err, tc) { struct pollfd pfd; int fd = 0; @@ -236,163 +236,12 @@ ATF_TC_BODY(poll_err, tc) ATF_REQUIRE_ERRNO(EINVAL, poll(&pfd, 1, -2) == -1); } -ATF_TC(pollts_basic); -ATF_TC_HEAD(pollts_basic, tc) -{ - atf_tc_set_md_var(tc, "timeout", "10"); - atf_tc_set_md_var(tc, "descr", - "Basis functionality test for pollts(2)"); -} - -ATF_TC_BODY(pollts_basic, tc) -{ - int fds[2]; - struct pollfd pfds[2]; - struct timespec timeout; - int ret; - - ATF_REQUIRE_EQ(pipe(fds), 0); - - pfds[0].fd = fds[0]; - pfds[0].events = POLLIN; - pfds[1].fd = fds[1]; - pfds[1].events = POLLOUT; - - /* Use a timeout of 1 second. */ - timeout.tv_sec = 1; - timeout.tv_nsec = 0; - - /* - * Check that we get a timeout waiting for data on the read end - * of our pipe. - */ - pfds[0].revents = -1; - pfds[1].revents = -1; - ATF_REQUIRE_EQ_MSG(ret = pollts(&pfds[0], 1, &timeout, NULL), 0, - "got: %d", ret); - ATF_REQUIRE_EQ_MSG(pfds[0].revents, 0, "got: %d", pfds[0].revents); - ATF_REQUIRE_EQ_MSG(pfds[1].revents, -1, "got: %d", pfds[1].revents); - - /* Check that the write end of the pipe as reported as ready. */ - pfds[0].revents = -1; - pfds[1].revents = -1; - ATF_REQUIRE_EQ_MSG(ret = pollts(&pfds[1], 1, &timeout, NULL), 1, - "got: %d", ret); - ATF_REQUIRE_EQ_MSG(pfds[0].revents, -1, "got: %d", pfds[0].revents); - ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d",\ - pfds[1].revents); - - /* Check that only the write end of the pipe as reported as ready. */ - pfds[0].revents = -1; - pfds[1].revents = -1; - ATF_REQUIRE_EQ_MSG(ret = pollts(pfds, 2, &timeout, NULL), 1, - "got: %d", ret); - ATF_REQUIRE_EQ_MSG(pfds[0].revents, 0, "got: %d", pfds[0].revents); - ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d", - pfds[1].revents); - - /* Write data to our pipe. */ - ATF_REQUIRE_EQ(write(fds[1], "", 1), 1); - - /* Check that both ends of our pipe are reported as ready. */ - pfds[0].revents = -1; - pfds[1].revents = -1; - ATF_REQUIRE_EQ_MSG(ret = pollts(pfds, 2, &timeout, NULL), 2, - "got: %d", ret); - ATF_REQUIRE_EQ_MSG(pfds[0].revents, POLLIN, "got: %d", - pfds[0].revents); - ATF_REQUIRE_EQ_MSG(pfds[1].revents, POLLOUT, "got: %d", - pfds[1].revents); - - ATF_REQUIRE_EQ(close(fds[0]), 0); - ATF_REQUIRE_EQ(close(fds[1]), 0); -} - -ATF_TC(pollts_err); -ATF_TC_HEAD(pollts_err, tc) -{ - atf_tc_set_md_var(tc, "descr", "Check errors from pollts(2)"); -} - -ATF_TC_BODY(pollts_err, tc) -{ - struct timespec timeout; - struct pollfd pfd; - int fd = 0; - - pfd.fd = fd; - pfd.events = POLLIN; - - timeout.tv_sec = 1; - timeout.tv_nsec = 0; - - errno = 0; - ATF_REQUIRE_ERRNO(EFAULT, pollts((void *)-1, 1, &timeout, NULL) == -1); - - timeout.tv_sec = -1; - timeout.tv_nsec = -1; - - errno = 0; - ATF_REQUIRE_ERRNO(EINVAL, pollts(&pfd, 1, &timeout, NULL) == -1); -} - -ATF_TC(pollts_sigmask); -ATF_TC_HEAD(pollts_sigmask, tc) -{ - atf_tc_set_md_var(tc, "timeout", "10"); - atf_tc_set_md_var(tc, "descr", - "Check that pollts(2) restores the signal mask (PR kern/44986)"); -} - -ATF_TC_BODY(pollts_sigmask, tc) -{ - int fd; - struct pollfd pfd; - struct timespec timeout; - sigset_t mask; - int ret; - - fd = open(_PATH_DEVNULL, O_RDONLY); - ATF_REQUIRE(fd >= 0); - - pfd.fd = fd; - pfd.events = POLLIN; - - /* Use a timeout of 1 second. */ - timeout.tv_sec = 1; - timeout.tv_nsec = 0; - - /* Unblock all signals. */ - ATF_REQUIRE_EQ(sigfillset(&mask), 0); - ATF_REQUIRE_EQ(sigprocmask(SIG_UNBLOCK, &mask, NULL), 0); - - /* - * Check that pollts(2) immediately returns. We block *all* - * signals during pollts(2). - */ - ATF_REQUIRE_EQ_MSG(ret = pollts(&pfd, 1, &timeout, &mask), 1, - "got: %d", ret); - - /* Check that signals are now longer blocked. */ - ATF_REQUIRE_EQ(sigprocmask(SIG_SETMASK, NULL, &mask), 0); - ATF_REQUIRE_EQ_MSG(sigismember(&mask, SIGUSR1), 0, - "signal mask was changed."); - - ATF_REQUIRE_EQ(close(fd), 0); -} - ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, poll_3way); - ATF_TP_ADD_TC(tp, poll_basic); - ATF_TP_ADD_TC(tp, poll_err); - /* - * Adjusted for OpenBSD, not supported - * ATF_TP_ADD_TC(tp, pollts_basic); - * ATF_TP_ADD_TC(tp, pollts_err); - * ATF_TP_ADD_TC(tp, pollts_sigmask); - */ + ATF_TP_ADD_TC(tp, 3way); + ATF_TP_ADD_TC(tp, basic); + ATF_TP_ADD_TC(tp, err); return atf_no_error(); } diff --git a/src/regress/lib/libc/sys/t_ptrace.c b/src/regress/lib/libc/sys/t_ptrace.c index e651dec0a1..a48616efb2 100644 --- a/src/regress/lib/libc/sys/t_ptrace.c +++ b/src/regress/lib/libc/sys/t_ptrace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: t_ptrace.c,v 1.3 2020/02/02 20:18:17 bluhm Exp $ */ +/* $OpenBSD: t_ptrace.c,v 1.4 2020/11/09 23:18:51 bluhm Exp $ */ /* $NetBSD: t_ptrace.c,v 1.4 2018/05/14 12:44:40 kamil Exp $ */ /*- @@ -171,7 +171,11 @@ ATF_TC_BODY(attach_chroot, tc) rv = write(fds_toparent[1], &msg, sizeof(msg)); FORKEE_ASSERTX(rv == sizeof(msg)); +#ifdef __OpenBSD__ ATF_REQUIRE_ERRNO(EINVAL, +#else + ATF_REQUIRE_ERRNO(EPERM, +#endif ptrace(PT_ATTACH, getppid(), NULL, 0) == -1); rv = read(fds_fromparent[0], &msg, sizeof(msg)); diff --git a/src/regress/lib/libc/sys/t_revoke.c b/src/regress/lib/libc/sys/t_revoke.c index ad54f814d1..7640c2d871 100644 --- a/src/regress/lib/libc/sys/t_revoke.c +++ b/src/regress/lib/libc/sys/t_revoke.c @@ -1,4 +1,4 @@ -/* $OpenBSD: t_revoke.c,v 1.1.1.1 2019/11/19 19:57:04 bluhm Exp $ */ +/* $OpenBSD: t_revoke.c,v 1.2 2020/11/09 23:18:51 bluhm Exp $ */ /* $NetBSD: t_revoke.c,v 1.2 2017/01/13 21:15:57 christos Exp $ */ /*- @@ -118,8 +118,11 @@ ATF_TC_BODY(revoke_err, tc) ATF_REQUIRE_ERRNO(ENAMETOOLONG, revoke(buf) == -1); errno = 0; - /* Adjusted for OpenBSD, initially EPERM */ +#ifdef __OpenBSD__ ATF_REQUIRE_ERRNO(ENOTTY, revoke("/etc/passwd") == -1); +#else + ATF_REQUIRE_ERRNO(EPERM, revoke("/etc/passwd") == -1); +#endif errno = 0; ATF_REQUIRE_ERRNO(ENOENT, revoke("/etc/xxx/yyy") == -1); @@ -184,15 +187,15 @@ ATF_TC_CLEANUP(revoke_perm, tc) ATF_TP_ADD_TCS(tp) { - /* - * Adjusted for OpenBSD, revoke only on ttys supported - * ATF_TP_ADD_TC(tp, revoke_basic); - */ +#ifndef __OpenBSD__ + /* OpenBSD supports revoke only on ttys */ + ATF_TP_ADD_TC(tp, revoke_basic); +#endif ATF_TP_ADD_TC(tp, revoke_err); - /* - * Adjusted for OpenBSD, revoke only on ttys supported - * ATF_TP_ADD_TC(tp, revoke_perm); - */ +#ifndef __OpenBSD__ + /* OpenBSD supports revoke only on ttys */ + ATF_TP_ADD_TC(tp, revoke_perm); +#endif return atf_no_error(); } diff --git a/src/regress/lib/libc/sys/t_select.c b/src/regress/lib/libc/sys/t_select.c index 94ff3d3410..b10fe87495 100644 --- a/src/regress/lib/libc/sys/t_select.c +++ b/src/regress/lib/libc/sys/t_select.c @@ -1,4 +1,4 @@ -/* $OpenBSD: t_select.c,v 1.1.1.1 2019/11/19 19:57:04 bluhm Exp $ */ +/* $OpenBSD: t_select.c,v 1.2 2020/11/09 23:18:51 bluhm Exp $ */ /* $NetBSD: t_select.c,v 1.4 2017/01/13 21:18:33 christos Exp $ */ /*- @@ -76,10 +76,18 @@ prmask(const sigset_t *m, char *buf, size_t len) buf[0] = '0'; buf[1] = 'x'; #define N(p, a) (((p) >> ((a) * 4)) & 0xf) - /* Adjusted for OpenBSD, on NetBSD sigset_t is a struct */ +#ifdef __OpenBSD__ + /* On NetBSD sigset_t is a struct */ uint32_t p = (*m); for (size_t k = sizeof(p); k > 0; k--) buf[j++] = xtoa(N(p, k - 1)); +#else + for (size_t i = __arraycount(m->__bits); i > 0; i--) { + uint32_t p = m->__bits[i - 1]; + for (size_t k = sizeof(p); k > 0; k--) + buf[j++] = xtoa(N(p, k - 1)); + } +#endif buf[j] = '\0'; return buf; } diff --git a/src/regress/lib/libc/sys/t_stat.c b/src/regress/lib/libc/sys/t_stat.c index 73350c0e6a..5aadf39b99 100644 --- a/src/regress/lib/libc/sys/t_stat.c +++ b/src/regress/lib/libc/sys/t_stat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: t_stat.c,v 1.2 2019/11/22 15:59:53 bluhm Exp $ */ +/* $OpenBSD: t_stat.c,v 1.3 2020/11/09 23:18:51 bluhm Exp $ */ /* $NetBSD: t_stat.c,v 1.6 2019/07/16 17:29:18 martin Exp $ */ /*- @@ -68,7 +68,7 @@ ATF_TC_BODY(stat_chflags, tc) (void)memset(&sa, 0, sizeof(struct stat)); (void)memset(&sb, 0, sizeof(struct stat)); - fd = open(path, O_RDONLY | O_CREAT); + fd = open(path, O_RDONLY | O_CREAT, 0600); ATF_REQUIRE(fd != -1); ATF_REQUIRE(stat(path, &sa) == 0); @@ -258,7 +258,7 @@ ATF_TC_BODY(stat_perm, tc) uid = getuid(); gid = getgid(); - fd = open(path, O_RDONLY | O_CREAT); + fd = open(path, O_RDONLY | O_CREAT, 0600); ATF_REQUIRE(fd != -1); ATF_REQUIRE(fstat(fd, &sa) == 0); diff --git a/src/regress/lib/libc/sys/t_write.c b/src/regress/lib/libc/sys/t_write.c index f05edb5bed..326032db71 100644 --- a/src/regress/lib/libc/sys/t_write.c +++ b/src/regress/lib/libc/sys/t_write.c @@ -1,4 +1,4 @@ -/* $OpenBSD: t_write.c,v 1.2 2019/11/22 15:59:53 bluhm Exp $ */ +/* $OpenBSD: t_write.c,v 1.3 2020/11/09 23:18:51 bluhm Exp $ */ /* $NetBSD: t_write.c,v 1.7 2019/07/16 17:29:18 martin Exp $ */ /*- @@ -74,7 +74,7 @@ ATF_TC_BODY(write_err, tc) errno = 0; ATF_REQUIRE_ERRNO(EBADF, write(-1, wbuf, sizeof(wbuf)) == -1); - fd = open(path, O_RDWR | O_CREAT); + fd = open(path, O_RDWR | O_CREAT, 0600); if (fd >= 0) { @@ -146,7 +146,7 @@ ATF_TC_BODY(write_pos, tc) size_t i; int fd; - fd = open(path, O_RDWR | O_CREAT); + fd = open(path, O_RDWR | O_CREAT, 0600); ATF_REQUIRE(fd >= 0); for (i = 0; i < n; i++) { -- cgit v1.2.3-55-g6feb