From 590662b1f60f8fd9b794f12cbc90c52b370702aa Mon Sep 17 00:00:00 2001
From: Nick Gasson
Date: Sun, 4 Aug 2024 18:28:57 +0100
Subject: [PATCH] Fix HTML validation errors in coverage report
---
src/cov/cov-report.c | 70 +++++++++++++++++++++++++-------------------
1 file changed, 40 insertions(+), 30 deletions(-)
diff --git a/src/cov/cov-report.c b/src/cov/cov-report.c
index a719b046f..a7fd16ed9 100644
--- a/src/cov/cov-report.c
+++ b/src/cov/cov-report.c
@@ -190,7 +190,7 @@ static cover_file_t *cover_file_for_scope(cover_scope_t *s)
static void cover_print_html_header(FILE *f)
{
fprintf(f, "\n"
- "\n"
+ "\n"
" \n"
" ");
@@ -243,7 +243,6 @@ static void cover_print_html_header(FILE *f)
" .tab {\n"
" overflow: hidden;\n"
" border: none;\n"
- " background-color: none;\n"
" margin-left: " MARGIN_LEFT ";\n"
" margin-top: 10px;\n"
" }\n"
@@ -256,7 +255,7 @@ static void cover_print_html_header(FILE *f)
" .tab button {\n"
" background-color: inherit;\n"
" float: left;\n"
- " margin-left: 20px\n"
+ " margin-left: 20px;\n"
" border: 2px solid black;\n"
" cursor: pointer;\n"
" padding: 14px 16px;\n"
@@ -279,9 +278,14 @@ static void cover_print_html_header(FILE *f)
" .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"
+ " .percent100 { background-color: #00cc00; }\n"
+ " .percent90 { background-color: #e6e600; }\n"
+ " .percent80 { background-color: #ff9900; }\n"
+ " .percent0 { background-color: #ff0000; }\n"
+ " .percentna { background-color: #aaaaaa; }\n"
" \n"
- " \n"
- " \n\n");
+ "\n"
+ "\n\n");
fprintf(f, "");
fprintf(f, COV_RPT_TITLE "\n");
@@ -335,22 +339,21 @@ static void cover_print_percents_cell(FILE *f, unsigned hit, unsigned total)
{
if (total > 0) {
float perc = ((float) hit / (float) total) * 100;
- char color[8];
+ const char *class = "percent0";
if (hit == total)
- checked_sprintf(color, sizeof(color), "#00cc00");
+ class = "percent100";
else if (perc > 90)
- checked_sprintf(color, sizeof(color), "#e6e600");
+ class = "percent90";
else if (perc > 80)
- checked_sprintf(color, sizeof(color), "#ff9900");
+ class = "percent80";
else
- checked_sprintf(color, sizeof(color), "#ff0000");
+ class = "percent0";
- fprintf(f, " %.1f %% (%d/%d) | \n",
- color, perc, hit, total);
- return;
+ fprintf(f, " %.1f %% (%d/%d) | \n",
+ class, perc, hit, total);
}
-
- fprintf(f, " N.A. | \n");
+ else
+ fprintf(f, " N.A. | \n");
}
static void cover_print_hierarchy_header(FILE *f)
@@ -378,12 +381,13 @@ static void cover_print_timestamp(FILE *f)
time_t t;
time(&t);
- fprintf(f, " \n");
-
fprintf(f, "");
+ fprintf(f, "\n");
+
+ fprintf(f, "\n");
+ fprintf(f, "\n");
}
static void cover_print_hierarchy_summary(FILE *f, cover_report_ctx_t *ctx, ident_t hier,
@@ -499,10 +503,15 @@ static void cover_print_hierarchy_summary(FILE *f, cover_report_ctx_t *ctx, iden
static inline void cover_print_char(FILE *f, char c)
{
- if (c == '\n' || c == ' ')
- fprintf(f, " ");
- else
- fprintf(f, "%c", c);
+ switch (c) {
+ case '\n':
+ case ' ': fputs(" ", f); break;
+ case '<': fputs("<", f); break;
+ case '>': fputs(">", f); break;
+ case '&': fputs("&", f); break;
+ case '\t': // TODO: handle tabs better
+ default: fputc(c, f); break;
+ }
}
static void cover_print_single_code_line(FILE *f, loc_t loc, cover_line_t *line)
@@ -824,7 +833,7 @@ static void cover_print_pairs(FILE *f, cover_pair_t *first, cov_pair_kind_t pkin
int step;
do {
- fprintf(f, " ");
+ if (curr > first) fprintf(f, "
");
step = curr->item->consecutive;
@@ -894,12 +903,11 @@ static void cover_print_pairs(FILE *f, cover_pair_t *first, cov_pair_kind_t pkin
curr->item->kind);
}
- fprintf(f, "
");
- fprintf(f, "
\n");
-
curr += step;
} while (curr <= last);
+
+ fprintf(f, "\n");
}
static void cover_print_chain(FILE *f, cover_data_t *data, cover_chain_t *chn,
@@ -916,7 +924,7 @@ static void cover_print_chain(FILE *f, cover_data_t *data, cover_chain_t *chn,
else if (kind == COV_ITEM_EXPRESSION)
fprintf(f, "Expression");
else if (kind == COV_ITEM_STATE)
- fprintf(f, "FSM state");
+ fprintf(f, "FSM_state");
else if (kind == COV_ITEM_FUNCTIONAL)
fprintf(f, "Functional");
@@ -976,8 +984,10 @@ static void cover_print_chain(FILE *f, cover_data_t *data, cover_chain_t *chn,
fprintf(f, "functional coverage:");
fprintf(f, "\n");
- fprintf(f, " \n");
+ fprintf(f, " \n");
cover_print_pairs(f, first_pair, pkind, n);
+ fprintf(f, "
\n");
+
fprintf(f, " \n\n");
}
@@ -991,7 +1001,7 @@ static void cover_print_hierarchy_guts(FILE *f, cover_report_ctx_t *ctx)
" \n"
" \n"
" \n"
- " \n"
+ " \n"
" \n"
"\n\n");
@@ -1003,7 +1013,6 @@ static void cover_print_hierarchy_guts(FILE *f, cover_report_ctx_t *ctx)
cover_print_chain(f, ctx->data, &(ctx->ch_functional), COV_ITEM_FUNCTIONAL);
fprintf(f, "\n");
}