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 | |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 47 | #include "test.h" |
| 48 | #include "usctest.h" |
| 49 | #include "linux_syscall_numbers.h" |
| 50 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 51 | char *TCID = "newuname01"; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 52 | int testno; |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 53 | int TST_TOTAL = 1; |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 54 | |
| 55 | /* Extern Global Functions */ |
| 56 | /******************************************************************************/ |
| 57 | /* */ |
| 58 | /* Function: cleanup */ |
| 59 | /* */ |
| 60 | /* Description: Performs all one time clean up for this test on successful */ |
| 61 | /* completion, premature exit or failure. Closes all temporary */ |
| 62 | /* files, removes all temporary directories exits the test with */ |
| 63 | /* appropriate return code by calling tst_exit() function. */ |
| 64 | /* */ |
| 65 | /* Input: None. */ |
| 66 | /* */ |
| 67 | /* Output: None. */ |
| 68 | /* */ |
| 69 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
| 70 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 71 | /* */ |
| 72 | /******************************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 73 | void cleanup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 74 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 75 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 76 | TEST_CLEANUP; |
| 77 | tst_rmdir(); |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 78 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 79 | tst_exit(); |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /* Local Functions */ |
| 83 | /******************************************************************************/ |
| 84 | /* */ |
| 85 | /* Function: setup */ |
| 86 | /* */ |
| 87 | /* Description: Performs all one time setup for this test. This function is */ |
| 88 | /* typically used to capture signals, create temporary dirs */ |
| 89 | /* and temporary files that may be used in the course of this */ |
| 90 | /* test. */ |
| 91 | /* */ |
| 92 | /* Input: None. */ |
| 93 | /* */ |
| 94 | /* Output: None. */ |
| 95 | /* */ |
| 96 | /* Return: On failure - Exits by calling cleanup(). */ |
| 97 | /* On success - returns 0. */ |
| 98 | /* */ |
| 99 | /******************************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 100 | void setup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 101 | { |
| 102 | /* Capture signals if any */ |
| 103 | /* Create temporary directories */ |
| 104 | TEST_PAUSE; |
| 105 | tst_tmpdir(); |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 108 | int main(int ac, char **av) |
| 109 | { |
| 110 | struct utsname name; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 111 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 112 | const char *msg; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 113 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 114 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
| 115 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 116 | } |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 117 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 118 | setup(); |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 119 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 120 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 121 | tst_count = 0; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 122 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 123 | TEST(ltp_syscall(__NR_uname, &name)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 124 | if (TEST_RETURN == -1) { |
Cyril Hrubis | 9fa8ad0 | 2014-12-16 13:20:49 +0100 | [diff] [blame^] | 125 | tst_brkm(TFAIL, cleanup, "%s failed - errno = %d : %s", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 126 | TCID, TEST_ERRNO, |
| 127 | strerror(TEST_ERRNO)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 128 | } else { |
| 129 | tst_resm(TPASS, |
| 130 | "newuname call succeed: return value = %ld ", |
| 131 | TEST_RETURN); |
| 132 | TEST(strcmp(name.sysname, "Linux")); //Linux ? |
| 133 | if (TEST_RETURN == 0) { |
| 134 | tst_resm(TINFO, "This system is %s", |
| 135 | name.sysname); |
| 136 | tst_resm(TINFO, |
| 137 | "The system infomation is :"); |
| 138 | tst_resm(TINFO, |
| 139 | "System is %s on %s hardware", |
| 140 | name.sysname, name.machine); |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 141 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 142 | tst_resm(TINFO, "Nodename is %s", |
| 143 | name.nodename); |
| 144 | tst_resm(TINFO, "Version is %s, %s", |
| 145 | name.release, name.version); |
| 146 | tst_resm(TINFO, "Domainname is %s ", |
| 147 | *(&name.machine + 1)); |
| 148 | cleanup(); |
| 149 | tst_exit(); |
| 150 | } else { |
| 151 | tst_resm(TFAIL, |
| 152 | "%s failed - errno = %d : %s", |
| 153 | TCID, TEST_ERRNO, |
| 154 | strerror(TEST_ERRNO)); |
| 155 | tst_resm(TINFO, |
| 156 | "This system is not Linux"); |
| 157 | cleanup(); |
| 158 | tst_exit(); |
| 159 | } |
| 160 | |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 161 | } |
subrata_modak | 6e05831 | 2009-05-21 18:19:16 +0000 | [diff] [blame] | 162 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 163 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 164 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 165 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 166 | } |