| 84 | } |
| 85 | |
| 86 | static int run_test(bool stream) |
| 87 | { |
| 88 | struct fds sockfds; |
| 89 | ssize_t bytes_in, bytes_out; |
| 90 | struct io_uring ring; |
| 91 | size_t written_bytes; |
| 92 | int error; |
| 93 | |
| 94 | /* Create three sockets */ |
| 95 | sockfds = create_sockets(stream); |
| 96 | assert(sockfds.tx > 0); |
| 97 | assert(sockfds.rx > 0); |
| 98 | /* Send data sing the sockfds->send */ |
| 99 | written_bytes = send_data(&sockfds, MSG); |
| 100 | |
| 101 | /* Simply io_uring ring creation */ |
| 102 | error = t_create_ring(1, &ring, 0); |
| 103 | if (error == T_SETUP_SKIP) |
| 104 | return error; |
| 105 | else if (error != T_SETUP_OK) |
| 106 | return T_EXIT_FAIL; |
| 107 | |
| 108 | error = create_sqe_and_submit(&ring, sockfds.rx, |
| 109 | SOCKET_URING_OP_SIOCINQ); |
| 110 | if (error) |
| 111 | return T_EXIT_FAIL; |
| 112 | bytes_in = receive_cqe(&ring); |
| 113 | if (bytes_in < 0) { |
| 114 | if (bytes_in == -EINVAL || bytes_in == -EOPNOTSUPP) { |
| 115 | no_io_cmd = 1; |
| 116 | return T_EXIT_SKIP; |
| 117 | } |
| 118 | fprintf(stderr, "Bad return value %ld\n", (long) bytes_in); |
| 119 | return T_EXIT_FAIL; |
| 120 | } |
| 121 | |
| 122 | error = create_sqe_and_submit(&ring, sockfds.tx, |
| 123 | SOCKET_URING_OP_SIOCOUTQ); |
| 124 | if (error) |
| 125 | return T_EXIT_FAIL; |
| 126 | |
| 127 | bytes_out = receive_cqe(&ring); |
| 128 | if (bytes_in == -ENOTSUP || bytes_out == -ENOTSUP) { |
| 129 | fprintf(stderr, "Skipping tests. -ENOTSUP returned\n"); |
| 130 | return T_EXIT_SKIP; |
| 131 | } |
| 132 | |
| 133 | /* |
| 134 | * Assert the number of written bytes are either in the socket buffer |
| 135 | * or on the receive side |
| 136 | */ |
| 137 | if (bytes_in + bytes_out != written_bytes) { |
| 138 | fprintf(stderr, "values does not match: %zu+%zu != %zu\n", |
| 139 | bytes_in, bytes_out, written_bytes); |
| 140 | return T_EXIT_FAIL; |
| 141 | } |
| 142 | |
| 143 | io_uring_queue_exit(&ring); |
no test coverage detected