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