Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the coverage report pretty #588

Merged
merged 3 commits into from
Mar 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions fuzzing/coverage/report_generation.go
Original file line number Diff line number Diff line change
@@ -22,6 +22,24 @@ var (
func WriteHTMLReport(sourceAnalysis *SourceAnalysis, reportDir string) (string, error) {
// Define mappings onto some useful variables/functions.
functionMap := template.FuncMap{
"formatNumber": func(num uint) string {
// Format large numbers to be more readable (e.g., 1234 → 1.2K, 1500000 → 1.5M)
if num < 1000 {
return fmt.Sprintf("%d", num) // Keep small numbers as is
} else if num < 1000000 {
// Format as K (thousands)
value := float64(num) / 1000.0
return fmt.Sprintf("%.1fK", value)
} else if num < 1000000000 {
// Format as M (millions)
value := float64(num) / 1000000.0
return fmt.Sprintf("%.1fM", value)
} else {
// Format as B (billions)
value := float64(num) / 1000000000.0
return fmt.Sprintf("%.1fB", value)
}
},
"timeNow": time.Now,
"add": func(x int, y int) int {
return x + y
@@ -40,6 +58,18 @@ func WriteHTMLReport(sourceAnalysis *SourceAnalysis, reportDir string) (string,

return relativePath
},
"filePathToId": func(path string) string {
// Convert a file path to a safe HTML ID by replacing non-alphanumeric characters with underscores
safeId := ""
for _, c := range path {
if (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') {
safeId += string(c)
} else {
safeId += "_"
}
}
return safeId
},
"percentageStr": func(x int, y int, decimals int) string {
// Determine our precision string
formatStr := "%." + strconv.Itoa(decimals) + "f"
@@ -56,6 +86,26 @@ func WriteHTMLReport(sourceAnalysis *SourceAnalysis, reportDir string) (string,
}
return int(math.Round(float64(x) / float64(y) * 100))
},
"getCoverageColor": func(percentage int) string {
// Color gradient: red (0%) -> yellow (50%) -> green (100%)
if percentage < 50 {
// Red to yellow (0-50%)
return fmt.Sprintf("hsl(%d, 90%%, 50%%)", int(float64(percentage)*1.2))
} else {
// Yellow to green (50-100%)
return fmt.Sprintf("hsl(%d, 90%%, 45%%)", 60+int(float64(percentage-50)*1.2))
}
},
"getCoverageColorAlpha": func(percentage int) string {
// Color gradient with alpha: red (0%) -> yellow (50%) -> green (100%)
if percentage < 50 {
// Red to yellow (0-50%)
return fmt.Sprintf("hsla(%d, 90%%, 50%%, 0.15)", int(float64(percentage)*1.2))
} else {
// Yellow to green (50-100%)
return fmt.Sprintf("hsla(%d, 90%%, 45%%, 0.15)", 60+int(float64(percentage-50)*1.2))
}
},
}

// Parse our HTML template
Loading