aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/test_libbpf_open.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/testing/selftests/bpf/test_libbpf_open.c')
-rw-r--r--tools/testing/selftests/bpf/test_libbpf_open.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/tools/testing/selftests/bpf/test_libbpf_open.c b/tools/testing/selftests/bpf/test_libbpf_open.c
index 8fcd1c076add..1909ecf4d999 100644
--- a/tools/testing/selftests/bpf/test_libbpf_open.c
+++ b/tools/testing/selftests/bpf/test_libbpf_open.c
@@ -34,23 +34,16 @@ static void usage(char *argv[])
34 printf("\n"); 34 printf("\n");
35} 35}
36 36
37#define DEFINE_PRINT_FN(name, enabled) \ 37static bool debug = 0;
38static int libbpf_##name(const char *fmt, ...) \ 38static int libbpf_debug_print(enum libbpf_print_level level,
39{ \ 39 const char *fmt, va_list args)
40 va_list args; \ 40{
41 int ret; \ 41 if (level == LIBBPF_DEBUG && !debug)
42 \ 42 return 0;
43 va_start(args, fmt); \ 43
44 if (enabled) { \ 44 fprintf(stderr, "[%d] ", level);
45 fprintf(stderr, "[" #name "] "); \ 45 return vfprintf(stderr, fmt, args);
46 ret = vfprintf(stderr, fmt, args); \
47 } \
48 va_end(args); \
49 return ret; \
50} 46}
51DEFINE_PRINT_FN(warning, 1)
52DEFINE_PRINT_FN(info, 1)
53DEFINE_PRINT_FN(debug, 1)
54 47
55#define EXIT_FAIL_LIBBPF EXIT_FAILURE 48#define EXIT_FAIL_LIBBPF EXIT_FAILURE
56#define EXIT_FAIL_OPTION 2 49#define EXIT_FAIL_OPTION 2
@@ -120,15 +113,14 @@ int main(int argc, char **argv)
120 int longindex = 0; 113 int longindex = 0;
121 int opt; 114 int opt;
122 115
123 libbpf_set_print(libbpf_warning, libbpf_info, NULL); 116 libbpf_set_print(libbpf_debug_print);
124 117
125 /* Parse commands line args */ 118 /* Parse commands line args */
126 while ((opt = getopt_long(argc, argv, "hDq", 119 while ((opt = getopt_long(argc, argv, "hDq",
127 long_options, &longindex)) != -1) { 120 long_options, &longindex)) != -1) {
128 switch (opt) { 121 switch (opt) {
129 case 'D': 122 case 'D':
130 libbpf_set_print(libbpf_warning, libbpf_info, 123 debug = 1;
131 libbpf_debug);
132 break; 124 break;
133 case 'q': /* Use in scripting mode */ 125 case 'q': /* Use in scripting mode */
134 verbose = 0; 126 verbose = 0;