Skip to content
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

feat:add movz/movn mips test #12353

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 65 additions & 2 deletions cannon/mipsevm/tests/evm_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func TestEVM(t *testing.T) {

cases := GetMipsVersionTestCases(t)
skippedTests := map[string][]string{
"multi-threaded": []string{"clone.bin"},
"single-threaded": []string{},
"multi-threaded": {"clone.bin"},
"single-threaded": {},
}

for _, c := range cases {
Expand Down Expand Up @@ -315,6 +315,69 @@ func TestEVMSingleStep_LoadStore(t *testing.T) {
}
}

func TestEVMSingleStep_MovzMovn(t *testing.T) {
var tracer *tracing.Hooks
versions := GetMipsVersionTestCases(t)
cases := []struct {
name string
funct uint32
}{
{name: "movz", funct: uint32(0xa)},
{name: "movn", funct: uint32(0xb)},
}
for _, v := range versions {
for i, tt := range cases {
testName := fmt.Sprintf("%v (%v)", tt.name, v.Name)
t.Run(testName, func(t *testing.T) {
goVm := v.VMFactory(nil, os.Stdout, os.Stderr, testutil.CreateLogger(), testutil.WithRandomization(int64(i)), testutil.WithPC(0), testutil.WithNextPC(4))
state := goVm.GetState()
rsReg := uint32(9)
rtReg := uint32(10)
rdReg := uint32(8)
insn := rsReg<<21 | rtReg<<16 | rdReg<<11 | tt.funct
var t2 Word
if tt.funct == 0xa {
t2 = 0x0
} else {
t2 = 0x1
}
state.GetRegistersRef()[rtReg] = t2
state.GetRegistersRef()[rsReg] = Word(0xb)
state.GetRegistersRef()[rdReg] = Word(0xa)
state.GetMemory().SetUint32(0, insn)
step := state.GetStep()
// Setup expectations
expected := testutil.NewExpectedState(state)
expected.ExpectStep()
expected.Registers[rdReg] = state.GetRegistersRef()[rsReg]

stepWitness, err := goVm.Step(true)
require.NoError(t, err)
// Check expectations
expected.Validate(t, state)
testutil.ValidateEVM(t, stepWitness, step, goVm, v.StateHashFn, v.Contracts, tracer)

if tt.funct == 0xa {
t2 = 0x1
} else {
t2 = 0x0
}
state.GetRegistersRef()[rtReg] = t2
expected.ExpectStep()
expected.Registers[rtReg] = t2
expected.Registers[rdReg] = state.GetRegistersRef()[rdReg]

stepWitness, err = goVm.Step(true)
require.NoError(t, err)
// Check expectations
expected.Validate(t, state)
testutil.ValidateEVM(t, stepWitness, step, goVm, v.StateHashFn, v.Contracts, tracer)
})
}
}

}

func TestEVM_MMap(t *testing.T) {
var tracer *tracing.Hooks

Expand Down