|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
1 | 2 | /* |
2 | 3 | * |
3 | | - * Copyright (c) International Business Machines Corp., 2001 |
| 4 | + * Copyright (c) International Business Machines Corp., 2001 |
4 | 5 | * |
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. |
| 6 | + * Basic test for uname(): |
| 7 | + * Calling uname() with invalid buf got EFAULT. |
9 | 8 | * |
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 | 9 | */ |
19 | 10 |
|
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 | 11 | #include <errno.h> |
57 | 12 | #include <sys/utsname.h> |
| 13 | +#include "tst_test.h" |
58 | 14 |
|
59 | | -void cleanup(void); |
60 | | -void setup(void); |
| 15 | +static void *bad_addr; |
61 | 16 |
|
62 | | -char *TCID = "uname02"; |
63 | | -int TST_TOTAL = 1; |
64 | | - |
65 | | -#if !defined(UCLINUX) |
66 | | - |
67 | | -int main(int ac, char **av) |
| 17 | +static void verify_uname(void) |
68 | 18 | { |
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 | | - } |
| 19 | + TEST(uname(bad_addr)); |
| 20 | + if (TST_RET == 0) { |
| 21 | + tst_res(TFAIL, "uname() succeed when failure expected"); |
| 22 | + return; |
95 | 23 | } |
96 | 24 |
|
97 | | - cleanup(); |
| 25 | + if (TST_RET != -1) { |
| 26 | + tst_res(TFAIL, "Invalid uname() return value %ld", TST_RET); |
| 27 | + return; |
| 28 | + } |
98 | 29 |
|
99 | | - tst_exit(); |
| 30 | + if (TST_ERR == EFAULT) |
| 31 | + tst_res(TPASS, "uname() got EFAULT as expected"); |
| 32 | + else |
| 33 | + tst_res(TFAIL | TTERRNO, "uname() failed unexpectedly"); |
100 | 34 |
|
101 | 35 | } |
102 | 36 |
|
103 | | -void setup(void) |
| 37 | +static void setup(void) |
104 | 38 | { |
105 | | - |
106 | | - tst_sig(FORK, DEF_HANDLER, cleanup); |
107 | | - |
108 | | - TEST_PAUSE; |
| 39 | + bad_addr = tst_get_bad_addr(NULL); |
109 | 40 | } |
110 | 41 |
|
111 | | -void cleanup(void) |
112 | | -{ |
113 | | -} |
114 | | -#else |
115 | | -int main(void) |
116 | | -{ |
117 | | - tst_resm(TCONF, NULL, "test is not available on uClinux"); |
118 | | -} |
119 | | -#endif /* if !defined(UCLINUX) */ |
| 42 | +static struct tst_test test = { |
| 43 | + .test_all = verify_uname, |
| 44 | + .setup = setup, |
| 45 | +}; |
0 commit comments