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 test__vprintf(format, args);
12 if (!strstr(format, "verifier log"))
14 test__vprintf("%s", args);
18 static int check_load(const char *file, enum bpf_prog_type type)
20 struct bpf_prog_load_attr attr;
21 struct bpf_object *obj = NULL;
24 memset(&attr, 0, sizeof(struct bpf_prog_load_attr));
26 attr.prog_type = type;
28 attr.prog_flags = BPF_F_TEST_RND_HI32;
29 err = bpf_prog_load_xattr(&attr, &obj, &prog_fd);
30 bpf_object__close(obj);
36 struct scale_test_def {
38 enum bpf_prog_type attach_type;
42 void test_bpf_verif_scale(void)
44 struct scale_test_def tests[] = {
45 { "loop3.o", BPF_PROG_TYPE_RAW_TRACEPOINT, true /* fails */ },
47 { "test_verif_scale1.o", BPF_PROG_TYPE_SCHED_CLS },
48 { "test_verif_scale2.o", BPF_PROG_TYPE_SCHED_CLS },
49 { "test_verif_scale3.o", BPF_PROG_TYPE_SCHED_CLS },
51 /* full unroll by llvm */
52 { "pyperf50.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
53 { "pyperf100.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
54 { "pyperf180.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
56 /* partial unroll. llvm will unroll loop ~150 times.
57 * C loop count -> 600.
58 * Asm loop count -> 4.
59 * 16k insns in loop body.
60 * Total of 5 such loops. Total program size ~82k insns.
62 { "pyperf600.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
65 * C loop count -> 600.
66 * ASM loop count -> 600.
67 * ~110 insns in loop body.
68 * Total of 5 such loops. Total program size ~1500 insns.
70 { "pyperf600_nounroll.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
72 { "loop1.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
73 { "loop2.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
75 /* partial unroll. 19k insn in a loop.
76 * Total program size 20.8k insn.
77 * ~350k processed_insns
79 { "strobemeta.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
81 /* no unroll, tiny loops */
82 { "strobemeta_nounroll1.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
83 { "strobemeta_nounroll2.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
85 { "test_sysctl_loop1.o", BPF_PROG_TYPE_CGROUP_SYSCTL },
86 { "test_sysctl_loop2.o", BPF_PROG_TYPE_CGROUP_SYSCTL },
88 { "test_xdp_loop.o", BPF_PROG_TYPE_XDP },
89 { "test_seg6_loop.o", BPF_PROG_TYPE_LWT_SEG6LOCAL },
91 libbpf_print_fn_t old_print_fn = NULL;
94 if (env.verifier_stats) {
96 old_print_fn = libbpf_set_print(libbpf_debug_print);
99 for (i = 0; i < ARRAY_SIZE(tests); i++) {
100 const struct scale_test_def *test = &tests[i];
102 if (!test__start_subtest(test->file))
105 err = check_load(test->file, test->attach_type);
106 if (test->fails) { /* expected to fail */
114 if (env.verifier_stats)
115 libbpf_set_print(old_print_fn);