1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
3 #include <test_progs.h>
8 static int libbpf_debug_print(enum libbpf_print_level level
,
9 const char *format
, va_list args
)
13 if (level
!= LIBBPF_WARN
||
14 strcmp(format
, "libbpf: \n%s\n")) {
15 vprintf(format
, args
);
19 log_buf
= va_arg(args
, char *);
22 if (err_str
&& strstr(log_buf
, err_str
) == 0)
25 printf(format
, log_buf
);
29 extern int extra_prog_load_log_flags
;
31 static int check_load(const char *file
)
33 struct bpf_prog_load_attr attr
;
34 struct bpf_object
*obj
= NULL
;
37 memset(&attr
, 0, sizeof(struct bpf_prog_load_attr
));
39 attr
.prog_type
= BPF_PROG_TYPE_UNSPEC
;
40 attr
.log_level
= extra_prog_load_log_flags
;
41 attr
.prog_flags
= BPF_F_TEST_RND_HI32
;
43 err
= bpf_prog_load_xattr(&attr
, &obj
, &prog_fd
);
44 bpf_object__close(obj
);
53 void test_test_global_funcs(void)
55 struct test_def tests
[] = {
56 { "test_global_func1.o", "combined stack size of 4 calls is 544" },
57 { "test_global_func2.o" },
58 { "test_global_func3.o" , "the call stack of 8 frames" },
59 { "test_global_func4.o" },
60 { "test_global_func5.o" , "expected pointer to ctx, but got PTR" },
61 { "test_global_func6.o" , "modified ctx ptr R2" },
62 { "test_global_func7.o" , "foo() doesn't return scalar" },
63 { "test_global_func8.o" },
65 libbpf_print_fn_t old_print_fn
= NULL
;
66 int err
, i
, duration
= 0;
68 old_print_fn
= libbpf_set_print(libbpf_debug_print
);
70 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
71 const struct test_def
*test
= &tests
[i
];
73 if (!test__start_subtest(test
->file
))
76 err_str
= test
->err_str
;
77 err
= check_load(test
->file
);
78 CHECK_FAIL(!!err
^ !!err_str
);
80 CHECK(found
, "", "expected string '%s'", err_str
);
82 libbpf_set_print(old_print_fn
);