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 |
| 22 | * uname02.c |
| 23 | * |
| 24 | * DESCRIPTION |
| 25 | * uname02 - call uname() with an invalid address to produce a failure |
| 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 EFAULT - errno 14 |
| 32 | * otherwise, the tests fails |
| 33 | * issue a FAIL message |
| 34 | * break any remaining tests |
| 35 | * call cleanup |
| 36 | * |
| 37 | * USAGE: <for command-line> |
| 38 | * uname02 [-c n] [-e] [-i n] [-I x] [-p x] [-t] |
| 39 | * where, -c n : Run n copies concurrently. |
| 40 | * -e : Turn on errno logging. |
| 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" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 55 | |
| 56 | #include <errno.h> |
| 57 | #include <sys/utsname.h> |
| 58 | |
| 59 | void cleanup(void); |
| 60 | void setup(void); |
| 61 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 62 | char *TCID = "uname02"; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 63 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 64 | |
vapier | 6925ca3 | 2006-02-27 04:25:25 +0000 | [diff] [blame] | 65 | #if !defined(UCLINUX) |
| 66 | |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 67 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 68 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 69 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 70 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 71 | |
Garrett Cooper | 5eb15d5 | 2010-12-19 07:56:36 -0800 | [diff] [blame] | 72 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 73 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 74 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 75 | setup(); /* global setup */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 76 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 77 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 78 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 79 | |
| 80 | /* |
| 81 | * call the system call with the TEST() macro |
| 82 | * send -1 for an illegal address |
| 83 | */ |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 84 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 85 | TEST(uname((struct utsname *)-1)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 86 | |
Garrett Cooper | 5eb15d5 | 2010-12-19 07:56:36 -0800 | [diff] [blame] | 87 | if (TEST_RETURN == 0) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | tst_resm(TFAIL, "call succeed when failure expected"); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 89 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 90 | switch (TEST_ERRNO) { |
| 91 | case EFAULT: |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 92 | tst_resm(TPASS | TTERRNO, "uname failed as expected"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 93 | break; |
| 94 | default: |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 95 | tst_resm(TFAIL | TTERRNO, "uname failed unexpectedly"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
| 99 | cleanup(); |
| 100 | |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 101 | tst_exit(); |
robbiew | 9a66de1 | 2003-03-27 22:16:14 +0000 | [diff] [blame] | 102 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 103 | } |
| 104 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 105 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 106 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 107 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 108 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 109 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 110 | TEST_PAUSE; |
| 111 | } |
| 112 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 113 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 114 | { |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 115 | } |
Garrett Cooper | 5eb15d5 | 2010-12-19 07:56:36 -0800 | [diff] [blame] | 116 | #else |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 117 | int main(void) |
Garrett Cooper | 5eb15d5 | 2010-12-19 07:56:36 -0800 | [diff] [blame] | 118 | { |
| 119 | tst_resm(TCONF, NULL, "test is not available on uClinux"); |
| 120 | } |
| 121 | #endif /* if !defined(UCLINUX) */ |