plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) International Business Machines Corp., 2001 |
| 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame^] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * NAME |
robbiew | b480635 | 2002-02-27 18:09:56 +0000 | [diff] [blame] | 22 | * uname03.c |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 23 | * |
| 24 | * DESCRIPTION |
robbiew | b480635 | 2002-02-27 18:09:56 +0000 | [diff] [blame] | 25 | * uname03 - call uname() and make sure it succeeds |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 26 | * |
| 27 | * ALGORITHM |
| 28 | * loop if that option was specified |
| 29 | * issue the system call |
| 30 | * check the errno value |
| 31 | * issue a PASS message if we get zero |
| 32 | * otherwise, the tests fails |
| 33 | * issue a FAIL message |
| 34 | * break any remaining tests |
| 35 | * call cleanup |
| 36 | * |
| 37 | * USAGE: <for command-line> |
robbiew | b480635 | 2002-02-27 18:09:56 +0000 | [diff] [blame] | 38 | * uname03 [-c n] [-f] [-i n] [-I x] [-p x] [-t] |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 39 | * where, -c n : Run n copies concurrently. |
| 40 | * -f : Turn off functionality Testing. |
| 41 | * -i n : Execute test n times. |
| 42 | * -I x : Execute test for x seconds. |
| 43 | * -P x : Pause for x seconds between iterations. |
| 44 | * -t : Turn on syscall timing. |
| 45 | * |
| 46 | * History |
| 47 | * 07/2001 John George |
| 48 | * -Ported |
| 49 | * |
| 50 | * Restrictions |
| 51 | * none |
| 52 | */ |
| 53 | |
| 54 | #include "test.h" |
| 55 | #include "usctest.h" |
| 56 | |
| 57 | #include <errno.h> |
| 58 | #include <sys/utsname.h> |
| 59 | #include <string.h> |
| 60 | |
| 61 | void cleanup(void); |
| 62 | void setup(void); |
| 63 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 64 | char *TCID = "uname03"; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 65 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 66 | |
| 67 | #define LINUX "Linux" |
| 68 | |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 69 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 70 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 71 | int lc; /* loop counter */ |
| 72 | char *msg; /* message returned from parse_opts */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 73 | struct utsname *buf; |
| 74 | |
| 75 | /* parse standard options */ |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 76 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 77 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 78 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 79 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 80 | setup(); /* global setup */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 81 | |
| 82 | /* allocate some space for buf */ |
| 83 | |
| 84 | if ((buf = (struct utsname *)malloc((size_t) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 85 | sizeof(struct utsname))) == NULL) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 86 | tst_brkm(TBROK, cleanup, "malloc failed for buf"); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 87 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | |
| 89 | /* The following loop checks looping state if -i option given */ |
| 90 | |
| 91 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 92 | /* reset Tst_count in case we are looping */ |
| 93 | Tst_count = 0; |
| 94 | |
| 95 | /* Now make the system call with the TEST() macro */ |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 96 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 97 | TEST(uname(buf)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 98 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 99 | if (TEST_RETURN != 0) { |
| 100 | tst_resm(TFAIL, "%s failed - errno = %d - %s", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 101 | TCID, TEST_ERRNO, strerror(TEST_ERRNO)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 102 | } else { |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 103 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 104 | if (STD_FUNCTIONAL_TEST) { |
| 105 | if ((strcmp(buf->sysname, LINUX)) == 0) { |
| 106 | tst_resm(TPASS, "%s functionality test " |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 107 | "succeeded", TCID); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 108 | } else { |
| 109 | tst_resm(TFAIL, "%s functionality test " |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 110 | "failed", TCID); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 111 | } |
| 112 | } else { |
| 113 | tst_resm(TPASS, "%s call succeeded", TCID); |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | free(buf); |
| 119 | buf = NULL; |
| 120 | |
| 121 | cleanup(); |
| 122 | |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 123 | tst_exit(); |
robbiew | 9a66de1 | 2003-03-27 22:16:14 +0000 | [diff] [blame] | 124 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /* |
| 128 | * setup() - performs all the ONE TIME setup for this test. |
| 129 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 130 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 131 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 132 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 133 | tst_sig(FORK, DEF_HANDLER, cleanup); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 134 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 135 | TEST_PAUSE; |
| 136 | } |
| 137 | |
| 138 | /* |
| 139 | * cleanup() - performs all the ONE TIME cleanup for this test at completion |
| 140 | * or premature exit. |
| 141 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 142 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 143 | { |
| 144 | /* |
| 145 | * print timing stats if that option was specified. |
| 146 | * print errno log if that option was specified. |
| 147 | */ |
| 148 | TEST_CLEANUP; |
| 149 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 150 | } |