robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 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 |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 16 | * along with this program; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* 11/20/2002 Port to LTP robbiew@us.ibm.com */ |
| 21 | /* 06/30/2001 Port to Linux nsharoff@us.ibm.com */ |
| 22 | |
| 23 | /* |
| 24 | * NAME |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 25 | * confstr1.c - test for confstr(3C) - Get configuration-defined string |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 26 | * values. |
| 27 | * |
| 28 | * CALLS |
| 29 | * confstr(3C) |
| 30 | * |
| 31 | * RESTRICTIONS |
| 32 | * MUST RUN AS ROOT |
| 33 | * |
| 34 | */ |
| 35 | |
Cyril Hrubis | 970c0e0 | 2013-11-28 17:09:11 +0100 | [diff] [blame] | 36 | #define _XOPEN_SOURCE 500 |
| 37 | |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 38 | #include <unistd.h> |
| 39 | #include <stdio.h> |
| 40 | #include <sys/types.h> |
| 41 | #include <errno.h> |
| 42 | |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 43 | #include "test.h" |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 44 | #include "safe_macros.h" |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 45 | |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 46 | static struct test_case_t { |
| 47 | int value; |
| 48 | char *name; |
| 49 | } test_cases[] = { |
| 50 | {_CS_PATH, "PATH"}, |
| 51 | {_CS_XBS5_ILP32_OFF32_CFLAGS, "XBS5_ILP32_OFF32_CFLAGS"}, |
| 52 | {_CS_XBS5_ILP32_OFF32_LDFLAGS, "XBS5_ILP32_OFF32_LDFLAGS"}, |
| 53 | {_CS_XBS5_ILP32_OFF32_LIBS, "XBS5_ILP32_OFF32_LIBS"}, |
| 54 | {_CS_XBS5_ILP32_OFF32_LINTFLAGS, "XBS5_ILP32_OFF32_LINTFLAGS"}, |
| 55 | {_CS_XBS5_ILP32_OFFBIG_CFLAGS, "XBS5_ILP32_OFFBIG_CFLAGS"}, |
| 56 | {_CS_XBS5_ILP32_OFFBIG_LDFLAGS, "XBS5_ILP32_OFFBIG_LDFLAGS"}, |
| 57 | {_CS_XBS5_ILP32_OFFBIG_LIBS, "XBS5_ILP32_OFFBIG_LIBS"}, |
| 58 | {_CS_XBS5_ILP32_OFFBIG_LINTFLAGS, "XBS5_ILP32_OFFBIG_LINTFLAGS"}, |
| 59 | {_CS_XBS5_LP64_OFF64_CFLAGS, "XBS5_LP64_OFF64_CFLAGS"}, |
| 60 | {_CS_XBS5_LP64_OFF64_LDFLAGS, "XBS5_LP64_OFF64_LDFLAGS"}, |
| 61 | {_CS_XBS5_LP64_OFF64_LIBS, "XBS5_LP64_OFF64_LIBS"}, |
| 62 | {_CS_XBS5_LP64_OFF64_LINTFLAGS, "XBS5_LP64_OFF64_LINTFLAGS"}, |
| 63 | {_CS_XBS5_LPBIG_OFFBIG_CFLAGS, "XBS5_LPBIG_OFFBIG_CFLAGS"}, |
| 64 | {_CS_XBS5_LPBIG_OFFBIG_LDFLAGS, "XBS5_LPBIG_OFFBIG_LDFLAGS"}, |
| 65 | {_CS_XBS5_LPBIG_OFFBIG_LIBS, "XBS5_LPBIG_OFFBIG_LIBS"}, |
| 66 | {_CS_XBS5_LPBIG_OFFBIG_LINTFLAGS, "XBS5_LPBIG_OFFBIG_LINTFLAGS"}, |
zenglg.jy | 470d545 | 2013-11-27 18:10:03 +0800 | [diff] [blame] | 67 | {_CS_GNU_LIBC_VERSION, "GNU_LIBC_VERSION"}, |
| 68 | {_CS_GNU_LIBPTHREAD_VERSION, "GNU_LIBPTHREAD_VERSION"}, |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 69 | }; |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 70 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 71 | char *TCID = "confstr01"; |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 72 | int TST_TOTAL = ARRAY_SIZE(test_cases); |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 73 | |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 74 | static void setup(void); |
| 75 | static void cleanup(void); |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 76 | |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 77 | int main(int argc, char *argv[]) |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 78 | { |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 79 | int lc; |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 80 | int i; |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 81 | char *buf; |
| 82 | int len; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 83 | const char *msg; |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 84 | |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 85 | msg = parse_opts(argc, argv, NULL, NULL); |
| 86 | if (msg != NULL) |
| 87 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 88 | |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 89 | setup(); |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 90 | |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 91 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 92 | |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 93 | tst_count = 0; |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 94 | |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 95 | for (i = 0; i < TST_TOTAL; i++) { |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 96 | |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 97 | TEST(confstr(test_cases[i].value, NULL, (size_t)0)); |
| 98 | |
| 99 | if (TEST_RETURN != 0) { |
| 100 | len = TEST_RETURN; |
| 101 | buf = SAFE_MALLOC(cleanup, len); |
| 102 | TEST(confstr(test_cases[i].value, buf, len)); |
| 103 | |
| 104 | if (TEST_RETURN != len || buf[len-1] != '\0') { |
| 105 | tst_brkm(TBROK, cleanup, |
| 106 | "confstr :%s failed", |
| 107 | test_cases[i].name); |
| 108 | } else { |
| 109 | tst_resm(TPASS, "confstr %s = '%s'", |
| 110 | test_cases[i].name, buf); |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 111 | } |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 112 | free(buf); |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 113 | } else { |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 114 | if (TEST_ERRNO == EINVAL) { |
| 115 | tst_resm(TCONF, |
| 116 | "confstr %s not supported", |
| 117 | test_cases[i].name); |
| 118 | } else { |
| 119 | tst_resm(TFAIL, |
| 120 | "confstr %s failed", |
| 121 | test_cases[i].name); |
| 122 | } |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | } |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 126 | |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 127 | cleanup(); |
| 128 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 129 | tst_exit(); |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 130 | } |
robbiew | f891d87 | 2002-12-04 18:05:07 +0000 | [diff] [blame] | 131 | |
zenglg.jy | b7c04bb | 2013-11-27 18:07:54 +0800 | [diff] [blame] | 132 | static void setup(void) |
| 133 | { |
| 134 | TEST_PAUSE; |
| 135 | } |
| 136 | |
| 137 | static void cleanup(void) |
| 138 | { |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 139 | } |