From 77eac31aee89346d1399193be6199b9b16fb77af Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Fri, 11 Apr 2003 04:52:29 +0000 Subject: 2003-04-11 Havoc Pennington * test/decode-gcov.c: add "below average functions" to the coverage report, and change how some of the code works. * bus/test-main.c: bracket some stuff in DBUS_BUILD_TESTS so it's not in the coverage stats. * test/test-service.c (main): use _dbus_verbose not fprintf in a couple places so running the test suite doesn't result in megaspam. --- test/decode-gcov.c | 170 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 110 insertions(+), 60 deletions(-) (limited to 'test/decode-gcov.c') diff --git a/test/decode-gcov.c b/test/decode-gcov.c index db6fef60..f7104bf3 100644 --- a/test/decode-gcov.c +++ b/test/decode-gcov.c @@ -400,6 +400,13 @@ struct Function char *name; Block *block_graph; int n_blocks; + /* number of blocks in DBUS_BUILD_TESTS */ + int n_test_blocks; + int n_test_blocks_executed; + /* number of blocks outside DBUS_BUILD_TESTS */ + int n_nontest_blocks; + int n_nontest_blocks_executed; + /* Summary result flags */ unsigned int unused : 1; unsigned int inside_dbus_build_tests : 1; unsigned int partial : 1; /* only some of the blocks were executed */ @@ -1180,35 +1187,6 @@ fill_line_content (const DBusString *str, } } -static void -mark_unused_functions (File *f) -{ - int i; - DBusList *link; - - link = _dbus_list_get_first_link (&f->functions); - while (link != NULL) - { - Function *func = link->data; - dbus_bool_t used; - - used = FALSE; - i = 0; - while (i < func->n_blocks) - { - if (func->block_graph[i].exec_count > 0) - used = TRUE; - - ++i; - } - - if (!used) - func->unused = TRUE; - - link = _dbus_list_get_next_link (&f->functions, link); - } -} - static void mark_inside_dbus_build_tests (File *f) { @@ -1287,7 +1265,7 @@ mark_inside_dbus_build_tests (File *f) } static void -mark_partials (File *f) +mark_coverage (File *f) { int i; DBusList *link; @@ -1327,25 +1305,49 @@ mark_partials (File *f) { Function *func = link->data; int i; - int n_blocks; - int n_blocks_executed; + int n_test_blocks; + int n_test_blocks_executed; + int n_nontest_blocks; + int n_nontest_blocks_executed; + + n_test_blocks = 0; + n_test_blocks_executed = 0; + n_nontest_blocks = 0; + n_nontest_blocks_executed = 0; - n_blocks = 0; - n_blocks_executed = 0; i = 0; while (i < func->n_blocks) { - /* Break as soon as any block is not a test block */ - if (func->block_graph[i].exec_count > 0) - n_blocks_executed += 1; + if (!func->block_graph[i].inside_dbus_build_tests) + { + n_nontest_blocks += 1; + + if (func->block_graph[i].exec_count > 0) + n_nontest_blocks_executed += 1; + } + else + { + n_test_blocks += 1; + + if (func->block_graph[i].exec_count > 0) + n_test_blocks_executed += 1; + } - n_blocks += 1; ++i; } - - if (n_blocks_executed > 0 && - n_blocks_executed < n_blocks) + + if (n_nontest_blocks_executed > 0 && + n_nontest_blocks_executed < n_nontest_blocks) func->partial = TRUE; + + if (n_nontest_blocks_executed == 0 && + n_nontest_blocks > 0) + func->unused = TRUE; + + func->n_test_blocks = n_test_blocks; + func->n_test_blocks_executed = n_test_blocks_executed; + func->n_nontest_blocks = n_nontest_blocks; + func->n_nontest_blocks_executed = n_nontest_blocks_executed; link = _dbus_list_get_next_link (&f->functions, link); } @@ -1392,9 +1394,8 @@ load_c_file (const DBusString *filename) load_block_line_associations (filename, f); - mark_unused_functions (f); mark_inside_dbus_build_tests (f); - mark_partials (f); + mark_coverage (f); return f; } @@ -1502,24 +1503,15 @@ merge_stats_for_file (Stats *stats, if (func->partial) stats->n_functions_partial += 1; } - - i = 0; - while (i < func->n_blocks) - { - Block *b = &func->block_graph[i]; - if (b->inside_dbus_build_tests) - stats->n_blocks_inside_dbus_build_tests += 1; - else - { - if (b->exec_count > 0) - stats->n_blocks_executed += 1; - - stats->n_blocks += 1; - } - - ++i; - } + stats->n_blocks_inside_dbus_build_tests += + func->n_test_blocks; + + stats->n_blocks_executed += + func->n_nontest_blocks_executed; + + stats->n_blocks += + func->n_nontest_blocks; link = _dbus_list_get_next_link (&f->functions, link); } @@ -1762,6 +1754,54 @@ print_untested_functions (File *f) printf ("\n"); } +static void +print_poorly_tested_functions (File *f, + Stats *stats) +{ + DBusList *link; + dbus_bool_t found; + +#define TEST_FRACTION(function) ((function)->n_nontest_blocks_executed / (double) (function)->n_nontest_blocks) + +#define AVERAGE_COVERAGE ((stats)->n_blocks_executed / (double) (stats)->n_blocks) + +#define POORLY_TESTED(function) (!(function)->unused && \ + (function)->n_nontest_blocks > 0 && \ + TEST_FRACTION (function) < AVERAGE_COVERAGE) + + found = FALSE; + link = _dbus_list_get_first_link (&f->functions); + while (link != NULL) + { + Function *func = link->data; + + if (POORLY_TESTED (func)) + found = TRUE; + + link = _dbus_list_get_next_link (&f->functions, link); + } + + if (!found) + return; + + printf ("Below average functions in %s\n", f->name); + printf ("=======\n"); + + link = _dbus_list_get_first_link (&f->functions); + while (link != NULL) + { + Function *func = link->data; + + if (POORLY_TESTED (func)) + printf (" %s (%d%%)\n", func->name, + (int) (TEST_FRACTION (func) * 100)); + + link = _dbus_list_get_next_link (&f->functions, link); + } + + printf ("\n"); +} + static void print_stats (Stats *stats, const char *of_what) @@ -1985,6 +2025,16 @@ main (int argc, char **argv) print_untested_functions (f); + link = _dbus_list_get_next_link (&files, link); + } + + link = _dbus_list_get_first_link (&files); + while (link != NULL) + { + File *f = link->data; + + print_poorly_tested_functions (f, &stats); + link = _dbus_list_get_next_link (&files, link); } } -- cgit