1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2019 Facebook
3 #include <test_progs.h>
4 static int libbpf_debug_print(enum libbpf_print_level level
,
5 const char *format
, va_list args
)
7 if (level
!= LIBBPF_DEBUG
)
8 return vfprintf(stderr
, format
, args
);
10 if (!strstr(format
, "verifier log"))
12 return vfprintf(stderr
, "%s", args
);
15 static int check_load(const char *file
, enum bpf_prog_type type
)
17 struct bpf_prog_load_attr attr
;
18 struct bpf_object
*obj
= NULL
;
21 memset(&attr
, 0, sizeof(struct bpf_prog_load_attr
));
23 attr
.prog_type
= type
;
25 attr
.prog_flags
= BPF_F_TEST_RND_HI32
;
26 err
= bpf_prog_load_xattr(&attr
, &obj
, &prog_fd
);
27 bpf_object__close(obj
);
33 void test_bpf_verif_scale(void)
35 const char *sched_cls
[] = {
36 "./test_verif_scale1.o", "./test_verif_scale2.o", "./test_verif_scale3.o",
38 const char *raw_tp
[] = {
39 /* full unroll by llvm */
40 "./pyperf50.o", "./pyperf100.o", "./pyperf180.o",
42 /* partial unroll. llvm will unroll loop ~150 times.
43 * C loop count -> 600.
44 * Asm loop count -> 4.
45 * 16k insns in loop body.
46 * Total of 5 such loops. Total program size ~82k insns.
51 * C loop count -> 600.
52 * ASM loop count -> 600.
53 * ~110 insns in loop body.
54 * Total of 5 such loops. Total program size ~1500 insns.
56 "./pyperf600_nounroll.o",
58 "./loop1.o", "./loop2.o",
60 /* partial unroll. 19k insn in a loop.
61 * Total program size 20.8k insn.
62 * ~350k processed_insns
66 /* no unroll, tiny loops */
67 "./strobemeta_nounroll1.o",
68 "./strobemeta_nounroll2.o",
70 const char *cg_sysctl
[] = {
71 "./test_sysctl_loop1.o", "./test_sysctl_loop2.o",
76 libbpf_set_print(libbpf_debug_print
);
78 err
= check_load("./loop3.o", BPF_PROG_TYPE_RAW_TRACEPOINT
);
79 printf("test_scale:loop3:%s\n", err
? (error_cnt
--, "OK") : "FAIL");
81 for (i
= 0; i
< ARRAY_SIZE(sched_cls
); i
++) {
82 err
= check_load(sched_cls
[i
], BPF_PROG_TYPE_SCHED_CLS
);
83 printf("test_scale:%s:%s\n", sched_cls
[i
], err
? "FAIL" : "OK");
86 for (i
= 0; i
< ARRAY_SIZE(raw_tp
); i
++) {
87 err
= check_load(raw_tp
[i
], BPF_PROG_TYPE_RAW_TRACEPOINT
);
88 printf("test_scale:%s:%s\n", raw_tp
[i
], err
? "FAIL" : "OK");
91 for (i
= 0; i
< ARRAY_SIZE(cg_sysctl
); i
++) {
92 err
= check_load(cg_sysctl
[i
], BPF_PROG_TYPE_CGROUP_SYSCTL
);
93 printf("test_scale:%s:%s\n", cg_sysctl
[i
], err
? "FAIL" : "OK");
95 err
= check_load("./test_xdp_loop.o", BPF_PROG_TYPE_XDP
);
96 printf("test_scale:test_xdp_loop:%s\n", err
? "FAIL" : "OK");
98 err
= check_load("./test_seg6_loop.o", BPF_PROG_TYPE_LWT_SEG6LOCAL
);
99 printf("test_scale:test_seg6_loop:%s\n", err
? "FAIL" : "OK");