From 3db6a79df1b94985c0c6877158812e5cf53e8257 Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" <pesco@khjk.org> Date: Tue, 11 Feb 2020 18:07:43 +0100 Subject: [PATCH] print arena stats only when running test_suite --verbose i was trying to find out why the test suite suddenly insisted on being so noisy. turns out glib now does TAP by default and all messages get printed, --verbose or not. the old mode is considered deprecated. cf. https://en.wikipedia.org/wiki/Test_Anything_Protocol https://gitlab.gnome.org/GNOME/glib/commit/ad175766575b23be920f41cdb1c350447c743347 https://gitlab.gnome.org/GNOME/glib/commit/19aafc4ca4dba2b63d24f01d23890ff30ef9b133 --- src/test_suite.h | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/test_suite.h b/src/test_suite.h index e59f1c4..d81d9ea 100644 --- a/src/test_suite.h +++ b/src/test_suite.h @@ -96,6 +96,17 @@ #define g_check_parse_failed(p, be, input, len) \ g_check_parse_failed__m(&system_allocator, p, be, input, len) +#define print_arena_stats(arena) do { \ + if (g_test_verbose()) { \ + HArenaStats stats; \ + h_allocator_stats(arena, &stats); \ + g_test_message("Parse used %zd bytes, wasted %zd bytes. " \ + "Inefficiency: %5f%%", \ + stats.used, stats.wasted, \ + stats.wasted * 100. / (stats.used+stats.wasted)); \ + } \ + } while(0) + #define g_check_parse_ok(parser, backend, input, inp_len) do { \ int skip = h_compile((HParser *)(parser), (HParserBackend) backend, NULL); \ if(skip) { \ @@ -108,12 +119,7 @@ g_test_message("Parse failed on line %d", __LINE__); \ g_test_fail(); \ } else { \ - HArenaStats stats; \ - h_allocator_stats(res->arena, &stats); \ - g_test_message("Parse used %zd bytes, wasted %zd bytes. " \ - "Inefficiency: %5f%%", \ - stats.used, stats.wasted, \ - stats.wasted * 100. / (stats.used+stats.wasted)); \ + print_arena_stats(res->arena); \ h_parse_result_free(res); \ } \ } while(0) @@ -133,12 +139,7 @@ char* cres = h_write_result_unamb(res->ast); \ g_check_string(cres, ==, result); \ (&system_allocator)->free(&system_allocator, cres); \ - HArenaStats stats; \ - h_allocator_stats(res->arena, &stats); \ - g_test_message("Parse used %zd bytes, wasted %zd bytes. " \ - "Inefficiency: %5f%%", \ - stats.used, stats.wasted, \ - stats.wasted * 100. / (stats.used+stats.wasted)); \ + print_arena_stats(res->arena); \ h_parse_result_free(res); \ } \ } while(0) @@ -200,12 +201,7 @@ g_test_message("Parse failed on line %d", __LINE__); \ g_test_fail(); \ } else { \ - HArenaStats stats; \ - h_allocator_stats(res->arena, &stats); \ - g_test_message("Parse used %zd bytes, wasted %zd bytes. " \ - "Inefficiency: %5f%%", \ - stats.used, stats.wasted, \ - stats.wasted * 100. / (stats.used+stats.wasted)); \ + print_arena_stats(res->arena); \ h_parse_result_free(res); \ } \ } while(0) @@ -237,12 +233,7 @@ char* cres = h_write_result_unamb(res->ast); \ g_check_string(cres, ==, result); \ (&system_allocator)->free(&system_allocator, cres); \ - HArenaStats stats; \ - h_allocator_stats(res->arena, &stats); \ - g_test_message("Parse used %zd bytes, wasted %zd bytes. " \ - "Inefficiency: %5f%%", \ - stats.used, stats.wasted, \ - stats.wasted * 100. / (stats.used+stats.wasted)); \ + print_arena_stats(res->arena); \ h_parse_result_free(res); \ } \ } while(0) -- GitLab