Message ID | 20230915121452.87192-5-sgarzare@redhat.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 2a8548a9bb4c4ba14badd6be72f1d2b87a6bddc0 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | vsock/test: add recv_buf()/send_buf() utility functions and some improvements | expand |
Context | Check | Description |
---|---|---|
netdev/series_format | success | Posting correctly formatted |
netdev/tree_selection | success | Clearly marked for net-next |
netdev/fixes_present | success | Fixes tag not required for -next series |
netdev/header_inline | success | No static functions without inline keyword in header files |
netdev/build_32bit | success | Errors and warnings before: 9 this patch: 9 |
netdev/cc_maintainers | success | CCed 3 of 3 maintainers |
netdev/build_clang | success | Errors and warnings before: 9 this patch: 9 |
netdev/verify_signedoff | success | Signed-off-by tag matches author and committer |
netdev/deprecated_api | success | None detected |
netdev/check_selftest | success | No net selftest shell script |
netdev/verify_fixes | success | No Fixes tag |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 9 this patch: 9 |
netdev/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 154 lines checked |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/source_inline | success | Was 0 now: 0 |
On 15.09.2023 15:14, Stefano Garzarella wrote: > We have a very common pattern used in vsock_test that we can > now replace with the new send_buf(). > > This allows us to reuse the code we already had to check the > actual return value and wait for all the bytes to be sent with > an appropriate timeout. > > Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> > --- > tools/testing/vsock/vsock_test.c | 75 ++++---------------------------- > 1 file changed, 9 insertions(+), 66 deletions(-) Reviewed-by: Arseniy Krasnov <avkrasnov@salutedevices.com> > > diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c > index d1dcbaeb477a..b18acbaf92e2 100644 > --- a/tools/testing/vsock/vsock_test.c > +++ b/tools/testing/vsock/vsock_test.c > @@ -261,7 +261,6 @@ static void test_msg_peek_client(const struct test_opts *opts, > bool seqpacket) > { > unsigned char buf[MSG_PEEK_BUF_LEN]; > - ssize_t send_size; > int fd; > int i; > > @@ -280,17 +279,7 @@ static void test_msg_peek_client(const struct test_opts *opts, > > control_expectln("SRVREADY"); > > - send_size = send(fd, buf, sizeof(buf), 0); > - > - if (send_size < 0) { > - perror("send"); > - exit(EXIT_FAILURE); > - } > - > - if (send_size != sizeof(buf)) { > - fprintf(stderr, "Invalid send size %zi\n", send_size); > - exit(EXIT_FAILURE); > - } > + send_buf(fd, buf, sizeof(buf), 0, sizeof(buf)); > > close(fd); > } > @@ -385,7 +374,6 @@ static void test_seqpacket_msg_bounds_client(const struct test_opts *opts) > msg_count = SOCK_BUF_SIZE / MAX_MSG_SIZE; > > for (int i = 0; i < msg_count; i++) { > - ssize_t send_size; > size_t buf_size; > int flags; > void *buf; > @@ -413,17 +401,7 @@ static void test_seqpacket_msg_bounds_client(const struct test_opts *opts) > flags = 0; > } > > - send_size = send(fd, buf, buf_size, flags); > - > - if (send_size < 0) { > - perror("send"); > - exit(EXIT_FAILURE); > - } > - > - if (send_size != buf_size) { > - fprintf(stderr, "Invalid send size\n"); > - exit(EXIT_FAILURE); > - } > + send_buf(fd, buf, buf_size, flags, buf_size); > > /* > * Hash sum is computed at both client and server in > @@ -524,10 +502,7 @@ static void test_seqpacket_msg_trunc_client(const struct test_opts *opts) > exit(EXIT_FAILURE); > } > > - if (send(fd, buf, sizeof(buf), 0) != sizeof(buf)) { > - perror("send failed"); > - exit(EXIT_FAILURE); > - } > + send_buf(fd, buf, sizeof(buf), 0, sizeof(buf)); > > control_writeln("SENDDONE"); > close(fd); > @@ -649,7 +624,6 @@ static void test_seqpacket_timeout_server(const struct test_opts *opts) > static void test_seqpacket_bigmsg_client(const struct test_opts *opts) > { > unsigned long sock_buf_size; > - ssize_t send_size; > socklen_t len; > void *data; > int fd; > @@ -676,18 +650,7 @@ static void test_seqpacket_bigmsg_client(const struct test_opts *opts) > exit(EXIT_FAILURE); > } > > - send_size = send(fd, data, sock_buf_size, 0); > - if (send_size != -1) { > - fprintf(stderr, "expected 'send(2)' failure, got %zi\n", > - send_size); > - exit(EXIT_FAILURE); > - } > - > - if (errno != EMSGSIZE) { > - fprintf(stderr, "expected EMSGSIZE in 'errno', got %i\n", > - errno); > - exit(EXIT_FAILURE); > - } > + send_buf(fd, data, sock_buf_size, 0, -EMSGSIZE); > > control_writeln("CLISENT"); > > @@ -741,15 +704,9 @@ static void test_seqpacket_invalid_rec_buffer_client(const struct test_opts *opt > memset(buf1, BUF_PATTERN_1, buf_size); > memset(buf2, BUF_PATTERN_2, buf_size); > > - if (send(fd, buf1, buf_size, 0) != buf_size) { > - perror("send failed"); > - exit(EXIT_FAILURE); > - } > + send_buf(fd, buf1, buf_size, 0, buf_size); > > - if (send(fd, buf2, buf_size, 0) != buf_size) { > - perror("send failed"); > - exit(EXIT_FAILURE); > - } > + send_buf(fd, buf2, buf_size, 0, buf_size); > > close(fd); > } > @@ -972,7 +929,6 @@ static void test_inv_buf_client(const struct test_opts *opts, bool stream) > static void test_inv_buf_server(const struct test_opts *opts, bool stream) > { > unsigned char data[INV_BUF_TEST_DATA_LEN] = {0}; > - ssize_t res; > int fd; > > if (stream) > @@ -985,11 +941,7 @@ static void test_inv_buf_server(const struct test_opts *opts, bool stream) > exit(EXIT_FAILURE); > } > > - res = send(fd, data, sizeof(data), 0); > - if (res != sizeof(data)) { > - fprintf(stderr, "unexpected send(2) result %zi\n", res); > - exit(EXIT_FAILURE); > - } > + send_buf(fd, data, sizeof(data), 0, sizeof(data)); > > control_writeln("SENDDONE"); > > @@ -1023,7 +975,6 @@ static void test_seqpacket_inv_buf_server(const struct test_opts *opts) > > static void test_stream_virtio_skb_merge_client(const struct test_opts *opts) > { > - ssize_t res; > int fd; > > fd = vsock_stream_connect(opts->peer_cid, 1234); > @@ -1033,22 +984,14 @@ static void test_stream_virtio_skb_merge_client(const struct test_opts *opts) > } > > /* Send first skbuff. */ > - res = send(fd, HELLO_STR, strlen(HELLO_STR), 0); > - if (res != strlen(HELLO_STR)) { > - fprintf(stderr, "unexpected send(2) result %zi\n", res); > - exit(EXIT_FAILURE); > - } > + send_buf(fd, HELLO_STR, strlen(HELLO_STR), 0, strlen(HELLO_STR)); > > control_writeln("SEND0"); > /* Peer reads part of first skbuff. */ > control_expectln("REPLY0"); > > /* Send second skbuff, it will be appended to the first. */ > - res = send(fd, WORLD_STR, strlen(WORLD_STR), 0); > - if (res != strlen(WORLD_STR)) { > - fprintf(stderr, "unexpected send(2) result %zi\n", res); > - exit(EXIT_FAILURE); > - } > + send_buf(fd, WORLD_STR, strlen(WORLD_STR), 0, strlen(WORLD_STR)); > > control_writeln("SEND1"); > /* Peer reads merged skbuff packet. */
diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index d1dcbaeb477a..b18acbaf92e2 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -261,7 +261,6 @@ static void test_msg_peek_client(const struct test_opts *opts, bool seqpacket) { unsigned char buf[MSG_PEEK_BUF_LEN]; - ssize_t send_size; int fd; int i; @@ -280,17 +279,7 @@ static void test_msg_peek_client(const struct test_opts *opts, control_expectln("SRVREADY"); - send_size = send(fd, buf, sizeof(buf), 0); - - if (send_size < 0) { - perror("send"); - exit(EXIT_FAILURE); - } - - if (send_size != sizeof(buf)) { - fprintf(stderr, "Invalid send size %zi\n", send_size); - exit(EXIT_FAILURE); - } + send_buf(fd, buf, sizeof(buf), 0, sizeof(buf)); close(fd); } @@ -385,7 +374,6 @@ static void test_seqpacket_msg_bounds_client(const struct test_opts *opts) msg_count = SOCK_BUF_SIZE / MAX_MSG_SIZE; for (int i = 0; i < msg_count; i++) { - ssize_t send_size; size_t buf_size; int flags; void *buf; @@ -413,17 +401,7 @@ static void test_seqpacket_msg_bounds_client(const struct test_opts *opts) flags = 0; } - send_size = send(fd, buf, buf_size, flags); - - if (send_size < 0) { - perror("send"); - exit(EXIT_FAILURE); - } - - if (send_size != buf_size) { - fprintf(stderr, "Invalid send size\n"); - exit(EXIT_FAILURE); - } + send_buf(fd, buf, buf_size, flags, buf_size); /* * Hash sum is computed at both client and server in @@ -524,10 +502,7 @@ static void test_seqpacket_msg_trunc_client(const struct test_opts *opts) exit(EXIT_FAILURE); } - if (send(fd, buf, sizeof(buf), 0) != sizeof(buf)) { - perror("send failed"); - exit(EXIT_FAILURE); - } + send_buf(fd, buf, sizeof(buf), 0, sizeof(buf)); control_writeln("SENDDONE"); close(fd); @@ -649,7 +624,6 @@ static void test_seqpacket_timeout_server(const struct test_opts *opts) static void test_seqpacket_bigmsg_client(const struct test_opts *opts) { unsigned long sock_buf_size; - ssize_t send_size; socklen_t len; void *data; int fd; @@ -676,18 +650,7 @@ static void test_seqpacket_bigmsg_client(const struct test_opts *opts) exit(EXIT_FAILURE); } - send_size = send(fd, data, sock_buf_size, 0); - if (send_size != -1) { - fprintf(stderr, "expected 'send(2)' failure, got %zi\n", - send_size); - exit(EXIT_FAILURE); - } - - if (errno != EMSGSIZE) { - fprintf(stderr, "expected EMSGSIZE in 'errno', got %i\n", - errno); - exit(EXIT_FAILURE); - } + send_buf(fd, data, sock_buf_size, 0, -EMSGSIZE); control_writeln("CLISENT"); @@ -741,15 +704,9 @@ static void test_seqpacket_invalid_rec_buffer_client(const struct test_opts *opt memset(buf1, BUF_PATTERN_1, buf_size); memset(buf2, BUF_PATTERN_2, buf_size); - if (send(fd, buf1, buf_size, 0) != buf_size) { - perror("send failed"); - exit(EXIT_FAILURE); - } + send_buf(fd, buf1, buf_size, 0, buf_size); - if (send(fd, buf2, buf_size, 0) != buf_size) { - perror("send failed"); - exit(EXIT_FAILURE); - } + send_buf(fd, buf2, buf_size, 0, buf_size); close(fd); } @@ -972,7 +929,6 @@ static void test_inv_buf_client(const struct test_opts *opts, bool stream) static void test_inv_buf_server(const struct test_opts *opts, bool stream) { unsigned char data[INV_BUF_TEST_DATA_LEN] = {0}; - ssize_t res; int fd; if (stream) @@ -985,11 +941,7 @@ static void test_inv_buf_server(const struct test_opts *opts, bool stream) exit(EXIT_FAILURE); } - res = send(fd, data, sizeof(data), 0); - if (res != sizeof(data)) { - fprintf(stderr, "unexpected send(2) result %zi\n", res); - exit(EXIT_FAILURE); - } + send_buf(fd, data, sizeof(data), 0, sizeof(data)); control_writeln("SENDDONE"); @@ -1023,7 +975,6 @@ static void test_seqpacket_inv_buf_server(const struct test_opts *opts) static void test_stream_virtio_skb_merge_client(const struct test_opts *opts) { - ssize_t res; int fd; fd = vsock_stream_connect(opts->peer_cid, 1234); @@ -1033,22 +984,14 @@ static void test_stream_virtio_skb_merge_client(const struct test_opts *opts) } /* Send first skbuff. */ - res = send(fd, HELLO_STR, strlen(HELLO_STR), 0); - if (res != strlen(HELLO_STR)) { - fprintf(stderr, "unexpected send(2) result %zi\n", res); - exit(EXIT_FAILURE); - } + send_buf(fd, HELLO_STR, strlen(HELLO_STR), 0, strlen(HELLO_STR)); control_writeln("SEND0"); /* Peer reads part of first skbuff. */ control_expectln("REPLY0"); /* Send second skbuff, it will be appended to the first. */ - res = send(fd, WORLD_STR, strlen(WORLD_STR), 0); - if (res != strlen(WORLD_STR)) { - fprintf(stderr, "unexpected send(2) result %zi\n", res); - exit(EXIT_FAILURE); - } + send_buf(fd, WORLD_STR, strlen(WORLD_STR), 0, strlen(WORLD_STR)); control_writeln("SEND1"); /* Peer reads merged skbuff packet. */
We have a very common pattern used in vsock_test that we can now replace with the new send_buf(). This allows us to reuse the code we already had to check the actual return value and wait for all the bytes to be sent with an appropriate timeout. Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> --- tools/testing/vsock/vsock_test.c | 75 ++++---------------------------- 1 file changed, 9 insertions(+), 66 deletions(-)