From 42963c953c6465c07678536156e256ac8cd06aba Mon Sep 17 00:00:00 2001 From: Ondrej Ille Date: Fri, 7 Jul 2023 17:06:09 +0200 Subject: [PATCH 1/2] src/cover: Format printed HTML nicely for debug. Avoid printing past text buffer. Dont print newlines in code samples. --- src/rt/cover.c | 183 ++++++++++++++++++++++++------------------------- 1 file changed, 90 insertions(+), 93 deletions(-) diff --git a/src/rt/cover.c b/src/rt/cover.c index db2fc0add..5a7ca3d4d 100644 --- a/src/rt/cover.c +++ b/src/rt/cover.c @@ -1344,22 +1344,20 @@ static void cover_print_html_header(FILE *f, cover_report_ctx_t *ctx, bool top, fprintf(f, "\n" "\n" " \n" - " \n"); + " <title>"); va_list ap; va_start(ap, title); vfprintf(f, title, ap); va_end(ap); - fprintf(f, " \n" + fprintf(f, "\n" " \n" " \n" - "
\n"); + "
\n\n"); if (!top) { - fprintf(f, "\n\n"); } - fprintf(f, "
\n"); + fprintf(f, "
"); va_start(ap, title); vfprintf(f, title, ap); va_end(ap); - fprintf(f, "
\n"); + fprintf(f, "
\n\n"); - fprintf(f, "

\n"); + fprintf(f, "

\n"); if (!top) - fprintf(f, " Instance: %s\n", istr(s->hier)); + fprintf(f, " Instance: %s\n", istr(s->hier)); else - fprintf(f, " Instance:"); - fprintf(f, "

\n"); + fprintf(f, " Instance:"); + fprintf(f, "\n\n"); cover_file_t *src = cover_file(&(s->loc)); - fprintf(f, "

\n"); + fprintf(f, "

\n"); if (!top) - fprintf(f, " File:  ../../%s\n", + fprintf(f, " File:  ../../%s\n", src->name, src->name); else - fprintf(f, " File:"); - fprintf(f, "

\n"); + fprintf(f, " File:"); + fprintf(f, "\n\n"); } static void cover_print_percents_cell(FILE *f, unsigned hit, unsigned total) @@ -1491,30 +1480,30 @@ static void cover_print_percents_cell(FILE *f, unsigned hit, unsigned total) else checked_sprintf(color, sizeof(color), "#ff0000"); - fprintf(f, " %.1f %% (%d/%d)\n", + fprintf(f, " %.1f %% (%d/%d)\n", color, perc, hit, total); return; } - fprintf(f, " N.A.\n"); + fprintf(f, " N.A.\n"); } static void cover_print_hierarchy_header(FILE *f) { fprintf(f, " \n" " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" " \n"); } static void cover_print_hierarchy_footer(FILE *f) { - fprintf(f, "
InstanceStatementBranchToggleExpressionAverageInstanceStatementBranchToggleExpressionAverage
\n"); + fprintf(f, "\n\n"); } static void cover_print_timestamp(FILE *f) @@ -1541,8 +1530,8 @@ static void cover_print_hierarchy_summary(FILE *f, cover_report_ctx_t *ctx, iden else stats = &(ctx->nested_stats); - fprintf(f, " \n" - " %s\n", + fprintf(f, " \n" + " %s\n", top ? "hier/" : "", istr(hier), istr(print_hier)); cover_print_percents_cell(f, stats->hit_stmts, stats->total_stmts); @@ -1557,7 +1546,7 @@ static void cover_print_hierarchy_summary(FILE *f, cover_report_ctx_t *ctx, iden cover_print_percents_cell(f, avg_hit, avg_total); - fprintf(f, " \n"); + fprintf(f, " \n"); float perc_stmt = 0.0f; float perc_branch = 0.0f; @@ -1622,13 +1611,21 @@ static void cover_print_code_line(FILE *f, loc_t loc, cover_line_t *line) fprintf(f, " "); int last = strlen(line->text); int curr = 0; - while (curr <= last) { + while (curr < last) { + + // Highlight code location if (curr == loc.first_column) fprintf(f, ""); - fprintf(f, "%c", line->text[curr]); + + char c = line->text[curr]; + if (c != '\n') + fprintf(f, "%c", c); + + // Finish code highlight if (curr == (loc.first_column + loc.column_delta) && loc.line_delta == 0) fprintf(f, ""); + curr++; } if (loc.line_delta > 0) @@ -1776,7 +1773,7 @@ static void cover_print_bins(FILE *f, cover_pair_t *pair, cov_pair_kind_t pkind) static void cover_print_pair(FILE *f, cover_pair_t *pair, cov_pair_kind_t pkind) { loc_t loc = pair->tag->loc; - fprintf(f, "

"); + fprintf(f, "

"); switch (pair->tag->kind) { case TAG_STMT: @@ -1823,7 +1820,7 @@ static void cover_print_pair(FILE *f, cover_pair_t *pair, cov_pair_kind_t pkind) default: fatal("unsupported type of code coverage: %d !", pair->tag->kind); } - fprintf(f, "

"); + fprintf(f, "

\n"); } static void cover_print_chain(FILE *f, cover_tagging_t *tagging, @@ -1866,15 +1863,15 @@ static void cover_print_chain(FILE *f, cover_tagging_t *tagging, n = chn->n_hits; } - fprintf(f, "
"); + fprintf(f, "#ffcccc;\">\n"); else if (pkind == PAIR_EXCLUDED) - fprintf(f, "#d6eaf8;\">"); + fprintf(f, "#d6eaf8;\">\n"); else - fprintf(f, "#ccffcc;\">"); + fprintf(f, "#ccffcc;\">\n"); - fprintf(f, "

"); + fprintf(f, "

"); if (pkind == PAIR_UNCOVERED) fprintf(f, "Uncovered "); else if (pkind == PAIR_EXCLUDED) @@ -1890,14 +1887,14 @@ static void cover_print_chain(FILE *f, cover_tagging_t *tagging, fprintf(f, "toggles:"); else if (kind == TAG_EXPRESSION) fprintf(f, "expressions:"); - fprintf(f, "

"); + fprintf(f, "\n"); - fprintf(f, "
\n"); for (int j = 0; j < n; j++) { cover_print_pair(f, pair, pkind); pair++; } - fprintf(f, "
"); + fprintf(f, "
\n\n"); } fprintf(f, "\n"); @@ -1910,7 +1907,7 @@ static void cover_print_hierarchy_guts(FILE *f, cover_report_ctx_t *ctx) " \n" " \n" " \n" - "\n"); + "\n\n"); cover_print_chain(f, ctx->tagging, &(ctx->ch_stmt), TAG_STMT); cover_print_chain(f, ctx->tagging, &(ctx->ch_branch), TAG_BRANCH); @@ -2201,7 +2198,7 @@ static void cover_report_hierarchy(cover_report_ctx_t *ctx, cover_print_html_header(f, ctx, false, s, "NVC code coverage report"); - fprintf(f, "

Sub-instances:

\n"); + fprintf(f, "

\n Sub-instances:\n

\n\n"); cover_print_hierarchy_header(f); int skipped = 0; @@ -2209,16 +2206,16 @@ static void cover_report_hierarchy(cover_report_ctx_t *ctx, cover_print_hierarchy_footer(f); - fprintf(f, "

Current Instance:

\n"); + fprintf(f, "

\n Current Instance:\n

\n\n"); cover_print_hierarchy_header(f); cover_print_hierarchy_summary(f, ctx, s->hier, false, true, true); cover_print_hierarchy_footer(f); - fprintf(f, "

Details:

\n"); + fprintf(f, "

\n Details:\n

\n\n"); if (skipped) fprintf(f, "

The limit of " "printed items was reached (%d). Total %d items are not " - "displayed.

", ctx->tagging->report_item_limit, skipped); + "displayed.\n\n", ctx->tagging->report_item_limit, skipped); cover_print_hierarchy_guts(f, ctx); cover_print_timestamp(f); From 05a35dea04d56db3361af22b6051a173065611aa Mon Sep 17 00:00:00 2001 From: Ondrej Ille Date: Fri, 7 Jul 2023 18:02:31 +0200 Subject: [PATCH 2/2] src: Reduce size of generated coverage report, add CSS classes for common properties. --- src/rt/cover.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/rt/cover.c b/src/rt/cover.c index 5a7ca3d4d..a51f7efd2 100644 --- a/src/rt/cover.c +++ b/src/rt/cover.c @@ -1417,6 +1417,23 @@ static void cover_print_html_header(FILE *f, cover_report_ctx_t *ctx, bool top, " padding: 14px 16px;\n" " font-size: 17px;\n" " }\n" + " .cbg {\n" + " background-color: #bbbbbb;\n" + " }\n" + " .cbt {\n" + " margin-top: 8px;\n" + " }\n" + " .cbt th {\n" + " background-color: #bbbbbb;\n" + " text-align: center;\n" + " }\n" + " .cbt td, .cbt th {\n" + " width:50px;\n" + " text-align: center;\n" + " }\n" + " .cbt td + td, .cbt th + th { width:150px; }\n" + " .cbt td + td + td, .cbt th + th + th { width:150px; }\n" + " .cbt td + td + td + td, .cbt th + th + th + th { width:150px; }\n" " \n" " \n" "
\n\n"); @@ -1492,12 +1509,12 @@ static void cover_print_hierarchy_header(FILE *f) { fprintf(f, " \n" " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" " \n"); } @@ -1615,7 +1632,7 @@ static void cover_print_code_line(FILE *f, loc_t loc, cover_line_t *line) // Highlight code location if (curr == loc.first_column) - fprintf(f, ""); + fprintf(f, ""); char c = line->text[curr]; if (c != '\n') @@ -1689,19 +1706,18 @@ static void cover_print_bin_header(FILE *f, cov_pair_kind_t pkind, int cols, ... va_list argp; va_start(argp, cols); - fprintf(f, ""); - fprintf(f, ""); + fprintf(f, ""); for (int i = 0; i < cols; i++) { const char *val = va_arg(argp, const char *); - fprintf(f, "", val); + fprintf(f, "", val); } if (pkind == PAIR_UNCOVERED) - fprintf(f, ""); + fprintf(f, ""); if (pkind == PAIR_EXCLUDED) - fprintf(f, ""); + fprintf(f, ""); fprintf(f, ""); } @@ -1710,7 +1726,7 @@ static void cover_print_bins(FILE *f, cover_pair_t *pair, cov_pair_kind_t pkind) { loc_t loc = pair->tag->loc; - fprintf(f, "
InstanceStatementBranchToggleExpressionAverageInstanceStatementBranchToggleExpressionAverage
%s%sExclude CommandExclude CommandExcluded due toExcluded due to
"); + fprintf(f, "
"); switch (pair->tag->kind) { case TAG_BRANCH: @@ -1871,7 +1887,7 @@ static void cover_print_chain(FILE *f, cover_tagging_t *tagging, else fprintf(f, "#ccffcc;\">\n"); - fprintf(f, "

"); + fprintf(f, "

"); if (pkind == PAIR_UNCOVERED) fprintf(f, "Uncovered "); else if (pkind == PAIR_EXCLUDED)