mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-05 22:48:36 +00:00
cmd/evm: add --workers flag to blocktest for parallel file processing
This commit is contained in:
parent
2ef6227b89
commit
58fe59263c
1 changed files with 68 additions and 11 deletions
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
|
|
@ -44,6 +45,7 @@ var blockTestCommand = &cli.Command{
|
||||||
RunFlag,
|
RunFlag,
|
||||||
WitnessCrossCheckFlag,
|
WitnessCrossCheckFlag,
|
||||||
FuzzFlag,
|
FuzzFlag,
|
||||||
|
WorkersFlag,
|
||||||
}, traceFlags),
|
}, traceFlags),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,16 +54,14 @@ func blockTestCmd(ctx *cli.Context) error {
|
||||||
|
|
||||||
// If path is provided, run the tests at that path.
|
// If path is provided, run the tests at that path.
|
||||||
if len(path) != 0 {
|
if len(path) != 0 {
|
||||||
var (
|
collected := collectFiles(path)
|
||||||
collected = collectFiles(path)
|
workers := ctx.Int(WorkersFlag.Name)
|
||||||
results []testResult
|
if workers <= 0 {
|
||||||
)
|
workers = 1
|
||||||
for _, fname := range collected {
|
}
|
||||||
r, err := runBlockTest(ctx, fname)
|
results, err := runBlockTestsParallel(ctx, collected, workers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
results = append(results, r...)
|
|
||||||
}
|
}
|
||||||
report(ctx, results)
|
report(ctx, results)
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -85,6 +85,63 @@ func blockTestCmd(ctx *cli.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runBlockTestsParallel(ctx *cli.Context, files []string, workers int) ([]testResult, error) {
|
||||||
|
if workers == 1 {
|
||||||
|
var results []testResult
|
||||||
|
for _, fname := range files {
|
||||||
|
r, err := runBlockTest(ctx, fname)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
results = append(results, r...)
|
||||||
|
}
|
||||||
|
return results, nil
|
||||||
|
}
|
||||||
|
var (
|
||||||
|
wg sync.WaitGroup
|
||||||
|
fileCh = make(chan struct {
|
||||||
|
index int
|
||||||
|
fname string
|
||||||
|
}, len(files))
|
||||||
|
resultCh = make(chan fileResult, len(files))
|
||||||
|
)
|
||||||
|
for i, fname := range files {
|
||||||
|
fileCh <- struct {
|
||||||
|
index int
|
||||||
|
fname string
|
||||||
|
}{i, fname}
|
||||||
|
}
|
||||||
|
close(fileCh)
|
||||||
|
|
||||||
|
for w := 0; w < workers; w++ {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
for item := range fileCh {
|
||||||
|
r, err := runBlockTest(ctx, item.fname)
|
||||||
|
resultCh <- fileResult{index: item.index, results: r, err: err}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
wg.Wait()
|
||||||
|
close(resultCh)
|
||||||
|
}()
|
||||||
|
|
||||||
|
ordered := make([]fileResult, len(files))
|
||||||
|
for fr := range resultCh {
|
||||||
|
if fr.err != nil {
|
||||||
|
return nil, fr.err
|
||||||
|
}
|
||||||
|
ordered[fr.index] = fr
|
||||||
|
}
|
||||||
|
var results []testResult
|
||||||
|
for _, fr := range ordered {
|
||||||
|
results = append(results, fr.results...)
|
||||||
|
}
|
||||||
|
return results, nil
|
||||||
|
}
|
||||||
|
|
||||||
func runBlockTest(ctx *cli.Context, fname string) ([]testResult, error) {
|
func runBlockTest(ctx *cli.Context, fname string) ([]testResult, error) {
|
||||||
src, err := os.ReadFile(fname)
|
src, err := os.ReadFile(fname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -92,7 +149,7 @@ func runBlockTest(ctx *cli.Context, fname string) ([]testResult, error) {
|
||||||
}
|
}
|
||||||
var tests map[string]*tests.BlockTest
|
var tests map[string]*tests.BlockTest
|
||||||
if err = json.Unmarshal(src, &tests); err != nil {
|
if err = json.Unmarshal(src, &tests); err != nil {
|
||||||
return nil, err
|
return nil, nil // Skip non-fixture JSON files
|
||||||
}
|
}
|
||||||
re, err := regexp.Compile(ctx.String(RunFlag.Name))
|
re, err := regexp.Compile(ctx.String(RunFlag.Name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue