• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright (c) International Business Machines  Corp., 2002
4  *
5  * This program is free software;  you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13  * the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program;  if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /*
21  * http://www.opengroup.org/onlinepubs/009695399/functions/sysconf.html
22  *
23  * NAME :
24  * sysconf01 :  test for sysconf( get configurable system variables) sys call.
25  *
26  * USAGE :
27  *      sysconf01
28  */
29 
30 #define _GNU_SOURCE 1
31 #include <stdio.h>
32 #include <sys/types.h>
33 #include <errno.h>
34 #include <unistd.h>
35 
36 #define INVAL_FLAG	-1
37 
38 /** LTP Port **/
39 #include "test.h"
40 
41 char *TCID = "sysconf01";
42 int TST_TOTAL = 56;
43 
_test_sysconf(long name,const char * strname)44 static void _test_sysconf(long name, const char *strname)
45 {
46 	long retval;
47 
48 	/* make sure we reset this as sysconf() will not */
49 	errno = 0;
50 	retval = sysconf(name);
51 	if (retval == -1) {
52 
53 		/*
54 		 * The manpage for sysconf(2) specifically states that:
55 		 * 1. If -1 is returned and errno is EINVAL, then the resource
56 		 * name doesn't exist.
57 		 * 2. If errno remains 0, then the limit isn't implemented.
58 		 * 3. Else, something weird happened with the syscall.
59 		 */
60 		switch (errno) {
61 		case EINVAL:
62 			tst_resm(TCONF, "Resource doesn't exist: %s", strname);
63 			break;
64 		case 0:
65 			tst_resm(TCONF, "Not supported sysconf resource: %s",
66 				 strname);
67 			break;
68 		default:
69 			tst_resm(TFAIL | TERRNO, "Unexpected errno value for "
70 				 "%s", strname);
71 			break;
72 		}
73 	} else
74 		tst_resm(TPASS, "%s = %li", strname, retval);
75 
76 }
77 
78 #define test_sysconf(name) _test_sysconf(name, #name)
79 
main(void)80 int main(void)
81 {
82 	/* 1 - 5 */
83 	test_sysconf(_SC_CLK_TCK);
84 	test_sysconf(_SC_ARG_MAX);
85 	test_sysconf(_SC_CHILD_MAX);
86 	test_sysconf(_SC_OPEN_MAX);
87 	test_sysconf(_SC_JOB_CONTROL);
88 	/* 6 - 10 */
89 	test_sysconf(_SC_SAVED_IDS);
90 	test_sysconf(_SC_VERSION);
91 	test_sysconf(_SC_PASS_MAX);
92 	test_sysconf(_SC_LOGIN_NAME_MAX);
93 	test_sysconf(_SC_XOPEN_VERSION);
94 	/* 11 - 15 */
95 	test_sysconf(_SC_TZNAME_MAX);
96 	test_sysconf(_SC_STREAM_MAX);
97 	test_sysconf(_SC_XOPEN_CRYPT);
98 	test_sysconf(_SC_XOPEN_ENH_I18N);
99 	test_sysconf(_SC_XOPEN_SHM);
100 	/* 16 - 20 */
101 	test_sysconf(_SC_XOPEN_XCU_VERSION);
102 	test_sysconf(_SC_ATEXIT_MAX);
103 	test_sysconf(_SC_2_C_BIND);
104 	test_sysconf(_SC_2_C_DEV);
105 #ifdef _SC_2_C_VERSION
106 	test_sysconf(_SC_2_C_VERSION);
107 #else
108 	tst_resm(TCONF, "_SC_2_C_VERSION not defined");
109 #endif
110 	/* 21 - 25 */
111 	test_sysconf(_SC_2_CHAR_TERM);
112 	test_sysconf(_SC_2_FORT_DEV);
113 	test_sysconf(_SC_2_FORT_RUN);
114 	test_sysconf(_SC_2_LOCALEDEF);
115 	test_sysconf(_SC_2_SW_DEV);
116 	/* 26 - 30 */
117 	test_sysconf(_SC_2_UPE);
118 	test_sysconf(_SC_2_VERSION);
119 	test_sysconf(_SC_BC_BASE_MAX);
120 	test_sysconf(_SC_BC_DIM_MAX);
121 	test_sysconf(_SC_BC_SCALE_MAX);
122 	/* 31 - 35 */
123 	test_sysconf(_SC_BC_STRING_MAX);
124 	test_sysconf(_SC_COLL_WEIGHTS_MAX);
125 	test_sysconf(_SC_EXPR_NEST_MAX);
126 	test_sysconf(_SC_LINE_MAX);
127 	test_sysconf(_SC_RE_DUP_MAX);
128 	/* 36 - 40 */
129 	test_sysconf(_SC_XOPEN_UNIX);
130 	test_sysconf(_SC_PAGESIZE);
131 	test_sysconf(_SC_PHYS_PAGES);
132 	test_sysconf(_SC_AVPHYS_PAGES);
133 	test_sysconf(_SC_AIO_MAX);
134 	/* 41 - 45 */
135 	test_sysconf(_SC_AIO_PRIO_DELTA_MAX);
136 	test_sysconf(_SC_SEMAPHORES);
137 	test_sysconf(_SC_SEM_NSEMS_MAX);
138 	test_sysconf(_SC_SEM_VALUE_MAX);
139 	test_sysconf(_SC_MEMORY_PROTECTION);
140 	/* 46 - 50 */
141 	test_sysconf(_SC_FSYNC);
142 	test_sysconf(_SC_MEMORY_PROTECTION);
143 	test_sysconf(_SC_TIMERS);
144 	test_sysconf(_SC_TIMER_MAX);
145 	test_sysconf(_SC_MAPPED_FILES);
146 	/* 51 - 55 */
147 	test_sysconf(_SC_THREAD_PRIORITY_SCHEDULING);
148 	test_sysconf(_SC_XOPEN_LEGACY);
149 	test_sysconf(_SC_MEMLOCK);
150 	test_sysconf(_SC_XBS5_ILP32_OFF32);
151 	test_sysconf(_SC_XBS5_ILP32_OFFBIG);
152 
153 	/* 56 */
154 	{
155 		int retval, actual;
156 		errno = 0;
157 		retval = sysconf(INVAL_FLAG);
158 		actual = errno;
159 		if (retval != -1) {
160 			tst_resm(TFAIL,
161 				 "sysconf succeeded for invalid flag (%i), "
162 				 " retval=%d errno=%d: %s",
163 				 INVAL_FLAG, retval, actual, strerror(actual));
164 		} else if (actual != EINVAL) {
165 			tst_resm(TFAIL,
166 				 "sysconf correctly failed, but expected "
167 				 "errno (%i) != actual (%i)", EINVAL, actual);
168 		} else
169 			tst_resm(TPASS, "The invalid sysconf key was trapped "
170 				 "appropriately");
171 	}
172 
173 	tst_exit();
174 }
175