From 8e68690cca8b4e2f5e74c6572e2576c298aa10ab Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 19:54:53 +0100 Subject: [PATCH 01/22] ci: run integration tests against the optimizing compiler (linux/arm64) Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 245 +++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index bc3df26818..1ce90e9d10 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -111,6 +111,59 @@ jobs: - name: Run the test binary with wazero CLI run: wazero run -mount=:/ ./zigbin/test.wasm + zig-opt: + needs: build_zig_test_binary + name: Zig / Optimizing Compiler + runs-on: ubuntu-22.04 + strategy: + fail-fast: false # don't fail fast as sometimes failures are arch/OS specific + matrix: + arch: + - "arm64" + + steps: + - name: Checkout wazero + uses: actions/checkout@v3 + + - uses: actions/cache@v3 + id: binary-cache + with: + # Use share the cache containing archives across OSes. + enableCrossOsArchive: true + # We need this cache to run tests. + fail-on-cache-miss: true + key: zig-stdlib-test-binary-${{ env.ZIG_VERSION }} + path: + ./zigbin/ + + - uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Build wazero + run: go build -o ./wazerocli ./cmd/wazero + env: + GOARCH: ${{ matrix.arch }} + + - name: Set up QEMU + if: ${{ matrix.arch != 'amd64' }} + uses: docker/setup-qemu-action@v2 + with: # Avoid docker.io rate-limits; built with internal-images.yml + image: ghcr.io/tetratelabs/wazero/internal-binfmt + platforms: ${{ matrix.arch }} + + - name: Build scratch container + run: | + echo 'FROM scratch' >> Dockerfile + echo 'CMD ["/test"]' >> Dockerfile + docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . + + - name: Run built test binaries + # This runs all tests compiled above in sequence. Note: This mounts /tmp to allow t.TempDir() in tests. + run: | + docker run --platform linux/${{ matrix.arch }} -v $(pwd)/zigbin:/test -v $(pwd)/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ + /wazero run -optimizing-compiler -mount=:/ ./test/test.wasm + build_tinygo_test_binary: name: Build TinyGo test binary runs-on: ubuntu-22.04 @@ -235,6 +288,63 @@ jobs: wazero run -mount=:/ -mount=:/tmp $bin -- -test.v done + tinygo-opt: + needs: build_tinygo_test_binary + name: TinyGo / Optimizing Compiler + runs-on: ubuntu-22.04 + strategy: + fail-fast: false # don't fail fast as sometimes failures are arch/OS specific + matrix: + arch: + - "arm64" + + steps: + - name: Checkout wazero + uses: actions/checkout@v3 + + - uses: actions/cache@v3 + id: binary-cache + with: + # Use share the cache containing archives across OSes. + enableCrossOsArchive: true + # We need this cache to run tests. + fail-on-cache-miss: true + key: tinygo-test-binaries-${{ env.TINYGO_VERSION }} + path: + ./tinygobin/ + + - uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Build wazero + run: go build -o ~/wazerocli ./cmd/wazero + env: + GOARCH: ${{ matrix.arch }} + + - name: Set up QEMU + if: ${{ matrix.arch != 'amd64' }} + uses: docker/setup-qemu-action@v2 + with: # Avoid docker.io rate-limits; built with internal-images.yml + image: ghcr.io/tetratelabs/wazero/internal-binfmt + platforms: ${{ matrix.arch }} + + - name: Build scratch container + run: | + echo 'FROM scratch' >> Dockerfile + echo 'CMD ["/test"]' >> Dockerfile + docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . + + - name: Run built test binaries + # This runs all tests compiled above in sequence. Note: This mounts /tmp to allow t.TempDir() in tests. + run: | + cd ./tinygobin + for bin in *.test; do + echo $bin + docker run --platform linux/${{ matrix.arch }} -v $(pwd):/test -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ + /wazero run -optimizing-compiler -mount=:/ /test/$bin -- -test.v + done + wasi-testsuite: name: wasi-testsuite runs-on: ${{ matrix.os }} @@ -481,3 +591,138 @@ jobs: # Run all the tests in their own shell. $RUNNER + + go_tests_opt: + # Due to the embedding of the GOROOT of the building env(https://github.com/golang/go/blob/3c59639b902fada0a2e5a6a35bafd10fc9183b89/src/os/os_test.go#L112), + # we have to build and cache on each OS unlike others in this file. + name: Go / Optimizing Compiler + runs-on: ${{ matrix.os }} + needs: go_tests + strategy: + fail-fast: false # don't fail fast as sometimes failures are arch/OS specific + matrix: + os: [ubuntu-22.04] + arch: + - "arm64" + + steps: + - id: setup-go + uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Cache Go test binaries + id: cache-go-test-binaries + uses: actions/cache@v3 + with: + path: ~/tests + # Use precise Go version from setup-go as patch version differences can effect tests. + key: go-wasip1-binaries-${{ matrix.os }}-${{ steps.setup-go.outputs.go-version }} + + - if: ${{ steps.cache-go-test-binaries.outputs.cache-hit != 'true' }} + name: Build Test Binaries + run: | + mkdir ~/tests + cd $(go env GOROOT) + # Choose important packages to limit execution time. + for value in src/archive/tar \ + src/bufio \ + src/bytes \ + src/context \ + src/encoding/ascii85 \ + src/encoding/asn1 \ + src/encoding/base32 \ + src/encoding/base64 \ + src/encoding/binary \ + src/encoding/csv \ + src/encoding/gob \ + src/encoding/hex \ + src/encoding/json \ + src/encoding/pem \ + src/encoding/xml \ + src/errors \ + src/expvar \ + src/flag \ + src/fmt \ + src/hash \ + src/hash/adler32 \ + src/hash/crc32 \ + src/hash/crc64 \ + src/hash/fnv \ + src/hash/maphash \ + src/io \ + src/io/fs \ + src/io/ioutil \ + src/log \ + src/log/syslog \ + src/maps \ + src/math \ + src/math/big \ + src/math/bits \ + src/math/cmplx \ + src/math/rand \ + src/mime \ + src/mime/multipart \ + src/mime/quotedprintable \ + src/os \ + src/os/exec \ + src/os/signal \ + src/os/user \ + src/path \ + src/reflect \ + src/regexp \ + src/regexp/syntax \ + src/runtime \ + src/runtime/internal/atomic \ + src/runtime/internal/math \ + src/runtime/internal/sys \ + src/slices \ + src/sort \ + src/strconv \ + src/strings \ + src/sync \ + src/sync/atomic \ + src/syscall \ + src/testing \ + src/testing/fstest \ + src/testing/iotest \ + src/testing/quick \ + src/time + do + echo "GOOS=wasip1 GOARCH=wasm go test -v -c -o ~/tests/${value//\//_}.test ./$value" + GOOS=wasip1 GOARCH=wasm go test -v -c -o ~/tests/${value//\//_}.test ./$value + done + + - name: Checkout wazero + uses: actions/checkout@v3 + + - name: Build wazero + run: go build -o ~/wazerocli ./cmd/wazero + env: + GOARCH: ${{ matrix.arch }} + + - name: Set up QEMU + if: ${{ matrix.arch != 'amd64' }} + uses: docker/setup-qemu-action@v2 + with: # Avoid docker.io rate-limits; built with internal-images.yml + image: ghcr.io/tetratelabs/wazero/internal-binfmt + platforms: ${{ matrix.arch }} + + - name: Build scratch container + run: | + echo 'FROM scratch' >> Dockerfile + echo 'CMD ["/test"]' >> Dockerfile + docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . + + - name: Run standard library tests + run: | + echo "Running $(find ~/tests -name *.test | wc -l) test binaries" + + # Go tests often look for files relative to the source. Change to the corresponding directory. + for bin in ~/tests/*.test; do + dir=$(basename $bin); dir=${dir%.test}; dir=${dir//_/\/} + pushd $(go env GOROOT)/$dir + docker run --platform linux/${{ matrix.arch }} -v $(pwd):/test -v /:/ROOT -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ + /wazero run -optimizing-compiler -mount=/ROOT:/ -env PWD=$PWD /$bin -- -test.short -test.v + popd + done From a6fea913e89ecaab88e470c5491ad8056d3dea3f Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 14 Dec 2023 12:45:44 -0800 Subject: [PATCH 02/22] wazevo(arm64): relocations for large conditional branches (#1873) Signed-off-by: Takeshi Yoneda --- .../engine/wazevo/backend/isa/arm64/instr.go | 6 +- .../backend/isa/arm64/instr_encoding_test.go | 2 +- .../wazevo/backend/isa/arm64/machine.go | 125 ++++++++++++++---- .../wazevo/backend/isa/arm64/machine_test.go | 97 ++++++++++++++ 4 files changed, 205 insertions(+), 25 deletions(-) diff --git a/internal/engine/wazevo/backend/isa/arm64/instr.go b/internal/engine/wazevo/backend/isa/arm64/instr.go index 3f5a33ec1c..3aa50e4c8a 100644 --- a/internal/engine/wazevo/backend/isa/arm64/instr.go +++ b/internal/engine/wazevo/backend/isa/arm64/instr.go @@ -647,7 +647,7 @@ func (i *instruction) brLabel() label { } // brOffsetResolved is called when the target label is resolved. -func (i *instruction) brOffsetResolved(offset int64) { +func (i *instruction) brOffsetResolve(offset int64) { i.u2 = uint64(offset) i.u3 = 1 // indicate that the offset is resolved, for debugging. } @@ -666,6 +666,10 @@ func (i *instruction) asCondBr(c cond, target label, is64bit bool) { } } +func (i *instruction) setCondBrTargets(target label) { + i.u2 = uint64(target) +} + func (i *instruction) condBrLabel() label { return label(i.u2) } diff --git a/internal/engine/wazevo/backend/isa/arm64/instr_encoding_test.go b/internal/engine/wazevo/backend/isa/arm64/instr_encoding_test.go index 58242bf619..924a81197c 100644 --- a/internal/engine/wazevo/backend/isa/arm64/instr_encoding_test.go +++ b/internal/engine/wazevo/backend/isa/arm64/instr_encoding_test.go @@ -1280,7 +1280,7 @@ func TestInstruction_encode(t *testing.T) { }}, {want: "20000014", setup: func(i *instruction) { i.asBr(dummyLabel) - i.brOffsetResolved(0x80) + i.brOffsetResolve(0x80) }}, {want: "01040034", setup: func(i *instruction) { i.asCondBr(registerAsRegZeroCond(x1VReg), dummyLabel, false) diff --git a/internal/engine/wazevo/backend/isa/arm64/machine.go b/internal/engine/wazevo/backend/isa/arm64/machine.go index 59d60e2952..ecd9d0ccb5 100644 --- a/internal/engine/wazevo/backend/isa/arm64/machine.go +++ b/internal/engine/wazevo/backend/isa/arm64/machine.go @@ -43,6 +43,9 @@ type ( addends64 queue[regalloc.VReg] unresolvedAddressModes []*instruction + // condBrRelocs holds the conditional branches which need offset relocation. + condBrRelocs []condBrReloc + // spillSlotSize is the size of the stack slot in bytes used for spilling registers. // During the execution of the function, the stack looks like: // @@ -98,10 +101,20 @@ type ( // labelPosition represents the regions of the generated code which the label represents. labelPosition struct { + l label begin, end *instruction binarySize int64 binaryOffset int64 } + + condBrReloc struct { + cbr *instruction + // currentLabelPos is the labelPosition within which condBr is defined. + currentLabelPos *labelPosition + // Next block's labelPosition. + nextLabel label + offset int64 + } ) const ( @@ -205,7 +218,7 @@ func (m *machine) StartBlock(blk ssa.BasicBlock) { labelPos, ok := m.labelPositions[l] if !ok { - labelPos = m.allocateLabelPosition() + labelPos = m.allocateLabelPosition(l) m.labelPositions[l] = labelPos } m.orderedBlockLabels = append(m.orderedBlockLabels, labelPos) @@ -231,18 +244,24 @@ func (m *machine) insert(i *instruction) { } func (m *machine) insertBrTargetLabel() label { - l := m.allocateLabel() - nop := m.allocateInstr() - nop.asNop0WithLabel(l) + nop, l := m.allocateBrTarget() m.insert(nop) - pos := m.allocateLabelPosition() + return l +} + +func (m *machine) allocateBrTarget() (nop *instruction, l label) { + l = m.allocateLabel() + nop = m.allocateInstr() + nop.asNop0WithLabel(l) + pos := m.allocateLabelPosition(l) pos.begin, pos.end = nop, nop m.labelPositions[l] = pos - return l + return } -func (m *machine) allocateLabelPosition() *labelPosition { +func (m *machine) allocateLabelPosition(la label) *labelPosition { l := m.labelPositionPool.Allocate() + l.l = la return l } @@ -344,17 +363,34 @@ func (m *machine) ResolveRelativeAddresses() { } } + // Reuse the slice to gather the unresolved conditional branches. + cbrs := m.condBrRelocs[:0] + // Next, in order to determine the offsets of relative jumps, we have to calculate the size of each label. var offset int64 - for _, pos := range m.orderedBlockLabels { + for i, pos := range m.orderedBlockLabels { pos.binaryOffset = offset var size int64 for cur := pos.begin; ; cur = cur.next { - if cur.kind == nop0 { + switch cur.kind { + case nop0: l := cur.nop0Label() if pos, ok := m.labelPositions[l]; ok { pos.binaryOffset = offset + size } + case condBr: + if !cur.condBrOffsetResolved() { + var nextLabel label + if i < len(m.orderedBlockLabels)-1 { + // Note: this is only used when the block ends with fallthrough, + // therefore can be safely assumed that the next block exists when it's needed. + nextLabel = m.orderedBlockLabels[i+1].l + } + cbrs = append(cbrs, condBrReloc{ + cbr: cur, currentLabelPos: pos, offset: offset + size, + nextLabel: nextLabel, + }) + } } size += cur.size() if cur == pos.end { @@ -365,6 +401,30 @@ func (m *machine) ResolveRelativeAddresses() { offset += size } + // Before resolving any offsets, we need to check if all the conditional branches can be resolved. + var needRerun bool + for i := range cbrs { + reloc := &cbrs[i] + cbr := reloc.cbr + offset := reloc.offset + + target := cbr.condBrLabel() + offsetOfTarget := m.labelPositions[target].binaryOffset + diff := offsetOfTarget - offset + if divided := diff >> 2; divided < minSignedInt19 || divided > maxSignedInt19 { + // This case the conditional branch is too huge. We place the trampoline instructions at the end of the current block, + // and jump to it. + m.insertConditionalJumpTrampoline(cbr, reloc.currentLabelPos, reloc.nextLabel) + // Then, we need to recall this function to fix up the label offsets + // as they have changed after the trampoline is inserted. + needRerun = true + } + } + if needRerun { + m.ResolveRelativeAddresses() + return + } + var currentOffset int64 for cur := m.rootInstr; cur != nil; cur = cur.next { switch cur.kind { @@ -372,29 +432,19 @@ func (m *machine) ResolveRelativeAddresses() { target := cur.brLabel() offsetOfTarget := m.labelPositions[target].binaryOffset diff := offsetOfTarget - currentOffset - if diff%4 != 0 { - panic("BUG: offsets between b and the target must be a multiple of 4") - } divided := diff >> 2 if divided < minSignedInt26 || divided > maxSignedInt26 { // This means the currently compiled single function is extremely large. - panic("BUG: implement branch relocation for large unconditional branch larger than 26-bit range") + panic("too large function that requires branch relocation of large unconditional branch larger than 26-bit range") } - cur.brOffsetResolved(diff) + cur.brOffsetResolve(diff) case condBr: if !cur.condBrOffsetResolved() { target := cur.condBrLabel() offsetOfTarget := m.labelPositions[target].binaryOffset diff := offsetOfTarget - currentOffset - if diff%4 != 0 { - panic("BUG: offsets between b and the target must be a multiple of 4") - } - divided := diff >> 2 - if divided < minSignedInt19 || divided > maxSignedInt19 { - // This case we can insert "trampoline block" in the middle and jump to it. - // After that, we need to re-calculate the offset of labels after the trampoline block by - // recursively calling this function. - panic("TODO: implement branch relocation for large conditional branch larger than 19-bit range") + if divided := diff >> 2; divided < minSignedInt19 || divided > maxSignedInt19 { + panic("BUG: branch relocation for large conditional branch larger than 19-bit range must be handled properly") } cur.condBrOffsetResolve(diff) } @@ -421,6 +471,35 @@ const ( minSignedInt19 int64 = -(1 << 19) ) +func (m *machine) insertConditionalJumpTrampoline(cbr *instruction, currentBlk *labelPosition, nextLabel label) { + cur := currentBlk.end + originalTarget := cbr.condBrLabel() + endNext := cur.next + + if cur.kind != br { + // If the current block ends with a conditional branch, we can just insert the trampoline after it. + // Otherwise, we need to insert "skip" instruction to skip the trampoline instructions. + skip := m.allocateInstr() + skip.asBr(nextLabel) + cur = linkInstr(cur, skip) + } + + cbrNewTargetInstr, cbrNewTargetLabel := m.allocateBrTarget() + cbr.setCondBrTargets(cbrNewTargetLabel) + cur = linkInstr(cur, cbrNewTargetInstr) + + // Then insert the unconditional branch to the original, which should be possible to get encoded + // as 26-bit offset should be enough for any practical application. + br := m.allocateInstr() + br.asBr(originalTarget) + cur = linkInstr(cur, br) + + // Update the end of the current block. + currentBlk.end = cur + + linkInstr(cur, endNext) +} + func (m *machine) getOrAllocateSSABlockLabel(blk ssa.BasicBlock) label { if blk.ReturnBlock() { return returnLabel diff --git a/internal/engine/wazevo/backend/isa/arm64/machine_test.go b/internal/engine/wazevo/backend/isa/arm64/machine_test.go index da4227c7af..48e3dd3039 100644 --- a/internal/engine/wazevo/backend/isa/arm64/machine_test.go +++ b/internal/engine/wazevo/backend/isa/arm64/machine_test.go @@ -123,3 +123,100 @@ func TestMachine_getVRegSpillSlotOffsetFromSP(t *testing.T) { _, ok = m.spillSlots[id] require.True(t, ok) } + +func TestMachine_insertConditionalJumpTrampoline(t *testing.T) { + for _, tc := range []struct { + brAtEnd bool + expBefore, expAfter string + }{ + { + brAtEnd: true, + expBefore: ` +L100: + b.eq L12345 + b L888888888 +L200: + exit_sequence x0 +`, + expAfter: ` +L100: + b.eq L10000000 + b L888888888 +L10000000: + b L12345 +L200: + exit_sequence x0 +`, + }, + { + brAtEnd: false, + expBefore: ` +L100: + b.eq L12345 + udf +L200: + exit_sequence x0 +`, + expAfter: ` +L100: + b.eq L10000000 + udf + b L200 +L10000000: + b L12345 +L200: + exit_sequence x0 +`, + }, + } { + var name string + if tc.brAtEnd { + name = "brAtEnd" + } else { + name = "brNotAtEnd" + } + + t.Run(name, func(t *testing.T) { + m := NewBackend().(*machine) + const ( + originLabel = 100 + originLabelNext = 200 + targetLabel = 12345 + ) + + cbr := m.allocateInstr() + cbr.asCondBr(eq.asCond(), targetLabel, false) + + end := m.allocateInstr() + if tc.brAtEnd { + end.asBr(888888888) + } else { + end.asUDF() + } + + originalEndNext := m.allocateInstr() + originalEndNext.asExitSequence(x0VReg) + + originLabelPos := m.allocateLabelPosition(originLabel) + originLabelPos.begin = cbr + originLabelPos.end = linkInstr(cbr, end) + originNextLabelPos := m.allocateLabelPosition(originLabelNext) + originNextLabelPos.begin = originalEndNext + linkInstr(originLabelPos.end, originalEndNext) + + m.labelPositions[originLabel] = originLabelPos + m.labelPositions[originLabelNext] = originNextLabelPos + + m.rootInstr = cbr + require.Equal(t, tc.expBefore, m.Format()) + + m.nextLabel = 9999999 + m.insertConditionalJumpTrampoline(cbr, originLabelPos, originLabelNext) + + require.Equal(t, tc.expAfter, m.Format()) + + // The original label position should be updated to the unconditional jump to the original target destination. + require.Equal(t, "b L12345", originLabelPos.end.String()) + }) + } +} From 96a033e0d734cb76260d8c791d01a7ed78b07faa Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 22:01:48 +0100 Subject: [PATCH 03/22] wip Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 1ce90e9d10..b717740651 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -723,6 +723,6 @@ jobs: dir=$(basename $bin); dir=${dir%.test}; dir=${dir//_/\/} pushd $(go env GOROOT)/$dir docker run --platform linux/${{ matrix.arch }} -v $(pwd):/test -v /:/ROOT -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ - /wazero run -optimizing-compiler -mount=/ROOT:/ -env PWD=$PWD /$bin -- -test.short -test.v + /wazero run -optimizing-compiler -mount=/ROOT:/ -env PWD=$PWD $bin -- -test.short -test.v popd done From c8e6f8a544d069ac38ad490249b2fb002db60b6f Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 22:08:46 +0100 Subject: [PATCH 04/22] wasip1 Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index b717740651..046597a97a 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -722,7 +722,8 @@ jobs: for bin in ~/tests/*.test; do dir=$(basename $bin); dir=${dir%.test}; dir=${dir//_/\/} pushd $(go env GOROOT)/$dir - docker run --platform linux/${{ matrix.arch }} -v $(pwd):/test -v /:/ROOT -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ + # mount / as /ROOT in docker and then remount /ROOT as / in wazero + docker run --platform linux/${{ matrix.arch }} -v /:/ROOT -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ /wazero run -optimizing-compiler -mount=/ROOT:/ -env PWD=$PWD $bin -- -test.short -test.v popd done From 064e5fcdf4621a04bfbb7334ceb8dfa867027b7a Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 22:15:57 +0100 Subject: [PATCH 05/22] tmate Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 046597a97a..4962d02b6a 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -597,7 +597,7 @@ jobs: # we have to build and cache on each OS unlike others in this file. name: Go / Optimizing Compiler runs-on: ${{ matrix.os }} - needs: go_tests + # needs: go_tests strategy: fail-fast: false # don't fail fast as sometimes failures are arch/OS specific matrix: @@ -714,6 +714,9 @@ jobs: echo 'CMD ["/test"]' >> Dockerfile docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + - name: Run standard library tests run: | echo "Running $(find ~/tests -name *.test | wc -l) test binaries" From 0e0c3c8a11a0ade867fd2126da462fa9fc1ddbd7 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 22:24:52 +0100 Subject: [PATCH 06/22] wasip1 Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 4962d02b6a..4a21582505 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -714,9 +714,6 @@ jobs: echo 'CMD ["/test"]' >> Dockerfile docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 - - name: Run standard library tests run: | echo "Running $(find ~/tests -name *.test | wc -l) test binaries" @@ -725,8 +722,8 @@ jobs: for bin in ~/tests/*.test; do dir=$(basename $bin); dir=${dir%.test}; dir=${dir//_/\/} pushd $(go env GOROOT)/$dir - # mount / as /ROOT in docker and then remount /ROOT as / in wazero - docker run --platform linux/${{ matrix.arch }} -v /:/ROOT -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ - /wazero run -optimizing-compiler -mount=/ROOT:/ -env PWD=$PWD $bin -- -test.short -test.v + # Mount / as /ROOT in docker and then remount /ROOT as / in wazero; $bin is now in /ROOT/$bin. + docker run --platform linux/arm64 -v /:/ROOT -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ + /wazero run -optimizing-compiler -mount=/ROOT:/ -env PWD=$PWD /ROOT/$bin -- -test.short -test.v popd done From 95a611c9cf253225562d316ec25257454f052ba0 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 22:38:05 +0100 Subject: [PATCH 07/22] consolidate zig build Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 57 +++++++++--------------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 4a21582505..96acbee82e 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -80,46 +80,13 @@ jobs: strategy: fail-fast: false # don't fail fast as sometimes failures are arch/OS specific matrix: - os: [ubuntu-22.04, macos-12, windows-2022] - - steps: - - name: Checkout wazero - uses: actions/checkout@v3 - - - uses: actions/cache@v3 - id: binary-cache - with: - # Use share the cache containing archives across OSes. - enableCrossOsArchive: true - # We need this cache to run tests. - fail-on-cache-miss: true - key: zig-stdlib-test-binary-${{ env.ZIG_VERSION }} - path: - ./zigbin/ - - - uses: actions/setup-go@v4 - with: - go-version: ${{ env.GO_VERSION }} - - - name: Install wazero - run: go install ./cmd/wazero - - # This runs the previously compiled Zig tests with wazero. If you need - # to troubleshoot one, you can add "-hostlogging=filesystem" after - # adding filter argument to the "Build Stdlib test binary" step. - # e.g. --test-filter "Dir.Iterator but dir is deleted during iteration" - - name: Run the test binary with wazero CLI - run: wazero run -mount=:/ ./zigbin/test.wasm - - zig-opt: - needs: build_zig_test_binary - name: Zig / Optimizing Compiler - runs-on: ubuntu-22.04 - strategy: - fail-fast: false # don't fail fast as sometimes failures are arch/OS specific - matrix: - arch: - - "arm64" + os: [ubuntu-22.04, macos-12, windows-2022] + compiler: [plain] + arch: [amd64] + include: + - os: ubuntu-22.04 + compiler: optimizing + arch: "arm64" steps: - name: Checkout wazero @@ -153,17 +120,25 @@ jobs: platforms: ${{ matrix.arch }} - name: Build scratch container + if: ${{ runner.os != 'Windows' }} run: | echo 'FROM scratch' >> Dockerfile echo 'CMD ["/test"]' >> Dockerfile docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . - name: Run built test binaries - # This runs all tests compiled above in sequence. Note: This mounts /tmp to allow t.TempDir() in tests. + if: ${{ runner.os != 'Windows' }} + # This runs the previously compiled Zig tests with wazero. If you need + # to troubleshoot one, you can add "-hostlogging=filesystem" after + # adding filter argument to the "Build Stdlib test binary" step. + # e.g. --test-filter "Dir.Iterator but dir is deleted during iteration" run: | docker run --platform linux/${{ matrix.arch }} -v $(pwd)/zigbin:/test -v $(pwd)/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ /wazero run -optimizing-compiler -mount=:/ ./test/test.wasm + - name: Run the test binary with wazero CLI + run: ./wazerocli run -mount=:/ ./zigbin/test.wasm + build_tinygo_test_binary: name: Build TinyGo test binary runs-on: ubuntu-22.04 From b3d50b8928013dd9c62bc1883bf9886b4d030f01 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 22:41:28 +0100 Subject: [PATCH 08/22] consolidate tinygo build Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 43 +++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 96acbee82e..996d32592a 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -137,6 +137,7 @@ jobs: /wazero run -optimizing-compiler -mount=:/ ./test/test.wasm - name: Run the test binary with wazero CLI + if: ${{ runner.os == 'Windows' }} run: ./wazerocli run -mount=:/ ./zigbin/test.wasm build_tinygo_test_binary: @@ -227,7 +228,13 @@ jobs: strategy: fail-fast: false # don't fail fast as sometimes failures are arch/OS specific matrix: - os: [ubuntu-22.04, macos-12, windows-2022] + os: [ubuntu-22.04, macos-12, windows-2022] + compiler: [plain] + arch: [amd64] + include: + - os: ubuntu-22.04 + compiler: optimizing + arch: "arm64" steps: - name: Checkout wazero @@ -248,19 +255,47 @@ jobs: with: go-version: ${{ env.GO_VERSION }} - - name: Install wazero - run: go install ./cmd/wazero + - name: Build wazero + run: go build -o ~/wazerocli ./cmd/wazero + env: + GOARCH: ${{ matrix.arch }} + + - name: Set up QEMU + if: ${{ matrix.arch != 'amd64' }} + uses: docker/setup-qemu-action@v2 + with: # Avoid docker.io rate-limits; built with internal-images.yml + image: ghcr.io/tetratelabs/wazero/internal-binfmt + platforms: ${{ matrix.arch }} + + - name: Build scratch container + run: | + echo 'FROM scratch' >> Dockerfile + echo 'CMD ["/test"]' >> Dockerfile + docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . + + - name: Run built test binaries + if: ${{ runner.os != 'Windows' }} + # This runs all tests compiled above in sequence. Note: This mounts /tmp to allow t.TempDir() in tests. + run: | + cd ./tinygobin + for bin in *.test; do + echo $bin + docker run --platform linux/${{ matrix.arch }} -v $(pwd):/test -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ + /wazero run -optimizing-compiler -mount=:/ /test/$bin -- -test.v + done + # This runs the previously compiled TinyGo tests with wazero. If you need # to troubleshoot one, you can add "-hostlogging=filesystem" and also a # trailing argument narrowing which test to execute. # e.g. "-test.run '^TestStatBadDir$'" - name: Run standard library tests + if: ${{ runner.os == 'Windows' }} run: | cd ./tinygobin for bin in *.test; do echo $bin - wazero run -mount=:/ -mount=:/tmp $bin -- -test.v + ~/wazerocli run -mount=:/ -mount=:/tmp $bin -- -test.v done tinygo-opt: From e59f46c44f4250f72114b77116a04c7d025d4d30 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 22:51:51 +0100 Subject: [PATCH 09/22] fix Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 996d32592a..5a966ccd4d 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -75,7 +75,7 @@ jobs: zig: needs: build_zig_test_binary - name: Zig (${{ matrix.os }}) + name: Zig (${{ matrix.os }} / ${{ matrix.arch }} / ${{ matrix.compiler }}) runs-on: ${{ matrix.os }} strategy: fail-fast: false # don't fail fast as sometimes failures are arch/OS specific @@ -113,21 +113,21 @@ jobs: GOARCH: ${{ matrix.arch }} - name: Set up QEMU - if: ${{ matrix.arch != 'amd64' }} + if: ${{ matrix.compiler == 'optimizing' && matrix.arch == 'arm64' }} uses: docker/setup-qemu-action@v2 with: # Avoid docker.io rate-limits; built with internal-images.yml image: ghcr.io/tetratelabs/wazero/internal-binfmt platforms: ${{ matrix.arch }} - name: Build scratch container - if: ${{ runner.os != 'Windows' }} + if: ${{ matrix.compiler == 'optimizing' }} run: | echo 'FROM scratch' >> Dockerfile echo 'CMD ["/test"]' >> Dockerfile docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . - name: Run built test binaries - if: ${{ runner.os != 'Windows' }} + if: ${{ matrix.compiler == 'optimizing' }} # This runs the previously compiled Zig tests with wazero. If you need # to troubleshoot one, you can add "-hostlogging=filesystem" after # adding filter argument to the "Build Stdlib test binary" step. @@ -137,7 +137,7 @@ jobs: /wazero run -optimizing-compiler -mount=:/ ./test/test.wasm - name: Run the test binary with wazero CLI - if: ${{ runner.os == 'Windows' }} + if: ${{ matrix.compiler != 'optimizing' }} run: ./wazerocli run -mount=:/ ./zigbin/test.wasm build_tinygo_test_binary: @@ -223,7 +223,7 @@ jobs: tinygo: needs: build_tinygo_test_binary - name: TinyGo (${{ matrix.os }}) + name: TinyGo (${{ matrix.os }} / ${{ matrix.arch }} / ${{ matrix.compiler }}) runs-on: ${{ matrix.os }} strategy: fail-fast: false # don't fail fast as sometimes failures are arch/OS specific @@ -261,20 +261,21 @@ jobs: GOARCH: ${{ matrix.arch }} - name: Set up QEMU - if: ${{ matrix.arch != 'amd64' }} + if: ${{ matrix.compiler == 'optimizing' && matrix.arch == 'arm64' }} uses: docker/setup-qemu-action@v2 with: # Avoid docker.io rate-limits; built with internal-images.yml image: ghcr.io/tetratelabs/wazero/internal-binfmt platforms: ${{ matrix.arch }} - name: Build scratch container + if: ${{ matrix.compiler == 'optimizing' }} run: | echo 'FROM scratch' >> Dockerfile echo 'CMD ["/test"]' >> Dockerfile docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . - name: Run built test binaries - if: ${{ runner.os != 'Windows' }} + if: ${{ matrix.compiler == 'optimizing' }} # This runs all tests compiled above in sequence. Note: This mounts /tmp to allow t.TempDir() in tests. run: | cd ./tinygobin @@ -290,7 +291,7 @@ jobs: # trailing argument narrowing which test to execute. # e.g. "-test.run '^TestStatBadDir$'" - name: Run standard library tests - if: ${{ runner.os == 'Windows' }} + if: ${{ matrix.compiler != 'optimizing' }} run: | cd ./tinygobin for bin in *.test; do From b7fcad5c66b3319eddb3d2f2deb3cf3a2929d388 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 23:02:45 +0100 Subject: [PATCH 10/22] fix + add go Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 126 ++++++++++++----------------- 1 file changed, 53 insertions(+), 73 deletions(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 5a966ccd4d..8f0e14acd6 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -75,18 +75,18 @@ jobs: zig: needs: build_zig_test_binary - name: Zig (${{ matrix.os }} / ${{ matrix.arch }} / ${{ matrix.compiler }}) + name: Zig (${{ matrix.os }}, ${{ matrix.arch }}, ${{ matrix.compiler }}-compiler) runs-on: ${{ matrix.os }} strategy: fail-fast: false # don't fail fast as sometimes failures are arch/OS specific matrix: os: [ubuntu-22.04, macos-12, windows-2022] - compiler: [plain] + compiler: [baseline] arch: [amd64] include: - - os: ubuntu-22.04 + - os: ubuntu-22.04 compiler: optimizing - arch: "arm64" + arch: "arm64" steps: - name: Checkout wazero @@ -223,18 +223,18 @@ jobs: tinygo: needs: build_tinygo_test_binary - name: TinyGo (${{ matrix.os }} / ${{ matrix.arch }} / ${{ matrix.compiler }}) + name: TinyGo (${{ matrix.os }}, ${{ matrix.arch }}, ${{ matrix.compiler }}-compiler) runs-on: ${{ matrix.os }} strategy: fail-fast: false # don't fail fast as sometimes failures are arch/OS specific matrix: os: [ubuntu-22.04, macos-12, windows-2022] - compiler: [plain] + compiler: [baseline] arch: [amd64] include: - - os: ubuntu-22.04 + - os: ubuntu-22.04 compiler: optimizing - arch: "arm64" + arch: "arm64" steps: - name: Checkout wazero @@ -299,63 +299,6 @@ jobs: ~/wazerocli run -mount=:/ -mount=:/tmp $bin -- -test.v done - tinygo-opt: - needs: build_tinygo_test_binary - name: TinyGo / Optimizing Compiler - runs-on: ubuntu-22.04 - strategy: - fail-fast: false # don't fail fast as sometimes failures are arch/OS specific - matrix: - arch: - - "arm64" - - steps: - - name: Checkout wazero - uses: actions/checkout@v3 - - - uses: actions/cache@v3 - id: binary-cache - with: - # Use share the cache containing archives across OSes. - enableCrossOsArchive: true - # We need this cache to run tests. - fail-on-cache-miss: true - key: tinygo-test-binaries-${{ env.TINYGO_VERSION }} - path: - ./tinygobin/ - - - uses: actions/setup-go@v4 - with: - go-version: ${{ env.GO_VERSION }} - - - name: Build wazero - run: go build -o ~/wazerocli ./cmd/wazero - env: - GOARCH: ${{ matrix.arch }} - - - name: Set up QEMU - if: ${{ matrix.arch != 'amd64' }} - uses: docker/setup-qemu-action@v2 - with: # Avoid docker.io rate-limits; built with internal-images.yml - image: ghcr.io/tetratelabs/wazero/internal-binfmt - platforms: ${{ matrix.arch }} - - - name: Build scratch container - run: | - echo 'FROM scratch' >> Dockerfile - echo 'CMD ["/test"]' >> Dockerfile - docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . - - - name: Run built test binaries - # This runs all tests compiled above in sequence. Note: This mounts /tmp to allow t.TempDir() in tests. - run: | - cd ./tinygobin - for bin in *.test; do - echo $bin - docker run --platform linux/${{ matrix.arch }} -v $(pwd):/test -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ - /wazero run -optimizing-compiler -mount=:/ /test/$bin -- -test.v - done - wasi-testsuite: name: wasi-testsuite runs-on: ${{ matrix.os }} @@ -446,15 +389,21 @@ jobs: go_tests: # Due to the embedding of the GOROOT of the building env(https://github.com/golang/go/blob/3c59639b902fada0a2e5a6a35bafd10fc9183b89/src/os/os_test.go#L112), # we have to build and cache on each OS unlike others in this file. - name: Go (${{ matrix.os }}, Go-${{ matrix.go-version }}) + name: Go (${{ matrix.os }}, Go-${{ matrix.go-version }}, ${{ matrix.arch }}, ${{ matrix.compiler }}-compiler) runs-on: ${{ matrix.os }} strategy: fail-fast: false # don't fail fast as sometimes failures are arch/OS specific matrix: - os: [ubuntu-22.04, macos-12, windows-2022] + os: [ubuntu-22.04, macos-12, windows-2022] + compiler: [baseline] + arch: [amd64] go-version: - "1.21" # Current Go version && The only version that supports wasip1. - + include: + - os: ubuntu-22.04 + compiler: optimizing + arch: "arm64" + go-version: "1.21" steps: - id: setup-go uses: actions/setup-go@v4 @@ -546,10 +495,41 @@ jobs: - name: Checkout wazero uses: actions/checkout@v3 - - name: Install wazero - run: go install ./cmd/wazero + - name: Build wazero + run: go build -o ~/wazerocli ./cmd/wazero + env: + GOARCH: ${{ matrix.arch }} + + - name: Set up QEMU + if: ${{ matrix.compiler == 'optimizing' && matrix.arch == 'arm64' }} + uses: docker/setup-qemu-action@v2 + with: # Avoid docker.io rate-limits; built with internal-images.yml + image: ghcr.io/tetratelabs/wazero/internal-binfmt + platforms: ${{ matrix.arch }} + + - name: Build scratch container + if: ${{ matrix.compiler == 'optimizing' }} + run: | + echo 'FROM scratch' >> Dockerfile + echo 'CMD ["/test"]' >> Dockerfile + docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . + + - if: ${{ matrix.compiler == 'optimizing' }} + name: Run standard library tests + run: | + echo "Running $(find ~/tests -name *.test | wc -l) test binaries" + + # Go tests often look for files relative to the source. Change to the corresponding directory. + for bin in ~/tests/*.test; do + dir=$(basename $bin); dir=${dir%.test}; dir=${dir//_/\/} + pushd $(go env GOROOT)/$dir + # Mount / as /ROOT in docker and then remount /ROOT as / in wazero; $bin is now in /ROOT/$bin. + docker run --platform linux/arm64 -v /:/ROOT -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ + /wazero run -optimizing-compiler -mount=/ROOT:/ -env PWD=$PWD /ROOT/$bin -- -test.short -test.v + popd + done - - if: ${{ runner.os != 'Windows' }} + - if: ${{ matrix.compiler != 'optimizing' && runner.os != 'Windows' }} name: Run standard library tests run: | echo "Running $(find ~/tests -name *.test | wc -l) test binaries" @@ -558,7 +538,7 @@ jobs: for bin in ~/tests/*.test; do dir=$(basename $bin); dir=${dir%.test}; dir=${dir//_/\/} pushd $(go env GOROOT)/$dir - wazero run -mount=/:/ -env PWD=$PWD $bin -- -test.short -test.v + ~/wazerocli run -mount=/:/ -env PWD=$PWD $bin -- -test.short -test.v popd done @@ -592,7 +572,7 @@ jobs: # Create a script with all the tests (do not run yet). echo ${MOUNT} ${IN_WASM_PWD} $GOROOT/$dir - COMMAND="wazero run -mount=${MOUNT} ${EXTRAPARAMS} -hostlogging=filesystem -env PWD=${IN_WASM_PWD} -env GOROOT=${GOROOT} -env GOOS=wasip1 $bin -- -test.short -test.v" + COMMAND="~/wazerocli run -mount=${MOUNT} ${EXTRAPARAMS} -hostlogging=filesystem -env PWD=${IN_WASM_PWD} -env GOROOT=${GOROOT} -env GOOS=wasip1 $bin -- -test.short -test.v" echo $COMMAND >> $SCRIPT # Uncomment the following line for early exit on error on Windows. # Otherwise the tests will report are successful evne on failure. From 9d128f47bf9aa672f282b92debc1dc79f85f9a76 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 19:54:53 +0100 Subject: [PATCH 11/22] ci: run integration tests against the optimizing compiler (linux/arm64) Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 245 +++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index bc3df26818..1ce90e9d10 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -111,6 +111,59 @@ jobs: - name: Run the test binary with wazero CLI run: wazero run -mount=:/ ./zigbin/test.wasm + zig-opt: + needs: build_zig_test_binary + name: Zig / Optimizing Compiler + runs-on: ubuntu-22.04 + strategy: + fail-fast: false # don't fail fast as sometimes failures are arch/OS specific + matrix: + arch: + - "arm64" + + steps: + - name: Checkout wazero + uses: actions/checkout@v3 + + - uses: actions/cache@v3 + id: binary-cache + with: + # Use share the cache containing archives across OSes. + enableCrossOsArchive: true + # We need this cache to run tests. + fail-on-cache-miss: true + key: zig-stdlib-test-binary-${{ env.ZIG_VERSION }} + path: + ./zigbin/ + + - uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Build wazero + run: go build -o ./wazerocli ./cmd/wazero + env: + GOARCH: ${{ matrix.arch }} + + - name: Set up QEMU + if: ${{ matrix.arch != 'amd64' }} + uses: docker/setup-qemu-action@v2 + with: # Avoid docker.io rate-limits; built with internal-images.yml + image: ghcr.io/tetratelabs/wazero/internal-binfmt + platforms: ${{ matrix.arch }} + + - name: Build scratch container + run: | + echo 'FROM scratch' >> Dockerfile + echo 'CMD ["/test"]' >> Dockerfile + docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . + + - name: Run built test binaries + # This runs all tests compiled above in sequence. Note: This mounts /tmp to allow t.TempDir() in tests. + run: | + docker run --platform linux/${{ matrix.arch }} -v $(pwd)/zigbin:/test -v $(pwd)/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ + /wazero run -optimizing-compiler -mount=:/ ./test/test.wasm + build_tinygo_test_binary: name: Build TinyGo test binary runs-on: ubuntu-22.04 @@ -235,6 +288,63 @@ jobs: wazero run -mount=:/ -mount=:/tmp $bin -- -test.v done + tinygo-opt: + needs: build_tinygo_test_binary + name: TinyGo / Optimizing Compiler + runs-on: ubuntu-22.04 + strategy: + fail-fast: false # don't fail fast as sometimes failures are arch/OS specific + matrix: + arch: + - "arm64" + + steps: + - name: Checkout wazero + uses: actions/checkout@v3 + + - uses: actions/cache@v3 + id: binary-cache + with: + # Use share the cache containing archives across OSes. + enableCrossOsArchive: true + # We need this cache to run tests. + fail-on-cache-miss: true + key: tinygo-test-binaries-${{ env.TINYGO_VERSION }} + path: + ./tinygobin/ + + - uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Build wazero + run: go build -o ~/wazerocli ./cmd/wazero + env: + GOARCH: ${{ matrix.arch }} + + - name: Set up QEMU + if: ${{ matrix.arch != 'amd64' }} + uses: docker/setup-qemu-action@v2 + with: # Avoid docker.io rate-limits; built with internal-images.yml + image: ghcr.io/tetratelabs/wazero/internal-binfmt + platforms: ${{ matrix.arch }} + + - name: Build scratch container + run: | + echo 'FROM scratch' >> Dockerfile + echo 'CMD ["/test"]' >> Dockerfile + docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . + + - name: Run built test binaries + # This runs all tests compiled above in sequence. Note: This mounts /tmp to allow t.TempDir() in tests. + run: | + cd ./tinygobin + for bin in *.test; do + echo $bin + docker run --platform linux/${{ matrix.arch }} -v $(pwd):/test -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ + /wazero run -optimizing-compiler -mount=:/ /test/$bin -- -test.v + done + wasi-testsuite: name: wasi-testsuite runs-on: ${{ matrix.os }} @@ -481,3 +591,138 @@ jobs: # Run all the tests in their own shell. $RUNNER + + go_tests_opt: + # Due to the embedding of the GOROOT of the building env(https://github.com/golang/go/blob/3c59639b902fada0a2e5a6a35bafd10fc9183b89/src/os/os_test.go#L112), + # we have to build and cache on each OS unlike others in this file. + name: Go / Optimizing Compiler + runs-on: ${{ matrix.os }} + needs: go_tests + strategy: + fail-fast: false # don't fail fast as sometimes failures are arch/OS specific + matrix: + os: [ubuntu-22.04] + arch: + - "arm64" + + steps: + - id: setup-go + uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Cache Go test binaries + id: cache-go-test-binaries + uses: actions/cache@v3 + with: + path: ~/tests + # Use precise Go version from setup-go as patch version differences can effect tests. + key: go-wasip1-binaries-${{ matrix.os }}-${{ steps.setup-go.outputs.go-version }} + + - if: ${{ steps.cache-go-test-binaries.outputs.cache-hit != 'true' }} + name: Build Test Binaries + run: | + mkdir ~/tests + cd $(go env GOROOT) + # Choose important packages to limit execution time. + for value in src/archive/tar \ + src/bufio \ + src/bytes \ + src/context \ + src/encoding/ascii85 \ + src/encoding/asn1 \ + src/encoding/base32 \ + src/encoding/base64 \ + src/encoding/binary \ + src/encoding/csv \ + src/encoding/gob \ + src/encoding/hex \ + src/encoding/json \ + src/encoding/pem \ + src/encoding/xml \ + src/errors \ + src/expvar \ + src/flag \ + src/fmt \ + src/hash \ + src/hash/adler32 \ + src/hash/crc32 \ + src/hash/crc64 \ + src/hash/fnv \ + src/hash/maphash \ + src/io \ + src/io/fs \ + src/io/ioutil \ + src/log \ + src/log/syslog \ + src/maps \ + src/math \ + src/math/big \ + src/math/bits \ + src/math/cmplx \ + src/math/rand \ + src/mime \ + src/mime/multipart \ + src/mime/quotedprintable \ + src/os \ + src/os/exec \ + src/os/signal \ + src/os/user \ + src/path \ + src/reflect \ + src/regexp \ + src/regexp/syntax \ + src/runtime \ + src/runtime/internal/atomic \ + src/runtime/internal/math \ + src/runtime/internal/sys \ + src/slices \ + src/sort \ + src/strconv \ + src/strings \ + src/sync \ + src/sync/atomic \ + src/syscall \ + src/testing \ + src/testing/fstest \ + src/testing/iotest \ + src/testing/quick \ + src/time + do + echo "GOOS=wasip1 GOARCH=wasm go test -v -c -o ~/tests/${value//\//_}.test ./$value" + GOOS=wasip1 GOARCH=wasm go test -v -c -o ~/tests/${value//\//_}.test ./$value + done + + - name: Checkout wazero + uses: actions/checkout@v3 + + - name: Build wazero + run: go build -o ~/wazerocli ./cmd/wazero + env: + GOARCH: ${{ matrix.arch }} + + - name: Set up QEMU + if: ${{ matrix.arch != 'amd64' }} + uses: docker/setup-qemu-action@v2 + with: # Avoid docker.io rate-limits; built with internal-images.yml + image: ghcr.io/tetratelabs/wazero/internal-binfmt + platforms: ${{ matrix.arch }} + + - name: Build scratch container + run: | + echo 'FROM scratch' >> Dockerfile + echo 'CMD ["/test"]' >> Dockerfile + docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . + + - name: Run standard library tests + run: | + echo "Running $(find ~/tests -name *.test | wc -l) test binaries" + + # Go tests often look for files relative to the source. Change to the corresponding directory. + for bin in ~/tests/*.test; do + dir=$(basename $bin); dir=${dir%.test}; dir=${dir//_/\/} + pushd $(go env GOROOT)/$dir + docker run --platform linux/${{ matrix.arch }} -v $(pwd):/test -v /:/ROOT -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ + /wazero run -optimizing-compiler -mount=/ROOT:/ -env PWD=$PWD /$bin -- -test.short -test.v + popd + done From d808d09490a353a572958023fc5b1fb05d714a01 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 22:01:48 +0100 Subject: [PATCH 12/22] wip Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 1ce90e9d10..b717740651 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -723,6 +723,6 @@ jobs: dir=$(basename $bin); dir=${dir%.test}; dir=${dir//_/\/} pushd $(go env GOROOT)/$dir docker run --platform linux/${{ matrix.arch }} -v $(pwd):/test -v /:/ROOT -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ - /wazero run -optimizing-compiler -mount=/ROOT:/ -env PWD=$PWD /$bin -- -test.short -test.v + /wazero run -optimizing-compiler -mount=/ROOT:/ -env PWD=$PWD $bin -- -test.short -test.v popd done From 800f397f1a70aedad39d956ec03b3bc2d1f29e8f Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 22:08:46 +0100 Subject: [PATCH 13/22] wasip1 Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index b717740651..046597a97a 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -722,7 +722,8 @@ jobs: for bin in ~/tests/*.test; do dir=$(basename $bin); dir=${dir%.test}; dir=${dir//_/\/} pushd $(go env GOROOT)/$dir - docker run --platform linux/${{ matrix.arch }} -v $(pwd):/test -v /:/ROOT -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ + # mount / as /ROOT in docker and then remount /ROOT as / in wazero + docker run --platform linux/${{ matrix.arch }} -v /:/ROOT -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ /wazero run -optimizing-compiler -mount=/ROOT:/ -env PWD=$PWD $bin -- -test.short -test.v popd done From a3a3c1508234fe332a717d179bd94fa4161f2464 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 22:15:57 +0100 Subject: [PATCH 14/22] tmate Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 046597a97a..4962d02b6a 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -597,7 +597,7 @@ jobs: # we have to build and cache on each OS unlike others in this file. name: Go / Optimizing Compiler runs-on: ${{ matrix.os }} - needs: go_tests + # needs: go_tests strategy: fail-fast: false # don't fail fast as sometimes failures are arch/OS specific matrix: @@ -714,6 +714,9 @@ jobs: echo 'CMD ["/test"]' >> Dockerfile docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + - name: Run standard library tests run: | echo "Running $(find ~/tests -name *.test | wc -l) test binaries" From 1f90a17f69271975fa13d05cb6d77874a05c8b75 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 22:24:52 +0100 Subject: [PATCH 15/22] wasip1 Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 4962d02b6a..4a21582505 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -714,9 +714,6 @@ jobs: echo 'CMD ["/test"]' >> Dockerfile docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 - - name: Run standard library tests run: | echo "Running $(find ~/tests -name *.test | wc -l) test binaries" @@ -725,8 +722,8 @@ jobs: for bin in ~/tests/*.test; do dir=$(basename $bin); dir=${dir%.test}; dir=${dir//_/\/} pushd $(go env GOROOT)/$dir - # mount / as /ROOT in docker and then remount /ROOT as / in wazero - docker run --platform linux/${{ matrix.arch }} -v /:/ROOT -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ - /wazero run -optimizing-compiler -mount=/ROOT:/ -env PWD=$PWD $bin -- -test.short -test.v + # Mount / as /ROOT in docker and then remount /ROOT as / in wazero; $bin is now in /ROOT/$bin. + docker run --platform linux/arm64 -v /:/ROOT -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ + /wazero run -optimizing-compiler -mount=/ROOT:/ -env PWD=$PWD /ROOT/$bin -- -test.short -test.v popd done From c82f103e6bf355a2c1d11265ca0a0a166b8582be Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 22:38:05 +0100 Subject: [PATCH 16/22] consolidate zig build Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 57 +++++++++--------------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 4a21582505..96acbee82e 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -80,46 +80,13 @@ jobs: strategy: fail-fast: false # don't fail fast as sometimes failures are arch/OS specific matrix: - os: [ubuntu-22.04, macos-12, windows-2022] - - steps: - - name: Checkout wazero - uses: actions/checkout@v3 - - - uses: actions/cache@v3 - id: binary-cache - with: - # Use share the cache containing archives across OSes. - enableCrossOsArchive: true - # We need this cache to run tests. - fail-on-cache-miss: true - key: zig-stdlib-test-binary-${{ env.ZIG_VERSION }} - path: - ./zigbin/ - - - uses: actions/setup-go@v4 - with: - go-version: ${{ env.GO_VERSION }} - - - name: Install wazero - run: go install ./cmd/wazero - - # This runs the previously compiled Zig tests with wazero. If you need - # to troubleshoot one, you can add "-hostlogging=filesystem" after - # adding filter argument to the "Build Stdlib test binary" step. - # e.g. --test-filter "Dir.Iterator but dir is deleted during iteration" - - name: Run the test binary with wazero CLI - run: wazero run -mount=:/ ./zigbin/test.wasm - - zig-opt: - needs: build_zig_test_binary - name: Zig / Optimizing Compiler - runs-on: ubuntu-22.04 - strategy: - fail-fast: false # don't fail fast as sometimes failures are arch/OS specific - matrix: - arch: - - "arm64" + os: [ubuntu-22.04, macos-12, windows-2022] + compiler: [plain] + arch: [amd64] + include: + - os: ubuntu-22.04 + compiler: optimizing + arch: "arm64" steps: - name: Checkout wazero @@ -153,17 +120,25 @@ jobs: platforms: ${{ matrix.arch }} - name: Build scratch container + if: ${{ runner.os != 'Windows' }} run: | echo 'FROM scratch' >> Dockerfile echo 'CMD ["/test"]' >> Dockerfile docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . - name: Run built test binaries - # This runs all tests compiled above in sequence. Note: This mounts /tmp to allow t.TempDir() in tests. + if: ${{ runner.os != 'Windows' }} + # This runs the previously compiled Zig tests with wazero. If you need + # to troubleshoot one, you can add "-hostlogging=filesystem" after + # adding filter argument to the "Build Stdlib test binary" step. + # e.g. --test-filter "Dir.Iterator but dir is deleted during iteration" run: | docker run --platform linux/${{ matrix.arch }} -v $(pwd)/zigbin:/test -v $(pwd)/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ /wazero run -optimizing-compiler -mount=:/ ./test/test.wasm + - name: Run the test binary with wazero CLI + run: ./wazerocli run -mount=:/ ./zigbin/test.wasm + build_tinygo_test_binary: name: Build TinyGo test binary runs-on: ubuntu-22.04 From f16f17aa6b686b3a9bf251d76f3386d4767f25c8 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 22:41:28 +0100 Subject: [PATCH 17/22] consolidate tinygo build Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 43 +++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 96acbee82e..996d32592a 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -137,6 +137,7 @@ jobs: /wazero run -optimizing-compiler -mount=:/ ./test/test.wasm - name: Run the test binary with wazero CLI + if: ${{ runner.os == 'Windows' }} run: ./wazerocli run -mount=:/ ./zigbin/test.wasm build_tinygo_test_binary: @@ -227,7 +228,13 @@ jobs: strategy: fail-fast: false # don't fail fast as sometimes failures are arch/OS specific matrix: - os: [ubuntu-22.04, macos-12, windows-2022] + os: [ubuntu-22.04, macos-12, windows-2022] + compiler: [plain] + arch: [amd64] + include: + - os: ubuntu-22.04 + compiler: optimizing + arch: "arm64" steps: - name: Checkout wazero @@ -248,19 +255,47 @@ jobs: with: go-version: ${{ env.GO_VERSION }} - - name: Install wazero - run: go install ./cmd/wazero + - name: Build wazero + run: go build -o ~/wazerocli ./cmd/wazero + env: + GOARCH: ${{ matrix.arch }} + + - name: Set up QEMU + if: ${{ matrix.arch != 'amd64' }} + uses: docker/setup-qemu-action@v2 + with: # Avoid docker.io rate-limits; built with internal-images.yml + image: ghcr.io/tetratelabs/wazero/internal-binfmt + platforms: ${{ matrix.arch }} + + - name: Build scratch container + run: | + echo 'FROM scratch' >> Dockerfile + echo 'CMD ["/test"]' >> Dockerfile + docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . + + - name: Run built test binaries + if: ${{ runner.os != 'Windows' }} + # This runs all tests compiled above in sequence. Note: This mounts /tmp to allow t.TempDir() in tests. + run: | + cd ./tinygobin + for bin in *.test; do + echo $bin + docker run --platform linux/${{ matrix.arch }} -v $(pwd):/test -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ + /wazero run -optimizing-compiler -mount=:/ /test/$bin -- -test.v + done + # This runs the previously compiled TinyGo tests with wazero. If you need # to troubleshoot one, you can add "-hostlogging=filesystem" and also a # trailing argument narrowing which test to execute. # e.g. "-test.run '^TestStatBadDir$'" - name: Run standard library tests + if: ${{ runner.os == 'Windows' }} run: | cd ./tinygobin for bin in *.test; do echo $bin - wazero run -mount=:/ -mount=:/tmp $bin -- -test.v + ~/wazerocli run -mount=:/ -mount=:/tmp $bin -- -test.v done tinygo-opt: From eb2730ad7b352fa22dc2c85c0004ea3d300cf004 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 22:51:51 +0100 Subject: [PATCH 18/22] fix Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 996d32592a..5a966ccd4d 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -75,7 +75,7 @@ jobs: zig: needs: build_zig_test_binary - name: Zig (${{ matrix.os }}) + name: Zig (${{ matrix.os }} / ${{ matrix.arch }} / ${{ matrix.compiler }}) runs-on: ${{ matrix.os }} strategy: fail-fast: false # don't fail fast as sometimes failures are arch/OS specific @@ -113,21 +113,21 @@ jobs: GOARCH: ${{ matrix.arch }} - name: Set up QEMU - if: ${{ matrix.arch != 'amd64' }} + if: ${{ matrix.compiler == 'optimizing' && matrix.arch == 'arm64' }} uses: docker/setup-qemu-action@v2 with: # Avoid docker.io rate-limits; built with internal-images.yml image: ghcr.io/tetratelabs/wazero/internal-binfmt platforms: ${{ matrix.arch }} - name: Build scratch container - if: ${{ runner.os != 'Windows' }} + if: ${{ matrix.compiler == 'optimizing' }} run: | echo 'FROM scratch' >> Dockerfile echo 'CMD ["/test"]' >> Dockerfile docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . - name: Run built test binaries - if: ${{ runner.os != 'Windows' }} + if: ${{ matrix.compiler == 'optimizing' }} # This runs the previously compiled Zig tests with wazero. If you need # to troubleshoot one, you can add "-hostlogging=filesystem" after # adding filter argument to the "Build Stdlib test binary" step. @@ -137,7 +137,7 @@ jobs: /wazero run -optimizing-compiler -mount=:/ ./test/test.wasm - name: Run the test binary with wazero CLI - if: ${{ runner.os == 'Windows' }} + if: ${{ matrix.compiler != 'optimizing' }} run: ./wazerocli run -mount=:/ ./zigbin/test.wasm build_tinygo_test_binary: @@ -223,7 +223,7 @@ jobs: tinygo: needs: build_tinygo_test_binary - name: TinyGo (${{ matrix.os }}) + name: TinyGo (${{ matrix.os }} / ${{ matrix.arch }} / ${{ matrix.compiler }}) runs-on: ${{ matrix.os }} strategy: fail-fast: false # don't fail fast as sometimes failures are arch/OS specific @@ -261,20 +261,21 @@ jobs: GOARCH: ${{ matrix.arch }} - name: Set up QEMU - if: ${{ matrix.arch != 'amd64' }} + if: ${{ matrix.compiler == 'optimizing' && matrix.arch == 'arm64' }} uses: docker/setup-qemu-action@v2 with: # Avoid docker.io rate-limits; built with internal-images.yml image: ghcr.io/tetratelabs/wazero/internal-binfmt platforms: ${{ matrix.arch }} - name: Build scratch container + if: ${{ matrix.compiler == 'optimizing' }} run: | echo 'FROM scratch' >> Dockerfile echo 'CMD ["/test"]' >> Dockerfile docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . - name: Run built test binaries - if: ${{ runner.os != 'Windows' }} + if: ${{ matrix.compiler == 'optimizing' }} # This runs all tests compiled above in sequence. Note: This mounts /tmp to allow t.TempDir() in tests. run: | cd ./tinygobin @@ -290,7 +291,7 @@ jobs: # trailing argument narrowing which test to execute. # e.g. "-test.run '^TestStatBadDir$'" - name: Run standard library tests - if: ${{ runner.os == 'Windows' }} + if: ${{ matrix.compiler != 'optimizing' }} run: | cd ./tinygobin for bin in *.test; do From faa31f6436af46d2272c002b7cba2df433a193c7 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 23:11:26 +0100 Subject: [PATCH 19/22] cleanup Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 146 +---------------------------- 1 file changed, 5 insertions(+), 141 deletions(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 5a9b35ff08..b2543dea2d 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -273,7 +273,7 @@ jobs: echo 'CMD ["/test"]' >> Dockerfile docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . - - name: Run built test binaries + - name: Run test binaries (container) if: ${{ matrix.compiler == 'optimizing' }} # This runs all tests compiled above in sequence. Note: This mounts /tmp to allow t.TempDir() in tests. run: | @@ -289,7 +289,7 @@ jobs: # to troubleshoot one, you can add "-hostlogging=filesystem" and also a # trailing argument narrowing which test to execute. # e.g. "-test.run '^TestStatBadDir$'" - - name: Run standard library tests + - name: Run test binaries if: ${{ matrix.compiler != 'optimizing' }} run: | cd ./tinygobin @@ -514,7 +514,7 @@ jobs: docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . - if: ${{ matrix.compiler == 'optimizing' }} - name: Run standard library tests + name: Run test binaries (container) run: | echo "Running $(find ~/tests -name *.test | wc -l) test binaries" @@ -529,7 +529,7 @@ jobs: done - if: ${{ matrix.compiler != 'optimizing' && runner.os != 'Windows' }} - name: Run standard library tests + name: Run test binaries run: | echo "Running $(find ~/tests -name *.test | wc -l) test binaries" @@ -542,7 +542,7 @@ jobs: done - if: ${{ runner.os == 'Windows' }} - name: Run standard library tests + name: Run test binaries (Windows) # Ack failures on Windows. https://github.com/tetratelabs/wazero/issues/1410 continue-on-error: true run: | @@ -581,139 +581,3 @@ jobs: # Run all the tests in their own shell. $RUNNER - - go_tests_opt: - # Due to the embedding of the GOROOT of the building env(https://github.com/golang/go/blob/3c59639b902fada0a2e5a6a35bafd10fc9183b89/src/os/os_test.go#L112), - # we have to build and cache on each OS unlike others in this file. - name: Go / Optimizing Compiler - runs-on: ${{ matrix.os }} - # needs: go_tests - strategy: - fail-fast: false # don't fail fast as sometimes failures are arch/OS specific - matrix: - os: [ubuntu-22.04] - arch: - - "arm64" - - steps: - - id: setup-go - uses: actions/setup-go@v4 - with: - go-version: ${{ env.GO_VERSION }} - - - name: Cache Go test binaries - id: cache-go-test-binaries - uses: actions/cache@v3 - with: - path: ~/tests - # Use precise Go version from setup-go as patch version differences can effect tests. - key: go-wasip1-binaries-${{ matrix.os }}-${{ steps.setup-go.outputs.go-version }} - - - if: ${{ steps.cache-go-test-binaries.outputs.cache-hit != 'true' }} - name: Build Test Binaries - run: | - mkdir ~/tests - cd $(go env GOROOT) - # Choose important packages to limit execution time. - for value in src/archive/tar \ - src/bufio \ - src/bytes \ - src/context \ - src/encoding/ascii85 \ - src/encoding/asn1 \ - src/encoding/base32 \ - src/encoding/base64 \ - src/encoding/binary \ - src/encoding/csv \ - src/encoding/gob \ - src/encoding/hex \ - src/encoding/json \ - src/encoding/pem \ - src/encoding/xml \ - src/errors \ - src/expvar \ - src/flag \ - src/fmt \ - src/hash \ - src/hash/adler32 \ - src/hash/crc32 \ - src/hash/crc64 \ - src/hash/fnv \ - src/hash/maphash \ - src/io \ - src/io/fs \ - src/io/ioutil \ - src/log \ - src/log/syslog \ - src/maps \ - src/math \ - src/math/big \ - src/math/bits \ - src/math/cmplx \ - src/math/rand \ - src/mime \ - src/mime/multipart \ - src/mime/quotedprintable \ - src/os \ - src/os/exec \ - src/os/signal \ - src/os/user \ - src/path \ - src/reflect \ - src/regexp \ - src/regexp/syntax \ - src/runtime \ - src/runtime/internal/atomic \ - src/runtime/internal/math \ - src/runtime/internal/sys \ - src/slices \ - src/sort \ - src/strconv \ - src/strings \ - src/sync \ - src/sync/atomic \ - src/syscall \ - src/testing \ - src/testing/fstest \ - src/testing/iotest \ - src/testing/quick \ - src/time - do - echo "GOOS=wasip1 GOARCH=wasm go test -v -c -o ~/tests/${value//\//_}.test ./$value" - GOOS=wasip1 GOARCH=wasm go test -v -c -o ~/tests/${value//\//_}.test ./$value - done - - - name: Checkout wazero - uses: actions/checkout@v3 - - - name: Build wazero - run: go build -o ~/wazerocli ./cmd/wazero - env: - GOARCH: ${{ matrix.arch }} - - - name: Set up QEMU - if: ${{ matrix.arch != 'amd64' }} - uses: docker/setup-qemu-action@v2 - with: # Avoid docker.io rate-limits; built with internal-images.yml - image: ghcr.io/tetratelabs/wazero/internal-binfmt - platforms: ${{ matrix.arch }} - - - name: Build scratch container - run: | - echo 'FROM scratch' >> Dockerfile - echo 'CMD ["/test"]' >> Dockerfile - docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . - - - name: Run standard library tests - run: | - echo "Running $(find ~/tests -name *.test | wc -l) test binaries" - - # Go tests often look for files relative to the source. Change to the corresponding directory. - for bin in ~/tests/*.test; do - dir=$(basename $bin); dir=${dir%.test}; dir=${dir//_/\/} - pushd $(go env GOROOT)/$dir - # Mount / as /ROOT in docker and then remount /ROOT as / in wazero; $bin is now in /ROOT/$bin. - docker run --platform linux/arm64 -v /:/ROOT -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ - /wazero run -optimizing-compiler -mount=/ROOT:/ -env PWD=$PWD /ROOT/$bin -- -test.short -test.v - popd - done From 8d67af13a8cbd8d3608dcddd81eaae9447787cfa Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 14 Dec 2023 23:14:14 +0100 Subject: [PATCH 20/22] fix Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index b2543dea2d..3efaa411d6 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -80,6 +80,7 @@ jobs: strategy: fail-fast: false # don't fail fast as sometimes failures are arch/OS specific matrix: + os: [ubuntu-22.04, macos-12, windows-2022] compiler: [baseline] arch: [amd64] include: From 1ac6ee34222daf3dc8b337cd062ec19c8fbae7e6 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Fri, 15 Dec 2023 11:04:04 +0100 Subject: [PATCH 21/22] fix Signed-off-by: Edoardo Vacchi --- .github/workflows/integration.yaml | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 3efaa411d6..0e7c87d260 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -126,17 +126,20 @@ jobs: echo 'CMD ["/test"]' >> Dockerfile docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . - - name: Run built test binaries + + # The following two steps run the previously compiled Zig tests with wazero. + # If you need to troubleshoot any of the test, you can add "-hostlogging=filesystem" after + # adding filter argument either to step "Run built test binaries" or + # "Run built test binaries (container)". + # e.g. --test-filter "Dir.Iterator but dir is deleted during iteration" + + - name: Run built test binaries (container) if: ${{ matrix.compiler == 'optimizing' }} - # This runs the previously compiled Zig tests with wazero. If you need - # to troubleshoot one, you can add "-hostlogging=filesystem" after - # adding filter argument to the "Build Stdlib test binary" step. - # e.g. --test-filter "Dir.Iterator but dir is deleted during iteration" run: | docker run --platform linux/${{ matrix.arch }} -v $(pwd)/zigbin:/test -v $(pwd)/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ /wazero run -optimizing-compiler -mount=:/ ./test/test.wasm - - name: Run the test binary with wazero CLI + - name: Run built test binaries if: ${{ matrix.compiler != 'optimizing' }} run: ./wazerocli run -mount=:/ ./zigbin/test.wasm @@ -274,6 +277,11 @@ jobs: echo 'CMD ["/test"]' >> Dockerfile docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . + # The following steps run the previously compiled TinyGo tests with wazero. If you need + # to troubleshoot one, you can add "-hostlogging=filesystem" and also a + # trailing argument narrowing which test to execute. + # e.g. "-test.run '^TestStatBadDir$'" + - name: Run test binaries (container) if: ${{ matrix.compiler == 'optimizing' }} # This runs all tests compiled above in sequence. Note: This mounts /tmp to allow t.TempDir() in tests. @@ -285,11 +293,6 @@ jobs: /wazero run -optimizing-compiler -mount=:/ /test/$bin -- -test.v done - - # This runs the previously compiled TinyGo tests with wazero. If you need - # to troubleshoot one, you can add "-hostlogging=filesystem" and also a - # trailing argument narrowing which test to execute. - # e.g. "-test.run '^TestStatBadDir$'" - name: Run test binaries if: ${{ matrix.compiler != 'optimizing' }} run: | @@ -525,7 +528,7 @@ jobs: pushd $(go env GOROOT)/$dir # Mount / as /ROOT in docker and then remount /ROOT as / in wazero; $bin is now in /ROOT/$bin. docker run --platform linux/arm64 -v /:/ROOT -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ - /wazero run -optimizing-compiler -mount=/ROOT:/ -env PWD=$PWD /ROOT/$bin -- -test.short -test.v + /wazero run -optimizing-compiler -mount=/ROOT:/ -mount=/tmp:/tmp -env PWD=$PWD /ROOT/$bin -- -test.short -test.v popd done From 4f0398066076f2ee00f219b0829f1fa90abec345 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Fri, 15 Dec 2023 11:31:13 +0100 Subject: [PATCH 22/22] bump Signed-off-by: Edoardo Vacchi --- internal/engine/wazevo/call_engine.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/engine/wazevo/call_engine.go b/internal/engine/wazevo/call_engine.go index 85515de47f..a38963f203 100644 --- a/internal/engine/wazevo/call_engine.go +++ b/internal/engine/wazevo/call_engine.go @@ -395,7 +395,7 @@ func opaqueViewFromPtr(ptr uintptr) []byte { return opaque } -const callStackCeiling = uintptr(5000000) // in uint64 (8 bytes) == 40000000 bytes in total == 40mb. +const callStackCeiling = uintptr(50000000) // in uint64 (8 bytes) == 40000000 bytes in total == 40mb. func (c *callEngine) growStackWithGuarded() (newSP uintptr, err error) { if wazevoapi.StackGuardCheckEnabled {