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