Skip to content

Commit 71a3681

Browse files
Avineshwangli5665
authored andcommitted
fcntl30.c: Convert the test to new LTP API
Signed-off-by: Avinesh Kumar <[email protected]> Reviewed-by: Li Wang <[email protected]>
1 parent 5cbf1f6 commit 71a3681

File tree

1 file changed

+31
-80
lines changed

1 file changed

+31
-80
lines changed
Lines changed: 31 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,54 @@
1+
// SPDX-License-Identifier: GPL-2.0
12
/*
23
* Copyright (c) 2014 Fujitsu Ltd.
34
* Author: Xiaoguang Wang <[email protected]>
4-
*
5-
* This program is free software; you can redistribute it and/or modify it
6-
* under the terms of version 2 of the GNU General Public License as
7-
* published by the Free Software Foundation.
8-
*
9-
* This program is distributed in the hope that it would be useful, but
10-
* WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12-
*
13-
* You should have received a copy of the GNU General Public License along
14-
* with this program; if not, write the Free Software Foundation, Inc.,
15-
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
5+
* Copyright (c) 2023 SUSE LLC Avinesh Kumar <[email protected]>
166
*/
177

18-
/*
19-
* Description:
20-
* Verify that,
21-
* Basic test for fcntl(2) using F_SETPIPE_SZ, F_GETPIPE_SZ argument.
8+
/*\
9+
* [Description]
10+
*
11+
* Verify that, fetching and changing the capacity of a pipe works as
12+
* expected with fcntl(2) syscall using F_GETPIPE_SZ, F_SETPIPE_SZ arguments.
2213
*/
2314

24-
25-
#include <stdio.h>
26-
#include <errno.h>
27-
#include <unistd.h>
28-
#include <string.h>
29-
#include <signal.h>
30-
#include <sys/types.h>
31-
#include <pwd.h>
32-
33-
#include "test.h"
34-
#include "safe_macros.h"
15+
#include "tst_test.h"
3516
#include "lapi/fcntl.h"
3617

37-
char *TCID = "fcntl30";
38-
int TST_TOTAL = 1;
39-
40-
static void setup(void);
41-
static void cleanup(void);
18+
static int fds[2];
19+
static int max_size_unpriv;
4220

43-
int main(int ac, char **av)
21+
static void run(void)
4422
{
45-
int lc;
46-
int pipe_fds[2], test_fd;
47-
int orig_pipe_size, new_pipe_size;
23+
SAFE_PIPE(fds);
4824

25+
TST_EXP_POSITIVE(fcntl(fds[1], F_GETPIPE_SZ));
4926

50-
tst_parse_opts(ac, av, NULL, NULL);
27+
TST_EXP_POSITIVE(fcntl(fds[1], F_SETPIPE_SZ, max_size_unpriv));
28+
TST_EXP_POSITIVE(fcntl(fds[1], F_GETPIPE_SZ));
29+
TST_EXP_EXPR(TST_RET >= max_size_unpriv,
30+
"new pipe size (%ld) >= requested size (%d)",
31+
TST_RET, max_size_unpriv);
5132

52-
setup();
53-
54-
for (lc = 0; TEST_LOOPING(lc); lc++) {
55-
tst_count = 0;
56-
57-
SAFE_PIPE(cleanup, pipe_fds);
58-
test_fd = pipe_fds[1];
59-
60-
TEST(fcntl(test_fd, F_GETPIPE_SZ));
61-
if (TEST_RETURN < 0) {
62-
tst_brkm(TFAIL | TTERRNO, cleanup,
63-
"fcntl get pipe size failed");
64-
}
65-
66-
orig_pipe_size = TEST_RETURN;
67-
new_pipe_size = orig_pipe_size * 2;
68-
TEST(fcntl(test_fd, F_SETPIPE_SZ, new_pipe_size));
69-
if (TEST_RETURN < 0) {
70-
tst_brkm(TFAIL | TTERRNO, cleanup,
71-
"fcntl test F_SETPIPE_SZ failed");
72-
}
73-
74-
TEST(fcntl(test_fd, F_GETPIPE_SZ));
75-
if (TEST_RETURN < 0) {
76-
tst_brkm(TFAIL | TTERRNO, cleanup,
77-
"fcntl test F_GETPIPE_SZ failed");
78-
}
79-
tst_resm(TINFO, "orig_pipe_size: %d new_pipe_size: %d",
80-
orig_pipe_size, new_pipe_size);
81-
if (TEST_RETURN >= new_pipe_size) {
82-
tst_resm(TPASS, "fcntl test F_GETPIPE_SZ and F_SETPIPE_SZ passed");
83-
} else {
84-
tst_resm(TFAIL, "fcntl test F_GETPIPE_SZ and F_SETPIPE_SZ failed");
85-
}
86-
SAFE_CLOSE(cleanup, pipe_fds[0]);
87-
SAFE_CLOSE(cleanup, pipe_fds[1]);
88-
}
89-
90-
cleanup();
91-
tst_exit();
33+
SAFE_CLOSE(fds[0]);
34+
SAFE_CLOSE(fds[1]);
9235
}
9336

9437
static void setup(void)
9538
{
96-
tst_sig(NOFORK, DEF_HANDLER, cleanup);
97-
98-
TEST_PAUSE;
39+
SAFE_FILE_SCANF("/proc/sys/fs/pipe-max-size", "%d", &max_size_unpriv);
9940
}
10041

10142
static void cleanup(void)
10243
{
44+
if (fds[0] > 0)
45+
SAFE_CLOSE(fds[0]);
46+
if (fds[1] > 0)
47+
SAFE_CLOSE(fds[1]);
10348
}
49+
50+
static struct tst_test test = {
51+
.test_all = run,
52+
.setup = setup,
53+
.cleanup = cleanup
54+
};

0 commit comments

Comments
 (0)