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
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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"
55
56 #include <errno.h>
57 #include <sys/utsname.h>
58
59 void cleanup(void);
60 void setup(void);
61
62 char *TCID = "uname02";
63 int TST_TOTAL = 1;
64
65 #if !defined(UCLINUX)
66
main(int ac,char ** av)67 int main(int ac, char **av)
68 {
69 int lc;
70
71 tst_parse_opts(ac, av, NULL, NULL);
72
73 setup(); /* global setup */
74
75 for (lc = 0; TEST_LOOPING(lc); lc++) {
76 tst_count = 0;
77
78 /*
79 * call the system call with the TEST() macro
80 * send -1 for an illegal address
81 */
82
83 TEST(uname((struct utsname *)-1));
84
85 if (TEST_RETURN == 0)
86 tst_resm(TFAIL, "call succeed when failure expected");
87
88 switch (TEST_ERRNO) {
89 case EFAULT:
90 tst_resm(TPASS | TTERRNO, "uname failed as expected");
91 break;
92 default:
93 tst_resm(TFAIL | TTERRNO, "uname failed unexpectedly");
94 }
95 }
96
97 cleanup();
98
99 tst_exit();
100
101 }
102
setup(void)103 void setup(void)
104 {
105
106 tst_sig(FORK, DEF_HANDLER, cleanup);
107
108 TEST_PAUSE;
109 }
110
cleanup(void)111 void cleanup(void)
112 {
113 }
114 #else
main(void)115 int main(void)
116 {
117 tst_resm(TCONF, NULL, "test is not available on uClinux");
118 }
119 #endif /* if !defined(UCLINUX) */
120