Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Make test_varlen work with 32-bit user-space arch

Despite bpftool generating data section memory layout that will work for
32-bit architectures on user-space side, BPF programs should be careful to not
use ambiguous types like `long`, which have different size in 32-bit and
64-bit environments. Fix that in test by using __u64 explicitly, which is
a recommended approach anyway.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200813204945.1020225-10-andriin@fb.com

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
4fccd2ff 0f993845

+7 -7
+4 -4
tools/testing/selftests/bpf/prog_tests/varlen.c
··· 44 44 CHECK_VAL(bss->payload1_len2, size2); 45 45 CHECK_VAL(bss->total1, size1 + size2); 46 46 CHECK(memcmp(bss->payload1, exp_str, size1 + size2), "content_check", 47 - "doesn't match!"); 47 + "doesn't match!\n"); 48 48 49 49 CHECK_VAL(data->payload2_len1, size1); 50 50 CHECK_VAL(data->payload2_len2, size2); 51 51 CHECK_VAL(data->total2, size1 + size2); 52 52 CHECK(memcmp(data->payload2, exp_str, size1 + size2), "content_check", 53 - "doesn't match!"); 53 + "doesn't match!\n"); 54 54 55 55 CHECK_VAL(data->payload3_len1, size1); 56 56 CHECK_VAL(data->payload3_len2, size2); 57 57 CHECK_VAL(data->total3, size1 + size2); 58 58 CHECK(memcmp(data->payload3, exp_str, size1 + size2), "content_check", 59 - "doesn't match!"); 59 + "doesn't match!\n"); 60 60 61 61 CHECK_VAL(data->payload4_len1, size1); 62 62 CHECK_VAL(data->payload4_len2, size2); 63 63 CHECK_VAL(data->total4, size1 + size2); 64 64 CHECK(memcmp(data->payload4, exp_str, size1 + size2), "content_check", 65 - "doesn't match!"); 65 + "doesn't match!\n"); 66 66 cleanup: 67 67 test_varlen__destroy(skel); 68 68 }
+3 -3
tools/testing/selftests/bpf/progs/test_varlen.c
··· 15 15 bool capture = false; 16 16 17 17 /* .bss */ 18 - long payload1_len1 = 0; 19 - long payload1_len2 = 0; 20 - long total1 = 0; 18 + __u64 payload1_len1 = 0; 19 + __u64 payload1_len2 = 0; 20 + __u64 total1 = 0; 21 21 char payload1[MAX_LEN + MAX_LEN] = {}; 22 22 23 23 /* .data */