diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2016-09-03 19:09:01 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2016-09-03 19:09:01 +0000 |
commit | c22165b4f1f5d38b681921797a44b3ba8c13b7e0 (patch) | |
tree | 252c24b568ad866ae902fd3b64462c1df486afd1 /contrib/netbsd-tests/lib | |
parent | 86ea5291326635f26a1f6a923852f706d44a4be1 (diff) | |
parent | 2db7b9f259535c36879c35f6c656090034f33101 (diff) | |
download | src-c22165b4f1f5d38b681921797a44b3ba8c13b7e0.tar.gz src-c22165b4f1f5d38b681921797a44b3ba8c13b7e0.zip |
Merge ^/head r305346 through r305360.
Notes
Notes:
svn path=/projects/clang390-import/; revision=305361
Diffstat (limited to 'contrib/netbsd-tests/lib')
59 files changed, 5330 insertions, 332 deletions
diff --git a/contrib/netbsd-tests/lib/libbpfjit/t_bpfjit.c b/contrib/netbsd-tests/lib/libbpfjit/t_bpfjit.c index da67c1b335ce..4d81dd663d43 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 530887685f21..5cb5f39ed783 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 d40298e11dcc..10629c57a4af 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 43ddd2c51822..d393fd1ddf5b 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/db/h_lfsr.c b/contrib/netbsd-tests/lib/libc/db/h_lfsr.c new file mode 100644 index 000000000000..3f3d712dfd85 --- /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 4f45ec101da4..eb6b8c9250d1 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.6 2015/11/18 18:35:35 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 @@ -77,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 @@ -106,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 @@ -133,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 @@ -164,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 @@ -195,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 @@ -220,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 @@ -249,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 } @@ -277,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" } @@ -305,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 } @@ -373,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 @@ -411,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 @@ -463,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 @@ -532,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 } @@ -576,7 +581,7 @@ h_repeated() } }' >in - $(prog) btree in + $(prog_db) btree in } atf_test_case repeated_btree @@ -631,7 +636,7 @@ 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() @@ -660,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 | @@ -674,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 } @@ -730,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 @@ -763,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() @@ -783,14 +788,14 @@ h_byte_orders() 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 } @@ -823,14 +828,14 @@ 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 @@ -896,9 +901,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() { @@ -921,15 +944,36 @@ 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_init_test_cases() { atf_add_test_case small_btree @@ -957,4 +1001,5 @@ 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 } 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 000000000000..6e19e22407b1 --- /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 32de6e765780..d3752cd5f948 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 7d73a227ce79..c44ffda082a0 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_spawn.c b/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawn.c index 178374b863df..12f276050bdd 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/t_fnmatch.c b/contrib/netbsd-tests/lib/libc/gen/t_fnmatch.c index f90d8cfdd0d1..c0064c38f66a 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.6 2014/10/12 22:33:41 christos 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.6 2014/10/12 22:33:41 christos Exp $"); #include <atf-c.h> #include <fnmatch.h> @@ -153,6 +153,30 @@ 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-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 +186,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 3366c1f2f5cb..5edc583ce2a8 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_randomid.c b/contrib/netbsd-tests/lib/libc/gen/t_randomid.c index 8377806252cd..9ab2ccaaa073 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 9c9a3c743c0b..64f72acabdcf 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 f722ec9691b4..e89df690e4e7 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.9 2016/08/11 21:34:11 kre Exp $ */ /*- * Copyright (c) 2006 Frank Kardel @@ -180,7 +180,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 790f3caada48..290540366d1d 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.3 2014/10/31 12:22:38 justin Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * 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.3 2014/10/31 12:22:38 justin Exp $"); #ifdef __FreeBSD__ #include <sys/time.h> @@ -94,15 +94,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_vis.c b/contrib/netbsd-tests/lib/libc/gen/t_vis.c index 525bafafb17e..38decb3069c9 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.8 2015/05/23 14:02:11 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,35 @@ ATF_TC_BODY(strunvis_hex, tc) } } +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); +} + ATF_TP_ADD_TCS(tp) { @@ -150,6 +180,7 @@ 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); + ATF_TP_ADD_TC(tp, strvis_locale); 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 000000000000..d7547fd7b3ff --- /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 a6a6c62b61dc..c44fe11603e3 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 0979eb37dc84..4c23f009b232 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 a9715cf3a97f..72bda8d4fb8b 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.9 2015/11/27 13:59:40 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.9 2015/11/27 13:59:40 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> @@ -28,6 +29,12 @@ __RCSID("$NetBSD: t_rpc.c,v 1.3 2013/02/28 15:56:53 christos Exp $"); #define SKIPX(ev, msg, ...) errx(ev, msg, __VA_ARGS__) #endif +#ifdef DEBUG +#define DPRINTF(...) printf(__VA_ARGS__) +#else +#define DPRINTF(...) +#endif + #define RPCBPROC_NULL 0 @@ -51,7 +58,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) @@ -86,9 +93,140 @@ onehost(const char *host, const char *transp) 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(EXIT_FAILURE, "svc_sendreply failed %d", 0); + return; + case PLUSONE: + break; + case DESTROY: + if (!svc_sendreply(transp, (xdrproc_t)xdr_void, NULL)) + ERRX(EXIT_FAILURE, "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(EXIT_FAILURE, "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)) + ERRX(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 +241,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 +315,79 @@ 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__ + atf_tc_expect_fail("fails with: clnt_call: " + "RPC: Can't decode result -- PR # 211804"); +#endif + rawtest(NULL); + +} + +ATF_TC(tcp); +ATF_TC_HEAD(tcp, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks svc tcp (select)"); +} + +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)"); +} + +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)"); +} + +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)"); +} + +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/stdio/t_open_memstream.c b/contrib/netbsd-tests/lib/libc/stdio/t_open_memstream.c new file mode 100644 index 000000000000..950a258ac5c5 --- /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 5a8fa2822429..7e297783fa79 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 47afb8493bed..8db788075fc1 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 8f0f899e2ee4..905306d042bf 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[] = @@ -246,7 +244,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 +268,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 000000000000..bf958a18d016 --- /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 5a0c6d0e51ea..54e190760656 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_memset.c b/contrib/netbsd-tests/lib/libc/string/t_memset.c index c1fb3855e076..5a2be2896654 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/sync/cpp_atomic_ops_linkable.cc b/contrib/netbsd-tests/lib/libc/sync/cpp_atomic_ops_linkable.cc new file mode 100644 index 000000000000..742685103dba --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/sync/cpp_atomic_ops_linkable.cc @@ -0,0 +1,119 @@ +/* $NetBSD: cpp_atomic_ops_linkable.cc,v 1.4 2016/02/27 18:50:39 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; +}; + +#if defined(__clang__) && defined(__sparc64__) +#define NO_SHORT_ATOMICS +#endif + +int main(int argc, char **argv) +{ +#ifndef NO_SHORT_ATOMICS + ATest<char>(); + ATest<signed char>(); + ATest<unsigned char>(); + ATest<short>(); + ATest<unsigned short>(); +#endif + ATest<int>(); + ATest<unsigned int>(); + ATest<long>(); + ATest<unsigned long>(); +#ifdef __HAVE_ATOMIC64_OPS + ATest<long long>(); + ATest<unsigned long long>(); +#endif +#ifndef NO_SHORT_ATOMICS + ATest<char16_t>(); +#endif + ATest<char32_t>(); + ATest<wchar_t>(); +#ifndef NO_SHORT_ATOMICS + ATest<int_least8_t>(); + ATest<uint_least8_t>(); + ATest<int_least16_t>(); + ATest<uint_least16_t>(); +#endif + ATest<int_least32_t>(); + ATest<uint_least32_t>(); +#ifdef __HAVE_ATOMIC64_OPS + ATest<int_least64_t>(); + ATest<uint_least64_t>(); +#endif +#ifndef NO_SHORT_ATOMICS + ATest<int_fast8_t>(); + ATest<uint_fast8_t>(); + ATest<int_fast16_t>(); + ATest<uint_fast16_t>(); +#endif + 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 /* NO_SHORT_ATOMICS */ +} 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 000000000000..0c6027c2a14a --- /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_connect.c b/contrib/netbsd-tests/lib/libc/sys/t_connect.c index 896b49074a77..672a022c326e 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_getrusage.c b/contrib/netbsd-tests/lib/libc/sys/t_getrusage.c index 85eeac6bee0c..aa5c4d567a0e 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> @@ -64,6 +64,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 000000000000..01b1f8a5bec3 --- /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 fe298c552825..385855401dcb 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> @@ -179,8 +179,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_mlock.c b/contrib/netbsd-tests/lib/libc/sys/t_mlock.c index d4aef4a382b1..75048b3b48d6 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> @@ -180,6 +180,7 @@ ATF_TC_BODY(mlock_err, tc) void *invalid_ptr; #endif int null_errno = ENOMEM; /* error expected for NULL */ + void *buf; #ifdef __FreeBSD__ #ifdef VM_MIN_ADDRESS @@ -191,32 +192,52 @@ 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); /* There is no sbrk on AArch64 and RISC-V */ #if !defined(__aarch64__) && !defined(__riscv__) /* + * 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 * brk will likely do. */ diff --git a/contrib/netbsd-tests/lib/libc/sys/t_mmap.c b/contrib/netbsd-tests/lib/libc/sys/t_mmap.c index 5d821ecad044..9e74d41fd6c6 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.9 2015/02/28 13:57:08 martin Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -55,7 +55,7 @@ * 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.9 2015/02/28 13:57:08 martin Exp $"); #include <sys/param.h> #include <sys/mman.h> @@ -461,6 +461,72 @@ 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); + 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 +584,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 ee345aadf2c0..5dc3eae14701 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 000000000000..b931ebdb2b10 --- /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 72175e4f682d..84b014972361 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> @@ -512,6 +512,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) { @@ -527,6 +546,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 6686f022b131..e911d42e93a0 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_wait.c b/contrib/netbsd-tests/lib/libc/sys/t_wait.c new file mode 100644 index 000000000000..027c40dd67b6 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/sys/t_wait.c @@ -0,0 +1,265 @@ +/* $NetBSD: t_wait.c,v 1.4 2016/04/27 21:14:24 christos 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.4 2016/04/27 21:14:24 christos 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_noproc); +ATF_TC_HEAD(wait6_noproc, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Test that wait6(2) returns ECHILD with for no processes"); +} + +ATF_TC_BODY(wait6_noproc, tc) +{ + siginfo_t si; + struct wrusage wru; + int st; + ATF_REQUIRE(wait6(P_ALL, 0, &st, WEXITED, &wru, &si) == -1 + && errno == ECHILD); +} + +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(WIFSTOPPED(st) && WSTOPSIG(st) == SIGSTOP); + 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(WIFCONTINUED(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(WIFSIGNALED(st) && WTERMSIG(st) == SIGQUIT); + 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_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, wait6_invalid); + ATF_TP_ADD_TC(tp, wait6_noproc); + 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); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libc/time/t_strptime.c b/contrib/netbsd-tests/lib/libc/time/t_strptime.c index 99871ffdc4b6..863df36e5969 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 37c813fa6c27..75aaf62d6220 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_exp.c b/contrib/netbsd-tests/lib/libm/t_exp.c index 7a8e9f804366..0eb6412b566e 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_fenv.c b/contrib/netbsd-tests/lib/libm/t_fenv.c new file mode 100644 index 000000000000..544503673a98 --- /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 837e9b24f5c1..2a221f5f62e1 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 000000000000..deb7e86ad5ac --- /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_log.c b/contrib/netbsd-tests/lib/libm/t_log.c index 016423344be2..756efcf39769 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 a8ae6f0f62fa..fbdb9845363e 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/libpthread/t_cond.c b/contrib/netbsd-tests/lib/libpthread/t_cond.c index 9f33c9e05091..83a3833015d1 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 eb371fabd883..1fcd69ed470c 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.10 2016/07/31 13:01:29 christos Exp $ */ /* * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -29,12 +29,15 @@ #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.10 2016/07/31 13:01:29 christos Exp $"); #include <pthread.h> #include <stdio.h> #include <string.h> +#include <errno.h> #include <unistd.h> +#include <sys/sched.h> +#include <sys/param.h> #include <atf-c.h> @@ -316,12 +319,281 @@ 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(pthread_mutex_lock(&mutex5)); + 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, ¶m); + 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(pthread_mutex_lock(&mutex5)); + 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, ¶m)); + PTHREAD_REQUIRE(pthread_getschedparam(childid, &policy, ¶m)); + 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(pthread_mutex_lock(&mutex6)); + 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, ¶m)); + PTHREAD_REQUIRE(pthread_getschedparam(childid, &policy, ¶m)); + 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(pthread_mutex_lock(&mutex6)); + 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, ¶m); + 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); + } +} + 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); + 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 b2a3d6f0aec8..81f8c58a0591 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/librumpclient/t_exec.sh b/contrib/netbsd-tests/lib/librumpclient/t_exec.sh index 661a3b92779b..a07af0c27814 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 aa0d1ccc6945..6e6d9470e7a1 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 d6a16fad6a2c..718dfdc1de4c 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.17 2016/08/11 21:29:44 kre Exp $ # # Copyright (c) 2011 The NetBSD Foundation, Inc. # All rights reserved. @@ -25,7 +25,7 @@ # POSSIBILITY OF SUCH DAMAGE. # -rumpnetsrv='rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet' +rumpnetsrv='rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpdev' export RUMP_SERVER=unix://csock atf_test_case http cleanup @@ -53,8 +53,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 +122,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 +179,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 +205,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 +232,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 +254,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 000000000000..dedcb11fc2b0 --- /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 000000000000..f20652a926f1 --- /dev/null +++ b/contrib/netbsd-tests/lib/libusbhid/t_usbhid.c @@ -0,0 +1,449 @@ +/* $NetBSD: t_usbhid.c,v 1.11 2016/01/07 16:10:49 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.11 2016/01/07 16:10:49 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_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 000000000000..2444ef228282 --- /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 ec035a6dfaf6..c78df58b6b1c 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(); } + |