Skip to content

Commit b4cbbf0

Browse files
committed
Merge branch 'vsock-test-tests-for-memory-leaks'
Michal Luczaj says: ==================== vsock/test: Tests for memory leaks Series adds tests for recently fixed memory leaks[1]: commit d7b0ff5 ("virtio/vsock: Fix accept_queue memory leak") commit fbf7085 ("vsock: Fix sk_error_queue memory leak") commit 60cf620 ("virtio/vsock: Improve MSG_ZEROCOPY error handling") Patch 1 is a non-functional preparatory cleanup. Patch 2 is a test suite extension for picking specific tests. Patch 3 explains the need of kmemleak scans. Patch 4 adapts utility functions to handle MSG_ZEROCOPY. Patches 5-6-7 add the tests. NOTE: Test in the last patch ("vsock/test: Add test for MSG_ZEROCOPY completion memory leak") may stop working even before this series is merged. See changes proposed in [2]. The failslab variant would be unaffected. [1] https://lore.kernel.org/[email protected] [2] https://lore.kernel.org/CANn89i+oL+qoPmbbGvE_RT3_3OWgeck7cCPcTafeehKrQZ8kyw@mail.gmail.com v3: https://lore.kernel.org/[email protected] v2: https://lore.kernel.org/[email protected] v1: https://lore.kernel.org/[email protected] ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents aa4ad7c + d127ac8 commit b4cbbf0

File tree

4 files changed

+309
-6
lines changed

4 files changed

+309
-6
lines changed

tools/testing/vsock/README

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ Invoke test binaries in both directions as follows:
3636
--control-port=1234 \
3737
--peer-cid=3
3838

39+
Some tests are designed to produce kernel memory leaks. Leaks detection,
40+
however, is deferred to Kernel Memory Leak Detector. It is recommended to enable
41+
kmemleak (CONFIG_DEBUG_KMEMLEAK=y) and explicitly trigger a scan after each test
42+
suite run, e.g.
43+
44+
# echo clear > /sys/kernel/debug/kmemleak
45+
# $TEST_BINARY ...
46+
# echo "wait for any grace periods" && sleep 2
47+
# echo scan > /sys/kernel/debug/kmemleak
48+
# echo "wait for kmemleak" && sleep 5
49+
# echo scan > /sys/kernel/debug/kmemleak
50+
# cat /sys/kernel/debug/kmemleak
51+
52+
For more information see Documentation/dev-tools/kmemleak.rst.
53+
3954
vsock_perf utility
4055
-------------------
4156
'vsock_perf' is a simple tool to measure vsock performance. It works in

tools/testing/vsock/util.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ void recv_buf(int fd, void *buf, size_t len, int flags, ssize_t expected_ret)
401401
*/
402402
void send_byte(int fd, int expected_ret, int flags)
403403
{
404-
const uint8_t byte = 'A';
404+
static const uint8_t byte = 'A';
405405

406406
send_buf(fd, &byte, sizeof(byte), flags, expected_ret);
407407
}
@@ -420,7 +420,7 @@ void recv_byte(int fd, int expected_ret, int flags)
420420
recv_buf(fd, &byte, sizeof(byte), flags, expected_ret);
421421

422422
if (byte != 'A') {
423-
fprintf(stderr, "unexpected byte read %c\n", byte);
423+
fprintf(stderr, "unexpected byte read 0x%02x\n", byte);
424424
exit(EXIT_FAILURE);
425425
}
426426
}
@@ -486,8 +486,7 @@ void list_tests(const struct test_case *test_cases)
486486
exit(EXIT_FAILURE);
487487
}
488488

489-
void skip_test(struct test_case *test_cases, size_t test_cases_len,
490-
const char *test_id_str)
489+
static unsigned long parse_test_id(const char *test_id_str, size_t test_cases_len)
491490
{
492491
unsigned long test_id;
493492
char *endptr = NULL;
@@ -505,9 +504,35 @@ void skip_test(struct test_case *test_cases, size_t test_cases_len,
505504
exit(EXIT_FAILURE);
506505
}
507506

507+
return test_id;
508+
}
509+
510+
void skip_test(struct test_case *test_cases, size_t test_cases_len,
511+
const char *test_id_str)
512+
{
513+
unsigned long test_id = parse_test_id(test_id_str, test_cases_len);
508514
test_cases[test_id].skip = true;
509515
}
510516

517+
void pick_test(struct test_case *test_cases, size_t test_cases_len,
518+
const char *test_id_str)
519+
{
520+
static bool skip_all = true;
521+
unsigned long test_id;
522+
523+
if (skip_all) {
524+
unsigned long i;
525+
526+
for (i = 0; i < test_cases_len; ++i)
527+
test_cases[i].skip = true;
528+
529+
skip_all = false;
530+
}
531+
532+
test_id = parse_test_id(test_id_str, test_cases_len);
533+
test_cases[test_id].skip = false;
534+
}
535+
511536
unsigned long hash_djb2(const void *data, size_t len)
512537
{
513538
unsigned long hash = 5381;

tools/testing/vsock/util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ void run_tests(const struct test_case *test_cases,
6262
void list_tests(const struct test_case *test_cases);
6363
void skip_test(struct test_case *test_cases, size_t test_cases_len,
6464
const char *test_id_str);
65+
void pick_test(struct test_case *test_cases, size_t test_cases_len,
66+
const char *test_id_str);
6567
unsigned long hash_djb2(const void *data, size_t len);
6668
size_t iovec_bytes(const struct iovec *iov, size_t iovnum);
6769
unsigned long iovec_hash_djb2(const struct iovec *iov, size_t iovnum);

0 commit comments

Comments
 (0)