1e1f2d32ngie/*	$NetBSD: t_types.c,v 1.4 2012/03/18 07:14:08 jruoho Exp $ */
2e1f2d32ngie
3e1f2d32ngie/*-
4e1f2d32ngie * Copyright (c) 2011 The NetBSD Foundation, Inc.
5e1f2d32ngie * All rights reserved.
6e1f2d32ngie *
7e1f2d32ngie * This code is derived from software contributed to The NetBSD Foundation
8e1f2d32ngie * by Jukka Ruohonen.
9e1f2d32ngie *
10e1f2d32ngie * Redistribution and use in source and binary forms, with or without
11e1f2d32ngie * modification, are permitted provided that the following conditions
12e1f2d32ngie * are met:
13e1f2d32ngie * 1. Redistributions of source code must retain the above copyright
14e1f2d32ngie *    notice, this list of conditions and the following disclaimer.
15e1f2d32ngie * 2. Redistributions in binary form must reproduce the above copyright
16e1f2d32ngie *    notice, this list of conditions and the following disclaimer in the
17e1f2d32ngie *    documentation and/or other materials provided with the distribution.
18e1f2d32ngie *
19e1f2d32ngie * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20e1f2d32ngie * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21e1f2d32ngie * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22e1f2d32ngie * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23e1f2d32ngie * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24e1f2d32ngie * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25e1f2d32ngie * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26e1f2d32ngie * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27e1f2d32ngie * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28e1f2d32ngie * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29e1f2d32ngie * POSSIBILITY OF SUCH DAMAGE.
30e1f2d32ngie */
31e1f2d32ngie#include <sys/cdefs.h>
32e1f2d32ngie__RCSID("$NetBSD: t_types.c,v 1.4 2012/03/18 07:14:08 jruoho Exp $");
33e1f2d32ngie
34e1f2d32ngie#include <sys/types.h>
35e1f2d32ngie
36e1f2d32ngie#include <atf-c.h>
37e1f2d32ngie#include <limits.h>
38e1f2d32ngie#include <stdint.h>
39e1f2d32ngie
40e1f2d32ngie#include <stdio.h>
41e1f2d32ngie
42e1f2d32ngieATF_TC(types_limits);
43e1f2d32ngieATF_TC_HEAD(types_limits, tc)
44e1f2d32ngie{
45e1f2d32ngie	atf_tc_set_md_var(tc, "descr", "Known limits for types(3)");
46e1f2d32ngie}
47e1f2d32ngie
48e1f2d32ngieATF_TC_BODY(types_limits, tc)
49e1f2d32ngie{
50e1f2d32ngie	useconds_t usec;
51e1f2d32ngie	ssize_t size;
52e1f2d32ngie
53e1f2d32ngie	/*
54e1f2d32ngie	 * IEEE Std 1003.1-2008:
55e1f2d32ngie	 *
56e1f2d32ngie	 * "The type ssize_t shall be capable of storing
57e1f2d32ngie	 *  values at least in the range [-1, {SSIZE_MAX}]."
58e1f2d32ngie	 *
59e1f2d32ngie	 */
60e1f2d32ngie	size = SSIZE_MAX;
61e1f2d32ngie	ATF_REQUIRE(size > 0);
62e1f2d32ngie
63e1f2d32ngie	size = size + 1;
64e1f2d32ngie	ATF_REQUIRE(size < 0);
65e1f2d32ngie
66e1f2d32ngie	/*
67e1f2d32ngie	 * IEEE Std 1003.1-2008:
68e1f2d32ngie	 *
69e1f2d32ngie	 * "The type suseconds_t shall be a signed integer type capable
70e1f2d32ngie	 *  of storing values at least in the range [-1, 1000000]."
71e1f2d32ngie	 */
72e1f2d32ngie	usec = 1000000;
73e1f2d32ngie	ATF_REQUIRE(usec > 0);
74e1f2d32ngie}
75e1f2d32ngie
76e1f2d32ngieATF_TC(types_signed);
77e1f2d32ngieATF_TC_HEAD(types_signed, tc)
78e1f2d32ngie{
79e1f2d32ngie	atf_tc_set_md_var(tc, "descr", "Signed types(3)"
80e1f2d32ngie	    " (PR standards/44847)");
81e1f2d32ngie}
82e1f2d32ngie
83e1f2d32ngieATF_TC_BODY(types_signed, tc)
84e1f2d32ngie{
85e1f2d32ngie	blkcnt_t bc;
86e1f2d32ngie	blksize_t bs;
87e1f2d32ngie	ssize_t size;
88e1f2d32ngie	off_t off;
89e1f2d32ngie	pid_t pid;
90e1f2d32ngie
91e1f2d32ngie	/*
92e1f2d32ngie	 * As noted in types(3), the following
93e1f2d32ngie	 * types should be signed integers.
94e1f2d32ngie	 */
95e1f2d32ngie	bc = 0;
96e1f2d32ngie	bs = 0;
97e1f2d32ngie	off = 0;
98e1f2d32ngie	pid = 0;
99e1f2d32ngie	size = 0;
100e1f2d32ngie
101e1f2d32ngie	ATF_CHECK((bc - 1) <= 0);
102e1f2d32ngie	ATF_CHECK((bs - 1) <= 0);
103e1f2d32ngie	ATF_CHECK((off - 1) <= 0);
104e1f2d32ngie	ATF_CHECK((pid - 1) <= 0);
105e1f2d32ngie	ATF_CHECK((size - 1) <= 0);
106e1f2d32ngie}
107e1f2d32ngie
108e1f2d32ngieATF_TC(types_unsigned);
109e1f2d32ngieATF_TC_HEAD(types_unsigned, tc)
110e1f2d32ngie{
111e1f2d32ngie	atf_tc_set_md_var(tc, "descr", "Unsigned types(3)"
112e1f2d32ngie		" (PR standards/18067)");
113e1f2d32ngie}
114e1f2d32ngie
115e1f2d32ngieATF_TC_BODY(types_unsigned, tc)
116e1f2d32ngie{
117e1f2d32ngie	fsblkcnt_t fb;
118e1f2d32ngie	fsfilcnt_t ff;
119e1f2d32ngie	size_t size;
120e1f2d32ngie	rlim_t lim;
121e1f2d32ngie	ino_t ino;
122e1f2d32ngie
123e1f2d32ngie	fb = 0;
124e1f2d32ngie	ff = 0;
125e1f2d32ngie	ino = 0;
126e1f2d32ngie	lim = 0;
127e1f2d32ngie	size = 0;
128e1f2d32ngie
129e1f2d32ngie	ATF_CHECK((fb - 1) > 0);
130e1f2d32ngie	ATF_CHECK((ff - 1) > 0);
131e1f2d32ngie	ATF_CHECK((ino - 1) > 0);
132e1f2d32ngie	ATF_CHECK((lim - 1) > 0);
133e1f2d32ngie	ATF_CHECK((size - 1) > 0);
134e1f2d32ngie}
135e1f2d32ngie
136e1f2d32ngieATF_TP_ADD_TCS(tp)
137e1f2d32ngie{
138e1f2d32ngie
139e1f2d32ngie	ATF_TP_ADD_TC(tp, types_limits);
140e1f2d32ngie	ATF_TP_ADD_TC(tp, types_signed);
141e1f2d32ngie	ATF_TP_ADD_TC(tp, types_unsigned);
142e1f2d32ngie
143e1f2d32ngie	return atf_no_error();
144e1f2d32ngie}
145