Skip to content

Commit 0c72b4c

Browse files
committed
Merge branch 'next'
* next: tests: test both TCP ends in send zc tests tests: test poll_first tests: add tests for retries with long iovec tests: add non-zc tests in send-zerocopy.c tests: pass params in a struct tests: improve zc cflags handling test/fsnotify: only test on regular files test/pipe-bug.c: remove last remaining bzero() io_uring: add a test for missing task work Add fsnotify test case
2 parents 4915f2a + b6b8653 commit 0c72b4c

File tree

4 files changed

+336
-55
lines changed

4 files changed

+336
-55
lines changed

test/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ test_srcs := \
8686
fixed-link.c \
8787
fixed-reuse.c \
8888
fpos.c \
89+
fsnotify.c \
8990
fsync.c \
9091
hardlink.c \
9192
io-cancel.c \
@@ -112,6 +113,7 @@ test_srcs := \
112113
open-direct-link.c \
113114
open-direct-pick.c \
114115
personality.c \
116+
pipe-bug.c \
115117
pipe-eof.c \
116118
pipe-reuse.c \
117119
poll.c \

test/fsnotify.c

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/* SPDX-License-Identifier: MIT */
2+
/*
3+
* Description: test fsnotify access off O_DIRECT read
4+
*/
5+
#include <stdio.h>
6+
#include <stdlib.h>
7+
#include <unistd.h>
8+
#include <fcntl.h>
9+
#include <sys/fanotify.h>
10+
#include <sys/stat.h>
11+
#include <sys/wait.h>
12+
13+
#include "liburing.h"
14+
#include "helpers.h"
15+
16+
int main(int argc, char *argv[])
17+
{
18+
struct io_uring_sqe *sqe;
19+
struct io_uring_cqe *cqe;
20+
struct io_uring ring;
21+
int fan, ret, fd, err;
22+
char fname[64], *f;
23+
struct stat sb;
24+
void *buf;
25+
26+
fan = fanotify_init(FAN_CLASS_NOTIF|FAN_CLASS_CONTENT, 0);
27+
if (fan < 0) {
28+
if (errno == ENOSYS)
29+
return T_EXIT_SKIP;
30+
if (geteuid())
31+
return T_EXIT_SKIP;
32+
perror("fanotify_init");
33+
return T_EXIT_FAIL;
34+
}
35+
36+
err = T_EXIT_FAIL;
37+
if (argc > 1) {
38+
f = argv[1];
39+
fd = open(argv[1], O_RDONLY | O_DIRECT);
40+
} else {
41+
sprintf(fname, ".fsnotify.%d", getpid());
42+
f = fname;
43+
t_create_file(fname, 8192);
44+
fd = open(fname, O_RDONLY | O_DIRECT);
45+
}
46+
if (fd < 0) {
47+
perror("open");
48+
goto out;
49+
}
50+
51+
if (fstat(fd, &sb) < 0) {
52+
perror("fstat");
53+
goto out;
54+
}
55+
if ((sb.st_mode & S_IFMT) != S_IFREG) {
56+
err = T_EXIT_SKIP;
57+
close(fd);
58+
goto out;
59+
}
60+
61+
ret = fanotify_mark(fan, FAN_MARK_ADD, FAN_ACCESS|FAN_MODIFY, fd, NULL);
62+
if (ret < 0) {
63+
perror("fanotify_mark");
64+
goto out;
65+
}
66+
67+
if (fork()) {
68+
int wstat;
69+
70+
io_uring_queue_init(1, &ring, 0);
71+
if (posix_memalign(&buf, 4096, 4096))
72+
goto out;
73+
sqe = io_uring_get_sqe(&ring);
74+
io_uring_prep_read(sqe, fd, buf, 4096, 0);
75+
io_uring_submit(&ring);
76+
ret = io_uring_wait_cqe(&ring, &cqe);
77+
if (ret) {
78+
fprintf(stderr, "wait_ret=%d\n", ret);
79+
goto out;
80+
}
81+
wait(&wstat);
82+
if (!WEXITSTATUS(wstat))
83+
err = T_EXIT_PASS;
84+
} else {
85+
struct fanotify_event_metadata m;
86+
int fret;
87+
88+
fret = read(fan, &m, sizeof(m));
89+
if (fret < 0)
90+
perror("fanotify read");
91+
/* fail if mask isn't right or pid indicates non-task context */
92+
else if (!(m.mask & 1) || !m.pid)
93+
exit(1);
94+
exit(0);
95+
}
96+
97+
out:
98+
if (f == fname)
99+
unlink(fname);
100+
return err;
101+
}

test/pipe-bug.c

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
/*
4+
* Description: tests bug fixed in
5+
* "io_uring: don't gate task_work run on TIF_NOTIFY_SIGNAL"
6+
*
7+
* See: https://github.com/axboe/liburing/issues/665
8+
*/
9+
10+
#include <stdio.h>
11+
#include <string.h>
12+
#include <unistd.h>
13+
14+
#include "helpers.h"
15+
#include "liburing.h"
16+
17+
#define CHECK(x) if (!(x)) { \
18+
fprintf(stderr, "%s:%d %s failed\n", __FILE__, __LINE__, #x); \
19+
return -1; }
20+
21+
static int pipe_bug(void)
22+
{
23+
struct io_uring_params p;
24+
struct io_uring ring;
25+
struct io_uring_sqe *sqe;
26+
struct io_uring_cqe *cqe;
27+
char buf[1024];
28+
int fds[2];
29+
struct __kernel_timespec to = {
30+
.tv_sec = 1
31+
};
32+
33+
CHECK(pipe(fds) == 0);
34+
35+
memset(&p, 0, sizeof(p));
36+
CHECK(t_create_ring_params(8, &ring, &p) == 0);
37+
38+
/* WRITE */
39+
sqe = io_uring_get_sqe(&ring);
40+
CHECK(sqe);
41+
io_uring_prep_write(sqe, fds[1], "foobar", strlen("foobar"), 0); /* or -1 */
42+
CHECK(io_uring_submit(&ring) == 1);
43+
CHECK(io_uring_wait_cqe(&ring, &cqe) == 0);
44+
45+
io_uring_cqe_seen(&ring, cqe);
46+
47+
/* CLOSE */
48+
sqe = io_uring_get_sqe(&ring);
49+
CHECK(sqe);
50+
io_uring_prep_close(sqe, fds[1]);
51+
CHECK(io_uring_submit(&ring) == 1);
52+
CHECK(io_uring_wait_cqe_timeout(&ring, &cqe, &to) == 0);
53+
io_uring_cqe_seen(&ring, cqe);
54+
55+
/* READ */
56+
sqe = io_uring_get_sqe(&ring);
57+
CHECK(sqe);
58+
io_uring_prep_read(sqe, fds[0], buf, sizeof(buf), 0); /* or -1 */
59+
CHECK(io_uring_submit(&ring) == 1);
60+
CHECK(io_uring_wait_cqe_timeout(&ring, &cqe, &to) == 0);
61+
io_uring_cqe_seen(&ring, cqe);
62+
memset(buf, 0, sizeof(buf));
63+
64+
/* READ */
65+
sqe = io_uring_get_sqe(&ring);
66+
CHECK(sqe);
67+
io_uring_prep_read(sqe, fds[0], buf, sizeof(buf), 0); /* or -1 */
68+
CHECK(io_uring_submit(&ring) == 1);
69+
CHECK(io_uring_wait_cqe_timeout(&ring, &cqe, &to) == 0);
70+
io_uring_cqe_seen(&ring, cqe);
71+
72+
close(fds[0]);
73+
io_uring_queue_exit(&ring);
74+
75+
return 0;
76+
}
77+
78+
int main(int argc, char *argv[])
79+
{
80+
int i;
81+
82+
if (argc > 1)
83+
return T_EXIT_SKIP;
84+
85+
for (i = 0; i < 10000; i++) {
86+
if (pipe_bug())
87+
return T_EXIT_FAIL;
88+
}
89+
90+
return T_EXIT_PASS;
91+
}

0 commit comments

Comments
 (0)