MCPcopy Create free account
hub / github.com/axboe/liburing / test_stdout_io_fixed

Function test_stdout_io_fixed

test/stdout.c:98–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98static int test_stdout_io_fixed(struct io_uring *ring)
99{
100 const char str[] = "This is a fixed pipe test\n";
101 struct io_uring_cqe *cqe;
102 struct io_uring_sqe *sqe;
103 struct iovec vecs;
104 int ret;
105
106 t_posix_memalign(&vecs.iov_base, 4096, 4096);
107 memcpy(vecs.iov_base, str, strlen(str));
108 vecs.iov_len = strlen(str);
109
110 ret = io_uring_register_buffers(ring, &vecs, 1);
111 if (ret) {
112 fprintf(stderr, "Failed to register buffers: %d\n", ret);
113 return 1;
114 }
115
116 sqe = io_uring_get_sqe(ring);
117 if (!sqe) {
118 fprintf(stderr, "get sqe failed\n");
119 goto err;
120 }
121 io_uring_prep_write_fixed(sqe, STDOUT_FILENO, vecs.iov_base, vecs.iov_len, 0, 0);
122
123 ret = io_uring_submit(ring);
124 if (ret < 0) {
125 fprintf(stderr, "sqe submit failed: %d\n", ret);
126 goto err;
127 } else if (ret < 1) {
128 fprintf(stderr, "Submitted only %d\n", ret);
129 goto err;
130 }
131
132 ret = io_uring_wait_cqe(ring, &cqe);
133 if (ret < 0) {
134 fprintf(stderr, "wait completion %d\n", ret);
135 goto err;
136 }
137 if (cqe->res < 0) {
138 fprintf(stderr, "STDOUT write error: %s\n", strerror(-cqe->res));
139 goto err;
140 }
141 if (cqe->res != vecs.iov_len) {
142 fprintf(stderr, "Got %d write, wanted %d\n", cqe->res, (int)vecs.iov_len);
143 goto err;
144 }
145 io_uring_cqe_seen(ring, cqe);
146 io_uring_unregister_buffers(ring);
147 free(vecs.iov_base);
148 return 0;
149err:
150 return 1;
151}
152
153static int test_stdout_io(struct io_uring *ring)
154{

Callers 1

mainFunction · 0.85

Calls 5

t_posix_memalignFunction · 0.85
io_uring_submitFunction · 0.85
io_uring_get_sqeFunction · 0.50

Tested by

no test coverage detected