Skip to content

Commit

Permalink
cannon: move example test programs into testdata directory to prevent…
Browse files Browse the repository at this point in the history
… Go tool noise (#11379)
  • Loading branch information
protolambda authored Aug 7, 2024
1 parent e6dd1ee commit 79c8fe8
Show file tree
Hide file tree
Showing 21 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
- run:
name: build Cannon example binaries
command: make elf # only compile ELF binaries with Go, we do not have MIPS GCC for creating the debug-dumps.
working_directory: cannon/example
working_directory: cannon/testdata/example
- run:
name: Cannon Go lint
command: |
Expand Down
2 changes: 1 addition & 1 deletion cannon/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cache
venv
.idea
*.log
example/bin
testdata/example/bin
contracts/out
state.json
*.json
Expand Down
2 changes: 1 addition & 1 deletion cannon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ clean:
rm -rf bin

elf:
make -C ./example elf
make -C ./testdata/example elf

contract:
cd ../packages/contracts-bedrock && forge build
Expand Down
2 changes: 1 addition & 1 deletion cannon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ The smart-contracts are integrated into the Optimism monorepo contracts:

Example programs that can be run and proven with Cannon.
Optional dependency, but required for `mipsevm` Go tests.
See [`example/Makefile`](./example/Makefile) for building the example MIPS binaries.
See [`testdata/example/Makefile`](./testdata/example/Makefile) for building the example MIPS binaries.

## License

Expand Down
4 changes: 2 additions & 2 deletions cannon/mipsevm/multithreaded/instrumented_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestInstrumentedState_Claim(t *testing.T) {
}

func TestInstrumentedState_MultithreadedProgram(t *testing.T) {
state := testutil.LoadELFProgram(t, "../../example/bin/multithreaded.elf", CreateInitialState, false)
state := testutil.LoadELFProgram(t, "../../testdata/example/bin/multithreaded.elf", CreateInitialState, false)
oracle := testutil.StaticOracle(t, []byte{})

var stdOutBuf, stdErrBuf bytes.Buffer
Expand All @@ -56,7 +56,7 @@ func TestInstrumentedState_MultithreadedProgram(t *testing.T) {
func TestInstrumentedState_Alloc(t *testing.T) {
t.Skip("TODO(client-pod#906): Currently failing - need to debug.")

state := testutil.LoadELFProgram(t, "../../example/bin/alloc.elf", CreateInitialState, false)
state := testutil.LoadELFProgram(t, "../../testdata/example/bin/alloc.elf", CreateInitialState, false)
const numAllocs = 100 // where each alloc is a 32 MiB chunk
oracle := testutil.AllocOracle(t, numAllocs)

Expand Down
2 changes: 1 addition & 1 deletion cannon/mipsevm/multithreaded/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestState_EncodeWitness(t *testing.T) {
}

func TestState_JSONCodec(t *testing.T) {
elfProgram, err := elf.Open("../../example/bin/hello.elf")
elfProgram, err := elf.Open("../../testdata/example/bin/hello.elf")
require.NoError(t, err, "open ELF file")
state, err := program.LoadELF(elfProgram, CreateInitialState)
require.NoError(t, err, "load ELF into state")
Expand Down
2 changes: 1 addition & 1 deletion cannon/mipsevm/singlethreaded/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestStateHash(t *testing.T) {
}

func TestStateJSONCodec(t *testing.T) {
elfProgram, err := elf.Open("../../example/bin/hello.elf")
elfProgram, err := elf.Open("../../testdata/example/bin/hello.elf")
require.NoError(t, err, "open ELF file")
state, err := program.LoadELF(elfProgram, CreateInitialState)
require.NoError(t, err, "load ELF into state")
Expand Down
4 changes: 2 additions & 2 deletions cannon/mipsevm/tests/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func TestHelloEVM(t *testing.T) {
evm.SetTracer(tracer)
testutil.LogStepFailureAtCleanup(t, evm)

state := testutil.LoadELFProgram(t, "../../example/bin/hello.elf", singlethreaded.CreateInitialState, true)
state := testutil.LoadELFProgram(t, "../../testdata/example/bin/hello.elf", singlethreaded.CreateInitialState, true)
var stdOutBuf, stdErrBuf bytes.Buffer
goState := singlethreaded.NewInstrumentedState(state, nil, io.MultiWriter(&stdOutBuf, os.Stdout), io.MultiWriter(&stdErrBuf, os.Stderr), nil)

Expand Down Expand Up @@ -469,7 +469,7 @@ func TestClaimEVM(t *testing.T) {
evm.SetTracer(tracer)
testutil.LogStepFailureAtCleanup(t, evm)

state := testutil.LoadELFProgram(t, "../../example/bin/claim.elf", singlethreaded.CreateInitialState, true)
state := testutil.LoadELFProgram(t, "../../testdata/example/bin/claim.elf", singlethreaded.CreateInitialState, true)
oracle, expectedStdOut, expectedStdErr := testutil.ClaimTestOracle(t)

var stdOutBuf, stdErrBuf bytes.Buffer
Expand Down
4 changes: 2 additions & 2 deletions cannon/mipsevm/testutil/vmtests.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func RunVMTests_OpenMips[T mipsevm.FPVMState](t *testing.T, stateFactory StateFa
}

func RunVMTest_Hello[T mipsevm.FPVMState](t *testing.T, initState program.CreateInitialFPVMState[T], vmFactory VMFactory[T], doPatchGo bool) {
state := LoadELFProgram(t, "../../example/bin/hello.elf", initState, doPatchGo)
state := LoadELFProgram(t, "../../testdata/example/bin/hello.elf", initState, doPatchGo)

var stdOutBuf, stdErrBuf bytes.Buffer
us := vmFactory(state, nil, io.MultiWriter(&stdOutBuf, os.Stdout), io.MultiWriter(&stdErrBuf, os.Stderr), CreateLogger())
Expand All @@ -99,7 +99,7 @@ func RunVMTest_Hello[T mipsevm.FPVMState](t *testing.T, initState program.Create
}

func RunVMTest_Claim[T mipsevm.FPVMState](t *testing.T, initState program.CreateInitialFPVMState[T], vmFactory VMFactory[T], doPatchGo bool) {
state := LoadELFProgram(t, "../../example/bin/claim.elf", initState, doPatchGo)
state := LoadELFProgram(t, "../../testdata/example/bin/claim.elf", initState, doPatchGo)

oracle, expectedStdOut, expectedStdErr := ClaimTestOracle(t)

Expand Down
11 changes: 11 additions & 0 deletions cannon/testdata/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Cannon testdata

These example Go programs are used in tests,
and encapsulated as their own Go modules.

## Testdata

The `testdata` directory name (special Go exception) prevents tools like `go mod tidy`
that run from the monorepo root from picking up on the test data,
preventing noisy dependabot PRs.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ require (
golang.org/x/sys v0.22.0 // indirect
)

replace github.com/ethereum-optimism/optimism v0.0.0 => ../../..
replace github.com/ethereum-optimism/optimism v0.0.0 => ../../../..
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ require (
golang.org/x/sys v0.22.0 // indirect
)

replace github.com/ethereum-optimism/optimism v0.0.0 => ../../..
replace github.com/ethereum-optimism/optimism v0.0.0 => ../../../..
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 79c8fe8

Please sign in to comment.