summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests/lib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/netbsd-tests/lib')
-rw-r--r--contrib/netbsd-tests/lib/libbpfjit/t_bpfjit.c818
-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
-rw-r--r--contrib/netbsd-tests/lib/libcurses/director/testlang_parse.y5
-rw-r--r--contrib/netbsd-tests/lib/libm/t_casinh.c81
-rw-r--r--contrib/netbsd-tests/lib/libm/t_exp.c41
-rw-r--r--contrib/netbsd-tests/lib/libm/t_fe_round.c124
-rw-r--r--contrib/netbsd-tests/lib/libm/t_fenv.c220
-rw-r--r--contrib/netbsd-tests/lib/libm/t_fmod.c9
-rw-r--r--contrib/netbsd-tests/lib/libm/t_hypot.c81
-rw-r--r--contrib/netbsd-tests/lib/libm/t_ilogb.c130
-rw-r--r--contrib/netbsd-tests/lib/libm/t_ldexp.c12
-rw-r--r--contrib/netbsd-tests/lib/libm/t_log.c16
-rw-r--r--contrib/netbsd-tests/lib/libm/t_pow.c7
-rw-r--r--contrib/netbsd-tests/lib/libm/t_precision.c8
-rw-r--r--contrib/netbsd-tests/lib/libpthread/h_common.h6
-rw-r--r--contrib/netbsd-tests/lib/libpthread/t_cond.c25
-rw-r--r--contrib/netbsd-tests/lib/libpthread/t_mutex.c460
-rw-r--r--contrib/netbsd-tests/lib/libpthread/t_rwlock.c20
-rw-r--r--contrib/netbsd-tests/lib/libpthread/t_swapcontext.c9
-rw-r--r--contrib/netbsd-tests/lib/libpthread/t_timedmutex.c30
-rw-r--r--contrib/netbsd-tests/lib/librumpclient/h_execthr.c68
-rwxr-xr-xcontrib/netbsd-tests/lib/librumpclient/t_exec.sh4
-rw-r--r--contrib/netbsd-tests/lib/librumpclient/t_fd.c4
-rwxr-xr-xcontrib/netbsd-tests/lib/librumphijack/t_tcpip.sh19
-rw-r--r--contrib/netbsd-tests/lib/libusbhid/hid_test_data.c137
-rw-r--r--contrib/netbsd-tests/lib/libusbhid/t_usbhid.c452
-rw-r--r--contrib/netbsd-tests/lib/libusbhid/test_usb_hid_usages17
-rw-r--r--contrib/netbsd-tests/lib/libutil/t_parsedate.c473
108 files changed, 7210 insertions, 673 deletions
diff --git a/contrib/netbsd-tests/lib/libbpfjit/t_bpfjit.c b/contrib/netbsd-tests/lib/libbpfjit/t_bpfjit.c
index da67c1b3..4d81dd6 100644
--- a/contrib/netbsd-tests/lib/libbpfjit/t_bpfjit.c
+++ b/contrib/netbsd-tests/lib/libbpfjit/t_bpfjit.c
@@ -1,7 +1,7 @@
-/* $NetBSD: t_bpfjit.c,v 1.6 2014/07/08 21:07:52 alnsn Exp $ */
+/* $NetBSD: t_bpfjit.c,v 1.14 2015/02/14 22:40:18 alnsn Exp $ */
/*-
- * Copyright (c) 2011-2012, 2014 Alexander Nasonov.
+ * Copyright (c) 2011-2012, 2014-2015 Alexander Nasonov.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_bpfjit.c,v 1.6 2014/07/08 21:07:52 alnsn Exp $");
+__RCSID("$NetBSD: t_bpfjit.c,v 1.14 2015/02/14 22:40:18 alnsn Exp $");
#include <atf-c.h>
#include <stdint.h>
@@ -67,9 +67,75 @@ ATF_TC_BODY(libbpfjit_empty, tc)
{
struct bpf_insn dummy;
+ ATF_CHECK(!bpf_validate(&dummy, 0));
ATF_CHECK(bpfjit_generate_code(NULL, &dummy, 0) == NULL);
}
+ATF_TC(libbpfjit_ret_k);
+ATF_TC_HEAD(libbpfjit_ret_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of a trivial bpf program");
+}
+
+ATF_TC_BODY(libbpfjit_ret_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_RET+BPF_K, 17)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 17);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_bad_ret_k);
+ATF_TC_HEAD(libbpfjit_bad_ret_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that JIT compilation of a program with bad BPF_RET fails");
+}
+
+ATF_TC_BODY(libbpfjit_bad_ret_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_RET+BPF_K+0x8000, 13)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ /*
+ * The point of this test is checking a bad instruction of
+ * a valid class and with a valid BPF_RVAL data.
+ */
+ const uint16_t rcode = insns[0].code;
+ ATF_CHECK(BPF_CLASS(rcode) == BPF_RET &&
+ (BPF_RVAL(rcode) == BPF_K || BPF_RVAL(rcode) == BPF_A));
+
+ ATF_CHECK(!bpf_validate(insns, insn_count));
+
+ /* Current implementation generates code. */
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 13);
+
+ bpfjit_free_code(code);
+}
+
ATF_TC(libbpfjit_alu_add_k);
ATF_TC_HEAD(libbpfjit_alu_add_k, tc)
{
@@ -399,6 +465,245 @@ ATF_TC_BODY(libbpfjit_alu_div80000000_k, tc)
bpfjit_free_code(code);
}
+ATF_TC(libbpfjit_alu_mod0_k);
+ATF_TC_HEAD(libbpfjit_alu_mod0_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=0");
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod0_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 0),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ //ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 0);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod1_k);
+ATF_TC_HEAD(libbpfjit_alu_mod1_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=1");
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod1_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, 7),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 1),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 0);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod2_k);
+ATF_TC_HEAD(libbpfjit_alu_mod2_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=2");
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod2_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, 7),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 2),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 1);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod4_k);
+ATF_TC_HEAD(libbpfjit_alu_mod4_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=4");
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod4_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0xffffffff)),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 4),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 3);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod10_k);
+ATF_TC_HEAD(libbpfjit_alu_mod10_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=10");
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod10_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294843849)),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 10),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 9);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod10000_k);
+ATF_TC_HEAD(libbpfjit_alu_mod10000_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=10000");
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod10000_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294843849)),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 10000),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 3849);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod7609801_k);
+ATF_TC_HEAD(libbpfjit_alu_mod7609801_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_mod+BPF_K with k=7609801");
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod7609801_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294967295)),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, UINT32_C(7609801)),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == UINT32_C(3039531));
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod80000000_k);
+ATF_TC_HEAD(libbpfjit_alu_mod80000000_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=0x80000000");
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod80000000_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0xffffffde)),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, UINT32_C(0x80000000)),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == UINT32_C(0x7fffffde));
+
+ bpfjit_free_code(code);
+}
+
ATF_TC(libbpfjit_alu_and_k);
ATF_TC_HEAD(libbpfjit_alu_and_k, tc)
{
@@ -459,6 +764,36 @@ ATF_TC_BODY(libbpfjit_alu_or_k, tc)
bpfjit_free_code(code);
}
+ATF_TC(libbpfjit_alu_xor_k);
+ATF_TC_HEAD(libbpfjit_alu_xor_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_XOR+BPF_K");
+}
+
+ATF_TC_BODY(libbpfjit_alu_xor_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, 0xdead0f0f),
+ BPF_STMT(BPF_ALU+BPF_XOR+BPF_K, 0x0000b1e0),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 0xdeadbeef);
+
+ bpfjit_free_code(code);
+}
+
ATF_TC(libbpfjit_alu_lsh_k);
ATF_TC_HEAD(libbpfjit_alu_lsh_k, tc)
{
@@ -962,7 +1297,7 @@ ATF_TC_HEAD(libbpfjit_alu_div80000000_x, tc)
ATF_TC_BODY(libbpfjit_alu_div80000000_x, tc)
{
static struct bpf_insn insns[] = {
- BPF_STMT(BPF_LD+BPF_IMM, UINT32_MAX - 33),
+ BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0xffffffde)),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_C(0x80000000)),
BPF_STMT(BPF_ALU+BPF_DIV+BPF_X, 0),
BPF_STMT(BPF_RET+BPF_A, 0)
@@ -983,6 +1318,253 @@ ATF_TC_BODY(libbpfjit_alu_div80000000_x, tc)
bpfjit_free_code(code);
}
+ATF_TC(libbpfjit_alu_mod0_x);
+ATF_TC_HEAD(libbpfjit_alu_mod0_x, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=0");
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod0_x, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_X, 0),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 0);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod1_x);
+ATF_TC_HEAD(libbpfjit_alu_mod1_x, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=1");
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod1_x, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, 7),
+ BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 1),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_X, 0),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 0);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod2_x);
+ATF_TC_HEAD(libbpfjit_alu_mod2_x, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=2");
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod2_x, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, 7),
+ BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 2),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_X, 0),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 1);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod4_x);
+ATF_TC_HEAD(libbpfjit_alu_mod4_x, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=4");
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod4_x, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0xffffffff)),
+ BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 4),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_X, 0),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 3);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod10_x);
+ATF_TC_HEAD(libbpfjit_alu_mod10_x, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=10");
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod10_x, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294843849)),
+ BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 10),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_X, 0),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 9);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod10000_x);
+ATF_TC_HEAD(libbpfjit_alu_mod10000_x, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=10000");
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod10000_x, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294843849)),
+ BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 10000),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_X, 0),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 3849);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod7609801_x);
+ATF_TC_HEAD(libbpfjit_alu_mod7609801_x, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=7609801");
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod7609801_x, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294967295)),
+ BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_C(7609801)),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_X, 0),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == UINT32_C(3039531));
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod80000000_x);
+ATF_TC_HEAD(libbpfjit_alu_mod80000000_x, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=0x80000000");
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod80000000_x, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0xffffffde)),
+ BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_C(0x80000000)),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_X, 0),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == UINT32_C(0x7fffffde));
+
+ bpfjit_free_code(code);
+}
+
ATF_TC(libbpfjit_alu_and_x);
ATF_TC_HEAD(libbpfjit_alu_and_x, tc)
{
@@ -1045,6 +1627,37 @@ ATF_TC_BODY(libbpfjit_alu_or_x, tc)
bpfjit_free_code(code);
}
+ATF_TC(libbpfjit_alu_xor_x);
+ATF_TC_HEAD(libbpfjit_alu_xor_x, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_XOR+BPF_X");
+}
+
+ATF_TC_BODY(libbpfjit_alu_xor_x, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, 0xdead0f0f),
+ BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0x0000b1e0),
+ BPF_STMT(BPF_ALU+BPF_XOR+BPF_X, 0),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 0xdeadbeef);
+
+ bpfjit_free_code(code);
+}
+
ATF_TC(libbpfjit_alu_lsh_x);
ATF_TC_HEAD(libbpfjit_alu_lsh_x, tc)
{
@@ -1305,6 +1918,54 @@ ATF_TC_BODY(libbpfjit_jmp_ja, tc)
bpfjit_free_code(code);
}
+ATF_TC(libbpfjit_jmp_ja_invalid);
+ATF_TC_HEAD(libbpfjit_jmp_ja_invalid, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test BPF_JMP+BPF_JA to invalid destination");
+}
+
+ATF_TC_BODY(libbpfjit_jmp_ja_invalid, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_JMP+BPF_JA, 4),
+ BPF_STMT(BPF_RET+BPF_K, 0),
+ BPF_STMT(BPF_RET+BPF_K, 1),
+ BPF_STMT(BPF_RET+BPF_K, 2),
+ BPF_STMT(BPF_RET+BPF_K, 3),
+ };
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(!bpf_validate(insns, insn_count));
+ ATF_CHECK(bpfjit_generate_code(NULL, insns, insn_count) == NULL);
+}
+
+ATF_TC(libbpfjit_jmp_ja_overflow);
+ATF_TC_HEAD(libbpfjit_jmp_ja_overflow, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test BPF_JMP+BPF_JA with negative offset");
+}
+
+ATF_TC_BODY(libbpfjit_jmp_ja_overflow, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_JMP+BPF_JA, 1),
+ BPF_STMT(BPF_RET+BPF_K, 777),
+ BPF_STMT(BPF_JMP+BPF_JA, UINT32_MAX - 1), // -2
+ BPF_STMT(BPF_RET+BPF_K, 0)
+ };
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ /* Jumps with negative offsets work in userspace ... */
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ /* .. but not for bpfjit. */
+ ATF_CHECK(bpfjit_generate_code(NULL, insns, insn_count) == NULL);
+}
+
ATF_TC(libbpfjit_jmp_jgt_k);
ATF_TC_HEAD(libbpfjit_jmp_jgt_k, tc)
{
@@ -1693,26 +2354,26 @@ ATF_TC_BODY(libbpfjit_jmp_jeq_x, tc)
BPF_STMT(BPF_LD+BPF_W+BPF_LEN, 0),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 8),
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 0, 1),
- BPF_STMT(BPF_RET+BPF_K, 0),
+ BPF_STMT(BPF_RET+BPF_K, 1),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 3),
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 2, 0),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 9),
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 1, 1),
- BPF_STMT(BPF_RET+BPF_K, 1),
- BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 5),
- BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 1, 1),
BPF_STMT(BPF_RET+BPF_K, 2),
+ BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 5),
+ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 0, 1),
+ BPF_STMT(BPF_RET+BPF_K, 3),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 7),
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 2, 3),
- BPF_STMT(BPF_RET+BPF_K, 3),
BPF_STMT(BPF_RET+BPF_K, 4),
BPF_STMT(BPF_RET+BPF_K, 5),
+ BPF_STMT(BPF_RET+BPF_K, 6),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 6),
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 3, 1),
- BPF_STMT(BPF_RET+BPF_K, 6),
- BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 1, 0, 0),
BPF_STMT(BPF_RET+BPF_K, 7),
- BPF_STMT(BPF_RET+BPF_K, 8)
+ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 1, 0),
+ BPF_STMT(BPF_RET+BPF_K, 8),
+ BPF_STMT(BPF_RET+BPF_K, 9)
};
bpfjit_func_t code;
@@ -1725,14 +2386,14 @@ ATF_TC_BODY(libbpfjit_jmp_jeq_x, tc)
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
- ATF_CHECK(jitcall(code, pkt, 1, 1) == 7);
- ATF_CHECK(jitcall(code, pkt, 2, 2) == 7);
- ATF_CHECK(jitcall(code, pkt, 3, 3) == 1);
- ATF_CHECK(jitcall(code, pkt, 4, 4) == 7);
- ATF_CHECK(jitcall(code, pkt, 5, 5) == 7);
- ATF_CHECK(jitcall(code, pkt, 6, 6) == 8);
- ATF_CHECK(jitcall(code, pkt, 7, 7) == 5);
- ATF_CHECK(jitcall(code, pkt, 8, 8) == 0);
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 8);
+ ATF_CHECK(jitcall(code, pkt, 2, 2) == 8);
+ ATF_CHECK(jitcall(code, pkt, 3, 3) == 2);
+ ATF_CHECK(jitcall(code, pkt, 4, 4) == 8);
+ ATF_CHECK(jitcall(code, pkt, 5, 5) == 3);
+ ATF_CHECK(jitcall(code, pkt, 6, 6) == 9);
+ ATF_CHECK(jitcall(code, pkt, 7, 7) == 6);
+ ATF_CHECK(jitcall(code, pkt, 8, 8) == 1);
bpfjit_free_code(code);
}
@@ -1794,6 +2455,98 @@ ATF_TC_BODY(libbpfjit_jmp_jset_x, tc)
bpfjit_free_code(code);
}
+ATF_TC(libbpfjit_jmp_jeq_x_noinit_ax);
+ATF_TC_HEAD(libbpfjit_jmp_jeq_x_noinit_ax, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test JIT compilation "
+ "of BPF_JMP+BPF_EQ+BPF_X with uninitialised A and X");
+}
+
+ATF_TC_BODY(libbpfjit_jmp_jeq_x_noinit_ax, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 0, 1),
+ BPF_STMT(BPF_RET+BPF_K, 10),
+ BPF_STMT(BPF_RET+BPF_K, 11)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[8]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 10);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_jmp_jeq_x_noinit_a);
+ATF_TC_HEAD(libbpfjit_jmp_jeq_x_noinit_a, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test JIT compilation "
+ "of BPF_JMP+BPF_EQ+BPF_X with uninitialised A");
+}
+
+ATF_TC_BODY(libbpfjit_jmp_jeq_x_noinit_a, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LDX+BPF_W+BPF_LEN, 0), /* X > 0 */
+ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 0, 1),
+ BPF_STMT(BPF_RET+BPF_K, 10),
+ BPF_STMT(BPF_RET+BPF_K, 11)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[8]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 11);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_jmp_jeq_x_noinit_x);
+ATF_TC_HEAD(libbpfjit_jmp_jeq_x_noinit_x, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test JIT compilation "
+ "of BPF_JMP+BPF_EQ+BPF_X with uninitialised X");
+}
+
+ATF_TC_BODY(libbpfjit_jmp_jeq_x_noinit_x, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_LEN, 0), /* A > 0 */
+ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 0, 1),
+ BPF_STMT(BPF_RET+BPF_K, 10),
+ BPF_STMT(BPF_RET+BPF_K, 11)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[8]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ ATF_CHECK(bpf_validate(insns, insn_count));
+
+ code = bpfjit_generate_code(NULL, insns, insn_count);
+ ATF_REQUIRE(code != NULL);
+
+ ATF_CHECK(jitcall(code, pkt, 1, 1) == 11);
+
+ bpfjit_free_code(code);
+}
+
ATF_TC(libbpfjit_jmp_modulo_x);
ATF_TC_HEAD(libbpfjit_jmp_modulo_x, tc)
{
@@ -3883,6 +4636,8 @@ ATF_TP_ADD_TCS(tp)
* to ../../net/bpfjit/t_bpfjit.c
*/
ATF_TP_ADD_TC(tp, libbpfjit_empty);
+ ATF_TP_ADD_TC(tp, libbpfjit_ret_k);
+ ATF_TP_ADD_TC(tp, libbpfjit_bad_ret_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_add_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_sub_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_mul_k);
@@ -3894,8 +4649,17 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, libbpfjit_alu_div10000_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_div7609801_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_div80000000_k);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_mod0_k);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_mod1_k);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_mod2_k);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_mod4_k);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_mod10_k);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_mod10000_k);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_mod7609801_k);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_mod80000000_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_and_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_or_k);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_xor_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_lsh_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_lsh0_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_rsh_k);
@@ -3912,8 +4676,17 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, libbpfjit_alu_div10000_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_div7609801_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_div80000000_x);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_mod0_x);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_mod1_x);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_mod2_x);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_mod4_x);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_mod10_x);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_mod10000_x);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_mod7609801_x);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_mod80000000_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_and_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_or_x);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_xor_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_lsh_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_lsh0_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_rsh_x);
@@ -3921,6 +4694,8 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, libbpfjit_alu_modulo_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_neg);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_ja);
+ ATF_TP_ADD_TC(tp, libbpfjit_jmp_ja_invalid);
+ ATF_TP_ADD_TC(tp, libbpfjit_jmp_ja_overflow);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jgt_k);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jge_k);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jeq_k);
@@ -3930,6 +4705,9 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jge_x);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jeq_x);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jset_x);
+ ATF_TP_ADD_TC(tp, libbpfjit_jmp_jeq_x_noinit_ax);
+ ATF_TP_ADD_TC(tp, libbpfjit_jmp_jeq_x_noinit_a);
+ ATF_TP_ADD_TC(tp, libbpfjit_jmp_jeq_x_noinit_x);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_modulo_x);
ATF_TP_ADD_TC(tp, libbpfjit_ld_abs);
ATF_TP_ADD_TC(tp, libbpfjit_ld_abs_k_overflow);
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();
}
diff --git a/contrib/netbsd-tests/lib/libcurses/director/testlang_parse.y b/contrib/netbsd-tests/lib/libcurses/director/testlang_parse.y
index 37c813f..75aaf62 100644
--- a/contrib/netbsd-tests/lib/libcurses/director/testlang_parse.y
+++ b/contrib/netbsd-tests/lib/libcurses/director/testlang_parse.y
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: testlang_parse.y,v 1.13 2012/09/19 11:51:56 blymn Exp $ */
+/* $NetBSD: testlang_parse.y,v 1.14 2015/01/04 20:19:46 christos Exp $ */
/*-
* Copyright 2009 Brett Lymn <blymn@NetBSD.org>
@@ -39,7 +39,8 @@
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
-#include <sys/syslimits.h>
+#include <stdlib.h>
+#include <limits.h>
#include <time.h>
#include <vis.h>
#include <stdint.h>
diff --git a/contrib/netbsd-tests/lib/libm/t_casinh.c b/contrib/netbsd-tests/lib/libm/t_casinh.c
new file mode 100644
index 0000000..f9f93c3
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libm/t_casinh.c
@@ -0,0 +1,81 @@
+/* $NetBSD: t_casinh.c,v 1.2 2016/09/20 17:19:28 christos Exp $ */
+
+/*
+ * Written by Maya Rashish
+ * Public domain.
+ *
+ * Testing special values of casinh
+ * Values from ISO/IEC 9899:201x G.6.2.2
+ */
+
+#include <atf-c.h>
+#include <complex.h>
+#include <math.h>
+
+#define RE(z) (((double *)(&z))[0])
+#define IM(z) (((double *)(&z))[1])
+
+static const struct {
+ double input_re;
+ double input_im;
+ double result_re;
+ double result_im;
+} values[] = {
+ { +0, +0, +0, +0},
+ { +5.032E3, +INFINITY, +INFINITY, +M_PI/2},
+ { +INFINITY, +5.023E3, +INFINITY, +0},
+ { +INFINITY, +INFINITY, +INFINITY, +M_PI/4},
+#ifdef __HAVE_NANF
+ { +INFINITY, +NAN, +INFINITY, +NAN},
+ { +5.032E3, +NAN, +NAN, +NAN}, /* + FE_INVALID optionally raised */
+ { +NAN, +0, +NAN, +0},
+ { +NAN, -5.023E3, +NAN, +NAN}, /* + FE_INVALID optionally raised */
+ { +NAN, +INFINITY, +INFINITY, +NAN}, /* sign of real part of result unspecified */
+ { +NAN, +NAN, +NAN, +NAN},
+#endif
+};
+
+#ifdef __HAVE_NANF
+#define both_nan(a,b) (isnan(a) && isnan(b))
+#else
+#define both_nan(a,b) 0
+#endif
+
+#define crude_equality(a,b) ((a == b) || both_nan(a,b))
+
+#define ATF_COMPLEX_EQUAL(a,b) do { \
+ complex double ci = casinh(a); \
+ ATF_CHECK_MSG(crude_equality(creal(ci),creal(b)) && \
+ crude_equality(cimag(ci), cimag(b)), \
+ "for casinh([%g,%g]) = [%g,%g] != [%g,%g]", \
+ creal(a), cimag(a), creal(ci), cimag(ci), creal(b), cimag(b)); \
+} while (0/*CONSTCOND*/)
+
+
+ATF_TC(casinh);
+ATF_TC_HEAD(casinh, tc)
+{
+ atf_tc_set_md_var(tc, "descr","Check casinh family - special values");
+}
+
+ATF_TC_BODY(casinh, tc)
+{
+ complex double input;
+ complex double result;
+ unsigned int i;
+ for (i = 0; i < __arraycount(values); i++) {
+ RE(input) = values[i].input_re;
+ IM(input) = values[i].input_im;
+ RE(result) = values[i].result_re;
+ IM(result) = values[i].result_im;
+ ATF_COMPLEX_EQUAL(input, result);
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, casinh);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libm/t_exp.c b/contrib/netbsd-tests/lib/libm/t_exp.c
index 7a8e9f8..0eb6412 100644
--- a/contrib/netbsd-tests/lib/libm/t_exp.c
+++ b/contrib/netbsd-tests/lib/libm/t_exp.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_exp.c,v 1.7 2014/03/17 11:08:11 martin Exp $ */
+/* $NetBSD: t_exp.c,v 1.8 2014/10/07 16:53:44 gson Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -145,47 +145,40 @@ ATF_LIBM_TEST(exp2_values, "Test exp2(x) is correct for some x")
{
static const struct {
double x;
- double y;
+ double d_y;
+ float f_y;
double d_eps;
double f_eps;
} v[] = {
#if __DBL_MAX_EXP__ > 128
/* The largest double constant */
- { 0x1.fffffffffffffp9, 0x1.ffffffffffd3ap1023,
+ { 0x1.fffffffffffffp9, 0x1.ffffffffffd3ap1023, 0.00,
0x1p969, 0.0 },
/* The largest float constant */
- { 0x1.fffffep6, 0x1.ffff4ep+127, 6e30, 0.0 },
+ { 0x1.fffffep6, 0x1.ffff4ep+127, 0x1.ffff4ep+127, 6e30, 0.0 },
#endif
#ifdef T_LIBM_PLUS_INF
- { T_LIBM_PLUS_INF, T_LIBM_PLUS_INF, 0.0, 0.0 },
+ { T_LIBM_PLUS_INF, T_LIBM_PLUS_INF, T_LIBM_PLUS_INF, 0.0, 0.0 },
#endif
/* The few values from the old tests */
/* Results from i386/amd64, d_eps needed on i386 */
- { 1.1, 0x1.125fbee250664p+1, 0x1p-52, 0x1.8p-22 },
- { 2.2, 0x1.2611186bae675p+2, 0x1p-51, 0x1.8p-21 },
- { 3.3, 0x1.3b2c47bff8328p+3, 0x1p-50, 0x1.8p-20 },
- { 4.4, 0x1.51cb453b9536ep+4, 0x1p-49, 0x1.8p-19 },
- { 5.5, 0x1.6a09e667f3bcdp+5, 0x1p-48, 0x1.8p-18 },
- { 6.6, 0x1.8406003b2ae5bp+6, 0x1p-47, 0x1.8p-17 },
- /*
- * These two currently fail for 'float'.
- * 8.8 is definitely out by more than it should be.
- */
- { 7.7, 0x1.9fdf8bcce533ep+7, 0x1p-46, 0x1.8p-16 },
- { 8.8, 0x1.bdb8cdadbe124p+8, 0x1p-45, 0x1.8p-15 },
+ /* f_y values calculated using py-mpmath */
+ { 1.1, 0x1.125fbee250664p+1, 0x1.125fc0p+1, 0x1p-52, 0x1.8p-22 },
+ { 2.2, 0x1.2611186bae675p+2, 0x1.26111ap+2, 0x1p-51, 0x1.8p-21 },
+ { 3.3, 0x1.3b2c47bff8328p+3, 0x1.3b2c48p+3, 0x1p-50, 0x1.8p-20 },
+ { 4.4, 0x1.51cb453b9536ep+4, 0x1.51cb46p+4, 0x1p-49, 0x1.8p-19 },
+ { 5.5, 0x1.6a09e667f3bcdp+5, 0x1.6a09e6p+5, 0x1p-48, 0x1.8p-18 },
+ { 6.6, 0x1.8406003b2ae5bp+6, 0x1.8405fep+6, 0x1p-47, 0x1.8p-17 },
+ { 7.7, 0x1.9fdf8bcce533ep+7, 0x1.9fdf88p+7, 0x1p-46, 0x1.8p-16 },
+ { 8.8, 0x1.bdb8cdadbe124p+8, 0x1.bdb8d2p+8, 0x1p-45, 0x1.8p-15 },
};
unsigned int i;
-#ifdef __FreeBSD__
- atf_tc_expect_fail("Some of the cases produce failures on FreeBSD "
- "due to the error epsilon being so small");
-#endif
-
for (i = 0; i < __arraycount(v); i++) {
- T_LIBM_CHECK(i, exp2, v[i].x, v[i].y, v[i].d_eps);
+ T_LIBM_CHECK(i, exp2, v[i].x, v[i].d_y, v[i].d_eps);
if (i > 1)
- T_LIBM_CHECK(i, exp2f, v[i].x, v[i].y, v[i].f_eps);
+ T_LIBM_CHECK(i, exp2f, v[i].x, v[i].f_y, v[i].f_eps);
}
}
diff --git a/contrib/netbsd-tests/lib/libm/t_fe_round.c b/contrib/netbsd-tests/lib/libm/t_fe_round.c
new file mode 100644
index 0000000..fe805b4
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libm/t_fe_round.c
@@ -0,0 +1,124 @@
+/*
+ * Written by Maya Rashish <maya@NetBSD.org>
+ * Public domain.
+ *
+ * Testing IEEE-754 rounding modes (and lrint)
+ */
+
+#include <atf-c.h>
+#include <fenv.h>
+#ifdef __HAVE_FENV
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+/*#pragma STDC FENV_ACCESS ON gcc?? */
+
+#define INT 9223L
+
+#define EPSILON 0.001
+
+static const struct {
+ int round_mode;
+ double input;
+ long int expected;
+} values[] = {
+ { FE_DOWNWARD, 3.7, 3},
+ { FE_DOWNWARD, -3.7, -4},
+ { FE_DOWNWARD, +0, 0},
+ { FE_DOWNWARD, -INT-0.01, -INT-1},
+ { FE_DOWNWARD, +INT-0.01, INT-1},
+ { FE_DOWNWARD, -INT+0.01, -INT},
+ { FE_DOWNWARD, +INT+0.01, INT},
+#if 0 /* cpu bugs? */
+ { FE_DOWNWARD, -0, -1},
+
+ { FE_UPWARD, +0, 1},
+#endif
+ { FE_UPWARD, -0, 0},
+ { FE_UPWARD, -123.7, -123},
+ { FE_UPWARD, 123.999, 124},
+ { FE_UPWARD, -INT-0.01, -INT},
+ { FE_UPWARD, +INT-0.01, INT},
+ { FE_UPWARD, -INT+0.01, -INT+1},
+ { FE_UPWARD, +INT+0.01, INT+1},
+
+ { FE_TOWARDZERO, 1.99, 1},
+ { FE_TOWARDZERO, -1.99, -1},
+ { FE_TOWARDZERO, 0.2, 0},
+ { FE_TOWARDZERO, INT+0.01, INT},
+ { FE_TOWARDZERO, INT-0.01, INT - 1},
+ { FE_TOWARDZERO, -INT+0.01, -INT + 1},
+ { FE_TOWARDZERO, +0, 0},
+ { FE_TOWARDZERO, -0, 0},
+
+ { FE_TONEAREST, -INT-0.01, -INT},
+ { FE_TONEAREST, +INT-0.01, INT},
+ { FE_TONEAREST, -INT+0.01, -INT},
+ { FE_TONEAREST, +INT+0.01, INT},
+ { FE_TONEAREST, -INT-0.501, -INT-1},
+ { FE_TONEAREST, +INT-0.501, INT-1},
+ { FE_TONEAREST, -INT+0.501, -INT+1},
+ { FE_TONEAREST, +INT+0.501, INT+1},
+ { FE_TONEAREST, +0, 0},
+ { FE_TONEAREST, -0, 0},
+};
+
+ATF_TC(fe_round);
+ATF_TC_HEAD(fe_round, tc)
+{
+ atf_tc_set_md_var(tc, "descr","Checking IEEE 754 rounding modes using lrint");
+}
+
+ATF_TC_BODY(fe_round, tc)
+{
+ long int received;
+
+ for (unsigned int i = 0; i < __arraycount(values); i++) {
+ fesetround(values[i].round_mode);
+
+ received = lrint(values[i].input);
+ ATF_CHECK_MSG(
+ (labs(received - values[i].expected) < EPSILON),
+ "lrint rounding wrong, difference too large\n"
+ "input: %f (index %d): got %ld, expected %ld\n",
+ values[i].input, i, received, values[i].expected);
+
+ /* Do we get the same rounding mode out? */
+ ATF_CHECK_MSG(
+ (fegetround() == values[i].round_mode),
+ "Didn't get the same rounding mode out!\n"
+ "(index %d) fed in %d rounding mode, got %d out\n",
+ i, fegetround(), values[i].round_mode);
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, fe_round);
+
+ return atf_no_error();
+}
+#else
+ATF_TC(t_nofe_round);
+
+ATF_TC_HEAD(t_nofe_round, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "dummy test case - no fenv.h support");
+}
+
+
+ATF_TC_BODY(t_nofe_round, tc)
+{
+ atf_tc_skip("no fenv.h support on this architecture");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, t_nofe_round);
+ return atf_no_error();
+}
+
+#endif
diff --git a/contrib/netbsd-tests/lib/libm/t_fenv.c b/contrib/netbsd-tests/lib/libm/t_fenv.c
new file mode 100644
index 0000000..5445036
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libm/t_fenv.c
@@ -0,0 +1,220 @@
+/* $NetBSD: t_fenv.c,v 1.3 2015/12/22 14:20:59 christos 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.
+ *
+ * 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_fenv.c,v 1.3 2015/12/22 14:20:59 christos Exp $");
+
+#include <atf-c.h>
+
+#include <fenv.h>
+#ifdef __HAVE_FENV
+
+#include <ieeefp.h>
+#include <stdlib.h>
+
+
+#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_EXC_PREREQ() \
+ if (0 == fpsetmask(fpsetmask(FP_X_INV))) \
+ atf_tc_skip("FPU does not implement exception handling");
+
+ /*
+ * Same as above: some don't allow configuring the rounding mode.
+ */
+#define FPU_RND_PREREQ() \
+ if (0 == fpsetround(fpsetround(FP_RZ))) \
+ atf_tc_skip("FPU does not implement configurable " \
+ "rounding modes");
+#endif
+
+#ifndef FPU_EXC_PREREQ
+#define FPU_EXC_PREREQ() /* nothing */
+#endif
+#ifndef FPU_RND_PREREQ
+#define FPU_RND_PREREQ() /* nothing */
+#endif
+
+
+ATF_TC(fegetround);
+
+ATF_TC_HEAD(fegetround, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "verify the fegetround() function agrees with the legacy "
+ "fpsetround");
+}
+
+ATF_TC_BODY(fegetround, tc)
+{
+ FPU_RND_PREREQ();
+
+ fpsetround(FP_RZ);
+ ATF_CHECK(fegetround() == FE_TOWARDZERO);
+ fpsetround(FP_RM);
+ ATF_CHECK(fegetround() == FE_DOWNWARD);
+ fpsetround(FP_RN);
+ ATF_CHECK(fegetround() == FE_TONEAREST);
+ fpsetround(FP_RP);
+ ATF_CHECK(fegetround() == FE_UPWARD);
+}
+
+ATF_TC(fesetround);
+
+ATF_TC_HEAD(fesetround, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "verify the fesetround() function agrees with the legacy "
+ "fpgetround");
+}
+
+ATF_TC_BODY(fesetround, tc)
+{
+ FPU_RND_PREREQ();
+
+ fesetround(FE_TOWARDZERO);
+ ATF_CHECK(fpgetround() == FP_RZ);
+ fesetround(FE_DOWNWARD);
+ ATF_CHECK(fpgetround() == FP_RM);
+ fesetround(FE_TONEAREST);
+ ATF_CHECK(fpgetround() == FP_RN);
+ fesetround(FE_UPWARD);
+ ATF_CHECK(fpgetround() == FP_RP);
+}
+
+ATF_TC(fegetexcept);
+
+ATF_TC_HEAD(fegetexcept, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "verify the fegetexcept() function agrees with the legacy "
+ "fpsetmask()");
+}
+
+ATF_TC_BODY(fegetexcept, tc)
+{
+ FPU_EXC_PREREQ();
+
+ fpsetmask(0);
+ ATF_CHECK(fegetexcept() == 0);
+
+ fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
+ ATF_CHECK(fegetexcept() == (FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW
+ |FE_UNDERFLOW|FE_INEXACT));
+
+ fpsetmask(FP_X_INV);
+ ATF_CHECK(fegetexcept() == FE_INVALID);
+
+ fpsetmask(FP_X_DZ);
+ ATF_CHECK(fegetexcept() == FE_DIVBYZERO);
+
+ fpsetmask(FP_X_OFL);
+ ATF_CHECK(fegetexcept() == FE_OVERFLOW);
+
+ fpsetmask(FP_X_UFL);
+ ATF_CHECK(fegetexcept() == FE_UNDERFLOW);
+
+ fpsetmask(FP_X_IMP);
+ ATF_CHECK(fegetexcept() == FE_INEXACT);
+}
+
+ATF_TC(feenableexcept);
+
+ATF_TC_HEAD(feenableexcept, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "verify the feenableexcept() function agrees with the legacy "
+ "fpgetmask()");
+}
+
+ATF_TC_BODY(feenableexcept, tc)
+{
+ FPU_EXC_PREREQ();
+
+ fedisableexcept(FE_ALL_EXCEPT);
+ ATF_CHECK(fpgetmask() == 0);
+
+ feenableexcept(FE_UNDERFLOW);
+ ATF_CHECK(fpgetmask() == FP_X_UFL);
+
+ fedisableexcept(FE_ALL_EXCEPT);
+ feenableexcept(FE_OVERFLOW);
+ ATF_CHECK(fpgetmask() == FP_X_OFL);
+
+ fedisableexcept(FE_ALL_EXCEPT);
+ feenableexcept(FE_DIVBYZERO);
+ ATF_CHECK(fpgetmask() == FP_X_DZ);
+
+ fedisableexcept(FE_ALL_EXCEPT);
+ feenableexcept(FE_INEXACT);
+ ATF_CHECK(fpgetmask() == FP_X_IMP);
+
+ fedisableexcept(FE_ALL_EXCEPT);
+ feenableexcept(FE_INVALID);
+ ATF_CHECK(fpgetmask() == FP_X_INV);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, fegetround);
+ ATF_TP_ADD_TC(tp, fesetround);
+ ATF_TP_ADD_TC(tp, fegetexcept);
+ ATF_TP_ADD_TC(tp, feenableexcept);
+
+ return atf_no_error();
+}
+
+#else /* no fenv.h support */
+
+ATF_TC(t_nofenv);
+
+ATF_TC_HEAD(t_nofenv, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "dummy test case - no fenv.h support");
+}
+
+
+ATF_TC_BODY(t_nofenv, tc)
+{
+ atf_tc_skip("no fenv.h support on this architecture");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, t_nofenv);
+ return atf_no_error();
+}
+
+#endif
diff --git a/contrib/netbsd-tests/lib/libm/t_fmod.c b/contrib/netbsd-tests/lib/libm/t_fmod.c
index 837e9b2..2a221f5 100644
--- a/contrib/netbsd-tests/lib/libm/t_fmod.c
+++ b/contrib/netbsd-tests/lib/libm/t_fmod.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_fmod.c,v 1.2 2014/02/27 17:26:02 joerg Exp $ */
+/* $NetBSD: t_fmod.c,v 1.3 2015/01/03 14:23:53 gson Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -33,6 +33,8 @@
#include <float.h>
#include <math.h>
+#include "isqemu.h"
+
ATF_TC(fmod);
ATF_TC_HEAD(fmod, tc)
{
@@ -41,6 +43,11 @@ ATF_TC_HEAD(fmod, tc)
ATF_TC_BODY(fmod, tc)
{
+#ifdef __NetBSD__
+ if (isQEMU())
+ atf_tc_expect_fail("PR misc/44767");
+#endif
+
ATF_CHECK(fmodf(2.0, 1.0) == 0);
ATF_CHECK(fmod(2.0, 1.0) == 0);
#if !defined(__FreeBSD__) || LDBL_PREC != 53
diff --git a/contrib/netbsd-tests/lib/libm/t_hypot.c b/contrib/netbsd-tests/lib/libm/t_hypot.c
new file mode 100644
index 0000000..deb7e86
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libm/t_hypot.c
@@ -0,0 +1,81 @@
+/* $NetBSD: t_hypot.c,v 1.1 2016/01/24 20:26:47 gson 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 <atf-c.h>
+#include <math.h>
+
+ATF_TC(hypot_integer);
+ATF_TC_HEAD(hypot_integer, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test hypot with integer args");
+}
+
+ATF_TC_BODY(hypot_integer, tc)
+{
+ /* volatile so hypotf() won't be evaluated at compile time */
+ volatile double a = 5;
+ volatile double b = 12;
+ ATF_CHECK(hypot(a, b) == 13.0);
+}
+
+ATF_TC(hypotf_integer);
+ATF_TC_HEAD(hypotf_integer, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test hypotf with integer args");
+}
+
+ATF_TC_BODY(hypotf_integer, tc)
+{
+ volatile float a = 5;
+ volatile float b = 12;
+ ATF_CHECK(hypotf(a, b) == 13.0f);
+}
+
+ATF_TC(pr50698);
+ATF_TC_HEAD(pr50698, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Check for the bug of PR 50698");
+}
+
+ATF_TC_BODY(pr50698, tc)
+{
+ volatile float a = 1e-18f;
+ float val = hypotf(a, a);
+ ATF_CHECK(!isinf(val));
+ ATF_CHECK(!isnan(val));
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, hypot_integer);
+ ATF_TP_ADD_TC(tp, hypotf_integer);
+ ATF_TP_ADD_TC(tp, pr50698);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libm/t_ilogb.c b/contrib/netbsd-tests/lib/libm/t_ilogb.c
new file mode 100644
index 0000000..b3c2126
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libm/t_ilogb.c
@@ -0,0 +1,130 @@
+/* $NetBSD: t_ilogb.c,v 1.6 2016/08/26 08:01:55 christos Exp $ */
+
+/*-
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Maya Rashish.
+ *
+ * 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.
+ */
+
+#ifdef __FreeBSD__
+#include <limits.h>
+#endif
+#include <atf-c.h>
+#include <fenv.h>
+#include <math.h>
+
+#ifndef __HAVE_FENV
+
+# define ATF_CHECK_RAISED_INVALID
+# define ATF_CHECK_RAISED_NOTHING
+
+#else
+# define ATF_CHECK_RAISED_INVALID do { \
+ int r = fetestexcept(FE_ALL_EXCEPT); \
+ ATF_CHECK_MSG(r == FE_INVALID, "r=%#x != %#x\n", r, FE_INVALID); \
+ (void)feclearexcept(FE_ALL_EXCEPT); \
+} while (/*CONSTCOND*/0)
+
+# define ATF_CHECK_RAISED_NOTHING do { \
+ int r = fetestexcept(FE_ALL_EXCEPT); \
+ ATF_CHECK_MSG(r == 0, "r=%#x != 0\n", r); \
+ (void)feclearexcept(FE_ALL_EXCEPT); \
+} while (/*CONSTCOND*/0)
+#endif
+
+ATF_TC(ilogb);
+ATF_TC_HEAD(ilogb, tc)
+{
+ atf_tc_set_md_var(tc, "descr","Check ilogb family");
+}
+
+ATF_TC_BODY(ilogb, tc)
+{
+
+ ATF_CHECK(ilogbf(0) == FP_ILOGB0);
+ ATF_CHECK_RAISED_INVALID;
+ ATF_CHECK(ilogb(0) == FP_ILOGB0);
+ ATF_CHECK_RAISED_INVALID;
+#ifdef __HAVE_LONG_DOUBLE
+ ATF_CHECK(ilogbl(0) == FP_ILOGB0);
+ ATF_CHECK_RAISED_INVALID;
+#endif
+
+ ATF_CHECK(ilogbf(-0) == FP_ILOGB0);
+ ATF_CHECK_RAISED_INVALID;
+ ATF_CHECK(ilogb(-0) == FP_ILOGB0);
+ ATF_CHECK_RAISED_INVALID;
+#ifdef __HAVE_LONG_DOUBLE
+ ATF_CHECK(ilogbl(-0) == FP_ILOGB0);
+ ATF_CHECK_RAISED_INVALID;
+#endif
+
+ ATF_CHECK(ilogbf(INFINITY) == INT_MAX);
+ ATF_CHECK_RAISED_INVALID;
+ ATF_CHECK(ilogb(INFINITY) == INT_MAX);
+ ATF_CHECK_RAISED_INVALID;
+#ifdef __HAVE_LONG_DOUBLE
+ ATF_CHECK(ilogbl(INFINITY) == INT_MAX);
+ ATF_CHECK_RAISED_INVALID;
+#endif
+
+ ATF_CHECK(ilogbf(-INFINITY) == INT_MAX);
+ ATF_CHECK_RAISED_INVALID;
+ ATF_CHECK(ilogb(-INFINITY) == INT_MAX);
+ ATF_CHECK_RAISED_INVALID;
+#ifdef __HAVE_LONG_DOUBLE
+ ATF_CHECK(ilogbl(-INFINITY) == INT_MAX);
+ ATF_CHECK_RAISED_INVALID;
+#endif
+
+ ATF_CHECK(ilogbf(1024) == 10);
+ ATF_CHECK_RAISED_NOTHING;
+ ATF_CHECK(ilogb(1024) == 10);
+ ATF_CHECK_RAISED_NOTHING;
+#ifdef __HAVE_LONG_DOUBLE
+ ATF_CHECK(ilogbl(1024) == 10);
+ ATF_CHECK_RAISED_NOTHING;
+#endif
+
+#ifndef __vax__
+ ATF_CHECK(ilogbf(NAN) == FP_ILOGBNAN);
+ ATF_CHECK_RAISED_INVALID;
+ ATF_CHECK(ilogb(NAN) == FP_ILOGBNAN);
+ ATF_CHECK_RAISED_INVALID;
+#ifdef __HAVE_LONG_DOUBLE
+ ATF_CHECK(ilogbl(NAN) == FP_ILOGBNAN);
+ ATF_CHECK_RAISED_INVALID;
+#endif
+#endif
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, ilogb);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libm/t_ldexp.c b/contrib/netbsd-tests/lib/libm/t_ldexp.c
index eaf8a4b..251f2ae 100644
--- a/contrib/netbsd-tests/lib/libm/t_ldexp.c
+++ b/contrib/netbsd-tests/lib/libm/t_ldexp.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ldexp.c,v 1.14 2014/11/04 00:20:19 justin Exp $ */
+/* $NetBSD: t_ldexp.c,v 1.16 2016/08/25 00:32:31 maya Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_ldexp.c,v 1.14 2014/11/04 00:20:19 justin Exp $");
+__RCSID("$NetBSD: t_ldexp.c,v 1.16 2016/08/25 00:32:31 maya Exp $");
#include <sys/param.h>
@@ -96,10 +96,12 @@ struct ldexp_test ldexp_overflow[] = {
{ 1.0, 1023, 1, " inf" },
{ 1.0, -1022, 2046, " inf" },
{ 1.0, 1025, SKIP, " inf" },
+ { 2.0, INT_MAX,SKIP, " inf" },
{ -1.0, 1024, SKIP, " -inf" },
{ -1.0, 1023, 1, " -inf" },
{ -1.0, -1022, 2046, " -inf" },
{ -1.0, 1025, SKIP, " -inf" },
+ { -2.0, INT_MAX,SKIP, " -inf" },
{ 0, 0, 0, NULL }
};
@@ -170,10 +172,8 @@ run_test(struct ldexp_test *table)
v = ldexp(table->x, table->exp1);
- if (table->exp2 == SKIP)
- continue;
-
- v = ldexp(v, table->exp2);
+ if (table->exp2 != SKIP)
+ v = ldexp(v, table->exp2);
(void)snprintf(outbuf, sizeof(outbuf), FORMAT, v);
diff --git a/contrib/netbsd-tests/lib/libm/t_log.c b/contrib/netbsd-tests/lib/libm/t_log.c
index 0164233..756efcf 100644
--- a/contrib/netbsd-tests/lib/libm/t_log.c
+++ b/contrib/netbsd-tests/lib/libm/t_log.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_log.c,v 1.12 2014/11/04 00:20:19 justin Exp $ */
+/* $NetBSD: t_log.c,v 1.13 2015/02/09 19:39:48 martin Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_log.c,v 1.12 2014/11/04 00:20:19 justin Exp $");
+__RCSID("$NetBSD: t_log.c,v 1.13 2015/02/09 19:39:48 martin Exp $");
#include <atf-c.h>
@@ -186,10 +186,6 @@ ATF_TC_BODY(log10f_inf_pos, tc)
{
const float x = 1.0L / 0.0L;
-#if defined(__alpha__)
- atf_tc_expect_fail("PR port-alpha/46301");
-#endif
-
ATF_CHECK(log10f(x) == x);
}
@@ -562,10 +558,6 @@ ATF_TC_BODY(log2f_inf_pos, tc)
{
const float x = 1.0L / 0.0L;
-#if defined(__alpha__)
- atf_tc_expect_fail("PR port-alpha/46301");
-#endif
-
ATF_CHECK(log2f(x) == x);
}
@@ -766,10 +758,6 @@ ATF_TC_BODY(logf_inf_pos, tc)
{
const float x = 1.0L / 0.0L;
-#if defined(__alpha__)
- atf_tc_expect_fail("PR port-alpha/46301");
-#endif
-
ATF_CHECK(logf(x) == x);
}
diff --git a/contrib/netbsd-tests/lib/libm/t_pow.c b/contrib/netbsd-tests/lib/libm/t_pow.c
index a8ae6f0..fbdb984 100644
--- a/contrib/netbsd-tests/lib/libm/t_pow.c
+++ b/contrib/netbsd-tests/lib/libm/t_pow.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_pow.c,v 1.3 2014/03/03 10:39:08 martin Exp $ */
+/* $NetBSD: t_pow.c,v 1.4 2015/09/08 05:24:27 dholland Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_pow.c,v 1.3 2014/03/03 10:39:08 martin Exp $");
+__RCSID("$NetBSD: t_pow.c,v 1.4 2015/09/08 05:24:27 dholland Exp $");
#include <atf-c.h>
#include <math.h>
@@ -284,21 +284,18 @@ ATF_TC_BODY(pow_zero_x, tc)
z = pow(+0.0, -4.0);
if (z != HUGE_VAL) {
- atf_tc_expect_fail("PR port-amd64/45391");
atf_tc_fail_nonfatal("pow(+0.0, -4.0) != HUGE_VAL");
}
z = pow(-0.0, -4.0);
if (z != HUGE_VAL) {
- atf_tc_expect_fail("PR port-amd64/45391");
atf_tc_fail_nonfatal("pow(-0.0, -4.0) != HUGE_VAL");
}
z = pow(+0.0, -5.0);
if (z != HUGE_VAL) {
- atf_tc_expect_fail("PR port-amd64/45391");
atf_tc_fail_nonfatal("pow(+0.0, -5.0) != HUGE_VAL");
}
diff --git a/contrib/netbsd-tests/lib/libm/t_precision.c b/contrib/netbsd-tests/lib/libm/t_precision.c
index c01deba..df2d8a3 100644
--- a/contrib/netbsd-tests/lib/libm/t_precision.c
+++ b/contrib/netbsd-tests/lib/libm/t_precision.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_precision.c,v 1.2 2014/11/04 00:20:19 justin Exp $ */
+/* $NetBSD: t_precision.c,v 1.3 2016/08/27 10:07:05 christos Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_precision.c,v 1.2 2014/11/04 00:20:19 justin Exp $");
+__RCSID("$NetBSD: t_precision.c,v 1.3 2016/08/27 10:07:05 christos Exp $");
#include <atf-c.h>
@@ -45,7 +45,9 @@ ATF_TC_HEAD(t_precision, tc)
}
volatile double x = 1;
+#if __HAVE_LONG_DOUBLE
volatile long double y = 1;
+#endif
ATF_TC_BODY(t_precision, tc)
{
@@ -58,7 +60,7 @@ ATF_TC_BODY(t_precision, tc)
x += DBL_EPSILON;
ATF_CHECK(x == 2.0);
-#if !defined(__FreeBSD__) || !defined(__i386__)
+#if __HAVE_LONG_DOUBLE
y += LDBL_EPSILON;
ATF_CHECK(y != 1.0L);
y -= 1;
diff --git a/contrib/netbsd-tests/lib/libpthread/h_common.h b/contrib/netbsd-tests/lib/libpthread/h_common.h
index f4d03bc..2e8b0a1 100644
--- a/contrib/netbsd-tests/lib/libpthread/h_common.h
+++ b/contrib/netbsd-tests/lib/libpthread/h_common.h
@@ -9,4 +9,10 @@
ATF_REQUIRE_MSG(ret == 0, "%s: %s", #x, strerror(ret)); \
} while (0)
+#define PTHREAD_REQUIRE_STATUS(x, v) \
+ do { \
+ int ret = (x); \
+ ATF_REQUIRE_MSG(ret == (v), "%s: %s", #x, strerror(ret)); \
+ } while (0)
+
#endif // H_COMMON_H
diff --git a/contrib/netbsd-tests/lib/libpthread/t_cond.c b/contrib/netbsd-tests/lib/libpthread/t_cond.c
index 9f33c9e..83a3833 100644
--- a/contrib/netbsd-tests/lib/libpthread/t_cond.c
+++ b/contrib/netbsd-tests/lib/libpthread/t_cond.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_cond.c,v 1.6 2014/09/03 16:23:24 gson Exp $ */
+/* $NetBSD: t_cond.c,v 1.7 2016/07/03 14:24:59 christos Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_cond.c,v 1.6 2014/09/03 16:23:24 gson Exp $");
+__RCSID("$NetBSD: t_cond.c,v 1.7 2016/07/03 14:24:59 christos Exp $");
#include <sys/time.h>
@@ -547,6 +547,26 @@ ATF_TC_BODY(destroy_after_cancel, tc)
PTHREAD_REQUIRE(pthread_mutex_destroy(&mutex));
}
+ATF_TC(condattr);
+ATF_TC_HEAD(condattr, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks Condattr");
+}
+ATF_TC_BODY(condattr, tc)
+{
+ pthread_condattr_t condattr;
+ clockid_t clockid;
+
+ PTHREAD_REQUIRE(pthread_condattr_init(&condattr));
+ PTHREAD_REQUIRE(pthread_condattr_setclock(&condattr, CLOCK_REALTIME));
+ PTHREAD_REQUIRE(pthread_condattr_getclock(&condattr, &clockid));
+ ATF_REQUIRE_EQ(clockid, CLOCK_REALTIME);
+
+ PTHREAD_REQUIRE(pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC));
+ PTHREAD_REQUIRE(pthread_condattr_getclock(&condattr, &clockid));
+ ATF_REQUIRE_EQ(clockid, CLOCK_MONOTONIC);
+}
+
ATF_TP_ADD_TCS(tp)
{
@@ -558,6 +578,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, broadcast);
ATF_TP_ADD_TC(tp, bogus_timedwaits);
ATF_TP_ADD_TC(tp, destroy_after_cancel);
+ ATF_TP_ADD_TC(tp, condattr);
return atf_no_error();
}
diff --git a/contrib/netbsd-tests/lib/libpthread/t_mutex.c b/contrib/netbsd-tests/lib/libpthread/t_mutex.c
index eb371fa..b8d60e6 100644
--- a/contrib/netbsd-tests/lib/libpthread/t_mutex.c
+++ b/contrib/netbsd-tests/lib/libpthread/t_mutex.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mutex.c,v 1.7 2014/11/04 00:20:19 justin Exp $ */
+/* $NetBSD: t_mutex.c,v 1.14 2016/10/31 23:51:20 christos Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,12 +29,20 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_mutex.c,v 1.7 2014/11/04 00:20:19 justin Exp $");
+__RCSID("$NetBSD: t_mutex.c,v 1.14 2016/10/31 23:51:20 christos Exp $");
+#ifdef __FreeBSD__
+#include <sys/time.h> /* For timespecadd */
+#include <inttypes.h> /* For UINT16_MAX */
+#endif
#include <pthread.h>
#include <stdio.h>
#include <string.h>
+#include <errno.h>
+#include <time.h>
#include <unistd.h>
+#include <sys/sched.h>
+#include <sys/param.h>
#include <atf-c.h>
@@ -44,6 +52,31 @@ static pthread_mutex_t mutex;
static pthread_mutex_t static_mutex = PTHREAD_MUTEX_INITIALIZER;
static int global_x;
+#ifdef TIMEDMUTEX
+/* This code is used for verifying non-timed specific code */
+static struct timespec ts_lengthy = {
+ .tv_sec = UINT16_MAX,
+ .tv_nsec = 0
+};
+/* This code is used for verifying timed-only specific code */
+static struct timespec ts_shortlived = {
+ .tv_sec = 0,
+ .tv_nsec = 120
+};
+
+static int
+mutex_lock(pthread_mutex_t *m, const struct timespec *ts)
+{
+ struct timespec ts_wait;
+ ATF_REQUIRE(clock_gettime(CLOCK_REALTIME, &ts_wait) != -1);
+ timespecadd(&ts_wait, ts, &ts_wait);
+
+ return pthread_mutex_timedlock(m, &ts_wait);
+}
+#else
+#define mutex_lock(a, b) pthread_mutex_lock(a)
+#endif
+
static void *
mutex1_threadfunc(void *arg)
{
@@ -53,7 +86,7 @@ mutex1_threadfunc(void *arg)
param = arg;
printf("2: Locking mutex\n");
- pthread_mutex_lock(&mutex);
+ mutex_lock(&mutex, &ts_lengthy);
printf("2: Got mutex. *param = %d\n", *param);
ATF_REQUIRE_EQ(*param, 20);
(*param)++;
@@ -78,7 +111,7 @@ ATF_TC_BODY(mutex1, tc)
PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
x = 1;
- PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+ PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex1_threadfunc, &x));
printf("1: Before changing the value.\n");
sleep(2);
@@ -89,7 +122,7 @@ ATF_TC_BODY(mutex1, tc)
printf("1: After releasing the mutex.\n");
PTHREAD_REQUIRE(pthread_join(new, &joinval));
- PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+ PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
printf("1: Thread joined. X was %d. Return value (int) was %d\n",
x, *(int *)joinval);
ATF_REQUIRE_EQ(x, 21);
@@ -105,7 +138,7 @@ mutex2_threadfunc(void *arg)
printf("2: Second thread (%p). Count is %ld\n", pthread_self(), count);
while (count--) {
- PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+ PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
global_x++;
PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
}
@@ -142,7 +175,7 @@ ATF_TC_BODY(mutex2, tc)
global_x = 0;
count = count2 = 10000000;
- PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+ PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex2_threadfunc, &count2));
printf("1: Thread %p\n", pthread_self());
@@ -150,14 +183,14 @@ ATF_TC_BODY(mutex2, tc)
PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
while (count--) {
- PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+ PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
global_x++;
PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
}
PTHREAD_REQUIRE(pthread_join(new, &joinval));
- PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+ PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
printf("1: Thread joined. X was %d. Return value (long) was %ld\n",
global_x, (long)joinval);
ATF_REQUIRE_EQ(global_x, 20000000);
@@ -181,7 +214,7 @@ mutex3_threadfunc(void *arg)
printf("2: Second thread (%p). Count is %ld\n", pthread_self(), count);
while (count--) {
- PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex));
+ PTHREAD_REQUIRE(mutex_lock(&static_mutex, &ts_lengthy));
global_x++;
PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
}
@@ -217,7 +250,7 @@ ATF_TC_BODY(mutex3, tc)
global_x = 0;
count = count2 = 10000000;
- PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex));
+ PTHREAD_REQUIRE(mutex_lock(&static_mutex, &ts_lengthy));
PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex3_threadfunc, &count2));
printf("1: Thread %p\n", pthread_self());
@@ -225,14 +258,14 @@ ATF_TC_BODY(mutex3, tc)
PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
while (count--) {
- PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex));
+ PTHREAD_REQUIRE(mutex_lock(&static_mutex, &ts_lengthy));
global_x++;
PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
}
PTHREAD_REQUIRE(pthread_join(new, &joinval));
- PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex));
+ PTHREAD_REQUIRE(mutex_lock(&static_mutex, &ts_lengthy));
printf("1: Thread joined. X was %d. Return value (long) was %ld\n",
global_x, (long)joinval);
ATF_REQUIRE_EQ(global_x, 20000000);
@@ -257,7 +290,7 @@ mutex4_threadfunc(void *arg)
param = arg;
printf("2: Locking mutex\n");
- PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+ PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
printf("2: Got mutex. *param = %d\n", *param);
(*param)++;
@@ -288,11 +321,11 @@ ATF_TC_BODY(mutex4, tc)
PTHREAD_REQUIRE(pthread_mutexattr_destroy(&mattr));
x = 1;
- PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+ PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex4_threadfunc, &x));
printf("1: Before recursively acquiring the mutex.\n");
- PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+ PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
printf("1: Before releasing the mutex once.\n");
sleep(2);
@@ -308,7 +341,7 @@ ATF_TC_BODY(mutex4, tc)
PTHREAD_REQUIRE(pthread_join(new, &joinval));
- PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+ PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
printf("1: Thread joined. X was %d. Return value (int) was %d\n",
x, *(int *)joinval);
ATF_REQUIRE_EQ(x, 21);
@@ -316,12 +349,405 @@ ATF_TC_BODY(mutex4, tc)
PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
}
+#ifdef __NetBSD__
+static pthread_mutexattr_t attr5;
+static pthread_mutex_t mutex5;
+static int min_fifo_prio, max_fifo_prio;
+
+static void *
+child_func(void* arg)
+{
+ int res;
+
+ printf("child is waiting\n");
+ res = _sched_protect(-2);
+ ATF_REQUIRE_EQ_MSG(res, -1, "sched_protect returned %d", res);
+ ATF_REQUIRE_EQ(errno, ENOENT);
+ PTHREAD_REQUIRE(mutex_lock(&mutex5, &ts_lengthy));
+ printf("child is owning resource\n");
+ res = _sched_protect(-2);
+ ATF_REQUIRE_EQ(res, max_fifo_prio);
+ PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex5));
+ printf("child is done\n");
+
+ return 0;
+}
+
+ATF_TC(mutex5);
+ATF_TC_HEAD(mutex5, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks mutexes for priority setting");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+
+ATF_TC_BODY(mutex5, tc)
+{
+ int res;
+ struct sched_param param;
+ pthread_t child;
+
+ min_fifo_prio = sched_get_priority_min(SCHED_FIFO);
+ max_fifo_prio = sched_get_priority_max(SCHED_FIFO);
+ printf("min prio for FIFO = %d\n", min_fifo_prio);
+ param.sched_priority = min_fifo_prio;
+
+ /* = 0 OTHER, 1 FIFO, 2 RR, -1 NONE */
+ res = sched_setscheduler(getpid(), SCHED_FIFO, &param);
+ printf("previous policy used = %d\n", res);
+
+ res = sched_getscheduler(getpid());
+ ATF_REQUIRE_EQ_MSG(res, SCHED_FIFO, "sched %d != FIFO %d", res,
+ SCHED_FIFO);
+
+ PTHREAD_REQUIRE(pthread_mutexattr_init(&attr5));
+ PTHREAD_REQUIRE(pthread_mutexattr_setprotocol(&attr5,
+ PTHREAD_PRIO_PROTECT));
+ PTHREAD_REQUIRE(pthread_mutexattr_setprioceiling(&attr5,
+ max_fifo_prio));
+
+ PTHREAD_REQUIRE(pthread_mutex_init(&mutex5, &attr5));
+ PTHREAD_REQUIRE(mutex_lock(&mutex5, &ts_lengthy));
+ printf("enter critical section for main\n");
+ PTHREAD_REQUIRE(pthread_create(&child, NULL, child_func, NULL));
+ printf("main starts to sleep\n");
+ sleep(10);
+ printf("main completes\n");
+ PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex5));
+ PTHREAD_REQUIRE(pthread_join(child, NULL));
+}
+
+static pthread_mutex_t mutex6;
+static int start = 0;
+static uintmax_t high_cnt = 0, low_cnt = 0, MAX_LOOP = 100000000;
+
+static void *
+high_prio(void* arg)
+{
+ struct sched_param param;
+ int policy;
+ param.sched_priority = min_fifo_prio + 10;
+ pthread_t childid = pthread_self();
+
+ PTHREAD_REQUIRE(pthread_setschedparam(childid, 1, &param));
+ PTHREAD_REQUIRE(pthread_getschedparam(childid, &policy, &param));
+ printf("high protect = %d, prio = %d\n",
+ _sched_protect(-2), param.sched_priority);
+ ATF_REQUIRE_EQ(policy, 1);
+ printf("high prio = %d\n", param.sched_priority);
+ sleep(1);
+ long tmp = 0;
+ for (int i = 0; i < 20; i++) {
+ while (high_cnt < MAX_LOOP) {
+ tmp += (123456789 % 1234) * (987654321 % 54321);
+ high_cnt += 1;
+ }
+ high_cnt = 0;
+ sleep(1);
+ }
+ PTHREAD_REQUIRE(mutex_lock(&mutex6, &ts_lengthy));
+ if (start == 0) start = 2;
+ PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex6));
+
+ return 0;
+}
+
+static void *
+low_prio(void* arg)
+{
+ struct sched_param param;
+ int policy;
+ param.sched_priority = min_fifo_prio;
+ pthread_t childid = pthread_self();
+ int res = _sched_protect(max_fifo_prio);
+ ATF_REQUIRE_EQ(res, 0);
+ PTHREAD_REQUIRE(pthread_setschedparam(childid, 1, &param));
+ PTHREAD_REQUIRE(pthread_getschedparam(childid, &policy, &param));
+ printf("low protect = %d, prio = %d\n", _sched_protect(-2),
+ param.sched_priority);
+ ATF_REQUIRE_EQ(policy, 1);
+ printf("low prio = %d\n", param.sched_priority);
+ sleep(1);
+ long tmp = 0;
+ for (int i = 0; i < 20; i++) {
+ while (low_cnt < MAX_LOOP) {
+ tmp += (123456789 % 1234) * (987654321 % 54321);
+ low_cnt += 1;
+ }
+ low_cnt = 0;
+ sleep(1);
+ }
+ PTHREAD_REQUIRE(mutex_lock(&mutex6, &ts_lengthy));
+ if (start == 0)
+ start = 1;
+ PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex6));
+
+ return 0;
+}
+
+ATF_TC(mutex6);
+ATF_TC_HEAD(mutex6, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Checks scheduling for priority ceiling");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+
+/*
+ * 1. main thread sets itself to be a realtime task and launched two tasks,
+ * one has higher priority and the other has lower priority.
+ * 2. each child thread(low and high priority thread) sets its scheduler and
+ * priority.
+ * 3. each child thread did several rounds of computation, after each round it
+ * sleep 1 second.
+ * 4. the child thread with low priority will call _sched_protect to increase
+ * its protect priority.
+ * 5. We verify the thread with low priority runs first.
+ *
+ * Why does it work? From the main thread, we launched the high
+ * priority thread first. This gives this thread the benefit of
+ * starting first. The low priority thread did not call _sched_protect(2).
+ * The high priority thread should finish the task first. After each
+ * round of computation, we call sleep, to put the task into the
+ * sleep queue, and wake up again after the timer expires. This
+ * gives the scheduler the chance to decide which task to run. So,
+ * the thread with real high priority will always block the thread
+ * with real low priority.
+ *
+ */
+ATF_TC_BODY(mutex6, tc)
+{
+ struct sched_param param;
+ int res;
+ pthread_t high, low;
+
+ min_fifo_prio = sched_get_priority_min(SCHED_FIFO);
+ max_fifo_prio = sched_get_priority_max(SCHED_FIFO);
+ PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
+ printf("min_fifo_prio = %d, max_fifo_info = %d\n", min_fifo_prio,
+ max_fifo_prio);
+
+ param.sched_priority = min_fifo_prio;
+ res = sched_setscheduler(getpid(), SCHED_FIFO, &param);
+ printf("previous policy used = %d\n", res);
+
+ res = sched_getscheduler(getpid());
+ ATF_REQUIRE_EQ(res, 1);
+ PTHREAD_REQUIRE(pthread_create(&high, NULL, high_prio, NULL));
+ PTHREAD_REQUIRE(pthread_create(&low, NULL, low_prio, NULL));
+ sleep(5);
+ PTHREAD_REQUIRE(pthread_join(low, NULL));
+ PTHREAD_REQUIRE(pthread_join(high, NULL));
+
+ ATF_REQUIRE_EQ(start, 1);
+}
+#endif
+
+ATF_TC(mutexattr1);
+ATF_TC_HEAD(mutexattr1, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks mutexattr");
+}
+
+ATF_TC_BODY(mutexattr1, tc)
+{
+ pthread_mutexattr_t mattr;
+ int protocol, target;
+
+ PTHREAD_REQUIRE(pthread_mutexattr_init(&mattr));
+
+ target = PTHREAD_PRIO_NONE;
+ PTHREAD_REQUIRE(pthread_mutexattr_setprotocol(&mattr, target));
+ PTHREAD_REQUIRE(pthread_mutexattr_getprotocol(&mattr, &protocol));
+ ATF_REQUIRE_EQ(protocol, target);
+
+ /*
+ target = PTHREAD_PRIO_INHERIT;
+ PTHREAD_REQUIRE(pthread_mutexattr_setprotocol(&mattr, target));
+ PTHREAD_REQUIRE(pthread_mutexattr_getprotocol(&mattr, &protocol));
+ ATF_REQUIRE_EQ(protocol, target);
+ */
+
+ target = PTHREAD_PRIO_PROTECT;
+ PTHREAD_REQUIRE(pthread_mutexattr_setprotocol(&mattr, target));
+ PTHREAD_REQUIRE(pthread_mutexattr_getprotocol(&mattr, &protocol));
+ ATF_REQUIRE_EQ(protocol, target);
+}
+
+ATF_TC(mutexattr2);
+ATF_TC_HEAD(mutexattr2, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks mutexattr");
+}
+
+ATF_TC_BODY(mutexattr2, tc)
+{
+ pthread_mutexattr_t mattr;
+
+#ifdef __FreeBSD__
+ atf_tc_expect_fail("fails on i == 0 with: "
+ "pthread_mutexattr_setprioceiling(&mattr, i): Invalid argument "
+ "-- PR # 211802");
+#endif
+
+ PTHREAD_REQUIRE(pthread_mutexattr_init(&mattr));
+ int max_prio = sched_get_priority_max(SCHED_FIFO);
+ int min_prio = sched_get_priority_min(SCHED_FIFO);
+ for (int i = min_prio; i <= max_prio; i++) {
+ int prioceiling;
+#ifdef __FreeBSD__
+ int protocol;
+
+ PTHREAD_REQUIRE(pthread_mutexattr_getprotocol(&mattr,
+ &protocol));
+
+ printf("priority: %d\nprotocol: %d\n", i, protocol);
+#endif
+ PTHREAD_REQUIRE(pthread_mutexattr_setprioceiling(&mattr, i));
+ PTHREAD_REQUIRE(pthread_mutexattr_getprioceiling(&mattr,
+ &prioceiling));
+#ifdef __FreeBSD__
+ printf("prioceiling: %d\n", prioceiling);
+#endif
+ ATF_REQUIRE_EQ(i, prioceiling);
+ }
+}
+
+#ifdef TIMEDMUTEX
+ATF_TC(timedmutex1);
+ATF_TC_HEAD(timedmutex1, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks timeout on selflock");
+}
+
+ATF_TC_BODY(timedmutex1, tc)
+{
+
+ printf("Timed mutex-test 1\n");
+
+ PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
+
+ printf("Before acquiring mutex\n");
+ PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+
+ printf("Before endeavor to reacquire timed-mutex (timeout expected)\n");
+ PTHREAD_REQUIRE_STATUS(mutex_lock(&mutex, &ts_shortlived),
+ ETIMEDOUT);
+
+ printf("Unlocking mutex\n");
+ PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
+}
+
+ATF_TC(timedmutex2);
+ATF_TC_HEAD(timedmutex2, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Checks timeout on selflock with timedlock");
+}
+
+ATF_TC_BODY(timedmutex2, tc)
+{
+
+ printf("Timed mutex-test 2\n");
+
+ PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
+
+ printf("Before acquiring mutex with timedlock\n");
+ PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
+
+ printf("Before endeavor to reacquire timed-mutex (timeout expected)\n");
+ PTHREAD_REQUIRE_STATUS(mutex_lock(&mutex, &ts_shortlived),
+ ETIMEDOUT);
+
+ printf("Unlocking mutex\n");
+ PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
+}
+
+ATF_TC(timedmutex3);
+ATF_TC_HEAD(timedmutex3, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Checks timeout on selflock in a new thread");
+}
+
+static void *
+timedmtx_thrdfunc(void *arg)
+{
+ printf("Before endeavor to reacquire timed-mutex (timeout expected)\n");
+ PTHREAD_REQUIRE_STATUS(mutex_lock(&mutex, &ts_shortlived),
+ ETIMEDOUT);
+
+ return NULL;
+}
+
+ATF_TC_BODY(timedmutex3, tc)
+{
+ pthread_t new;
+
+ printf("Timed mutex-test 3\n");
+
+ PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
+
+ printf("Before acquiring mutex with timedlock\n");
+ PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+
+ printf("Before creating new thread\n");
+ PTHREAD_REQUIRE(pthread_create(&new, NULL, timedmtx_thrdfunc, NULL));
+
+ printf("Before joining the mutex\n");
+ PTHREAD_REQUIRE(pthread_join(new, NULL));
+
+ printf("Unlocking mutex\n");
+ PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
+}
+
+ATF_TC(timedmutex4);
+ATF_TC_HEAD(timedmutex4, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Checks timeout on selflock with timedlock in a new thread");
+}
+
+ATF_TC_BODY(timedmutex4, tc)
+{
+ pthread_t new;
+
+ printf("Timed mutex-test 4\n");
+
+ PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
+
+ printf("Before acquiring mutex with timedlock\n");
+ PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
+
+ printf("Before creating new thread\n");
+ PTHREAD_REQUIRE(pthread_create(&new, NULL, timedmtx_thrdfunc, NULL));
+
+ printf("Before joining the mutex\n");
+ PTHREAD_REQUIRE(pthread_join(new, NULL));
+
+ printf("Unlocking mutex\n");
+ PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
+}
+#endif
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, mutex1);
ATF_TP_ADD_TC(tp, mutex2);
ATF_TP_ADD_TC(tp, mutex3);
ATF_TP_ADD_TC(tp, mutex4);
+#ifdef __NetBSD__
+ ATF_TP_ADD_TC(tp, mutex5);
+ ATF_TP_ADD_TC(tp, mutex6);
+#endif
+ ATF_TP_ADD_TC(tp, mutexattr1);
+ ATF_TP_ADD_TC(tp, mutexattr2);
+
+#ifdef TIMEDMUTEX
+ ATF_TP_ADD_TC(tp, timedmutex1);
+ ATF_TP_ADD_TC(tp, timedmutex2);
+ ATF_TP_ADD_TC(tp, timedmutex3);
+ ATF_TP_ADD_TC(tp, timedmutex4);
+#endif
return atf_no_error();
}
diff --git a/contrib/netbsd-tests/lib/libpthread/t_rwlock.c b/contrib/netbsd-tests/lib/libpthread/t_rwlock.c
index b2a3d6f..81f8c58 100644
--- a/contrib/netbsd-tests/lib/libpthread/t_rwlock.c
+++ b/contrib/netbsd-tests/lib/libpthread/t_rwlock.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_rwlock.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */
+/* $NetBSD: t_rwlock.c,v 1.2 2015/06/26 11:07:20 pooka Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_rwlock.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $");
+__RCSID("$NetBSD: t_rwlock.c,v 1.2 2015/06/26 11:07:20 pooka Exp $");
#include <errno.h>
#include <pthread.h>
@@ -70,6 +70,8 @@ pthread_rwlock_t lk;
struct timespec to;
+static pthread_rwlock_t static_rwlock = PTHREAD_RWLOCK_INITIALIZER;
+
/* ARGSUSED */
static void *
do_nothing(void *dummy)
@@ -117,9 +119,23 @@ ATF_TC_BODY(rwlock1, tc)
"%s", strerror(error));
}
+ATF_TC(rwlock_static);
+ATF_TC_HEAD(rwlock_static, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "rwlock w/ static initializer");
+}
+ATF_TC_BODY(rwlock_static, tc)
+{
+
+ PTHREAD_REQUIRE(pthread_rwlock_rdlock(&static_rwlock));
+ PTHREAD_REQUIRE(pthread_rwlock_unlock(&static_rwlock));
+ PTHREAD_REQUIRE(pthread_rwlock_destroy(&static_rwlock));
+}
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, rwlock1);
+ ATF_TP_ADD_TC(tp, rwlock_static);
return atf_no_error();
}
diff --git a/contrib/netbsd-tests/lib/libpthread/t_swapcontext.c b/contrib/netbsd-tests/lib/libpthread/t_swapcontext.c
index a18ac2f..8536846 100644
--- a/contrib/netbsd-tests/lib/libpthread/t_swapcontext.c
+++ b/contrib/netbsd-tests/lib/libpthread/t_swapcontext.c
@@ -104,6 +104,15 @@ ATF_TC_BODY(swapcontext1, tc)
{
pthread_t thread;
+#if defined(__FreeBSD__) && defined(__mips__)
+ /*
+ * MIPS modifies TLS pointer in set_mcontext(), so
+ * swapping contexts obtained from different threads
+ * gives us different pthread_self() return value.
+ */
+ atf_tc_skip("Platform is not supported.");
+#endif
+
oself = (void *)&val1;
nself = (void *)&val2;
diff --git a/contrib/netbsd-tests/lib/libpthread/t_timedmutex.c b/contrib/netbsd-tests/lib/libpthread/t_timedmutex.c
new file mode 100644
index 0000000..4f71acd
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libpthread/t_timedmutex.c
@@ -0,0 +1,30 @@
+/* $NetBSD: t_timedmutex.c,v 1.2 2016/10/31 16:21:23 christos Exp $ */
+
+/*
+ * Copyright (c) 2008 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 TIMEDMUTEX
+#include "t_mutex.c"
diff --git a/contrib/netbsd-tests/lib/librumpclient/h_execthr.c b/contrib/netbsd-tests/lib/librumpclient/h_execthr.c
index f653fe6..c209375 100644
--- a/contrib/netbsd-tests/lib/librumpclient/h_execthr.c
+++ b/contrib/netbsd-tests/lib/librumpclient/h_execthr.c
@@ -1,4 +1,4 @@
-/* $NetBSD: h_execthr.c,v 1.3 2014/08/13 00:03:00 pooka Exp $ */
+/* $NetBSD: h_execthr.c,v 1.7 2016/11/24 00:37:29 dholland Exp $ */
/*
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -42,6 +42,14 @@
#include <rump/rumpclient.h>
#include <rump/rump_syscalls.h>
+//#define VERBOSE
+
+#ifdef VERBOSE
+#define SAY(...) printf(__VA_ARGS__)
+#else
+#define SAY(...)
+#endif
+
static int canreturn = 0;
/*
@@ -103,6 +111,7 @@ main(int argc, char *argv[], char *envp[])
else
execd = 0;
sprintf(nexec, "%d", execd+1);
+ SAY("execd: %d\n", execd);
if (rumpclient_init() == -1) {
if (execd)
@@ -111,33 +120,43 @@ main(int argc, char *argv[], char *envp[])
err(1, "init");
}
mypid = rump_sys_getpid();
+ SAY("rumpclient_init finished.\n");
if (execd) {
canreturn = 1;
- if (pthread_create(&pt, NULL,
- wrk, (void *)(uintptr_t)P2_0) != 0)
- errx(1, "exec pthread_create");
+ errno = pthread_create(&pt, NULL,
+ wrk, (void *)(uintptr_t)P2_0);
+ if (errno != 0)
+ err(1, "exec pthread_create");
+ SAY("startup pthread_create finished.\n");
i = 37;
rump_sys_write(P2_1, &i, sizeof(i));
pthread_join(pt, NULL);
+ SAY("startup pthread_join finished.\n");
n = rump_sys_read(P1_0, &i, sizeof(i));
if (n != -1 || errno != EBADF)
errx(1, "post-exec cloexec works");
+ SAY("startup rump_sys_read finished.\n");
getproc(mypid, &p);
+ SAY("startup getproc finished.\n");
if (p.p_nlwps != 2)
errx(1, "invalid nlwps: %lld", (long long)p.p_nlwps);
/* we passed? */
- if (execd > 10)
+ if (execd > 10) {
+ SAY("done.\n");
exit(0);
+ }
rump_sys_close(P2_0);
rump_sys_close(P2_1);
}
+ SAY("making pipes...\n");
+
if (rump_sys_pipe(p1) == -1)
err(1, "pipe1");
if (p1[0] != P1_0 || p1[1] != P1_1)
@@ -151,32 +170,47 @@ main(int argc, char *argv[], char *envp[])
if (rump_sys_fcntl(p1[1], F_SETFD, FD_CLOEXEC) == -1)
err(1, "cloexec");
- for (i = 0; i < NTHR; i++)
- if (pthread_create(&pt, NULL,
- wrk, (void *)(uintptr_t)p1[0]) != 0)
- errx(1, "pthread_create 1 %d", i);
+ SAY("making threads...\n");
+
+ for (i = 0; i < NTHR; i++) {
+ errno = pthread_create(&pt, NULL,
+ wrk, (void *)(uintptr_t)p1[0]);
+ if (errno != 0)
+ err(1, "pthread_create 1 %d", i);
+ }
+
+ for (i = 0; i < NTHR; i++) {
+ errno = pthread_create(&pt, NULL,
+ wrk, (void *)(uintptr_t)p2[0]);
+ if (errno != 0)
+ err(1, "pthread_create 2 %d", i);
+ }
- for (i = 0; i < NTHR; i++)
- if (pthread_create(&pt, NULL,
- wrk, (void *)(uintptr_t)p2[0]) != 0)
- errx(1, "pthread_create 2 %d", i);
+ SAY("waiting for threads to start...\n");
/* wait for all the threads to be enjoying themselves */
for (;;) {
getproc(mypid, &p);
+ SAY("getproc finished.\n");
if (p.p_nlwps == 2*NTHR + 2)
break;
usleep(10000);
}
+ SAY("making some more threads start...\n");
+
/*
* load up one more (big) set. these won't start executing, though,
* but we're interested in if they create blockage
*/
- for (i = 0; i < 3*NTHR; i++)
- if (pthread_create(&pt, NULL,
- wrk, (void *)(uintptr_t)p1[0]) != 0)
- errx(1, "pthread_create 1 %d", i);
+ for (i = 0; i < 3*NTHR; i++) {
+ errno = pthread_create(&pt, NULL,
+ wrk, (void *)(uintptr_t)p1[0]);
+ if (errno != 0)
+ err(1, "pthread_create 3 %d", i);
+ }
+
+ SAY("calling exec...\n");
/* then, we exec! */
execarg[0] = argv[0];
diff --git a/contrib/netbsd-tests/lib/librumpclient/t_exec.sh b/contrib/netbsd-tests/lib/librumpclient/t_exec.sh
index 661a3b9..a07af0c 100755
--- a/contrib/netbsd-tests/lib/librumpclient/t_exec.sh
+++ b/contrib/netbsd-tests/lib/librumpclient/t_exec.sh
@@ -1,4 +1,4 @@
-# $NetBSD: t_exec.sh,v 1.8 2011/03/08 12:40:25 pooka Exp $
+# $NetBSD: t_exec.sh,v 1.9 2016/08/10 21:10:18 kre Exp $
#
# Copyright (c) 2011 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -25,7 +25,7 @@
# POSSIBILITY OF SUCH DAMAGE.
#
-rumpsrv='rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet'
+rumpsrv='rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpdev -lrumpvfs'
export RUMP_SERVER=unix://csock
export RUMPHIJACK_RETRYCONNECT='die'
diff --git a/contrib/netbsd-tests/lib/librumpclient/t_fd.c b/contrib/netbsd-tests/lib/librumpclient/t_fd.c
index aa0d1cc..6e6d947 100644
--- a/contrib/netbsd-tests/lib/librumpclient/t_fd.c
+++ b/contrib/netbsd-tests/lib/librumpclient/t_fd.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_fd.c,v 1.4 2011/08/25 18:46:01 hannken Exp $ */
+/* $NetBSD: t_fd.c,v 1.5 2016/08/10 21:10:18 kre Exp $ */
/*
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -110,7 +110,7 @@ ATF_TC_BODY(sigio, tc)
signal(SIGIO, gotsig);
RZ(system("rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet "
- RUMPSERV));
+ "-lrumpdev -lrumpvfs " RUMPSERV));
RL(setenv("RUMP_SERVER", RUMPSERV, 1));
RL(rumpclient_init());
diff --git a/contrib/netbsd-tests/lib/librumphijack/t_tcpip.sh b/contrib/netbsd-tests/lib/librumphijack/t_tcpip.sh
index d6a16fa..411be33 100755
--- a/contrib/netbsd-tests/lib/librumphijack/t_tcpip.sh
+++ b/contrib/netbsd-tests/lib/librumphijack/t_tcpip.sh
@@ -1,4 +1,4 @@
-# $NetBSD: t_tcpip.sh,v 1.13 2014/01/03 13:18:00 pooka Exp $
+# $NetBSD: t_tcpip.sh,v 1.18 2016/08/13 11:22:11 christos Exp $
#
# Copyright (c) 2011 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -25,7 +25,8 @@
# POSSIBILITY OF SUCH DAMAGE.
#
-rumpnetsrv='rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet'
+rumpnetlibs="-lrumpnet -lrumpnet_net -lrumpnet_netinet6 -lrumpnet_netinet"
+rumpnetsrv="rump_server $rumpnetlibs -lrumpdev"
export RUMP_SERVER=unix://csock
atf_test_case http cleanup
@@ -37,7 +38,7 @@ http_head()
http_body()
{
- atf_check -s exit:0 ${rumpnetsrv} -lrumpnet_netinet6 ${RUMP_SERVER}
+ atf_check -s exit:0 ${rumpnetsrv} ${RUMP_SERVER}
# start bozo in daemon mode
atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
@@ -53,8 +54,9 @@ http_body()
# check that we got what we wanted
atf_check -o match:'HTTP/1.0 200 OK' cat webfile
atf_check -o match:'Content-Length: 95' cat webfile
+ blank_line_re="$(printf '^\r$')" # matches a line with only <CR><LF>
atf_check -o file:"$(atf_get_srcdir)/index.html" \
- sed -n '1,/^$/!p' webfile
+ sed -n "1,/${blank_line_re}/!p" webfile
}
http_cleanup()
@@ -121,6 +123,7 @@ ssh_head()
ssh_body()
{
+ atf_expect_fail "PR lib/50174"
atf_check -s exit:0 ${rumpnetsrv} ${RUMP_SERVER}
# make sure clients die after we nuke the server
@@ -177,6 +180,8 @@ test_nfs()
'echo "/export -noresvport -noresvmnt 10.1.1.100" | \
dd of=/rump/etc/exports 2> /dev/null'
+ atf_check -s exit:0 rump.sysctl -q -w kern.module.autoload=1
+
atf_check -s exit:0 -e ignore mount_ffs /dk /rump/export
atf_check -s exit:0 -x "echo ${magicstr} > /rump/export/im_alive"
@@ -201,7 +206,7 @@ test_nfs()
unset LD_PRELOAD
# at least the kernel server is easier
- atf_check -s exit:0 rump_server -lrumpvfs -lrumpnet \
+ atf_check -s exit:0 rump_server -lrumpvfs -lrumpnet -lrumpdev \
-lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif -lrumpfs_nfs\
${RUMP_SERVER}
@@ -228,7 +233,7 @@ nfs_head()
nfs_body()
{
test_nfs -lrumpvfs -lrumpdev -lrumpnet -lrumpnet_net \
- -lrumpnet_netinet -lrumpnet_local -lrumpnet_shmif \
+ -lrumpnet_netinet -lrumpnet_local -lrumpnet_shmif -lrumpdev \
-lrumpdev_disk -lrumpfs_ffs -lrumpfs_nfs -lrumpfs_nfsserver \
-d key=/dk,hostpath=ffs.img,size=host
}
@@ -250,7 +255,7 @@ nfs_autoload_body()
{
[ `uname -m` = "i386" ] || atf_skip "test currently valid only on i386"
test_nfs -lrumpvfs -lrumpdev -lrumpnet -lrumpnet_net \
- -lrumpnet_netinet -lrumpnet_local -lrumpnet_shmif \
+ -lrumpnet_netinet -lrumpnet_local -lrumpnet_shmif -lrumpdev \
-lrumpdev_disk -d key=/dk,hostpath=ffs.img,size=host
}
diff --git a/contrib/netbsd-tests/lib/libusbhid/hid_test_data.c b/contrib/netbsd-tests/lib/libusbhid/hid_test_data.c
new file mode 100644
index 0000000..dedcb11
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libusbhid/hid_test_data.c
@@ -0,0 +1,137 @@
+/* $NetBSD: hid_test_data.c,v 1.2 2016/01/07 15:58:23 jakllsch Exp $ */
+
+/*
+ * Copyright (c) 2016 Jonathan A. Kollasch
+ * 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 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.
+ */
+
+static const uint8_t range_test_report_descriptor[] = {
+ 0x0b, 0x03, 0x00, 0x00, 0xff, // Usage
+ 0x75, 0x20, // Report Size
+ 0x95, 0x01, // Report Count
+ 0x17, 0x00, 0x00, 0x00, 0x80, // Logical Minimum
+ 0x27, 0xff, 0xff, 0xff, 0x7f, // Logical Maximum
+ 0x37, 0x00, 0x00, 0x00, 0x80, // Physical Minimum
+ 0x47, 0xff, 0xff, 0xff, 0x7f, // Physical Maximum
+ 0x81, 0x00, // Input
+
+ 0x0b, 0x02, 0x00, 0x00, 0xff, // Usage
+ 0x75, 0x10, // Report Size
+ 0x95, 0x01, // Report Count
+ 0x16, 0x00, 0x80, // Logical Minimum
+ 0x26, 0xff, 0x7f, // Logical Maximum
+ 0x36, 0x00, 0x80, // Physical Minimum
+ 0x46, 0xff, 0x7f, // Physical Maximum
+ 0x81, 0x00, // Input
+
+ 0x0b, 0x01, 0x00, 0x00, 0xff, // Usage
+ 0x75, 0x08, // Report Size
+ 0x95, 0x01, // Report Count
+ 0x15, 0x80, // Logical Minimum
+ 0x25, 0x7f, // Logical Maximum
+ 0x35, 0x80, // Physical Minimum
+ 0x45, 0x7f, // Physical Maximum
+ 0x81, 0x00, // Input
+};
+
+static const uint8_t range_test_minimum_report[7] = {
+ 0x00, 0x00, 0x00, 0x80,
+ 0x00, 0x80,
+ 0x80,
+};
+
+static const uint8_t range_test_negative_one_report[7] = {
+ 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff,
+ 0xff,
+};
+
+static const uint8_t range_test_positive_one_report[7] = {
+ 0x01, 0x00, 0x00, 0x00,
+ 0x01, 0x00,
+ 0x01,
+};
+
+static const uint8_t range_test_maximum_report[7] = {
+ 0xff, 0xff, 0xff, 0x7f,
+ 0xff, 0x7f,
+ 0x7f,
+};
+
+static const uint8_t unsigned_range_test_report_descriptor[] = {
+ 0x0b, 0x13, 0x00, 0x00, 0xff, // Usage
+ 0x75, 0x20, // Report Size
+ 0x95, 0x01, // Report Count
+ 0x17, 0x00, 0x00, 0x00, 0x00, // Logical Minimum
+ 0x27, 0xff, 0xff, 0xff, 0xff, // Logical Maximum
+ 0x37, 0x00, 0x00, 0x00, 0x00, // Physical Minimum
+ 0x47, 0xff, 0xff, 0xff, 0xff, // Physical Maximum
+ 0x81, 0x00, // Input
+
+ 0x0b, 0x12, 0x00, 0x00, 0xff, // Usage
+ 0x75, 0x10, // Report Size
+ 0x95, 0x01, // Report Count
+ 0x16, 0x00, 0x00, // Logical Minimum
+ 0x26, 0xff, 0xff, // Logical Maximum
+ 0x36, 0x00, 0x00, // Physical Minimum
+ 0x46, 0xff, 0xff, // Physical Maximum
+ 0x81, 0x00, // Input
+
+ 0x0b, 0x11, 0x00, 0x00, 0xff, // Usage
+ 0x75, 0x08, // Report Size
+ 0x95, 0x01, // Report Count
+ 0x15, 0x00, // Logical Minimum
+ 0x25, 0xff, // Logical Maximum
+ 0x35, 0x00, // Physical Minimum
+ 0x45, 0xff, // Physical Maximum
+ 0x81, 0x00, // Input
+};
+
+static const uint8_t unsigned_range_test_minimum_report[7] = {
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00,
+ 0x00,
+};
+
+static const uint8_t unsigned_range_test_positive_one_report[7] = {
+ 0x01, 0x00, 0x00, 0x00,
+ 0x01, 0x00,
+ 0x01,
+};
+
+static const uint8_t unsigned_range_test_negative_one_report[7] = {
+ 0xfe, 0xff, 0xff, 0xff,
+ 0xfe, 0xff,
+ 0xfe,
+};
+
+static const uint8_t unsigned_range_test_maximum_report[7] = {
+ 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff,
+ 0xff,
+};
+
+static const uint8_t just_pop_report_descriptor[] = {
+ 0xb4,
+};
diff --git a/contrib/netbsd-tests/lib/libusbhid/t_usbhid.c b/contrib/netbsd-tests/lib/libusbhid/t_usbhid.c
new file mode 100644
index 0000000..2766da2
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libusbhid/t_usbhid.c
@@ -0,0 +1,452 @@
+/* $NetBSD: t_usbhid.c,v 1.12 2016/08/17 12:10:42 jakllsch Exp $ */
+
+/*
+ * Copyright (c) 2016 Jonathan A. Kollasch
+ * 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 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_usbhid.c,v 1.12 2016/08/17 12:10:42 jakllsch Exp $");
+
+#include <atf-c.h>
+
+#include <inttypes.h>
+#include <usbhid.h>
+#include <string.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <limits.h>
+
+ATF_TC(check_hid_logical_range);
+ATF_TC(check_hid_physical_range);
+ATF_TC(check_hid_usage);
+ATF_TC(check_hid_get_data);
+ATF_TC(check_hid_set_data);
+ATF_TC(check_parse_just_pop);
+
+#define MYd_ATF_CHECK_EQ(d, v) \
+ ATF_CHECK_EQ_MSG(d, v, "== %d", (d))
+
+#define MYu_ATF_CHECK_EQ(d, v) \
+ ATF_CHECK_EQ_MSG(d, v, "== %u", (d))
+
+#define MYx_ATF_CHECK_EQ(d, v) \
+ ATF_CHECK_EQ_MSG(d, v, "== 0x%x", (d))
+
+#include "hid_test_data.c"
+
+ATF_TC_HEAD(check_hid_usage, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Test libusbhid usage.c");
+}
+
+ATF_TC_BODY(check_hid_usage, tc)
+{
+ char usages_path[PATH_MAX];
+
+ (void)strlcpy(usages_path, atf_tc_get_config_var(tc, "srcdir"),
+ sizeof(usages_path));
+ (void)strlcat(usages_path, "/test_usb_hid_usages",
+ sizeof(usages_path));
+
+ hid_init(usages_path);
+
+ ATF_CHECK_STREQ("t_usbhid_page", hid_usage_page(0xff1b));
+ ATF_CHECK_EQ((uint32_t)hid_parse_usage_page("t_usbhid_page"), 0xff1b);
+
+ ATF_CHECK_STREQ("t_usbhid_usage", hid_usage_in_page(0xff1bff2a));
+ ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
+ "t_usbhid_page:t_usbhid_usage"), 0xff1bff2a);
+
+ ATF_CHECK_STREQ("Quick_zephyrs_blow_vexing_daft_Jim_",
+ hid_usage_page(0xff2a));
+ ATF_CHECK_EQ((uint32_t)hid_parse_usage_page(
+ "Quick_zephyrs_blow_vexing_daft_Jim_"), 0xff2a);
+
+ ATF_CHECK_STREQ("Usage_ID_Zero_%", hid_usage_in_page(0xff2a0000));
+ ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
+ "Quick_zephyrs_blow_vexing_daft_Jim_:Usage_ID_Zero_%"),
+ 0xff2a0000);
+
+ //ATF_CHECK_STREQ("Usage_ID_0_%", hid_usage_in_page(0xff2a0000));
+ ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
+ "Quick_zephyrs_blow_vexing_daft_Jim_:Usage_ID_0_%"), 0xff2a0000);
+
+ ATF_CHECK_STREQ("Usage_ID_65535_%", hid_usage_in_page(0xff2affff));
+ ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
+ "Quick_zephyrs_blow_vexing_daft_Jim_:Usage_ID_65535_%"),
+ 0xff2affff);
+
+ MYx_ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page("0xff2a:0xff1b"),
+ 0xff2aff1b);
+}
+
+ATF_TC_HEAD(check_hid_logical_range, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Test hid_get_item "
+ "Logical Minimum/Maximum results");
+}
+
+ATF_TC_BODY(check_hid_logical_range, tc)
+{
+ report_desc_t hrd;
+ hid_item_t hi;
+ uint32_t minimum, maximum;
+
+ atf_tc_expect_fail("only the 32-bit opcode works, "
+ "8 and 16-bit is broken");
+
+ ATF_REQUIRE((hrd = hid_use_report_desc(range_test_report_descriptor,
+ __arraycount(range_test_report_descriptor))) != NULL);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ MYd_ATF_CHECK_EQ(hi.logical_minimum, -128);
+ MYd_ATF_CHECK_EQ(hi.logical_maximum, 127);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ MYd_ATF_CHECK_EQ(hi.logical_minimum, -32768);
+ MYd_ATF_CHECK_EQ(hi.logical_maximum, 32767);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ MYd_ATF_CHECK_EQ(hi.logical_minimum, -2147483648);
+ MYd_ATF_CHECK_EQ(hi.logical_maximum, 2147483647);
+
+ hid_dispose_report_desc(hrd);
+ hrd = NULL;
+
+ ATF_REQUIRE((hrd = hid_use_report_desc(
+ unsigned_range_test_report_descriptor,
+ __arraycount(unsigned_range_test_report_descriptor))) != NULL);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ ATF_CHECK(hi.logical_minimum > hi.logical_maximum);
+ minimum = (uint32_t)hi.logical_minimum & ((1ULL<<hi.report_size)-1);
+ MYu_ATF_CHECK_EQ(minimum, 0);
+ maximum = (uint32_t)hi.logical_maximum & ((1ULL<<hi.report_size)-1);
+ MYu_ATF_CHECK_EQ(maximum, 255);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ ATF_CHECK(hi.logical_minimum > hi.logical_maximum);
+ minimum = hi.logical_minimum & ((1ULL<<hi.report_size)-1);
+ MYu_ATF_CHECK_EQ(minimum, 0);
+ maximum = hi.logical_maximum & ((1ULL<<hi.report_size)-1);
+ MYu_ATF_CHECK_EQ(maximum, 65535);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ ATF_CHECK(hi.logical_minimum > hi.logical_maximum);
+ minimum = hi.logical_minimum & ((1ULL<<hi.report_size)-1);
+ MYu_ATF_CHECK_EQ(minimum, 0);
+ maximum = hi.logical_maximum & ((1ULL<<hi.report_size)-1);
+ MYu_ATF_CHECK_EQ(maximum, 4294967295);
+
+ hid_dispose_report_desc(hrd);
+ hrd = NULL;
+}
+
+ATF_TC_HEAD(check_hid_physical_range, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Test hid_get_item "
+ "Physical Minimum/Maximum results");
+}
+
+ATF_TC_BODY(check_hid_physical_range, tc)
+{
+ report_desc_t hrd;
+ hid_item_t hi;
+ uint32_t minimum, maximum;
+
+ atf_tc_expect_fail("only the 32-bit opcode works, "
+ "8 and 16-bit is broken");
+
+ ATF_REQUIRE((hrd = hid_use_report_desc(range_test_report_descriptor,
+ __arraycount(range_test_report_descriptor))) != NULL);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ MYd_ATF_CHECK_EQ(hi.physical_minimum, -128);
+ MYd_ATF_CHECK_EQ(hi.physical_maximum, 127);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ MYd_ATF_CHECK_EQ(hi.physical_minimum, -32768);
+ MYd_ATF_CHECK_EQ(hi.physical_maximum, 32767);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ MYd_ATF_CHECK_EQ(hi.physical_minimum, -2147483648);
+ MYd_ATF_CHECK_EQ(hi.physical_maximum, 2147483647);
+
+ hid_dispose_report_desc(hrd);
+ hrd = NULL;
+
+ ATF_REQUIRE((hrd = hid_use_report_desc(
+ unsigned_range_test_report_descriptor,
+ __arraycount(unsigned_range_test_report_descriptor))) != NULL);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ ATF_CHECK(hi.physical_minimum > hi.physical_maximum);
+ minimum = (uint32_t)hi.physical_minimum & ((1ULL<<hi.report_size)-1);
+ MYu_ATF_CHECK_EQ(minimum, 0);
+ maximum = (uint32_t)hi.physical_maximum & ((1ULL<<hi.report_size)-1);
+ MYu_ATF_CHECK_EQ(maximum, 255);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ ATF_CHECK(hi.physical_minimum > hi.physical_maximum);
+ minimum = hi.physical_minimum & ((1ULL<<hi.report_size)-1);
+ MYu_ATF_CHECK_EQ(minimum, 0);
+ maximum = hi.physical_maximum & ((1ULL<<hi.report_size)-1);
+ MYu_ATF_CHECK_EQ(maximum, 65535);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ ATF_CHECK(hi.physical_minimum > hi.physical_maximum);
+ minimum = hi.physical_minimum & ((1ULL<<hi.report_size)-1);
+ MYu_ATF_CHECK_EQ(minimum, 0);
+ maximum = hi.physical_maximum & ((1ULL<<hi.report_size)-1);
+ MYu_ATF_CHECK_EQ(maximum, 4294967295);
+
+ hid_dispose_report_desc(hrd);
+ hrd = NULL;
+}
+
+ATF_TC_HEAD(check_hid_get_data, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Test hid_get_data results");
+}
+
+ATF_TC_BODY(check_hid_get_data, tc)
+{
+ report_desc_t hrd;
+ hid_item_t hi;
+ int32_t data;
+ uint32_t udat;
+
+ atf_tc_expect_fail("only the 32-bit opcode works, "
+ "8 and 16-bit is broken");
+
+ ATF_REQUIRE((hrd = hid_use_report_desc(
+ range_test_report_descriptor,
+ __arraycount(range_test_report_descriptor))) != NULL);
+
+ ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ data = hid_get_data(range_test_minimum_report, &hi);
+ MYd_ATF_CHECK_EQ(data, -128);
+ data = hid_get_data(range_test_negative_one_report, &hi);
+ MYd_ATF_CHECK_EQ(data, -1);
+ data = hid_get_data(range_test_positive_one_report, &hi);
+ MYd_ATF_CHECK_EQ(data, 1);
+ data = hid_get_data(range_test_maximum_report, &hi);
+ MYd_ATF_CHECK_EQ(data, 127);
+
+ ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ data = hid_get_data(range_test_minimum_report, &hi);
+ MYd_ATF_CHECK_EQ(data, -32768);
+ data = hid_get_data(range_test_negative_one_report, &hi);
+ MYd_ATF_CHECK_EQ(data, -1);
+ data = hid_get_data(range_test_positive_one_report, &hi);
+ MYd_ATF_CHECK_EQ(data, 1);
+ data = hid_get_data(range_test_maximum_report, &hi);
+ MYd_ATF_CHECK_EQ(data, 32767);
+
+ ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ data = hid_get_data(range_test_minimum_report, &hi);
+ MYd_ATF_CHECK_EQ(data, -2147483648);
+ data = hid_get_data(range_test_negative_one_report, &hi);
+ MYd_ATF_CHECK_EQ(data, -1);
+ data = hid_get_data(range_test_positive_one_report, &hi);
+ MYd_ATF_CHECK_EQ(data, 1);
+ data = hid_get_data(range_test_maximum_report, &hi);
+ MYd_ATF_CHECK_EQ(data, 2147483647);
+
+ hid_dispose_report_desc(hrd);
+ hrd = NULL;
+
+ ATF_REQUIRE((hrd = hid_use_report_desc(
+ unsigned_range_test_report_descriptor,
+ __arraycount(unsigned_range_test_report_descriptor))) != NULL);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ udat = hid_get_data(unsigned_range_test_minimum_report, &hi);
+ MYu_ATF_CHECK_EQ(udat, 0);
+ udat = hid_get_data(unsigned_range_test_positive_one_report, &hi);
+ MYu_ATF_CHECK_EQ(udat, 1);
+ udat = hid_get_data(unsigned_range_test_negative_one_report, &hi);
+ MYu_ATF_CHECK_EQ(udat, 254);
+ udat = hid_get_data(unsigned_range_test_maximum_report, &hi);
+ MYu_ATF_CHECK_EQ(udat, 255);
+
+ ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ udat = hid_get_data(unsigned_range_test_minimum_report, &hi);
+ MYu_ATF_CHECK_EQ(udat, 0);
+ udat = hid_get_data(unsigned_range_test_positive_one_report, &hi);
+ MYu_ATF_CHECK_EQ(udat, 1);
+ udat = hid_get_data(unsigned_range_test_negative_one_report, &hi);
+ MYu_ATF_CHECK_EQ(udat, 65534);
+ udat = hid_get_data(unsigned_range_test_maximum_report, &hi);
+ MYu_ATF_CHECK_EQ(udat, 65535);
+
+ ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ udat = hid_get_data(unsigned_range_test_minimum_report, &hi);
+ MYu_ATF_CHECK_EQ(udat, 0);
+ udat = hid_get_data(unsigned_range_test_positive_one_report, &hi);
+ MYu_ATF_CHECK_EQ(udat, 1);
+ udat = hid_get_data(unsigned_range_test_negative_one_report, &hi);
+ MYu_ATF_CHECK_EQ(udat, 4294967294);
+ udat = hid_get_data(unsigned_range_test_maximum_report, &hi);
+ MYu_ATF_CHECK_EQ(udat, 4294967295);
+
+ hid_dispose_report_desc(hrd);
+ hrd = NULL;
+}
+
+ATF_TC_HEAD(check_hid_set_data, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Test hid_set_data results");
+}
+
+ATF_TC_BODY(check_hid_set_data, tc)
+{
+ report_desc_t hrd;
+ hid_item_t hi;
+ uint8_t test_data_minimum[7];
+ uint8_t test_data_negative_one[7];
+ uint8_t test_data_positive_one[7];
+ uint8_t test_data_maximum[7];
+
+ ATF_REQUIRE((hrd = hid_use_report_desc(
+ range_test_report_descriptor,
+ __arraycount(range_test_report_descriptor))) != NULL);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ hid_set_data(test_data_minimum, &hi, -128);
+ hid_set_data(test_data_negative_one, &hi, -1);
+ hid_set_data(test_data_positive_one, &hi, 1);
+ hid_set_data(test_data_maximum, &hi, 127);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ hid_set_data(test_data_minimum, &hi, -32768);
+ hid_set_data(test_data_negative_one, &hi, -1);
+ hid_set_data(test_data_positive_one, &hi, 1);
+ hid_set_data(test_data_maximum, &hi, 32767);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ hid_set_data(test_data_minimum, &hi, -2147483648);
+ hid_set_data(test_data_negative_one, &hi, -1);
+ hid_set_data(test_data_positive_one, &hi, 1);
+ hid_set_data(test_data_maximum, &hi, 2147483647);
+ ATF_CHECK(memcmp(test_data_minimum, range_test_minimum_report,
+ sizeof test_data_minimum) == 0);
+ ATF_CHECK(memcmp(test_data_negative_one,
+ range_test_negative_one_report,
+ sizeof test_data_negative_one) == 0);
+ ATF_CHECK(memcmp(test_data_positive_one,
+ range_test_positive_one_report,
+ sizeof test_data_positive_one) == 0);
+ ATF_CHECK(memcmp(test_data_maximum, range_test_maximum_report,
+ sizeof test_data_maximum) == 0);
+
+ hid_dispose_report_desc(hrd);
+ hrd = NULL;
+
+ ATF_REQUIRE((hrd = hid_use_report_desc(
+ unsigned_range_test_report_descriptor,
+ __arraycount(range_test_report_descriptor))) != NULL);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ hid_set_data(test_data_minimum, &hi, 0);
+ hid_set_data(test_data_positive_one, &hi, 1);
+ hid_set_data(test_data_negative_one, &hi, 0xfffffffe);
+ hid_set_data(test_data_maximum, &hi, 0xffffffff);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ hid_set_data(test_data_minimum, &hi, 0);
+ hid_set_data(test_data_positive_one, &hi, 1);
+ hid_set_data(test_data_negative_one, &hi, 0xfffe);
+ hid_set_data(test_data_maximum, &hi, 0xffff);
+ ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
+ NO_REPORT_ID) > 0);
+ hid_set_data(test_data_minimum, &hi, 0);
+ hid_set_data(test_data_positive_one, &hi, 1);
+ hid_set_data(test_data_negative_one, &hi, 0xfffffffe);
+ hid_set_data(test_data_maximum, &hi, 0xffffffff);
+ ATF_CHECK(memcmp(test_data_minimum,
+ unsigned_range_test_minimum_report,
+ sizeof test_data_minimum) == 0);
+ ATF_CHECK(memcmp(test_data_negative_one,
+ unsigned_range_test_negative_one_report,
+ sizeof test_data_negative_one) == 0);
+ ATF_CHECK(memcmp(test_data_positive_one,
+ unsigned_range_test_positive_one_report,
+ sizeof test_data_positive_one) == 0);
+ ATF_CHECK(memcmp(test_data_maximum,
+ unsigned_range_test_maximum_report,
+ sizeof test_data_maximum) == 0);
+
+ hid_dispose_report_desc(hrd);
+ hrd = NULL;
+}
+
+ATF_TC_HEAD(check_parse_just_pop, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "check Pop on empty stack bug");
+}
+
+ATF_TC_BODY(check_parse_just_pop, tc)
+{
+ report_desc_t hrd;
+ hid_data_t hd;
+ hid_item_t hi;
+
+ ATF_REQUIRE((hrd = hid_use_report_desc(
+ just_pop_report_descriptor,
+ sizeof just_pop_report_descriptor)) != NULL);
+ hd = hid_start_parse(hrd, 0, NO_REPORT_ID);
+ while (hid_get_item(hd, &hi) > 0) {
+ }
+ hid_end_parse(hd);
+ hid_dispose_report_desc(hrd);
+ hrd = NULL;
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, check_hid_logical_range);
+ ATF_TP_ADD_TC(tp, check_hid_physical_range);
+ ATF_TP_ADD_TC(tp, check_hid_usage);
+ ATF_TP_ADD_TC(tp, check_hid_get_data);
+ ATF_TP_ADD_TC(tp, check_hid_set_data);
+ ATF_TP_ADD_TC(tp, check_parse_just_pop);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libusbhid/test_usb_hid_usages b/contrib/netbsd-tests/lib/libusbhid/test_usb_hid_usages
new file mode 100644
index 0000000..2444ef2
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libusbhid/test_usb_hid_usages
@@ -0,0 +1,17 @@
+# $NetBSD: test_usb_hid_usages,v 1.1 2016/01/01 21:38:54 jakllsch Exp $
+#
+# USB HID usage table (for t_usbhid)
+# Syntax:
+# - lines that do not start with a white space give the number and name of
+# a usage page.
+# - lines that start with a white space give the number and name of
+# a usage with the last given page.
+# If the number is * then the line matches all usages and the name
+# is a printf formatting string that will be given the usage number.
+#
+0xff1b t_usbhid page
+ 0xff2a t_usbhid usage
+
+0xff2a Quick zephyrs blow vexing daft Jim.
+ 0 Usage ID Zero %
+ * Usage ID %u %%
diff --git a/contrib/netbsd-tests/lib/libutil/t_parsedate.c b/contrib/netbsd-tests/lib/libutil/t_parsedate.c
index ec035a6..c78df58 100644
--- a/contrib/netbsd-tests/lib/libutil/t_parsedate.c
+++ b/contrib/netbsd-tests/lib/libutil/t_parsedate.c
@@ -1,6 +1,6 @@
-/* $NetBSD: t_parsedate.c,v 1.7 2013/01/19 15:21:43 apb Exp $ */
+/* $NetBSD: t_parsedate.c,v 1.25 2016/06/22 15:01:38 kre Exp $ */
/*-
- * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * Copyright (c) 2010, 2015 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -29,14 +29,88 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_parsedate.c,v 1.7 2013/01/19 15:21:43 apb Exp $");
+__RCSID("$NetBSD: t_parsedate.c,v 1.25 2016/06/22 15:01:38 kre Exp $");
#include <atf-c.h>
#include <errno.h>
+#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <util.h>
+/*
+ * ANY is used as a placeholder for values that do not need to be
+ * checked. The actual value is arbitrary. We don't use -1
+ * because some tests might want to use -1 as a literal value.
+ */
+#define ANY -30215
+
+/* parsecheck --
+ * call parsedate(), then call time_to_tm() on the result,
+ * and check that year/month/day/hour/minute/second are as expected.
+ *
+ * time_to_tm should usually be localtime_r or gmtime_r.
+ *
+ * Don't check values specified as ANY.
+ */
+static void
+parsecheck(const char *datestr, const time_t *reftime, const int *zoff,
+ struct tm * time_to_tm(const time_t *, struct tm *),
+ int year, int month, int day, int hour, int minute, int second)
+{
+ time_t t;
+ struct tm tm;
+ char argstr[128];
+
+ /*
+ * printable version of the args.
+ *
+ * Note that printf("%.*d", 0, 0)) prints nothing at all,
+ * while printf("%.*d", 1, val) prints the value as usual.
+ */
+ snprintf(argstr, sizeof(argstr), "%s%s%s, %s%.*jd, %s%.*d",
+ /* NULL or \"<datestr>\" */
+ (datestr ? "\"" : ""),
+ (datestr ? datestr : "NULL"),
+ (datestr ? "\"" : ""),
+ /* NULL or *reftime */
+ (reftime ? "" : "NULL"),
+ (reftime ? 1 : 0),
+ (reftime ? (intmax_t)*reftime : (intmax_t)0),
+ /* NULL or *zoff */
+ (zoff ? "" : "NULL"),
+ (zoff ? 1 : 0),
+ (zoff ? *zoff : 0));
+
+ ATF_CHECK_MSG((t = parsedate(datestr, reftime, zoff)) != -1,
+ "parsedate(%s) returned -1\n", argstr);
+ ATF_CHECK(time_to_tm(&t, &tm) != NULL);
+ if (year != ANY)
+ ATF_CHECK_MSG(tm.tm_year + 1900 == year,
+ "parsedate(%s) expected year %d got %d (+1900)\n",
+ argstr, year, (int)tm.tm_year);
+ if (month != ANY)
+ ATF_CHECK_MSG(tm.tm_mon + 1 == month,
+ "parsedate(%s) expected month %d got %d (+1)\n",
+ argstr, month, (int)tm.tm_mon);
+ if (day != ANY)
+ ATF_CHECK_MSG(tm.tm_mday == day,
+ "parsedate(%s) expected day %d got %d\n",
+ argstr, day, (int)tm.tm_mday);
+ if (hour != ANY)
+ ATF_CHECK_MSG(tm.tm_hour == hour,
+ "parsedate(%s) expected hour %d got %d\n",
+ argstr, hour, (int)tm.tm_hour);
+ if (minute != ANY)
+ ATF_CHECK_MSG(tm.tm_min == minute,
+ "parsedate(%s) expected minute %d got %d\n",
+ argstr, minute, (int)tm.tm_min);
+ if (second != ANY)
+ ATF_CHECK_MSG(tm.tm_sec == second,
+ "parsedate(%s) expected second %d got %d\n",
+ argstr, second, (int)tm.tm_sec);
+}
+
ATF_TC(dates);
ATF_TC_HEAD(dates, tc)
@@ -48,15 +122,34 @@ ATF_TC_HEAD(dates, tc)
ATF_TC_BODY(dates, tc)
{
- ATF_CHECK(parsedate("69-09-10", NULL, NULL) != -1);
- ATF_CHECK(parsedate("2006-11-17", NULL, NULL) != -1);
- ATF_CHECK(parsedate("10/1/2000", NULL, NULL) != -1);
- ATF_CHECK(parsedate("20 Jun 1994", NULL, NULL) != -1);
- ATF_CHECK(parsedate("23jun2001", NULL, NULL) != -1);
- ATF_CHECK(parsedate("1-sep-06", NULL, NULL) != -1);
- ATF_CHECK(parsedate("1/11", NULL, NULL) != -1);
- ATF_CHECK(parsedate("1500-01-02", NULL, NULL) != -1);
- ATF_CHECK(parsedate("9999-12-21", NULL, NULL) != -1);
+ parsecheck("9/10/69", NULL, NULL, localtime_r,
+ 2069, 9, 10, 0, 0, 0); /* year < 70: add 2000 */
+ parsecheck("9/10/70", NULL, NULL, localtime_r,
+ 1970, 9, 10, 0, 0, 0); /* 70 <= year < 100: add 1900 */
+ parsecheck("69-09-10", NULL, NULL, localtime_r,
+ 69, 9, 10, 0, 0, 0); /* ISO8601 year remains unchanged */
+ parsecheck("70-09-10", NULL, NULL, localtime_r,
+ 70, 9, 10, 0, 0, 0); /* ISO8601 year remains unchanged */
+ parsecheck("2006-11-17", NULL, NULL, localtime_r,
+ 2006, 11, 17, 0, 0, 0);
+ parsecheck("10/1/2000", NULL, NULL, localtime_r,
+ 2000, 10, 1, 0, 0, 0); /* month/day/year */
+ parsecheck("20 Jun 1994", NULL, NULL, localtime_r,
+ 1994, 6, 20, 0, 0, 0);
+ parsecheck("97 September 2", NULL, NULL, localtime_r,
+ 1997, 9, 2, 0, 0, 0);
+ parsecheck("23jun2001", NULL, NULL, localtime_r,
+ 2001, 6, 23, 0, 0, 0);
+ parsecheck("1-sep-06", NULL, NULL, localtime_r,
+ 2006, 9, 1, 0, 0, 0);
+ parsecheck("1/11", NULL, NULL, localtime_r,
+ ANY, 1, 11, 0, 0, 0); /* month/day */
+ parsecheck("1500-01-02", NULL, NULL, localtime_r,
+ 1500, 1, 2, 0, 0, 0);
+ parsecheck("9999-12-21", NULL, NULL, localtime_r,
+ 9999, 12, 21, 0, 0, 0);
+ parsecheck("2015.12.07.08.07.35", NULL, NULL, localtime_r,
+ 2015, 12, 7, 8, 7, 35);
}
ATF_TC(times);
@@ -70,10 +163,66 @@ ATF_TC_HEAD(times, tc)
ATF_TC_BODY(times, tc)
{
- ATF_CHECK(parsedate("10:01", NULL, NULL) != -1);
- ATF_CHECK(parsedate("10:12pm", NULL, NULL) != -1);
- ATF_CHECK(parsedate("12:11:01.000012", NULL, NULL) != -1);
- ATF_CHECK(parsedate("12:21-0500", NULL, NULL) != -1);
+ parsecheck("10:01", NULL, NULL, localtime_r,
+ ANY, ANY, ANY, 10, 1, 0);
+ parsecheck("10:12pm", NULL, NULL, localtime_r,
+ ANY, ANY, ANY, 22, 12, 0);
+ parsecheck("12:11:01.000012", NULL, NULL, localtime_r,
+ ANY, ANY, ANY, 12, 11, 1);
+ parsecheck("12:21-0500", NULL, NULL, gmtime_r,
+ ANY, ANY, ANY, 12+5, 21, 0);
+ /* numeric zones not permitted with am/pm ... */
+ parsecheck("7 a.m. ICT", NULL, NULL, gmtime_r,
+ ANY, ANY, ANY, 7-7, 0, 0);
+ parsecheck("midnight", NULL, NULL, localtime_r,
+ ANY, ANY, ANY, 0, 0, 0);
+ parsecheck("mn", NULL, NULL, localtime_r,
+ ANY, ANY, ANY, 0, 0, 0);
+ parsecheck("noon", NULL, NULL, localtime_r,
+ ANY, ANY, ANY, 12, 0, 0);
+}
+
+ATF_TC(dsttimes);
+
+ATF_TC_HEAD(dsttimes, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test DST transition times"
+ " (PR lib/47916)");
+}
+
+ATF_TC_BODY(dsttimes, tc)
+{
+ struct tm tm;
+ time_t t;
+ int tzoff;
+
+ putenv(__UNCONST("TZ=EST"));
+ tzset();
+ parsecheck("12:0", NULL, NULL, localtime_r,
+ ANY, ANY, ANY, 12, 0, 0);
+
+ putenv(__UNCONST("TZ=Asia/Tokyo"));
+ tzset();
+ parsecheck("12:0", NULL, NULL, localtime_r,
+ ANY, ANY, ANY, 12, 0, 0);
+
+ /*
+ * When the effective local time is Tue Jul 9 13:21:53 BST 2013,
+ * check mktime("14:00")
+ */
+ putenv(__UNCONST("TZ=Europe/London"));
+ tzset();
+ tm = (struct tm){
+ .tm_year = 2013-1900, .tm_mon = 7-1, .tm_mday = 9,
+ .tm_hour = 13, .tm_min = 21, .tm_sec = 53,
+ .tm_isdst = 0 };
+ t = mktime(&tm);
+ ATF_CHECK(t != (time_t)-1);
+ parsecheck("14:00", &t, NULL, localtime_r,
+ 2013, 7, 9, 14, 0, 0);
+ tzoff = -60; /* British Summer Time */
+ parsecheck("14:00", &t, &tzoff, localtime_r,
+ 2013, 7, 9, 14, 0, 0);
}
ATF_TC(relative);
@@ -86,6 +235,23 @@ ATF_TC_HEAD(relative, tc)
ATF_TC_BODY(relative, tc)
{
+ struct tm tm;
+ time_t now;
+
+#define REL_CHECK(s, now, tm) do { \
+ time_t p, q; \
+ char nb[30], pb[30], qb[30]; \
+ p = parsedate(s, &now, NULL); \
+ q = mktime(&tm); \
+ ATF_CHECK_EQ_MSG(p, q, \
+ "From %jd (%24.24s) using \"%s\", obtained %jd (%24.24s); expected %jd (%24.24s)", \
+ (uintmax_t)now, ctime_r(&now, nb), \
+ s, (uintmax_t)p, ctime_r(&p, pb), (uintmax_t)q, \
+ ctime_r(&q, qb)); \
+ } while (/*CONSTCOND*/0)
+
+#define isleap(yr) (((yr) & 3) == 0 && (((yr) % 100) != 0 || \
+ ((1900+(yr)) % 400) == 0))
ATF_CHECK(parsedate("-1 month", NULL, NULL) != -1);
ATF_CHECK(parsedate("last friday", NULL, NULL) != -1);
@@ -93,6 +259,169 @@ ATF_TC_BODY(relative, tc)
ATF_CHECK(parsedate("this thursday", NULL, NULL) != -1);
ATF_CHECK(parsedate("next sunday", NULL, NULL) != -1);
ATF_CHECK(parsedate("+2 years", NULL, NULL) != -1);
+
+ /*
+ * Test relative to a number of fixed dates. Avoid the
+ * edges of the time_t range to avert under- or overflow
+ * of the relative date, and use a prime step for maximum
+ * coverage of different times of day/week/month/year.
+ */
+ for (now = 0x00FFFFFF; now < 0xFF000000; now += 3777779) {
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ tm.tm_mday--;
+ /* "yesterday" leaves time untouched */
+ tm.tm_isdst = -1;
+ REL_CHECK("yesterday", now, tm);
+
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ tm.tm_mday++;
+ /* as does "tomorrow" */
+ tm.tm_isdst = -1;
+ REL_CHECK("tomorrow", now, tm);
+
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ if (tm.tm_wday > 4)
+ tm.tm_mday += 7;
+ tm.tm_mday += 4 - tm.tm_wday;
+ /* if a day name is mentioned, it means midnight (by default) */
+ tm.tm_sec = tm.tm_min = tm.tm_hour = 0;
+ tm.tm_isdst = -1;
+ REL_CHECK("this thursday", now, tm);
+
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ tm.tm_mday += 14 - (tm.tm_wday ? tm.tm_wday : 7);
+ tm.tm_sec = tm.tm_min = tm.tm_hour = 0;
+ tm.tm_isdst = -1;
+ REL_CHECK("next sunday", now, tm);
+
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ if (tm.tm_wday <= 5)
+ tm.tm_mday -= 7;
+ tm.tm_mday += 5 - tm.tm_wday;
+ tm.tm_sec = tm.tm_min = 0;
+ tm.tm_hour = 16;
+ tm.tm_isdst = -1;
+ REL_CHECK("last friday 4 p.m.", now, tm);
+
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ tm.tm_mday += 14;
+ if (tm.tm_wday > 3)
+ tm.tm_mday += 7;
+ tm.tm_mday += 3 - tm.tm_wday;
+ tm.tm_sec = tm.tm_min = 0;
+ tm.tm_hour = 3;
+ tm.tm_isdst = -1;
+ REL_CHECK("we fortnight 3 a.m.", now, tm);
+
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ tm.tm_min -= 5;
+ tm.tm_isdst = -1;
+ REL_CHECK("5 minutes ago", now, tm);
+
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ tm.tm_hour++;
+ tm.tm_min += 37;
+ tm.tm_isdst = -1;
+ REL_CHECK("97 minutes", now, tm);
+
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ tm.tm_mon++;
+ if (tm.tm_mon == 1 &&
+ tm.tm_mday > 28 + isleap(tm.tm_year))
+ tm.tm_mday = 28 + isleap(tm.tm_year);
+ else if ((tm.tm_mon == 3 || tm.tm_mon == 5 ||
+ tm.tm_mon == 8 || tm.tm_mon == 10) && tm.tm_mday == 31)
+ tm.tm_mday = 30;
+ tm.tm_isdst = -1;
+ REL_CHECK("month", now, tm);
+
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ tm.tm_mon += 2; /* "next" means add 2 ... */
+ if (tm.tm_mon == 13 &&
+ tm.tm_mday > 28 + isleap(tm.tm_year + 1))
+ tm.tm_mday = 28 + isleap(tm.tm_year + 1);
+ else if (tm.tm_mon == 8 && tm.tm_mday == 31)
+ tm.tm_mday = 30;
+ tm.tm_isdst = -1;
+ REL_CHECK("next month", now, tm);
+
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ tm.tm_mon--;
+ if (tm.tm_mon == 1 &&
+ tm.tm_mday > 28 + isleap(tm.tm_year))
+ tm.tm_mday = 28 + isleap(tm.tm_year);
+ else if ((tm.tm_mon == 3 || tm.tm_mon == 5 ||
+ tm.tm_mon == 8 || tm.tm_mon == 10) && tm.tm_mday == 31)
+ tm.tm_mday = 30;
+ tm.tm_isdst = -1;
+ REL_CHECK("last month", now, tm);
+
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ tm.tm_mon += 6;
+ if (tm.tm_mon == 13 &&
+ tm.tm_mday > 28 + isleap(tm.tm_year + 1))
+ tm.tm_mday = 28 + isleap(tm.tm_year + 1);
+ else if ((tm.tm_mon == 15 || tm.tm_mon == 17 ||
+ tm.tm_mon == 8 || tm.tm_mon == 10) && tm.tm_mday == 31)
+ tm.tm_mday = 30;
+ tm.tm_mday += 2;
+ tm.tm_isdst = -1;
+ REL_CHECK("+6 months 2 days", now, tm);
+
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ tm.tm_mon -= 9;
+ if (tm.tm_mon == 1 && tm.tm_mday > 28 + isleap(tm.tm_year))
+ tm.tm_mday = 28 + isleap(tm.tm_year);
+ else if ((tm.tm_mon == -9 || tm.tm_mon == -7 ||
+ tm.tm_mon == -2) && tm.tm_mday == 31)
+ tm.tm_mday = 30;
+ tm.tm_isdst = -1;
+ REL_CHECK("9 months ago", now, tm);
+
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ if (tm.tm_wday <= 2)
+ tm.tm_mday -= 7;
+ tm.tm_mday += 2 - tm.tm_wday;
+ tm.tm_isdst = -1;
+ tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
+ REL_CHECK("1 week ago Tu", now, tm);
+
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ tm.tm_isdst = -1;
+ tm.tm_mday++;
+ tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
+ REL_CHECK("midnight tomorrow", now, tm);
+
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ tm.tm_isdst = -1;
+ tm.tm_mday++;
+ tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
+ REL_CHECK("tomorrow midnight", now, tm);
+
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ tm.tm_isdst = -1;
+ tm.tm_mday++;
+ tm.tm_hour = 12;
+ tm.tm_min = tm.tm_sec = 0;
+ REL_CHECK("noon tomorrow", now, tm);
+
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ if (tm.tm_wday > 2)
+ tm.tm_mday += 7;
+ tm.tm_mday += 2 - tm.tm_wday;
+ tm.tm_sec = tm.tm_min = tm.tm_hour = 0;
+ tm.tm_isdst = -1;
+ REL_CHECK("midnight Tuesday", now, tm);
+
+ ATF_CHECK(localtime_r(&now, &tm) != NULL);
+ if (tm.tm_wday > 2 + 1)
+ tm.tm_mday += 7;
+ tm.tm_mday += 2 - tm.tm_wday;
+ tm.tm_mday++; /* xxx midnight --> the next day */
+ tm.tm_sec = tm.tm_min = tm.tm_hour = 0;
+ tm.tm_isdst = -1;
+ REL_CHECK("Tuesday midnight", now, tm);
+ }
}
ATF_TC(atsecs);
@@ -131,12 +460,124 @@ ATF_TC_BODY(atsecs, tc)
ATF_CHECK(parsedate("@junk", NULL, NULL) == (time_t)-1 && errno != 0);
}
+ATF_TC(zones);
+
+ATF_TC_HEAD(zones, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test parsing dates with zones");
+}
+
+ATF_TC_BODY(zones, tc)
+{
+ parsecheck("2015-12-06 16:11:48 UTC", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 16, 11, 48);
+ parsecheck("2015-12-06 16:11:48 UT", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 16, 11, 48);
+ parsecheck("2015-12-06 16:11:48 GMT", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 16, 11, 48);
+ parsecheck("2015-12-06 16:11:48 +0000", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 16, 11, 48);
+
+ parsecheck("2015-12-06 16:11:48 -0500", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 21, 11, 48);
+ parsecheck("2015-12-06 16:11:48 EST", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 21, 11, 48);
+ parsecheck("2015-12-06 16:11:48 EDT", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 20, 11, 48);
+ parsecheck("2015-12-06 16:11:48 +0500", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 11, 11, 48);
+
+ parsecheck("2015-12-06 16:11:48 +1000", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 6, 11, 48);
+ parsecheck("2015-12-06 16:11:48 AEST", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 6, 11, 48);
+ parsecheck("2015-12-06 16:11:48 -1000", NULL, NULL, gmtime_r,
+ 2015, 12, 7, 2, 11, 48);
+ parsecheck("2015-12-06 16:11:48 HST", NULL, NULL, gmtime_r,
+ 2015, 12, 7, 2, 11, 48);
+
+ parsecheck("2015-12-06 16:11:48 AWST", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 8, 11, 48);
+ parsecheck("2015-12-06 16:11:48 NZDT", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 3, 11, 48);
+
+ parsecheck("Sun, 6 Dec 2015 09:43:16 -0500", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 14, 43, 16);
+ parsecheck("Mon Dec 7 03:13:31 ICT 2015", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 20, 13, 31);
+ /* the day name is ignored when a day of month (etc) is given... */
+ parsecheck("Sat Dec 7 03:13:31 ICT 2015", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 20, 13, 31);
+
+
+ parsecheck("2015-12-06 12:00:00 IDLW", NULL, NULL, gmtime_r,
+ 2015, 12, 7, 0, 0, 0);
+ parsecheck("2015-12-06 12:00:00 IDLE", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 0, 0, 0);
+
+ parsecheck("2015-12-06 21:17:33 NFT", NULL, NULL, gmtime_r,
+ 2015, 12, 7, 0, 47, 33);
+ parsecheck("2015-12-06 21:17:33 ACST", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 11, 47, 33);
+ parsecheck("2015-12-06 21:17:33 +0717", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 14, 0, 33);
+
+ parsecheck("2015-12-06 21:21:21 Z", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 21, 21, 21);
+ parsecheck("2015-12-06 21:21:21 A", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 22, 21, 21);
+ parsecheck("2015-12-06 21:21:21 G", NULL, NULL, gmtime_r,
+ 2015, 12, 7, 4, 21, 21);
+ parsecheck("2015-12-06 21:21:21 M", NULL, NULL, gmtime_r,
+ 2015, 12, 7, 9, 21, 21);
+ parsecheck("2015-12-06 21:21:21 N", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 20, 21, 21);
+ parsecheck("2015-12-06 21:21:21 T", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 14, 21, 21);
+ parsecheck("2015-12-06 21:21:21 Y", NULL, NULL, gmtime_r,
+ 2015, 12, 6, 9, 21, 21);
+
+}
+
+ATF_TC(gibberish);
+
+ATF_TC_HEAD(gibberish, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test (not) parsing nonsense");
+}
+
+ATF_TC_BODY(gibberish, tc)
+{
+ errno = 0;
+ ATF_CHECK(parsedate("invalid nonsense", NULL, NULL) == (time_t)-1
+ && errno != 0);
+ errno = 0;
+ ATF_CHECK(parsedate("12th day of Christmas", NULL, NULL) == (time_t)-1
+ && errno != 0);
+ errno = 0;
+ ATF_CHECK(parsedate("2015-31-07 15:00", NULL, NULL) == (time_t)-1
+ && errno != 0);
+ errno = 0;
+ ATF_CHECK(parsedate("2015-02-29 10:01", NULL, NULL) == (time_t)-1
+ && errno != 0);
+ errno = 0;
+ ATF_CHECK(parsedate("2015-12-06 24:01", NULL, NULL) == (time_t)-1
+ && errno != 0);
+ errno = 0;
+ ATF_CHECK(parsedate("2015-12-06 14:61", NULL, NULL) == (time_t)-1
+ && errno != 0);
+}
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, dates);
ATF_TP_ADD_TC(tp, times);
+ ATF_TP_ADD_TC(tp, dsttimes);
ATF_TP_ADD_TC(tp, relative);
ATF_TP_ADD_TC(tp, atsecs);
+ ATF_TP_ADD_TC(tp, zones);
+ ATF_TP_ADD_TC(tp, gibberish);
return atf_no_error();
}
+
OpenPOWER on IntegriCloud