blob: 8542e774278a9b208afec39c0d2334d3bbd6c979 [file] [log] [blame]
robbiewed1fe5e2002-12-04 19:06:19 +00001/*
2 *
subrata_modak56207ce2009-03-23 13:35:39 +00003 * Copyright (c) International Business Machines Corp., 2002
robbiewed1fe5e2002-12-04 19:06:19 +00004 *
subrata_modak56207ce2009-03-23 13:35:39 +00005 * 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.
robbiewed1fe5e2002-12-04 19:06:19 +00009 *
subrata_modak56207ce2009-03-23 13:35:39 +000010 * 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.
robbiewed1fe5e2002-12-04 19:06:19 +000014 *
subrata_modak56207ce2009-03-23 13:35:39 +000015 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
robbiewed1fe5e2002-12-04 19:06:19 +000018 */
19
robbiewed1fe5e2002-12-04 19:06:19 +000020/*
vapierf8699452007-03-13 19:16:51 +000021 * http://www.opengroup.org/onlinepubs/009695399/functions/sysconf.html
22 *
robbiewed1fe5e2002-12-04 19:06:19 +000023 * NAME :
24 * sysconf01 : test for sysconf( get configurable system variables) sys call.
25 *
26 * USAGE :
vapierf8699452007-03-13 19:16:51 +000027 * sysconf01
robbiewed1fe5e2002-12-04 19:06:19 +000028 */
29
robbiewed1fe5e2002-12-04 19:06:19 +000030#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"
robbiewed1fe5e2002-12-04 19:06:19 +000040
Cyril Hrubisac157c42011-07-22 16:47:18 +020041char *TCID = "sysconf01";
42int TST_TOTAL = 56;
robbiewed1fe5e2002-12-04 19:06:19 +000043
yaberauneya5208ecd2009-11-14 06:09:40 +000044static void _test_sysconf(long name, const char *strname)
vapierf8699452007-03-13 19:16:51 +000045{
46 long retval;
47
48 /* make sure we reset this as sysconf() will not */
49 errno = 0;
50 retval = sysconf(name);
yaberauneya5208ecd2009-11-14 06:09:40 +000051 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",
Wanlong Gao354ebb42012-12-07 10:10:04 +080066 strname);
yaberauneya5208ecd2009-11-14 06:09:40 +000067 break;
68 default:
69 tst_resm(TFAIL | TERRNO, "Unexpected errno value for "
Wanlong Gao354ebb42012-12-07 10:10:04 +080070 "%s", strname);
yaberauneya5208ecd2009-11-14 06:09:40 +000071 break;
72 }
73 } else
vapierf8699452007-03-13 19:16:51 +000074 tst_resm(TPASS, "%s = %li", strname, retval);
yaberauneya5208ecd2009-11-14 06:09:40 +000075
vapierf8699452007-03-13 19:16:51 +000076}
subrata_modak56207ce2009-03-23 13:35:39 +000077
vapierf8699452007-03-13 19:16:51 +000078#define test_sysconf(name) _test_sysconf(name, #name)
79
Cyril Hrubisac157c42011-07-22 16:47:18 +020080int main(void)
robbiewed1fe5e2002-12-04 19:06:19 +000081{
vapierf8699452007-03-13 19:16:51 +000082 /* 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);
robbiewed1fe5e2002-12-04 19:06:19 +0000148
vapierf8699452007-03-13 19:16:51 +0000149 /* 56 */
150 {
subrata_modakc9ef78b2009-03-17 08:42:30 +0000151 int retval, actual;
vapierf8699452007-03-13 19:16:51 +0000152 errno = 0;
153 retval = sysconf(INVAL_FLAG);
subrata_modakc9ef78b2009-03-17 08:42:30 +0000154 actual = errno;
yaberauneya5208ecd2009-11-14 06:09:40 +0000155 if (retval != -1) {
vapierf8699452007-03-13 19:16:51 +0000156 tst_resm(TFAIL,
yaberauneya5208ecd2009-11-14 06:09:40 +0000157 "sysconf succeeded for invalid flag (%i), "
158 " retval=%d errno=%d: %s",
subrata_modak56207ce2009-03-23 13:35:39 +0000159 INVAL_FLAG, retval, actual, strerror(actual));
yaberauneya5208ecd2009-11-14 06:09:40 +0000160 } else if (actual != EINVAL) {
vapierf8699452007-03-13 19:16:51 +0000161 tst_resm(TFAIL,
yaberauneya5208ecd2009-11-14 06:09:40 +0000162 "sysconf correctly failed, but expected "
163 "errno (%i) != actual (%i)", EINVAL, actual);
164 } else
165 tst_resm(TPASS, "The invalid sysconf key was trapped "
Wanlong Gao354ebb42012-12-07 10:10:04 +0800166 "appropriately");
vapierf8699452007-03-13 19:16:51 +0000167 }
robbiewed1fe5e2002-12-04 19:06:19 +0000168
vapierf8699452007-03-13 19:16:51 +0000169 tst_exit();
Cyril Hrubisac157c42011-07-22 16:47:18 +0200170}