OSDN Git Service

selftests/bpf: Validate libbpf's auto-sizing of LD/ST/STX instructions
authorAndrii Nakryiko <andriin@fb.com>
Thu, 8 Oct 2020 00:10:24 +0000 (17:10 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 8 Oct 2020 01:50:27 +0000 (18:50 -0700)
commit888d83b961f6057aa377065b60c5206fd8bff97c
tree52172b5918a4b75107c00ecc8d4a9cd9943e9553
parent2b7d88c2b582c659a6567e851d96873d0209a501
selftests/bpf: Validate libbpf's auto-sizing of LD/ST/STX instructions

Add selftests validating libbpf's auto-resizing of load/store instructions
when used with CO-RE relocations. An explicit and manual approach with using
bpf_core_read() is also demonstrated and tested. Separate BPF program is
supposed to fail due to using signed integers of sizes that differ from
kernel's sizes.

To reliably simulate 32-bit BTF (i.e., the one with sizeof(long) ==
sizeof(void *) == 4), selftest generates its own custom BTF and passes it as
a replacement for real kernel BTF. This allows to test 32/64-bitness mix on
all architectures.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20201008001025.292064-5-andrii@kernel.org
tools/testing/selftests/bpf/prog_tests/core_autosize.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/test_core_autosize.c [new file with mode: 0644]