Skip to content

Commit f086388

Browse files
Arseniy Krasnovkuba-moo
authored andcommitted
vsock/test: fix SEQPACKET message bounds test
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 <[email protected]> Reported-by: Bogdan Marcynkov <[email protected]> Reviewed-by: Stefano Garzarella <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 4e20655 commit f086388

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

tools/testing/vsock/vsock_test.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,12 @@ static void test_stream_msg_peek_server(const struct test_opts *opts)
353353
}
354354

355355
#define SOCK_BUF_SIZE (2 * 1024 * 1024)
356-
#define MAX_MSG_SIZE (32 * 1024)
356+
#define MAX_MSG_PAGES 4
357357

358358
static void test_seqpacket_msg_bounds_client(const struct test_opts *opts)
359359
{
360360
unsigned long curr_hash;
361+
size_t max_msg_size;
361362
int page_size;
362363
int msg_count;
363364
int fd;
@@ -373,7 +374,8 @@ static void test_seqpacket_msg_bounds_client(const struct test_opts *opts)
373374

374375
curr_hash = 0;
375376
page_size = getpagesize();
376-
msg_count = SOCK_BUF_SIZE / MAX_MSG_SIZE;
377+
max_msg_size = MAX_MSG_PAGES * page_size;
378+
msg_count = SOCK_BUF_SIZE / max_msg_size;
377379

378380
for (int i = 0; i < msg_count; i++) {
379381
size_t buf_size;
@@ -383,7 +385,7 @@ static void test_seqpacket_msg_bounds_client(const struct test_opts *opts)
383385
/* Use "small" buffers and "big" buffers. */
384386
if (i & 1)
385387
buf_size = page_size +
386-
(rand() % (MAX_MSG_SIZE - page_size));
388+
(rand() % (max_msg_size - page_size));
387389
else
388390
buf_size = 1 + (rand() % page_size);
389391

@@ -429,7 +431,6 @@ static void test_seqpacket_msg_bounds_server(const struct test_opts *opts)
429431
unsigned long remote_hash;
430432
unsigned long curr_hash;
431433
int fd;
432-
char buf[MAX_MSG_SIZE];
433434
struct msghdr msg = {0};
434435
struct iovec iov = {0};
435436

@@ -457,8 +458,13 @@ static void test_seqpacket_msg_bounds_server(const struct test_opts *opts)
457458
control_writeln("SRVREADY");
458459
/* Wait, until peer sends whole data. */
459460
control_expectln("SENDDONE");
460-
iov.iov_base = buf;
461-
iov.iov_len = sizeof(buf);
461+
iov.iov_len = MAX_MSG_PAGES * getpagesize();
462+
iov.iov_base = malloc(iov.iov_len);
463+
if (!iov.iov_base) {
464+
perror("malloc");
465+
exit(EXIT_FAILURE);
466+
}
467+
462468
msg.msg_iov = &iov;
463469
msg.msg_iovlen = 1;
464470

@@ -483,6 +489,7 @@ static void test_seqpacket_msg_bounds_server(const struct test_opts *opts)
483489
curr_hash += hash_djb2(msg.msg_iov[0].iov_base, recv_size);
484490
}
485491

492+
free(iov.iov_base);
486493
close(fd);
487494
remote_hash = control_readulong();
488495

0 commit comments

Comments
 (0)