1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2014 Fujitsu Ltd.
4 * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
5 * Copyright (c) 2023 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
6 */
7
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.
13 */
14
15 #include "tst_test.h"
16 #include "lapi/fcntl.h"
17
18 static int fds[2];
19 static int max_size_unpriv;
20
run(void)21 static void run(void)
22 {
23 SAFE_PIPE(fds);
24
25 TST_EXP_POSITIVE(fcntl(fds[1], F_GETPIPE_SZ));
26
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);
32
33 SAFE_CLOSE(fds[0]);
34 SAFE_CLOSE(fds[1]);
35 }
36
setup(void)37 static void setup(void)
38 {
39 SAFE_FILE_SCANF("/proc/sys/fs/pipe-max-size", "%d", &max_size_unpriv);
40 }
41
cleanup(void)42 static void cleanup(void)
43 {
44 if (fds[0] > 0)
45 SAFE_CLOSE(fds[0]);
46 if (fds[1] > 0)
47 SAFE_CLOSE(fds[1]);
48 }
49
50 static struct tst_test test = {
51 .test_all = run,
52 .setup = setup,
53 .cleanup = cleanup
54 };
55