1*643acb6dSgson /* $NetBSD: t_sysctl.c,v 1.1 2014/08/09 07:04:03 gson Exp $ */
2*643acb6dSgson
3*643acb6dSgson /*-
4*643acb6dSgson * Copyright (c) 2014 The NetBSD Foundation, Inc.
5*643acb6dSgson * All rights reserved.
6*643acb6dSgson *
7*643acb6dSgson * Redistribution and use in source and binary forms, with or without
8*643acb6dSgson * modification, are permitted provided that the following conditions
9*643acb6dSgson * are met:
10*643acb6dSgson * 1. Redistributions of source code must retain the above copyright
11*643acb6dSgson * notice, this list of conditions and the following disclaimer.
12*643acb6dSgson * 2. Redistributions in binary form must reproduce the above copyright
13*643acb6dSgson * notice, this list of conditions and the following disclaimer in the
14*643acb6dSgson * documentation and/or other materials provided with the distribution.
15*643acb6dSgson *
16*643acb6dSgson * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17*643acb6dSgson * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18*643acb6dSgson * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19*643acb6dSgson * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20*643acb6dSgson * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21*643acb6dSgson * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22*643acb6dSgson * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23*643acb6dSgson * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24*643acb6dSgson * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25*643acb6dSgson * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26*643acb6dSgson * POSSIBILITY OF SUCH DAMAGE.
27*643acb6dSgson */
28*643acb6dSgson
29*643acb6dSgson #include <sys/cdefs.h>
30*643acb6dSgson __COPYRIGHT("@(#) Copyright (c) 2014\
31*643acb6dSgson The NetBSD Foundation, inc. All rights reserved.");
32*643acb6dSgson __RCSID("$NetBSD: t_sysctl.c,v 1.1 2014/08/09 07:04:03 gson Exp $");
33*643acb6dSgson
34*643acb6dSgson #include <sys/sysctl.h>
35*643acb6dSgson #include <errno.h>
36*643acb6dSgson #include <memory.h>
37*643acb6dSgson
38*643acb6dSgson #include <atf-c.h>
39*643acb6dSgson
40*643acb6dSgson ATF_TC(bufsize);
ATF_TC_HEAD(bufsize,tc)41*643acb6dSgson ATF_TC_HEAD(bufsize, tc)
42*643acb6dSgson {
43*643acb6dSgson atf_tc_set_md_var(tc, "descr",
44*643acb6dSgson "Test sysctl integer reads with different buffer sizes");
45*643acb6dSgson }
ATF_TC_BODY(bufsize,tc)46*643acb6dSgson ATF_TC_BODY(bufsize, tc)
47*643acb6dSgson {
48*643acb6dSgson union {
49*643acb6dSgson int int_val;
50*643acb6dSgson unsigned char space[256];
51*643acb6dSgson } buf;
52*643acb6dSgson size_t len;
53*643acb6dSgson for (len = 0; len < sizeof(buf); len++) {
54*643acb6dSgson size_t oldlen = len;
55*643acb6dSgson int r;
56*643acb6dSgson memset(&buf, 0xFF, sizeof(buf));
57*643acb6dSgson r = sysctlbyname("kern.job_control", &buf, &oldlen, 0, (size_t) 0);
58*643acb6dSgson if (len < sizeof(int)) {
59*643acb6dSgson ATF_REQUIRE_EQ(r, -1);
60*643acb6dSgson ATF_REQUIRE_EQ(errno, ENOMEM);
61*643acb6dSgson } else {
62*643acb6dSgson ATF_REQUIRE_EQ(r, 0);
63*643acb6dSgson ATF_REQUIRE_EQ(buf.int_val, 1);
64*643acb6dSgson ATF_REQUIRE_EQ(oldlen, sizeof(int));
65*643acb6dSgson }
66*643acb6dSgson }
67*643acb6dSgson }
68*643acb6dSgson
ATF_TP_ADD_TCS(tp)69*643acb6dSgson ATF_TP_ADD_TCS(tp)
70*643acb6dSgson {
71*643acb6dSgson ATF_TP_ADD_TC(tp, bufsize);
72*643acb6dSgson
73*643acb6dSgson return atf_no_error();
74*643acb6dSgson }
75