23b159d95c3f7f2c1f19e1bfb306302bbfa66f20
[sfrench/cifs-2.6.git] / tools / testing / selftests / bpf / prog_tests / bpf_verif_scale.c
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)
16 {
17         struct bpf_prog_load_attr attr;
18         struct bpf_object *obj;
19         int err, prog_fd;
20
21         memset(&attr, 0, sizeof(struct bpf_prog_load_attr));
22         attr.file = file;
23         attr.prog_type = BPF_PROG_TYPE_SCHED_CLS;
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 *file1 = "./test_verif_scale1.o";
35         const char *file2 = "./test_verif_scale2.o";
36         const char *file3 = "./test_verif_scale3.o";
37         int err;
38
39         if (verifier_stats)
40                 libbpf_set_print(libbpf_debug_print);
41
42         err = check_load(file1);
43         err |= check_load(file2);
44         err |= check_load(file3);
45         if (!err)
46                 printf("test_verif_scale:OK\n");
47         else
48                 printf("test_verif_scale:FAIL\n");
49 }