Skip to content

Commit a07a83b

Browse files
yangx-jymetan-ucw
authored andcommitted
syscalls/uname02: Convert to new API and cleanup
Signed-off-by: Xiao Yang <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]>
1 parent e5c1aff commit a07a83b

File tree

1 file changed

+25
-99
lines changed

1 file changed

+25
-99
lines changed
Lines changed: 25 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,45 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
12
/*
23
*
3-
* Copyright (c) International Business Machines Corp., 2001
4+
* Copyright (c) International Business Machines Corp., 2001
45
*
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.
98
*
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
189
*/
1910

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-
5611
#include <errno.h>
5712
#include <sys/utsname.h>
13+
#include "tst_test.h"
5814

59-
void cleanup(void);
60-
void setup(void);
15+
static void *bad_addr;
6116

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)
6818
{
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;
9523
}
9624

97-
cleanup();
25+
if (TST_RET != -1) {
26+
tst_res(TFAIL, "Invalid uname() return value %ld", TST_RET);
27+
return;
28+
}
9829

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");
10034

10135
}
10236

103-
void setup(void)
37+
static void setup(void)
10438
{
105-
106-
tst_sig(FORK, DEF_HANDLER, cleanup);
107-
108-
TEST_PAUSE;
39+
bad_addr = tst_get_bad_addr(NULL);
10940
}
11041

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

Comments
 (0)