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

Upgrade wagon and add tests #93

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: test
on: [push, pull_request]
jobs:
unit:
name: Unit
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v1
with:
go-version: 1.13
id: go
- uses: actions/checkout@v1
- run: make test

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ coverage.txt
*.test

go.sum
test_runner
tests/generated
target/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "testsuite"]
path = testsuite
url = [email protected]:WebAssembly/testsuite.git
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
JSON_DIR:=tests/generated
WAST_DIR:=testsuite
NO_TEST:=tests/skipped/%.no-test
TEST_RUNNER:=target/test_runner

# Run all test fixtures
.PHONY: test
test: build testsuite test_runner wast $(patsubst ${JSON_DIR}/%.json, ${NO_TEST}, $(wildcard ${JSON_DIR}/*.json))

.PHONY: build
build:
go build .

target/test_runner:
go build -o ${TEST_RUNNER} ./spec/test_runner

# Pseudo target to run each test fixture
${NO_TEST}: ${JSON_DIR}/%.json
${TEST_RUNNER} $<

# Get latest test suite as a git submodule
.PHONY: testsuite
testsuite:
git submodule update --init testsuite

# Build all JSON specs
.PHONY: wast
wast: $(patsubst ${WAST_DIR}/%.wast, ${JSON_DIR}/%.json, $(wildcard ${WAST_DIR}/*.wast))

# Build JSON specs - requires the wast2json binary to be on PATH, from wabt (https://github.com/WebAssembly/wabt)
${JSON_DIR}/%.json: testsuite/%.wast
wast2json $< -o $@


4 changes: 2 additions & 2 deletions compiler/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (m *Module) CompileWithNGen(gp GasPolicy, numGlobals uint64) (out string, r

for i, f := range m.Base.FunctionIndexSpace {
//fmt.Printf("Compiling function %d (%+v) with %d locals\n", i, f.Sig, len(f.Body.Locals))
d, err := disasm.Disassemble(f, m.Base)
d, err := disasm.NewDisassembly(f, m.Base)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -220,7 +220,7 @@ func (m *Module) CompileForInterpreter(gp GasPolicy) (_retCode []InterpreterCode

for i, f := range m.Base.FunctionIndexSpace {
//fmt.Printf("Compiling function %d (%+v) with %d locals\n", i, f.Sig, len(f.Body.Locals))
d, err := disasm.Disassemble(f, m.Base)
d, err := disasm.NewDisassembly(f, m.Base)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,10 +722,10 @@ func (c *SSAFunctionCompiler) Serialize() []byte {
binary.Write(buf, binary.LittleEndian, uint32(v))
}

case "current_memory":
case "memory.size":
binary.Write(buf, binary.LittleEndian, opcodes.CurrentMemory)

case "grow_memory":
case "memory.grow":
binary.Write(buf, binary.LittleEndian, opcodes.GrowMemory)
binary.Write(buf, binary.LittleEndian, uint32(ins.Values[0]))

Expand Down
4 changes: 2 additions & 2 deletions compiler/ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,12 @@ func (c *SSAFunctionCompiler) Compile(importTypeIDs []int) {
c.PushStack(targetValueID)
}

case "current_memory":
case "memory.size":
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could avoid the strings in this switch if upstream merges: go-interpreter/wagon#172

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed; I left a suggestion comment over in go-interpreter/wagon#172. It's not absolutely mandatory, though regardless of whichever option is chosen for converting an opcode into a string, we should definitely incorporate the change int a separate PR.

retID := c.NextValueID()
c.Code = append(c.Code, buildInstr(retID, ins.Op.Name, nil, nil))
c.PushStack(retID)

case "grow_memory":
case "memory.grow":
retID := c.NextValueID()
c.Code = append(c.Code, buildInstr(retID, ins.Op.Name, nil, c.PopStack(1)))
c.PushStack(retID)
Expand Down
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module github.com/perlin-network/life

replace github.com/go-interpreter/wagon v0.0.0 => github.com/perlin-network/wagon v0.3.1-0.20180825141017-f8cb99b55a39
go 1.13

require (
github.com/go-interpreter/wagon v0.0.0
github.com/go-interpreter/wagon v0.6.1-0.20190923081222-01d3d3376951
github.com/kr/pretty v0.1.0 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e // indirect
google.golang.org/appengine v1.6.5 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
)
1 change: 1 addition & 0 deletions tests/skipped/data.no-test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file indicates that the corresponding JSON test in tests/generated is not yet passing and will be excluded. Remove this file to include the test.
1 change: 1 addition & 0 deletions tests/skipped/elem.no-test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file indicates that the corresponding JSON test in tests/generated is not yet passing and will be excluded. Remove this file to include the test.
1 change: 1 addition & 0 deletions tests/skipped/imports.no-test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file indicates that the corresponding JSON test in tests/generated is not yet passing and will be excluded. Remove this file to include the test.
1 change: 1 addition & 0 deletions tests/skipped/linking.no-test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file indicates that the corresponding JSON test in tests/generated is not yet passing and will be excluded. Remove this file to include the test.
1 change: 1 addition & 0 deletions tests/skipped/start.no-test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file indicates that the corresponding JSON test in tests/generated is not yet passing and will be excluded. Remove this file to include the test.
1 change: 1 addition & 0 deletions testsuite
Submodule testsuite added at d072a8