1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
/* SPDX-License-Identifier: MIT */
/*
* Description: run various nop tests
*
*/
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include "liburing.h"
#include "test.h"
static int seq;
static int test_single_nop(struct io_uring *ring, unsigned req_flags)
{
struct io_uring_cqe *cqe;
struct io_uring_sqe *sqe;
int ret;
bool cqe32 = (ring->flags & IORING_SETUP_CQE32);
sqe = io_uring_get_sqe(ring);
if (!sqe) {
fprintf(stderr, "get sqe failed\n");
goto err;
}
io_uring_prep_nop(sqe);
sqe->user_data = ++seq;
sqe->flags |= req_flags;
ret = io_uring_submit(ring);
if (ret <= 0) {
fprintf(stderr, "sqe submit failed: %d\n", ret);
goto err;
}
ret = io_uring_wait_cqe(ring, &cqe);
if (ret < 0) {
fprintf(stderr, "wait completion %d\n", ret);
goto err;
}
if (!cqe->user_data) {
fprintf(stderr, "Unexpected 0 user_data\n");
goto err;
}
if (cqe32) {
if (cqe->big_cqe[0] != 0) {
fprintf(stderr, "Unexpected extra1\n");
goto err;
}
if (cqe->big_cqe[1] != 0) {
fprintf(stderr, "Unexpected extra2\n");
goto err;
}
}
io_uring_cqe_seen(ring, cqe);
return 0;
err:
return 1;
}
static int test_barrier_nop(struct io_uring *ring, unsigned req_flags)
{
struct io_uring_cqe *cqe;
struct io_uring_sqe *sqe;
int ret, i;
bool cqe32 = (ring->flags & IORING_SETUP_CQE32);
for (i = 0; i < 8; i++) {
sqe = io_uring_get_sqe(ring);
if (!sqe) {
fprintf(stderr, "get sqe failed\n");
goto err;
}
io_uring_prep_nop(sqe);
if (i == 4)
sqe->flags = IOSQE_IO_DRAIN;
sqe->user_data = ++seq;
sqe->flags |= req_flags;
}
ret = io_uring_submit(ring);
if (ret < 0) {
fprintf(stderr, "sqe submit failed: %d\n", ret);
goto err;
} else if (ret < 8) {
fprintf(stderr, "Submitted only %d\n", ret);
goto err;
}
for (i = 0; i < 8; i++) {
ret = io_uring_wait_cqe(ring, &cqe);
if (ret < 0) {
fprintf(stderr, "wait completion %d\n", ret);
goto err;
}
if (!cqe->user_data) {
fprintf(stderr, "Unexpected 0 user_data\n");
goto err;
}
if (cqe32) {
if (cqe->big_cqe[0] != 0) {
fprintf(stderr, "Unexpected extra1\n");
goto err;
}
if (cqe->big_cqe[1] != 0) {
fprintf(stderr, "Unexpected extra2\n");
goto err;
}
}
io_uring_cqe_seen(ring, cqe);
}
return 0;
err:
return 1;
}
static int test_ring(unsigned flags)
{
struct io_uring ring;
struct io_uring_params p = { };
int ret, i;
p.flags = flags;
ret = io_uring_queue_init_params(8, &ring, &p);
if (ret) {
if (ret == -EINVAL)
return 0;
fprintf(stderr, "ring setup failed: %d\n", ret);
return 1;
}
for (i = 0; i < 1000; i++) {
unsigned req_flags = (i & 1) ? IOSQE_ASYNC : 0;
ret = test_single_nop(&ring, req_flags);
if (ret) {
fprintf(stderr, "test_single_nop failed\n");
goto err;
}
ret = test_barrier_nop(&ring, req_flags);
if (ret) {
fprintf(stderr, "test_barrier_nop failed\n");
goto err;
}
}
err:
io_uring_queue_exit(&ring);
return ret;
}
int main(int argc, char *argv[])
{
int ret;
if (argc > 1)
return 0;
FOR_ALL_TEST_CONFIGS {
ret = test_ring(IORING_GET_TEST_CONFIG_FLAGS());
if (ret) {
fprintf(stderr, "Normal ring test failed: %s\n",
IORING_GET_TEST_CONFIG_DESCRIPTION());
return ret;
}
}
return 0;
}
|