add memory limit
This commit is contained in:
@@ -34,8 +34,15 @@ func Text(w io.Writer, result *runner.SuiteResult) {
|
||||
if tr.Status != runner.StatusPass {
|
||||
icon = "✗"
|
||||
}
|
||||
fmt.Fprintf(w, "│ %s [%s] %s (%dms)\n",
|
||||
icon, tr.Status, tr.Name, tr.Elapsed.Milliseconds())
|
||||
mem := ""
|
||||
if tr.PeakMemory > 0 {
|
||||
mem = fmt.Sprintf(", %s", humanBytes(tr.PeakMemory))
|
||||
if tr.MemoryLimit > 0 {
|
||||
mem = fmt.Sprintf(", %s/%s", humanBytes(tr.PeakMemory), humanBytes(tr.MemoryLimit))
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(w, "│ %s [%s] %s (%dms%s)\n",
|
||||
icon, tr.Status, tr.Name, tr.Elapsed.Milliseconds(), mem)
|
||||
|
||||
for _, f := range tr.Failures {
|
||||
for _, line := range strings.Split(f, "\n") {
|
||||
@@ -71,10 +78,12 @@ type jsonGroupResult struct {
|
||||
}
|
||||
|
||||
type jsonTestResult struct {
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
ElapsedMs int64 `json:"elapsed_ms"`
|
||||
Failures []string `json:"failures,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
ElapsedMs int64 `json:"elapsed_ms"`
|
||||
PeakMemoryKB int64 `json:"peak_memory_kb,omitempty"`
|
||||
MemoryLimitKB int64 `json:"memory_limit_kb,omitempty"`
|
||||
Failures []string `json:"failures,omitempty"`
|
||||
}
|
||||
|
||||
func Aggregate(w io.Writer, dir string) error {
|
||||
@@ -131,6 +140,24 @@ func Aggregate(w io.Writer, dir string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func humanBytes(n int64) string {
|
||||
const (
|
||||
KiB = 1024
|
||||
MiB = 1024 * KiB
|
||||
GiB = 1024 * MiB
|
||||
)
|
||||
switch {
|
||||
case n >= GiB:
|
||||
return fmt.Sprintf("%.2fGiB", float64(n)/float64(GiB))
|
||||
case n >= MiB:
|
||||
return fmt.Sprintf("%.1fMiB", float64(n)/float64(MiB))
|
||||
case n >= KiB:
|
||||
return fmt.Sprintf("%.0fKiB", float64(n)/float64(KiB))
|
||||
default:
|
||||
return fmt.Sprintf("%dB", n)
|
||||
}
|
||||
}
|
||||
|
||||
func jsonResult(r *runner.SuiteResult) jsonSuiteResult {
|
||||
res := jsonSuiteResult{
|
||||
TotalScore: r.TotalScore,
|
||||
@@ -146,10 +173,12 @@ func jsonResult(r *runner.SuiteResult) jsonSuiteResult {
|
||||
}
|
||||
for _, tr := range gr.Tests {
|
||||
jgr.Tests = append(jgr.Tests, jsonTestResult{
|
||||
Name: tr.Name,
|
||||
Status: tr.Status.String(),
|
||||
ElapsedMs: tr.Elapsed.Milliseconds(),
|
||||
Failures: tr.Failures,
|
||||
Name: tr.Name,
|
||||
Status: tr.Status.String(),
|
||||
ElapsedMs: tr.Elapsed.Milliseconds(),
|
||||
PeakMemoryKB: tr.PeakMemory / 1024,
|
||||
MemoryLimitKB: tr.MemoryLimit / 1024,
|
||||
Failures: tr.Failures,
|
||||
})
|
||||
}
|
||||
res.Groups = append(res.Groups, jgr)
|
||||
|
||||
Reference in New Issue
Block a user