blob: e6e59e3b9e4e4a6cf22edb37f9836b33652e7c17 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
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 Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
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"
plars865695b2001-08-27 22:15:12 +000055
56#include <errno.h>
57#include <sys/utsname.h>
58
59void cleanup(void);
60void setup(void);
61
subrata_modak56207ce2009-03-23 13:35:39 +000062char *TCID = "uname02";
plars865695b2001-08-27 22:15:12 +000063int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000064
vapier6925ca32006-02-27 04:25:25 +000065#if !defined(UCLINUX)
66
plars74948ad2002-11-14 16:16:14 +000067int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000068{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020069 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020070 const char *msg;
plars865695b2001-08-27 22:15:12 +000071
Garrett Cooper5eb15d52010-12-19 07:56:36 -080072 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080073 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000074
subrata_modak56207ce2009-03-23 13:35:39 +000075 setup(); /* global setup */
plars865695b2001-08-27 22:15:12 +000076
plars865695b2001-08-27 22:15:12 +000077 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080078 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000079
80 /*
81 * call the system call with the TEST() macro
82 * send -1 for an illegal address
83 */
subrata_modakbdbaec52009-02-26 12:14:51 +000084
plars865695b2001-08-27 22:15:12 +000085 TEST(uname((struct utsname *)-1));
subrata_modakbdbaec52009-02-26 12:14:51 +000086
Garrett Cooper5eb15d52010-12-19 07:56:36 -080087 if (TEST_RETURN == 0)
plars865695b2001-08-27 22:15:12 +000088 tst_resm(TFAIL, "call succeed when failure expected");
subrata_modakbdbaec52009-02-26 12:14:51 +000089
plars865695b2001-08-27 22:15:12 +000090 switch (TEST_ERRNO) {
91 case EFAULT:
Wanlong Gao354ebb42012-12-07 10:10:04 +080092 tst_resm(TPASS | TTERRNO, "uname failed as expected");
plars865695b2001-08-27 22:15:12 +000093 break;
94 default:
Wanlong Gao354ebb42012-12-07 10:10:04 +080095 tst_resm(TFAIL | TTERRNO, "uname failed unexpectedly");
plars865695b2001-08-27 22:15:12 +000096 }
97 }
98
99 cleanup();
100
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800101 tst_exit();
robbiew9a66de12003-03-27 22:16:14 +0000102
plars865695b2001-08-27 22:15:12 +0000103}
104
subrata_modak56207ce2009-03-23 13:35:39 +0000105void setup(void)
plars865695b2001-08-27 22:15:12 +0000106{
Garrett Cooper2c282152010-12-16 00:55:50 -0800107
plars865695b2001-08-27 22:15:12 +0000108 tst_sig(FORK, DEF_HANDLER, cleanup);
109
plars865695b2001-08-27 22:15:12 +0000110 TEST_PAUSE;
111}
112
subrata_modak56207ce2009-03-23 13:35:39 +0000113void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000114{
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800115}
Garrett Cooper5eb15d52010-12-19 07:56:36 -0800116#else
Mike Frysingerc57fba52014-04-09 18:56:30 -0400117int main(void)
Garrett Cooper5eb15d52010-12-19 07:56:36 -0800118{
119 tst_resm(TCONF, NULL, "test is not available on uClinux");
120}
121#endif /* if !defined(UCLINUX) */