From 67c08cfc9b5c28f95478592d4d1133f3919bab4d Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Fri, 21 May 2021 19:23:57 +0200 Subject: [PATCH] lib: test-event-filter-*: Hide details of tests unless they fail This removes ~14k lines of output from test-lib run. --- src/lib/test-event-filter-expr.c | 34 ++++++++++++++++++------------ src/lib/test-event-filter-merge.c | 25 ++++++++++++---------- src/lib/test-event-filter-parser.c | 27 +++++++++++++++--------- 3 files changed, 51 insertions(+), 35 deletions(-) diff --git a/src/lib/test-event-filter-expr.c b/src/lib/test-event-filter-expr.c index 0af8a982eb..444f16f252 100644 --- a/src/lib/test-event-filter-expr.c +++ b/src/lib/test-event-filter-expr.c @@ -13,7 +13,8 @@ #define SOURCE_FILENAME "blah.c" #define SOURCE_LINE 123 -static void check_expr(struct event *event, +static void check_expr(const char *test_name, + struct event *event, struct event_filter *filter, enum event_filter_log_type log_type, bool expected) @@ -24,36 +25,39 @@ static void check_expr(struct event *event, /* get at the expr inside the filter */ expr = event_filter_get_expr_for_testing(filter, &num_queries); - test_assert(num_queries == 1); /* should have only one query */ + test_out_quiet(t_strdup_printf("%s:num_queries==1", test_name), + num_queries == 1); /* should have only one query */ got = event_filter_query_match_eval(expr, event, SOURCE_FILENAME, SOURCE_LINE, log_type); - test_assert(got == expected); + test_out_quiet(t_strdup_printf("%s:got=expected", test_name), + got == expected); } static void do_test_expr(const char *filter_string, struct event *event, enum event_filter_log_type log_type, bool expected) { - const char *error; + const char *test_name, *error; - test_begin(t_strdup_printf("%.*s log type + event {a=%s, b=%s} + filter '%s' (exp %s)", - 3, /* truncate the type name to avoid CI seeing 'warning' messages */ - event_filter_category_from_log_type(log_type), - event_find_field_recursive_str(event, "a"), - event_find_field_recursive_str(event, "b"), - filter_string, - expected ? "true" : "false")); + test_name = t_strdup_printf( + "%.*s log type + event {a=%s, b=%s} + filter '%s' (exp %s)", + 3, /* truncate the type name to avoid CI seeing 'warning' messages */ + event_filter_category_from_log_type(log_type), + event_find_field_recursive_str(event, "a"), + event_find_field_recursive_str(event, "b"), + filter_string, + expected ? "true" : "false"); /* set up the filter expression */ struct event_filter *filter = event_filter_create(); - test_assert(event_filter_parse(filter_string, filter, &error) == 0); + test_out_quiet(t_strdup_printf("%s:event_filter_parse()", test_name), + event_filter_parse(filter_string, filter, &error) == 0); - check_expr(event, filter, log_type, expected); + check_expr(test_name, event, filter, log_type, expected); event_filter_unref(&filter); - test_end(); } static void test_unary_expr(struct event *event, @@ -239,6 +243,8 @@ void test_event_filter_expr(void) }; unsigned int i; + test_begin("event filter expressions"); for (i = 0; i < N_ELEMENTS(log_types); i++) test_event_filter_expr_fields(log_types[i]); + test_end(); } diff --git a/src/lib/test-event-filter-merge.c b/src/lib/test-event-filter-merge.c index c29e53352a..b520cf920f 100644 --- a/src/lib/test-event-filter-merge.c +++ b/src/lib/test-event-filter-merge.c @@ -7,22 +7,25 @@ static void filter_merge(const char *parent_str, const char *child_str) { struct event_filter *parent, *child; - const char *error; + const char *test_name, *error; string_t *out = t_str_new(128); - test_begin(t_strdup_printf("parent %s, child %s", - (parent_str == NULL) ? "NULL" : parent_str, - (child_str == NULL) ? "NULL" : child_str)); + test_name = t_strdup_printf("parent %s, child %s", + (parent_str == NULL) ? "NULL" : parent_str, + (child_str == NULL) ? "NULL" : child_str); parent = event_filter_create(); child = event_filter_create(); /* prime the filters with an expression */ - if (parent_str != NULL) - test_assert(event_filter_parse(parent_str, parent, &error) == 0); - if (child_str != NULL) - test_assert(event_filter_parse(child_str, child, &error) == 0); - + if (parent_str != NULL) { + test_out_quiet(t_strdup_printf("%s:parent", test_name), + event_filter_parse(parent_str, parent, &error) == 0); + } + if (child_str != NULL) { + test_out_quiet(t_strdup_printf("%s:child", test_name), + event_filter_parse(child_str, child, &error) == 0); + } /* merge */ event_filter_merge(parent, child); @@ -32,8 +35,6 @@ static void filter_merge(const char *parent_str, const char *child_str) event_filter_unref(&parent); event_filter_unref(&child); - - test_end(); } void test_event_filter_merge(void) @@ -56,9 +57,11 @@ void test_event_filter_merge(void) }; unsigned int i, j; + test_begin("event filter merge"); for (i = 0; i < N_ELEMENTS(inputs); i++) { for (j = 0; j < N_ELEMENTS(inputs); j++) T_BEGIN { filter_merge(inputs[i], inputs[j]); } T_END; } + test_end(); } diff --git a/src/lib/test-event-filter-parser.c b/src/lib/test-event-filter-parser.c index 3cfb7fe461..3dd265881e 100644 --- a/src/lib/test-event-filter-parser.c +++ b/src/lib/test-event-filter-parser.c @@ -223,12 +223,11 @@ static void testcase(const char *name, const char *input, const char *exp, const char *error; int ret; - test_begin(t_strdup_printf("event filter parser: %s", name)); - filter = event_filter_create(); ret = event_filter_parse(input, filter, &error); - test_assert((ret != 0) == fails); + test_out_quiet(name != NULL ? name : "filter parser", + (ret != 0) == fails); if (ret == 0) { string_t *tmp = t_str_new(128); @@ -243,20 +242,19 @@ static void testcase(const char *name, const char *input, const char *exp, } event_filter_unref(&filter); - - test_end(); } static void test_event_filter_parser_table(void) { unsigned int i; + test_begin("event filter parser: table"); for (i = 0; i < N_ELEMENTS(tests); i++) T_BEGIN { - testcase("table", - tests[i].input, + testcase(NULL, tests[i].input, tests[i].output, tests[i].fails); } T_END; + test_end(); } static void test_event_filter_parser_categories(void) @@ -266,6 +264,7 @@ static void test_event_filter_parser_categories(void) }; unsigned int i; + test_begin("event filter parser: log type category"); for (i = 0; i < N_ELEMENTS(cat_names); i++) T_BEGIN { string_t *str = t_str_new(128); @@ -273,8 +272,9 @@ static void test_event_filter_parser_categories(void) str_append(str, cat_names[i]); str_append(str, ")"); - testcase("log type category", str_c(str), str_c(str), FALSE); + testcase(NULL, str_c(str), str_c(str), FALSE); } T_END; + test_end(); } static void @@ -309,7 +309,7 @@ test_event_filter_parser_simple_nesting_helper(bool not1, bool not2, expr2, not2 ? ")" : ""); - testcase("simple nesting", in, exp, FALSE); + testcase(NULL, in, exp, FALSE); } static void test_event_filter_parser_simple_nesting(void) @@ -325,6 +325,7 @@ static void test_event_filter_parser_simple_nesting(void) unsigned int loc; unsigned int not; + test_begin("event filter parser: simple nesting"); for (i = 0; i < N_ELEMENTS(whitespace); i++) { for (not = 0; not < 4; not++) { const bool not1 = (not & 0x2) != 0; @@ -349,6 +350,7 @@ static void test_event_filter_parser_simple_nesting(void) } T_END; } } + test_end(); } /* @@ -435,6 +437,8 @@ static void test_event_filter_parser_generated(bool parens) { unsigned int w, v; + test_begin(t_strdup_printf("event filter parser: parser generated parens=%s", + parens ? "yes" : "no")); /* check that non-field keys work */ for (w = 0; w < N_ELEMENTS(what_special); w++) { for (v = 0; v < N_ELEMENTS(values_single); v++) @@ -518,11 +522,14 @@ static void test_event_filter_parser_generated(bool parens) QUOTE_MUST); } } + test_end(); } static void test_event_filter_parser_simple_invalid(void) { - testcase("simple invalid", "a=b=c", "", TRUE); + test_begin("event filter parser: simple invalid"); + testcase(NULL, "a=b=c", "", TRUE); + test_end(); } void test_event_filter_parser(void) -- 2.47.3