subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
| 2 | /* Copyright (c) Crackerjack Project., 2007 */ |
| 3 | /* */ |
| 4 | /* This program is free software; you can redistribute it and/or modify */ |
| 5 | /* it under the terms of the GNU General Public License as published by */ |
| 6 | /* the Free Software Foundation; either version 2 of the License, or */ |
| 7 | /* (at your option) any later version. */ |
| 8 | /* */ |
| 9 | /* This program is distributed in the hope that it will be useful, */ |
| 10 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 11 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ |
| 12 | /* the GNU General Public License for more details. */ |
| 13 | /* */ |
| 14 | /* You should have received a copy of the GNU General Public License */ |
| 15 | /* along with this program; if not, write to the Free Software */ |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 16 | /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 17 | /* */ |
| 18 | /******************************************************************************/ |
| 19 | /******************************************************************************/ |
| 20 | /* */ |
| 21 | /* File: newuname01.c */ |
| 22 | /* */ |
| 23 | /* Description: This tests the newuname() syscall */ |
| 24 | /* */ |
| 25 | /* Usage: <for command-line> */ |
| 26 | /* newuname01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */ |
| 27 | /* where, -c n : Run n copies concurrently. */ |
| 28 | /* -e : Turn on errno logging. */ |
| 29 | /* -i n : Execute test n times. */ |
| 30 | /* -I x : Execute test for x seconds. */ |
| 31 | /* -P x : Pause for x seconds between iterations. */ |
| 32 | /* -t : Turn on syscall timing. */ |
| 33 | /* */ |
| 34 | /* Total Tests: 1 */ |
| 35 | /* */ |
| 36 | /* Test Name: newuname01 */ |
| 37 | /* History: Porting from Crackerjack to LTP is done by */ |
| 38 | /* Manas Kumar Nayak maknayak@in.ibm.com> */ |
| 39 | /******************************************************************************/ |
| 40 | #include <unistd.h> |
| 41 | #include <sys/utsname.h> |
| 42 | #include <errno.h> |
| 43 | #include <stdio.h> |
| 44 | #include <sys/stat.h> |
| 45 | #include <stdlib.h> |
| 46 | |
| 47 | /* Harness Specific Include Files. */ |
| 48 | #include "test.h" |
| 49 | #include "usctest.h" |
| 50 | #include "linux_syscall_numbers.h" |
| 51 | |
| 52 | /* Extern Global Variables */ |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 53 | |
| 54 | /* Global Variables */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 55 | char *TCID = "newuname01"; /* Test program identifier. */ |
| 56 | int testno; |
| 57 | int TST_TOTAL = 1; /* total number of tests in this file. */ |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 58 | |
| 59 | /* Extern Global Functions */ |
| 60 | /******************************************************************************/ |
| 61 | /* */ |
| 62 | /* Function: cleanup */ |
| 63 | /* */ |
| 64 | /* Description: Performs all one time clean up for this test on successful */ |
| 65 | /* completion, premature exit or failure. Closes all temporary */ |
| 66 | /* files, removes all temporary directories exits the test with */ |
| 67 | /* appropriate return code by calling tst_exit() function. */ |
| 68 | /* */ |
| 69 | /* Input: None. */ |
| 70 | /* */ |
| 71 | /* Output: None. */ |
| 72 | /* */ |
| 73 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
| 74 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 75 | /* */ |
| 76 | /******************************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 77 | extern void cleanup() |
| 78 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 79 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 80 | TEST_CLEANUP; |
| 81 | tst_rmdir(); |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 82 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 83 | tst_exit(); |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /* Local Functions */ |
| 87 | /******************************************************************************/ |
| 88 | /* */ |
| 89 | /* Function: setup */ |
| 90 | /* */ |
| 91 | /* Description: Performs all one time setup for this test. This function is */ |
| 92 | /* typically used to capture signals, create temporary dirs */ |
| 93 | /* and temporary files that may be used in the course of this */ |
| 94 | /* test. */ |
| 95 | /* */ |
| 96 | /* Input: None. */ |
| 97 | /* */ |
| 98 | /* Output: None. */ |
| 99 | /* */ |
| 100 | /* Return: On failure - Exits by calling cleanup(). */ |
| 101 | /* On success - returns 0. */ |
| 102 | /* */ |
| 103 | /******************************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 104 | void setup() |
| 105 | { |
| 106 | /* Capture signals if any */ |
| 107 | /* Create temporary directories */ |
| 108 | TEST_PAUSE; |
| 109 | tst_tmpdir(); |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 112 | int main(int ac, char **av) |
| 113 | { |
| 114 | struct utsname name; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 115 | int lc; |
| 116 | char *msg; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 117 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 118 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
| 119 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
| 120 | tst_exit(); |
| 121 | } |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 122 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 123 | setup(); |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 124 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 125 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
| 126 | Tst_count = 0; |
| 127 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 128 | TEST(ltp_syscall(__NR_uname, &name)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 129 | if (TEST_RETURN == -1) { |
| 130 | tst_resm(TFAIL, "%s failed - errno = %d : %s", |
| 131 | TCID, TEST_ERRNO, |
| 132 | strerror(TEST_ERRNO)); |
| 133 | cleanup(); |
| 134 | tst_exit(); |
| 135 | } else { |
| 136 | tst_resm(TPASS, |
| 137 | "newuname call succeed: return value = %ld ", |
| 138 | TEST_RETURN); |
| 139 | TEST(strcmp(name.sysname, "Linux")); //Linux ? |
| 140 | if (TEST_RETURN == 0) { |
| 141 | tst_resm(TINFO, "This system is %s", |
| 142 | name.sysname); |
| 143 | tst_resm(TINFO, |
| 144 | "The system infomation is :"); |
| 145 | tst_resm(TINFO, |
| 146 | "System is %s on %s hardware", |
| 147 | name.sysname, name.machine); |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 148 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 149 | tst_resm(TINFO, "Nodename is %s", |
| 150 | name.nodename); |
| 151 | tst_resm(TINFO, "Version is %s, %s", |
| 152 | name.release, name.version); |
| 153 | tst_resm(TINFO, "Domainname is %s ", |
| 154 | *(&name.machine + 1)); |
| 155 | cleanup(); |
| 156 | tst_exit(); |
| 157 | } else { |
| 158 | tst_resm(TFAIL, |
| 159 | "%s failed - errno = %d : %s", |
| 160 | TCID, TEST_ERRNO, |
| 161 | strerror(TEST_ERRNO)); |
| 162 | tst_resm(TINFO, |
| 163 | "This system is not Linux"); |
| 164 | cleanup(); |
| 165 | tst_exit(); |
| 166 | } |
| 167 | |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 168 | } |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 169 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 170 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 171 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 172 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 173 | } |