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) 6 { 7 if (level != LIBBPF_DEBUG) 8 return vfprintf(stderr, format, args); 9 10 if (!strstr(format, "verifier log")) 11 return 0; 12 return vfprintf(stderr, "%s", args); 13 } 14 15 static int check_load(const char *file, enum bpf_prog_type type) 16 { 17 struct bpf_prog_load_attr attr; 18 struct bpf_object *obj = NULL; 19 int err, prog_fd; 20 21 memset(&attr, 0, sizeof(struct bpf_prog_load_attr)); 22 attr.file = file; 23 attr.prog_type = type; 24 attr.log_level = 4; 25 attr.prog_flags = BPF_F_TEST_RND_HI32; 26 err = bpf_prog_load_xattr(&attr, &obj, &prog_fd); 27 bpf_object__close(obj); 28 if (err) 29 error_cnt++; 30 return err; 31 } 32 33 void test_bpf_verif_scale(void) 34 { 35 const char *sched_cls[] = { 36 "./test_verif_scale1.o", "./test_verif_scale2.o", "./test_verif_scale3.o", 37 }; 38 const char *raw_tp[] = { 39 /* full unroll by llvm */ 40 "./pyperf50.o", "./pyperf100.o", "./pyperf180.o", 41 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. 47 */ 48 "./pyperf600.o", 49 50 /* no unroll at all. 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. 55 */ 56 "./pyperf600_nounroll.o", 57 58 "./loop1.o", "./loop2.o", 59 60 /* partial unroll. 19k insn in a loop. 61 * Total program size 20.8k insn. 62 * ~350k processed_insns 63 */ 64 "./strobemeta.o", 65 66 /* no unroll, tiny loops */ 67 "./strobemeta_nounroll1.o", 68 "./strobemeta_nounroll2.o", 69 }; 70 const char *cg_sysctl[] = { 71 "./test_sysctl_loop1.o", "./test_sysctl_loop2.o", 72 }; 73 int err, i; 74 75 if (verifier_stats) 76 libbpf_set_print(libbpf_debug_print); 77 78 err = check_load("./loop3.o", BPF_PROG_TYPE_RAW_TRACEPOINT); 79 printf("test_scale:loop3:%s\n", err ? (error_cnt--, "OK") : "FAIL"); 80 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"); 84 } 85 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"); 89 } 90 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"); 94 } 95 err = check_load("./test_xdp_loop.o", BPF_PROG_TYPE_XDP); 96 printf("test_scale:test_xdp_loop:%s\n", err ? "FAIL" : "OK"); 97 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"); 100 } 101