Skip to content

Commit d2245a0

Browse files
committed
test: use t_{set,clear}_nonblock() helpers
Use these consistently rather than doing it manually. Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 604ad00 commit d2245a0

9 files changed

Lines changed: 20 additions & 110 deletions

File tree

test/232c93d07b74.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,8 @@ static void *rcv(void *arg)
100100
int s1 = accept(s0, NULL, NULL);
101101
assert(s1 != -1);
102102

103-
if (p->non_blocking) {
104-
int flags = fcntl(s1, F_GETFL, 0);
105-
assert(flags != -1);
106-
107-
flags |= O_NONBLOCK;
108-
res = fcntl(s1, F_SETFL, flags);
109-
assert(res != -1);
110-
}
103+
if (p->non_blocking)
104+
t_set_nonblock(s1);
111105

112106
struct io_uring m_io_uring;
113107
void *ret = NULL;
@@ -208,14 +202,8 @@ static void *snd(void *arg)
208202
assert(ret != -1);
209203
}
210204

211-
if (p->non_blocking) {
212-
int flags = fcntl(s0, F_GETFL, 0);
213-
assert(flags != -1);
214-
215-
flags |= O_NONBLOCK;
216-
ret = fcntl(s0, F_SETFL, flags);
217-
assert(ret != -1);
218-
}
205+
if (p->non_blocking)
206+
t_set_nonblock(s0);
219207

220208
struct io_uring m_io_uring;
221209

test/accept.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -218,23 +218,12 @@ static int set_client_fd(struct sockaddr_in *addr)
218218
ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
219219
assert(ret != -1);
220220

221-
int32_t flags = fcntl(fd, F_GETFL, 0);
222-
assert(flags != -1);
223-
224-
flags |= O_NONBLOCK;
225-
ret = fcntl(fd, F_SETFL, flags);
226-
assert(ret != -1);
221+
t_set_nonblock(fd);
227222

228223
ret = connect(fd, (struct sockaddr *)addr, sizeof(*addr));
229224
assert(ret == -1);
230225

231-
flags = fcntl(fd, F_GETFL, 0);
232-
assert(flags != -1);
233-
234-
flags &= ~O_NONBLOCK;
235-
ret = fcntl(fd, F_SETFL, flags);
236-
assert(ret != -1);
237-
226+
t_clear_nonblock(fd);
238227
return fd;
239228
}
240229

test/conn-unreach.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ static int test(struct io_uring *ring, struct sockaddr_in *saddr, int p_fd)
9595
int main(int argc, char *argv[])
9696
{
9797
struct sockaddr_in addr = { };
98-
int val, p_fd, ret, flags;
9998
struct io_uring ring;
99+
int val, p_fd, ret;
100100

101101
if (argc > 1)
102102
return T_EXIT_SKIP;
@@ -116,12 +116,7 @@ int main(int argc, char *argv[])
116116
ret = setsockopt(p_fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &val, sizeof(val));
117117
assert(ret != -1);
118118

119-
flags = fcntl(p_fd, F_GETFL, 0);
120-
assert(flags != -1);
121-
122-
flags |= O_NONBLOCK;
123-
ret = fcntl(p_fd, F_SETFL, flags);
124-
assert(ret != -1);
119+
t_set_nonblock(p_fd);
125120

126121
addr.sin_family = AF_INET;
127122
/* any unreachable address */

test/fifo-nonblock-read.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ int main(int argc, char *argv[])
1818
struct io_uring ring;
1919
char buf[32];
2020
int fds[2];
21-
int flags;
2221
int ret;
2322

2423
io_uring_queue_init(1, &ring, 0);
@@ -28,17 +27,7 @@ int main(int argc, char *argv[])
2827
return T_EXIT_FAIL;
2928
}
3029

31-
flags = fcntl(fds[0], F_GETFL, 0);
32-
if (flags < 0) {
33-
perror("fcntl get");
34-
return T_EXIT_FAIL;
35-
}
36-
flags |= O_NONBLOCK;
37-
ret = fcntl(fds[0], F_SETFL, flags);
38-
if (ret < 0) {
39-
perror("fcntl set");
40-
return T_EXIT_FAIL;
41-
}
30+
t_set_nonblock(fds[0]);
4231

4332
sqe = io_uring_get_sqe(&ring);
4433
io_uring_prep_read(sqe, fds[0], buf, sizeof(buf), 0);

test/shutdown.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,12 @@ int main(int argc, char *argv[])
5858
ret = setsockopt(p_fd[1], IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
5959
assert(ret != -1);
6060

61-
int32_t flags = fcntl(p_fd[1], F_GETFL, 0);
62-
assert(flags != -1);
63-
64-
flags |= O_NONBLOCK;
65-
ret = fcntl(p_fd[1], F_SETFL, flags);
66-
assert(ret != -1);
61+
t_set_nonblock(p_fd[1]);
6762

6863
ret = connect(p_fd[1], (struct sockaddr*)&addr, sizeof(addr));
6964
assert(ret == -1);
7065

71-
flags = fcntl(p_fd[1], F_GETFL, 0);
72-
assert(flags != -1);
73-
74-
flags &= ~O_NONBLOCK;
75-
ret = fcntl(p_fd[1], F_SETFL, flags);
76-
assert(ret != -1);
66+
t_clear_nonblock(p_fd[1]);
7767

7868
p_fd[0] = accept(recv_s0, NULL, NULL);
7969
assert(p_fd[0] != -1);

test/socket-nb.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,16 @@ static int test(int o_nonblock, int msg_dontwait)
5151
ret = setsockopt(p_fd[1], IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
5252
assert(ret != -1);
5353

54-
flags = fcntl(p_fd[1], F_GETFL, 0);
55-
assert(flags != -1);
56-
57-
flags |= O_NONBLOCK;
58-
ret = fcntl(p_fd[1], F_SETFL, flags);
59-
assert(ret != -1);
54+
t_set_nonblock(p_fd[1]);
6055

6156
ret = connect(p_fd[1], (struct sockaddr *) &addr, sizeof(addr));
6257
assert(ret == -1);
6358

6459
p_fd[0] = accept(recv_s0, NULL, NULL);
6560
assert(p_fd[0] != -1);
6661

67-
if (o_nonblock) {
68-
flags = fcntl(p_fd[0], F_GETFL, 0);
69-
assert(flags != -1);
70-
71-
flags |= O_NONBLOCK;
72-
ret = fcntl(p_fd[0], F_SETFL, flags);
73-
assert(ret != -1);
74-
}
62+
if (o_nonblock)
63+
t_set_nonblock(p_fd[0]);
7564

7665
while (1) {
7766
int32_t code;

test/socket-rw-eagain.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,15 @@ int main(int argc, char *argv[])
5353
ret = setsockopt(p_fd[1], IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
5454
assert(ret != -1);
5555

56-
int32_t flags = fcntl(p_fd[1], F_GETFL, 0);
57-
assert(flags != -1);
58-
59-
flags |= O_NONBLOCK;
60-
ret = fcntl(p_fd[1], F_SETFL, flags);
61-
assert(ret != -1);
56+
t_set_nonblock(p_fd[1]);
6257

6358
ret = connect(p_fd[1], (struct sockaddr*)&addr, sizeof(addr));
6459
assert(ret == -1);
6560

6661
p_fd[0] = accept(recv_s0, NULL, NULL);
6762
assert(p_fd[0] != -1);
6863

69-
flags = fcntl(p_fd[0], F_GETFL, 0);
70-
assert(flags != -1);
71-
72-
flags |= O_NONBLOCK;
73-
ret = fcntl(p_fd[0], F_SETFL, flags);
74-
assert(ret != -1);
64+
t_set_nonblock(p_fd[0]);
7565

7666
while (1) {
7767
int32_t code;

test/socket-rw-offset.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,12 @@ int main(int argc, char *argv[])
5656
ret = setsockopt(p_fd[1], IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
5757
assert(ret != -1);
5858

59-
int32_t flags = fcntl(p_fd[1], F_GETFL, 0);
60-
assert(flags != -1);
61-
62-
flags |= O_NONBLOCK;
63-
ret = fcntl(p_fd[1], F_SETFL, flags);
64-
assert(ret != -1);
59+
t_set_nonblock(p_fd[1]);
6560

6661
ret = connect(p_fd[1], (struct sockaddr*)&addr, sizeof(addr));
6762
assert(ret == -1);
6863

69-
flags = fcntl(p_fd[1], F_GETFL, 0);
70-
assert(flags != -1);
71-
72-
flags &= ~O_NONBLOCK;
73-
ret = fcntl(p_fd[1], F_SETFL, flags);
74-
assert(ret != -1);
64+
t_clear_nonblock(p_fd[1]);
7565

7666
p_fd[0] = accept(recv_s0, NULL, NULL);
7767
assert(p_fd[0] != -1);

test/socket-rw.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,12 @@ int main(int argc, char *argv[])
5656
ret = setsockopt(p_fd[1], IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
5757
assert(ret != -1);
5858

59-
int32_t flags = fcntl(p_fd[1], F_GETFL, 0);
60-
assert(flags != -1);
61-
62-
flags |= O_NONBLOCK;
63-
ret = fcntl(p_fd[1], F_SETFL, flags);
64-
assert(ret != -1);
59+
t_set_nonblock(p_fd[1]);
6560

6661
ret = connect(p_fd[1], (struct sockaddr*)&addr, sizeof(addr));
6762
assert(ret == -1);
6863

69-
flags = fcntl(p_fd[1], F_GETFL, 0);
70-
assert(flags != -1);
71-
72-
flags &= ~O_NONBLOCK;
73-
ret = fcntl(p_fd[1], F_SETFL, flags);
74-
assert(ret != -1);
64+
t_clear_nonblock(p_fd[1]);
7565

7666
p_fd[0] = accept(recv_s0, NULL, NULL);
7767
assert(p_fd[0] != -1);

0 commit comments

Comments
 (0)