Commit 0f4feacc authored by Yucong Sun's avatar Yucong Sun Committed by Andrii Nakryiko

selftests/bpf: Adding pid filtering for atomics test

This make atomics test able to run in parallel with other tests.
Signed-off-by: default avatarYucong Sun <sunyucong@gmail.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211006185619.364369-11-fallentree@fb.com
parent 445e72c7
...@@ -225,6 +225,7 @@ void test_atomics(void) ...@@ -225,6 +225,7 @@ void test_atomics(void)
test__skip(); test__skip();
goto cleanup; goto cleanup;
} }
skel->bss->pid = getpid();
if (test__start_subtest("add")) if (test__start_subtest("add"))
test_add(skel); test_add(skel);
......
...@@ -10,6 +10,8 @@ bool skip_tests __attribute((__section__(".data"))) = false; ...@@ -10,6 +10,8 @@ bool skip_tests __attribute((__section__(".data"))) = false;
bool skip_tests = true; bool skip_tests = true;
#endif #endif
__u32 pid = 0;
__u64 add64_value = 1; __u64 add64_value = 1;
__u64 add64_result = 0; __u64 add64_result = 0;
__u32 add32_value = 1; __u32 add32_value = 1;
...@@ -21,6 +23,8 @@ __u64 add_noreturn_value = 1; ...@@ -21,6 +23,8 @@ __u64 add_noreturn_value = 1;
SEC("fentry/bpf_fentry_test1") SEC("fentry/bpf_fentry_test1")
int BPF_PROG(add, int a) int BPF_PROG(add, int a)
{ {
if (pid != (bpf_get_current_pid_tgid() >> 32))
return 0;
#ifdef ENABLE_ATOMICS_TESTS #ifdef ENABLE_ATOMICS_TESTS
__u64 add_stack_value = 1; __u64 add_stack_value = 1;
...@@ -45,6 +49,8 @@ __s64 sub_noreturn_value = 1; ...@@ -45,6 +49,8 @@ __s64 sub_noreturn_value = 1;
SEC("fentry/bpf_fentry_test1") SEC("fentry/bpf_fentry_test1")
int BPF_PROG(sub, int a) int BPF_PROG(sub, int a)
{ {
if (pid != (bpf_get_current_pid_tgid() >> 32))
return 0;
#ifdef ENABLE_ATOMICS_TESTS #ifdef ENABLE_ATOMICS_TESTS
__u64 sub_stack_value = 1; __u64 sub_stack_value = 1;
...@@ -67,6 +73,8 @@ __u64 and_noreturn_value = (0x110ull << 32); ...@@ -67,6 +73,8 @@ __u64 and_noreturn_value = (0x110ull << 32);
SEC("fentry/bpf_fentry_test1") SEC("fentry/bpf_fentry_test1")
int BPF_PROG(and, int a) int BPF_PROG(and, int a)
{ {
if (pid != (bpf_get_current_pid_tgid() >> 32))
return 0;
#ifdef ENABLE_ATOMICS_TESTS #ifdef ENABLE_ATOMICS_TESTS
and64_result = __sync_fetch_and_and(&and64_value, 0x011ull << 32); and64_result = __sync_fetch_and_and(&and64_value, 0x011ull << 32);
...@@ -86,6 +94,8 @@ __u64 or_noreturn_value = (0x110ull << 32); ...@@ -86,6 +94,8 @@ __u64 or_noreturn_value = (0x110ull << 32);
SEC("fentry/bpf_fentry_test1") SEC("fentry/bpf_fentry_test1")
int BPF_PROG(or, int a) int BPF_PROG(or, int a)
{ {
if (pid != (bpf_get_current_pid_tgid() >> 32))
return 0;
#ifdef ENABLE_ATOMICS_TESTS #ifdef ENABLE_ATOMICS_TESTS
or64_result = __sync_fetch_and_or(&or64_value, 0x011ull << 32); or64_result = __sync_fetch_and_or(&or64_value, 0x011ull << 32);
or32_result = __sync_fetch_and_or(&or32_value, 0x011); or32_result = __sync_fetch_and_or(&or32_value, 0x011);
...@@ -104,6 +114,8 @@ __u64 xor_noreturn_value = (0x110ull << 32); ...@@ -104,6 +114,8 @@ __u64 xor_noreturn_value = (0x110ull << 32);
SEC("fentry/bpf_fentry_test1") SEC("fentry/bpf_fentry_test1")
int BPF_PROG(xor, int a) int BPF_PROG(xor, int a)
{ {
if (pid != (bpf_get_current_pid_tgid() >> 32))
return 0;
#ifdef ENABLE_ATOMICS_TESTS #ifdef ENABLE_ATOMICS_TESTS
xor64_result = __sync_fetch_and_xor(&xor64_value, 0x011ull << 32); xor64_result = __sync_fetch_and_xor(&xor64_value, 0x011ull << 32);
xor32_result = __sync_fetch_and_xor(&xor32_value, 0x011); xor32_result = __sync_fetch_and_xor(&xor32_value, 0x011);
...@@ -123,6 +135,8 @@ __u32 cmpxchg32_result_succeed = 0; ...@@ -123,6 +135,8 @@ __u32 cmpxchg32_result_succeed = 0;
SEC("fentry/bpf_fentry_test1") SEC("fentry/bpf_fentry_test1")
int BPF_PROG(cmpxchg, int a) int BPF_PROG(cmpxchg, int a)
{ {
if (pid != (bpf_get_current_pid_tgid() >> 32))
return 0;
#ifdef ENABLE_ATOMICS_TESTS #ifdef ENABLE_ATOMICS_TESTS
cmpxchg64_result_fail = __sync_val_compare_and_swap(&cmpxchg64_value, 0, 3); cmpxchg64_result_fail = __sync_val_compare_and_swap(&cmpxchg64_value, 0, 3);
cmpxchg64_result_succeed = __sync_val_compare_and_swap(&cmpxchg64_value, 1, 2); cmpxchg64_result_succeed = __sync_val_compare_and_swap(&cmpxchg64_value, 1, 2);
...@@ -142,6 +156,8 @@ __u32 xchg32_result = 0; ...@@ -142,6 +156,8 @@ __u32 xchg32_result = 0;
SEC("fentry/bpf_fentry_test1") SEC("fentry/bpf_fentry_test1")
int BPF_PROG(xchg, int a) int BPF_PROG(xchg, int a)
{ {
if (pid != (bpf_get_current_pid_tgid() >> 32))
return 0;
#ifdef ENABLE_ATOMICS_TESTS #ifdef ENABLE_ATOMICS_TESTS
__u64 val64 = 2; __u64 val64 = 2;
__u32 val32 = 2; __u32 val32 = 2;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment