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 test_sysconf(_SC_2_C_VERSION);
106 /* 21 - 25 */
107 test_sysconf(_SC_2_CHAR_TERM);
108 test_sysconf(_SC_2_FORT_DEV);
109 test_sysconf(_SC_2_FORT_RUN);
110 test_sysconf(_SC_2_LOCALEDEF);
111 test_sysconf(_SC_2_SW_DEV);
112 /* 26 - 30 */
113 test_sysconf(_SC_2_UPE);
114 test_sysconf(_SC_2_VERSION);
115 test_sysconf(_SC_BC_BASE_MAX);
116 test_sysconf(_SC_BC_DIM_MAX);
117 test_sysconf(_SC_BC_SCALE_MAX);
118 /* 31 - 35 */
119 test_sysconf(_SC_BC_STRING_MAX);
120 test_sysconf(_SC_COLL_WEIGHTS_MAX);
121 test_sysconf(_SC_EXPR_NEST_MAX);
122 test_sysconf(_SC_LINE_MAX);
123 test_sysconf(_SC_RE_DUP_MAX);
124 /* 36 - 40 */
125 test_sysconf(_SC_XOPEN_UNIX);
126 test_sysconf(_SC_PAGESIZE);
127 test_sysconf(_SC_PHYS_PAGES);
128 test_sysconf(_SC_AVPHYS_PAGES);
129 test_sysconf(_SC_AIO_MAX);
130 /* 41 - 45 */
131 test_sysconf(_SC_AIO_PRIO_DELTA_MAX);
132 test_sysconf(_SC_SEMAPHORES);
133 test_sysconf(_SC_SEM_NSEMS_MAX);
134 test_sysconf(_SC_SEM_VALUE_MAX);
135 test_sysconf(_SC_MEMORY_PROTECTION);
136 /* 46 - 50 */
137 test_sysconf(_SC_FSYNC);
138 test_sysconf(_SC_MEMORY_PROTECTION);
139 test_sysconf(_SC_TIMERS);
140 test_sysconf(_SC_TIMER_MAX);
141 test_sysconf(_SC_MAPPED_FILES);
142 /* 51 - 55 */
143 test_sysconf(_SC_THREAD_PRIORITY_SCHEDULING);
144 test_sysconf(_SC_XOPEN_LEGACY);
145 test_sysconf(_SC_MEMLOCK);
146 test_sysconf(_SC_XBS5_ILP32_OFF32);
147 test_sysconf(_SC_XBS5_ILP32_OFFBIG);
148
149 /* 56 */
150 {
151 int retval, actual;
152 errno = 0;
153 retval = sysconf(INVAL_FLAG);
154 actual = errno;
155 if (retval != -1) {
156 tst_resm(TFAIL,
157 "sysconf succeeded for invalid flag (%i), "
158 " retval=%d errno=%d: %s",
159 INVAL_FLAG, retval, actual, strerror(actual));
160 } else if (actual != EINVAL) {
161 tst_resm(TFAIL,
162 "sysconf correctly failed, but expected "
163 "errno (%i) != actual (%i)", EINVAL, actual);
164 } else
165 tst_resm(TPASS, "The invalid sysconf key was trapped "
166 "appropriately");
167 }
168
169 tst_exit();
170 }
171