aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/test_libbpf_open.c
diff options
context:
space:
mode:
authorYonghong Song <yhs@fb.com>2019-02-01 16:14:17 -0800
committerAlexei Starovoitov <ast@kernel.org>2019-02-04 09:40:59 -0800
commit6f1ae8b6628b9e054d3a8c959cf472234944a578 (patch)
treea06e49a2ac5d5a35f3fb6a25c1ea689f3c6bfe40 /tools/testing/selftests/bpf/test_libbpf_open.c
parenttools/bpf: print out btf log at LIBBPF_WARN level (diff)
downloadlinux-dev-6f1ae8b6628b9e054d3a8c959cf472234944a578.tar.xz
linux-dev-6f1ae8b6628b9e054d3a8c959cf472234944a578.zip
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>
Diffstat (limited to 'tools/testing/selftests/bpf/test_libbpf_open.c')
-rw-r--r--tools/testing/selftests/bpf/test_libbpf_open.c36
1 files changed, 17 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..b9ff3bf76544 100644
--- a/tools/testing/selftests/bpf/test_libbpf_open.c
+++ b/tools/testing/selftests/bpf/test_libbpf_open.c
@@ -34,23 +34,22 @@ static void usage(char *argv[])
printf("\n");
}
-#define DEFINE_PRINT_FN(name, enabled) \
-static int libbpf_##name(const char *fmt, ...) \
-{ \
- va_list args; \
- int ret; \
- \
- va_start(args, fmt); \
- if (enabled) { \
- fprintf(stderr, "[" #name "] "); \
- ret = vfprintf(stderr, fmt, args); \
- } \
- va_end(args); \
- return ret; \
+static bool debug = 0;
+static int libbpf_debug_print(enum libbpf_print_level level,
+ const char *fmt, ...)
+{
+ va_list args;
+ int ret;
+
+ if (level == LIBBPF_DEBUG && !debug)
+ return 0;
+
+ va_start(args, fmt);
+ fprintf(stderr, "[%d] ", level);
+ ret = vfprintf(stderr, fmt, args);
+ va_end(args);
+ return ret;
}
-DEFINE_PRINT_FN(warning, 1)
-DEFINE_PRINT_FN(info, 1)
-DEFINE_PRINT_FN(debug, 1)
#define EXIT_FAIL_LIBBPF EXIT_FAILURE
#define EXIT_FAIL_OPTION 2
@@ -120,15 +119,14 @@ int main(int argc, char **argv)
int longindex = 0;
int opt;
- libbpf_set_print(libbpf_warning, libbpf_info, NULL);
+ libbpf_set_print(libbpf_debug_print);
/* Parse commands line args */
while ((opt = getopt_long(argc, argv, "hDq",
long_options, &longindex)) != -1) {
switch (opt) {
case 'D':
- libbpf_set_print(libbpf_warning, libbpf_info,
- libbpf_debug);
+ debug = 1;
break;
case 'q': /* Use in scripting mode */
verbose = 0;