aboutsummaryrefslogtreecommitdiffstats
path: root/tests/state_test_util.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <geffobscura@gmail.com>2015-07-18 05:09:36 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2015-08-07 18:52:17 +0800
commit846f34f78b5f76233655d0cf3611706e99f2efe2 (patch)
tree4e25f0320e30c0ed45b706835fd4377632bdcb45 /tests/state_test_util.go
parent698e98d9814605bfea98ba3ad2fe7fda073cb2b1 (diff)
downloaddexon-846f34f78b5f76233655d0cf3611706e99f2efe2.tar
dexon-846f34f78b5f76233655d0cf3611706e99f2efe2.tar.gz
dexon-846f34f78b5f76233655d0cf3611706e99f2efe2.tar.bz2
dexon-846f34f78b5f76233655d0cf3611706e99f2efe2.tar.lz
dexon-846f34f78b5f76233655d0cf3611706e99f2efe2.tar.xz
dexon-846f34f78b5f76233655d0cf3611706e99f2efe2.tar.zst
dexon-846f34f78b5f76233655d0cf3611706e99f2efe2.zip
core/vm, tests: implemented semi-jit vm
* changed stack and removed stack ptr. Let go decide on slice reuse.
Diffstat (limited to 'tests/state_test_util.go')
-rw-r--r--tests/state_test_util.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/state_test_util.go b/tests/state_test_util.go
index 7086de389..695e50852 100644
--- a/tests/state_test_util.go
+++ b/tests/state_test_util.go
@@ -23,6 +23,7 @@ import (
"io"
"math/big"
"strconv"
+ "testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
@@ -60,6 +61,61 @@ func RunStateTest(p string, skipTests []string) error {
}
+func BenchStateTest(p string, conf bconf, b *testing.B) error {
+ tests := make(map[string]VmTest)
+ if err := readJsonFile(p, &tests); 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
+
+ // XXX Yeah, yeah...
+ 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)
+ }
+
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchStateTest(test, env, b)
+ }
+
+ vm.DisableJit = pNoJit
+ vm.ForceJit = pForceJit
+
+ return nil
+}
+
+func benchStateTest(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()
+
+ RunState(statedb, env, test.Exec)
+}
+
func runStateTests(tests map[string]VmTest, skipTests []string) error {
skipTest := make(map[string]bool, len(skipTests))
for _, name := range skipTests {