tools/bpf: simplify libbpf API function libbpf_set_print()

Currently, the libbpf API function libbpf_set_print()
takes three function pointer parameters for warning, info
and debug printout respectively.

This patch changes the API to have just one function pointer
parameter and the function pointer has one additional
parameter "debugging level". So if in the future, if
the debug level is increased, the function signature
won't change.

Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Yonghong Song
2019-02-01 16:14:17 -08:00
committed by Alexei Starovoitov
parent 9d100a19ff
commit 6f1ae8b662
7 changed files with 68 additions and 76 deletions

View File

@ -10,6 +10,7 @@
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <stdarg.h>
#include <time.h>
#include <linux/types.h>
@ -1783,6 +1784,21 @@ static void test_task_fd_query_tp(void)
"sys_enter_read");
}
static int libbpf_debug_print(enum libbpf_print_level level,
const char *format, ...)
{
va_list args;
int ret;
if (level == LIBBPF_DEBUG)
return 0;
va_start(args, format);
ret = vfprintf(stderr, format, args);
va_end(args);
return ret;
}
static void test_reference_tracking()
{
const char *file = "./test_sk_lookup_kern.o";
@ -1809,9 +1825,9 @@ static void test_reference_tracking()
/* Expect verifier failure if test name has 'fail' */
if (strstr(title, "fail") != NULL) {
libbpf_set_print(NULL, NULL, NULL);
libbpf_set_print(NULL);
err = !bpf_program__load(prog, "GPL", 0);
libbpf_set_print(printf, printf, NULL);
libbpf_set_print(libbpf_debug_print);
} else {
err = bpf_program__load(prog, "GPL", 0);
}