Skip to content

Commit 624cd2a

Browse files
Alexei Starovoitovanakryiko
authored andcommitted
selftests/bpf: Convert exceptions_assert.c to bpf_cmp
Convert exceptions_assert.c to bpf_cmp_unlikely() macro. Since bpf_assert(bpf_cmp_unlikely(var, ==, 100)); other code; will generate assembly code: if r1 == 100 goto L2; r0 = 0 call bpf_throw L1: other code; ... L2: goto L1; LLVM generates redundant basic block with extra goto. LLVM will be fixed eventually. Right now it's less efficient than __bpf_assert(var, ==, 100) macro that produces: if r1 == 100 goto L1; r0 = 0 call bpf_throw L1: other code; But extra goto doesn't hurt the verification process. Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Jiri Olsa <[email protected]> Acked-by: Kumar Kartikeya Dwivedi <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent a8b242d commit 624cd2a

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

tools/testing/selftests/bpf/progs/exceptions_assert.c

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,51 +11,51 @@
1111
#define check_assert(type, op, name, value) \
1212
SEC("?tc") \
1313
__log_level(2) __failure \
14-
int check_assert_##op##_##name(void *ctx) \
14+
int check_assert_##name(void *ctx) \
1515
{ \
1616
type num = bpf_ktime_get_ns(); \
17-
bpf_assert_##op(num, value); \
17+
bpf_assert(bpf_cmp_unlikely(num, op, value)); \
1818
return *(u64 *)num; \
1919
}
2020

21-
__msg(": R0_w=0xffffffff80000000 R10=fp0")
22-
check_assert(s64, eq, int_min, INT_MIN);
23-
__msg(": R0_w=0x7fffffff R10=fp0")
24-
check_assert(s64, eq, int_max, INT_MAX);
25-
__msg(": R0_w=0 R10=fp0")
26-
check_assert(s64, eq, zero, 0);
27-
__msg(": R0_w=0x8000000000000000 R1_w=0x8000000000000000 R10=fp0")
28-
check_assert(s64, eq, llong_min, LLONG_MIN);
29-
__msg(": R0_w=0x7fffffffffffffff R1_w=0x7fffffffffffffff R10=fp0")
30-
check_assert(s64, eq, llong_max, LLONG_MAX);
31-
32-
__msg(": R0_w=scalar(smax=0x7ffffffe) R10=fp0")
33-
check_assert(s64, lt, pos, INT_MAX);
34-
__msg(": R0_w=scalar(smax=-1,umin=0x8000000000000000,var_off=(0x8000000000000000; 0x7fffffffffffffff))")
35-
check_assert(s64, lt, zero, 0);
36-
__msg(": R0_w=scalar(smax=0xffffffff7fffffff,umin=0x8000000000000000,umax=0xffffffff7fffffff,var_off=(0x8000000000000000; 0x7fffffffffffffff))")
37-
check_assert(s64, lt, neg, INT_MIN);
38-
39-
__msg(": R0_w=scalar(smax=0x7fffffff) R10=fp0")
40-
check_assert(s64, le, pos, INT_MAX);
41-
__msg(": R0_w=scalar(smax=0) R10=fp0")
42-
check_assert(s64, le, zero, 0);
43-
__msg(": R0_w=scalar(smax=0xffffffff80000000,umin=0x8000000000000000,umax=0xffffffff80000000,var_off=(0x8000000000000000; 0x7fffffffffffffff))")
44-
check_assert(s64, le, neg, INT_MIN);
45-
46-
__msg(": R0_w=scalar(smin=umin=0x80000000,umax=0x7fffffffffffffff,var_off=(0x0; 0x7fffffffffffffff))")
47-
check_assert(s64, gt, pos, INT_MAX);
48-
__msg(": R0_w=scalar(smin=umin=1,umax=0x7fffffffffffffff,var_off=(0x0; 0x7fffffffffffffff))")
49-
check_assert(s64, gt, zero, 0);
50-
__msg(": R0_w=scalar(smin=0xffffffff80000001) R10=fp0")
51-
check_assert(s64, gt, neg, INT_MIN);
52-
53-
__msg(": R0_w=scalar(smin=umin=0x7fffffff,umax=0x7fffffffffffffff,var_off=(0x0; 0x7fffffffffffffff))")
54-
check_assert(s64, ge, pos, INT_MAX);
55-
__msg(": R0_w=scalar(smin=0,umax=0x7fffffffffffffff,var_off=(0x0; 0x7fffffffffffffff)) R10=fp0")
56-
check_assert(s64, ge, zero, 0);
57-
__msg(": R0_w=scalar(smin=0xffffffff80000000) R10=fp0")
58-
check_assert(s64, ge, neg, INT_MIN);
21+
__msg(": R0_w=0xffffffff80000000")
22+
check_assert(s64, ==, eq_int_min, INT_MIN);
23+
__msg(": R0_w=0x7fffffff")
24+
check_assert(s64, ==, eq_int_max, INT_MAX);
25+
__msg(": R0_w=0")
26+
check_assert(s64, ==, eq_zero, 0);
27+
__msg(": R0_w=0x8000000000000000 R1_w=0x8000000000000000")
28+
check_assert(s64, ==, eq_llong_min, LLONG_MIN);
29+
__msg(": R0_w=0x7fffffffffffffff R1_w=0x7fffffffffffffff")
30+
check_assert(s64, ==, eq_llong_max, LLONG_MAX);
31+
32+
__msg(": R0_w=scalar(id=1,smax=0x7ffffffe)")
33+
check_assert(s64, <, lt_pos, INT_MAX);
34+
__msg(": R0_w=scalar(id=1,smax=-1,umin=0x8000000000000000,var_off=(0x8000000000000000; 0x7fffffffffffffff))")
35+
check_assert(s64, <, lt_zero, 0);
36+
__msg(": R0_w=scalar(id=1,smax=0xffffffff7fffffff")
37+
check_assert(s64, <, lt_neg, INT_MIN);
38+
39+
__msg(": R0_w=scalar(id=1,smax=0x7fffffff)")
40+
check_assert(s64, <=, le_pos, INT_MAX);
41+
__msg(": R0_w=scalar(id=1,smax=0)")
42+
check_assert(s64, <=, le_zero, 0);
43+
__msg(": R0_w=scalar(id=1,smax=0xffffffff80000000")
44+
check_assert(s64, <=, le_neg, INT_MIN);
45+
46+
__msg(": R0_w=scalar(id=1,smin=umin=0x80000000,umax=0x7fffffffffffffff,var_off=(0x0; 0x7fffffffffffffff))")
47+
check_assert(s64, >, gt_pos, INT_MAX);
48+
__msg(": R0_w=scalar(id=1,smin=umin=1,umax=0x7fffffffffffffff,var_off=(0x0; 0x7fffffffffffffff))")
49+
check_assert(s64, >, gt_zero, 0);
50+
__msg(": R0_w=scalar(id=1,smin=0xffffffff80000001")
51+
check_assert(s64, >, gt_neg, INT_MIN);
52+
53+
__msg(": R0_w=scalar(id=1,smin=umin=0x7fffffff,umax=0x7fffffffffffffff,var_off=(0x0; 0x7fffffffffffffff))")
54+
check_assert(s64, >=, ge_pos, INT_MAX);
55+
__msg(": R0_w=scalar(id=1,smin=0,umax=0x7fffffffffffffff,var_off=(0x0; 0x7fffffffffffffff))")
56+
check_assert(s64, >=, ge_zero, 0);
57+
__msg(": R0_w=scalar(id=1,smin=0xffffffff80000000")
58+
check_assert(s64, >=, ge_neg, INT_MIN);
5959

6060
SEC("?tc")
6161
__log_level(2) __failure

0 commit comments

Comments
 (0)