Skip to content

Commit 50cbff1

Browse files
committed
syscalls/munlock01: Convert into new api
Reviewed-by: Li Wang <liwang@redhat.com> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
1 parent f201308 commit 50cbff1

File tree

1 file changed

+35
-146
lines changed

1 file changed

+35
-146
lines changed
Lines changed: 35 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,162 +1,51 @@
1+
// SPDX-License-Identifier: GPL-2.0
12
/*
23
* Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
3-
*
4-
* This program is free software; you can redistribute it and/or modify it
5-
* under the terms of version 2 of the GNU General Public License as
6-
* published by the Free Software Foundation.
7-
*
8-
* This program is distributed in the hope that it would be useful, but
9-
* WITHOUT ANY WARRANTY; without even the implied warranty of
10-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11-
*
12-
* You should have received a copy of the GNU General Public License along
13-
* with this program; if not, write the Free Software Foundation, Inc.,
14-
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15-
*
4+
* AUTHOR: Nirmala Devi Dhanasekar <nirmala.devi@wipro.com>
165
*/
17-
/**************************************************************************
18-
*
19-
* TEST IDENTIFIER : munlock01
20-
*
21-
* EXECUTED BY : root / superuser
22-
*
23-
* TEST TITLE : Basic test for munlock(2)
24-
*
25-
* TEST CASE TOTAL : 4
26-
*
27-
* AUTHOR : Nirmala Devi Dhanasekar <nirmala.devi@wipro.com>
28-
*
29-
* SIGNALS
30-
* Uses SIGUSR1 to pause before test if option set.
31-
* (See the parse_opts(3) man page).
32-
*
33-
* DESCRIPTION
34-
* This is a Phase I test for the munlock(2) system call.
35-
* It is intended to provide a limited exposure of the system call.
36-
*
37-
* Setup:
38-
* Setup signal handling.
39-
* Pause for SIGUSR1 if option specified.
40-
*
41-
* Test:
42-
* Loop if the proper options are given.
43-
* Execute system call
44-
* Check return code, if system call failed (return=-1)
45-
* Log the errno and Issue a FAIL message.
46-
* Otherwise, Issue a PASS message.
47-
*
48-
* Cleanup:
49-
* Print errno log and/or timing stats if options given
50-
*
51-
* USAGE: <for command-line>
52-
* munlock01 [-c n] [-e] [-i n] [-I x] [-p x] [-t]
53-
* where, -c n : Run n copies concurrently
54-
* -e : Turn on errno logging.
55-
* -h : Show this help screen
56-
* -i n : Execute test n times.
57-
* -I x : Execute test for x seconds.
58-
* -p : Pause for SIGUSR1 before starting
59-
* -P x : Pause for x seconds between iterations.
60-
* -t : Turn on syscall timing.
61-
*
62-
* RESTRICTIONS
63-
* Must be root/superuser to run it.
64-
*****************************************************************************/
65-
66-
#include <errno.h>
67-
#include <unistd.h>
68-
#include <sys/mman.h>
69-
#include "test.h"
706

71-
void setup();
72-
void setup1(int);
73-
void cleanup();
7+
/*\
8+
* [Description]
9+
*
10+
* Test munlock with various valid addresses and lengths.
11+
*/
7412

75-
char *TCID = "munlock01";
76-
int TST_TOTAL = 4;
13+
#include <stdlib.h>
14+
#include "tst_test.h"
7715

78-
void *addr1;
16+
static void *addr;
7917

80-
struct test_case_t {
81-
void **addr;
18+
static struct tcase {
19+
char *msg;
8220
int len;
83-
void (*setupfunc) ();
84-
} TC[] = {
85-
{
86-
&addr1, 1, setup1}, {
87-
&addr1, 1024, setup1}, {
88-
&addr1, 1024 * 1024, setup1}, {
89-
&addr1, 1024 * 1024 * 10, setup1}
21+
} tcases[] = {
22+
{"munlock 1 byte", 1},
23+
{"munlock 1024 bytes", 1024},
24+
{"munlock 1024 * 1024 bytes", 1024 * 1024},
25+
{"munlock 1024 * 1024 * 10 bytes", 1024 * 1024 * 10}
9026
};
9127

92-
int main(int ac, char **av)
93-
{
94-
int lc, i;
95-
96-
tst_parse_opts(ac, av, NULL, NULL);
97-
98-
setup();
99-
100-
/* check looping state */
101-
for (lc = 0; TEST_LOOPING(lc); lc++) {
102-
103-
tst_count = 0;
104-
105-
for (i = 0; i < TST_TOTAL; i++) {
106-
107-
if (TC[i].setupfunc != NULL)
108-
TC[i].setupfunc(i);
109-
110-
TEST(munlock(*(TC[i].addr), TC[i].len));
111-
112-
/* check return code */
113-
if (TEST_RETURN == -1) {
114-
tst_resm(TFAIL | TTERRNO,
115-
"mlock(%p, %d) Failed with "
116-
"return=%ld", TC[i].addr, TC[i].len,
117-
TEST_RETURN);
118-
} else {
119-
tst_resm(TPASS, "test %d passed length = %d",
120-
i, TC[i].len);
121-
}
122-
}
123-
}
124-
125-
/* cleanup and exit */
126-
cleanup();
127-
128-
tst_exit();
129-
}
130-
131-
void setup1(int i)
28+
static void verify_munlock(unsigned int i)
13229
{
133-
addr1 = malloc(TC[i].len);
134-
if (addr1 == NULL)
135-
tst_brkm(TFAIL, cleanup, "malloc failed");
136-
TEST(mlock(*(TC[i].addr), TC[i].len));
137-
138-
/* check return code */
139-
if (TEST_RETURN == -1) {
140-
tst_brkm(TFAIL | TTERRNO, cleanup,
141-
"mlock(%p, %d) Failed with return=%ld", TC[i].addr,
142-
TC[i].len, TEST_RETURN);
143-
}
30+
struct tcase *tc = &tcases[i];
31+
32+
tst_res(TINFO, "%s", tc->msg);
33+
addr = SAFE_MALLOC(tc->len);
34+
SAFE_MLOCK(addr, tc->len);
35+
TST_EXP_PASS(munlock(addr, tc->len), "munlock(%p, %d)", addr, tc->len);
36+
free(addr);
37+
addr = NULL;
14438
}
14539

146-
/* setup() - performs all ONE TIME setup for this test. */
147-
void setup(void)
40+
static void cleanup(void)
14841
{
149-
tst_require_root();
150-
151-
tst_sig(NOFORK, DEF_HANDLER, cleanup);
152-
153-
TEST_PAUSE;
42+
if (addr)
43+
free(addr);
15444
}
15545

156-
/*
157-
* cleanup() - performs all ONE TIME cleanup for this test at
158-
* completion or premature exit.
159-
*/
160-
void cleanup(void)
161-
{
162-
}
46+
static struct tst_test test = {
47+
.needs_root = 1,
48+
.test = verify_munlock,
49+
.tcnt = ARRAY_SIZE(tcases),
50+
.cleanup = cleanup,
51+
};

0 commit comments

Comments
 (0)