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
Showing
- tools/testing/selftests/bpf/Makefile 2 additions, 0 deletionstools/testing/selftests/bpf/Makefile
- tools/testing/selftests/bpf/prog_tests/atomics.c 246 additions, 0 deletionstools/testing/selftests/bpf/prog_tests/atomics.c
- tools/testing/selftests/bpf/progs/atomics.c 154 additions, 0 deletionstools/testing/selftests/bpf/progs/atomics.c
- tools/testing/selftests/bpf/verifier/atomic_and.c 77 additions, 0 deletionstools/testing/selftests/bpf/verifier/atomic_and.c
- tools/testing/selftests/bpf/verifier/atomic_cmpxchg.c 96 additions, 0 deletionstools/testing/selftests/bpf/verifier/atomic_cmpxchg.c
- tools/testing/selftests/bpf/verifier/atomic_fetch_add.c 106 additions, 0 deletionstools/testing/selftests/bpf/verifier/atomic_fetch_add.c
- tools/testing/selftests/bpf/verifier/atomic_or.c 77 additions, 0 deletionstools/testing/selftests/bpf/verifier/atomic_or.c
- tools/testing/selftests/bpf/verifier/atomic_xchg.c 46 additions, 0 deletionstools/testing/selftests/bpf/verifier/atomic_xchg.c
- tools/testing/selftests/bpf/verifier/atomic_xor.c 77 additions, 0 deletionstools/testing/selftests/bpf/verifier/atomic_xor.c
tools/testing/selftests/bpf/progs/atomics.c
0 → 100644
Please register or sign in to comment