1 // SPDX-License-Identifier: GPL-2.0
3 #include <bpf/bpf_helpers.h>
4 #include <bpf/bpf_tracing.h>
7 #ifdef ENABLE_ATOMICS_TESTS
8 bool skip_tests __attribute((__section__(".data"))) = false;
10 bool skip_tests = true;
13 __u64 add64_value = 1;
14 __u64 add64_result = 0;
15 __u32 add32_value = 1;
16 __u32 add32_result = 0;
17 __u64 add_stack_value_copy = 0;
18 __u64 add_stack_result = 0;
19 __u64 add_noreturn_value = 1;
21 SEC("fentry/bpf_fentry_test1")
22 int BPF_PROG(add, int a)
24 #ifdef ENABLE_ATOMICS_TESTS
25 __u64 add_stack_value = 1;
27 add64_result = __sync_fetch_and_add(&add64_value, 2);
28 add32_result = __sync_fetch_and_add(&add32_value, 2);
29 add_stack_result = __sync_fetch_and_add(&add_stack_value, 2);
30 add_stack_value_copy = add_stack_value;
31 __sync_fetch_and_add(&add_noreturn_value, 2);
37 __s64 sub64_value = 1;
38 __s64 sub64_result = 0;
39 __s32 sub32_value = 1;
40 __s32 sub32_result = 0;
41 __s64 sub_stack_value_copy = 0;
42 __s64 sub_stack_result = 0;
43 __s64 sub_noreturn_value = 1;
45 SEC("fentry/bpf_fentry_test1")
46 int BPF_PROG(sub, int a)
48 #ifdef ENABLE_ATOMICS_TESTS
49 __u64 sub_stack_value = 1;
51 sub64_result = __sync_fetch_and_sub(&sub64_value, 2);
52 sub32_result = __sync_fetch_and_sub(&sub32_value, 2);
53 sub_stack_result = __sync_fetch_and_sub(&sub_stack_value, 2);
54 sub_stack_value_copy = sub_stack_value;
55 __sync_fetch_and_sub(&sub_noreturn_value, 2);
61 __u64 and64_value = (0x110ull << 32);
62 __u64 and64_result = 0;
63 __u32 and32_value = 0x110;
64 __u32 and32_result = 0;
65 __u64 and_noreturn_value = (0x110ull << 32);
67 SEC("fentry/bpf_fentry_test1")
68 int BPF_PROG(and, int a)
70 #ifdef ENABLE_ATOMICS_TESTS
72 and64_result = __sync_fetch_and_and(&and64_value, 0x011ull << 32);
73 and32_result = __sync_fetch_and_and(&and32_value, 0x011);
74 __sync_fetch_and_and(&and_noreturn_value, 0x011ull << 32);
80 __u64 or64_value = (0x110ull << 32);
81 __u64 or64_result = 0;
82 __u32 or32_value = 0x110;
83 __u32 or32_result = 0;
84 __u64 or_noreturn_value = (0x110ull << 32);
86 SEC("fentry/bpf_fentry_test1")
87 int BPF_PROG(or, int a)
89 #ifdef ENABLE_ATOMICS_TESTS
90 or64_result = __sync_fetch_and_or(&or64_value, 0x011ull << 32);
91 or32_result = __sync_fetch_and_or(&or32_value, 0x011);
92 __sync_fetch_and_or(&or_noreturn_value, 0x011ull << 32);
98 __u64 xor64_value = (0x110ull << 32);
99 __u64 xor64_result = 0;
100 __u32 xor32_value = 0x110;
101 __u32 xor32_result = 0;
102 __u64 xor_noreturn_value = (0x110ull << 32);
104 SEC("fentry/bpf_fentry_test1")
105 int BPF_PROG(xor, int a)
107 #ifdef ENABLE_ATOMICS_TESTS
108 xor64_result = __sync_fetch_and_xor(&xor64_value, 0x011ull << 32);
109 xor32_result = __sync_fetch_and_xor(&xor32_value, 0x011);
110 __sync_fetch_and_xor(&xor_noreturn_value, 0x011ull << 32);
116 __u64 cmpxchg64_value = 1;
117 __u64 cmpxchg64_result_fail = 0;
118 __u64 cmpxchg64_result_succeed = 0;
119 __u32 cmpxchg32_value = 1;
120 __u32 cmpxchg32_result_fail = 0;
121 __u32 cmpxchg32_result_succeed = 0;
123 SEC("fentry/bpf_fentry_test1")
124 int BPF_PROG(cmpxchg, int a)
126 #ifdef ENABLE_ATOMICS_TESTS
127 cmpxchg64_result_fail = __sync_val_compare_and_swap(&cmpxchg64_value, 0, 3);
128 cmpxchg64_result_succeed = __sync_val_compare_and_swap(&cmpxchg64_value, 1, 2);
130 cmpxchg32_result_fail = __sync_val_compare_and_swap(&cmpxchg32_value, 0, 3);
131 cmpxchg32_result_succeed = __sync_val_compare_and_swap(&cmpxchg32_value, 1, 2);
137 __u64 xchg64_value = 1;
138 __u64 xchg64_result = 0;
139 __u32 xchg32_value = 1;
140 __u32 xchg32_result = 0;
142 SEC("fentry/bpf_fentry_test1")
143 int BPF_PROG(xchg, int a)
145 #ifdef ENABLE_ATOMICS_TESTS
149 xchg64_result = __sync_lock_test_and_set(&xchg64_value, val64);
150 xchg32_result = __sync_lock_test_and_set(&xchg32_value, val32);