selftests/bpf: abstract away test log output
This patch changes how test output is printed out. By default, if test had no errors, the only output will be a single line with test number, name, and verdict at the end, e.g.: #31 xdp:OK If test had any errors, all log output captured during test execution will be output after test completes. It's possible to force output of log with `-v` (`--verbose`) option, in which case output won't be buffered and will be output immediately. To support this, individual tests are required to use helper methods for logging: `test__printf()` and `test__vprintf()`. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:

committed by
Alexei Starovoitov

parent
329e38f76c
commit
0ff97e56c0
@@ -38,9 +38,33 @@ typedef __u16 __sum16;
|
||||
#include "trace_helpers.h"
|
||||
#include "flow_dissector_load.h"
|
||||
|
||||
extern int error_cnt, pass_cnt;
|
||||
extern bool jit_enabled;
|
||||
extern bool verifier_stats;
|
||||
struct prog_test_def;
|
||||
|
||||
struct test_env {
|
||||
int test_num_selector;
|
||||
const char *test_name_selector;
|
||||
bool verifier_stats;
|
||||
bool verbose;
|
||||
bool very_verbose;
|
||||
|
||||
bool jit_enabled;
|
||||
|
||||
struct prog_test_def *test;
|
||||
char *log_buf;
|
||||
size_t log_cnt;
|
||||
size_t log_cap;
|
||||
|
||||
int succ_cnt;
|
||||
int fail_cnt;
|
||||
};
|
||||
|
||||
extern int error_cnt;
|
||||
extern int pass_cnt;
|
||||
extern struct test_env env;
|
||||
|
||||
extern void test__printf(const char *fmt, ...);
|
||||
extern void test__vprintf(const char *fmt, va_list args);
|
||||
extern void test__force_log();
|
||||
|
||||
#define MAGIC_BYTES 123
|
||||
|
||||
@@ -64,11 +88,12 @@ extern struct ipv6_packet pkt_v6;
|
||||
int __ret = !!(condition); \
|
||||
if (__ret) { \
|
||||
error_cnt++; \
|
||||
printf("%s:FAIL:%s ", __func__, tag); \
|
||||
printf(format); \
|
||||
test__printf("%s:FAIL:%s ", __func__, tag); \
|
||||
test__printf(format); \
|
||||
} else { \
|
||||
pass_cnt++; \
|
||||
printf("%s:PASS:%s %d nsec\n", __func__, tag, duration);\
|
||||
test__printf("%s:PASS:%s %d nsec\n", \
|
||||
__func__, tag, duration); \
|
||||
} \
|
||||
__ret; \
|
||||
})
|
||||
|
Reference in New Issue
Block a user