Skip to content

Commit

Permalink
vsock/test: fix SEQPACKET message bounds test
Browse files Browse the repository at this point in the history
[ Upstream commit f086388 ]

Tune message length calculation to make this test work on machines
where 'getpagesize()' returns >32KB. Now maximum message length is not
hardcoded (on machines above it was smaller than 'getpagesize()' return
value, thus we get negative value and test fails), but calculated at
runtime and always bigger than 'getpagesize()' result. Reproduced on
aarch64 with 64KB page size.

Fixes: 5c33811 ("test/vsock: rework message bounds test")
Signed-off-by: Arseniy Krasnov <avkrasnov@salutedevices.com>
Reported-by: Bogdan Marcynkov <bmarcynk@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Link: https://lore.kernel.org/r/20231121211642.163474-1-avkrasnov@salutedevices.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Arseniy Krasnov authored and gregkh committed Dec 3, 2023
1 parent 0bdd88a commit 78c0614
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions tools/testing/vsock/vsock_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,12 @@ static void test_stream_msg_peek_server(const struct test_opts *opts)
}

#define SOCK_BUF_SIZE (2 * 1024 * 1024)
#define MAX_MSG_SIZE (32 * 1024)
#define MAX_MSG_PAGES 4

static void test_seqpacket_msg_bounds_client(const struct test_opts *opts)
{
unsigned long curr_hash;
size_t max_msg_size;
int page_size;
int msg_count;
int fd;
Expand All @@ -412,7 +413,8 @@ static void test_seqpacket_msg_bounds_client(const struct test_opts *opts)

curr_hash = 0;
page_size = getpagesize();
msg_count = SOCK_BUF_SIZE / MAX_MSG_SIZE;
max_msg_size = MAX_MSG_PAGES * page_size;
msg_count = SOCK_BUF_SIZE / max_msg_size;

for (int i = 0; i < msg_count; i++) {
ssize_t send_size;
Expand All @@ -423,7 +425,7 @@ static void test_seqpacket_msg_bounds_client(const struct test_opts *opts)
/* Use "small" buffers and "big" buffers. */
if (i & 1)
buf_size = page_size +
(rand() % (MAX_MSG_SIZE - page_size));
(rand() % (max_msg_size - page_size));
else
buf_size = 1 + (rand() % page_size);

Expand Down Expand Up @@ -479,7 +481,6 @@ static void test_seqpacket_msg_bounds_server(const struct test_opts *opts)
unsigned long remote_hash;
unsigned long curr_hash;
int fd;
char buf[MAX_MSG_SIZE];
struct msghdr msg = {0};
struct iovec iov = {0};

Expand Down Expand Up @@ -507,8 +508,13 @@ static void test_seqpacket_msg_bounds_server(const struct test_opts *opts)
control_writeln("SRVREADY");
/* Wait, until peer sends whole data. */
control_expectln("SENDDONE");
iov.iov_base = buf;
iov.iov_len = sizeof(buf);
iov.iov_len = MAX_MSG_PAGES * getpagesize();
iov.iov_base = malloc(iov.iov_len);
if (!iov.iov_base) {
perror("malloc");
exit(EXIT_FAILURE);
}

msg.msg_iov = &iov;
msg.msg_iovlen = 1;

Expand All @@ -533,6 +539,7 @@ static void test_seqpacket_msg_bounds_server(const struct test_opts *opts)
curr_hash += hash_djb2(msg.msg_iov[0].iov_base, recv_size);
}

free(iov.iov_base);
close(fd);
remote_hash = control_readulong();

Expand Down

0 comments on commit 78c0614

Please sign in to comment.