selftests/bpf: Fix kmem_cache iterator draining
authorT.J. Mercier <tjmercier@google.com>
Mon, 28 Apr 2025 18:02:54 +0000 (18:02 +0000)
committerMartin KaFai Lau <martin.lau@kernel.org>
Tue, 29 Apr 2025 20:21:48 +0000 (13:21 -0700)
The closing parentheses around the read syscall is misplaced, causing
single byte reads from the iterator instead of buf sized reads. While
the end result is the same, many more read calls than necessary are
performed.

$ tools/testing/selftests/bpf/vmtest.sh  "./test_progs -t kmem_cache_iter"
145/1   kmem_cache_iter/check_task_struct:OK
145/2   kmem_cache_iter/check_slabinfo:OK
145/3   kmem_cache_iter/open_coded_iter:OK
145     kmem_cache_iter:OK
Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED

Fixes: a496d0cdc84d ("selftests/bpf: Add a test for kmem_cache_iter")
Signed-off-by: T.J. Mercier <tjmercier@google.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Acked-by: Song Liu <song@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Link: https://patch.msgid.link/20250428180256.1482899-1-tjmercier@google.com
tools/testing/selftests/bpf/prog_tests/kmem_cache_iter.c

index 8e13a3416a21d2e9bd9c47f518ac91918c7f8b5f..1de14b111931aacb921bbe0a36d795fd6406b8a0 100644 (file)
@@ -104,7 +104,7 @@ void test_kmem_cache_iter(void)
                goto destroy;
 
        memset(buf, 0, sizeof(buf));
-       while (read(iter_fd, buf, sizeof(buf) > 0)) {
+       while (read(iter_fd, buf, sizeof(buf)) > 0) {
                /* Read out all contents */
                printf("%s", buf);
        }