Skip to content

Commit 4fccd2f

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
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 <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 0f99384 commit 4fccd2f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

tools/testing/selftests/bpf/prog_tests/varlen.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,25 @@ void test_varlen(void)
4444
CHECK_VAL(bss->payload1_len2, size2);
4545
CHECK_VAL(bss->total1, size1 + size2);
4646
CHECK(memcmp(bss->payload1, exp_str, size1 + size2), "content_check",
47-
"doesn't match!");
47+
"doesn't match!\n");
4848

4949
CHECK_VAL(data->payload2_len1, size1);
5050
CHECK_VAL(data->payload2_len2, size2);
5151
CHECK_VAL(data->total2, size1 + size2);
5252
CHECK(memcmp(data->payload2, exp_str, size1 + size2), "content_check",
53-
"doesn't match!");
53+
"doesn't match!\n");
5454

5555
CHECK_VAL(data->payload3_len1, size1);
5656
CHECK_VAL(data->payload3_len2, size2);
5757
CHECK_VAL(data->total3, size1 + size2);
5858
CHECK(memcmp(data->payload3, exp_str, size1 + size2), "content_check",
59-
"doesn't match!");
59+
"doesn't match!\n");
6060

6161
CHECK_VAL(data->payload4_len1, size1);
6262
CHECK_VAL(data->payload4_len2, size2);
6363
CHECK_VAL(data->total4, size1 + size2);
6464
CHECK(memcmp(data->payload4, exp_str, size1 + size2), "content_check",
65-
"doesn't match!");
65+
"doesn't match!\n");
6666
cleanup:
6767
test_varlen__destroy(skel);
6868
}

tools/testing/selftests/bpf/progs/test_varlen.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ int test_pid = 0;
1515
bool capture = false;
1616

1717
/* .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;
2121
char payload1[MAX_LEN + MAX_LEN] = {};
2222

2323
/* .data */

0 commit comments

Comments
 (0)