-
Notifications
You must be signed in to change notification settings - Fork 21.9k
cmd/evm: add enginetest command for direct engine fixture execution #34650
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
Draft
spencer-tb
wants to merge
9
commits into
ethereum:master
Choose a base branch
from
spencer-tb:feat/evm-enginetest
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2ef6227
cmd/evm: add enginetest command for direct engine fixture execution
spencer-tb 58fe592
cmd/evm: add --workers flag to blocktest for parallel file processing
spencer-tb d46370a
cmd/evm: add --workers flag to statetest for parallel file processing
spencer-tb 1063416
cmd/evm: add initial forkchoice update to genesis in enginetest
spencer-tb ffc5899
cmd/evm: always include error field in JSON output
spencer-tb 6f0ae11
cmd/evm: add --ndjson flag for streaming JSON output
spencer-tb 2ca9720
tests: move block insertion debug output from stdout to stderr
spencer-tb c8fdb1d
cmd/evm: remove --ndjson flag (not needed for consume direct)
spencer-tb 1b1c90a
cmd/evm: per-type result schema and error reporting for consume direct
spencer-tb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,221 @@ | ||
| // Copyright 2025 The go-ethereum Authors | ||
| // This file is part of go-ethereum. | ||
| // | ||
| // go-ethereum is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // go-ethereum is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License | ||
| // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "bufio" | ||
| "encoding/json" | ||
| "fmt" | ||
| "maps" | ||
| "os" | ||
| "regexp" | ||
| "runtime" | ||
| "slices" | ||
| "sync" | ||
|
|
||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/core" | ||
| "github.com/ethereum/go-ethereum/core/rawdb" | ||
| "github.com/ethereum/go-ethereum/log" | ||
| "github.com/ethereum/go-ethereum/tests" | ||
| "github.com/urfave/cli/v2" | ||
| ) | ||
|
|
||
| var ( | ||
| WorkersFlag = &cli.IntFlag{ | ||
| Name: "workers", | ||
| Usage: "Number of parallel workers for processing fixture files", | ||
| Value: 1, | ||
| } | ||
| ) | ||
|
|
||
| var engineTestCommand = &cli.Command{ | ||
| Action: engineTestCmd, | ||
| Name: "enginetest", | ||
| Usage: "Executes the given engine API tests. Filenames can be fed via standard input (batch mode) or as an argument (one-off execution).", | ||
| ArgsUsage: "<path>", | ||
| Flags: slices.Concat([]cli.Flag{ | ||
| DumpFlag, | ||
| HumanReadableFlag, | ||
| RunFlag, | ||
| FuzzFlag, | ||
| WorkersFlag, | ||
| }, traceFlags), | ||
| } | ||
|
|
||
| func engineTestCmd(ctx *cli.Context) error { | ||
| path := ctx.Args().First() | ||
|
|
||
| // If path is provided, run the tests at that path. | ||
| if len(path) != 0 { | ||
| collected := collectFiles(path) | ||
| workers := ctx.Int(WorkersFlag.Name) | ||
| if workers <= 0 { | ||
| workers = runtime.NumCPU() | ||
| } | ||
| results, err := runEngineTestsParallel(ctx, collected, workers) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| report(ctx, results) | ||
| return nil | ||
| } | ||
| // Otherwise, read filenames from stdin and execute back-to-back. | ||
| scanner := bufio.NewScanner(os.Stdin) | ||
| for scanner.Scan() { | ||
| fname := scanner.Text() | ||
| if len(fname) == 0 { | ||
| return nil | ||
| } | ||
| results, err := runEngineTest(ctx, fname) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if !ctx.IsSet(FuzzFlag.Name) { | ||
| report(ctx, results) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // fileResult holds the results from processing a single fixture file. | ||
| type fileResult struct { | ||
| index int | ||
| results []testResult | ||
| err error | ||
| } | ||
|
|
||
| // runEngineTestsParallel processes fixture files using a worker pool. | ||
| func runEngineTestsParallel(ctx *cli.Context, files []string, workers int) ([]testResult, error) { | ||
| if workers == 1 { | ||
| // Fast path: no goroutine overhead for single worker | ||
| var results []testResult | ||
| for _, fname := range files { | ||
| r, err := runEngineTest(ctx, fname) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| results = append(results, r...) | ||
| } | ||
| return results, nil | ||
| } | ||
| // Parallel execution | ||
| var ( | ||
| wg sync.WaitGroup | ||
| fileCh = make(chan struct { | ||
| index int | ||
| fname string | ||
| }, len(files)) | ||
| resultCh = make(chan fileResult, len(files)) | ||
| ) | ||
| // Feed files into the channel | ||
| for i, fname := range files { | ||
| fileCh <- struct { | ||
| index int | ||
| fname string | ||
| }{i, fname} | ||
| } | ||
| close(fileCh) | ||
|
|
||
| // Start workers | ||
| for w := 0; w < workers; w++ { | ||
| wg.Add(1) | ||
| go func() { | ||
| defer wg.Done() | ||
| for item := range fileCh { | ||
| r, err := runEngineTest(ctx, item.fname) | ||
| resultCh <- fileResult{index: item.index, results: r, err: err} | ||
| } | ||
| }() | ||
| } | ||
| // Close result channel when all workers are done | ||
| go func() { | ||
| wg.Wait() | ||
| close(resultCh) | ||
| }() | ||
|
|
||
| // Collect results in order | ||
| 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 runEngineTest(ctx *cli.Context, fname string) ([]testResult, error) { | ||
| src, err := os.ReadFile(fname) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| var testsByName map[string]*tests.EngineTest | ||
| if err = json.Unmarshal(src, &testsByName); err != nil { | ||
| // Skip non-fixture JSON files (e.g. .meta/index.json) | ||
| return nil, nil | ||
| } | ||
| re, err := regexp.Compile(ctx.String(RunFlag.Name)) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("invalid regex -%s: %v", RunFlag.Name, err) | ||
| } | ||
| tracer := tracerFromFlags(ctx) | ||
|
|
||
| if ctx.IsSet(FuzzFlag.Name) { | ||
| log.SetDefault(log.NewLogger(log.DiscardHandler())) | ||
| } | ||
|
|
||
| keys := slices.Sorted(maps.Keys(testsByName)) | ||
|
|
||
| var results []testResult | ||
| for _, name := range keys { | ||
| if !re.MatchString(name) { | ||
| continue | ||
| } | ||
| test := testsByName[name] | ||
| result := &testResult{Name: name, Pass: true} | ||
| var finalRoot *common.Hash | ||
| if err := test.Run(rawdb.PathScheme, tracer, func(res error, chain *core.BlockChain) { | ||
| if ctx.Bool(DumpFlag.Name) { | ||
| if s, _ := chain.State(); s != nil { | ||
| result.State = dump(s) | ||
| } | ||
| } | ||
| if chain != nil { | ||
| root := chain.CurrentBlock().Root | ||
| finalRoot = &root | ||
| } | ||
| }); err != nil { | ||
| result.Pass, result.Error = false, err.Error() | ||
| } | ||
|
|
||
| result.Fork = test.Network() | ||
| if result.Pass && finalRoot != nil { | ||
| result.Root = finalRoot | ||
| } | ||
|
|
||
| if ctx.IsSet(FuzzFlag.Name) { | ||
| report(ctx, []testResult{*result}) | ||
| } | ||
| results = append(results, *result) | ||
| } | ||
| return results, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to confirm that this also skips errors from malformed fixture files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would