OSDN Git Service

bpf: Add tests for new BPF atomic operations
authorBrendan Jackman <jackmanb@google.com>
Thu, 14 Jan 2021 18:17:50 +0000 (18:17 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 15 Jan 2021 02:34:29 +0000 (18:34 -0800)
commit98d666d05a1d9706bb3fe972157fa6155dbb180f
tree7d756eb0f033b90497e951419d8c682c603a472f
parent981f94c3e92146705baf97fb417a5ed1ab1a79a5
bpf: Add tests for new BPF atomic operations

The prog_test that's added depends on Clang/LLVM features added by
Yonghong in commit 286daafd6512 (was https://reviews.llvm.org/D72184).

Note the use of a define called ENABLE_ATOMICS_TESTS: this is used
to:

 - Avoid breaking the build for people on old versions of Clang
 - Avoid needing separate lists of test objects for no_alu32, where
   atomics are not supported even if Clang has the feature.

The atomics_test.o BPF object is built unconditionally both for
test_progs and test_progs-no_alu32. For test_progs, if Clang supports
atomics, ENABLE_ATOMICS_TESTS is defined, so it includes the proper
test code. Otherwise, progs and global vars are defined anyway, as
stubs; this means that the skeleton user code still builds.

The atomics_test.o userspace object is built once and used for both
test_progs and test_progs-no_alu32. A variable called skip_tests is
defined in the BPF object's data section, which tells the userspace
object whether to skip the atomics test.

Signed-off-by: Brendan Jackman <jackmanb@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20210114181751.768687-11-jackmanb@google.com
tools/testing/selftests/bpf/Makefile
tools/testing/selftests/bpf/prog_tests/atomics.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/atomics.c [new file with mode: 0644]
tools/testing/selftests/bpf/verifier/atomic_and.c [new file with mode: 0644]
tools/testing/selftests/bpf/verifier/atomic_cmpxchg.c [new file with mode: 0644]
tools/testing/selftests/bpf/verifier/atomic_fetch_add.c [new file with mode: 0644]
tools/testing/selftests/bpf/verifier/atomic_or.c [new file with mode: 0644]
tools/testing/selftests/bpf/verifier/atomic_xchg.c [new file with mode: 0644]
tools/testing/selftests/bpf/verifier/atomic_xor.c [new file with mode: 0644]