Files
ToastyFS/scripts/generate_coverage_html.sh
T
Claude abaa12c5b3 Remove all CSS styling from HTML reports, use browser defaults
Remove all custom styling and CSS to use only plain HTML with
browser default rendering.

Changes:
- Remove all <style> tags and CSS
- Remove CSS classes from generated HTML
- Simplify source code display to plain text format
- Use simple line number: execution count: source code format
- Browser will render with its own default styles

The reports are now pure HTML with no styling at all.
2025-11-13 20:26:20 +00:00

165 lines
4.7 KiB
Bash
Executable File

#!/bin/bash
# Generate HTML coverage report from gcov files
set -e
OUTPUT_DIR="coverage_report"
mkdir -p "$OUTPUT_DIR"
# Create main index.html
cat > "$OUTPUT_DIR/index.html" <<'HTMLHEADER'
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Branch Coverage Report</title>
</head>
<body>
<h1>Branch Coverage Report</h1>
<p>Generated from random simulation coverage analysis</p>
<h2>Overall Coverage Summary</h2>
HTMLHEADER
# Calculate totals
TOTAL_BRANCHES=0
TAKEN_BRANCHES=0
for gcov_file in *.c.gcov; do
if [ -f "$gcov_file" ]; then
branches=$(grep -c "^branch" "$gcov_file" 2>/dev/null || echo "0")
if [ "$branches" -gt 0 ]; then
taken=$(grep "^branch" "$gcov_file" 2>/dev/null | grep -c "taken [1-9]" 2>/dev/null || echo "0")
taken=$(echo "$taken" | tr -d '[:space:]')
if [ -z "$taken" ]; then taken=0; fi
TOTAL_BRANCHES=$((TOTAL_BRANCHES + branches))
TAKEN_BRANCHES=$((TAKEN_BRANCHES + taken))
fi
fi
done
if [ "$TOTAL_BRANCHES" -gt 0 ]; then
COVERAGE_PERCENT=$((TAKEN_BRANCHES * 100 / TOTAL_BRANCHES))
cat >> "$OUTPUT_DIR/index.html" <<HTMLSUMMARY
<p>
<strong>Total Branches:</strong> $TOTAL_BRANCHES<br>
<strong>Branches Taken:</strong> $TAKEN_BRANCHES<br>
<strong>Coverage:</strong> ${COVERAGE_PERCENT}%
</p>
<h2>Coverage by File</h2>
<table>
<tr>
<th>File</th>
<th>Branches Taken</th>
<th>Total Branches</th>
<th>Coverage %</th>
</tr>
HTMLSUMMARY
# Generate table rows for each file
for gcov_file in *.c.gcov; do
if [ -f "$gcov_file" ]; then
filename=$(echo "$gcov_file" | sed 's/.gcov$//')
branches=$(grep -c "^branch" "$gcov_file" 2>/dev/null || echo "0")
if [ "$branches" -gt 0 ]; then
taken=$(grep "^branch" "$gcov_file" 2>/dev/null | grep -c "taken [1-9]" 2>/dev/null || echo "0")
taken=$(echo "$taken" | tr -d '[:space:]')
if [ -z "$taken" ]; then taken=0; fi
percentage=$((taken * 100 / branches))
# Generate individual file report
file_html="${filename}.html"
echo "Generating report for $filename..."
cat > "$OUTPUT_DIR/$file_html" <<FILEHEADER
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Coverage: $filename</title>
</head>
<body>
<p><a href="index.html">Back to Summary</a></p>
<h1>Coverage: $filename</h1>
<p><strong>Branches Taken:</strong> $taken / $branches ($percentage%)</p>
<pre>
FILEHEADER
# Process the gcov file and add source code with branch info
awk '
/^branch/ {
branch_info = branch_info " " $0
next
}
/^ / {
# Line with execution count
line_num = $2
gsub(/:/, "", line_num)
exec_count = $1
gsub(/^[ \t]+/, "", exec_count)
# Get the actual source line
line_content = substr($0, index($0, $3))
# Format execution count
if (exec_count == "-") {
exec_str = "-"
} else if (exec_count == "#####") {
exec_str = "0"
} else {
exec_str = exec_count
}
# Output line number, execution count, and source
printf "%6s: %5s:%s", line_num, exec_str, line_content
if (branch_info != "") {
printf " [%s]", branch_info
}
printf "\n"
branch_info = ""
}
' "$gcov_file" >> "$OUTPUT_DIR/$file_html"
cat >> "$OUTPUT_DIR/$file_html" <<'FILEFOOTER'
</pre>
</body>
</html>
FILEFOOTER
# Add row to main index
cat >> "$OUTPUT_DIR/index.html" <<TABLEROW
<tr>
<td><a href="$file_html">$filename</a></td>
<td>$taken</td>
<td>$branches</td>
<td>${percentage}%</td>
</tr>
TABLEROW
fi
fi
done
# Close HTML
cat >> "$OUTPUT_DIR/index.html" <<'HTMLFOOTER'
</table>
</body>
</html>
HTMLFOOTER
else
cat >> "$OUTPUT_DIR/index.html" <<'HTMLFOOTER'
<p>No branch coverage data found.</p>
</body>
</html>
HTMLFOOTER
fi
echo "HTML report generated in $OUTPUT_DIR/"