Skip to content

Commit 2364b3a

Browse files
committed
initial test262 scheduler
1 parent b37545a commit 2364b3a

File tree

7 files changed

+514
-20
lines changed

7 files changed

+514
-20
lines changed

Cargo.lock

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/yavashark_test262/runner/go.mod

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,15 @@ module yavashark_test262_runner
22

33
go 1.23.2
44

5-
require github.com/BurntSushi/toml v1.5.0 // indirect
5+
require (
6+
github.com/BurntSushi/toml v1.5.0
7+
github.com/schollz/progressbar/v3 v3.14.1
8+
)
9+
10+
require (
11+
github.com/mattn/go-runewidth v0.0.15 // indirect
12+
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
13+
github.com/rivo/uniseg v0.4.7 // indirect
14+
golang.org/x/sys v0.21.0 // indirect
15+
golang.org/x/term v0.21.0 // indirect
16+
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
2+
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
package progress
2+
3+
import (
4+
"fmt"
5+
"sync"
6+
"sync/atomic"
7+
"yavashark_test262_runner/status"
8+
)
9+
10+
const (
11+
ColorGreen = "\033[32m"
12+
ColorRed = "\033[31m"
13+
ColorYellow = "\033[33m"
14+
ColorBlue = "\033[34m"
15+
ColorMagenta = "\033[35m"
16+
ColorCyan = "\033[36m"
17+
ColorReset = "\033[0m"
18+
ColorGray = "\033[90m"
19+
)
20+
21+
type ProgressTracker struct {
22+
mu sync.Mutex
23+
24+
passed atomic.Uint32
25+
failed atomic.Uint32
26+
skipped atomic.Uint32
27+
timeout atomic.Uint32
28+
crashed atomic.Uint32
29+
parseError atomic.Uint32
30+
parseSuccessError atomic.Uint32
31+
notImplemented atomic.Uint32
32+
runnerError atomic.Uint32
33+
total atomic.Uint32
34+
lastPrintedProgress atomic.Uint32
35+
36+
totalTests uint32
37+
}
38+
39+
func NewProgressTracker(totalTests uint32) *ProgressTracker {
40+
return &ProgressTracker{
41+
totalTests: totalTests,
42+
}
43+
}
44+
45+
func (pt *ProgressTracker) Add(s status.Status) {
46+
switch s {
47+
case status.PASS:
48+
pt.passed.Add(1)
49+
case status.FAIL:
50+
pt.failed.Add(1)
51+
case status.SKIP:
52+
pt.skipped.Add(1)
53+
case status.TIMEOUT:
54+
pt.timeout.Add(1)
55+
case status.CRASH:
56+
pt.crashed.Add(1)
57+
case status.PARSE_ERROR:
58+
pt.parseError.Add(1)
59+
case status.PARSE_SUCCESS_ERROR:
60+
pt.parseSuccessError.Add(1)
61+
case status.NOT_IMPLEMENTED:
62+
pt.notImplemented.Add(1)
63+
case status.RUNNER_ERROR:
64+
pt.runnerError.Add(1)
65+
}
66+
67+
current := pt.total.Add(1)
68+
pt.updateProgress(current)
69+
}
70+
71+
func (pt *ProgressTracker) updateProgress(current uint32) {
72+
lastPrinted := pt.lastPrintedProgress.Load()
73+
74+
threshold := uint32(100)
75+
if pt.totalTests > 0 {
76+
percentThreshold := pt.totalTests / 50 // 2%
77+
if percentThreshold > threshold {
78+
threshold = percentThreshold
79+
}
80+
}
81+
82+
if current-lastPrinted >= threshold || current == pt.totalTests {
83+
if pt.lastPrintedProgress.CompareAndSwap(lastPrinted, current) {
84+
pt.printProgressBar(current)
85+
}
86+
}
87+
}
88+
89+
func (pt *ProgressTracker) printProgressBar(current uint32) {
90+
passed := pt.passed.Load()
91+
failed := pt.failed.Load()
92+
skipped := pt.skipped.Load()
93+
timeout := pt.timeout.Load()
94+
crashed := pt.crashed.Load()
95+
96+
barWidth := 50
97+
passedWidth := int(float64(passed) / float64(current) * float64(barWidth))
98+
failedWidth := int(float64(failed) / float64(current) * float64(barWidth))
99+
skippedWidth := int(float64(skipped) / float64(current) * float64(barWidth))
100+
timeoutWidth := int(float64(timeout) / float64(current) * float64(barWidth))
101+
crashedWidth := int(float64(crashed) / float64(current) * float64(barWidth))
102+
otherWidth := barWidth - passedWidth - failedWidth - skippedWidth - timeoutWidth - crashedWidth
103+
104+
bar := ""
105+
if passedWidth > 0 {
106+
bar += ColorGreen + repeatChar("█", passedWidth) + ColorReset
107+
}
108+
if failedWidth > 0 {
109+
bar += ColorRed + repeatChar("█", failedWidth) + ColorReset
110+
}
111+
if timeoutWidth > 0 {
112+
bar += ColorYellow + repeatChar("█", timeoutWidth) + ColorReset
113+
}
114+
if crashedWidth > 0 {
115+
bar += ColorMagenta + repeatChar("█", crashedWidth) + ColorReset
116+
}
117+
if skippedWidth > 0 {
118+
bar += ColorCyan + repeatChar("█", skippedWidth) + ColorReset
119+
}
120+
if otherWidth > 0 {
121+
bar += ColorGray + repeatChar("░", otherWidth) + ColorReset
122+
}
123+
124+
percentage := float64(current) / float64(pt.totalTests) * 100
125+
126+
fmt.Printf("\r[%s] %3d%% (%d/%d) | %sP:%d%s %sF:%d%s %sT:%d%s %sC:%d%s %sS:%d%s",
127+
bar,
128+
int(percentage),
129+
current,
130+
pt.totalTests,
131+
ColorGreen, passed, ColorReset,
132+
ColorRed, failed, ColorReset,
133+
ColorYellow, timeout, ColorReset,
134+
ColorMagenta, crashed, ColorReset,
135+
ColorCyan, skipped, ColorReset,
136+
)
137+
}
138+
139+
func (pt *ProgressTracker) GetStats() (passed, failed, skipped, timeout, crashed, parseError, parseSuccessError, notImplemented, runnerError, total uint32) {
140+
return pt.passed.Load(), pt.failed.Load(), pt.skipped.Load(), pt.timeout.Load(), pt.crashed.Load(),
141+
pt.parseError.Load(), pt.parseSuccessError.Load(), pt.notImplemented.Load(), pt.runnerError.Load(),
142+
pt.total.Load()
143+
}
144+
145+
func repeatChar(char string, count int) string {
146+
result := ""
147+
for i := 0; i < count; i++ {
148+
result += char
149+
}
150+
return result
151+
}

crates/yavashark_test262/runner/results/results.go

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ import (
88
"yavashark_test262_runner/status"
99
)
1010

11+
const (
12+
ColorGreen = "\033[32m"
13+
ColorRed = "\033[31m"
14+
ColorYellow = "\033[33m"
15+
ColorBlue = "\033[34m"
16+
ColorMagenta = "\033[35m"
17+
ColorCyan = "\033[36m"
18+
ColorReset = "\033[0m"
19+
ColorBold = "\033[1m"
20+
ColorDim = "\033[2m"
21+
)
22+
1123
type TestResults struct {
1224
TestResults []Result
1325
Passed uint32
@@ -212,7 +224,119 @@ func (tr *TestResults) Compare(other *TestResults) {
212224
printDiff("Timeout", tr.Timeout, other.Timeout, tr.Total)
213225
printDiff("Parse Error", tr.ParseError, other.ParseError, tr.Total)
214226
printDiff("Total", tr.Total, other.Total, tr.Total)
227+
}
228+
229+
func (tr *TestResults) PrintResultsWithDiff(other *TestResults) {
230+
fmt.Printf("\n%s=== Test Results Summary ===%s\n\n", ColorBold, ColorReset)
231+
232+
fmt.Printf("%sCurrent Run:%s\n", ColorBold, ColorReset)
233+
tr.printResultsLine("Passed", tr.Passed, tr.Total, other.Passed)
234+
tr.printResultsLine("Failed", tr.Failed, tr.Total, other.Failed)
235+
tr.printResultsLine("Timeout", tr.Timeout, tr.Total, other.Timeout)
236+
tr.printResultsLine("Crashed", tr.Crashed, tr.Total, other.Crashed)
237+
tr.printResultsLine("Skipped", tr.Skipped, tr.Total, other.Skipped)
238+
tr.printResultsLine("Not Implemented", tr.NotImplemented, tr.Total, other.NotImplemented)
239+
tr.printResultsLine("Runner Error", tr.RunnerError, tr.Total, other.RunnerError)
240+
tr.printResultsLine("Parse Error", tr.ParseError, tr.Total, other.ParseError)
241+
tr.printResultsLine("Parse Success Error", tr.ParseSuccessError, tr.Total, other.ParseSuccessError)
242+
243+
fmt.Printf("\n%sTotal: %d%s\n", ColorBold, tr.Total, ColorReset)
244+
245+
fmt.Printf("\n%s=== Net Changes ===%s\n", ColorBold, ColorReset)
246+
netPassed := int32(tr.Passed) - int32(other.Passed)
247+
netFailed := int32(tr.Failed) - int32(other.Failed)
248+
netTimeout := int32(tr.Timeout) - int32(other.Timeout)
249+
netCrashed := int32(tr.Crashed) - int32(other.Crashed)
250+
251+
if netPassed != 0 {
252+
if netPassed > 0 {
253+
fmt.Printf("%s✓ Passed: +%d%s (gained)\n", ColorGreen, netPassed, ColorReset)
254+
} else {
255+
fmt.Printf("%s✗ Passed: %d%s (lost)\n", ColorRed, netPassed, ColorReset)
256+
}
257+
}
258+
259+
if netFailed != 0 {
260+
if netFailed > 0 {
261+
fmt.Printf("%s✗ Failed: +%d%s (gained)\n", ColorRed, netFailed, ColorReset)
262+
} else {
263+
fmt.Printf("%s✓ Failed: %d%s (improved)\n", ColorGreen, netFailed, ColorReset)
264+
}
265+
}
266+
267+
if netTimeout != 0 {
268+
if netTimeout > 0 {
269+
fmt.Printf("%s⏱ Timeout: +%d%s (gained)\n", ColorYellow, netTimeout, ColorReset)
270+
} else {
271+
fmt.Printf("%s✓ Timeout: %d%s (improved)\n", ColorGreen, netTimeout, ColorReset)
272+
}
273+
}
274+
275+
if netCrashed != 0 {
276+
if netCrashed > 0 {
277+
fmt.Printf("%s💥 Crashed: +%d%s (gained)\n", ColorMagenta, netCrashed, ColorReset)
278+
} else {
279+
fmt.Printf("%s✓ Crashed: %d%s (improved)\n", ColorGreen, netCrashed, ColorReset)
280+
}
281+
}
282+
283+
// Overall summary
284+
fmt.Printf("\n%s=== Overall Summary ===%s\n", ColorBold, ColorReset)
285+
totalChanges := abs(netPassed) + abs(netFailed) + abs(netTimeout) + abs(netCrashed)
286+
if totalChanges > 0 {
287+
fmt.Printf("Total test status changes: %d\n", totalChanges)
288+
289+
passedGained := 0
290+
if netPassed > 0 {
291+
passedGained = int(netPassed)
292+
}
293+
failedLost := 0
294+
if netFailed < 0 {
295+
failedLost = int(-netFailed)
296+
}
297+
improvements := passedGained + failedLost
215298

299+
if improvements > 0 {
300+
fmt.Printf("%s↑ Improvements: %d%s\n", ColorGreen, improvements, ColorReset)
301+
}
302+
303+
failedGained := 0
304+
if netFailed > 0 {
305+
failedGained = int(netFailed)
306+
}
307+
passedLost := 0
308+
if netPassed < 0 {
309+
passedLost = int(-netPassed)
310+
}
311+
regressions := failedGained + passedLost
312+
313+
if regressions > 0 {
314+
fmt.Printf("%s↓ Regressions: %d%s\n", ColorRed, regressions, ColorReset)
315+
}
316+
} else {
317+
fmt.Printf("%sNo changes from previous run%s\n", ColorDim, ColorReset)
318+
}
319+
}
320+
321+
func (tr *TestResults) printResultsLine(name string, current, total, previous uint32) {
322+
percentage := float64(current) / float64(total) * 100
323+
diff := int32(current) - int32(previous)
324+
325+
var diffStr string
326+
if diff > 0 {
327+
diffStr = fmt.Sprintf(" %s(+%d)%s", ColorGreen, diff, ColorReset)
328+
} else if diff < 0 {
329+
diffStr = fmt.Sprintf(" %s(%d)%s", ColorRed, diff, ColorReset)
330+
}
331+
332+
fmt.Printf(" %s: %d (%.2f%%)%s\n", name, current, percentage, diffStr)
333+
}
334+
335+
func abs(n int32) int32 {
336+
if n < 0 {
337+
return -n
338+
}
339+
return n
216340
}
217341

218342
func printDiff(name string, n1 uint32, n2 uint32, total uint32) {

0 commit comments

Comments
 (0)