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 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 *scale[] = { 36 "./test_verif_scale1.o", "./test_verif_scale2.o", "./test_verif_scale3.o" 37 }; 38 const char *pyperf[] = { 39 "./pyperf50.o", "./pyperf100.o", "./pyperf180.o" 40 }; 41 int err, i; 42 43 if (verifier_stats) 44 libbpf_set_print(libbpf_debug_print); 45 46 for (i = 0; i < ARRAY_SIZE(scale); i++) { 47 err = check_load(scale[i], BPF_PROG_TYPE_SCHED_CLS); 48 printf("test_scale:%s:%s\n", scale[i], err ? "FAIL" : "OK"); 49 } 50 51 for (i = 0; i < ARRAY_SIZE(pyperf); i++) { 52 err = check_load(pyperf[i], BPF_PROG_TYPE_RAW_TRACEPOINT); 53 printf("test_scale:%s:%s\n", pyperf[i], err ? "FAIL" : "OK"); 54 } 55 } 56