]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
selftest/bpf: centralize libbpf logging management for test_progs
authorAndrii Nakryiko <andriin@fb.com>
Sun, 28 Jul 2019 03:25:27 +0000 (20:25 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Sun, 28 Jul 2019 05:36:19 +0000 (22:36 -0700)
Make test_progs test runner own libbpf logging. Also introduce two
levels of verbosity: -v and -vv. First one will be used in subsequent
patches to enable test log output always. Second one increases verbosity
level of libbpf logging further to include debug output as well.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c
tools/testing/selftests/bpf/prog_tests/reference_tracking.c
tools/testing/selftests/bpf/test_progs.c

index e1b55261526f2d4319bba42326cafed1c5e0cd91..ceddb8cc86f46c1a9fc34b615a6c85ae86d41b9f 100644 (file)
@@ -70,10 +70,11 @@ void test_bpf_verif_scale(void)
        const char *cg_sysctl[] = {
                "./test_sysctl_loop1.o", "./test_sysctl_loop2.o",
        };
+       libbpf_print_fn_t old_print_fn = NULL;
        int err, i;
 
        if (verifier_stats)
-               libbpf_set_print(libbpf_debug_print);
+               old_print_fn = libbpf_set_print(libbpf_debug_print);
 
        err = check_load("./loop3.o", BPF_PROG_TYPE_RAW_TRACEPOINT);
        printf("test_scale:loop3:%s\n", err ? (error_cnt--, "OK") : "FAIL");
@@ -97,4 +98,7 @@ void test_bpf_verif_scale(void)
 
        err = check_load("./test_seg6_loop.o", BPF_PROG_TYPE_LWT_SEG6LOCAL);
        printf("test_scale:test_seg6_loop:%s\n", err ? "FAIL" : "OK");
+
+       if (verifier_stats)
+               libbpf_set_print(old_print_fn);
 }
index 5633be43828fc59d3ba35b97de711f0e1bb30bdd..4a4f428d1a78e1732c1e71384017b9b1379624df 100644 (file)
@@ -1,15 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
 
-static int libbpf_debug_print(enum libbpf_print_level level,
-                             const char *format, va_list args)
-{
-       if (level == LIBBPF_DEBUG)
-               return 0;
-
-       return vfprintf(stderr, format, args);
-}
-
 void test_reference_tracking(void)
 {
        const char *file = "./test_sk_lookup_kern.o";
@@ -36,9 +27,11 @@ void test_reference_tracking(void)
 
                /* Expect verifier failure if test name has 'fail' */
                if (strstr(title, "fail") != NULL) {
-                       libbpf_set_print(NULL);
+                       libbpf_print_fn_t old_print_fn;
+
+                       old_print_fn = libbpf_set_print(NULL);
                        err = !bpf_program__load(prog, "GPL", 0);
-                       libbpf_set_print(libbpf_debug_print);
+                       libbpf_set_print(old_print_fn);
                } else {
                        err = bpf_program__load(prog, "GPL", 0);
                }
index 6e04b9f837777eef31455a7377da149df3bf5f23..94b6951b90b3852dd9e5ed6fab61264593d17551 100644 (file)
@@ -186,6 +186,8 @@ enum ARG_KEYS {
        ARG_TEST_NUM = 'n',
        ARG_TEST_NAME = 't',
        ARG_VERIFIER_STATS = 's',
+
+       ARG_VERBOSE = 'v',
 };
        
 static const struct argp_option opts[] = {
@@ -195,6 +197,8 @@ static const struct argp_option opts[] = {
          "Run tests with names containing NAME" },
        { "verifier-stats", ARG_VERIFIER_STATS, NULL, 0,
          "Output verifier statistics", },
+       { "verbose", ARG_VERBOSE, "LEVEL", OPTION_ARG_OPTIONAL,
+         "Verbose output (use -vv for extra verbose output)" },
        {},
 };
 
@@ -202,12 +206,22 @@ struct test_env {
        int test_num_selector;
        const char *test_name_selector;
        bool verifier_stats;
+       bool verbose;
+       bool very_verbose;
 };
 
 static struct test_env env = {
        .test_num_selector = -1,
 };
 
+static int libbpf_print_fn(enum libbpf_print_level level,
+                          const char *format, va_list args)
+{
+       if (!env.very_verbose && level == LIBBPF_DEBUG)
+               return 0;
+       return vfprintf(stderr, format, args);
+}
+
 static error_t parse_arg(int key, char *arg, struct argp_state *state)
 {
        struct test_env *env = state->input;
@@ -229,6 +243,19 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
        case ARG_VERIFIER_STATS:
                env->verifier_stats = true;
                break;
+       case ARG_VERBOSE:
+               if (arg) {
+                       if (strcmp(arg, "v") == 0) {
+                               env->very_verbose = true;
+                       } else {
+                               fprintf(stderr,
+                                       "Unrecognized verbosity setting ('%s'), only -v and -vv are supported\n",
+                                       arg);
+                               return -EINVAL;
+                       }
+               }
+               env->verbose = true;
+               break;
        case ARGP_KEY_ARG:
                argp_usage(state);
                break;
@@ -255,6 +282,8 @@ int main(int argc, char **argv)
        if (err)
                return err;
 
+       libbpf_set_print(libbpf_print_fn);
+
        srand(time(NULL));
 
        jit_enabled = is_jit_enabled();