Importing NetBSD "Kyua" test framework
To do so, a few dependencies have been imported: * external/bsd/lutok * external/mit/lua * external/public-domain/sqlite * external/public-domain/xz The Kyua framework is the new generation of ATF (Automated Test Framework), it is composed of: * external/bsd/atf * external/bsd/kyua-atf-compat * external/bsd/kyua-cli * external/bsd/kyua-tester * tests Kyua/ATF being written in C++, it depends on libstdc++ which is provided by GCC. As this is not part of the sources, Kyua is only compiled when the native GCC utils are installed. To install Kyua do the following: * In a cross-build enviromnent, add the following to the build.sh commandline: -V MKBINUTILS=yes -V MKGCCCMDS=yes WARNING: At this point the import is still experimental, and not supported on native builds (a.k.a make build). Change-Id: I26aee23c5bbd2d64adcb7c1beb98fe0d479d7ada
This commit is contained in:
20
tests/include/sys/Makefile
Normal file
20
tests/include/sys/Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
# $NetBSD: Makefile,v 1.7 2012/08/08 13:57:06 christos Exp $
|
||||
|
||||
NOMAN= # defined
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
TESTSDIR= ${TESTSBASE}/include/sys
|
||||
|
||||
#LSC: Unsupported on Minix t_bitops
|
||||
TESTS_C= t_bootblock t_cdefs t_tree t_types
|
||||
|
||||
LDADD.t_bitops+= -lm
|
||||
|
||||
.if (${MKRUMP} != "no")
|
||||
TESTS_C+= t_socket
|
||||
LDADD.t_socket+= -lrumpnet_local -lrumpnet_net -lrumpnet
|
||||
LDADD.t_socket+= -lrumpvfs -lrump -lrumpuser -lpthread
|
||||
.endif
|
||||
|
||||
.include <bsd.test.mk>
|
||||
238
tests/include/sys/t_bitops.c
Normal file
238
tests/include/sys/t_bitops.c
Normal file
@@ -0,0 +1,238 @@
|
||||
/* $NetBSD: t_bitops.c,v 1.16 2012/12/07 02:28:19 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2011, 2012 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas and 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.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: t_bitops.c,v 1.16 2012/12/07 02:28:19 christos Exp $");
|
||||
|
||||
#include <atf-c.h>
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/bitops.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static const struct {
|
||||
uint32_t val;
|
||||
int ffs;
|
||||
int fls;
|
||||
} bits[] = {
|
||||
|
||||
{ 0x00, 0, 0 }, { 0x01, 1, 1 }, { 0x02, 2, 2 }, { 0x03, 1, 2 },
|
||||
{ 0x04, 3, 3 }, { 0x05, 1, 3 }, { 0x06, 2, 3 }, { 0x07, 1, 3 },
|
||||
{ 0x08, 4, 4 }, { 0x09, 1, 4 }, { 0x0A, 2, 4 }, { 0x0B, 1, 4 },
|
||||
{ 0x0C, 3, 4 }, { 0x0D, 1, 4 }, { 0x0E, 2, 4 }, { 0x0F, 1, 4 },
|
||||
|
||||
{ 0x10, 5, 5 }, { 0x11, 1, 5 }, { 0x12, 2, 5 }, { 0x13, 1, 5 },
|
||||
{ 0x14, 3, 5 }, { 0x15, 1, 5 }, { 0x16, 2, 5 }, { 0x17, 1, 5 },
|
||||
{ 0x18, 4, 5 }, { 0x19, 1, 5 }, { 0x1A, 2, 5 }, { 0x1B, 1, 5 },
|
||||
{ 0x1C, 3, 5 }, { 0x1D, 1, 5 }, { 0x1E, 2, 5 }, { 0x1F, 1, 5 },
|
||||
|
||||
{ 0xF0, 5, 8 }, { 0xF1, 1, 8 }, { 0xF2, 2, 8 }, { 0xF3, 1, 8 },
|
||||
{ 0xF4, 3, 8 }, { 0xF5, 1, 8 }, { 0xF6, 2, 8 }, { 0xF7, 1, 8 },
|
||||
{ 0xF8, 4, 8 }, { 0xF9, 1, 8 }, { 0xFA, 2, 8 }, { 0xFB, 1, 8 },
|
||||
{ 0xFC, 3, 8 }, { 0xFD, 1, 8 }, { 0xFE, 2, 8 }, { 0xFF, 1, 8 },
|
||||
|
||||
};
|
||||
|
||||
ATF_TC(bitmap_basic);
|
||||
ATF_TC_HEAD(bitmap_basic, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "A basic test of __BITMAP_*");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(bitmap_basic, tc)
|
||||
{
|
||||
__BITMAP_TYPE(, uint32_t, 65536) bm;
|
||||
__BITMAP_ZERO(&bm);
|
||||
|
||||
ATF_REQUIRE(__BITMAP_SIZE(uint32_t, 65536) == 2048);
|
||||
|
||||
ATF_REQUIRE(__BITMAP_SHIFT(uint32_t) == 5);
|
||||
|
||||
ATF_REQUIRE(__BITMAP_MASK(uint32_t) == 31);
|
||||
|
||||
for (size_t i = 0; i < 65536; i += 2)
|
||||
__BITMAP_SET(i, &bm);
|
||||
|
||||
for (size_t i = 0; i < 2048; i++)
|
||||
ATF_REQUIRE(bm._b[i] == 0x55555555);
|
||||
|
||||
for (size_t i = 0; i < 65536; i++)
|
||||
if (i & 1)
|
||||
ATF_REQUIRE(!__BITMAP_ISSET(i, &bm));
|
||||
else {
|
||||
ATF_REQUIRE(__BITMAP_ISSET(i, &bm));
|
||||
__BITMAP_CLR(i, &bm);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 65536; i += 2)
|
||||
ATF_REQUIRE(!__BITMAP_ISSET(i, &bm));
|
||||
}
|
||||
|
||||
ATF_TC(fast_divide32);
|
||||
ATF_TC_HEAD(fast_divide32, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "A basic test of fast_divide32(3)");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(fast_divide32, tc)
|
||||
{
|
||||
uint32_t a, b, q, r, m;
|
||||
uint8_t i, s1, s2;
|
||||
|
||||
a = 0xFFFF;
|
||||
b = 0x000F;
|
||||
|
||||
fast_divide32_prepare(b, &m, &s1, &s2);
|
||||
|
||||
q = fast_divide32(a, b, m, s1, s2);
|
||||
r = fast_remainder32(a, b, m, s1, s2);
|
||||
|
||||
ATF_REQUIRE(q == 0x1111 && r == 0);
|
||||
|
||||
for (i = 1; i < __arraycount(bits); i++) {
|
||||
|
||||
a = bits[i].val;
|
||||
b = bits[i].ffs;
|
||||
|
||||
fast_divide32_prepare(b, &m, &s1, &s2);
|
||||
|
||||
q = fast_divide32(a, b, m, s1, s2);
|
||||
r = fast_remainder32(a, b, m, s1, s2);
|
||||
|
||||
ATF_REQUIRE(q == a / b);
|
||||
ATF_REQUIRE(r == a % b);
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC(ffsfls);
|
||||
ATF_TC_HEAD(ffsfls, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test ffs32(3)-family for correctness");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(ffsfls, tc)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
ATF_REQUIRE(ffs32(0) == 0x00);
|
||||
ATF_REQUIRE(fls32(0) == 0x00);
|
||||
ATF_REQUIRE(ffs64(0) == 0x00);
|
||||
ATF_REQUIRE(fls64(0) == 0x00);
|
||||
|
||||
ATF_REQUIRE(ffs32(UINT32_MAX) == 0x01);
|
||||
ATF_REQUIRE(fls32(UINT32_MAX) == 0x20);
|
||||
ATF_REQUIRE(ffs64(UINT64_MAX) == 0x01);
|
||||
ATF_REQUIRE(fls64(UINT64_MAX) == 0x40);
|
||||
|
||||
for (i = 1; i < __arraycount(bits); i++) {
|
||||
|
||||
ATF_REQUIRE(ffs32(bits[i].val) == bits[i].ffs);
|
||||
ATF_REQUIRE(fls32(bits[i].val) == bits[i].fls);
|
||||
ATF_REQUIRE(ffs64(bits[i].val) == bits[i].ffs);
|
||||
ATF_REQUIRE(fls64(bits[i].val) == bits[i].fls);
|
||||
|
||||
ATF_REQUIRE(ffs32(bits[i].val << 1) == bits[i].ffs + 1);
|
||||
ATF_REQUIRE(fls32(bits[i].val << 1) == bits[i].fls + 1);
|
||||
ATF_REQUIRE(ffs64(bits[i].val << 1) == bits[i].ffs + 1);
|
||||
ATF_REQUIRE(fls64(bits[i].val << 1) == bits[i].fls + 1);
|
||||
|
||||
ATF_REQUIRE(ffs32(bits[i].val << 9) == bits[i].ffs + 9);
|
||||
ATF_REQUIRE(fls32(bits[i].val << 9) == bits[i].fls + 9);
|
||||
ATF_REQUIRE(ffs64(bits[i].val << 9) == bits[i].ffs + 9);
|
||||
ATF_REQUIRE(fls64(bits[i].val << 9) == bits[i].fls + 9);
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC(ilog2_basic);
|
||||
ATF_TC_HEAD(ilog2_basic, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test ilog2(3) for correctness");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(ilog2_basic, tc)
|
||||
{
|
||||
uint64_t i, x;
|
||||
|
||||
for (i = x = 0; i < 64; i++) {
|
||||
|
||||
x = (uint64_t)1 << i;
|
||||
|
||||
ATF_REQUIRE(i == (uint64_t)ilog2(x));
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC(ilog2_log2);
|
||||
ATF_TC_HEAD(ilog2_log2, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test log2(3) vs. ilog2(3)");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(ilog2_log2, tc)
|
||||
{
|
||||
#ifdef __vax__
|
||||
atf_tc_skip("Test is unavailable on vax because of lack of log2()");
|
||||
#else
|
||||
double x, y;
|
||||
uint64_t i;
|
||||
|
||||
/*
|
||||
* This may fail under QEMU; see PR misc/44767.
|
||||
*/
|
||||
for (i = 1; i < UINT32_MAX; i += UINT16_MAX) {
|
||||
|
||||
x = log2(i);
|
||||
y = (double)(ilog2(i));
|
||||
|
||||
ATF_REQUIRE(ceil(x) >= y);
|
||||
|
||||
if (fabs(floor(x) - y) > 1.0e-40) {
|
||||
atf_tc_expect_fail("PR misc/44767");
|
||||
atf_tc_fail("log2(%"PRIu64") != "
|
||||
"ilog2(%"PRIu64")", i, i);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
|
||||
ATF_TP_ADD_TC(tp, bitmap_basic);
|
||||
ATF_TP_ADD_TC(tp, fast_divide32);
|
||||
ATF_TP_ADD_TC(tp, ffsfls);
|
||||
ATF_TP_ADD_TC(tp, ilog2_basic);
|
||||
ATF_TP_ADD_TC(tp, ilog2_log2);
|
||||
|
||||
return atf_no_error();
|
||||
}
|
||||
73
tests/include/sys/t_bootblock.c
Normal file
73
tests/include/sys/t_bootblock.c
Normal file
@@ -0,0 +1,73 @@
|
||||
/* $NetBSD: t_bootblock.c,v 1.1 2010/07/17 19:26:27 jmmv Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004, 2008, 2010 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__COPYRIGHT("@(#) Copyright (c) 2008, 2010\
|
||||
The NetBSD Foundation, inc. All rights reserved.");
|
||||
__RCSID("$NetBSD: t_bootblock.c,v 1.1 2010/07/17 19:26:27 jmmv Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/bootblock.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(mbr_sector);
|
||||
ATF_TC_BODY(mbr_sector, tc)
|
||||
{
|
||||
ATF_CHECK_EQ(512, sizeof(struct mbr_sector));
|
||||
|
||||
ATF_CHECK_EQ(MBR_BPB_OFFSET, offsetof(struct mbr_sector, mbr_bpb));
|
||||
ATF_CHECK_EQ(MBR_BS_OFFSET, offsetof(struct mbr_sector, mbr_bootsel));
|
||||
|
||||
ATF_CHECK_EQ(440, offsetof(struct mbr_sector, mbr_dsn));
|
||||
|
||||
ATF_CHECK_EQ(446, MBR_PART_OFFSET);
|
||||
ATF_CHECK_EQ(MBR_PART_OFFSET, offsetof(struct mbr_sector, mbr_parts));
|
||||
|
||||
ATF_CHECK_EQ(510, MBR_MAGIC_OFFSET);
|
||||
ATF_CHECK_EQ(MBR_MAGIC_OFFSET, offsetof(struct mbr_sector, mbr_magic));
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(mbr_partition);
|
||||
ATF_TC_BODY(mbr_partition, tc)
|
||||
{
|
||||
ATF_CHECK_EQ(16, sizeof(struct mbr_partition));
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
|
||||
ATF_TP_ADD_TC(tp, mbr_sector);
|
||||
ATF_TP_ADD_TC(tp, mbr_partition);
|
||||
|
||||
return atf_no_error();
|
||||
}
|
||||
267
tests/include/sys/t_cdefs.c
Normal file
267
tests/include/sys/t_cdefs.c
Normal file
@@ -0,0 +1,267 @@
|
||||
/* $NetBSD: t_cdefs.c,v 1.2 2012/03/23 23:12:28 matt Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2012 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>
|
||||
__COPYRIGHT("@(#) Copyright (c) 2008\
|
||||
The NetBSD Foundation, inc. All rights reserved.");
|
||||
__RCSID("$NetBSD: t_cdefs.c,v 1.2 2012/03/23 23:12:28 matt Exp $");
|
||||
|
||||
#include <atf-c.h>
|
||||
#include <sys/types.h>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
intmax_t min;
|
||||
intmax_t max;
|
||||
} s[] = {
|
||||
{ "signed char", SCHAR_MIN, SCHAR_MAX },
|
||||
{ "signed short", SHRT_MIN, SHRT_MAX },
|
||||
{ "signed int", INT_MIN, INT_MAX },
|
||||
{ "signed long", LONG_MIN, LONG_MAX },
|
||||
{ "signed long long", LLONG_MIN, LLONG_MAX },
|
||||
};
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
uintmax_t min;
|
||||
uintmax_t max;
|
||||
} u[] = {
|
||||
{ "unsigned char", 0, UCHAR_MAX },
|
||||
{ "unsigned short", 0, USHRT_MAX },
|
||||
{ "unsigned int", 0, UINT_MAX },
|
||||
{ "unsigned long", 0, ULONG_MAX },
|
||||
{ "unsigned long long", 0, ULLONG_MAX },
|
||||
};
|
||||
|
||||
ATF_TC(stypeminmax);
|
||||
ATF_TC_HEAD(stypeminmax, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Checks signed type min/max macros");
|
||||
}
|
||||
|
||||
|
||||
ATF_TC_BODY(stypeminmax, tc)
|
||||
{
|
||||
#define CHECK(a, b) ATF_REQUIRE(__type_min(a) == s[b].min); \
|
||||
ATF_REQUIRE(__type_max(a) == s[b].max)
|
||||
|
||||
CHECK(signed char, 0);
|
||||
CHECK(signed short, 1);
|
||||
CHECK(signed int, 2);
|
||||
CHECK(signed long, 3);
|
||||
CHECK(signed long long, 4);
|
||||
#undef CHECK
|
||||
}
|
||||
|
||||
ATF_TC(utypeminmax);
|
||||
ATF_TC_HEAD(utypeminmax, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Checks unsigned type min/max macros");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(utypeminmax, tc)
|
||||
{
|
||||
#define CHECK(a, b) ATF_REQUIRE(__type_min(a) == u[b].min); \
|
||||
ATF_REQUIRE(__type_max(a) == u[b].max)
|
||||
|
||||
CHECK(unsigned char, 0);
|
||||
CHECK(unsigned short, 1);
|
||||
CHECK(unsigned int, 2);
|
||||
CHECK(unsigned long, 3);
|
||||
CHECK(unsigned long long, 4);
|
||||
#undef CHECK
|
||||
}
|
||||
|
||||
ATF_TC(sissigned);
|
||||
ATF_TC_HEAD(sissigned, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Checks issigned macro for signed");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(sissigned, tc)
|
||||
{
|
||||
#define CHECK(a) ATF_REQUIRE(__type_is_signed(a) == 1)
|
||||
|
||||
CHECK(signed char);
|
||||
CHECK(signed short);
|
||||
CHECK(signed int);
|
||||
CHECK(signed long);
|
||||
CHECK(signed long long);
|
||||
#undef CHECK
|
||||
}
|
||||
|
||||
ATF_TC(uissigned);
|
||||
ATF_TC_HEAD(uissigned, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Checks issigned macro for unsigned");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(uissigned, tc)
|
||||
{
|
||||
#define CHECK(a) ATF_REQUIRE(__type_is_signed(a) == 0)
|
||||
|
||||
CHECK(unsigned char);
|
||||
CHECK(unsigned short);
|
||||
CHECK(unsigned int);
|
||||
CHECK(unsigned long);
|
||||
CHECK(unsigned long long);
|
||||
#undef CHECK
|
||||
}
|
||||
|
||||
ATF_TC(utypemask);
|
||||
ATF_TC_HEAD(utypemask, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Checks type mask macro for unsigned");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(utypemask, tc)
|
||||
{
|
||||
#define CHECK(a, b) ATF_REQUIRE(__type_mask(a) == b)
|
||||
|
||||
CHECK(unsigned char, 0xffffffffffffff00ULL);
|
||||
CHECK(unsigned short, 0xffffffffffff0000ULL);
|
||||
CHECK(unsigned int, 0xffffffff00000000ULL);
|
||||
CHECK(unsigned long long, 0x0000000000000000ULL);
|
||||
#undef CHECK
|
||||
}
|
||||
|
||||
ATF_TC(stypemask);
|
||||
ATF_TC_HEAD(stypemask, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Checks type mask macro for signed");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(stypemask, tc)
|
||||
{
|
||||
#define CHECK(a, b) ATF_REQUIRE(__type_mask(a) == b)
|
||||
|
||||
CHECK(signed char, 0xffffffffffffff00LL);
|
||||
CHECK(signed short, 0xffffffffffff0000LL);
|
||||
CHECK(signed int, 0xffffffff00000000LL);
|
||||
CHECK(signed long long, 0x0000000000000000LL);
|
||||
#undef CHECK
|
||||
}
|
||||
|
||||
ATF_TC(stypefit);
|
||||
ATF_TC_HEAD(stypefit, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Checks typefit macro for signed");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(stypefit, tc)
|
||||
{
|
||||
#define CHECK(a, b, c) ATF_REQUIRE(!__type_fit(a, b) == c)
|
||||
|
||||
CHECK(signed char, -1, 0);
|
||||
CHECK(signed char, 1, 0);
|
||||
CHECK(signed char, 0x7f, 0);
|
||||
CHECK(signed char, 0x80, 1);
|
||||
CHECK(signed char, 0xff, 1);
|
||||
CHECK(signed char, 0x1ff, 1);
|
||||
|
||||
CHECK(signed short, -1, 0);
|
||||
CHECK(signed short, 1, 0);
|
||||
CHECK(signed short, 0x7fff, 0);
|
||||
CHECK(signed short, 0x8000, 1);
|
||||
CHECK(signed short, 0xffff, 1);
|
||||
CHECK(signed short, 0x1ffff, 1);
|
||||
|
||||
CHECK(signed int, -1, 0);
|
||||
CHECK(signed int, 1, 0);
|
||||
CHECK(signed int, 0x7fffffff, 0);
|
||||
CHECK(signed int, 0x80000000, 1);
|
||||
CHECK(signed int, 0xffffffff, 1);
|
||||
CHECK(signed int, 0x1ffffffffLL, 1);
|
||||
|
||||
CHECK(signed long long, -1, 0);
|
||||
CHECK(signed long long, 1, 0);
|
||||
CHECK(signed long long, 0x7fffffffffffffffLL, 0);
|
||||
CHECK(signed long long, 0x8000000000000000LL, 0);
|
||||
CHECK(signed long long, 0xffffffffffffffffLL, 0);
|
||||
|
||||
#undef CHECK
|
||||
}
|
||||
|
||||
ATF_TC(utypefit);
|
||||
ATF_TC_HEAD(utypefit, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Checks typefit macro for unsigned");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(utypefit, tc)
|
||||
{
|
||||
#define CHECK(a, b, c) ATF_REQUIRE(!__type_fit(a, b) == c)
|
||||
|
||||
CHECK(unsigned char, -1, 1);
|
||||
CHECK(unsigned char, 1, 0);
|
||||
CHECK(unsigned char, 0x7f, 0);
|
||||
CHECK(unsigned char, 0x80, 0);
|
||||
CHECK(unsigned char, 0xff, 0);
|
||||
CHECK(unsigned char, 0x1ff, 1);
|
||||
|
||||
CHECK(unsigned short, -1, 1);
|
||||
CHECK(unsigned short, 1, 0);
|
||||
CHECK(unsigned short, 0x7fff, 0);
|
||||
CHECK(unsigned short, 0x8000, 0);
|
||||
CHECK(unsigned short, 0xffff, 0);
|
||||
CHECK(unsigned short, 0x1ffff, 1);
|
||||
|
||||
CHECK(unsigned int, -1, 1);
|
||||
CHECK(unsigned int, 1, 0);
|
||||
CHECK(unsigned int, 0x7fffffff, 0);
|
||||
CHECK(unsigned int, 0x80000000, 0);
|
||||
CHECK(unsigned int, 0xffffffff, 0);
|
||||
CHECK(unsigned int, 0x1ffffffffLL, 1);
|
||||
|
||||
CHECK(unsigned long long, -1, 1);
|
||||
CHECK(unsigned long long, 1, 0);
|
||||
CHECK(unsigned long long, 0x7fffffffffffffffULL, 0);
|
||||
CHECK(unsigned long long, 0x8000000000000000ULL, 0);
|
||||
CHECK(unsigned long long, 0xffffffffffffffffULL, 0);
|
||||
|
||||
#undef CHECK
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
ATF_TP_ADD_TC(tp, stypeminmax);
|
||||
ATF_TP_ADD_TC(tp, utypeminmax);
|
||||
ATF_TP_ADD_TC(tp, sissigned);
|
||||
ATF_TP_ADD_TC(tp, uissigned);
|
||||
ATF_TP_ADD_TC(tp, stypemask);
|
||||
ATF_TP_ADD_TC(tp, utypemask);
|
||||
ATF_TP_ADD_TC(tp, stypefit);
|
||||
ATF_TP_ADD_TC(tp, utypefit);
|
||||
|
||||
return atf_no_error();
|
||||
}
|
||||
188
tests/include/sys/t_socket.c
Normal file
188
tests/include/sys/t_socket.c
Normal file
@@ -0,0 +1,188 @@
|
||||
/* $NetBSD: t_socket.c,v 1.1 2011/07/07 05:50:27 jruoho Exp $ */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
#include <rump/rump.h>
|
||||
#include <rump/rump_syscalls.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#include <fcntl.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <util.h>
|
||||
|
||||
#include "../../h_macros.h"
|
||||
|
||||
ATF_TC(cmsg_sendfd_bounds);
|
||||
ATF_TC_HEAD(cmsg_sendfd_bounds, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Checks that attempting to pass an "
|
||||
"invalid fd returns an error");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(cmsg_sendfd_bounds, tc)
|
||||
{
|
||||
struct cmsghdr *cmp;
|
||||
struct msghdr msg;
|
||||
struct iovec iov;
|
||||
int s[2];
|
||||
int fd;
|
||||
|
||||
rump_init();
|
||||
|
||||
if (rump_sys_socketpair(AF_LOCAL, SOCK_STREAM, 0, s) == -1)
|
||||
atf_tc_fail("rump_sys_socket");
|
||||
|
||||
cmp = malloc(CMSG_SPACE(sizeof(int)));
|
||||
|
||||
iov.iov_base = &fd;
|
||||
iov.iov_len = sizeof(int);
|
||||
|
||||
cmp->cmsg_level = SOL_SOCKET;
|
||||
cmp->cmsg_type = SCM_RIGHTS;
|
||||
cmp->cmsg_len = CMSG_LEN(sizeof(int));
|
||||
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_name = NULL;
|
||||
msg.msg_namelen = 0;
|
||||
msg.msg_control = cmp;
|
||||
msg.msg_controllen = CMSG_SPACE(sizeof(int));
|
||||
|
||||
/*
|
||||
* ERROR HERE: trying to pass invalid fd
|
||||
* (This value was previously directly used to index the fd
|
||||
* array and therefore we are passing a hyperspace index)
|
||||
*/
|
||||
*(int *)CMSG_DATA(cmp) = 0x12345678;
|
||||
|
||||
rump_sys_sendmsg(s[0], &msg, 0);
|
||||
if (errno != EBADF)
|
||||
atf_tc_fail("descriptor passing failed: expected EBADF (9), "
|
||||
"got %d\n(%s)", errno, strerror(errno));
|
||||
}
|
||||
|
||||
|
||||
ATF_TC(cmsg_sendfd);
|
||||
ATF_TC_HEAD(cmsg_sendfd, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Checks that fd passing works");
|
||||
atf_tc_set_md_var(tc, "timeout", "2");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(cmsg_sendfd, tc)
|
||||
{
|
||||
char buf[128];
|
||||
struct cmsghdr *cmp;
|
||||
struct msghdr msg;
|
||||
struct sockaddr_un sun;
|
||||
struct lwp *l1, *l2;
|
||||
struct iovec iov;
|
||||
socklen_t sl;
|
||||
int s1, s2, sgot;
|
||||
int rfd, fd[2], storage;
|
||||
|
||||
rump_init();
|
||||
|
||||
RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
|
||||
l1 = rump_pub_lwproc_curlwp();
|
||||
|
||||
/* create unix socket and bind it to a path */
|
||||
memset(&sun, 0, sizeof(sun));
|
||||
sun.sun_family = AF_LOCAL;
|
||||
#define SOCKPATH "/com"
|
||||
strncpy(sun.sun_path, SOCKPATH, sizeof(SOCKPATH));
|
||||
s1 = rump_sys_socket(AF_LOCAL, SOCK_STREAM, 0);
|
||||
if (s1 == -1)
|
||||
atf_tc_fail_errno("socket 1");
|
||||
if (rump_sys_bind(s1, (struct sockaddr *)&sun, SUN_LEN(&sun)) == -1)
|
||||
atf_tc_fail_errno("socket 1 bind");
|
||||
if (rump_sys_listen(s1, 1) == -1)
|
||||
atf_tc_fail_errno("socket 1 listen");
|
||||
|
||||
/* create second process for test */
|
||||
RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
|
||||
l2 = rump_pub_lwproc_curlwp();
|
||||
|
||||
/* connect to unix domain socket */
|
||||
memset(&sun, 0, sizeof(sun));
|
||||
sun.sun_family = AF_LOCAL;
|
||||
strncpy(sun.sun_path, SOCKPATH, sizeof(SOCKPATH));
|
||||
s2 = rump_sys_socket(AF_LOCAL, SOCK_STREAM, 0);
|
||||
if (s2 == -1)
|
||||
atf_tc_fail_errno("socket 2");
|
||||
if (rump_sys_connect(s2, (struct sockaddr *)&sun, SUN_LEN(&sun)) == -1)
|
||||
atf_tc_fail_errno("socket 2 connect");
|
||||
|
||||
/* open a pipe and write stuff to it */
|
||||
if (rump_sys_pipe(fd) == -1)
|
||||
atf_tc_fail_errno("can't open pipe");
|
||||
#define MAGICSTRING "duam xnaht"
|
||||
if (rump_sys_write(fd[1], MAGICSTRING, sizeof(MAGICSTRING)) !=
|
||||
sizeof(MAGICSTRING))
|
||||
atf_tc_fail_errno("pipe write"); /* XXX: errno */
|
||||
|
||||
cmp = malloc(CMSG_SPACE(sizeof(int)));
|
||||
|
||||
iov.iov_base = &storage;
|
||||
iov.iov_len = sizeof(int);
|
||||
|
||||
cmp->cmsg_level = SOL_SOCKET;
|
||||
cmp->cmsg_type = SCM_RIGHTS;
|
||||
cmp->cmsg_len = CMSG_LEN(sizeof(int));
|
||||
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_name = NULL;
|
||||
msg.msg_namelen = 0;
|
||||
msg.msg_control = cmp;
|
||||
msg.msg_controllen = CMSG_SPACE(sizeof(int));
|
||||
*(int *)CMSG_DATA(cmp) = fd[0];
|
||||
|
||||
/* pass the fd */
|
||||
if (rump_sys_sendmsg(s2, &msg, 0) == -1)
|
||||
atf_tc_fail_errno("sendmsg failed");
|
||||
|
||||
/*
|
||||
* We will read to the same cmsg space. Overwrite the space
|
||||
* with an invalid fd to make sure we get an explicit error
|
||||
* if we don't manage to read the fd.
|
||||
*/
|
||||
*(int *)CMSG_DATA(cmp) = -1;
|
||||
|
||||
/* switch back to original proc */
|
||||
rump_pub_lwproc_switch(l1);
|
||||
|
||||
/* accept connection and read fd */
|
||||
sl = sizeof(sun);
|
||||
sgot = rump_sys_accept(s1, (struct sockaddr *)&sun, &sl);
|
||||
if (sgot == -1)
|
||||
atf_tc_fail_errno("accept");
|
||||
if (rump_sys_recvmsg(sgot, &msg, 0) == -1)
|
||||
atf_tc_fail_errno("recvmsg failed");
|
||||
rfd = *(int *)CMSG_DATA(cmp);
|
||||
|
||||
/* read from the fd */
|
||||
memset(buf, 0, sizeof(buf));
|
||||
if (rump_sys_read(rfd, buf, sizeof(buf)) == -1)
|
||||
atf_tc_fail_errno("read rfd");
|
||||
|
||||
/* check that we got the right stuff */
|
||||
if (strcmp(buf, MAGICSTRING) != 0)
|
||||
atf_tc_fail("expected \"%s\", got \"%s\"", MAGICSTRING, buf);
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
ATF_TP_ADD_TC(tp, cmsg_sendfd);
|
||||
ATF_TP_ADD_TC(tp, cmsg_sendfd_bounds);
|
||||
|
||||
return atf_no_error();
|
||||
}
|
||||
124
tests/include/sys/t_tree.c
Normal file
124
tests/include/sys/t_tree.c
Normal file
@@ -0,0 +1,124 @@
|
||||
/* $NetBSD: t_tree.c,v 1.1 2011/05/05 13:36:05 jruoho Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/tree.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct mist {
|
||||
RB_ENTRY(mist) rbentry;
|
||||
int key;
|
||||
};
|
||||
RB_HEAD(head, mist) tt;
|
||||
|
||||
static int
|
||||
mistcmp(struct mist *a, struct mist *b)
|
||||
{
|
||||
#if 0
|
||||
return (b->key - a->key); /* wrong, can overflow */
|
||||
#else
|
||||
if (b->key > a->key)
|
||||
return 1;
|
||||
else if (b->key < a->key)
|
||||
return (-1);
|
||||
else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
RB_PROTOTYPE(head, mist, rbentry, mistcmp)
|
||||
RB_GENERATE(head, mist, rbentry, mistcmp)
|
||||
|
||||
static struct mist *
|
||||
addmist(int key)
|
||||
{
|
||||
struct mist *m;
|
||||
|
||||
m = malloc(sizeof(struct mist));
|
||||
m->key = key;
|
||||
RB_INSERT(head, &tt, m);
|
||||
return m;
|
||||
}
|
||||
|
||||
static int
|
||||
findmist(struct mist *m)
|
||||
{
|
||||
|
||||
return (!!RB_FIND(head, &tt, m));
|
||||
}
|
||||
|
||||
#define N 1000
|
||||
static int
|
||||
test(void)
|
||||
{
|
||||
struct mist *m[N];
|
||||
int fail, i, j;
|
||||
|
||||
RB_INIT(&tt);
|
||||
fail = 0;
|
||||
for (i = 0; i < N; i++) {
|
||||
m[i] = addmist(random() << 1); /* use all 32 bits */
|
||||
for (j = 0; j <= i; j++)
|
||||
if (!findmist(m[j]))
|
||||
fail++;
|
||||
}
|
||||
return fail;
|
||||
}
|
||||
|
||||
ATF_TC(tree_rbstress);
|
||||
ATF_TC_HEAD(tree_rbstress, tc)
|
||||
{
|
||||
|
||||
atf_tc_set_md_var(tc, "descr", "rb-tree stress test");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(tree_rbstress, tc)
|
||||
{
|
||||
int i, fail, f;
|
||||
|
||||
srandom(4711);
|
||||
fail = 0;
|
||||
for (i = 0; i < 10; i++) {
|
||||
f = test();
|
||||
if (f) {
|
||||
atf_tc_fail_nonfatal("loop %d: %d errors\n", i, f);
|
||||
fail += f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
|
||||
ATF_TP_ADD_TC(tp, tree_rbstress);
|
||||
|
||||
return atf_no_error();
|
||||
}
|
||||
144
tests/include/sys/t_types.c
Normal file
144
tests/include/sys/t_types.c
Normal file
@@ -0,0 +1,144 @@
|
||||
/* $NetBSD: t_types.c,v 1.4 2012/03/18 07:14:08 jruoho Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2011 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.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: t_types.c,v 1.4 2012/03/18 07:14:08 jruoho Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
ATF_TC(types_limits);
|
||||
ATF_TC_HEAD(types_limits, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Known limits for types(3)");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(types_limits, tc)
|
||||
{
|
||||
useconds_t usec;
|
||||
ssize_t size;
|
||||
|
||||
/*
|
||||
* IEEE Std 1003.1-2008:
|
||||
*
|
||||
* "The type ssize_t shall be capable of storing
|
||||
* values at least in the range [-1, {SSIZE_MAX}]."
|
||||
*
|
||||
*/
|
||||
size = SSIZE_MAX;
|
||||
ATF_REQUIRE(size > 0);
|
||||
|
||||
size = size + 1;
|
||||
ATF_REQUIRE(size < 0);
|
||||
|
||||
/*
|
||||
* IEEE Std 1003.1-2008:
|
||||
*
|
||||
* "The type suseconds_t shall be a signed integer type capable
|
||||
* of storing values at least in the range [-1, 1000000]."
|
||||
*/
|
||||
usec = 1000000;
|
||||
ATF_REQUIRE(usec > 0);
|
||||
}
|
||||
|
||||
ATF_TC(types_signed);
|
||||
ATF_TC_HEAD(types_signed, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Signed types(3)"
|
||||
" (PR standards/44847)");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(types_signed, tc)
|
||||
{
|
||||
blkcnt_t bc;
|
||||
blksize_t bs;
|
||||
ssize_t size;
|
||||
off_t off;
|
||||
pid_t pid;
|
||||
|
||||
/*
|
||||
* As noted in types(3), the following
|
||||
* types should be signed integers.
|
||||
*/
|
||||
bc = 0;
|
||||
bs = 0;
|
||||
off = 0;
|
||||
pid = 0;
|
||||
size = 0;
|
||||
|
||||
ATF_CHECK((bc - 1) <= 0);
|
||||
ATF_CHECK((bs - 1) <= 0);
|
||||
ATF_CHECK((off - 1) <= 0);
|
||||
ATF_CHECK((pid - 1) <= 0);
|
||||
ATF_CHECK((size - 1) <= 0);
|
||||
}
|
||||
|
||||
ATF_TC(types_unsigned);
|
||||
ATF_TC_HEAD(types_unsigned, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Unsigned types(3)"
|
||||
" (PR standards/18067)");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(types_unsigned, tc)
|
||||
{
|
||||
fsblkcnt_t fb;
|
||||
fsfilcnt_t ff;
|
||||
size_t size;
|
||||
rlim_t lim;
|
||||
ino_t ino;
|
||||
|
||||
fb = 0;
|
||||
ff = 0;
|
||||
ino = 0;
|
||||
lim = 0;
|
||||
size = 0;
|
||||
|
||||
ATF_CHECK((fb - 1) > 0);
|
||||
ATF_CHECK((ff - 1) > 0);
|
||||
ATF_CHECK((ino - 1) > 0);
|
||||
ATF_CHECK((lim - 1) > 0);
|
||||
ATF_CHECK((size - 1) > 0);
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
|
||||
ATF_TP_ADD_TC(tp, types_limits);
|
||||
ATF_TP_ADD_TC(tp, types_signed);
|
||||
ATF_TP_ADD_TC(tp, types_unsigned);
|
||||
|
||||
return atf_no_error();
|
||||
}
|
||||
Reference in New Issue
Block a user