xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/fcntl/fcntl27.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) International Business Machines  Corp., 2004
4  * Copyright (C) Bull S.A.S 2005-2006
5  * Author: Jacky Malcles
6  * Copyright (C) 2024 SUSE LLC Andrea Manzini <[email protected]>
7  */
8 
9 /*\
10  * [Description]
11  *
12  * Basic test for fcntl(2) using F_SETLEASE and F_RDLCK argument,
13  * testing O_RDWR and O_WRONLY.
14  */
15 
16 #include "lapi/fcntl.h"
17 #include "tst_test.h"
18 
19 #define TC(x, y) .oflags = x, .mode = y, .desc = #x " with mode " #y,
20 
21 static struct test_case
22 {
23 	int oflags;
24 	mode_t mode;
25 	char *desc;
26 } tcases[] = {
27 	{ TC(O_RDWR | O_CREAT, 0777) },
28 	{ TC(O_WRONLY | O_CREAT, 0222) },
29 };
30 
verify_fcntl(unsigned int nr)31 static void verify_fcntl(unsigned int nr)
32 {
33 	struct test_case *tc = &tcases[nr];
34 
35 	tst_res(TINFO, "Testing %s", tc->desc);
36 
37 	int fd = SAFE_OPEN("testfile", tc->oflags, tc->mode);
38 
39 	TST_EXP_FAIL(fcntl(fd, F_SETLEASE, F_RDLCK), EAGAIN);
40 	SAFE_CLOSE(fd);
41 }
42 
43 static struct tst_test test = {
44 	.test = verify_fcntl,
45 	.tcnt = ARRAY_SIZE(tcases),
46 	.needs_tmpdir = 1,
47 };
48