diff options
Diffstat (limited to 'tests/vm_test_util.go')
-rw-r--r-- | tests/vm_test_util.go | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/tests/vm_test_util.go b/tests/vm_test_util.go index e63a92558..b29dcd20f 100644 --- a/tests/vm_test_util.go +++ b/tests/vm_test_util.go @@ -22,6 +22,7 @@ import ( "io" "math/big" "strconv" + "testing" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state" @@ -48,8 +49,79 @@ func RunVmTestWithReader(r io.Reader, skipTests []string) error { return nil } -func RunVmTest(p string, skipTests []string) error { +type bconf struct { + name string + precomp bool + nojit bool +} + +func BenchVmTest(p string, conf bconf, b *testing.B) error { + tests := make(map[string]VmTest) + err := readJsonFile(p, &tests) + if err != nil { + return err + } + + test, ok := tests[conf.name] + if !ok { + return fmt.Errorf("test not found: %s", conf.name) + } + + pNoJit := vm.DisableJit + vm.DisableJit = conf.nojit + pForceJit := vm.ForceJit + vm.ForceJit = conf.precomp + + env := make(map[string]string) + env["currentCoinbase"] = test.Env.CurrentCoinbase + env["currentDifficulty"] = test.Env.CurrentDifficulty + env["currentGasLimit"] = test.Env.CurrentGasLimit + env["currentNumber"] = test.Env.CurrentNumber + env["previousHash"] = test.Env.PreviousHash + if n, ok := test.Env.CurrentTimestamp.(float64); ok { + env["currentTimestamp"] = strconv.Itoa(int(n)) + } else { + env["currentTimestamp"] = test.Env.CurrentTimestamp.(string) + } + /* + if conf.precomp { + program := vm.NewProgram(test.code) + err := vm.AttachProgram(program) + if err != nil { + return err + } + } + */ + + b.ResetTimer() + for i := 0; i < b.N; i++ { + benchVmTest(test, env, b) + } + + vm.DisableJit = pNoJit + vm.ForceJit = pForceJit + + return nil +} + +func benchVmTest(test VmTest, env map[string]string, b *testing.B) { + b.StopTimer() + db, _ := ethdb.NewMemDatabase() + statedb := state.New(common.Hash{}, db) + for addr, account := range test.Pre { + obj := StateObjectFromAccount(db, addr, account) + statedb.SetStateObject(obj) + for a, v := range account.Storage { + obj.SetState(common.HexToHash(a), common.HexToHash(v)) + } + } + b.StartTimer() + + RunVm(statedb, env, test.Exec) +} + +func RunVmTest(p string, skipTests []string) error { tests := make(map[string]VmTest) err := readJsonFile(p, &tests) if err != nil { |