xref: /aosp_15_r20/external/liburing/test/tty-write-dpoll.c (revision 25da2bea747f3a93b4c30fd9708b0618ef55a0e6)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Test double poll tty write. A test case for the regression fixed by:
4  *
5  * commit 6e295a664efd083ac9a5c1a8130c45be1db0cde7
6  * Author: Jens Axboe <[email protected]>
7  * Date:   Tue Mar 22 13:11:28 2022 -0600
8  *
9  *   io_uring: fix assuming triggered poll waitqueue is the single poll
10  *
11  */
12 #include <errno.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include <unistd.h>
16 #include <fcntl.h>
17 
18 #include "liburing.h"
19 #include "helpers.h"
20 
21 #define	SQES	128
22 #define BUFSIZE	512
23 
main(int argc,char * argv[])24 int main(int argc, char *argv[])
25 {
26 	static char buf[BUFSIZE];
27 	struct iovec vecs[SQES];
28 	struct io_uring ring;
29 	int ret, i, fd;
30 
31 	if (argc > 1)
32 		return 0;
33 
34 	fd = open("/dev/ttyS0", O_RDWR | O_NONBLOCK);
35 	if (fd < 0)
36 		return 0;
37 
38 	ret = t_create_ring(SQES, &ring, 0);
39 	if (ret == T_SETUP_SKIP)
40 		return 0;
41 	else if (ret < 0)
42 		return 1;
43 
44 	for (i = 0; i < SQES; i++) {
45 		struct io_uring_sqe *sqe;
46 
47 		sqe = io_uring_get_sqe(&ring);
48 		vecs[i].iov_base = buf;
49 		vecs[i].iov_len = sizeof(buf);
50 		io_uring_prep_writev(sqe, fd, &vecs[i], 1, 0);
51 	}
52 
53 	ret = io_uring_submit(&ring);
54 	if (ret != SQES) {
55 		fprintf(stderr, "submit: %d\n", ret);
56 		return 1;
57 	}
58 
59 	return 0;
60 }
61