summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests/lib/libc
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/netbsd-tests/lib/libc')
-rw-r--r--contrib/netbsd-tests/lib/libc/arch/ia64/return_one.S11
-rw-r--r--contrib/netbsd-tests/lib/libc/arch/powerpc/return_one.S5
-rw-r--r--contrib/netbsd-tests/lib/libc/arch/riscv/return_one.S4
-rw-r--r--contrib/netbsd-tests/lib/libc/arch/sparc64/exec_prot_support.c7
-rw-r--r--contrib/netbsd-tests/lib/libc/arch/sparc64/return_one.S11
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_faccessat.c10
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_fchmodat.c10
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_fchownat.c10
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_fexecve.c6
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_fstatat.c10
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_mkfifoat.c6
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_mknodat.c6
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_o_search.c9
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_openat.c10
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_readlinkat.c10
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_unlinkat.c10
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_utimensat.c9
-rw-r--r--contrib/netbsd-tests/lib/libc/db/h_db.c77
-rw-r--r--contrib/netbsd-tests/lib/libc/db/h_lfsr.c179
-rwxr-xr-xcontrib/netbsd-tests/lib/libc/db/t_db.sh442
-rw-r--r--contrib/netbsd-tests/lib/libc/db/t_db_hash_seq.c343
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/execve/t_execve.c5
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/isqemu.h28
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_fileactions.c10
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawn.c4
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c12
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/t_assert.c17
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/t_dir.c56
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/t_floatunditf.c5
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/t_fnmatch.c30
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/t_fpsetmask.c25
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/t_ftok.c6
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/t_humanize_number.c3
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/t_nice.c7
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/t_randomid.c22
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/t_siginfo.c25
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/t_sleep.c24
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/t_time.c17
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/t_ttyname.c6
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/t_vis.c37
-rw-r--r--contrib/netbsd-tests/lib/libc/inet/t_inet_addr.c109
-rw-r--r--contrib/netbsd-tests/lib/libc/inet/t_inet_network.c68
-rwxr-xr-xcontrib/netbsd-tests/lib/libc/net/t_servent.sh4
-rw-r--r--contrib/netbsd-tests/lib/libc/rpc/t_rpc.c296
-rw-r--r--contrib/netbsd-tests/lib/libc/setjmp/t_setjmp.c2
-rw-r--r--contrib/netbsd-tests/lib/libc/setjmp/t_threadjmp.c2
-rwxr-xr-xcontrib/netbsd-tests/lib/libc/ssp/t_ssp.sh3
-rw-r--r--contrib/netbsd-tests/lib/libc/stdio/t_open_memstream.c96
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_getenv.c6
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_posix_memalign.c75
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_strtod.c14
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_strtoi.c304
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_strtol.c13
-rw-r--r--contrib/netbsd-tests/lib/libc/string/t_memcpy.c6
-rw-r--r--contrib/netbsd-tests/lib/libc/string/t_memmem.c7
-rw-r--r--contrib/netbsd-tests/lib/libc/string/t_memset.c52
-rw-r--r--contrib/netbsd-tests/lib/libc/string/t_strchr.c12
-rw-r--r--contrib/netbsd-tests/lib/libc/string/t_strerror.c9
-rw-r--r--contrib/netbsd-tests/lib/libc/sync/cpp_atomic_ops_linkable.cc107
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_access.c19
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_bind.c78
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_chroot.c9
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_clock_nanosleep.c63
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_connect.c31
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_getcontext.c12
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_getrusage.c10
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_getsockname.c82
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_kevent.c14
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_mincore.c9
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_mlock.c116
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_mmap.c89
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_mprotect.c17
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_posix_fallocate.c63
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c50
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c155
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_timer_create.c119
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_wait.c323
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_wait_noproc.c345
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_wait_noproc_wnohang.c30
-rw-r--r--contrib/netbsd-tests/lib/libc/t_cdb.c7
-rw-r--r--contrib/netbsd-tests/lib/libc/time/t_strptime.c257
81 files changed, 4074 insertions, 533 deletions
diff --git a/contrib/netbsd-tests/lib/libc/arch/ia64/return_one.S b/contrib/netbsd-tests/lib/libc/arch/ia64/return_one.S
index 5308876..5cb5f39 100644
--- a/contrib/netbsd-tests/lib/libc/arch/ia64/return_one.S
+++ b/contrib/netbsd-tests/lib/libc/arch/ia64/return_one.S
@@ -1,8 +1,11 @@
-/* $NetBSD: return_one.S,v 1.1 2011/07/18 23:16:09 jym Exp $ */
+/* $NetBSD: return_one.S,v 1.2 2016/08/05 15:02:29 scole Exp $ */
#include <machine/asm.h>
-.globl return_one, return_one_end;
+.globl return_one_end
-return_one: return_one_end:
- nop
+ENTRY(return_one,0)
+ mov ret0=1
+ br.ret.sptk.few rp
+return_one_end:
+END(return_one)
diff --git a/contrib/netbsd-tests/lib/libc/arch/powerpc/return_one.S b/contrib/netbsd-tests/lib/libc/arch/powerpc/return_one.S
index d40298e..10629c5 100644
--- a/contrib/netbsd-tests/lib/libc/arch/powerpc/return_one.S
+++ b/contrib/netbsd-tests/lib/libc/arch/powerpc/return_one.S
@@ -1,10 +1,11 @@
-/* $NetBSD: return_one.S,v 1.2 2012/03/16 08:51:47 matt Exp $ */
+/* $NetBSD: return_one.S,v 1.3 2015/03/29 00:38:36 matt Exp $ */
#include <machine/asm.h>
-.globl return_one, return_one_end
+.globl return_one_start, return_one_end
_ENTRY(return_one)
+return_one_start:
li %r3, 1
blr
return_one_end:
diff --git a/contrib/netbsd-tests/lib/libc/arch/riscv/return_one.S b/contrib/netbsd-tests/lib/libc/arch/riscv/return_one.S
index 43ddd2c..d393fd1 100644
--- a/contrib/netbsd-tests/lib/libc/arch/riscv/return_one.S
+++ b/contrib/netbsd-tests/lib/libc/arch/riscv/return_one.S
@@ -1,11 +1,11 @@
-/* $NetBSD: return_one.S,v 1.1 2014/09/19 17:36:26 matt Exp $ */
+/* $NetBSD: return_one.S,v 1.2 2015/03/28 07:07:54 matt Exp $ */
#include <machine/asm.h>
.globl return_one_end
ENTRY_NP(return_one)
- li v0, 1
+ li a0, 1
ret
return_one_end:
END(return_one)
diff --git a/contrib/netbsd-tests/lib/libc/arch/sparc64/exec_prot_support.c b/contrib/netbsd-tests/lib/libc/arch/sparc64/exec_prot_support.c
index 474cfc7..8ca38b4 100644
--- a/contrib/netbsd-tests/lib/libc/arch/sparc64/exec_prot_support.c
+++ b/contrib/netbsd-tests/lib/libc/arch/sparc64/exec_prot_support.c
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_prot_support.c,v 1.1 2011/07/18 23:16:10 jym Exp $ */
+/* $NetBSD: exec_prot_support.c,v 1.2 2016/12/31 11:51:20 martin Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -30,12 +30,13 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: exec_prot_support.c,v 1.1 2011/07/18 23:16:10 jym Exp $");
+__RCSID("$NetBSD: exec_prot_support.c,v 1.2 2016/12/31 11:51:20 martin Exp $");
#include "../../common/exec_prot.h"
int
exec_prot_support(void)
{
- return NOTIMPL;
+
+ return PERPAGE_XP;
}
diff --git a/contrib/netbsd-tests/lib/libc/arch/sparc64/return_one.S b/contrib/netbsd-tests/lib/libc/arch/sparc64/return_one.S
index 3495260..ec8bcdd 100644
--- a/contrib/netbsd-tests/lib/libc/arch/sparc64/return_one.S
+++ b/contrib/netbsd-tests/lib/libc/arch/sparc64/return_one.S
@@ -1,8 +1,11 @@
-/* $NetBSD: return_one.S,v 1.1 2011/07/18 23:16:10 jym Exp $ */
+/* $NetBSD: return_one.S,v 1.2 2016/12/31 11:51:20 martin Exp $ */
#include <machine/asm.h>
-.globl return_one, return_one_end;
+.global return_one_end
-return_one: return_one_end:
- nop
+ENTRY(return_one)
+return_one:
+ retl
+ mov 1, %o0
+return_one_end:
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_faccessat.c b/contrib/netbsd-tests/lib/libc/c063/t_faccessat.c
index 99235ea..7de4f61 100644
--- a/contrib/netbsd-tests/lib/libc/c063/t_faccessat.c
+++ b/contrib/netbsd-tests/lib/libc/c063/t_faccessat.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_faccessat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $ */
+/* $NetBSD: t_faccessat.c,v 1.3 2017/01/10 15:13:56 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,8 +29,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_faccessat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $");
+__RCSID("$NetBSD: t_faccessat.c,v 1.3 2017/01/10 15:13:56 christos Exp $");
+#include <sys/param.h>
+#include <sys/stat.h>
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
@@ -39,10 +41,6 @@ __RCSID("$NetBSD: t_faccessat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $");
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <sys/param.h>
-#ifdef __FreeBSD__
-#include <sys/stat.h>
-#endif
#define DIR "dir"
#define FILE "dir/faccessat"
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_fchmodat.c b/contrib/netbsd-tests/lib/libc/c063/t_fchmodat.c
index 6598059..a7bb683 100644
--- a/contrib/netbsd-tests/lib/libc/c063/t_fchmodat.c
+++ b/contrib/netbsd-tests/lib/libc/c063/t_fchmodat.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_fchmodat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $ */
+/* $NetBSD: t_fchmodat.c,v 1.3 2017/01/10 15:13:56 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,8 +29,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_fchmodat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $");
+__RCSID("$NetBSD: t_fchmodat.c,v 1.3 2017/01/10 15:13:56 christos Exp $");
+#include <sys/param.h>
+#include <sys/stat.h>
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
@@ -39,10 +41,6 @@ __RCSID("$NetBSD: t_fchmodat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $");
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <sys/param.h>
-#ifdef __FreeBSD__
-#include <sys/stat.h>
-#endif
#define DIR "dir"
#define FILE "dir/fchmodat"
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_fchownat.c b/contrib/netbsd-tests/lib/libc/c063/t_fchownat.c
index 2ca14cf..631d55a 100644
--- a/contrib/netbsd-tests/lib/libc/c063/t_fchownat.c
+++ b/contrib/netbsd-tests/lib/libc/c063/t_fchownat.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_fchownat.c,v 1.3 2013/03/17 04:46:06 jmmv Exp $ */
+/* $NetBSD: t_fchownat.c,v 1.4 2017/01/10 15:13:56 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,8 +29,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_fchownat.c,v 1.3 2013/03/17 04:46:06 jmmv Exp $");
+__RCSID("$NetBSD: t_fchownat.c,v 1.4 2017/01/10 15:13:56 christos Exp $");
+#include <sys/param.h>
+#include <sys/stat.h>
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
@@ -40,10 +42,6 @@ __RCSID("$NetBSD: t_fchownat.c,v 1.3 2013/03/17 04:46:06 jmmv Exp $");
#include <string.h>
#include <unistd.h>
#include <pwd.h>
-#include <sys/param.h>
-#ifdef __FreeBSD__
-#include <sys/stat.h>
-#endif
#define DIR "dir"
#define FILE "dir/fchownat"
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_fexecve.c b/contrib/netbsd-tests/lib/libc/c063/t_fexecve.c
index 30b26a7..b9aa017 100644
--- a/contrib/netbsd-tests/lib/libc/c063/t_fexecve.c
+++ b/contrib/netbsd-tests/lib/libc/c063/t_fexecve.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_fexecve.c,v 1.2 2013/03/17 04:35:59 jmmv Exp $ */
+/* $NetBSD: t_fexecve.c,v 1.3 2017/01/10 15:15:09 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_fexecve.c,v 1.2 2013/03/17 04:35:59 jmmv Exp $");
+__RCSID("$NetBSD: t_fexecve.c,v 1.3 2017/01/10 15:15:09 christos Exp $");
#include <sys/wait.h>
@@ -70,9 +70,7 @@ ATF_TC_BODY(fexecve, tc)
error = 76;
else
error = EXIT_FAILURE;
-#ifdef __FreeBSD__
(void)close(fd);
-#endif
err(error, "fexecve");
}
}
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_fstatat.c b/contrib/netbsd-tests/lib/libc/c063/t_fstatat.c
index b23f625..c17961f 100644
--- a/contrib/netbsd-tests/lib/libc/c063/t_fstatat.c
+++ b/contrib/netbsd-tests/lib/libc/c063/t_fstatat.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_fstatat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $ */
+/* $NetBSD: t_fstatat.c,v 1.3 2017/01/10 15:13:56 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,8 +29,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_fstatat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $");
+__RCSID("$NetBSD: t_fstatat.c,v 1.3 2017/01/10 15:13:56 christos Exp $");
+#include <sys/param.h>
+#include <sys/stat.h>
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
@@ -39,10 +41,6 @@ __RCSID("$NetBSD: t_fstatat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $");
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <sys/param.h>
-#ifdef __FreeBSD__
-#include <sys/stat.h>
-#endif
#define DIR "dir"
#define FILE "dir/fstatat"
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_mkfifoat.c b/contrib/netbsd-tests/lib/libc/c063/t_mkfifoat.c
index 3736dfa..5c496c8 100644
--- a/contrib/netbsd-tests/lib/libc/c063/t_mkfifoat.c
+++ b/contrib/netbsd-tests/lib/libc/c063/t_mkfifoat.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mkfifoat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $ */
+/* $NetBSD: t_mkfifoat.c,v 1.3 2017/01/10 15:15:09 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_mkfifoat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $");
+__RCSID("$NetBSD: t_mkfifoat.c,v 1.3 2017/01/10 15:15:09 christos Exp $");
#include <atf-c.h>
#include <errno.h>
@@ -63,9 +63,7 @@ ATF_TC_BODY(mkfifoat_fd, tc)
ATF_REQUIRE((fd = mkfifoat(dfd, BASEFIFO, mode)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(access(FIFO, F_OK) == 0);
-#ifdef __FreeBSD__
(void)close(dfd);
-#endif
}
ATF_TC(mkfifoat_fdcwd);
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_mknodat.c b/contrib/netbsd-tests/lib/libc/c063/t_mknodat.c
index e8f71cd..7c3ab9b 100644
--- a/contrib/netbsd-tests/lib/libc/c063/t_mknodat.c
+++ b/contrib/netbsd-tests/lib/libc/c063/t_mknodat.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mknodat.c,v 1.3 2013/03/17 04:46:06 jmmv Exp $ */
+/* $NetBSD: t_mknodat.c,v 1.4 2017/01/10 15:15:09 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_mknodat.c,v 1.3 2013/03/17 04:46:06 jmmv Exp $");
+__RCSID("$NetBSD: t_mknodat.c,v 1.4 2017/01/10 15:15:09 christos Exp $");
#include <atf-c.h>
#include <errno.h>
@@ -80,9 +80,7 @@ ATF_TC_BODY(mknodat_fd, tc)
ATF_REQUIRE((fd = mknodat(dfd, BASEFILE, mode, dev)) != -1);
ATF_REQUIRE(close(fd) == 0);
ATF_REQUIRE(access(FILE, F_OK) == 0);
-#ifdef __FreeBSD__
(void)close(dfd);
-#endif
}
ATF_TC(mknodat_fdcwd);
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_o_search.c b/contrib/netbsd-tests/lib/libc/c063/t_o_search.c
index d9dbe19..7cefa8b 100644
--- a/contrib/netbsd-tests/lib/libc/c063/t_o_search.c
+++ b/contrib/netbsd-tests/lib/libc/c063/t_o_search.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_o_search.c,v 1.4 2013/03/17 04:46:06 jmmv Exp $ */
+/* $NetBSD: t_o_search.c,v 1.5 2017/01/10 22:25:01 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,9 +29,13 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_o_search.c,v 1.4 2013/03/17 04:46:06 jmmv Exp $");
+__RCSID("$NetBSD: t_o_search.c,v 1.5 2017/01/10 22:25:01 christos Exp $");
#include <atf-c.h>
+
+#include <sys/param.h>
+#include <sys/stat.h>
+
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
@@ -40,7 +44,6 @@ __RCSID("$NetBSD: t_o_search.c,v 1.4 2013/03/17 04:46:06 jmmv Exp $");
#include <string.h>
#include <unistd.h>
#include <pwd.h>
-#include <sys/param.h>
/*
* dholland 20130112: disable tests that require O_SEARCH semantics
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_openat.c b/contrib/netbsd-tests/lib/libc/c063/t_openat.c
index 5112efc..f7c8c74 100644
--- a/contrib/netbsd-tests/lib/libc/c063/t_openat.c
+++ b/contrib/netbsd-tests/lib/libc/c063/t_openat.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_openat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $ */
+/* $NetBSD: t_openat.c,v 1.3 2017/01/10 15:13:56 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,8 +29,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_openat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $");
+__RCSID("$NetBSD: t_openat.c,v 1.3 2017/01/10 15:13:56 christos Exp $");
+#include <sys/param.h>
+#include <sys/stat.h>
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
@@ -39,10 +41,6 @@ __RCSID("$NetBSD: t_openat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $");
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <sys/param.h>
-#ifdef __FreeBSD__
-#include <sys/stat.h>
-#endif
#define DIR "dir"
#define FILE "dir/openat"
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_readlinkat.c b/contrib/netbsd-tests/lib/libc/c063/t_readlinkat.c
index c9bc267..cf14652 100644
--- a/contrib/netbsd-tests/lib/libc/c063/t_readlinkat.c
+++ b/contrib/netbsd-tests/lib/libc/c063/t_readlinkat.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_readlinkat.c,v 1.3 2013/03/17 04:46:06 jmmv Exp $ */
+/* $NetBSD: t_readlinkat.c,v 1.4 2017/01/10 15:13:56 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,8 +29,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_readlinkat.c,v 1.3 2013/03/17 04:46:06 jmmv Exp $");
+__RCSID("$NetBSD: t_readlinkat.c,v 1.4 2017/01/10 15:13:56 christos Exp $");
+#include <sys/param.h>
+#include <sys/stat.h>
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
@@ -39,10 +41,6 @@ __RCSID("$NetBSD: t_readlinkat.c,v 1.3 2013/03/17 04:46:06 jmmv Exp $");
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <sys/param.h>
-#ifdef __FreeBSD__
-#include <sys/stat.h>
-#endif
#define DIR "dir"
#define FILE "dir/readlinkat"
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_unlinkat.c b/contrib/netbsd-tests/lib/libc/c063/t_unlinkat.c
index 220c4b2..9897b92 100644
--- a/contrib/netbsd-tests/lib/libc/c063/t_unlinkat.c
+++ b/contrib/netbsd-tests/lib/libc/c063/t_unlinkat.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_unlinkat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $ */
+/* $NetBSD: t_unlinkat.c,v 1.3 2017/01/10 15:13:56 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,8 +29,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_unlinkat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $");
+__RCSID("$NetBSD: t_unlinkat.c,v 1.3 2017/01/10 15:13:56 christos Exp $");
+#include <sys/param.h>
+#include <sys/stat.h>
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
@@ -39,10 +41,6 @@ __RCSID("$NetBSD: t_unlinkat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $");
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <sys/param.h>
-#ifdef __FreeBSD__
-#include <sys/stat.h>
-#endif
#define DIR "dir"
#define FILE "dir/unlinkat"
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_utimensat.c b/contrib/netbsd-tests/lib/libc/c063/t_utimensat.c
index 9f21fd6..682c2df 100644
--- a/contrib/netbsd-tests/lib/libc/c063/t_utimensat.c
+++ b/contrib/netbsd-tests/lib/libc/c063/t_utimensat.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_utimensat.c,v 1.5 2013/03/17 04:46:06 jmmv Exp $ */
+/* $NetBSD: t_utimensat.c,v 1.6 2017/01/10 15:13:56 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,8 +29,11 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_utimensat.c,v 1.5 2013/03/17 04:46:06 jmmv Exp $");
+__RCSID("$NetBSD: t_utimensat.c,v 1.6 2017/01/10 15:13:56 christos Exp $");
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/time.h>
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
@@ -39,8 +42,6 @@ __RCSID("$NetBSD: t_utimensat.c,v 1.5 2013/03/17 04:46:06 jmmv Exp $");
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <sys/param.h>
-#include <sys/time.h>
#define DIR "dir"
#define FILE "dir/utimensat"
diff --git a/contrib/netbsd-tests/lib/libc/db/h_db.c b/contrib/netbsd-tests/lib/libc/db/h_db.c
index dfb1385..dd19a03 100644
--- a/contrib/netbsd-tests/lib/libc/db/h_db.c
+++ b/contrib/netbsd-tests/lib/libc/db/h_db.c
@@ -1,4 +1,4 @@
-/* $NetBSD: h_db.c,v 1.1 2011/01/07 15:05:58 pgoyette Exp $ */
+/* $NetBSD: h_db.c,v 1.3 2016/09/24 21:18:22 christos Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\
#if 0
static char sccsid[] = "@(#)dbtest.c 8.17 (Berkeley) 9/1/94";
#else
-__RCSID("$NetBSD: h_db.c,v 1.1 2011/01/07 15:05:58 pgoyette Exp $");
+__RCSID("$NetBSD: h_db.c,v 1.3 2016/09/24 21:18:22 christos Exp $");
#endif
#endif /* not lint */
@@ -57,12 +57,13 @@ __RCSID("$NetBSD: h_db.c,v 1.1 2011/01/07 15:05:58 pgoyette Exp $");
#include <unistd.h>
#include <err.h>
#include <db.h>
+#include "btree.h"
enum S { COMMAND, COMPARE, GET, PUT, REMOVE, SEQ, SEQFLAG, KEY, DATA };
static void compare(DBT *, DBT *);
static DBTYPE dbtype(const char *);
-static void dump(DB *, int);
+static void dump(DB *, int, int);
static void get(DB *, DBT *);
static void getdata(DB *, DBT *, DBT *);
static void put(DB *, DBT *, DBT *);
@@ -73,6 +74,9 @@ static void *rfile(char *, size_t *);
static void seq(DB *, DBT *);
static u_int setflags(char *);
static void *setinfo(DBTYPE, char *);
+#ifdef __NetBSD__
+static void unlinkpg(DB *);
+#endif
static void usage(void) __attribute__((__noreturn__));
static void *xcopy(void *, size_t);
static void chkcmd(enum S);
@@ -82,6 +86,9 @@ static void chkkey(enum S);
#ifdef STATISTICS
extern void __bt_stat(DB *);
#endif
+#ifdef __NetBSD__
+extern int __bt_relink(BTREE *, PAGE *);
+#endif
static DBTYPE type; /* Database type. */
static void *infop; /* Iflags. */
@@ -315,8 +322,16 @@ lkey: switch (command) {
}
break;
case 'o':
- dump(dbp, p[1] == 'r');
+ dump(dbp, p[1] == 'r', 0);
+ break;
+#ifdef __NetBSD__
+ case 'O':
+ dump(dbp, p[1] == 'r', 1);
break;
+ case 'u':
+ unlinkpg(dbp);
+ break;
+#endif
default:
errx(1, "line %zu: %s: unknown command character",
lineno, p);
@@ -483,17 +498,25 @@ seq(DB *dbp, DBT *kp)
}
static void
-dump(DB *dbp, int rev)
+dump(DB *dbp, int rev, int recurse)
{
DBT key, data;
int xflags, nflags;
if (rev) {
xflags = R_LAST;
+#ifdef __NetBSD__
+ nflags = recurse ? R_RPREV : R_PREV;
+#else
nflags = R_PREV;
+#endif
} else {
xflags = R_FIRST;
+#ifdef __NetBSD__
+ nflags = recurse ? R_RNEXT : R_NEXT;
+#else
nflags = R_NEXT;
+#endif
}
for (;; xflags = nflags)
switch (dbp->seq(dbp, &key, &data, xflags)) {
@@ -511,6 +534,42 @@ dump(DB *dbp, int rev)
done: return;
}
+#ifdef __NetBSD__
+void
+unlinkpg(DB *dbp)
+{
+ BTREE *t = dbp->internal;
+ PAGE *h = NULL;
+ pgno_t pg;
+
+ for (pg = P_ROOT; pg < t->bt_mp->npages;
+ mpool_put(t->bt_mp, h, 0), pg++) {
+ if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)
+ break;
+ /* Look for a nonempty leaf page that has both left
+ * and right siblings. */
+ if (h->prevpg == P_INVALID || h->nextpg == P_INVALID)
+ continue;
+ if (NEXTINDEX(h) == 0)
+ continue;
+ if ((h->flags & (P_BLEAF | P_RLEAF)))
+ break;
+ }
+ if (h == NULL || pg == t->bt_mp->npages) {
+ errx(1, "%s: no appropriate page found", __func__);
+ return;
+ }
+ if (__bt_relink(t, h) != 0) {
+ perror("unlinkpg");
+ goto cleanup;
+ }
+ h->prevpg = P_INVALID;
+ h->nextpg = P_INVALID;
+cleanup:
+ mpool_put(t->bt_mp, h, MPOOL_DIRTY);
+}
+#endif
+
static u_int
setflags(char *s)
{
@@ -725,7 +784,11 @@ static void
usage(void)
{
(void)fprintf(stderr,
- "Usage: %s [-l] [-f file] [-i info] [-o file] type script\n",
- getprogname());
+#ifdef __NetBSD__
+ "Usage: %s [-lu] [-f file] [-i info] [-o file] [-O file] "
+#else
+ "Usage: %s [-l] [-f file] [-i info] [-o file] "
+#endif
+ "type script\n", getprogname());
exit(1);
}
diff --git a/contrib/netbsd-tests/lib/libc/db/h_lfsr.c b/contrib/netbsd-tests/lib/libc/db/h_lfsr.c
new file mode 100644
index 0000000..3f3d712
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/db/h_lfsr.c
@@ -0,0 +1,179 @@
+/*-
+ * Copyright (c) 2015 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 <sys/cdefs.h>
+__RCSID("$NetBSD: h_lfsr.c,v 1.1 2015/11/18 18:35:35 christos Exp $");
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <err.h>
+#include <string.h>
+#include <unistd.h>
+#include <db.h>
+
+#define MAXKEY 0xffff
+#ifdef DEBUG
+#define DPRINTF(...) printf(__VA_ARGS__)
+#else
+#define DPRINTF(...)
+#endif
+
+static uint16_t
+next(uint16_t *cur)
+{
+ uint16_t lsb = *cur & 1;
+ *cur >>= 1;
+ *cur ^= (-lsb) & 0xB400u;
+ return *cur;
+}
+
+int
+main(int argc, char *argv[])
+{
+ char buf[65536];
+ char kb[256];
+ DBT key, val;
+ DB *db;
+ HASHINFO hi;
+ uint8_t c;
+ uint16_t len;
+ uint32_t pagesize = atoi(argv[1]);
+
+ memset(&hi, 0, sizeof(hi));
+ memset(buf, 'a', sizeof(buf));
+ hi.bsize = pagesize;
+ hi.nelem = 65536;
+ hi.ffactor = 128;
+
+ key.data = kb;
+ val.data = buf;
+
+ db = dbopen(NULL, O_CREAT|O_TRUNC|O_RDWR, 0, DB_HASH, &hi);
+ if (db == NULL)
+ err(EXIT_FAILURE, "dbopen");
+
+ len = 0xaec1;
+ for (size_t i = 0; i < MAXKEY; i++) {
+ key.size = (len & 0xff) + 1;
+ c = len >> 8;
+ memset(kb, c, key.size);
+ val.size = (next(&len) & 0xff) + 1;
+ switch ((*db->put)(db, &key, &val, R_NOOVERWRITE)) {
+ case 0:
+ DPRINTF("put %zu %zu %#x\n",
+ key.size, val.size, c);
+ break;
+ case -1:
+ err(EXIT_FAILURE, "put error %zu %zu %#x",
+ key.size, val.size, c);
+ case 1:
+ errx(EXIT_FAILURE, "put overwrite %zu %zu %#x",
+ key.size, val.size, c);
+ default:
+ abort();
+ }
+ }
+
+ len = 0xaec1;
+ for (size_t i = 0; i < MAXKEY; i++) {
+ key.size = (len & 0xff) + 1;
+ c = len >> 8;
+ memset(kb, c, key.size);
+ next(&len);
+ switch ((*db->get)(db, &key, &val, 0)) {
+ case 0:
+ DPRINTF("get %zu %zu %#x\n",
+ key.size, val.size, c);
+ break;
+ case -1:
+ err(EXIT_FAILURE, "get %zu %zu %#x",
+ key.size, val.size, c);
+ case 1:
+ errx(EXIT_FAILURE, "get not found %zu %zu %#x",
+ key.size, val.size, c);
+ default:
+ abort();
+ }
+ if (memcmp(key.data, kb, key.size) != 0)
+ errx(EXIT_FAILURE, "get badkey %zu %zu %#x",
+ key.size, val.size, c);
+ if (val.size != (len & 0xff) + 1U)
+ errx(EXIT_FAILURE, "get badvallen %zu %zu %#x",
+ key.size, val.size, c);
+ if (memcmp(val.data, buf, val.size) != 0)
+ errx(EXIT_FAILURE, "get badval %zu %zu %#x",
+ key.size, val.size, c);
+ }
+
+ len = 0xaec1;
+ for (size_t i = 0; i < MAXKEY; i++) {
+ key.size = (len & 0xff) + 1;
+ c = len >> 8;
+ memset(kb, c, key.size);
+ next(&len);
+ switch ((*db->del)(db, &key, 0)) {
+ case 0:
+ DPRINTF("del %zu %zu %#x\n",
+ key.size, val.size, c);
+ break;
+ case -1:
+ err(EXIT_FAILURE, "del %zu %zu %#x", key.size,
+ val.size, c);
+ case 1:
+ errx(EXIT_FAILURE, "del not found %zu %zu %#x",
+ key.size, val.size, c);
+ default:
+ abort();
+ }
+ }
+
+ len = 0xaec1;
+ for (size_t i = 0; i < MAXKEY; i++) {
+ key.size = (len & 0xff) + 1;
+ c = len >> 8;
+ memset(kb, c, key.size);
+ next(&len);
+ switch ((*db->get)(db, &key, &val, 0)) {
+ case 0:
+ errx(EXIT_FAILURE, "get2 found %zu %zu %#x",
+ key.size, val.size, c);
+ break;
+ case -1:
+ err(EXIT_FAILURE, "get2 %zu %zu %#x",
+ key.size, val.size, c);
+ case 1:
+ DPRINTF("get2 %zu %zu %#x\n",
+ key.size, val.size, c);
+ break;
+ default:
+ abort();
+ }
+ }
+ return 0;
+}
diff --git a/contrib/netbsd-tests/lib/libc/db/t_db.sh b/contrib/netbsd-tests/lib/libc/db/t_db.sh
index d256508..6858e36 100755
--- a/contrib/netbsd-tests/lib/libc/db/t_db.sh
+++ b/contrib/netbsd-tests/lib/libc/db/t_db.sh
@@ -1,4 +1,4 @@
-# $NetBSD: t_db.sh,v 1.4 2013/07/29 10:43:15 skrll Exp $
+# $NetBSD: t_db.sh,v 1.7 2016/09/24 20:12:33 christos Exp $
#
# Copyright (c) 2008 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -25,11 +25,16 @@
# POSSIBILITY OF SUCH DAMAGE.
#
-prog()
+prog_db()
{
echo $(atf_get_srcdir)/h_db
}
+prog_lfsr()
+{
+ echo $(atf_get_srcdir)/h_lfsr
+}
+
dict()
{
if [ -f /usr/share/dict/words ]; then
@@ -37,6 +42,7 @@ dict()
elif [ -f /usr/dict/words ]; then
echo /usr/dict/words
else
+ echo ""
atf_fail "no dictionary found"
fi
}
@@ -44,12 +50,7 @@ dict()
# Begin FreeBSD
dict()
{
- if [ -f /usr/share/dict/words ]; then
- echo /usr/share/dict/words
- else
- echo /nonexistent
- atf_skip "Test requires dict/words"
- fi
+ echo /usr/share/dict/words
}
# End FreeBSD
@@ -62,6 +63,9 @@ small_btree_head()
"Checks btree database using small keys and small data" \
"pairs: takes the first hundred entries in the dictionary," \
"and makes them be key/data pairs."
+ # Begin FreeBSD
+ atf_set "require.files" /usr/share/dict/words
+ # End FreeBSD
}
small_btree_body()
{
@@ -78,7 +82,7 @@ small_btree_body()
echo k$i
done >in
- atf_check -o file:exp "$(prog)" btree in
+ atf_check -o file:exp "$(prog_db)" btree in
}
atf_test_case small_hash
@@ -88,6 +92,9 @@ small_hash_head()
"Checks hash database using small keys and small data" \
"pairs: takes the first hundred entries in the dictionary," \
"and makes them be key/data pairs."
+ # Begin FreeBSD
+ atf_set "require.files" /usr/share/dict/words
+ # End FreeBSD
}
small_hash_body()
{
@@ -104,7 +111,7 @@ small_hash_body()
echo k$i
done >in
- atf_check -o file:exp "$(prog)" hash in
+ atf_check -o file:exp "$(prog_db)" hash in
}
atf_test_case small_recno
@@ -114,6 +121,9 @@ small_recno_head()
"Checks recno database using small keys and small data" \
"pairs: takes the first hundred entries in the dictionary," \
"and makes them be key/data pairs."
+ # Begin FreeBSD
+ atf_set "require.files" /usr/share/dict/words
+ # End FreeBSD
}
small_recno_body()
{
@@ -128,7 +138,7 @@ small_recno_body()
printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
}' >in
- atf_check -o file:exp "$(prog)" recno in
+ atf_check -o file:exp "$(prog_db)" recno in
}
atf_test_case medium_btree
@@ -138,6 +148,9 @@ medium_btree_head()
"Checks btree database using small keys and medium" \
"data pairs: takes the first 200 entries in the" \
"dictionary, and gives them each a medium size data entry."
+ # Begin FreeBSD
+ atf_set "require.files" /usr/share/dict/words
+ # End FreeBSD
}
medium_btree_body()
{
@@ -156,7 +169,7 @@ medium_btree_body()
echo k$i
done >in
- atf_check -o file:exp "$(prog)" btree in
+ atf_check -o file:exp "$(prog_db)" btree in
}
atf_test_case medium_hash
@@ -166,6 +179,9 @@ medium_hash_head()
"Checks hash database using small keys and medium" \
"data pairs: takes the first 200 entries in the" \
"dictionary, and gives them each a medium size data entry."
+ # Begin FreeBSD
+ atf_set "require.files" /usr/share/dict/words
+ # End FreeBSD
}
medium_hash_body()
{
@@ -184,7 +200,7 @@ medium_hash_body()
echo k$i
done >in
- atf_check -o file:exp "$(prog)" hash in
+ atf_check -o file:exp "$(prog_db)" hash in
}
atf_test_case medium_recno
@@ -209,7 +225,7 @@ medium_recno_body()
printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
}' >in
- atf_check -o file:exp "$(prog)" recno in
+ atf_check -o file:exp "$(prog_db)" recno in
}
atf_test_case big_btree
@@ -238,7 +254,7 @@ big_btree_body()
echo k$i
done >in
- atf_check "$(prog)" -o out btree in
+ atf_check "$(prog_db)" -o out btree in
cmp -s exp out || atf_fail "test failed for page size: $psize"
done
}
@@ -266,7 +282,7 @@ big_hash_body()
echo k$i
done >in
- atf_check "$(prog)" -o out hash in
+ atf_check "$(prog_db)" -o out hash in
cmp -s exp out || atf_fail "test failed"
}
@@ -294,7 +310,7 @@ big_recno_body()
for psize in 512 16384 65536; do
echo "checking page size: $psize"
- atf_check "$(prog)" -o out recno in
+ atf_check "$(prog_db)" -o out recno in
cmp -s exp out || atf_fail "test failed for page size: $psize"
done
}
@@ -362,7 +378,7 @@ random_recno_body()
printf("g\nk%d\n", i);
}' >in
- atf_check -o file:exp "$(prog)" recno in
+ atf_check -o file:exp "$(prog_db)" recno in
}
atf_test_case reverse_recno
@@ -400,7 +416,7 @@ reverse_recno_body()
printf("g\nk%d\n", i);
}' >in
- atf_check -o file:exp "$(prog)" recno in
+ atf_check -o file:exp "$(prog_db)" recno in
}
atf_test_case alternate_recno
@@ -452,7 +468,7 @@ alternate_recno_body()
printf("g\nk%d\n", i);
}' >in
- atf_check "$(prog)" -o out recno in
+ atf_check "$(prog_db)" -o out recno in
sort -o exp exp
sort -o out out
@@ -521,7 +537,7 @@ h_delete()
}' >> exp
fi
- atf_check "$(prog)" -o out $type in
+ atf_check "$(prog_db)" -o out $type in
atf_check -o file:exp cat out
}
@@ -547,6 +563,7 @@ delete_recno_body()
h_repeated()
{
+ local type="$1"
TMPDIR="$(pwd)/db_dir"; export TMPDIR
mkdir ${TMPDIR}
@@ -565,7 +582,7 @@ h_repeated()
}
}' >in
- $(prog) btree in
+ $(prog_db) $type in
}
atf_test_case repeated_btree
@@ -620,16 +637,15 @@ duplicate_btree_body()
printf("o\n");
}' >in
- atf_check -o file:exp -x "$(prog) -iflags=1 btree in | sort"
+ atf_check -o file:exp -x "$(prog_db) -iflags=1 btree in | sort"
}
h_cursor_flags()
{
+ local type=$1
TMPDIR="$(pwd)/db_dir"; export TMPDIR
mkdir ${TMPDIR}
- type=$1
-
echo $SEVEN_SEVEN |
awk '{
for (i = 1; i <= 20; ++i)
@@ -649,7 +665,7 @@ h_cursor_flags()
printf("eR_CURSOR SHOULD HAVE FAILED\n");
}' >in
- atf_check -o ignore -e ignore -s ne:0 "$(prog)" -o out $type in
+ atf_check -o ignore -e ignore -s ne:0 "$(prog_db)" -o out $type in
atf_check -s ne:0 test -s out
cat exp |
@@ -663,7 +679,7 @@ h_cursor_flags()
printf("eR_CURSOR SHOULD HAVE FAILED\n");
}' >in
- atf_check -o ignore -e ignore -s ne:0 "$(prog)" -o out $type in
+ atf_check -o ignore -e ignore -s ne:0 "$(prog_db)" -o out $type in
atf_check -s ne:0 test -s out
}
@@ -719,7 +735,7 @@ reverse_order_recno_body()
printf("or\n");
}' >in
- atf_check -o file:exp "$(prog)" recno in
+ atf_check -o file:exp "$(prog_db)" recno in
}
atf_test_case small_page_btree
@@ -731,6 +747,9 @@ small_page_btree_head()
"reverses them, and gives them each a small size data" \
"entry. Uses a small page size to make sure the btree" \
"split code gets hammered."
+ # Begin FreeBSD
+ atf_set "require.files" /usr/share/dict/words
+ # End FreeBSD
}
small_page_btree_body()
{
@@ -749,7 +768,7 @@ small_page_btree_body()
echo k$i
done >in
- atf_check -o file:exp "$(prog)" -i psize=512 btree in
+ atf_check -o file:exp "$(prog_db)" -i psize=512 btree in
}
h_byte_orders()
@@ -765,18 +784,19 @@ h_byte_orders()
echo p
echo k$i
echo d$i
+ echo S
echo g
echo k$i
done >in
- atf_check -o file:exp "$(prog)" -ilorder=$order -f byte.file $type in
+ atf_check -o file:exp "$(prog_db)" -ilorder=$order -f byte.file $type in
for i in `sed 50q $(dict)`; do
echo g
echo k$i
done >in
- atf_check -o file:exp "$(prog)" -s -ilorder=$order -f byte.file $type in
+ atf_check -o file:exp "$(prog_db)" -s -ilorder=$order -f byte.file $type in
done
}
@@ -784,6 +804,9 @@ atf_test_case byte_orders_btree
byte_orders_btree_head()
{
atf_set "descr" "Checks btree database using differing byte orders"
+ # Begin FreeBSD
+ atf_set "require.files" /usr/share/dict/words
+ # End FreeBSD
}
byte_orders_btree_body()
{
@@ -806,16 +829,19 @@ h_bsize_ffactor()
ffactor=$2
echo "bucketsize $bsize, fill factor $ffactor"
- atf_check -o file:exp "$(prog)" "-ibsize=$bsize,\
+ atf_check -o file:exp "$(prog_db)" "-ibsize=$bsize,\
ffactor=$ffactor,nelem=25000,cachesize=65536" hash in
}
atf_test_case bsize_ffactor
bsize_ffactor_head()
{
- atf_set "timeout" "480"
+ atf_set "timeout" "1800"
atf_set "descr" "Checks hash database with various" \
"bucketsizes and fill factors"
+ # Begin FreeBSD
+ atf_set "require.files" /usr/share/dict/words
+ # End FreeBSD
}
bsize_ffactor_body()
{
@@ -876,9 +902,27 @@ bsize_ffactor_body()
h_bsize_ffactor 8192 341
h_bsize_ffactor 8192 455
h_bsize_ffactor 8192 683
+
+ h_bsize_ffactor 16384 341
+ h_bsize_ffactor 16384 455
+ h_bsize_ffactor 16384 683
+
+ h_bsize_ffactor 32768 341
+ h_bsize_ffactor 32768 455
+ h_bsize_ffactor 32768 683
+
+ # Begin FreeBSD
+ if false; then
+ # End FreeBSD
+ h_bsize_ffactor 65536 341
+ h_bsize_ffactor 65536 455
+ h_bsize_ffactor 65536 683
+ # Begin FreeBSD
+ fi
+ # End FreeBSD
}
-# FIXME: what does it test?
+# This tests 64K block size addition/removal
atf_test_case four_char_hash
four_char_hash_head()
{
@@ -901,15 +945,328 @@ EOF
# Begin FreeBSD
if true; then
- atf_check "$(prog)" -i bsize=32768 hash in
+ atf_check "$(prog_db)" -i bsize=32768 hash in
else
# End FreeBSD
- atf_check "$(prog)" -i bsize=65536 hash in
+ atf_check "$(prog_db)" -i bsize=65536 hash in
# Begin FreeBSD
fi
# End FreeBSD
}
+
+atf_test_case bsize_torture
+bsize_torture_head()
+{
+ atf_set "timeout" "36000"
+ atf_set "descr" "Checks hash database with various bucket sizes"
+}
+bsize_torture_body()
+{
+ TMPDIR="$(pwd)/db_dir"; export TMPDIR
+ mkdir ${TMPDIR}
+ # Begin FreeBSD
+ #
+ # db(3) doesn't support 64kB bucket sizes
+ for i in 2048 4096 8192 16384 32768 # 65536
+ # End FreeBSD
+ do
+ atf_check "$(prog_lfsr)" $i
+ done
+}
+
+atf_test_case btree_weird_page_split
+btree_weird_page_split_head()
+{
+ atf_set "descr" \
+ "Test for a weird page split condition where an insertion " \
+ "into index 0 of a page that would cause the new item to " \
+ "be the only item on the left page results in index 0 of " \
+ "the right page being erroneously skipped; this only " \
+ "happens with one particular key+data length for each page size."
+}
+btree_weird_page_split_body()
+{
+ for psize in 512 1024 2048 4096 8192; do
+ echo " page size $psize"
+ kdsizes=`awk 'BEGIN {
+ psize = '$psize'; hsize = int(psize/2);
+ for (kdsize = hsize-40; kdsize <= hsize; kdsize++) {
+ print kdsize;
+ }
+ }' /dev/null`
+
+ # Use a series of keylen+datalen values in the right
+ # neighborhood to find the one that triggers the bug.
+ # We could compute the exact size that triggers the
+ # bug but this additional fuzz may be useful.
+
+ # Insert keys in reverse order to maximize the chances
+ # for a split on index 0.
+
+ for kdsize in $kdsizes; do
+ awk 'BEGIN {
+ kdsize = '$kdsize';
+ for (i = 8; i-- > 0; ) {
+ s = sprintf("a%03d:%09d", i, kdsize);
+ for (j = 0; j < kdsize-20; j++) {
+ s = s "x";
+ }
+ printf("p\nka%03d\nd%s\n", i, s);
+ }
+ print "o";
+ }' /dev/null > in
+ sed -n 's/^d//p' in | sort > exp
+ atf_check -o file:exp \
+ "$(prog_db)" -i psize=$psize btree in
+ done
+ done
+}
+
+# Extremely tricky test attempting to replicate some unusual database
+# corruption seen in the field: pieces of the database becoming
+# inaccessible to random access, sequential access, or both. The
+# hypothesis is that at least some of these are triggered by the bug
+# in page splits on index 0 with a particular exact keylen+datalen.
+# (See Test 40.) For psize=4096, this size is exactly 2024.
+
+# The order of operations here relies on very specific knowledge of
+# the internals of the btree access method in order to place records
+# at specific offsets in a page and to create certain keys on internal
+# pages. The to-be-split page immediately prior to the bug-triggering
+# split has the following properties:
+#
+# * is not the leftmost leaf page
+# * key on the parent page is compares less than the key of the item
+# on index 0
+# * triggering record's key also compares greater than the key on the
+# parent page
+
+# Additionally, we prime the mpool LRU chain so that the head page on
+# the chain has the following properties:
+#
+# * record at index 0 is located where it will not get overwritten by
+# items written to the right-hand page during the split
+# * key of the record at index 0 compares less than the key of the
+# bug-triggering record
+
+# If the page-split bug exists, this test appears to create a database
+# where some records are inaccessible to a search, but still remain in
+# the file and are accessible by sequential traversal. At least one
+# record gets duplicated out of sequence.
+
+atf_test_case btree_tricky_page_split
+btree_tricky_page_split_head()
+{
+ atf_set "descr" \
+ "btree: no unsearchables due to page split on index 0"
+}
+btree_tricky_page_split_body()
+{
+ list=`(for i in a b c d; do
+ for j in 990 998 999; do
+ echo g ${i}${j} 1024
+ done
+ done;
+ echo g y997 2014
+ for i in y z; do
+ for j in 998 999; do
+ echo g ${i}${j} 1024
+ done
+ done)`
+ # Exact number for trigger condition accounts for newlines
+ # retained by dbtest with -ofile but not without; we use
+ # -ofile, so count newlines. keylen=5,datalen=5+2014 for
+ # psize=4096 here.
+ (cat - <<EOF
+p z999 1024
+p z998 1024
+p y999 1024
+p y990 1024
+p d999 1024
+p d990 1024
+p c999 1024
+p c990 1024
+p b999 1024
+p b990 1024
+p a999 1024
+p a990 1024
+p y998 1024
+r y990
+p d998 1024
+p d990 1024
+p c998 1024
+p c990 1024
+p b998 1024
+p b990 1024
+p a998 1024
+p a990 1024
+p y997 2014
+S
+o
+EOF
+ echo "$list") |
+ # awk script input:
+ # {p|g|r} key [datasize]
+ awk '/^[pgr]/{
+ printf("%s\nk%s\n", $1, $2);
+ }
+ /^p/{
+ s = $2;
+ for (i = 0; i < $3; i++) {
+ s = s "x";
+ }
+ printf("d%s\n", s);
+ }
+ !/^[pgr]/{
+ print $0;
+ }' > in
+ (echo "$list"; echo "$list") | awk '{
+ s = $2;
+ for (i = 0; i < $3; i++) {
+ s = s "x";
+ }
+ print s;
+ }' > exp
+ atf_check -o file:exp \
+ "$(prog_db)" -i psize=4096 btree in
+}
+
+# Begin FreeBSD
+if false; then
+# End FreeBSD
+atf_test_case btree_recursive_traversal
+btree_recursive_traversal_head()
+{
+ atf_set "descr" \
+ "btree: Test for recursive traversal successfully " \
+ "retrieving records that are inaccessible to normal " \
+ "sequential 'sibling-link' traversal. This works by " \
+ "unlinking a few leaf pages but leaving their parent " \
+ "links intact. To verify that the unlink actually makes " \
+ "records inaccessible, the test first uses 'o' to do a " \
+ "normal sequential traversal, followed by 'O' to do a " \
+ "recursive traversal."
+}
+btree_recursive_traversal_body()
+{
+ fill="abcdefghijklmnopqrstuvwxyzy"
+ script='{
+ for (i = 0; i < 20000; i++) {
+ printf("p\nkAA%05d\nd%05d%s\n", i, i, $0);
+ }
+ print "u";
+ print "u";
+ print "u";
+ print "u";
+ }'
+ (echo $fill | awk "$script"; echo o) > in1
+ echo $fill |
+ awk '{
+ for (i = 0; i < 20000; i++) {
+ if (i >= 5 && i <= 40)
+ continue;
+ printf("%05d%s\n", i, $0);
+ }
+ }' > exp1
+ atf_check -o file:exp1 \
+ "$(prog_db)" -i psize=512 btree in1
+ echo $fill |
+ awk '{
+ for (i = 0; i < 20000; i++) {
+ printf("%05d%s\n", i, $0);
+ }
+ }' > exp2
+ (echo $fill | awk "$script"; echo O) > in2
+ atf_check -o file:exp2 \
+ "$(prog_db)" -i psize=512 btree in2
+}
+# Begin FreeBSD
+fi
+# End FreeBSD
+
+atf_test_case btree_byteswap_unaligned_access_bksd
+btree_byteswap_unaligned_access_bksd_head()
+{
+ atf_set "descr" \
+ "btree: big key, small data, byteswap unaligned access"
+}
+btree_byteswap_unaligned_access_bksd_body()
+{
+ (echo foo; echo bar) |
+ awk '{
+ s = $0
+ for (i = 0; i < 488; i++) {
+ s = s "x";
+ }
+ printf("p\nk%s\ndx\n", s);
+ }' > in
+ for order in 1234 4321; do
+ atf_check \
+ "$(prog_db)" -o out -i psize=512,lorder=$order btree in
+ done
+}
+
+atf_test_case btree_byteswap_unaligned_access_skbd
+btree_byteswap_unaligned_access_skbd_head()
+{
+ atf_set "descr" \
+ "btree: small key, big data, byteswap unaligned access"
+}
+btree_byteswap_unaligned_access_skbd_body()
+{
+ # 484 = 512 - 20 (header) - 7 ("foo1234") - 1 (newline)
+ (echo foo1234; echo bar1234) |
+ awk '{
+ s = $0
+ for (i = 0; i < 484; i++) {
+ s = s "x";
+ }
+ printf("p\nk%s\nd%s\n", $0, s);
+ }' > in
+ for order in 1234 4321; do
+ atf_check \
+ "$(prog_db)" -o out -i psize=512,lorder=$order btree in
+ done
+}
+
+atf_test_case btree_known_byte_order
+btree_known_byte_order_head()
+{
+ atf_set "descr" \
+ "btree: small key, big data, known byte order"
+}
+btree_known_byte_order_body()
+{
+ local a="-i psize=512,lorder="
+
+ (echo foo1234; echo bar1234) |
+ awk '{
+ s = $0
+ for (i = 0; i < 484; i++) {
+ s = s "x";
+ }
+ printf("%s\n", s);
+ }' > exp
+ (echo foo1234; echo bar1234) |
+ awk '{
+ s = $0
+ for (i = 0; i < 484; i++) {
+ s = s "x";
+ }
+ printf("p\nk%s\nd%s\n", $0, s);
+ }' > in1
+ for order in 1234 4321; do
+ atf_check \
+ "$(prog_db)" -f out.$order $a$order btree in1
+ done
+ (echo g; echo kfoo1234; echo g; echo kbar1234) > in2
+ for order in 1234 4321; do
+ atf_check -o file:exp \
+ "$(prog_db)" -s -f out.$order $a$order btree in2
+ done
+}
+
atf_init_test_cases()
{
atf_add_test_case small_btree
@@ -937,4 +1294,17 @@ atf_init_test_cases()
atf_add_test_case byte_orders_hash
atf_add_test_case bsize_ffactor
atf_add_test_case four_char_hash
+ atf_add_test_case bsize_torture
+ atf_add_test_case btree_weird_page_split
+ atf_add_test_case btree_tricky_page_split
+ # Begin FreeBSD
+ if false; then
+ # End FreeBSD
+ atf_add_test_case btree_recursive_traversal
+ # Begin FreeBSD
+ fi
+ # End FreeBSD
+ atf_add_test_case btree_byteswap_unaligned_access_bksd
+ atf_add_test_case btree_byteswap_unaligned_access_skbd
+ atf_add_test_case btree_known_byte_order
}
diff --git a/contrib/netbsd-tests/lib/libc/db/t_db_hash_seq.c b/contrib/netbsd-tests/lib/libc/db/t_db_hash_seq.c
new file mode 100644
index 0000000..6e19e22
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/db/t_db_hash_seq.c
@@ -0,0 +1,343 @@
+/* $NetBSD: t_db_hash_seq.c,v 1.2 2015/06/22 22:35:51 christos Exp $ */
+
+/*-
+ * Copyright (c) 2015 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 <sys/cdefs.h>
+__RCSID("$NetBSD: t_db_hash_seq.c,v 1.2 2015/06/22 22:35:51 christos Exp $");
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <db.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <syslog.h>
+#include <netinet/in.h>
+
+#define ATF
+
+struct conf {
+ struct sockaddr_storage c_ss;
+ int c_lmask;
+ int c_port;
+ int c_proto;
+ int c_family;
+ int c_uid;
+ int c_nfail;
+ char c_name[128];
+ int c_rmask;
+ int c_duration;
+};
+
+struct dbinfo {
+ int count;
+ time_t last;
+ char id[64];
+};
+
+#ifdef ATF
+#include <atf-c.h>
+
+#define DO_ERR(msg, ...) ATF_REQUIRE_MSG(0, msg, __VA_ARGS__)
+#define DO_WARNX(msg, ...) ATF_REQUIRE_MSG(0, msg, __VA_ARGS__)
+#else
+#include <err.h>
+
+#define DO_ERR(fmt, ...) err(EXIT_FAILURE, fmt, __VA_ARGS__)
+#define DO_WARNX(fmt, ...) warnx(fmt, __VA_ARGS__)
+#endif
+
+#define DO_DEBUG(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
+
+static HASHINFO openinfo = {
+ 4096, /* bsize */
+ 32, /* ffactor */
+ 256, /* nelem */
+ 8 * 1024 * 1024,/* cachesize */
+ NULL, /* hash() */
+ 0 /* lorder */
+};
+
+static int debug = 0;
+
+static int
+state_close(DB *db)
+{
+ if (db == NULL)
+ return -1;
+ if ((*db->close)(db) == -1)
+ DO_ERR("%s: can't close db", __func__);
+ return 0;
+}
+
+static DB *
+state_open(const char *dbname, int flags, mode_t perm)
+{
+ DB *db;
+
+ db = dbopen(dbname, flags, perm, DB_HASH, &openinfo);
+ if (db == NULL) {
+ if (errno == ENOENT && (flags & O_CREAT) == 0)
+ return NULL;
+ DO_ERR("%s: can't open `%s'", __func__, dbname);
+ }
+ return db;
+}
+
+static int
+state_sizecheck(const DBT *t)
+{
+ if (sizeof(struct conf) == t->size)
+ return 0;
+ DO_WARNX("Key size mismatch %zu != %zu", sizeof(struct conf), t->size);
+ return 0;
+}
+
+static int
+state_del(DB *db, const struct conf *c)
+{
+ int rv;
+ DBT k;
+
+ if (db == NULL)
+ return -1;
+
+ k.data = __UNCONST(c);
+ k.size = sizeof(*c);
+
+ switch (rv = (*db->del)(db, &k, 1)) {
+ case 0:
+ case 1:
+ if (debug > 1) {
+ DO_DEBUG("%s: returns %d", __func__, rv);
+ (*db->sync)(db, 0);
+ }
+ return 0;
+ default:
+ DO_ERR("%s: failed", __func__);
+ return -1;
+ }
+}
+
+#if 0
+static int
+state_get(DB *db, const struct conf *c, struct dbinfo *dbi)
+{
+ int rv;
+ DBT k, v;
+
+ if (db == NULL)
+ return -1;
+
+ k.data = __UNCONST(c);
+ k.size = sizeof(*c);
+
+ switch (rv = (*db->get)(db, &k, &v, 0)) {
+ case 0:
+ case 1:
+ if (rv)
+ memset(dbi, 0, sizeof(*dbi));
+ else
+ memcpy(dbi, v.data, sizeof(*dbi));
+ if (debug > 1)
+ DO_DEBUG("%s: returns %d", __func__, rv);
+ return 0;
+ default:
+ DO_ERR("%s: failed", __func__);
+ return -1;
+ }
+}
+#endif
+
+static int
+state_put(DB *db, const struct conf *c, const struct dbinfo *dbi)
+{
+ int rv;
+ DBT k, v;
+
+ if (db == NULL)
+ return -1;
+
+ k.data = __UNCONST(c);
+ k.size = sizeof(*c);
+ v.data = __UNCONST(dbi);
+ v.size = sizeof(*dbi);
+
+ switch (rv = (*db->put)(db, &k, &v, 0)) {
+ case 0:
+ if (debug > 1) {
+ DO_DEBUG("%s: returns %d", __func__, rv);
+ (*db->sync)(db, 0);
+ }
+ return 0;
+ case 1:
+ errno = EEXIST;
+ /*FALLTHROUGH*/
+ default:
+ DO_ERR("%s: failed", __func__);
+ }
+}
+
+static int
+state_iterate(DB *db, struct conf *c, struct dbinfo *dbi, unsigned int first)
+{
+ int rv;
+ DBT k, v;
+
+ if (db == NULL)
+ return -1;
+
+ first = first ? R_FIRST : R_NEXT;
+
+ switch (rv = (*db->seq)(db, &k, &v, first)) {
+ case 0:
+ if (state_sizecheck(&k) == -1)
+ return -1;
+ memcpy(c, k.data, sizeof(*c));
+ memcpy(dbi, v.data, sizeof(*dbi));
+ if (debug > 1)
+ DO_DEBUG("%s: returns %d", __func__, rv);
+ return 1;
+ case 1:
+ if (debug > 1)
+ DO_DEBUG("%s: returns %d", __func__, rv);
+ return 0;
+ default:
+ DO_ERR("%s: failed", __func__);
+ return -1;
+ }
+}
+
+#define MAXB 100
+
+static int
+testdb(int skip)
+{
+ size_t i;
+ int f;
+ char flag[MAXB];
+ DB *db;
+ struct conf c;
+ struct dbinfo d;
+
+ db = state_open(NULL, O_RDWR|O_CREAT|O_TRUNC, 0600);
+ if (db == NULL)
+ DO_ERR("%s: cannot open `%s'", __func__, "foo");
+
+ memset(&c, 0, sizeof(c));
+ memset(&d, 0, sizeof(d));
+ memset(flag, 0, sizeof(flag));
+
+ for (i = 0; i < __arraycount(flag); i++) {
+ c.c_port = i;
+ state_put(db, &c, &d);
+ }
+
+ for (f = 1, i = 0; state_iterate(db, &c, &d, f) == 1; f = 0, i++) {
+ if (debug > 1)
+ DO_DEBUG("%zu %d\n", i, c.c_port);
+ if (flag[c.c_port])
+ DO_WARNX("Already visited %d", c.c_port);
+ flag[c.c_port] = 1;
+ if (skip == 0 || c.c_port % skip != 0)
+ continue;
+ state_del(db, &c);
+ }
+ state_close(db);
+ for (i = 0; i < __arraycount(flag); i++) {
+ if (flag[i] == 0)
+ DO_WARNX("Not visited %zu", i);
+ }
+ return 0;
+}
+
+#ifndef ATF
+int
+main(int argc, char *argv[])
+{
+ return testdb(6);
+}
+#else
+
+ATF_TC(test_hash_del_none);
+ATF_TC_HEAD(test_hash_del_none, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Check sequential scan of hash tables deleting none");
+}
+
+ATF_TC_BODY(test_hash_del_none, tc)
+{
+ testdb(0);
+}
+
+ATF_TC(test_hash_del_all);
+ATF_TC_HEAD(test_hash_del_all, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Check sequential scan of hash tables deleting all");
+}
+
+ATF_TC_BODY(test_hash_del_all, tc)
+{
+ testdb(1);
+}
+
+ATF_TC(test_hash_del_alt);
+ATF_TC_HEAD(test_hash_del_alt, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Check sequential scan of hash tables alternating deletets");
+}
+
+ATF_TC_BODY(test_hash_del_alt, tc)
+{
+ testdb(2);
+}
+
+ATF_TC(test_hash_del_every_7);
+ATF_TC_HEAD(test_hash_del_every_7, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Check sequential scan of hash tables deleting every 7 elements");
+}
+
+ATF_TC_BODY(test_hash_del_every_7, tc)
+{
+ testdb(7);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, test_hash_del_none);
+ ATF_TP_ADD_TC(tp, test_hash_del_all);
+ ATF_TP_ADD_TC(tp, test_hash_del_alt);
+ ATF_TP_ADD_TC(tp, test_hash_del_every_7);
+
+ return 0;
+}
+#endif
diff --git a/contrib/netbsd-tests/lib/libc/gen/execve/t_execve.c b/contrib/netbsd-tests/lib/libc/gen/execve/t_execve.c
index 32de6e7..d3752cd 100644
--- a/contrib/netbsd-tests/lib/libc/gen/execve/t_execve.c
+++ b/contrib/netbsd-tests/lib/libc/gen/execve/t_execve.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_execve.c,v 1.1 2014/04/29 06:29:02 uebayasi Exp $ */
+/* $NetBSD: t_execve.c,v 1.2 2015/09/12 15:21:33 christos Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -47,7 +47,8 @@ ATF_TC_BODY(t_execve_null, tc)
err = execve(NULL, NULL, NULL);
ATF_REQUIRE(err == -1);
- ATF_REQUIRE(errno == EFAULT);
+ ATF_REQUIRE_MSG(errno == EFAULT,
+ "wrong error returned %d instead of %d", errno, EFAULT);
}
ATF_TP_ADD_TCS(tp)
diff --git a/contrib/netbsd-tests/lib/libc/gen/isqemu.h b/contrib/netbsd-tests/lib/libc/gen/isqemu.h
index 7d73a22..c44ffda 100644
--- a/contrib/netbsd-tests/lib/libc/gen/isqemu.h
+++ b/contrib/netbsd-tests/lib/libc/gen/isqemu.h
@@ -1,4 +1,4 @@
-/* $NetBSD: isqemu.h,v 1.3 2013/04/14 12:46:29 martin Exp $ */
+/* $NetBSD: isqemu.h,v 1.4 2015/01/03 14:21:05 gson Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -34,12 +34,37 @@
#include <sys/param.h>
#include <sys/sysctl.h>
#include <stdbool.h>
+#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <err.h>
static __inline bool
isQEMU(void) {
+#ifdef __FreeBSD__
+ char *vm_guest_name_buf;
+ size_t len;
+ bool is_vm;
+
+ if (sysctlbyname("kern.vm_guest", NULL, &len, NULL, 0) == -1)
+ err(EXIT_FAILURE, "sysctl");
+
+ if ((vm_guest_name_buf = malloc(len)) == NULL)
+ err(EXIT_FAILURE, "malloc");
+
+ if (sysctlbyname("kern.vm_guest", vm_guest_name_buf, &len, NULL, 0)
+ == -1)
+ err(EXIT_FAILURE, "sysctl");
+
+ if (strcmp(vm_guest_name_buf, "none") == 0)
+ is_vm = false;
+ else
+ is_vm = true;
+
+ free(vm_guest_name_buf);
+
+ return is_vm;
+#else
#if defined(__i386__) || defined(__x86_64__)
char name[1024];
size_t len = sizeof(name);
@@ -53,6 +78,7 @@ isQEMU(void) {
#else
return false;
#endif
+#endif
}
#ifdef TEST
diff --git a/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_fileactions.c b/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_fileactions.c
index 5bbf337..74009a8 100644
--- a/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_fileactions.c
+++ b/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_fileactions.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_fileactions.c,v 1.5 2012/04/09 19:42:07 martin Exp $ */
+/* $NetBSD: t_fileactions.c,v 1.6 2017/01/10 22:36:29 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -31,10 +31,11 @@
*/
-#ifdef __FreeBSD__
-#include <sys/stat.h>
-#endif
#include <atf-c.h>
+
+#include <sys/wait.h>
+#include <sys/stat.h>
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -42,7 +43,6 @@
#include <fcntl.h>
#include <spawn.h>
#include <unistd.h>
-#include <sys/wait.h>
ATF_TC(t_spawn_openmode);
diff --git a/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawn.c b/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawn.c
index 178374b..12f2760 100644
--- a/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawn.c
+++ b/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawn.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_spawn.c,v 1.1 2012/02/13 21:03:08 martin Exp $ */
+/* $NetBSD: t_spawn.c,v 1.2 2014/10/18 08:33:30 snj Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -137,7 +137,7 @@ ATF_TC(t_spawn_child);
ATF_TC_HEAD(t_spawn_child, tc)
{
atf_tc_set_md_var(tc, "descr",
- "posix_spawn a child and get it's return code");
+ "posix_spawn a child and get its return code");
}
ATF_TC_BODY(t_spawn_child, tc)
diff --git a/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c b/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c
index 78313cd..2085b9e 100644
--- a/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c
+++ b/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c
@@ -60,16 +60,16 @@ get_different_scheduler(void)
/* get current schedule policy */
scheduler = sched_getscheduler(0);
- for (i = 0; i < nitems(schedulers); i++) {
+ for (i = 0; i < __arraycount(schedulers); i++) {
if (schedulers[i] == scheduler)
break;
}
- ATF_REQUIRE_MSG(i < nitems(schedulers),
+ ATF_REQUIRE_MSG(i < __arraycount(schedulers),
"Unknown current scheduler %d", scheduler);
-
+
/* new scheduler */
i++;
- if (i >= nitems(schedulers))
+ if (i >= __arraycount(schedulers))
i = 0;
return schedulers[i];
}
@@ -85,7 +85,7 @@ get_different_priority(int scheduler)
sched_getparam(0, &param);
priority = param.sched_priority;
-
+
/*
* Change numerical value of the priority, to ensure that it
* was set for the spawned child.
@@ -127,7 +127,7 @@ ATF_TC_BODY(t_spawnattr, tc)
scheduler = get_different_scheduler();
priority = get_different_priority(scheduler);
sp.sched_priority = priority;
-
+
sigemptyset(&sig);
sigaddset(&sig, SIGUSR1);
diff --git a/contrib/netbsd-tests/lib/libc/gen/t_assert.c b/contrib/netbsd-tests/lib/libc/gen/t_assert.c
index a09c130..ce73015 100644
--- a/contrib/netbsd-tests/lib/libc/gen/t_assert.c
+++ b/contrib/netbsd-tests/lib/libc/gen/t_assert.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_assert.c,v 1.2 2011/06/14 05:28:00 jruoho Exp $ */
+/* $NetBSD: t_assert.c,v 1.3 2017/01/10 15:17:57 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,8 +29,11 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_assert.c,v 1.2 2011/06/14 05:28:00 jruoho Exp $");
+__RCSID("$NetBSD: t_assert.c,v 1.3 2017/01/10 15:17:57 christos Exp $");
+#include <sys/types.h>
+#include <sys/resource.h>
+#include <sys/time.h>
#include <sys/wait.h>
#include <assert.h>
@@ -40,11 +43,6 @@ __RCSID("$NetBSD: t_assert.c,v 1.2 2011/06/14 05:28:00 jruoho Exp $");
#include <string.h>
#include <unistd.h>
-#ifdef __FreeBSD__
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-
static void
disable_corefile(void)
{
@@ -55,7 +53,6 @@ disable_corefile(void)
ATF_REQUIRE(setrlimit(RLIMIT_CORE, &limits) == 0);
}
-#endif
static void handler(int);
@@ -82,9 +79,7 @@ ATF_TC_BODY(assert_false, tc)
if (pid == 0) {
-#ifdef __FreeBSD__
disable_corefile();
-#endif
(void)closefrom(0);
(void)memset(&sa, 0, sizeof(struct sigaction));
@@ -122,9 +117,7 @@ ATF_TC_BODY(assert_true, tc)
if (pid == 0) {
-#ifdef __FreeBSD__
disable_corefile();
-#endif
(void)closefrom(0);
(void)memset(&sa, 0, sizeof(struct sigaction));
diff --git a/contrib/netbsd-tests/lib/libc/gen/t_dir.c b/contrib/netbsd-tests/lib/libc/gen/t_dir.c
index b37d89d..40de116 100644
--- a/contrib/netbsd-tests/lib/libc/gen/t_dir.c
+++ b/contrib/netbsd-tests/lib/libc/gen/t_dir.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_dir.c,v 1.6 2013/10/19 17:45:00 christos Exp $ */
+/* $NetBSD: t_dir.c,v 1.10 2017/01/11 18:15:02 christos Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -26,22 +26,19 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include <atf-c.h>
-
+#include <sys/stat.h>
#include <assert.h>
+#include <atf-c.h>
#include <dirent.h>
#include <err.h>
+#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <sys/stat.h>
-#ifdef __FreeBSD__
-#include <errno.h>
-#endif
ATF_TC(seekdir_basic);
ATF_TC_HEAD(seekdir_basic, tc)
@@ -58,7 +55,6 @@ ATF_TC_BODY(seekdir_basic, tc)
struct dirent *entry;
long here;
-#ifdef __FreeBSD__
#define CREAT(x, m) do { \
int _creat_fd; \
ATF_REQUIRE_MSG((_creat_fd = creat((x), (m))) != -1, \
@@ -72,12 +68,6 @@ ATF_TC_BODY(seekdir_basic, tc)
CREAT("t/a", 0600);
CREAT("t/b", 0600);
CREAT("t/c", 0600);
-#else
- mkdir("t", 0755);
- creat("t/a", 0600);
- creat("t/b", 0600);
- creat("t/c", 0600);
-#endif
dp = opendir("t");
if ( dp == NULL)
@@ -85,35 +75,40 @@ ATF_TC_BODY(seekdir_basic, tc)
/* skip two for . and .. */
entry = readdir(dp);
+ ATF_REQUIRE_MSG(entry != NULL, "readdir[%s] failed: %s",
+ ".", strerror(errno));
+
entry = readdir(dp);
+ ATF_REQUIRE_MSG(entry != NULL, "readdir[%s] failed: %s",
+ "..", strerror(errno));
/* get first entry */
entry = readdir(dp);
+ ATF_REQUIRE_MSG(entry != NULL, "readdir[%s] failed: %s",
+ "first", strerror(errno));
+
here = telldir(dp);
-#ifdef __FreeBSD__
- ATF_REQUIRE_MSG(here != -1,
- "telldir failed: %s", strerror(errno));
-#endif
+ ATF_REQUIRE_MSG(here != -1, "telldir failed: %s", strerror(errno));
/* get second entry */
entry = readdir(dp);
-#ifdef __FreeBSD__
- ATF_REQUIRE_MSG(entry != NULL,
- "readdir failed: %s", strerror(errno));
-#endif
+ ATF_REQUIRE_MSG(entry != NULL, "readdir[%s] failed: %s",
+ "second", strerror(errno));
+
wasname = strdup(entry->d_name);
if (wasname == NULL)
atf_tc_fail("cannot allocate memory");
/* get third entry */
entry = readdir(dp);
+ ATF_REQUIRE_MSG(entry != NULL, "readdir[%s] failed: %s",
+ "third", strerror(errno));
/* try to return to the position after the first entry */
seekdir(dp, here);
entry = readdir(dp);
-
- if (entry == NULL)
- atf_tc_fail("entry 1 not found");
+ ATF_REQUIRE_MSG(entry != NULL, "readdir[%s] failed: %s",
+ "first[1]", strerror(errno));
if (strcmp(entry->d_name, wasname) != 0)
atf_tc_fail("1st seekdir found wrong name");
@@ -121,25 +116,22 @@ ATF_TC_BODY(seekdir_basic, tc)
seekdir(dp, here);
here = telldir(dp);
entry = readdir(dp);
-
- if (entry == NULL)
- atf_tc_fail("entry 2 not found");
+ ATF_REQUIRE_MSG(entry != NULL, "readdir[%s] failed: %s",
+ "second[1]", strerror(errno));
if (strcmp(entry->d_name, wasname) != 0)
atf_tc_fail("2nd seekdir found wrong name");
/* One more time, to make sure that telldir() doesn't affect result */
seekdir(dp, here);
entry = readdir(dp);
+ ATF_REQUIRE_MSG(entry != NULL, "readdir[%s] failed: %s",
+ "third[1]", strerror(errno));
- if (entry == NULL)
- atf_tc_fail("entry 3 not found");
if (strcmp(entry->d_name, wasname) != 0)
atf_tc_fail("3rd seekdir found wrong name");
closedir(dp);
-#ifdef __FreeBSD__
free(wasname);
-#endif
}
ATF_TC(telldir_leak);
diff --git a/contrib/netbsd-tests/lib/libc/gen/t_floatunditf.c b/contrib/netbsd-tests/lib/libc/gen/t_floatunditf.c
index ef372f7..c3417bb 100644
--- a/contrib/netbsd-tests/lib/libc/gen/t_floatunditf.c
+++ b/contrib/netbsd-tests/lib/libc/gen/t_floatunditf.c
@@ -119,6 +119,11 @@ ATF_TC_BODY(floatunditf, tc)
#else
size_t i;
+#if defined(__FreeBSD__) && defined(__i386__)
+ atf_tc_expect_fail("the floating point error on FreeBSD/i386 doesn't "
+ "match the expected floating point error on NetBSD");
+#endif
+
for (i = 0; i < __arraycount(testcases); ++i)
ATF_CHECK_MSG(
testcases[i].ld == (long double)testcases[i].u64,
diff --git a/contrib/netbsd-tests/lib/libc/gen/t_fnmatch.c b/contrib/netbsd-tests/lib/libc/gen/t_fnmatch.c
index f90d8cf..69ee8d2 100644
--- a/contrib/netbsd-tests/lib/libc/gen/t_fnmatch.c
+++ b/contrib/netbsd-tests/lib/libc/gen/t_fnmatch.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_fnmatch.c,v 1.3 2012/04/08 09:58:59 jruoho Exp $ */
+/* $NetBSD: t_fnmatch.c,v 1.7 2016/10/31 05:08:53 dholland Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_fnmatch.c,v 1.3 2012/04/08 09:58:59 jruoho Exp $");
+__RCSID("$NetBSD: t_fnmatch.c,v 1.7 2016/10/31 05:08:53 dholland Exp $");
#include <atf-c.h>
#include <fnmatch.h>
@@ -153,6 +153,31 @@ ATF_TC_BODY(fnmatch_period, tc)
ATF_CHECK(fnmatch("x/*y", "x/.y", FNM_PATHNAME | FNM_PERIOD) != 0);
}
+ATF_TC(fnmatch_initialbracket);
+ATF_TC_HEAD(fnmatch_initialbracket, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test fnmatch with initial [");
+}
+
+ATF_TC_BODY(fnmatch_initialbracket, tc)
+{
+ ATF_CHECK(fnmatch("[[?*\\\\]", "\\", 0) == 0);
+ ATF_CHECK(fnmatch("[]?*\\\\]", "]", 0) == 0);
+ ATF_CHECK(fnmatch("[!]a-]", "b", 0) == 0);
+ ATF_CHECK(fnmatch("[]-_]", "^", 0) == 0); /* range: ']', '^', '_' */
+ ATF_CHECK(fnmatch("[!]-_]", "X", 0) == 0);
+ ATF_CHECK(fnmatch("[A-\\\\]", "[", 0) == 0);
+ ATF_CHECK(fnmatch("[a-z]/[a-z]", "a/b", 0) == 0);
+ ATF_CHECK(fnmatch("[*]/b", "*/b", 0) == 0);
+ ATF_CHECK(fnmatch("[?]/b", "?/b", 0) == 0);
+ ATF_CHECK(fnmatch("[[a]/b", "a/b", 0) == 0);
+ ATF_CHECK(fnmatch("[[a]/b", "[/b", 0) == 0);
+ ATF_CHECK(fnmatch("[/b", "[/b", 0) == 0);
+
+ ATF_CHECK(fnmatch("[*]/b", "a/b", 0) != 0);
+ ATF_CHECK(fnmatch("[?]/b", "a/b", 0) != 0);
+}
+
ATF_TP_ADD_TCS(tp)
{
@@ -162,6 +187,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, fnmatch_noescape);
ATF_TP_ADD_TC(tp, fnmatch_pathname);
ATF_TP_ADD_TC(tp, fnmatch_period);
+ ATF_TP_ADD_TC(tp, fnmatch_initialbracket);
return atf_no_error();
}
diff --git a/contrib/netbsd-tests/lib/libc/gen/t_fpsetmask.c b/contrib/netbsd-tests/lib/libc/gen/t_fpsetmask.c
index 3366c1f..5edc583 100644
--- a/contrib/netbsd-tests/lib/libc/gen/t_fpsetmask.c
+++ b/contrib/netbsd-tests/lib/libc/gen/t_fpsetmask.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_fpsetmask.c,v 1.14 2014/11/04 00:20:19 justin Exp $ */
+/* $NetBSD: t_fpsetmask.c,v 1.16 2016/03/12 11:55:14 martin Exp $ */
/*-
* Copyright (c) 1995 The NetBSD Foundation, Inc.
@@ -58,8 +58,20 @@ ATF_TC_BODY(no_test, tc)
#include <ieeefp.h>
-const char *skip_mesg;
-const char *skip_arch;
+#if __arm__ && !__SOFTFP__
+ /*
+ * Some NEON fpus do not implement IEEE exception handling,
+ * skip these tests if running on them and compiled for
+ * hard float.
+ */
+#define FPU_PREREQ() \
+ if (0 == fpsetmask(fpsetmask(FP_X_INV))) \
+ atf_tc_skip("FPU does not implement exception handling");
+#endif
+
+#ifndef FPU_PREREQ
+#define FPU_PREREQ() /* nothing */
+#endif
void sigfpe(int, siginfo_t *, void *);
@@ -296,6 +308,9 @@ sigfpe(int s, siginfo_t *si, void *c)
\
ATF_TC_BODY(m##_##t, tc) \
{ \
+ \
+ FPU_PREREQ(); \
+ \
if (strcmp(MACHINE, "macppc") == 0) \
atf_tc_expect_fail("PR port-macppc/46319"); \
\
@@ -323,11 +338,13 @@ ATF_TC_BODY(fpsetmask_basic, tc)
size_t i;
fp_except_t msk, lst[] = { FP_X_INV, FP_X_DZ, FP_X_OFL, FP_X_UFL };
+ FPU_PREREQ();
+
msk = fpgetmask();
for (i = 0; i < __arraycount(lst); i++) {
fpsetmask(msk | lst[i]);
ATF_CHECK((fpgetmask() & lst[i]) != 0);
- fpsetmask(msk & lst[i]);
+ fpsetmask(msk & ~lst[i]);
ATF_CHECK((fpgetmask() & lst[i]) == 0);
}
diff --git a/contrib/netbsd-tests/lib/libc/gen/t_ftok.c b/contrib/netbsd-tests/lib/libc/gen/t_ftok.c
index 718d310..4c1ab18 100644
--- a/contrib/netbsd-tests/lib/libc/gen/t_ftok.c
+++ b/contrib/netbsd-tests/lib/libc/gen/t_ftok.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ftok.c,v 1.1 2011/11/08 05:47:00 jruoho Exp $ */
+/* $NetBSD: t_ftok.c,v 1.2 2017/01/10 15:19:52 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_ftok.c,v 1.1 2011/11/08 05:47:00 jruoho Exp $");
+__RCSID("$NetBSD: t_ftok.c,v 1.2 2017/01/10 15:19:52 christos Exp $");
#include <sys/types.h>
#include <sys/ipc.h>
@@ -68,9 +68,7 @@ ATF_TC_BODY(ftok_link, tc)
fd = open(path, O_RDONLY | O_CREAT);
ATF_REQUIRE(fd >= 0);
-#ifdef __FreeBSD__
(void)close(fd);
-#endif
ATF_REQUIRE(link(path, hlnk) == 0);
ATF_REQUIRE(symlink(path, slnk) == 0);
diff --git a/contrib/netbsd-tests/lib/libc/gen/t_humanize_number.c b/contrib/netbsd-tests/lib/libc/gen/t_humanize_number.c
index 5836c86..17eac87 100644
--- a/contrib/netbsd-tests/lib/libc/gen/t_humanize_number.c
+++ b/contrib/netbsd-tests/lib/libc/gen/t_humanize_number.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_humanize_number.c,v 1.8 2012/03/18 07:14:08 jruoho Exp $ */
+/* $NetBSD: t_humanize_number.c,v 1.9 2017/01/10 15:20:44 christos Exp $ */
/*-
* Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
@@ -247,6 +247,7 @@ ATF_TC_BODY(humanize_number_basic, tc)
newline();
atf_tc_fail_nonfatal("Failed for table entry %d", i);
}
+ free(buf);
}
ATF_TC(humanize_number_big);
diff --git a/contrib/netbsd-tests/lib/libc/gen/t_nice.c b/contrib/netbsd-tests/lib/libc/gen/t_nice.c
index 10b8df7..9a0eac7 100644
--- a/contrib/netbsd-tests/lib/libc/gen/t_nice.c
+++ b/contrib/netbsd-tests/lib/libc/gen/t_nice.c
@@ -72,11 +72,6 @@ ATF_TC_BODY(nice_err, tc)
{
int i;
-#ifdef __FreeBSD__
- atf_tc_expect_fail("nice(incr) with incr < 0 fails with unprivileged "
- "users and sets errno == EPERM; see PR # 189821 for more details");
-#endif
-
/*
* The call should fail with EPERM if the
* supplied parameter is negative and the
@@ -130,7 +125,7 @@ ATF_TC_BODY(nice_priority, tc)
if (pid == 0) {
errno = 0;
-#ifdef __FreeBSD__
+#ifdef __NetBSD__
pri = getpriority(PRIO_PROCESS, 0);
#else
pri2 = getpriority(PRIO_PROCESS, 0);
diff --git a/contrib/netbsd-tests/lib/libc/gen/t_randomid.c b/contrib/netbsd-tests/lib/libc/gen/t_randomid.c
index 8377806..9ab2cca 100644
--- a/contrib/netbsd-tests/lib/libc/gen/t_randomid.c
+++ b/contrib/netbsd-tests/lib/libc/gen/t_randomid.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_randomid.c,v 1.3 2011/07/07 09:49:59 jruoho Exp $ */
+/* $NetBSD: t_randomid.c,v 1.5 2015/03/07 09:59:15 isaki Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
#define PERIOD 30000
-uint64_t last[65536];
+uint32_t last[65536];
ATF_TC(randomid_basic);
ATF_TC_HEAD(randomid_basic, tc)
@@ -50,30 +50,30 @@ ATF_TC_HEAD(randomid_basic, tc)
ATF_TC_BODY(randomid_basic, tc)
{
static randomid_t ctx = NULL;
- uint64_t lowest, n, diff;
+ uint32_t lowest, n, diff;
uint16_t id;
memset(last, 0, sizeof(last));
ctx = randomid_new(16, (long)3600);
- lowest = UINT64_MAX;
+ lowest = UINT32_MAX;
- for (n = 0; n < 1000000; n++) {
+ for (n = 0; n < 100000; n++) {
id = randomid(ctx);
if (last[id] > 0) {
diff = n - last[id];
if (diff <= lowest) {
- if (lowest != UINT64_MAX)
- printf("id %5d: last call at %9"PRIu64
- ", current call %9"PRIu64
- " (diff %5"PRIu64"), "
- "lowest %"PRIu64"\n",
+ if (lowest != UINT32_MAX)
+ printf("id %5d: last call at %9"PRIu32
+ ", current call %9"PRIu32
+ " (diff %5"PRIu32"), "
+ "lowest %"PRIu32"\n",
id, last[id], n, diff, lowest);
ATF_REQUIRE_MSG(diff >= PERIOD,
- "diff (%"PRIu64") less than minimum "
+ "diff (%"PRIu32") less than minimum "
"period (%d)", diff, PERIOD);
lowest = diff;
diff --git a/contrib/netbsd-tests/lib/libc/gen/t_siginfo.c b/contrib/netbsd-tests/lib/libc/gen/t_siginfo.c
index 9c9a3c7..64f72ac 100644
--- a/contrib/netbsd-tests/lib/libc/gen/t_siginfo.c
+++ b/contrib/netbsd-tests/lib/libc/gen/t_siginfo.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_siginfo.c,v 1.24 2014/11/04 00:20:19 justin Exp $ */
+/* $NetBSD: t_siginfo.c,v 1.30 2015/12/22 14:25:58 christos Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -46,8 +46,9 @@
#include <setjmp.h>
#include <float.h>
-#ifdef HAVE_FENV
#include <fenv.h>
+#ifdef __HAVE_FENV
+#include <ieeefp.h> /* only need for ARM Cortex/Neon hack */
#elif defined(_FLOAT_IEEE754)
#include <ieeefp.h>
#endif
@@ -316,13 +317,21 @@ ATF_TC_BODY(sigfpe_flt, tc)
atf_tc_skip("Test does not run correctly under QEMU");
#if defined(__powerpc__)
atf_tc_skip("Test not valid on powerpc");
+#elif defined(__arm__) && !__SOFTFP__
+ /*
+ * 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)))
+ atf_tc_skip("FPU does not implement exception handling");
#endif
if (sigsetjmp(sigfpe_flt_env, 0) == 0) {
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = sigfpe_flt_action;
sigemptyset(&sa.sa_mask);
sigaction(SIGFPE, &sa, NULL);
-#ifdef HAVE_FENV
+#ifdef __HAVE_FENV
feenableexcept(FE_ALL_EXCEPT);
#elif defined(_FLOAT_IEEE754)
fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
@@ -373,7 +382,7 @@ ATF_TC_BODY(sigfpe_int, tc)
sa.sa_sigaction = sigfpe_int_action;
sigemptyset(&sa.sa_mask);
sigaction(SIGFPE, &sa, NULL);
-#ifdef HAVE_FENV
+#ifdef __HAVE_FENV
feenableexcept(FE_ALL_EXCEPT);
#elif defined(_FLOAT_IEEE754)
fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
@@ -454,15 +463,19 @@ ATF_TC_BODY(sigbus_adraln, tc)
{
struct sigaction sa;
-#if defined(__alpha__)
+#if defined(__alpha__) || defined(__arm__)
int rv, val;
size_t len = sizeof(val);
rv = sysctlbyname("machdep.unaligned_sigbus", &val, &len, NULL, 0);
ATF_REQUIRE(rv == 0);
if (val == 0)
- atf_tc_skip("SIGBUS signal not enabled for unaligned accesses");
+ atf_tc_skip("No SIGBUS signal for unaligned accesses");
#endif
+ /* m68k (except sun2) never issue SIGBUS (PR lib/49653) */
+ if (strcmp(MACHINE_ARCH, "m68k") == 0)
+ atf_tc_skip("No SIGBUS signal for unaligned accesses");
+
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = sigbus_action;
sigemptyset(&sa.sa_mask);
diff --git a/contrib/netbsd-tests/lib/libc/gen/t_sleep.c b/contrib/netbsd-tests/lib/libc/gen/t_sleep.c
index f722ec9..e85867a 100644
--- a/contrib/netbsd-tests/lib/libc/gen/t_sleep.c
+++ b/contrib/netbsd-tests/lib/libc/gen/t_sleep.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_sleep.c,v 1.8 2014/07/15 14:56:34 gson Exp $ */
+/* $NetBSD: t_sleep.c,v 1.11 2017/01/10 15:43:59 maya Exp $ */
/*-
* Copyright (c) 2006 Frank Kardel
@@ -26,8 +26,18 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#ifdef __FreeBSD__
+/* kqueue(2) on FreeBSD requires sys/types.h for uintptr_t; NetBSD doesn't. */
+#include <sys/types.h>
+#endif
+#include <sys/cdefs.h>
+#include <sys/event.h>
+#include <sys/signal.h>
+#include <sys/time.h> /* for TIMESPEC_TO_TIMEVAL on FreeBSD */
+
#include <atf-c.h>
#include <errno.h>
+#include <inttypes.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
@@ -35,10 +45,6 @@
#include <time.h>
#include <unistd.h>
-#include <sys/cdefs.h>
-#include <sys/event.h>
-#include <sys/signal.h>
-
#include "isqemu.h"
#define BILLION 1000000000LL /* nano-seconds per second */
@@ -49,11 +55,6 @@
#define KEVNT_TIMEOUT 10300 /* measured in milli-seconds */
#define FUZZ (40 * MILLION) /* scheduling fuzz accepted - 40 ms */
-#ifdef __FreeBSD__
-#include <sys/time.h>
-#include <inttypes.h>
-#endif
-
/*
* Timer notes
*
@@ -180,7 +181,8 @@ do_kevent(struct timespec *delay, struct timespec *remain)
(void)close(kq);
if (rtc == -1) {
- ATF_REQUIRE_MSG(kerrno == EINTR, "kevent: %s", strerror(errno));
+ ATF_REQUIRE_MSG(kerrno == EINTR, "kevent: %s",
+ strerror(kerrno));
return 0;
}
diff --git a/contrib/netbsd-tests/lib/libc/gen/t_time.c b/contrib/netbsd-tests/lib/libc/gen/t_time.c
index 790f3ca..15a8d58 100644
--- a/contrib/netbsd-tests/lib/libc/gen/t_time.c
+++ b/contrib/netbsd-tests/lib/libc/gen/t_time.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_time.c,v 1.2 2011/11/11 05:03:38 jruoho Exp $ */
+/* $NetBSD: t_time.c,v 1.4 2017/01/10 15:32:46 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,11 +29,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_time.c,v 1.2 2011/11/11 05:03:38 jruoho Exp $");
+__RCSID("$NetBSD: t_time.c,v 1.4 2017/01/10 15:32:46 christos Exp $");
-#ifdef __FreeBSD__
-#include <sys/time.h>
-#endif
#include <atf-c.h>
#include <errno.h>
#include <inttypes.h>
@@ -41,6 +38,7 @@ __RCSID("$NetBSD: t_time.c,v 1.2 2011/11/11 05:03:38 jruoho Exp $");
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
+#include <sys/time.h>
#include <unistd.h>
ATF_TC(time_copy);
@@ -94,15 +92,16 @@ ATF_TC_HEAD(time_timeofday, tc)
ATF_TC_BODY(time_timeofday, tc)
{
struct timeval tv = { 0, 0 };
- time_t t;
+ time_t t1, t2;
- t = time(NULL);
+ t1 = time(NULL);
ATF_REQUIRE(gettimeofday(&tv, NULL) == 0);
+ t2 = time(NULL);
(void)fprintf(stderr, "%"PRId64" vs. %"PRId64"\n",
- (int64_t)t, (int64_t)tv.tv_sec);
+ (int64_t)t1, (int64_t)tv.tv_sec);
- if (t != tv.tv_sec)
+ if (t1 > tv.tv_sec || t2 < tv.tv_sec)
atf_tc_fail("time(3) and gettimeofday(2) differ");
}
diff --git a/contrib/netbsd-tests/lib/libc/gen/t_ttyname.c b/contrib/netbsd-tests/lib/libc/gen/t_ttyname.c
index 1c813fb..61121b8 100644
--- a/contrib/netbsd-tests/lib/libc/gen/t_ttyname.c
+++ b/contrib/netbsd-tests/lib/libc/gen/t_ttyname.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ttyname.c,v 1.3 2011/05/01 18:14:01 jruoho Exp $ */
+/* $NetBSD: t_ttyname.c,v 1.4 2017/01/10 15:33:40 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_ttyname.c,v 1.3 2011/05/01 18:14:01 jruoho Exp $");
+__RCSID("$NetBSD: t_ttyname.c,v 1.4 2017/01/10 15:33:40 christos Exp $");
#include <atf-c.h>
#include <errno.h>
@@ -78,9 +78,7 @@ ATF_TC_BODY(ttyname_err, tc)
ATF_REQUIRE(ttyname(fd) == NULL);
ATF_REQUIRE(errno == ENOTTY);
-#ifdef __FreeBSD__
(void)close(fd);
-#endif
}
}
diff --git a/contrib/netbsd-tests/lib/libc/gen/t_vis.c b/contrib/netbsd-tests/lib/libc/gen/t_vis.c
index 525bafa..adb0930 100644
--- a/contrib/netbsd-tests/lib/libc/gen/t_vis.c
+++ b/contrib/netbsd-tests/lib/libc/gen/t_vis.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_vis.c,v 1.7 2014/09/08 19:01:03 christos Exp $ */
+/* $NetBSD: t_vis.c,v 1.9 2017/01/10 15:16:57 christos Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -32,6 +32,7 @@
#include <string.h>
#include <stdlib.h>
+#include <locale.h>
#include <err.h>
#include <vis.h>
@@ -143,6 +144,37 @@ ATF_TC_BODY(strunvis_hex, tc)
}
}
+#ifdef VIS_NOLOCALE
+ATF_TC(strvis_locale);
+ATF_TC_HEAD(strvis_locale, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test strvis(3) with locale");
+}
+
+ATF_TC_BODY(strvis_locale, tc)
+{
+ char s[256], cd[sizeof(s) * 4 + 1], jd[sizeof(cd)], *ol;
+ int jr, cr;
+
+ for (size_t i = 0; i < sizeof(s) - 1; i++)
+ s[i] = i + 1;
+ s[sizeof(s) - 1] = '\0';
+
+ ol = setlocale(LC_CTYPE, "ja_JP.UTF-8");
+ ATF_REQUIRE(ol != NULL);
+ jr = strvisx(jd, s, sizeof(s), VIS_WHITE | VIS_NOLOCALE);
+ ATF_REQUIRE(jr != -1);
+ ol = strdup(ol);
+ ATF_REQUIRE(ol != NULL);
+ ATF_REQUIRE(setlocale(LC_CTYPE, "C") != NULL);
+ cr = strvisx(cd, s, sizeof(s), VIS_WHITE);
+ ATF_REQUIRE(jr == cr);
+ ATF_REQUIRE(memcmp(jd, cd, jr) == 0);
+ setlocale(LC_CTYPE, ol);
+ free(ol);
+}
+#endif /* VIS_NOLOCALE */
+
ATF_TP_ADD_TCS(tp)
{
@@ -150,6 +182,9 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, strvis_null);
ATF_TP_ADD_TC(tp, strvis_empty);
ATF_TP_ADD_TC(tp, strunvis_hex);
+#ifdef VIS_NOLOCALE
+ ATF_TP_ADD_TC(tp, strvis_locale);
+#endif /* VIS_NOLOCALE */
return atf_no_error();
}
diff --git a/contrib/netbsd-tests/lib/libc/inet/t_inet_addr.c b/contrib/netbsd-tests/lib/libc/inet/t_inet_addr.c
new file mode 100644
index 0000000..d7547fd
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/inet/t_inet_addr.c
@@ -0,0 +1,109 @@
+/* $NetBSD: t_inet_addr.c,v 1.1 2015/04/09 16:47:56 ginsbach Exp $ */
+
+/*
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ *
+ * 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 <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2011\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_inet_addr.c,v 1.1 2015/04/09 16:47:56 ginsbach Exp $");
+
+#include <arpa/inet.h>
+
+#include <atf-c.h>
+#include <stdio.h>
+#include <string.h>
+
+ATF_TC(inet_addr_basic);
+ATF_TC_HEAD(inet_addr_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks inet_addr(3)");
+}
+
+ATF_TC_BODY(inet_addr_basic, tc)
+{
+ static const char *addrs[] = {
+ "127.0.0.1", "99.99.99.99", "0.0.0.0", "255.255.255.255" };
+
+ struct in_addr ia;
+ const char *ian;
+ in_addr_t addr;
+ size_t i;
+
+ for (i = 0; i < __arraycount(addrs); i++) {
+
+ (void)fprintf(stderr, "checking %s\n", addrs[i]);;
+
+ addr = inet_addr(addrs[i]);
+ ia.s_addr = addr;
+ ian = inet_ntoa(ia);
+
+ ATF_REQUIRE(ian != NULL);
+ ATF_CHECK(strcmp(ian, addrs[i]) == 0);
+ }
+}
+
+ATF_TC(inet_addr_err);
+ATF_TC_HEAD(inet_addr_err, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Invalid addresses with inet_addr(3)");
+}
+
+ATF_TC_BODY(inet_addr_err, tc)
+{
+ static const char *addrs[] = {
+ ". . . .", "1.2.3.", "0.0.0.256", "255.255.255.256",
+ "................................................",
+ "a.b.c.d", "0x0.0x1.0x2.0x3", "-1.-1.-1.-1", "", " "};
+
+ struct in_addr ia;
+ const char *ian;
+ in_addr_t addr;
+ size_t i;
+
+ for (i = 0; i < __arraycount(addrs); i++) {
+
+ (void)fprintf(stderr, "checking %s\n", addrs[i]);;
+
+ addr = inet_addr(addrs[i]);
+ ia.s_addr = addr;
+ ian = inet_ntoa(ia);
+
+ ATF_REQUIRE(ian != NULL);
+ ATF_CHECK(strcmp(ian, addrs[i]) != 0);
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, inet_addr_basic);
+ ATF_TP_ADD_TC(tp, inet_addr_err);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/inet/t_inet_network.c b/contrib/netbsd-tests/lib/libc/inet/t_inet_network.c
index a6a6c62..c44fe11 100644
--- a/contrib/netbsd-tests/lib/libc/inet/t_inet_network.c
+++ b/contrib/netbsd-tests/lib/libc/inet/t_inet_network.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_inet_network.c,v 1.3 2011/07/15 11:27:23 jruoho Exp $ */
+/* $NetBSD: t_inet_network.c,v 1.4 2015/04/09 16:47:56 ginsbach Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -32,79 +32,17 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_inet_network.c,v 1.3 2011/07/15 11:27:23 jruoho Exp $");
+__RCSID("$NetBSD: t_inet_network.c,v 1.4 2015/04/09 16:47:56 ginsbach Exp $");
#include <arpa/inet.h>
#include <atf-c.h>
-#include <stdio.h>
-#include <string.h>
#define H_REQUIRE(input, expected) \
ATF_REQUIRE_EQ_MSG(inet_network(input), (in_addr_t) expected, \
"inet_network(%s) returned: 0x%08X, expected: %s", #input, \
inet_network(input), #expected)
-ATF_TC(inet_addr_basic);
-ATF_TC_HEAD(inet_addr_basic, tc)
-{
- atf_tc_set_md_var(tc, "descr", "Checks inet_addr(3)");
-}
-
-ATF_TC_BODY(inet_addr_basic, tc)
-{
- static const char *addrs[] = {
- "127.0.0.1", "99.99.99.99", "0.0.0.0", "255.255.255.255" };
-
- struct in_addr ia;
- const char *ian;
- in_addr_t addr;
- size_t i;
-
- for (i = 0; i < __arraycount(addrs); i++) {
-
- (void)fprintf(stderr, "checking %s\n", addrs[i]);;
-
- addr = inet_addr(addrs[i]);
- ia.s_addr = addr;
- ian = inet_ntoa(ia);
-
- ATF_REQUIRE(ian != NULL);
- ATF_CHECK(strcmp(ian, addrs[i]) == 0);
- }
-}
-
-ATF_TC(inet_addr_err);
-ATF_TC_HEAD(inet_addr_err, tc)
-{
- atf_tc_set_md_var(tc, "descr", "Invalid addresses with inet_addr(3)");
-}
-
-ATF_TC_BODY(inet_addr_err, tc)
-{
- static const char *addrs[] = {
- ". . . .", "1.2.3.", "0.0.0.256", "255.255.255.256",
- "................................................",
- "a.b.c.d", "0x0.0x1.0x2.0x3", "-1.-1.-1.-1", "", " "};
-
- struct in_addr ia;
- const char *ian;
- in_addr_t addr;
- size_t i;
-
- for (i = 0; i < __arraycount(addrs); i++) {
-
- (void)fprintf(stderr, "checking %s\n", addrs[i]);;
-
- addr = inet_addr(addrs[i]);
- ia.s_addr = addr;
- ian = inet_ntoa(ia);
-
- ATF_REQUIRE(ian != NULL);
- ATF_CHECK(strcmp(ian, addrs[i]) != 0);
- }
-}
-
ATF_TC(inet_network_basic);
ATF_TC_HEAD(inet_network_basic, tc)
{
@@ -165,8 +103,6 @@ ATF_TC_BODY(inet_network_err, tc)
ATF_TP_ADD_TCS(tp)
{
- ATF_TP_ADD_TC(tp, inet_addr_basic);
- ATF_TP_ADD_TC(tp, inet_addr_err);
ATF_TP_ADD_TC(tp, inet_network_basic);
ATF_TP_ADD_TC(tp, inet_network_err);
diff --git a/contrib/netbsd-tests/lib/libc/net/t_servent.sh b/contrib/netbsd-tests/lib/libc/net/t_servent.sh
index 0979eb3..4c23f00 100755
--- a/contrib/netbsd-tests/lib/libc/net/t_servent.sh
+++ b/contrib/netbsd-tests/lib/libc/net/t_servent.sh
@@ -1,4 +1,4 @@
-# $NetBSD: t_servent.sh,v 1.1 2011/01/12 17:32:27 pgoyette Exp $
+# $NetBSD: t_servent.sh,v 1.2 2016/03/08 08:34:17 joerg Exp $
#
# Copyright (c) 2008 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -29,6 +29,8 @@ atf_test_case servent
servent_head()
{
atf_set "descr" "Checks {get,set,end}servent(3)"
+ # libc doesn't include aliases
+ atf_set "require.files" "/var/db/services.cdb"
}
servent_body()
{
diff --git a/contrib/netbsd-tests/lib/libc/rpc/t_rpc.c b/contrib/netbsd-tests/lib/libc/rpc/t_rpc.c
index a9715cf..9c14a22 100644
--- a/contrib/netbsd-tests/lib/libc/rpc/t_rpc.c
+++ b/contrib/netbsd-tests/lib/libc/rpc/t_rpc.c
@@ -1,18 +1,19 @@
-/* $NetBSD: t_rpc.c,v 1.3 2013/02/28 15:56:53 christos Exp $ */
+/* $NetBSD: t_rpc.c,v 1.10 2016/08/27 14:36:22 christos Exp $ */
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_rpc.c,v 1.3 2013/02/28 15:56:53 christos Exp $");
+__RCSID("$NetBSD: t_rpc.c,v 1.10 2016/08/27 14:36:22 christos Exp $");
#include <sys/types.h>
#include <sys/socket.h>
#include <rpc/rpc.h>
#include <stdlib.h>
+#include <string.h>
#include <err.h>
#include <netdb.h>
#include <stdio.h>
+#include <errno.h>
#include <unistd.h>
-
#ifndef TEST
#include <atf-c.h>
@@ -20,17 +21,36 @@ __RCSID("$NetBSD: t_rpc.c,v 1.3 2013/02/28 15:56:53 christos Exp $");
#define SKIPX(ev, msg, ...) do { \
atf_tc_skip(msg, __VA_ARGS__); \
- return; \
+ return ev; \
+} while(/*CONSTCOND*/0)
+
+#ifdef __FreeBSD__
+#define SKIPXI(ev, msg, ...) do { \
+ atf_tc_skip(msg, __VA_ARGS__); \
+ return ev; \
} while(/*CONSTCOND*/0)
+#endif
#else
-#define ERRX(ev, msg, ...) errx(ev, msg, __VA_ARGS__)
-#define SKIPX(ev, msg, ...) errx(ev, msg, __VA_ARGS__)
+#define ERRX(ev, msg, ...) errx(EXIT_FAILURE, msg, __VA_ARGS__)
+#define SKIPX(ev, msg, ...) errx(EXIT_FAILURE, msg, __VA_ARGS__)
+#endif
+
+#ifdef DEBUG
+#define DPRINTF(...) printf(__VA_ARGS__)
+#else
+#define DPRINTF(...)
#endif
#define RPCBPROC_NULL 0
+/* XXX (ngie): for clarity on what needs to be reverted later. */
+#define __FreeBSD_bug_216954__
+#ifdef __FreeBSD_bug_216954__
+#include <signal.h>
+#endif
+
static int
reply(caddr_t replyp, struct netbuf * raddrp, struct netconfig * nconf)
{
@@ -51,7 +71,7 @@ reply(caddr_t replyp, struct netbuf * raddrp, struct netconfig * nconf)
#define __rpc_control rpc_control
#endif
-extern bool __rpc_control(int, void *);
+extern bool_t __rpc_control(int, void *);
static void
onehost(const char *host, const char *transp)
@@ -69,7 +89,7 @@ onehost(const char *host, const char *transp)
__rpc_control(CLCR_SET_RPCB_TIMEOUT, &tv);
if ((clnt = clnt_create(host, RPCBPROG, RPCBVERS, transp)) == NULL)
- SKIPX(EXIT_FAILURE, "clnt_create (%s)", clnt_spcreateerror(""));
+ SKIPX(, "clnt_create (%s)", clnt_spcreateerror(""));
tv.tv_sec = 1;
tv.tv_usec = 0;
@@ -81,14 +101,147 @@ onehost(const char *host, const char *transp)
if (clnt_call(clnt, RPCBPROC_NULL, xdr_void, NULL, xdr_void, NULL, tv)
!= RPC_SUCCESS)
#endif
- ERRX(EXIT_FAILURE, "clnt_call (%s)", clnt_sperror(clnt, ""));
+ ERRX(, "clnt_call (%s)", clnt_sperror(clnt, ""));
clnt_control(clnt, CLGET_SVC_ADDR, (char *) &addr);
reply(NULL, &addr, NULL);
}
+#define PROGNUM 0x81
+#define VERSNUM 0x01
+#define PLUSONE 1
+#define DESTROY 2
+
+static struct timeval tout = {1, 0};
+
+static void
+server(struct svc_req *rqstp, SVCXPRT *transp)
+{
+ int num;
+
+ DPRINTF("Starting server\n");
+
+ switch (rqstp->rq_proc) {
+ case NULLPROC:
+ if (!svc_sendreply(transp, (xdrproc_t)xdr_void, NULL))
+ ERRX(, "svc_sendreply failed %d", 0);
+ return;
+ case PLUSONE:
+ break;
+ case DESTROY:
+ if (!svc_sendreply(transp, (xdrproc_t)xdr_void, NULL))
+ ERRX(, "svc_sendreply failed %d", 0);
+ svc_destroy(transp);
+ exit(0);
+ default:
+ svcerr_noproc(transp);
+ return;
+ }
+
+ if (!svc_getargs(transp, (xdrproc_t)xdr_int, (void *)&num)) {
+ svcerr_decode(transp);
+ return;
+ }
+ DPRINTF("About to increment\n");
+ num++;
+ if (!svc_sendreply(transp, (xdrproc_t)xdr_int, (void *)&num))
+ ERRX(, "svc_sendreply failed %d", 1);
+ DPRINTF("Leaving server procedure.\n");
+}
+
+static int
+rawtest(const char *arg)
+{
+ CLIENT *clnt;
+ SVCXPRT *svc;
+ int num, resp;
+ enum clnt_stat rv;
+
+ if (arg)
+ num = atoi(arg);
+ else
+ num = 0;
+
+ svc = svc_raw_create();
+ if (svc == NULL)
+ ERRX(EXIT_FAILURE, "Cannot create server %d", num);
+ if (!svc_reg(svc, PROGNUM, VERSNUM, server, NULL))
+ ERRX(EXIT_FAILURE, "Cannot register server %d", num);
+
+ clnt = clnt_raw_create(PROGNUM, VERSNUM);
+ if (clnt == NULL)
+ ERRX(EXIT_FAILURE, "%s",
+ clnt_spcreateerror("clnt_raw_create"));
+ rv = clnt_call(clnt, PLUSONE, (xdrproc_t)xdr_int, (void *)&num,
+ (xdrproc_t)xdr_int, (void *)&resp, tout);
+ if (rv != RPC_SUCCESS)
+ ERRX(EXIT_FAILURE, "clnt_call: %s", clnt_sperrno(rv));
+ DPRINTF("Got %d\n", resp);
+ clnt_destroy(clnt);
+ svc_destroy(svc);
+ if (++num != resp)
+ ERRX(EXIT_FAILURE, "expected %d got %d", num, resp);
+
+ return EXIT_SUCCESS;
+}
+
+static int
+regtest(const char *hostname, const char *transp, const char *arg, int p)
+{
+ CLIENT *clnt;
+ int num, resp;
+ enum clnt_stat rv;
+ pid_t pid;
+
+ if (arg)
+ num = atoi(arg);
+ else
+ num = 0;
+
+#ifdef __NetBSD__
+ svc_fdset_init(p ? SVC_FDSET_POLL : 0);
+#endif
+ if (!svc_create(server, PROGNUM, VERSNUM, transp))
+ {
+ SKIPXI(EXIT_FAILURE, "Cannot create server %d", num);
+ }
+
+ switch ((pid = fork())) {
+ case 0:
+ DPRINTF("Calling svc_run\n");
+ svc_run();
+ ERRX(EXIT_FAILURE, "svc_run returned %d!", num);
+ case -1:
+ ERRX(EXIT_FAILURE, "Fork failed (%s)", strerror(errno));
+ default:
+ sleep(1);
+ break;
+ }
+
+ DPRINTF("Initializing client\n");
+ clnt = clnt_create(hostname, PROGNUM, VERSNUM, transp);
+ if (clnt == NULL)
+ ERRX(EXIT_FAILURE, "%s",
+ clnt_spcreateerror("clnt_raw_create"));
+ rv = clnt_call(clnt, PLUSONE, (xdrproc_t)xdr_int, (void *)&num,
+ (xdrproc_t)xdr_int, (void *)&resp, tout);
+ if (rv != RPC_SUCCESS)
+ ERRX(EXIT_FAILURE, "clnt_call: %s", clnt_sperrno(rv));
+ DPRINTF("Got %d\n", resp);
+ if (++num != resp)
+ ERRX(EXIT_FAILURE, "expected %d got %d", num, resp);
+ rv = clnt_call(clnt, DESTROY, (xdrproc_t)xdr_void, NULL,
+ (xdrproc_t)xdr_void, NULL, tout);
+ if (rv != RPC_SUCCESS)
+ ERRX(EXIT_FAILURE, "clnt_call: %s", clnt_sperrno(rv));
+ clnt_destroy(clnt);
+
+ return EXIT_SUCCESS;
+}
+
+
#ifdef TEST
static void
-allhosts(void)
+allhosts(const char *transp)
{
enum clnt_stat clnt_stat;
@@ -103,28 +256,49 @@ int
main(int argc, char *argv[])
{
int ch;
+ int s, p;
const char *transp = "udp";
-
- while ((ch = getopt(argc, argv, "ut")) != -1)
+ p = s = 0;
+ while ((ch = getopt(argc, argv, "prstu")) != -1)
switch (ch) {
+ case 'p':
+ p = 1;
+ break;
+ case 's':
+ s = 1;
+ break;
case 't':
transp = "tcp";
break;
case 'u':
transp = "udp";
break;
+ case 'r':
+ transp = NULL;
+ break;
default:
- fprintf(stderr, "Usage: %s -[t|u] [<hostname>...]\n",
+ fprintf(stderr,
+ "Usage: %s -[r|s|t|u] [<hostname>...]\n",
getprogname());
return EXIT_FAILURE;
}
- if (argc == optind)
- allhosts();
- else
- for (; optind < argc; optind++)
- onehost(argv[optind], transp);
+ if (argc == optind) {
+ if (transp)
+ allhosts(transp);
+ else
+ rawtest(NULL);
+ } else {
+ for (; optind < argc; optind++) {
+ if (transp)
+ s == 0 ?
+ onehost(argv[optind], transp) :
+ regtest(argv[optind], transp, "1", p);
+ else
+ rawtest(argv[optind]);
+ }
+ }
return EXIT_SUCCESS;
}
@@ -156,10 +330,96 @@ ATF_TC_BODY(get_svc_addr_udp, tc)
}
+ATF_TC(raw);
+ATF_TC_HEAD(raw, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks svc raw");
+}
+
+ATF_TC_BODY(raw, tc)
+{
+#ifdef __FreeBSD__
+#ifdef __FreeBSD_bug_216954__
+ atf_tc_expect_signal(SIGSEGV,
+ "fails with SIGSEGV only on ^/stable/10 -- bug # 216954");
+#else
+ atf_tc_expect_fail("fails with: clnt_call: "
+ "RPC: Can't decode result -- PR # 211804");
+#endif
+#endif
+ rawtest(NULL);
+
+}
+
+ATF_TC(tcp);
+ATF_TC_HEAD(tcp, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks svc tcp (select)");
+#ifdef __FreeBSD__
+ atf_tc_set_md_var(tc, "require.user", "root");
+#endif
+}
+
+ATF_TC_BODY(tcp, tc)
+{
+ regtest("localhost", "tcp", "1", 0);
+
+}
+
+ATF_TC(udp);
+ATF_TC_HEAD(udp, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks svc udp (select)");
+#ifdef __FreeBSD__
+ atf_tc_set_md_var(tc, "require.user", "root");
+#endif
+}
+
+ATF_TC_BODY(udp, tc)
+{
+ regtest("localhost", "udp", "1", 0);
+
+}
+
+ATF_TC(tcp_poll);
+ATF_TC_HEAD(tcp_poll, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks svc tcp (poll)");
+#ifdef __FreeBSD__
+ atf_tc_set_md_var(tc, "require.user", "root");
+#endif
+}
+
+ATF_TC_BODY(tcp_poll, tc)
+{
+ regtest("localhost", "tcp", "1", 1);
+
+}
+
+ATF_TC(udp_poll);
+ATF_TC_HEAD(udp_poll, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks svc udp (poll)");
+#ifdef __FreeBSD__
+ atf_tc_set_md_var(tc, "require.user", "root");
+#endif
+}
+
+ATF_TC_BODY(udp_poll, tc)
+{
+ regtest("localhost", "udp", "1", 1);
+
+}
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, get_svc_addr_udp);
ATF_TP_ADD_TC(tp, get_svc_addr_tcp);
+ ATF_TP_ADD_TC(tp, raw);
+ ATF_TP_ADD_TC(tp, tcp);
+ ATF_TP_ADD_TC(tp, udp);
+ ATF_TP_ADD_TC(tp, tcp_poll);
+ ATF_TP_ADD_TC(tp, udp_poll);
return atf_no_error();
}
diff --git a/contrib/netbsd-tests/lib/libc/setjmp/t_setjmp.c b/contrib/netbsd-tests/lib/libc/setjmp/t_setjmp.c
index 4d2a93b..34fd5cc 100644
--- a/contrib/netbsd-tests/lib/libc/setjmp/t_setjmp.c
+++ b/contrib/netbsd-tests/lib/libc/setjmp/t_setjmp.c
@@ -87,7 +87,7 @@ __RCSID("$NetBSD: t_setjmp.c,v 1.1 2010/12/27 19:35:31 pgoyette Exp $");
static int expectsignal;
static void
-aborthandler(int signo)
+aborthandler(int signo __unused)
{
ATF_REQUIRE_MSG(expectsignal, "kill(SIGABRT) succeeded");
atf_tc_pass();
diff --git a/contrib/netbsd-tests/lib/libc/setjmp/t_threadjmp.c b/contrib/netbsd-tests/lib/libc/setjmp/t_threadjmp.c
index 4437c92..2014470 100644
--- a/contrib/netbsd-tests/lib/libc/setjmp/t_threadjmp.c
+++ b/contrib/netbsd-tests/lib/libc/setjmp/t_threadjmp.c
@@ -91,7 +91,7 @@ static pthread_t myself = NULL;
static int expectsignal;
static void
-aborthandler(int signo)
+aborthandler(int signo __unused)
{
ATF_REQUIRE(myself == pthread_self());
ATF_REQUIRE_MSG(expectsignal, "kill(SIGABRT) succeeded");
diff --git a/contrib/netbsd-tests/lib/libc/ssp/t_ssp.sh b/contrib/netbsd-tests/lib/libc/ssp/t_ssp.sh
index 2986ccf..e535e3e 100755
--- a/contrib/netbsd-tests/lib/libc/ssp/t_ssp.sh
+++ b/contrib/netbsd-tests/lib/libc/ssp/t_ssp.sh
@@ -361,6 +361,9 @@ raw_head()
raw_body()
{
prog="$(atf_get_srcdir)/h_raw"
+ # Begin FreeBSD
+ [ -x $prog ] || atf_skip "$prog is missing; skipping testcase"
+ # End FreeBSD
h_pass "$prog 9"
# Begin FreeBSD
diff --git a/contrib/netbsd-tests/lib/libc/stdio/t_open_memstream.c b/contrib/netbsd-tests/lib/libc/stdio/t_open_memstream.c
new file mode 100644
index 0000000..950a258
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdio/t_open_memstream.c
@@ -0,0 +1,96 @@
+/*
+ * Based on the OpenBSD test
+ * Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_open_memstream.c,v 1.2 2014/10/19 11:17:43 justin Exp $");
+
+#include <atf-c.h>
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+ATF_TC(test_open_memstream);
+ATF_TC_HEAD(test_open_memstream, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test open_memstream functionality");
+}
+
+#define OFFSET 16384
+
+const char start[] = "start";
+const char hello[] = "hello";
+
+ATF_TC_BODY(test_open_memstream, tc)
+{
+ FILE *fp;
+ char *buf = (char *)0xff;
+ size_t size = 0;
+ off_t off;
+ int i;
+
+ fp = open_memstream(&buf, &size);
+ ATF_REQUIRE(fp != NULL);
+
+ off = ftello(fp);
+ ATF_CHECK(off == 0);
+
+ ATF_CHECK(fflush(fp) == 0);
+ ATF_CHECK(size == 0);
+ ATF_CHECK(buf != (char *)0xff);
+ ATF_CHECK(fseek(fp, -6, SEEK_SET) == -1);
+ ATF_CHECK(fseek(fp, OFFSET, SEEK_SET) == 0);
+ ATF_CHECK(fprintf(fp, hello) != EOF);
+ ATF_CHECK(fflush(fp) != EOF);
+ ATF_CHECK(size == OFFSET + sizeof(hello)-1);
+ ATF_CHECK(fseek(fp, 0, SEEK_SET) == 0);
+ ATF_CHECK(fprintf(fp, start) != EOF);
+ ATF_CHECK(fflush(fp) != EOF);
+ ATF_CHECK(size == sizeof(start)-1);
+
+ /* Needed for sparse files */
+ ATF_CHECK(strncmp(buf, start, sizeof(start)-1) == 0);
+ for (i = sizeof(start)-1; i < OFFSET; i++)
+ ATF_CHECK(buf[i] == '\0');
+
+ ATF_CHECK(memcmp(buf + OFFSET, hello, sizeof(hello)-1) == 0);
+
+ /* verify that simply seeking past the end doesn't increase the size */
+ ATF_CHECK(fseek(fp, 100, SEEK_END) == 0);
+ ATF_CHECK(fflush(fp) != EOF);
+ ATF_CHECK(size == OFFSET + sizeof(hello)-1);
+ ATF_CHECK(fseek(fp, 8, SEEK_SET) == 0);
+ ATF_CHECK(ftell(fp) == 8);
+
+ /* Try to seek backward */
+ ATF_CHECK(fseek(fp, -1, SEEK_CUR) == 0);
+ ATF_CHECK(ftell(fp) == 7);
+ ATF_CHECK(fseek(fp, 5, SEEK_CUR) == 0);
+ ATF_CHECK(fclose(fp) != EOF);
+ ATF_CHECK(size == 12);
+
+ free(buf);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, test_open_memstream);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_getenv.c b/contrib/netbsd-tests/lib/libc/stdlib/t_getenv.c
index 5a8fa28..7e29778 100644
--- a/contrib/netbsd-tests/lib/libc/stdlib/t_getenv.c
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_getenv.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_getenv.c,v 1.2 2011/07/15 13:54:31 jruoho Exp $ */
+/* $NetBSD: t_getenv.c,v 1.3 2015/02/27 08:55:35 martin Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_getenv.c,v 1.2 2011/07/15 13:54:31 jruoho Exp $");
+__RCSID("$NetBSD: t_getenv.c,v 1.3 2015/02/27 08:55:35 martin Exp $");
#include <atf-c.h>
#include <errno.h>
@@ -123,7 +123,7 @@ ATF_TC_HEAD(setenv_basic, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test setenv(3), getenv(3), unsetenv(3)");
- atf_tc_set_md_var(tc, "timeout", "300");
+ atf_tc_set_md_var(tc, "timeout", "600");
}
ATF_TC_BODY(setenv_basic, tc)
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_posix_memalign.c b/contrib/netbsd-tests/lib/libc/stdlib/t_posix_memalign.c
index 47afb84..8db7880 100644
--- a/contrib/netbsd-tests/lib/libc/stdlib/t_posix_memalign.c
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_posix_memalign.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_posix_memalign.c,v 1.2 2011/07/07 11:12:18 jruoho Exp $ */
+/* $NetBSD: t_posix_memalign.c,v 1.4 2015/11/07 17:35:31 nros Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -32,11 +32,12 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_posix_memalign.c,v 1.2 2011/07/07 11:12:18 jruoho Exp $");
+__RCSID("$NetBSD: t_posix_memalign.c,v 1.4 2015/11/07 17:35:31 nros Exp $");
#include <atf-c.h>
#include <errno.h>
+#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -49,10 +50,10 @@ ATF_TC_HEAD(posix_memalign_basic, tc)
}
ATF_TC_BODY(posix_memalign_basic, tc)
{
- size_t size[] = {
+ static const size_t size[] = {
1, 2, 3, 4, 10, 100, 16384, 32768, 65536
};
- size_t align[] = {
+ static const size_t align[] = {
512, 1024, 16, 32, 64, 4, 2048, 16, 2
};
@@ -63,7 +64,7 @@ ATF_TC_BODY(posix_memalign_basic, tc)
int ret;
p = (void*)0x1;
- (void)printf("Checking posix_memalign(&p, %zd, %zd)...\n",
+ (void)printf("Checking posix_memalign(&p, %zu, %zu)...\n",
align[i], size[i]);
ret = posix_memalign(&p, align[i], size[i]);
@@ -80,9 +81,71 @@ ATF_TC_BODY(posix_memalign_basic, tc)
}
}
+
+ATF_TC(aligned_alloc_basic);
+ATF_TC_HEAD(aligned_alloc_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks aligned_alloc(3)");
+}
+ATF_TC_BODY(aligned_alloc_basic, tc)
+{
+ static const size_t size[] = {
+ 1, 2, 3, 4, 10, 100, 16384, 32768, 65536, 10000, 0
+ };
+ static const size_t align[] = {
+ 512, 1024, 16, 32, 64, 4, 2048, 16, 2, 2048, 0
+ };
+
+ size_t i;
+ void *p;
+
+ for (i = 0; i < __arraycount(size); i++) {
+ (void)printf("Checking aligned_alloc(%zu, %zu)...\n",
+ align[i], size[i]);
+ p = aligned_alloc(align[i], size[i]);
+ if (p == NULL) {
+ if (align[i] == 0 || ((align[i] - 1) & align[i]) != 0 ||
+ size[i] % align[i] != 0) {
+ ATF_REQUIRE_EQ_MSG(errno, EINVAL,
+ "aligned_alloc: %s", strerror(errno));
+ }
+ else {
+ ATF_REQUIRE_EQ_MSG(errno, ENOMEM,
+ "aligned_alloc: %s", strerror(errno));
+ }
+ }
+ else {
+ ATF_REQUIRE_EQ_MSG(align[i] == 0, false,
+ "aligned_alloc: success when alignment was not "
+ "a power of 2");
+ ATF_REQUIRE_EQ_MSG((align[i] - 1) & align[i], 0,
+ "aligned_alloc: success when alignment was not "
+ "a power of 2");
+#ifdef __NetBSD__
+ /*
+ * NetBSD-specific invariant
+ *
+ * From aligned_alloc(3) on FreeBSD:
+ *
+ * Behavior is undefined if size is not an integral
+ * multiple of alignment.
+ */
+ ATF_REQUIRE_EQ_MSG(size[i] % align[i], 0,
+ "aligned_alloc: success when size was not an "
+ "integer multiple of alignment");
+#endif
+ ATF_REQUIRE_EQ_MSG(((intptr_t)p) & (align[i] - 1), 0,
+ "p = %p", p);
+ free(p);
+ }
+ }
+}
+
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, posix_memalign_basic);
-
+ ATF_TP_ADD_TC(tp, aligned_alloc_basic);
+
return atf_no_error();
}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_strtod.c b/contrib/netbsd-tests/lib/libc/stdlib/t_strtod.c
index 8f0f899..06f2de0 100644
--- a/contrib/netbsd-tests/lib/libc/stdlib/t_strtod.c
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_strtod.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strtod.c,v 1.32 2014/11/04 00:20:19 justin Exp $ */
+/* $NetBSD: t_strtod.c,v 1.34 2015/12/22 14:19:25 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
/* Public domain, Otto Moerbeek <otto@drijf.net>, 2006. */
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_strtod.c,v 1.32 2014/11/04 00:20:19 justin Exp $");
+__RCSID("$NetBSD: t_strtod.c,v 1.34 2015/12/22 14:19:25 christos Exp $");
#include <errno.h>
#include <math.h>
@@ -42,9 +42,7 @@ __RCSID("$NetBSD: t_strtod.c,v 1.32 2014/11/04 00:20:19 justin Exp $");
#include <atf-c.h>
-#if defined(__i386__) || defined(__amd64__) || defined(__sparc__)
#include <fenv.h>
-#endif
#if !defined(__vax__)
static const char * const inf_strings[] =
@@ -53,10 +51,6 @@ static const char * const inf_strings[] =
const char *nan_string = "NaN(x)y";
#endif
-#ifdef __FreeBSD__
-#define __HAVE_LONG_DOUBLE
-#endif
-
ATF_TC(strtod_basic);
ATF_TC_HEAD(strtod_basic, tc)
{
@@ -246,7 +240,7 @@ ATF_TC_HEAD(strtod_round, tc)
ATF_TC_BODY(strtod_round, tc)
{
-#if defined(__i386__) || defined(__amd64__) || defined(__sparc__)
+#ifdef __HAVE_FENV
/*
* Test that strtod(3) honors the current rounding mode.
@@ -270,7 +264,7 @@ ATF_TC_BODY(strtod_round, tc)
atf_tc_fail("strtod(3) did not honor fesetround(3)");
}
#else
- atf_tc_skip("Requires one of i386, amd64 or sparc");
+ atf_tc_skip("Requires <fenv.h> support");
#endif
}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_strtoi.c b/contrib/netbsd-tests/lib/libc/stdlib/t_strtoi.c
new file mode 100644
index 0000000..bf958a1
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_strtoi.c
@@ -0,0 +1,304 @@
+/* $NetBSD: t_strtoi.c,v 1.1 2015/05/01 14:17:56 christos Exp $ */
+
+/*-
+ * Copyright (c) 2015 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jukka Ruohonen.
+ *
+ * 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.
+ */
+
+/*
+ * Created by Kamil Rytarowski, vesed on ID:
+ * NetBSD: t_strtol.c,v 1.5 2011/06/14 02:45:58 jruoho Exp
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_strtoi.c,v 1.1 2015/05/01 14:17:56 christos Exp $");
+
+#include <atf-c.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+struct test {
+ const char *str;
+ intmax_t res;
+ int base;
+ const char *end;
+ intmax_t lo;
+ intmax_t hi;
+ int rstatus;
+};
+
+static void check(struct test *, intmax_t, char *, int);
+
+static void
+check(struct test *t, intmax_t rv, char *end, int rstatus)
+{
+
+ if (rv != t->res)
+ atf_tc_fail_nonfatal("strtoi(%s, &end, %d, %jd, %jd, &rstatus)"
+ " failed (rv = %jd)", t->str, t->base, t->lo, t->hi, rv);
+
+ if (rstatus != t->rstatus)
+ atf_tc_fail_nonfatal("strtoi(%s, &end, %d, %jd, %jd, &rstatus)"
+ " failed (rstatus: %d ('%s'))",
+ t->str, t->base, t->lo, t->hi, rstatus, strerror(rstatus));
+
+ if ((t->end != NULL && strcmp(t->end, end) != 0) ||
+ (t->end == NULL && *end != '\0'))
+ atf_tc_fail_nonfatal("invalid end pointer ('%s') from "
+ "strtoi(%s, &end, %d, %jd, %jd, &rstatus)",
+ end, t->str, t->base, t->lo, t->hi);
+}
+
+ATF_TC(strtoi_base);
+ATF_TC_HEAD(strtoi_base, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test strtoi(3) with different bases");
+}
+
+ATF_TC_BODY(strtoi_base, tc)
+{
+ struct test t[] = {
+ { "123456789", 123456789, 0, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "111010110111100110100010101",123456789, 2, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "22121022020212200", 123456789, 3, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "13112330310111", 123456789, 4, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "223101104124", 123456789, 5, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "20130035113", 123456789, 6, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "3026236221", 123456789, 7, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "726746425", 123456789, 8, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "277266780", 123456789, 9, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "123456789", 123456789, 10, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "63762A05", 123456789, 11, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "35418A99", 123456789, 12, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "1C767471", 123456789, 13, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "12579781", 123456789, 14, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "AC89BC9", 123456789, 15, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "75BCD15", 123456789, 16, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "1234567", 342391, 8, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "01234567", 342391, 0, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "0123456789", 123456789, 10, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "0x75bcd15", 123456789, 0, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ };
+
+ intmax_t rv;
+ char *end;
+ int e;
+ size_t i;
+
+ for (i = 0; i < __arraycount(t); i++) {
+
+ errno = 0;
+ rv = strtoi(t[i].str, &end, t[i].base, t[i].lo, t[i].hi, &e);
+
+ if (errno != 0)
+ atf_tc_fail("strtoi(3) changed errno to %d ('%s')",
+ e, strerror(e));
+
+ check(&t[i], rv, end, e);
+ }
+}
+
+ATF_TC(strtoi_case);
+ATF_TC_HEAD(strtoi_case, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Case insensitivity with strtoi(3)");
+}
+
+ATF_TC_BODY(strtoi_case, tc)
+{
+ struct test t[] = {
+ { "abcd", 0xabcd, 16, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { " dcba", 0xdcba, 16, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "abcd dcba", 0xabcd, 16, " dcba",
+ INTMAX_MIN, INTMAX_MAX, ENOTSUP },
+ { "abc0x123", 0xabc0, 16, "x123",
+ INTMAX_MIN, INTMAX_MAX, ENOTSUP },
+ { "abcd\0x123", 0xabcd, 16, "\0x123",
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "ABCD", 0xabcd, 16, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "aBcD", 0xabcd, 16, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "0xABCD", 0xabcd, 16, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "0xABCDX", 0xabcd, 16, "X",
+ INTMAX_MIN, INTMAX_MAX, ENOTSUP},
+ };
+
+ intmax_t rv;
+ char *end;
+ int e;
+ size_t i;
+
+ for (i = 0; i < __arraycount(t); i++) {
+
+ errno = 0;
+ rv = strtoi(t[i].str, &end, t[i].base, t[i].lo, t[i].hi, &e);
+
+ if (errno != 0)
+ atf_tc_fail("strtoi(3) changed errno to %d ('%s')",
+ e, strerror(e));
+
+ check(&t[i], rv, end, e);
+ }
+}
+
+ATF_TC(strtoi_range);
+ATF_TC_HEAD(strtoi_range, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test ERANGE from strtoi(3)");
+}
+
+ATF_TC_BODY(strtoi_range, tc)
+{
+ struct test t[] = {
+#if INTMAX_MAX == 0x7fffffffffffffff
+ { "1000000000000000000000", INTMAX_MAX, 8, NULL,
+ INTMAX_MIN, INTMAX_MAX, ERANGE },
+ { "9223372036854775808", INTMAX_MAX, 10, NULL,
+ INTMAX_MIN, INTMAX_MAX, ERANGE },
+ { "8000000000000000", INTMAX_MAX, 16, NULL,
+ INTMAX_MIN, INTMAX_MAX, ERANGE },
+#else
+#error extend this test to your platform!
+#endif
+ { "10", 1, 10, NULL,
+ -1, 1, ERANGE },
+ { "10", 11, 10, NULL,
+ 11, 20, ERANGE },
+ };
+
+ intmax_t rv;
+ char *end;
+ int e;
+ size_t i;
+
+ for (i = 0; i < __arraycount(t); i++) {
+
+ errno = 0;
+ rv = strtoi(t[i].str, &end, t[i].base, t[i].lo, t[i].hi, &e);
+
+ if (errno != 0)
+ atf_tc_fail("strtoi(3) changed errno to %d ('%s')",
+ e, strerror(e));
+
+ check(&t[i], rv, end, e);
+ }
+}
+
+ATF_TC(strtoi_signed);
+ATF_TC_HEAD(strtoi_signed, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A basic test of strtoi(3)");
+}
+
+ATF_TC_BODY(strtoi_signed, tc)
+{
+ struct test t[] = {
+ { "1", 1, 0, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { " 2", 2, 0, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { " 3", 3, 0, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { " -3", -3, 0, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "--1", 0, 0, "--1",
+ INTMAX_MIN, INTMAX_MAX, ECANCELED },
+ { "+-2", 0, 0, "+-2",
+ INTMAX_MIN, INTMAX_MAX, ECANCELED },
+ { "++3", 0, 0, "++3",
+ INTMAX_MIN, INTMAX_MAX, ECANCELED },
+ { "+9", 9, 0, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "+123", 123, 0, NULL,
+ INTMAX_MIN, INTMAX_MAX, 0 },
+ { "-1 3", -1, 0, " 3",
+ INTMAX_MIN, INTMAX_MAX, ENOTSUP },
+ { "-1.3", -1, 0, ".3",
+ INTMAX_MIN, INTMAX_MAX, ENOTSUP },
+ { "- 3", 0, 0, "- 3",
+ INTMAX_MIN, INTMAX_MAX, ECANCELED },
+ { "+33.", 33, 0, ".",
+ INTMAX_MIN, INTMAX_MAX, ENOTSUP },
+ { "30x0", 30, 0, "x0",
+ INTMAX_MIN, INTMAX_MAX, ENOTSUP },
+ };
+
+ intmax_t rv;
+ char *end;
+ int e;
+ size_t i;
+
+ for (i = 0; i < __arraycount(t); i++) {
+
+ errno = 0;
+ rv = strtoi(t[i].str, &end, t[i].base, t[i].lo, t[i].hi, &e);
+
+ if (errno != 0)
+ atf_tc_fail("strtoi(3) changed errno to %d ('%s')",
+ e, strerror(e));
+
+ check(&t[i], rv, end, e);
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, strtoi_base);
+ ATF_TP_ADD_TC(tp, strtoi_case);
+ ATF_TP_ADD_TC(tp, strtoi_range);
+ ATF_TP_ADD_TC(tp, strtoi_signed);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_strtol.c b/contrib/netbsd-tests/lib/libc/stdlib/t_strtol.c
index 5a0c6d0..54e1907 100644
--- a/contrib/netbsd-tests/lib/libc/stdlib/t_strtol.c
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_strtol.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strtol.c,v 1.5 2011/06/14 02:45:58 jruoho Exp $ */
+/* $NetBSD: t_strtol.c,v 1.6 2016/06/01 01:12:02 pgoyette Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_strtol.c,v 1.5 2011/06/14 02:45:58 jruoho Exp $");
+__RCSID("$NetBSD: t_strtol.c,v 1.6 2016/06/01 01:12:02 pgoyette Exp $");
#include <atf-c.h>
#include <errno.h>
@@ -59,7 +59,8 @@ check(struct test *t, long int li, long long int lli, char *end)
atf_tc_fail_nonfatal("strtoll(%s, NULL, %d) failed "
"(rv = %lld)", t->str, t->base, lli);
- if (t->end != NULL && strcmp(t->end, end) != 0)
+ if ((t->end != NULL && strcmp(t->end, end) != 0) ||
+ (t->end == NULL && *end != '\0'))
atf_tc_fail_nonfatal("invalid end pointer ('%s') from "
"strtol(%s, &end, %d)", end, t->str, t->base);
}
@@ -89,8 +90,8 @@ ATF_TC_BODY(strtol_base, tc)
{ "12579781", 123456789, 14, NULL },
{ "AC89BC9", 123456789, 15, NULL },
{ "75BCD15", 123456789, 16, NULL },
- { "123456789", 342391, 8, NULL },
- { "0123456789", 342391, 0, NULL },
+ { "1234567", 342391, 8, NULL },
+ { "01234567", 342391, 0, NULL },
{ "0123456789", 123456789, 10, NULL },
{ "0x75bcd15", 123456789, 0, NULL },
};
@@ -121,7 +122,7 @@ ATF_TC_BODY(strtol_case, tc)
{ "abcd", 0xabcd, 16, NULL },
{ " dcba", 0xdcba, 16, NULL },
{ "abcd dcba", 0xabcd, 16, " dcba" },
- { "abc0x123", 0xabc0, 16, NULL },
+ { "abc0x123", 0xabc0, 16, "x123" },
{ "abcd\0x123", 0xabcd, 16, "\0x123" },
{ "ABCD", 0xabcd, 16, NULL },
{ "aBcD", 0xabcd, 16, NULL },
diff --git a/contrib/netbsd-tests/lib/libc/string/t_memcpy.c b/contrib/netbsd-tests/lib/libc/string/t_memcpy.c
index 5bbd924..64cdb29 100644
--- a/contrib/netbsd-tests/lib/libc/string/t_memcpy.c
+++ b/contrib/netbsd-tests/lib/libc/string/t_memcpy.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_memcpy.c,v 1.5 2013/03/17 02:23:31 christos Exp $ */
+/* $NetBSD: t_memcpy.c,v 1.6 2017/01/11 18:05:54 christos Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -108,12 +108,8 @@ ATF_TC_BODY(memcpy_basic, tc)
if (i != j)
runTest(start[i], start[j]);
MD5End(mc, result);
-#ifdef __NetBSD__
- ATF_REQUIRE_EQ(strcmp(result, goodResult), 0);
-#else
ATF_REQUIRE_EQ_MSG(strcmp(result, goodResult), 0, "%s != %s",
result, goodResult);
-#endif
}
ATF_TC(memccpy_simple);
diff --git a/contrib/netbsd-tests/lib/libc/string/t_memmem.c b/contrib/netbsd-tests/lib/libc/string/t_memmem.c
index 8734bc3..5bf60ce 100644
--- a/contrib/netbsd-tests/lib/libc/string/t_memmem.c
+++ b/contrib/netbsd-tests/lib/libc/string/t_memmem.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_memmem.c,v 1.2 2011/07/07 08:27:36 jruoho Exp $ */
+/* $NetBSD: t_memmem.c,v 1.3 2017/01/11 18:07:37 christos Exp $ */
/*-
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -51,6 +51,8 @@ char p6[] = "9";
int lp6 = 1;
char p7[] = "654";
int lp7 = 3;
+char p8[] = "89abc";
+int lp8 = 5;
char b0[] = "";
int lb0 = 0;
@@ -75,7 +77,7 @@ ATF_TC_HEAD(memmem_basic, tc)
ATF_TC_BODY(memmem_basic, tc)
{
-#if defined(__darwin__) || defined(__FreeBSD__)
+#if defined(__darwin__)
expect(memmem(b2, lb2, p0, lp0) == NULL);
expect(memmem(b0, lb0, p0, lp0) == NULL);
#else
@@ -94,6 +96,7 @@ ATF_TC_BODY(memmem_basic, tc)
expect(memmem(b2, lb2, p4, lp4) == NULL);
expect(memmem(b2, lb2, p7, lp7) == NULL);
+ expect(memmem(b2, lb2, p8, lp8) == NULL);
}
ATF_TP_ADD_TCS(tp)
diff --git a/contrib/netbsd-tests/lib/libc/string/t_memset.c b/contrib/netbsd-tests/lib/libc/string/t_memset.c
index c1fb385..5a2be28 100644
--- a/contrib/netbsd-tests/lib/libc/string/t_memset.c
+++ b/contrib/netbsd-tests/lib/libc/string/t_memset.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_memset.c,v 1.3 2013/03/17 02:23:31 christos Exp $ */
+/* $NetBSD: t_memset.c,v 1.4 2015/09/11 09:25:52 martin Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_memset.c,v 1.3 2013/03/17 02:23:31 christos Exp $");
+__RCSID("$NetBSD: t_memset.c,v 1.4 2015/09/11 09:25:52 martin Exp $");
#include <sys/stat.h>
@@ -42,6 +42,8 @@ static long page = 0;
static void fill(char *, size_t, char);
static bool check(char *, size_t, char);
+int zero; /* always zero, but the compiler does not know */
+
ATF_TC(memset_array);
ATF_TC_HEAD(memset_array, tc)
{
@@ -133,6 +135,50 @@ ATF_TC_BODY(memset_nonzero, tc)
free(buf);
}
+ATF_TC(memset_zero_size);
+
+ATF_TC_HEAD(memset_zero_size, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test memset(3) with zero size");
+}
+
+ATF_TC_BODY(memset_zero_size, tc)
+{
+ char buf[1024];
+
+ (void)memset(buf, 'x', sizeof(buf));
+
+ if (check(buf, sizeof(buf), 'x') != true)
+ atf_tc_fail("memset(3) did not fill a static buffer");
+
+ (void)memset(buf+sizeof(buf)/2, 0, zero);
+
+ if (check(buf, sizeof(buf), 'x') != true)
+ atf_tc_fail("memset(3) with 0 size did change the buffer");
+}
+
+ATF_TC(bzero_zero_size);
+
+ATF_TC_HEAD(bzero_zero_size, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test bzero(3) with zero size");
+}
+
+ATF_TC_BODY(bzero_zero_size, tc)
+{
+ char buf[1024];
+
+ (void)memset(buf, 'x', sizeof(buf));
+
+ if (check(buf, sizeof(buf), 'x') != true)
+ atf_tc_fail("memset(3) did not fill a static buffer");
+
+ (void)bzero(buf+sizeof(buf)/2, zero);
+
+ if (check(buf, sizeof(buf), 'x') != true)
+ atf_tc_fail("bzero(3) with 0 size did change the buffer");
+}
+
ATF_TC(memset_struct);
ATF_TC_HEAD(memset_struct, tc)
{
@@ -202,6 +248,8 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, memset_nonzero);
ATF_TP_ADD_TC(tp, memset_struct);
ATF_TP_ADD_TC(tp, memset_return);
+ ATF_TP_ADD_TC(tp, memset_zero_size);
+ ATF_TP_ADD_TC(tp, bzero_zero_size);
return atf_no_error();
}
diff --git a/contrib/netbsd-tests/lib/libc/string/t_strchr.c b/contrib/netbsd-tests/lib/libc/string/t_strchr.c
index 4556b2c..5dd9a62 100644
--- a/contrib/netbsd-tests/lib/libc/string/t_strchr.c
+++ b/contrib/netbsd-tests/lib/libc/string/t_strchr.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strchr.c,v 1.1 2011/07/07 08:59:33 jruoho Exp $ */
+/* $NetBSD: t_strchr.c,v 1.2 2017/01/10 15:34:49 christos Exp $ */
/*
* Written by J.T. Conklin <jtc@acorntoolworks.com>
@@ -58,12 +58,10 @@ ATF_TC_HEAD(strchr_basic, tc)
ATF_TC_BODY(strchr_basic, tc)
{
-#ifdef __FreeBSD__
void *dl_handle;
-#endif
- unsigned int t, a;
char *off;
char buf[32];
+ unsigned int t, a;
const char *tab[] = {
"",
@@ -248,12 +246,8 @@ ATF_TC_BODY(strchr_basic, tc)
"abcdefgh/abcdefgh/",
};
-#ifdef __FreeBSD__
dl_handle = dlopen(NULL, RTLD_LAZY);
strchr_fn = dlsym(dl_handle, "test_strlen");
-#else
- strchr_fn = dlsym(dlopen(0, RTLD_LAZY), "test_strchr");
-#endif
if (!strchr_fn)
strchr_fn = strchr;
@@ -288,9 +282,7 @@ ATF_TC_BODY(strchr_basic, tc)
verify_strchr(buf + a, 0xff, t, a);
}
}
-#ifdef __FreeBSD__
(void)dlclose(dl_handle);
-#endif
}
ATF_TP_ADD_TCS(tp)
diff --git a/contrib/netbsd-tests/lib/libc/string/t_strerror.c b/contrib/netbsd-tests/lib/libc/string/t_strerror.c
index 888a826..99b95b4 100644
--- a/contrib/netbsd-tests/lib/libc/string/t_strerror.c
+++ b/contrib/netbsd-tests/lib/libc/string/t_strerror.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strerror.c,v 1.3 2011/05/10 06:55:27 jruoho Exp $ */
+/* $NetBSD: t_strerror.c,v 1.4 2017/01/10 20:35:49 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,18 +29,15 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_strerror.c,v 1.3 2011/05/10 06:55:27 jruoho Exp $");
+__RCSID("$NetBSD: t_strerror.c,v 1.4 2017/01/10 20:35:49 christos Exp $");
#include <atf-c.h>
#include <errno.h>
+#include <stdio.h> /* Needed for sys_nerr on FreeBSD */
#include <limits.h>
#include <locale.h>
#include <string.h>
-#ifdef __FreeBSD__
-#include <stdio.h>
-#endif
-
ATF_TC(strerror_basic);
ATF_TC_HEAD(strerror_basic, tc)
{
diff --git a/contrib/netbsd-tests/lib/libc/sync/cpp_atomic_ops_linkable.cc b/contrib/netbsd-tests/lib/libc/sync/cpp_atomic_ops_linkable.cc
new file mode 100644
index 0000000..e7822b7
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/sync/cpp_atomic_ops_linkable.cc
@@ -0,0 +1,107 @@
+/* $NetBSD: cpp_atomic_ops_linkable.cc,v 1.5 2017/01/11 12:10:26 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Martin Husemann <martin@NetBSD.org>.
+ *
+ * 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.
+ */
+
+/*
+ * This is a simple link-time test to verify all builtin atomic sync
+ * operations for C++ <atomic> are available.
+ */
+
+#include <atomic>
+#include <machine/types.h> // for __HAVE_ATOMIC64_OPS
+
+template <class T>
+class ATest {
+public:
+ ATest() : m_val(0)
+ {
+ m_val.exchange(std::atomic<T>(8));
+ m_val--;
+ m_val++;
+ m_val ^= 0x0f;
+ m_val &= 0x0f;
+ m_val |= 2;
+
+ T tval(1), other(42);
+ m_val.compare_exchange_weak(tval, other,
+ std::memory_order_release, std::memory_order_relaxed);
+ }
+
+private:
+ volatile std::atomic<T> m_val;
+};
+
+int main(int argc, char **argv)
+{
+ ATest<char>();
+ ATest<signed char>();
+ ATest<unsigned char>();
+ ATest<short>();
+ ATest<unsigned short>();
+ ATest<int>();
+ ATest<unsigned int>();
+ ATest<long>();
+ ATest<unsigned long>();
+#ifdef __HAVE_ATOMIC64_OPS
+ ATest<long long>();
+ ATest<unsigned long long>();
+#endif
+ ATest<char16_t>();
+ ATest<char32_t>();
+ ATest<wchar_t>();
+ ATest<int_least8_t>();
+ ATest<uint_least8_t>();
+ ATest<int_least16_t>();
+ ATest<uint_least16_t>();
+ ATest<int_least32_t>();
+ ATest<uint_least32_t>();
+#ifdef __HAVE_ATOMIC64_OPS
+ ATest<int_least64_t>();
+ ATest<uint_least64_t>();
+#endif
+ ATest<int_fast8_t>();
+ ATest<uint_fast8_t>();
+ ATest<int_fast16_t>();
+ ATest<uint_fast16_t>();
+ ATest<int_fast32_t>();
+ ATest<uint_fast32_t>();
+#ifdef __HAVE_ATOMIC64_OPS
+ ATest<int_fast64_t>();
+ ATest<uint_fast64_t>();
+#endif
+ ATest<intptr_t>();
+ ATest<uintptr_t>();
+ ATest<std::size_t>();
+ ATest<std::ptrdiff_t>();
+#ifdef __HAVE_ATOMIC64_OPS
+ ATest<intmax_t>();
+ ATest<uintmax_t>();
+#endif
+}
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_access.c b/contrib/netbsd-tests/lib/libc/sys/t_access.c
index 69d2df2..c537eca 100644
--- a/contrib/netbsd-tests/lib/libc/sys/t_access.c
+++ b/contrib/netbsd-tests/lib/libc/sys/t_access.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_access.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $ */
+/* $NetBSD: t_access.c,v 2.2 2017/01/10 22:36:29 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,15 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_access.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $");
+__RCSID("$NetBSD: t_access.c,v 1.2 2017/01/10 22:36:29 christos Exp $");
+
+#ifdef __FreeBSD__
+#include <sys/param.h> /* For __FreeBSD_version */
+#endif
+
+#include <atf-c.h>
+
+#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
@@ -38,13 +46,6 @@ __RCSID("$NetBSD: t_access.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $");
#include <stdlib.h>
#include <unistd.h>
-#include <atf-c.h>
-
-#ifdef __FreeBSD__
-#include <sys/param.h>
-#include <sys/stat.h>
-#endif
-
static const char path[] = "access";
static const int mode[4] = { R_OK, W_OK, X_OK, F_OK };
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_bind.c b/contrib/netbsd-tests/lib/libc/sys/t_bind.c
new file mode 100644
index 0000000..0c6027c
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/sys/t_bind.c
@@ -0,0 +1,78 @@
+/* $NetBSD: t_bind.c,v 1.3 2015/04/05 23:28:10 rtr Exp $ */
+/*
+ * Copyright (c) 2015 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <unistd.h>
+
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+#include <atf-c.h>
+
+ATF_TC(bind_foreign_family);
+
+ATF_TC_HEAD(bind_foreign_family, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks that binding a socket "
+ "with a different address family fails");
+}
+
+ATF_TC_BODY(bind_foreign_family, tc)
+{
+ struct sockaddr_in addr;
+
+ /* addr.sin_family = AF_UNSPEC = 0 */
+ memset(&addr, 0, sizeof(addr));
+
+ /*
+ * it is not necessary to initialize sin_{addr,port} since
+ * those structure members shall not be accessed if bind
+ * fails correctly.
+ */
+
+ int sock = socket(AF_LOCAL, SOCK_STREAM, 0);
+ ATF_REQUIRE(sock != -1);
+
+ /* should fail but currently doesn't */
+ ATF_REQUIRE(-1 == bind(sock, (struct sockaddr *)&addr, sizeof(addr)));
+ ATF_REQUIRE(EAFNOSUPPORT == errno);
+
+ close(sock);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, bind_foreign_family);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_chroot.c b/contrib/netbsd-tests/lib/libc/sys/t_chroot.c
index 651dc10..1f1c49b 100644
--- a/contrib/netbsd-tests/lib/libc/sys/t_chroot.c
+++ b/contrib/netbsd-tests/lib/libc/sys/t_chroot.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_chroot.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $ */
+/* $NetBSD: t_chroot.c,v 1.2 2017/01/10 22:36:29 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,9 +29,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_chroot.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $");
+__RCSID("$NetBSD: t_chroot.c,v 1.2 2017/01/10 22:36:29 christos Exp $");
#include <sys/wait.h>
+#include <sys/stat.h>
#include <atf-c.h>
#include <errno.h>
@@ -42,10 +43,6 @@ __RCSID("$NetBSD: t_chroot.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $");
#include <string.h>
#include <unistd.h>
-#ifdef __FreeBSD__
-#include <sys/stat.h>
-#endif
-
ATF_TC(chroot_basic);
ATF_TC_HEAD(chroot_basic, tc)
{
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_clock_nanosleep.c b/contrib/netbsd-tests/lib/libc/sys/t_clock_nanosleep.c
new file mode 100644
index 0000000..8c1fd03
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/sys/t_clock_nanosleep.c
@@ -0,0 +1,63 @@
+/* $NetBSD: t_clock_nanosleep.c,v 1.1 2016/11/11 15:30:44 njoly Exp $ */
+
+/*-
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_clock_nanosleep.c,v 1.1 2016/11/11 15:30:44 njoly Exp $");
+
+#include <atf-c.h>
+#include <time.h>
+
+ATF_TC(clock_nanosleep_remain);
+ATF_TC_HEAD(clock_nanosleep_remain, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Check clock_nanosleep(2) remaining time");
+}
+
+ATF_TC_BODY(clock_nanosleep_remain, tc)
+{
+ struct timespec rqtp, rmtp;
+
+ rqtp.tv_sec = 0; rqtp.tv_nsec = 0;
+ rmtp.tv_sec = -1; rmtp.tv_nsec = -1;
+ ATF_REQUIRE(clock_nanosleep(CLOCK_REALTIME, 0, &rqtp, &rmtp) == 0);
+ ATF_CHECK(rmtp.tv_sec == 0 && rmtp.tv_nsec == 0);
+
+ ATF_REQUIRE(clock_gettime(CLOCK_REALTIME, &rqtp) == 0);
+ rmtp.tv_sec = -1; rmtp.tv_nsec = -1;
+ ATF_REQUIRE(clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &rqtp, &rmtp) == 0);
+ ATF_CHECK(rmtp.tv_sec == -1 && rmtp.tv_nsec == -1);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, clock_nanosleep_remain);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_connect.c b/contrib/netbsd-tests/lib/libc/sys/t_connect.c
index 896b490..672a022 100644
--- a/contrib/netbsd-tests/lib/libc/sys/t_connect.c
+++ b/contrib/netbsd-tests/lib/libc/sys/t_connect.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_connect.c,v 1.1 2011/11/05 18:19:02 jruoho Exp $ */
+/* $NetBSD: t_connect.c,v 1.2 2015/04/05 23:17:41 rtr Exp $ */
/*
* Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -102,10 +102,39 @@ ATF_TC_BODY(connect_low_port, tc)
#endif
}
+ATF_TC(connect_foreign_family);
+ATF_TC_HEAD(connect_foreign_family, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks that connecting a socket "
+ "with a different address family fails");
+}
+ATF_TC_BODY(connect_foreign_family, tc)
+{
+ struct sockaddr_in addr;
+
+ /* addr.sin_family = AF_UNSPEC = 0 */
+ memset(&addr, 0, sizeof(addr));
+
+ /*
+ * it is not necessary to initialize sin_{addr,port} since
+ * those structure members shall not be accessed if connect
+ * fails correctly.
+ */
+
+ int sock = socket(AF_LOCAL, SOCK_STREAM, 0);
+ ATF_REQUIRE(sock != -1);
+
+ ATF_REQUIRE(-1 == connect(sock, (struct sockaddr *)&addr, sizeof(addr)));
+ ATF_REQUIRE(EAFNOSUPPORT == errno);
+
+ close(sock);
+}
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, connect_low_port);
+ ATF_TP_ADD_TC(tp, connect_foreign_family);
return atf_no_error();
}
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_getcontext.c b/contrib/netbsd-tests/lib/libc/sys/t_getcontext.c
index 46c0ff1..9f21b3e 100644
--- a/contrib/netbsd-tests/lib/libc/sys/t_getcontext.c
+++ b/contrib/netbsd-tests/lib/libc/sys/t_getcontext.c
@@ -53,6 +53,10 @@ run(int n, ...)
va_start(va, n);
#if defined(__FreeBSD__) && defined(__amd64__)
for (i = 0; i < 5; i++) {
+#elif defined(__FreeBSD__) && defined(__aarch64__)
+ for (i = 0; i < 7; i++) {
+#elif defined(__FreeBSD__) && defined(__mips__)
+ for (i = 0; i < 5; i++) {
#else
for (i = 0; i < 9; i++) {
#endif
@@ -116,6 +120,14 @@ ATF_TC_BODY(setcontext_link, tc)
/* FreeBSD/amd64 only permits up to 6 arguments. */
makecontext(&uc[i], (void *)run, 6, i,
0, 1, 2, 3, 4);
+#elif defined(__FreeBSD__) && defined(__aarch64__)
+ /* FreeBSD/arm64 only permits up to 8 arguments. */
+ makecontext(&uc[i], (void *)run, 8, i,
+ 0, 1, 2, 3, 4, 5, 6);
+#elif defined(__FreeBSD__) && defined(__mips__)
+ /* FreeBSD/mips only permits up to 6 arguments. */
+ makecontext(&uc[i], (void *)run, 6, i,
+ 0, 1, 2, 3, 4);
#else
makecontext(&uc[i], (void *)run, 10, i,
0, 1, 2, 3, 4, 5, 6, 7, 8);
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_getrusage.c b/contrib/netbsd-tests/lib/libc/sys/t_getrusage.c
index 85eeac6..f4ee96b 100644
--- a/contrib/netbsd-tests/lib/libc/sys/t_getrusage.c
+++ b/contrib/netbsd-tests/lib/libc/sys/t_getrusage.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_getrusage.c,v 1.3 2014/09/03 19:24:12 matt Exp $ */
+/* $NetBSD: t_getrusage.c,v 1.4 2016/08/05 15:01:39 scole Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_getrusage.c,v 1.3 2014/09/03 19:24:12 matt Exp $");
+__RCSID("$NetBSD: t_getrusage.c,v 1.4 2016/08/05 15:01:39 scole Exp $");
#include <sys/resource.h>
#include <sys/time.h>
@@ -56,6 +56,10 @@ sighandler(int signo)
/* Nothing. */
}
+#ifdef __FreeBSD__
+#define asm __asm
+#endif
+
static void
work(void)
{
@@ -64,6 +68,8 @@ work(void)
while (n > 0) {
#ifdef __or1k__
asm volatile("l.nop"); /* Do something. */
+#elif defined(__ia64__)
+ asm volatile("nop 0"); /* Do something. */
#else
asm volatile("nop"); /* Do something. */
#endif
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_getsockname.c b/contrib/netbsd-tests/lib/libc/sys/t_getsockname.c
new file mode 100644
index 0000000..01b1f8a
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/sys/t_getsockname.c
@@ -0,0 +1,82 @@
+/* $NetBSD: t_getsockname.c,v 1.1 2016/07/30 11:03:54 njoly Exp $ */
+/*
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+ATF_TC(getsockname_unix);
+
+ATF_TC_HEAD(getsockname_unix, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks getsockname with UNIX domain");
+}
+
+ATF_TC_BODY(getsockname_unix, tc)
+{
+ const char *path = "sock.unix";
+ int sd;
+ socklen_t len;
+ struct sockaddr_un sun;
+
+ sd = socket(AF_UNIX, SOCK_STREAM, 0);
+ ATF_REQUIRE(sd != -1);
+
+ len = sizeof(sun);
+ memset(&sun, 0, sizeof(sun));
+ ATF_REQUIRE(getsockname(sd, (struct sockaddr *)&sun, &len) != -1);
+ ATF_CHECK(sun.sun_family == AF_UNIX);
+ ATF_CHECK(strcmp(sun.sun_path, "") == 0);
+
+ len = sizeof(sun);
+ memset(&sun, 0, sizeof(sun));
+ sun.sun_family = AF_UNIX;
+ strcpy(sun.sun_path, path);
+ ATF_REQUIRE(bind(sd, (struct sockaddr *)&sun, len) != -1);
+
+ len = sizeof(sun);
+ memset(&sun, 0, sizeof(sun));
+ ATF_REQUIRE(getsockname(sd, (struct sockaddr *)&sun, &len) != -1);
+ ATF_CHECK(sun.sun_family == AF_UNIX);
+ ATF_CHECK(strcmp(sun.sun_path, path) == 0);
+
+ ATF_REQUIRE(close(sd) != -1);
+ ATF_REQUIRE(unlink(path) != -1);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, getsockname_unix);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_kevent.c b/contrib/netbsd-tests/lib/libc/sys/t_kevent.c
index c2fef44..8a20d63 100644
--- a/contrib/netbsd-tests/lib/libc/sys/t_kevent.c
+++ b/contrib/netbsd-tests/lib/libc/sys/t_kevent.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_kevent.c,v 1.6 2012/11/29 09:13:44 martin Exp $ */
+/* $NetBSD: t_kevent.c,v 1.7 2015/02/05 13:55:37 isaki Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_kevent.c,v 1.6 2012/11/29 09:13:44 martin Exp $");
+__RCSID("$NetBSD: t_kevent.c,v 1.7 2015/02/05 13:55:37 isaki Exp $");
#include <sys/types.h>
#include <sys/event.h>
@@ -182,8 +182,14 @@ ATF_TC_BODY(kqueue_unsupported_fd, tc)
struct kevent ev;
fd = open(DRVCTLDEV, O_RDONLY);
- if (fd == -1 && errno == ENOENT)
- atf_tc_skip("no " DRVCTLDEV " available for testing");
+ if (fd == -1) {
+ switch (errno) {
+ case ENOENT:
+ case ENXIO:
+ atf_tc_skip("no " DRVCTLDEV " available for testing");
+ break;
+ }
+ }
ATF_REQUIRE(fd != -1);
ATF_REQUIRE((kq = kqueue()) != -1);
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_mincore.c b/contrib/netbsd-tests/lib/libc/sys/t_mincore.c
index c31170f..ab8c33f 100644
--- a/contrib/netbsd-tests/lib/libc/sys/t_mincore.c
+++ b/contrib/netbsd-tests/lib/libc/sys/t_mincore.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mincore.c,v 1.8 2012/06/08 07:18:58 martin Exp $ */
+/* $NetBSD: t_mincore.c,v 1.9 2017/01/10 22:36:29 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -59,9 +59,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_mincore.c,v 1.8 2012/06/08 07:18:58 martin Exp $");
+__RCSID("$NetBSD: t_mincore.c,v 1.9 2017/01/10 22:36:29 christos Exp $");
#include <sys/mman.h>
+#include <sys/stat.h>
#include <sys/shm.h>
#include <atf-c.h>
@@ -74,10 +75,6 @@ __RCSID("$NetBSD: t_mincore.c,v 1.8 2012/06/08 07:18:58 martin Exp $");
#include <unistd.h>
#include <sys/resource.h>
-#ifdef __FreeBSD__
-#include <sys/stat.h>
-#endif
-
static long page = 0;
static const char path[] = "mincore";
static size_t check_residency(void *, size_t);
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_mlock.c b/contrib/netbsd-tests/lib/libc/sys/t_mlock.c
index 85d82c7..dcfba2b 100644
--- a/contrib/netbsd-tests/lib/libc/sys/t_mlock.c
+++ b/contrib/netbsd-tests/lib/libc/sys/t_mlock.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mlock.c,v 1.5 2014/02/26 20:49:26 martin Exp $ */
+/* $NetBSD: t_mlock.c,v 1.6 2016/08/09 12:02:44 kre Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_mlock.c,v 1.5 2014/02/26 20:49:26 martin Exp $");
+__RCSID("$NetBSD: t_mlock.c,v 1.6 2016/08/09 12:02:44 kre Exp $");
#ifdef __FreeBSD__
#include <sys/types.h>
@@ -50,86 +50,13 @@ __RCSID("$NetBSD: t_mlock.c,v 1.5 2014/02/26 20:49:26 martin Exp $");
#include <limits.h>
#define _KMEMUSER
#include <machine/vmparam.h>
+
+void set_vm_max_wired(int);
+void restore_vm_max_wired(void);
#endif
static long page = 0;
-#ifdef __FreeBSD__
-#define VM_MAX_WIRED "vm.max_wired"
-
-static void
-vm_max_wired_sysctl(int *old_value, int *new_value)
-{
- size_t old_len;
- size_t new_len = (new_value == NULL ? 0 : sizeof(int));
-
- if (old_value == NULL)
- printf("Setting the new value to %d\n", *new_value);
- else {
- ATF_REQUIRE_MSG(sysctlbyname(VM_MAX_WIRED, NULL, &old_len,
- new_value, new_len) == 0,
- "sysctlbyname(%s) failed: %s", VM_MAX_WIRED, strerror(errno));
- }
-
- ATF_REQUIRE_MSG(sysctlbyname(VM_MAX_WIRED, old_value, &old_len,
- new_value, new_len) == 0,
- "sysctlbyname(%s) failed: %s", VM_MAX_WIRED, strerror(errno));
-
- if (old_value != NULL)
- printf("Saved the old value (%d)\n", *old_value);
-}
-
-static void
-set_vm_max_wired(int new_value)
-{
- FILE *fp;
- int old_value;
-
- fp = fopen(VM_MAX_WIRED, "w");
- if (fp == NULL) {
- atf_tc_skip("could not open %s for writing: %s",
- VM_MAX_WIRED, strerror(errno));
- return;
- }
-
- vm_max_wired_sysctl(&old_value, NULL);
-
- ATF_REQUIRE_MSG(fprintf(fp, "%d", old_value) > 0,
- "saving %s failed", VM_MAX_WIRED);
-
- fclose(fp);
-
- vm_max_wired_sysctl(NULL, &new_value);
-}
-
-static void
-restore_vm_max_wired(void)
-{
- FILE *fp;
- int saved_max_wired;
-
- fp = fopen(VM_MAX_WIRED, "r");
- if (fp == NULL) {
- perror("fopen failed\n");
- return;
- }
-
- if (fscanf(fp, "%d", &saved_max_wired) != 1) {
- perror("fscanf failed\n");
- fclose(fp);
- return;
- }
-
- fclose(fp);
- printf("old value in %s: %d\n", VM_MAX_WIRED, saved_max_wired);
-
- if (saved_max_wired == 0) /* This will cripple the test host */
- return;
-
- vm_max_wired_sysctl(NULL, &saved_max_wired);
-}
-#endif
-
ATF_TC(mlock_clip);
ATF_TC_HEAD(mlock_clip, tc)
{
@@ -178,6 +105,7 @@ ATF_TC_BODY(mlock_err, tc)
#endif
void *invalid_ptr;
int null_errno = ENOMEM; /* error expected for NULL */
+ void *buf;
#ifdef __FreeBSD__
#ifdef VM_MIN_ADDRESS
@@ -189,28 +117,48 @@ ATF_TC_BODY(mlock_err, tc)
#else
if (sysctlbyname("vm.minaddress", &vmin, &len, NULL, 0) != 0)
atf_tc_fail("failed to read vm.minaddress");
+ /*
+ * Any bad address must return ENOMEM (for lock & unlock)
+ */
+ errno = 0;
+ ATF_REQUIRE_ERRNO(ENOMEM, mlock(NULL, page) == -1);
if (vmin > 0)
null_errno = EINVAL; /* NULL is not inside user VM */
#endif
errno = 0;
- ATF_REQUIRE_ERRNO(null_errno, mlock(NULL, page) == -1);
+ ATF_REQUIRE_ERRNO(ENOMEM, mlock((char *)0, page) == -1);
errno = 0;
- ATF_REQUIRE_ERRNO(null_errno, mlock((char *)0, page) == -1);
+ ATF_REQUIRE_ERRNO(ENOMEM, mlock((char *)-1, page) == -1);
errno = 0;
- ATF_REQUIRE_ERRNO(EINVAL, mlock((char *)-1, page) == -1);
+ ATF_REQUIRE_ERRNO(ENOMEM, munlock(NULL, page) == -1);
errno = 0;
- ATF_REQUIRE_ERRNO(null_errno, munlock(NULL, page) == -1);
+ ATF_REQUIRE_ERRNO(ENOMEM, munlock((char *)0, page) == -1);
errno = 0;
- ATF_REQUIRE_ERRNO(null_errno, munlock((char *)0, page) == -1);
+ ATF_REQUIRE_ERRNO(ENOMEM, munlock((char *)-1, page) == -1);
+
+ buf = malloc(page);
+ ATF_REQUIRE(buf != NULL);
+
+ /*
+ * unlocking memory that is not locked is an error...
+ */
errno = 0;
- ATF_REQUIRE_ERRNO(EINVAL, munlock((char *)-1, page) == -1);
+ ATF_REQUIRE_ERRNO(ENOMEM, munlock(buf, page) == -1);
+
+ /*
+ * These are permitted to fail (EINVAL) but do not on NetBSD
+ */
+ ATF_REQUIRE(mlock((void *)(((uintptr_t)buf) + page/3), page/5) == 0);
+ ATF_REQUIRE(munlock((void *)(((uintptr_t)buf) + page/3), page/5) == 0);
+
+ (void)free(buf);
/*
* Try to create a pointer to an unmapped page - first after current
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_mmap.c b/contrib/netbsd-tests/lib/libc/sys/t_mmap.c
index 5d821ec..738758c 100644
--- a/contrib/netbsd-tests/lib/libc/sys/t_mmap.c
+++ b/contrib/netbsd-tests/lib/libc/sys/t_mmap.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mmap.c,v 1.7 2012/06/14 17:47:58 bouyer Exp $ */
+/* $NetBSD: t_mmap.c,v 1.10 2017/01/10 22:36:29 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -55,10 +55,11 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_mmap.c,v 1.7 2012/06/14 17:47:58 bouyer Exp $");
+__RCSID("$NetBSD: t_mmap.c,v 1.10 2017/01/10 22:36:29 christos Exp $");
#include <sys/param.h>
#include <sys/mman.h>
+#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <sys/wait.h>
@@ -78,7 +79,6 @@ __RCSID("$NetBSD: t_mmap.c,v 1.7 2012/06/14 17:47:58 bouyer Exp $");
#ifdef __FreeBSD__
#include <sys/disklabel.h>
-#include <sys/stat.h>
#include <stdint.h>
#endif
@@ -381,9 +381,13 @@ ATF_TC_BODY(mmap_prot_3, tc)
* the access should generate SIGSEGV.
*/
fd = open(path, O_RDWR | O_CREAT, 0700);
-
if (fd < 0)
+#ifdef __FreeBSD__
+ atf_tc_skip("opening %s failed; skipping testcase: %s",
+ path, strerror(errno));
+#else
return;
+#endif
ATF_REQUIRE(write(fd, "XXX", 3) == 3);
ATF_REQUIRE(close(fd) == 0);
@@ -409,6 +413,9 @@ ATF_TC_BODY(mmap_prot_3, tc)
ATF_REQUIRE(WIFEXITED(sta) != 0);
ATF_REQUIRE(WEXITSTATUS(sta) == SIGSEGV);
ATF_REQUIRE(munmap(map, 3) == 0);
+#ifdef __FreeBSD__
+ (void)close(fd);
+#endif
}
ATF_TC_CLEANUP(mmap_prot_3, tc)
@@ -453,6 +460,9 @@ ATF_TC_BODY(mmap_truncate, tc)
ATF_REQUIRE(ftruncate(fd, page / 12) == 0);
ATF_REQUIRE(ftruncate(fd, page / 64) == 0);
+#ifdef __FreeBSD__
+ (void)munmap(map, page);
+#endif
ATF_REQUIRE(close(fd) == 0);
}
@@ -461,6 +471,76 @@ ATF_TC_CLEANUP(mmap_truncate, tc)
(void)unlink(path);
}
+ATF_TC_WITH_CLEANUP(mmap_truncate_signal);
+ATF_TC_HEAD(mmap_truncate_signal, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test mmap(2) ftruncate(2) causing signal");
+}
+
+ATF_TC_BODY(mmap_truncate_signal, tc)
+{
+ char *map;
+ long i;
+ int fd, sta;
+ pid_t pid;
+
+#ifdef __FreeBSD__
+ atf_tc_expect_fail("testcase fails with SIGSEGV on FreeBSD; bug # 211924");
+#endif
+
+ fd = open(path, O_RDWR | O_CREAT, 0700);
+
+ if (fd < 0)
+ return;
+
+ ATF_REQUIRE(write(fd, "foo\n", 5) == 5);
+
+ map = mmap(NULL, page, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0);
+ ATF_REQUIRE(map != MAP_FAILED);
+
+ sta = 0;
+ for (i = 0; i < 5; i++)
+ sta += map[i];
+ ATF_REQUIRE(sta == 334);
+
+ ATF_REQUIRE(ftruncate(fd, 0) == 0);
+ pid = fork();
+ ATF_REQUIRE(pid >= 0);
+
+ if (pid == 0) {
+ ATF_REQUIRE(signal(SIGBUS, map_sighandler) != SIG_ERR);
+ ATF_REQUIRE(signal(SIGSEGV, map_sighandler) != SIG_ERR);
+ sta = 0;
+ for (i = 0; i < page; i++)
+ sta += map[i];
+ /* child never will get this far, but the compiler will
+ not know, so better use the values calculated to
+ prevent the access to be optimized out */
+ ATF_REQUIRE(i == 0);
+ ATF_REQUIRE(sta == 0);
+#ifdef __FreeBSD__
+ (void)munmap(map, page);
+ (void)close(fd);
+#endif
+ return;
+ }
+
+ (void)wait(&sta);
+
+ ATF_REQUIRE(WIFEXITED(sta) != 0);
+ if (WEXITSTATUS(sta) == SIGSEGV)
+ atf_tc_fail("child process got SIGSEGV instead of SIGBUS");
+ ATF_REQUIRE(WEXITSTATUS(sta) == SIGBUS);
+ ATF_REQUIRE(munmap(map, page) == 0);
+ ATF_REQUIRE(close(fd) == 0);
+}
+
+ATF_TC_CLEANUP(mmap_truncate_signal, tc)
+{
+ (void)unlink(path);
+}
+
ATF_TC(mmap_va0);
ATF_TC_HEAD(mmap_va0, tc)
{
@@ -518,6 +598,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, mmap_prot_2);
ATF_TP_ADD_TC(tp, mmap_prot_3);
ATF_TP_ADD_TC(tp, mmap_truncate);
+ ATF_TP_ADD_TC(tp, mmap_truncate_signal);
ATF_TP_ADD_TC(tp, mmap_va0);
return atf_no_error();
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_mprotect.c b/contrib/netbsd-tests/lib/libc/sys/t_mprotect.c
index ee345aa..5dc3eae 100644
--- a/contrib/netbsd-tests/lib/libc/sys/t_mprotect.c
+++ b/contrib/netbsd-tests/lib/libc/sys/t_mprotect.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mprotect.c,v 1.3 2011/07/20 22:53:44 jym Exp $ */
+/* $NetBSD: t_mprotect.c,v 1.4 2016/05/28 14:34:49 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_mprotect.c,v 1.3 2011/07/20 22:53:44 jym Exp $");
+__RCSID("$NetBSD: t_mprotect.c,v 1.4 2016/05/28 14:34:49 christos Exp $");
#include <sys/param.h>
#include <sys/mman.h>
@@ -78,10 +78,7 @@ paxinit(void)
rv = sysctlbyname("security.pax.mprotect.enabled",
&pax_enabled, &len, NULL, 0);
- if (rv != 0)
- return false;
-
- return paxset(1, 1);
+ return rv == 0;
}
static bool
@@ -194,6 +191,12 @@ ATF_TC_BODY(mprotect_exec, tc)
break;
}
+ if (!paxinit())
+ return;
+ if (pax_enabled == 1 && pax_global == 1)
+ atf_tc_skip("PaX MPROTECT restrictions enabled");
+
+
/*
* Map a page read/write and copy a trivial assembly function inside.
* We will then change the mapping rights:
@@ -262,7 +265,7 @@ ATF_TC_BODY(mprotect_pax, tc)
size_t i;
int rv;
- if (paxinit() != true)
+ if (!paxinit() || !paxset(1, 1))
return;
/*
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_posix_fallocate.c b/contrib/netbsd-tests/lib/libc/sys/t_posix_fallocate.c
new file mode 100644
index 0000000..b931ebd
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/sys/t_posix_fallocate.c
@@ -0,0 +1,63 @@
+/* $NetBSD: t_posix_fallocate.c,v 1.1 2015/01/31 23:06:57 christos Exp $ */
+
+/*-
+ * Copyright 2015, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Google nor the names of its contributors may
+ * be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_posix_fallocate.c,v 1.1 2015/01/31 23:06:57 christos Exp $");
+
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+ATF_TC_WITHOUT_HEAD(ebadf);
+ATF_TC_BODY(ebadf, tc)
+{
+ int rc, saved;
+
+ errno = 1111;
+ rc = posix_fallocate(-1, 0, 4096);
+ saved = errno;
+ if (rc == -1 && saved != 1111)
+ atf_tc_fail("Should return error %s without setting errno.",
+ strerror(saved));
+ if (rc != EBADF)
+ atf_tc_fail("returned %s but expected %s.",
+ strerror(saved), strerror(EBADF));
+ if (saved != 1111)
+ atf_tc_fail("errno should be %d but got changed to %d.",
+ 1111, saved);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, ebadf);
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c b/contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c
index 4b21860..31db878 100644
--- a/contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c
+++ b/contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_setrlimit.c,v 1.4 2012/06/12 23:56:19 christos Exp $ */
+/* $NetBSD: t_setrlimit.c,v 1.5 2016/07/13 09:53:16 njoly Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_setrlimit.c,v 1.4 2012/06/12 23:56:19 christos Exp $");
+__RCSID("$NetBSD: t_setrlimit.c,v 1.5 2016/07/13 09:53:16 njoly Exp $");
#include <sys/resource.h>
#include <sys/mman.h>
@@ -50,6 +50,11 @@ __RCSID("$NetBSD: t_setrlimit.c,v 1.4 2012/06/12 23:56:19 christos Exp $");
#include <ucontext.h>
#include <unistd.h>
+#ifdef __FreeBSD__
+void set_vm_max_wired(int);
+void restore_vm_max_wired(void);
+#endif
+
static void sighandler(int);
static const char path[] = "setrlimit";
@@ -238,10 +243,18 @@ sighandler(int signo)
_exit(EXIT_SUCCESS);
}
+#ifdef __FreeBSD__
+ATF_TC_WITH_CLEANUP(setrlimit_memlock);
+#else
ATF_TC(setrlimit_memlock);
+#endif
ATF_TC_HEAD(setrlimit_memlock, tc)
{
atf_tc_set_md_var(tc, "descr", "Test setrlimit(2), RLIMIT_MEMLOCK");
+#ifdef __FreeBSD__
+ atf_tc_set_md_var(tc, "require.config", "allow_sysctl_side_effects");
+ atf_tc_set_md_var(tc, "require.user", "root");
+#endif
}
ATF_TC_BODY(setrlimit_memlock, tc)
@@ -252,6 +265,11 @@ ATF_TC_BODY(setrlimit_memlock, tc)
pid_t pid;
int sta;
+#ifdef __FreeBSD__
+ /* Set max_wired really really high to avoid EAGAIN */
+ set_vm_max_wired(INT_MAX);
+#endif
+
page = sysconf(_SC_PAGESIZE);
ATF_REQUIRE(page >= 0);
@@ -295,6 +313,14 @@ ATF_TC_BODY(setrlimit_memlock, tc)
atf_tc_fail("RLIMIT_MEMLOCK not enforced");
}
+#ifdef __FreeBSD__
+ATF_TC_CLEANUP(setrlimit_memlock, tc)
+{
+
+ restore_vm_max_wired();
+}
+#endif
+
ATF_TC(setrlimit_nofile_1);
ATF_TC_HEAD(setrlimit_nofile_1, tc)
{
@@ -515,6 +541,25 @@ ATF_TC_BODY(setrlimit_perm, tc)
}
}
+ATF_TC(setrlimit_stack);
+ATF_TC_HEAD(setrlimit_stack, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test setrlimit(2), RLIMIT_STACK");
+ atf_tc_set_md_var(tc, "require.user", "unprivileged");
+}
+
+ATF_TC_BODY(setrlimit_stack, tc)
+{
+ struct rlimit res;
+
+ /* Ensure soft limit is not bigger than hard limit */
+ res.rlim_cur = res.rlim_max = 4192256;
+ ATF_REQUIRE(setrlimit(RLIMIT_STACK, &res) == 0);
+ ATF_REQUIRE(getrlimit(RLIMIT_STACK, &res) == 0);
+ ATF_CHECK(res.rlim_cur <= res.rlim_max);
+
+}
+
ATF_TP_ADD_TCS(tp)
{
@@ -530,6 +575,7 @@ ATF_TP_ADD_TCS(tp)
#ifdef __NetBSD__
ATF_TP_ADD_TC(tp, setrlimit_nthr);
#endif
+ ATF_TP_ADD_TC(tp, setrlimit_stack);
return atf_no_error();
}
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c b/contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c
index 6686f02..e911d42 100644
--- a/contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c
+++ b/contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_sigqueue.c,v 1.4 2011/07/07 16:31:11 jruoho Exp $ */
+/* $NetBSD: t_sigqueue.c,v 1.6 2016/08/04 06:43:43 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -30,8 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_sigqueue.c,v 1.4 2011/07/07 16:31:11 jruoho Exp $");
-
+__RCSID("$NetBSD: t_sigqueue.c,v 1.6 2016/08/04 06:43:43 christos Exp $");
#include <atf-c.h>
#include <errno.h>
@@ -40,6 +39,11 @@ __RCSID("$NetBSD: t_sigqueue.c,v 1.4 2011/07/07 16:31:11 jruoho Exp $");
#include <sched.h>
#include <unistd.h>
+#ifdef __FreeBSD__
+#include <err.h>
+#include <stdio.h>
+#endif
+
static void handler(int, siginfo_t *, void *);
#define VALUE (int)0xc001dad1
@@ -77,7 +81,7 @@ ATF_TC_BODY(sigqueue_basic, tc)
sv.sival_int = VALUE;
#ifdef __FreeBSD__
- /*
+ /*
* From kern_sig.c:
* Specification says sigqueue can only send signal to single process.
*/
@@ -99,17 +103,158 @@ ATF_TC_HEAD(sigqueue_err, tc)
ATF_TC_BODY(sigqueue_err, tc)
{
- union sigval sv;
+ static union sigval sv;
errno = 0;
ATF_REQUIRE_ERRNO(EINVAL, sigqueue(getpid(), -1, sv) == -1);
}
+static int signals[] = {
+ SIGINT, SIGRTMIN + 1, SIGINT, SIGRTMIN + 0, SIGRTMIN + 2,
+ SIGQUIT, SIGRTMIN + 1
+};
+#ifdef __arraycount
+#define CNT __arraycount(signals)
+#else
+#define CNT (sizeof(signals) / sizeof(signals[0]))
+#endif
+
+static sig_atomic_t count = 0;
+static int delivered[CNT];
+
+static void
+myhandler(int signo, siginfo_t *info, void *context)
+{
+ delivered[count++] = signo;
+#ifdef __FreeBSD__
+ printf("Signal #%zu: signo: %d\n", (size_t)count, signo);
+#endif
+}
+
+static int
+asc(const void *a, const void *b)
+{
+ const int *ia = a, *ib = b;
+ return *ib - *ia;
+}
+
+/*
+ * given a array of signals to be delivered in tosend of size len
+ * place in ordered the signals to be delivered in delivery order
+ * and return the number of signals that should be delivered
+ */
+static size_t
+sigorder(int *ordered, const int *tosend, size_t len)
+{
+ memcpy(ordered, tosend, len * sizeof(*tosend));
+ qsort(ordered, len, sizeof(*ordered), asc);
+ if (len == 1)
+ return len;
+
+#ifdef __FreeBSD__
+ /*
+ * Don't dedupe signal numbers (bug 212173)
+ *
+ * Per kib's comment..
+ *
+ * "
+ * OTOH, FreeBSD behaviour is to treat all signals as realtime while
+ * there is no mem shortage and siginfo can be allocated. In
+ * particular, signals < SIGRTMIN are not collapsed when queued more
+ * than once.
+ * "
+ */
+
+ return len;
+#else
+
+ size_t i, j;
+ for (i = 0, j = 0; i < len - 1; i++) {
+ if (ordered[i] >= SIGRTMIN)
+ continue;
+ if (j == 0)
+ j = i + 1;
+ while (ordered[i] == ordered[j] && j < len)
+ j++;
+ if (j == len)
+ break;
+ ordered[i + 1] = ordered[j];
+ }
+ return i + 1;
+#endif
+}
+
+ATF_TC(sigqueue_rt);
+ATF_TC_HEAD(sigqueue_rt, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test queuing of real-time signals");
+}
+
+ATF_TC_BODY(sigqueue_rt, tc)
+{
+ pid_t pid;
+ union sigval val;
+ struct sigaction act;
+ int ordered[CNT];
+ struct sigaction oact[CNT];
+ size_t ndelivered;
+
+ ndelivered = sigorder(ordered, signals, CNT);
+
+ act.sa_flags = SA_SIGINFO;
+ act.sa_sigaction = myhandler;
+ sigemptyset(&act.sa_mask);
+ for (size_t i = 0; i < ndelivered; i++)
+ ATF_REQUIRE(sigaction(ordered[i], &act, &oact[i]) != -1);
+
+ val.sival_int = 0;
+ pid = getpid();
+
+ sigset_t mask, orig;
+ sigemptyset(&mask);
+ for (size_t i = 0; i < CNT; i++)
+#ifdef __FreeBSD__
+ if (sigaddset(&mask, signals[i]) == -1)
+ warn("sigaddset");
+#else
+ sigaddset(&mask, signals[i]);
+#endif
+
+ ATF_REQUIRE(sigprocmask(SIG_BLOCK, &mask, &orig) != -1);
+
+ for (size_t i = 0; i < CNT; i++)
+ ATF_REQUIRE(sigqueue(pid, signals[i], val) != -1);
+
+ ATF_REQUIRE(sigprocmask(SIG_UNBLOCK, &mask, &orig) != -1);
+ sleep(1);
+#ifdef __FreeBSD__
+ ATF_CHECK_MSG((size_t)count == ndelivered,
+ "count %zu != ndelivered %zu", (size_t)count, ndelivered);
+#else
+ ATF_REQUIRE_MSG((size_t)count == ndelivered,
+ "count %zu != ndelivered %zu", (size_t)count, ndelivered);
+#endif
+ for (size_t i = 0; i < ndelivered; i++)
+ ATF_REQUIRE_MSG(ordered[i] == delivered[i],
+ "%zu: ordered %d != delivered %d",
+ i, ordered[i], delivered[i]);
+
+#ifdef __FreeBSD__
+ if (count > ndelivered)
+ for (size_t i = ndelivered; i < count; i++)
+ printf("Undelivered signal #%zu: %d\n", i, ordered[i]);
+#endif
+
+ for (size_t i = 0; i < ndelivered; i++)
+ ATF_REQUIRE(sigaction(signals[i], &oact[i], NULL) != -1);
+}
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, sigqueue_basic);
ATF_TP_ADD_TC(tp, sigqueue_err);
+ ATF_TP_ADD_TC(tp, sigqueue_rt);
return atf_no_error();
}
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_timer_create.c b/contrib/netbsd-tests/lib/libc/sys/t_timer_create.c
index cc85307..364daaa 100644
--- a/contrib/netbsd-tests/lib/libc/sys/t_timer_create.c
+++ b/contrib/netbsd-tests/lib/libc/sys/t_timer_create.c
@@ -116,6 +116,61 @@ timer_signal_create(clockid_t cid, bool expire)
ATF_REQUIRE(timer_delete(t) == 0);
}
+#ifdef __FreeBSD__
+static void
+timer_callback(union sigval value)
+{
+ timer_t *tp;
+
+ tp = value.sival_ptr;
+
+ if (*tp == t)
+ fail = false;
+}
+
+static void
+timer_thread_create(clockid_t cid, bool expire)
+{
+ struct itimerspec tim;
+ struct sigevent evt;
+
+ t = 0;
+ fail = true;
+
+ (void)memset(&evt, 0, sizeof(struct sigevent));
+ (void)memset(&tim, 0, sizeof(struct itimerspec));
+
+ /*
+ * Create the timer (SIGEV_THREAD).
+ */
+ evt.sigev_notify_function = timer_callback;
+ evt.sigev_value.sival_ptr = &t;
+ evt.sigev_notify = SIGEV_THREAD;
+
+ ATF_REQUIRE(timer_create(cid, &evt, &t) == 0);
+
+ /*
+ * Start the timer.
+ */
+ tim.it_value.tv_sec = expire ? 5 : 1;
+ tim.it_value.tv_nsec = 0;
+
+ ATF_REQUIRE(timer_settime(t, 0, &tim, NULL) == 0);
+
+ (void)sleep(2);
+
+ if (expire) {
+ if (!fail)
+ atf_tc_fail("timer fired too soon");
+ } else {
+ if (fail)
+ atf_tc_fail("timer failed to fire");
+ }
+
+ ATF_REQUIRE(timer_delete(t) == 0);
+}
+#endif
+
ATF_TC(timer_create_err);
ATF_TC_HEAD(timer_create_err, tc)
{
@@ -198,6 +253,64 @@ ATF_TC_BODY(timer_create_mono_expire, tc)
timer_signal_create(CLOCK_MONOTONIC, true);
}
+ATF_TC(timer_thread_create_real);
+ATF_TC_HEAD(timer_thread_create_real, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks timer_create(2) with CLOCK_REALTIME and sigevent(3), "
+ "SIGEV_THREAD");
+}
+
+#ifdef __FreeBSD__
+ATF_TC_BODY(timer_thread_create_real, tc)
+{
+ timer_thread_create(CLOCK_REALTIME, false);
+}
+
+ATF_TC(timer_thread_create_mono);
+ATF_TC_HEAD(timer_thread_create_mono, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks timer_create(2) with CLOCK_MONOTONIC and sigevent(3), "
+ "SIGEV_THREAD");
+}
+
+ATF_TC_BODY(timer_thread_create_mono, tc)
+{
+ timer_thread_create(CLOCK_MONOTONIC, false);
+}
+
+ATF_TC(timer_thread_create_real_expire);
+ATF_TC_HEAD(timer_thread_create_real_expire, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks timer_create(2) with CLOCK_REALTIME and sigevent(3), "
+ "SIGEV_THREAD, with expiration");
+}
+
+ATF_TC_BODY(timer_thread_create_real_expire, tc)
+{
+ timer_thread_create(CLOCK_REALTIME, true);
+}
+
+ATF_TC(timer_thread_create_mono_expire);
+ATF_TC_HEAD(timer_thread_create_mono_expire, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks timer_create(2) with CLOCK_MONOTONIC and sigevent(3), "
+ "SIGEV_THREAD, with expiration");
+}
+
+ATF_TC_BODY(timer_thread_create_mono_expire, tc)
+{
+ timer_thread_create(CLOCK_MONOTONIC, true);
+}
+#endif
+
ATF_TP_ADD_TCS(tp)
{
@@ -206,6 +319,12 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, timer_create_mono);
ATF_TP_ADD_TC(tp, timer_create_real_expire);
ATF_TP_ADD_TC(tp, timer_create_mono_expire);
+#ifdef __FreeBSD__
+ ATF_TP_ADD_TC(tp, timer_thread_create_real);
+ ATF_TP_ADD_TC(tp, timer_thread_create_mono);
+ ATF_TP_ADD_TC(tp, timer_thread_create_real_expire);
+ ATF_TP_ADD_TC(tp, timer_thread_create_mono_expire);
+#endif
return atf_no_error();
}
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_wait.c b/contrib/netbsd-tests/lib/libc/sys/t_wait.c
new file mode 100644
index 0000000..8653265
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/sys/t_wait.c
@@ -0,0 +1,323 @@
+/* $NetBSD: t_wait.c,v 1.7 2016/11/06 15:04:14 kamil Exp $ */
+
+/*-
+ * Copyright (c) 2016 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 <sys/cdefs.h>
+__RCSID("$NetBSD: t_wait.c,v 1.7 2016/11/06 15:04:14 kamil Exp $");
+
+#include <sys/wait.h>
+#include <sys/resource.h>
+
+#include <stdio.h>
+#include <errno.h>
+#include <limits.h>
+#include <pwd.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+#ifdef __FreeBSD__
+#define wrusage __wrusage
+#endif
+
+ATF_TC(wait6_invalid);
+ATF_TC_HEAD(wait6_invalid, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that wait6(2) returns EINVAL with 0 options");
+}
+
+ATF_TC_BODY(wait6_invalid, tc)
+{
+ siginfo_t si;
+ struct wrusage wru;
+ int st;
+ ATF_REQUIRE(wait6(P_ALL, 0, &st, 0, &wru, &si) == -1
+ && errno == EINVAL);
+}
+
+ATF_TC(wait6_exited);
+ATF_TC_HEAD(wait6_exited, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that wait6(2) handled exiting process and code");
+}
+
+ATF_TC_BODY(wait6_exited, tc)
+{
+ siginfo_t si;
+ struct wrusage wru;
+ int st;
+ pid_t pid;
+
+ switch (pid = fork()) {
+ case -1:
+ ATF_REQUIRE(pid > 0);
+ case 0:
+ exit(0x5a5a5a5a);
+ /*NOTREACHED*/
+ default:
+ ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid);
+ ATF_REQUIRE(WIFEXITED(st) && WEXITSTATUS(st) == 0x5a);
+ ATF_REQUIRE(si.si_status = 0x5a5a5a5a);
+ ATF_REQUIRE(si.si_pid == pid);
+ ATF_REQUIRE(si.si_uid == getuid());
+ ATF_REQUIRE(si.si_code == CLD_EXITED);
+#ifdef __NetBSD__
+ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime,
+ (uintmax_t)si.si_utime);
+#endif
+ break;
+ }
+}
+
+ATF_TC(wait6_terminated);
+ATF_TC_HEAD(wait6_terminated, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that wait6(2) handled terminated process and code");
+}
+
+ATF_TC_BODY(wait6_terminated, tc)
+{
+ siginfo_t si;
+ struct wrusage wru;
+ int st;
+ pid_t pid;
+
+ switch (pid = fork()) {
+ case 0:
+ sleep(100);
+ /*FALLTHROUGH*/
+ case -1:
+ ATF_REQUIRE(pid > 0);
+ default:
+ ATF_REQUIRE(kill(pid, SIGTERM) == 0);
+ ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid);
+ ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGTERM);
+ ATF_REQUIRE(si.si_status == SIGTERM);
+ ATF_REQUIRE(si.si_pid == pid);
+ ATF_REQUIRE(si.si_uid == getuid());
+ ATF_REQUIRE(si.si_code == CLD_KILLED);
+#ifdef __NetBSD__
+ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime,
+ (uintmax_t)si.si_utime);
+#endif
+ break;
+ }
+}
+
+ATF_TC(wait6_coredumped);
+ATF_TC_HEAD(wait6_coredumped, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that wait6(2) handled coredumped process and code");
+}
+
+ATF_TC_BODY(wait6_coredumped, tc)
+{
+ siginfo_t si;
+ struct wrusage wru;
+ int st;
+ pid_t pid;
+ static const struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY };
+
+ switch (pid = fork()) {
+ case 0:
+ ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0);
+ *(char *)8 = 0;
+ /*FALLTHROUGH*/
+ case -1:
+ ATF_REQUIRE(pid > 0);
+ default:
+ ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid);
+ ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGSEGV
+ && WCOREDUMP(st));
+ ATF_REQUIRE(si.si_status == SIGSEGV);
+ ATF_REQUIRE(si.si_pid == pid);
+ ATF_REQUIRE(si.si_uid == getuid());
+ ATF_REQUIRE(si.si_code == CLD_DUMPED);
+#ifdef __NetBSD__
+ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime,
+ (uintmax_t)si.si_utime);
+#endif
+ break;
+ }
+}
+
+ATF_TC(wait6_stop_and_go);
+ATF_TC_HEAD(wait6_stop_and_go, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that wait6(2) handled stopped/continued process and code");
+}
+
+ATF_TC_BODY(wait6_stop_and_go, tc)
+{
+ siginfo_t si;
+ struct wrusage wru;
+ int st;
+ pid_t pid;
+ static const struct rlimit rl = { 0, 0 };
+
+ ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0);
+ switch (pid = fork()) {
+ case 0:
+ sleep(100);
+ /*FALLTHROUGH*/
+ case -1:
+ ATF_REQUIRE(pid > 0);
+ default:
+ ATF_REQUIRE(kill(pid, SIGSTOP) == 0);
+ ATF_REQUIRE(wait6(P_PID, pid, &st, WSTOPPED, &wru, &si) == pid);
+ ATF_REQUIRE(!WIFEXITED(st));
+ ATF_REQUIRE(!WIFSIGNALED(st));
+ ATF_REQUIRE(WIFSTOPPED(st) && WSTOPSIG(st) == SIGSTOP);
+ ATF_REQUIRE(!WIFCONTINUED(st));
+ ATF_REQUIRE(si.si_status == SIGSTOP);
+ ATF_REQUIRE(si.si_pid == pid);
+ ATF_REQUIRE(si.si_uid == getuid());
+ ATF_REQUIRE(si.si_code == CLD_STOPPED);
+#ifdef __NetBSD__
+ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime,
+ (uintmax_t)si.si_utime);
+#endif
+
+ ATF_REQUIRE(kill(pid, SIGCONT) == 0);
+ ATF_REQUIRE(wait6(P_PID, pid, &st, WCONTINUED, &wru, &si) == pid);
+ ATF_REQUIRE(!WIFEXITED(st));
+ ATF_REQUIRE(!WIFSIGNALED(st));
+ ATF_REQUIRE(WIFCONTINUED(st));
+ ATF_REQUIRE(!WIFSTOPPED(st));
+ ATF_REQUIRE(si.si_status == SIGCONT);
+ ATF_REQUIRE(si.si_pid == pid);
+ ATF_REQUIRE(si.si_uid == getuid());
+ ATF_REQUIRE(si.si_code == CLD_CONTINUED);
+#ifdef __NetBSD__
+ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime,
+ (uintmax_t)si.si_utime);
+#endif
+
+ ATF_REQUIRE(kill(pid, SIGQUIT) == 0);
+ ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid);
+ ATF_REQUIRE(!WIFEXITED(st));
+ ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGQUIT);
+ ATF_REQUIRE(!WIFSTOPPED(st));
+ ATF_REQUIRE(!WIFCONTINUED(st));
+ ATF_REQUIRE(si.si_status == SIGQUIT);
+ ATF_REQUIRE(si.si_pid == pid);
+ ATF_REQUIRE(si.si_uid == getuid());
+ ATF_REQUIRE(si.si_code == CLD_KILLED);
+#ifdef __NetBSD__
+ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime,
+ (uintmax_t)si.si_utime);
+#endif
+ break;
+ }
+}
+
+ATF_TC(wait6_stopgo_loop);
+ATF_TC_HEAD(wait6_stopgo_loop, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that wait6(2) handled stopped/continued process loop");
+}
+
+ATF_TC_BODY(wait6_stopgo_loop, tc)
+{
+ siginfo_t si;
+ struct wrusage wru;
+ int st;
+ pid_t pid;
+ static const struct rlimit rl = { 0, 0 };
+ size_t N = 100;
+
+ ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0);
+ switch (pid = fork()) {
+ case 0:
+ sleep(100);
+ /*FALLTHROUGH*/
+ case -1:
+ ATF_REQUIRE(pid > 0);
+ }
+
+ printf("Before loop of SIGSTOP/SIGCONT sequence %zu times\n", N);
+ while (N --> 0) {
+ ATF_REQUIRE(kill(pid, SIGSTOP) == 0);
+ ATF_REQUIRE(wait6(P_PID, pid, &st, WSTOPPED, &wru, &si) == pid);
+ ATF_REQUIRE(!WIFEXITED(st));
+ ATF_REQUIRE(!WIFSIGNALED(st));
+ ATF_REQUIRE(WIFSTOPPED(st) && WSTOPSIG(st) == SIGSTOP);
+ ATF_REQUIRE(!WIFCONTINUED(st));
+ ATF_REQUIRE(si.si_status == SIGSTOP);
+ ATF_REQUIRE(si.si_pid == pid);
+ ATF_REQUIRE(si.si_uid == getuid());
+ ATF_REQUIRE(si.si_code == CLD_STOPPED);
+
+ ATF_REQUIRE(kill(pid, SIGCONT) == 0);
+ ATF_REQUIRE(wait6(P_PID, pid, &st, WCONTINUED, &wru, &si) == pid);
+ ATF_REQUIRE(!WIFEXITED(st));
+ ATF_REQUIRE(!WIFSIGNALED(st));
+ ATF_REQUIRE(WIFCONTINUED(st));
+ ATF_REQUIRE(!WIFSTOPPED(st));
+ ATF_REQUIRE(si.si_status == SIGCONT);
+ ATF_REQUIRE(si.si_pid == pid);
+ ATF_REQUIRE(si.si_uid == getuid());
+ ATF_REQUIRE(si.si_code == CLD_CONTINUED);
+ }
+ ATF_REQUIRE(kill(pid, SIGQUIT) == 0);
+ ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid);
+ ATF_REQUIRE(!WIFEXITED(st));
+ ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGQUIT);
+ ATF_REQUIRE(!WIFSTOPPED(st));
+ ATF_REQUIRE(!WIFCONTINUED(st));
+ ATF_REQUIRE(si.si_status == SIGQUIT);
+ ATF_REQUIRE(si.si_pid == pid);
+ ATF_REQUIRE(si.si_uid == getuid());
+ ATF_REQUIRE(si.si_code == CLD_KILLED);
+#ifdef __NetBSD__
+ printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime,
+ (uintmax_t)si.si_utime);
+#endif
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, wait6_invalid);
+ ATF_TP_ADD_TC(tp, wait6_exited);
+ ATF_TP_ADD_TC(tp, wait6_terminated);
+ ATF_TP_ADD_TC(tp, wait6_coredumped);
+ ATF_TP_ADD_TC(tp, wait6_stop_and_go);
+ ATF_TP_ADD_TC(tp, wait6_stopgo_loop);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_wait_noproc.c b/contrib/netbsd-tests/lib/libc/sys/t_wait_noproc.c
new file mode 100644
index 0000000..e5ddcbd
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/sys/t_wait_noproc.c
@@ -0,0 +1,345 @@
+/* $NetBSD: t_wait_noproc.c,v 1.5 2016/11/09 17:50:19 kamil Exp $ */
+
+/*-
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_wait_noproc.c,v 1.5 2016/11/09 17:50:19 kamil Exp $");
+
+#ifdef __FreeBSD__
+#include <sys/param.h> /* For NBBY -- it's in sys/types.h on NetBSD */
+#endif
+#include <sys/wait.h>
+#include <sys/resource.h>
+
+#include <errno.h>
+#include <stdio.h>
+
+#include <atf-c.h>
+
+#ifndef TWAIT_OPTION
+#define TWAIT_OPTION 0
+#endif
+
+#if TWAIT_OPTION == 0
+ATF_TC(wait);
+ATF_TC_HEAD(wait, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that wait(2) returns ECHILD for no child");
+}
+
+ATF_TC_BODY(wait, tc)
+{
+ ATF_REQUIRE_ERRNO(ECHILD, wait(NULL) == -1);
+}
+#endif
+
+ATF_TC(waitpid);
+ATF_TC_HEAD(waitpid, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that waitpid(2) returns ECHILD for WAIT_ANY and option %s",
+ ___STRING(TWAIT_OPTION));
+}
+
+ATF_TC_BODY(waitpid, tc)
+{
+ ATF_REQUIRE_ERRNO(ECHILD, waitpid(WAIT_ANY, NULL, TWAIT_OPTION) == -1);
+}
+
+ATF_TC(waitid);
+ATF_TC_HEAD(waitid, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that waitid(2) returns ECHILD for P_ALL and option %s",
+ ___STRING(TWAIT_OPTION));
+}
+
+ATF_TC_BODY(waitid, tc)
+{
+ ATF_REQUIRE_ERRNO(ECHILD,
+ waitid(P_ALL, 0, NULL,
+ WTRAPPED | WEXITED | TWAIT_OPTION) == -1);
+}
+
+ATF_TC(wait3);
+ATF_TC_HEAD(wait3, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that wait3(2) returns ECHILD for no child");
+}
+
+ATF_TC_BODY(wait3, tc)
+{
+ ATF_REQUIRE_ERRNO(ECHILD, wait3(NULL, TWAIT_OPTION, NULL) == -1);
+}
+
+ATF_TC(wait4);
+ATF_TC_HEAD(wait4, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that wait4(2) returns ECHILD for WAIT_ANY and option %s",
+ ___STRING(TWAIT_OPTION));
+}
+
+ATF_TC_BODY(wait4, tc)
+{
+ ATF_REQUIRE_ERRNO(ECHILD,
+ wait4(WAIT_ANY, NULL, TWAIT_OPTION, NULL) == -1);
+}
+
+ATF_TC(wait6);
+ATF_TC_HEAD(wait6, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that wait6(2) returns ECHILD for P_ALL and option %s",
+ ___STRING(TWAIT_OPTION));
+}
+
+ATF_TC_BODY(wait6, tc)
+{
+ ATF_REQUIRE_ERRNO(ECHILD,
+ wait6(P_ALL, 0, NULL,
+ WTRAPPED | WEXITED | TWAIT_OPTION, NULL, NULL) == -1);
+}
+
+/*
+ * Generator of valid combinations of options
+ * Usage: i = 0; while ((o = get_options_wait6(i++)) != -1) {}
+ */
+static int
+get_options6(size_t pos)
+{
+ int rv = 0;
+ size_t n;
+
+ /*
+ * waitid(2) must specify at least one of WEXITED, WUNTRACED,
+ * WSTOPPED, WTRAPPED or WCONTINUED. Single option WNOWAIT
+ * isn't valid.
+ */
+
+ const int matrix[] = {
+ WNOWAIT, /* First in order to blacklist it easily */
+ WEXITED,
+ WUNTRACED,
+ WSTOPPED, /* SUS compatibility, equal to WUNTRACED */
+ WTRAPPED,
+ WCONTINUED
+ };
+
+ const size_t M = (1 << __arraycount(matrix)) - 1;
+
+ /* Skip empty and sole WNOWAIT option */
+ pos+=2;
+
+ if (pos > M)
+ return -1;
+
+ for (n = 0; n < __arraycount(matrix); n++) {
+ if (pos & __BIT(n))
+ rv |= matrix[n];
+ }
+
+ return rv;
+}
+
+/*
+ * Generator of valid combinations of options
+ * Usage: i = 0; while ((o = get_options_wait4(i++)) != -1) {}
+ */
+static int
+get_options4(size_t pos)
+{
+ int rv = 0;
+ size_t n;
+
+ const int special[] = {
+ 0,
+#ifdef __NetBSD__
+ WALLSIG,
+ WALTSIG,
+ __WALL, /* Linux compatibility, equal to WALLSIG */
+ __WCLONE /* Linux compatibility, equal to WALTSIG */
+#endif
+ };
+
+ const int matrix[] = {
+ WNOWAIT,
+ WEXITED,
+ WUNTRACED,
+ WSTOPPED, /* SUS compatibility, equal to WUNTRACED */
+ WTRAPPED,
+ WCONTINUED
+ };
+
+ const size_t M = (1 << __arraycount(special)) - 1;
+
+ if (pos < __arraycount(special))
+ return special[pos];
+
+ pos -= __arraycount(special);
+
+ ++pos; /* Don't start with empty mask */
+
+ if (pos > M)
+ return -1;
+
+ for (n = 0; n < __arraycount(special); n++) {
+ if (pos & __BIT(n))
+ rv |= matrix[n];
+ }
+
+ return rv;
+}
+
+ATF_TC(waitpid_options);
+ATF_TC_HEAD(waitpid_options, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that waitpid(2) returns ECHILD for WAIT_ANY and valid "
+ "combination of options with%s WNOHANG",
+ TWAIT_OPTION == 0 ? "out" : "");
+}
+
+ATF_TC_BODY(waitpid_options, tc)
+{
+ size_t i = 0;
+ int o;
+
+ while((o = get_options4(i++)) != -1) {
+ printf("Testing waitpid(2) with options %x\n", o);
+
+ ATF_REQUIRE_ERRNO(ECHILD,
+ waitpid(WAIT_ANY, NULL, o | TWAIT_OPTION) == -1);
+ }
+}
+
+ATF_TC(waitid_options);
+ATF_TC_HEAD(waitid_options, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that waitid(2) returns ECHILD for P_ALL and valid "
+ "combination of options with%s WNOHANG",
+ TWAIT_OPTION == 0 ? "out" : "");
+}
+
+ATF_TC_BODY(waitid_options, tc)
+{
+ size_t i = 0;
+ int o;
+
+ while((o = get_options6(i++)) != -1) {
+ printf("Testing waitid(2) with options %x\n", o);
+
+ ATF_REQUIRE_ERRNO(ECHILD,
+ waitid(P_ALL, 0, NULL, o | TWAIT_OPTION) == -1);
+ }
+}
+
+ATF_TC(wait3_options);
+ATF_TC_HEAD(wait3_options, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that wait3(2) returns ECHILD for no child");
+}
+
+ATF_TC_BODY(wait3_options, tc)
+{
+ size_t i = 0;
+ int o;
+
+ while((o = get_options4(i++)) != -1) {
+ printf("Testing wait3(2) with options %x\n", o);
+
+ ATF_REQUIRE_ERRNO(ECHILD,
+ wait3(NULL, o | TWAIT_OPTION, NULL) == -1);
+ }
+}
+
+ATF_TC(wait4_options);
+ATF_TC_HEAD(wait4_options, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that wait4(2) returns ECHILD for WAIT_ANY and option %s",
+ ___STRING(TWAIT_OPTION));
+}
+
+ATF_TC_BODY(wait4_options, tc)
+{
+ size_t i = 0;
+ int o;
+
+ while((o = get_options4(i++)) != -1) {
+ printf("Testing wait4(2) with options %x\n", o);
+
+ ATF_REQUIRE_ERRNO(ECHILD,
+ wait4(WAIT_ANY, NULL, o | TWAIT_OPTION, NULL) == -1);
+ }
+}
+
+ATF_TC(wait6_options);
+ATF_TC_HEAD(wait6_options, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that wait6(2) returns ECHILD for P_ALL and option %s",
+ ___STRING(TWAIT_OPTION));
+}
+
+ATF_TC_BODY(wait6_options, tc)
+{
+ size_t i = 0;
+ int o;
+
+ while((o = get_options6(i++)) != -1) {
+ printf("Testing wait6(2) with options %x\n", o);
+
+ ATF_REQUIRE_ERRNO(ECHILD,
+ wait6(P_ALL, 0, NULL, o | TWAIT_OPTION, NULL, NULL) == -1);
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+#if TWAIT_OPTION == 0
+ ATF_TP_ADD_TC(tp, wait);
+#endif
+ ATF_TP_ADD_TC(tp, waitpid);
+ ATF_TP_ADD_TC(tp, waitid);
+ ATF_TP_ADD_TC(tp, wait3);
+ ATF_TP_ADD_TC(tp, wait4);
+ ATF_TP_ADD_TC(tp, wait6);
+
+ ATF_TP_ADD_TC(tp, waitpid_options);
+ ATF_TP_ADD_TC(tp, waitid_options);
+ ATF_TP_ADD_TC(tp, wait3_options);
+ ATF_TP_ADD_TC(tp, wait4_options);
+ ATF_TP_ADD_TC(tp, wait6_options);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_wait_noproc_wnohang.c b/contrib/netbsd-tests/lib/libc/sys/t_wait_noproc_wnohang.c
new file mode 100644
index 0000000..45a9998
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/sys/t_wait_noproc_wnohang.c
@@ -0,0 +1,30 @@
+/* $NetBSD: t_wait_noproc_wnohang.c,v 1.1 2016/11/06 15:03:30 kamil Exp $ */
+
+/*-
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define TWAIT_OPTION WNOHANG
+#include "t_wait_noproc.c"
diff --git a/contrib/netbsd-tests/lib/libc/t_cdb.c b/contrib/netbsd-tests/lib/libc/t_cdb.c
index 5e88e65..97da4a3 100644
--- a/contrib/netbsd-tests/lib/libc/t_cdb.c
+++ b/contrib/netbsd-tests/lib/libc/t_cdb.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_cdb.c,v 1.1 2012/09/27 00:38:57 joerg Exp $ */
+/* $NetBSD: t_cdb.c,v 1.2 2017/01/10 22:24:29 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -32,9 +32,12 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_cdb.c,v 1.1 2012/09/27 00:38:57 joerg Exp $");
+__RCSID("$NetBSD: t_cdb.c,v 1.2 2017/01/10 22:24:29 christos Exp $");
#include <atf-c.h>
+
+#include <sys/stat.h>
+
#include <assert.h>
#include <cdbr.h>
#include <cdbw.h>
diff --git a/contrib/netbsd-tests/lib/libc/time/t_strptime.c b/contrib/netbsd-tests/lib/libc/time/t_strptime.c
index 99871ff..863df36e 100644
--- a/contrib/netbsd-tests/lib/libc/time/t_strptime.c
+++ b/contrib/netbsd-tests/lib/libc/time/t_strptime.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strptime.c,v 1.1 2011/01/13 00:14:10 pgoyette Exp $ */
+/* $NetBSD: t_strptime.c,v 1.12 2015/10/31 02:25:11 christos Exp $ */
/*-
* Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -32,9 +32,11 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_strptime.c,v 1.1 2011/01/13 00:14:10 pgoyette Exp $");
+__RCSID("$NetBSD: t_strptime.c,v 1.12 2015/10/31 02:25:11 christos Exp $");
#include <time.h>
+#include <stdlib.h>
+#include <stdio.h>
#include <atf-c.h>
@@ -97,6 +99,124 @@ h_fail(const char *buf, const char *fmt)
#endif
}
+static struct {
+ const char *name;
+ long offs;
+} zt[] = {
+ { "Z", 0 },
+ { "UT", 0 },
+ { "UTC", 0 },
+ { "GMT", 0 },
+ { "EST", -18000 },
+ { "EDT", -14400 },
+ { "CST", -21600 },
+ { "CDT", -18000 },
+ { "MST", -25200 },
+ { "MDT", -21600 },
+ { "PST", -28800 },
+ { "PDT", -25200 },
+
+ { "VST", -1 },
+ { "VDT", -1 },
+
+ { "+03", 10800 },
+ { "-03", -10800 },
+ { "+0403", 14580 },
+ { "-0403", -14580 },
+ { "+04:03", 14580 },
+ { "-04:03", -14580 },
+ { "+14:00", 50400 },
+ { "-14:00", -50400 },
+ { "+23:59", 86340 },
+ { "-23:59", -86340 },
+
+ { "1", -1 },
+ { "03", -1 },
+ { "0304", -1 },
+ { "+1", -1 },
+ { "-203", -1 },
+ { "+12345", -1 },
+ { "+12:345", -1 },
+ { "+123:45", -1 },
+ { "+2400", -1 },
+ { "-2400", -1 },
+ { "+1060", -1 },
+ { "-1060", -1 },
+
+ { "A", -3600 },
+ { "B", -7200 },
+ { "C", -10800 },
+ { "D", -14400 },
+ { "E", -18000 },
+ { "F", -21600 },
+ { "G", -25200 },
+ { "H", -28800 },
+ { "I", -32400 },
+ { "L", -39600 },
+ { "M", -43200 },
+ { "N", 3600 },
+ { "O", 7200 },
+ { "P", 10800 },
+ { "Q", 14400 },
+ { "R", 18000 },
+ { "T", 25200 },
+ { "U", 28800 },
+ { "V", 32400 },
+ { "W", 36000 },
+ { "X", 39600 },
+ { "Y", 43200 },
+
+ { "J", -2 },
+
+ { "America/Los_Angeles", -28800 },
+ { "America/New_York", -18000 },
+ { "EST4EDT", -14400 },
+
+ { "Bogus", -1 },
+};
+
+static void
+ztest1(const char *name, const char *fmt, long value)
+{
+ struct tm tm;
+ char *rv;
+
+ memset(&tm, 0, sizeof(tm));
+ if ((rv = strptime(name, fmt, &tm)) == NULL)
+ tm.tm_gmtoff = -1;
+ else if (rv == name && fmt[1] == 'Z')
+ value = 0;
+
+ switch (value) {
+ case -2:
+ value = -timezone;
+ break;
+ case -1:
+ if (fmt[1] == 'Z')
+ value = 0;
+ break;
+ default:
+ break;
+ }
+
+ ATF_REQUIRE_MSG(tm.tm_gmtoff == value,
+ "strptime(\"%s\", \"%s\", &tm): "
+ "expected: tm.tm_gmtoff=%ld, got: tm.tm_gmtoff=%ld",
+ name, fmt, value, tm.tm_gmtoff);
+ printf("%s %s %ld\n", name, fmt, tm.tm_gmtoff);
+}
+
+static void
+ztest(const char *fmt)
+{
+ setenv("TZ", "US/Eastern", 1);
+ ztest1("GMT", fmt, 0);
+ ztest1("UTC", fmt, 0);
+ ztest1("US/Eastern", fmt, -18000);
+ for (size_t i = 0; i < __arraycount(zt); i++)
+ ztest1(zt[i].name, fmt, zt[i].offs);
+}
+
ATF_TC(common);
ATF_TC_HEAD(common, tc)
@@ -113,33 +233,17 @@ ATF_TC_BODY(common, tc)
#endif
h_pass("Tue Jan 20 23:27:46 1998", "%a %b %d %T %Y",
- 24, 46, 27, 23, 20, 0, 98, 2, -1);
+ 24, 46, 27, 23, 20, 0, 98, 2, 19);
h_pass("Tue Jan 20 23:27:46 1998", "%a %b %d %H:%M:%S %Y",
- 24, 46, 27, 23, 20, 0, 98, 2, -1);
+ 24, 46, 27, 23, 20, 0, 98, 2, 19);
h_pass("Tue Jan 20 23:27:46 1998", "%c",
- 24, 46, 27, 23, 20, 0, 98, 2, -1);
+ 24, 46, 27, 23, 20, 0, 98, 2, 19);
h_pass("Fri Mar 4 20:05:34 2005", "%a %b %e %H:%M:%S %Y",
- 24, 34, 5, 20, 4, 2, 105, 5, -1);
+ 24, 34, 5, 20, 4, 2, 105, 5, 62);
h_pass("5\t3 4 8pm:05:34 2005", "%w%n%m%t%d%n%k%p:%M:%S %Y",
- 21, 34, 5, 20, 4, 2, 105, 5, -1);
+ 21, 34, 5, 20, 4, 2, 105, 5, 62);
h_pass("Fri Mar 4 20:05:34 2005", "%c",
- 24, 34, 5, 20, 4, 2, 105, 5, -1);
-
- h_pass("x20y", "x%Cy", 4, -1, -1, -1, -1, -1, 100, -1, -1);
- h_pass("x84y", "x%yy", 4, -1, -1, -1, -1, -1, 84, -1, -1);
- h_pass("x2084y", "x%C%yy", 6, -1, -1, -1, -1, -1, 184, -1, -1);
- h_pass("x8420y", "x%y%Cy", 6, -1, -1, -1, -1, -1, 184, -1, -1);
- h_pass("%20845", "%%%C%y5", 6, -1, -1, -1, -1, -1, 184, -1, -1);
- h_fail("%", "%E%");
-
- h_pass("1980", "%Y", 4, -1, -1, -1, -1, -1, 80, -1, -1);
- h_pass("1980", "%EY", 4, -1, -1, -1, -1, -1, 80, -1, -1);
-
- h_pass("0", "%S", 1, 0, -1, -1, -1, -1, -1, -1, -1);
- h_pass("59", "%S", 2, 59, -1, -1, -1, -1, -1, -1, -1);
- h_pass("60", "%S", 2, 60, -1, -1, -1, -1, -1, -1, -1);
- h_pass("61", "%S", 2, 61, -1, -1, -1, -1, -1, -1, -1);
- h_fail("62", "%S");
+ 24, 34, 5, 20, 4, 2, 105, 5, 62);
}
ATF_TC(day);
@@ -147,7 +251,8 @@ ATF_TC(day);
ATF_TC_HEAD(day, tc)
{
- atf_tc_set_md_var(tc, "descr", "Checks strptime(3): day names");
+ atf_tc_set_md_var(tc, "descr",
+ "Checks strptime(3) day name conversions [aA]");
}
ATF_TC_BODY(day, tc)
@@ -202,12 +307,35 @@ ATF_TC_BODY(day, tc)
#endif
}
+ATF_TC(hour);
+
+ATF_TC_HEAD(hour, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks strptime(3) hour conversions [IH]");
+}
+
+ATF_TC_BODY(hour, tc)
+{
+
+ h_fail("00", "%I");
+ h_fail("13", "%I");
+
+ h_pass("00", "%H", 2, -1, -1, 0, -1, -1, -1, -1, -1);
+ h_pass("12", "%H", 2, -1, -1, 12, -1, -1, -1, -1, -1);
+ h_pass("23", "%H", 2, -1, -1, 23, -1, -1, -1, -1, -1);
+ h_fail("24", "%H");
+}
+
+
ATF_TC(month);
ATF_TC_HEAD(month, tc)
{
- atf_tc_set_md_var(tc, "descr", "Checks strptime(3): month names");
+ atf_tc_set_md_var(tc, "descr",
+ "Checks strptime(3) month name conversions [bB]");
}
ATF_TC_BODY(month, tc)
@@ -270,12 +398,89 @@ ATF_TC_BODY(month, tc)
h_pass("septembe", "%B", 3, -1, -1, -1, -1, 8, -1, -1, -1);
}
+ATF_TC(seconds);
+
+ATF_TC_HEAD(seconds, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks strptime(3) seconds conversions [S]");
+}
+
+ATF_TC_BODY(seconds, tc)
+{
+
+ h_pass("0", "%S", 1, 0, -1, -1, -1, -1, -1, -1, -1);
+ h_pass("59", "%S", 2, 59, -1, -1, -1, -1, -1, -1, -1);
+ h_pass("60", "%S", 2, 60, -1, -1, -1, -1, -1, -1, -1);
+ h_pass("61", "%S", 2, 61, -1, -1, -1, -1, -1, -1, -1);
+ h_fail("62", "%S");
+}
+
+ATF_TC(year);
+
+ATF_TC_HEAD(year, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks strptime(3) century/year conversions [CyY]");
+}
+
+ATF_TC_BODY(year, tc)
+{
+
+ h_pass("x20y", "x%Cy", 4, -1, -1, -1, -1, -1, 100, -1, -1);
+ h_pass("x84y", "x%yy", 4, -1, -1, -1, -1, -1, 84, -1, -1);
+ h_pass("x2084y", "x%C%yy", 6, -1, -1, -1, -1, -1, 184, -1, -1);
+ h_pass("x8420y", "x%y%Cy", 6, -1, -1, -1, -1, -1, 184, -1, -1);
+ h_pass("%20845", "%%%C%y5", 6, -1, -1, -1, -1, -1, 184, -1, -1);
+ h_fail("%", "%E%");
+
+ h_pass("1980", "%Y", 4, -1, -1, -1, -1, -1, 80, -1, -1);
+ h_pass("1980", "%EY", 4, -1, -1, -1, -1, -1, 80, -1, -1);
+}
+
+ATF_TC(zone);
+
+ATF_TC_HEAD(zone, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks strptime(3) timezone conversion [z]");
+}
+
+
+ATF_TC_BODY(zone, tc)
+{
+ ztest("%z");
+}
+
+ATF_TC(Zone);
+
+ATF_TC_HEAD(Zone, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks strptime(3) timezone conversion [Z]");
+}
+
+
+ATF_TC_BODY(Zone, tc)
+{
+ ztest("%z");
+}
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, common);
ATF_TP_ADD_TC(tp, day);
+ ATF_TP_ADD_TC(tp, hour);
ATF_TP_ADD_TC(tp, month);
+ ATF_TP_ADD_TC(tp, seconds);
+ ATF_TP_ADD_TC(tp, year);
+ ATF_TP_ADD_TC(tp, zone);
+ ATF_TP_ADD_TC(tp, Zone);
return atf_no_error();
}
OpenPOWER on IntegriCloud