Skip to content

Commit eed7818

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
selftests/bpf: Fix btf_dump test cases on 32-bit arches
Fix btf_dump test cases by hard-coding BPF's pointer size of 8 bytes for cases where it's impossible to deterimne the pointer size (no long type in BTF). In cases where it's known, validate libbpf correctly determines it as 8. Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 44ad23d commit eed7818

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ void btf_dump_printf(void *ctx, const char *fmt, va_list args)
1212
static struct btf_dump_test_case {
1313
const char *name;
1414
const char *file;
15+
bool known_ptr_sz;
1516
struct btf_dump_opts opts;
1617
} btf_dump_test_cases[] = {
17-
{"btf_dump: syntax", "btf_dump_test_case_syntax", {}},
18-
{"btf_dump: ordering", "btf_dump_test_case_ordering", {}},
19-
{"btf_dump: padding", "btf_dump_test_case_padding", {}},
20-
{"btf_dump: packing", "btf_dump_test_case_packing", {}},
21-
{"btf_dump: bitfields", "btf_dump_test_case_bitfields", {}},
22-
{"btf_dump: multidim", "btf_dump_test_case_multidim", {}},
23-
{"btf_dump: namespacing", "btf_dump_test_case_namespacing", {}},
18+
{"btf_dump: syntax", "btf_dump_test_case_syntax", true, {}},
19+
{"btf_dump: ordering", "btf_dump_test_case_ordering", false, {}},
20+
{"btf_dump: padding", "btf_dump_test_case_padding", true, {}},
21+
{"btf_dump: packing", "btf_dump_test_case_packing", true, {}},
22+
{"btf_dump: bitfields", "btf_dump_test_case_bitfields", true, {}},
23+
{"btf_dump: multidim", "btf_dump_test_case_multidim", false, {}},
24+
{"btf_dump: namespacing", "btf_dump_test_case_namespacing", false, {}},
2425
};
2526

2627
static int btf_dump_all_types(const struct btf *btf,
@@ -62,6 +63,18 @@ static int test_btf_dump_case(int n, struct btf_dump_test_case *t)
6263
goto done;
6364
}
6465

66+
/* tests with t->known_ptr_sz have no "long" or "unsigned long" type,
67+
* so it's impossible to determine correct pointer size; but if they
68+
* do, it should be 8 regardless of host architecture, becaues BPF
69+
* target is always 64-bit
70+
*/
71+
if (!t->known_ptr_sz) {
72+
btf__set_pointer_size(btf, 8);
73+
} else {
74+
CHECK(btf__pointer_size(btf) != 8, "ptr_sz", "exp %d, got %zu\n",
75+
8, btf__pointer_size(btf));
76+
}
77+
6578
snprintf(out_file, sizeof(out_file), "/tmp/%s.output.XXXXXX", t->file);
6679
fd = mkstemp(out_file);
6780
if (CHECK(fd < 0, "create_tmp", "failed to create file: %d\n", fd)) {

0 commit comments

Comments
 (0)