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 0; 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 err = bpf_prog_load_xattr(&attr, &obj, &prog_fd); 26 bpf_object__close(obj); 27 if (err) 28 error_cnt++; 29 return err; 30 } 31 32 void test_bpf_verif_scale(void) 33 { 34 const char *scale[] = { 35 "./test_verif_scale1.o", "./test_verif_scale2.o", "./test_verif_scale3.o" 36 }; 37 const char *pyperf[] = { 38 "./pyperf50.o", "./pyperf100.o", "./pyperf180.o" 39 }; 40 int err, i; 41 42 if (verifier_stats) 43 libbpf_set_print(libbpf_debug_print); 44 45 for (i = 0; i < ARRAY_SIZE(scale); i++) { 46 err = check_load(scale[i], BPF_PROG_TYPE_SCHED_CLS); 47 printf("test_scale:%s:%s\n", scale[i], err ? "FAIL" : "OK"); 48 } 49 50 for (i = 0; i < ARRAY_SIZE(pyperf); i++) { 51 err = check_load(pyperf[i], BPF_PROG_TYPE_RAW_TRACEPOINT); 52 printf("test_scale:%s:%s\n", pyperf[i], err ? "FAIL" : "OK"); 53 } 54 } 55