From 648b352424e70f099f62cc18a768babb90434350 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 19 May 2015 17:22:41 +0200 Subject: [PATCH 1/3] tests/vm: updated tests and skipped output for specific tests Skipped tests due to large return value --- tests/vm/gh_test.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go index 838050fa1e..b014484205 100644 --- a/tests/vm/gh_test.go +++ b/tests/vm/gh_test.go @@ -87,7 +87,7 @@ func RunVmTest(p string, t *testing.T) { vm.Debug = true glog.SetV(4) glog.SetToStderr(true) - if name != "stackLimitPush32_1024" { + if name != "Call50000_sha256" { continue } */ @@ -128,9 +128,15 @@ func RunVmTest(p string, t *testing.T) { ret, logs, gas, err = helper.RunState(statedb, env, test.Transaction) } - rexp := helper.FromHex(test.Out) - if bytes.Compare(rexp, ret) != 0 { - t.Errorf("%s's return failed. Expected %x, got %x\n", name, rexp, ret) + switch name { + // the memory required for these tests (4294967297 bytes) would take too much time. + // on 19 May 2015 decided to skip these tests their output. + case "mload32bitBound_return", "mload32bitBound_return2": + default: + rexp := helper.FromHex(test.Out) + if bytes.Compare(rexp, ret) != 0 { + t.Errorf("%s's return failed. Expected %x, got %x\n", name, rexp, ret) + } } if isVmTest { @@ -246,8 +252,7 @@ func TestLogTest(t *testing.T) { } func TestPerformance(t *testing.T) { - t.Skip() - const fn = "../files/VMTests/vmPerformance.json" + const fn = "../files/VMTests/vmPerformanceTest.json" RunVmTest(fn, t) } @@ -342,13 +347,11 @@ func TestMemory(t *testing.T) { } func TestMemoryStress(t *testing.T) { - t.Skip("Skipped due to...consuming too much memory :D") const fn = "../files/StateTests/stMemoryStressTest.json" RunVmTest(fn, t) } func TestQuadraticComplexity(t *testing.T) { - t.Skip() // takes too long const fn = "../files/StateTests/stQuadraticComplexityTest.json" RunVmTest(fn, t) } From f5af1fdca8dc7d44b4c2025195c19819886729b6 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 19 May 2015 17:26:38 +0200 Subject: [PATCH 2/3] core/vm: RETURN op code returns pointer to memory rather than copy --- core/vm/memory.go | 12 ++++++++++++ core/vm/vm.go | 2 +- tests/vm/gh_test.go | 8 ++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/core/vm/memory.go b/core/vm/memory.go index b77d486ebb..d20aa95910 100644 --- a/core/vm/memory.go +++ b/core/vm/memory.go @@ -49,6 +49,18 @@ func (self *Memory) Get(offset, size int64) (cpy []byte) { return } +func (self *Memory) GetPtr(offset, size int64) []byte { + if size == 0 { + return nil + } + + if len(self.store) > int(offset) { + return self.store[offset : offset+size] + } + + return nil +} + func (m *Memory) Len() int { return len(m.store) } diff --git a/core/vm/vm.go b/core/vm/vm.go index 927b672936..35fa19d038 100644 --- a/core/vm/vm.go +++ b/core/vm/vm.go @@ -695,7 +695,7 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) { self.Printf("resume %x (%v)", context.Address(), context.Gas) case RETURN: offset, size := stack.pop(), stack.pop() - ret := mem.Get(offset.Int64(), size.Int64()) + ret := mem.GetPtr(offset.Int64(), size.Int64()) self.Printf(" => [%v, %v] (%d) 0x%x", offset, size, len(ret), ret).Endl() diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go index b014484205..827d8ec8ba 100644 --- a/tests/vm/gh_test.go +++ b/tests/vm/gh_test.go @@ -286,13 +286,13 @@ func TestInputLimitsLight(t *testing.T) { RunVmTest(fn, t) } -func TestStateExample(t *testing.T) { - const fn = "../files/StateTests/stExample.json" +func TestStateSystemOperations(t *testing.T) { + const fn = "../files/StateTests/stSystemOperationsTest.json" RunVmTest(fn, t) } -func TestStateSystemOperations(t *testing.T) { - const fn = "../files/StateTests/stSystemOperationsTest.json" +func TestStateExample(t *testing.T) { + const fn = "../files/StateTests/stExample.json" RunVmTest(fn, t) } From 9617aa8e19b660ead51c201b76c510ea079f40eb Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 20 May 2015 00:20:07 +0200 Subject: [PATCH 3/3] tests: added conditional skip on long running VM tests Set the TEST_VM_COMPLEX env var to test complex vm tests which require a lot of ram and quite some time. --- tests/vm/gh_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go index 827d8ec8ba..68eb4cb45c 100644 --- a/tests/vm/gh_test.go +++ b/tests/vm/gh_test.go @@ -4,6 +4,7 @@ import ( "bytes" "io/ioutil" "math/big" + "os" "path/filepath" "strconv" "testing" @@ -347,11 +348,17 @@ func TestMemory(t *testing.T) { } func TestMemoryStress(t *testing.T) { + if os.Getenv("TEST_VM_COMPLEX") == "" { + t.Skip() + } const fn = "../files/StateTests/stMemoryStressTest.json" RunVmTest(fn, t) } func TestQuadraticComplexity(t *testing.T) { + if os.Getenv("TEST_VM_COMPLEX") == "" { + t.Skip() + } const fn = "../files/StateTests/stQuadraticComplexityTest.json" RunVmTest(fn, t) }