github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/.github/workflows/integration.yaml (about) 1 name: Standard Library Integration Tests 2 on: 3 pull_request: 4 branches: [main] 5 paths-ignore: # ignore docs as they are built with Netlify. 6 - '**/*.md' 7 - 'site/**' 8 - 'netlify.toml' 9 push: 10 branches: [main] 11 paths-ignore: # ignore docs as they are built with Netlify. 12 - '**/*.md' 13 - 'site/**' 14 - 'netlify.toml' 15 16 defaults: 17 run: # use bash for all operating systems unless overridden 18 shell: bash 19 20 env: # Update this prior to requiring a higher minor version in go.mod 21 GO_VERSION: "1.21" # 1.xx == latest patch of 1.xx 22 TINYGO_VERSION: "0.30.0" 23 ZIG_VERSION: "0.11.0" 24 BINARYEN_VERSION: "116" 25 STDLIB_TESTS: "internal/integration_test/stdlibs" 26 27 concurrency: 28 # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-concurrency-to-cancel-any-in-progress-job-or-run 29 group: ${{ github.ref }}-${{ github.workflow }}-${{ github.actor }} 30 cancel-in-progress: true 31 32 jobs: 33 # This builds a zig test binary only if the same version tag hasn't been build before. 34 # This saves time as we rarely update the zig version. 35 build_zig_test_binary: 36 name: Build Zig test binary 37 runs-on: ubuntu-22.04 38 env: 39 ZIG_INSTALL: ~/zig-install 40 ZIG_SOURCE: ~/zig-source 41 BINARYEN_INSTALL: ~/binaryen-install 42 43 steps: 44 - name: Checkout wazero 45 uses: actions/checkout@v3 46 47 - uses: actions/cache@v3 48 id: binary-cache 49 with: 50 # Use share the cache containing archives across OSes. 51 enableCrossOsArchive: true 52 key: zig-stdlib-test-binary-${{ env.ZIG_VERSION }} 53 path: 54 ${{ env.STDLIB_TESTS }}/testdata/zig 55 56 - name: Install Zig build 57 if: steps.binary-cache.outputs.cache-hit != 'true' 58 run: | 59 mkdir -p ${{ env.ZIG_INSTALL }} 60 curl -sSL https://ziglang.org/download/${{ env.ZIG_VERSION }}/zig-linux-x86_64-${{ env.ZIG_VERSION }}.tar.xz | tar -xJ --strip-components=1 -C ${{ env.ZIG_INSTALL }} 61 62 - name: Download Zig source code 63 if: steps.binary-cache.outputs.cache-hit != 'true' 64 run: | 65 mkdir -p ${{ env.ZIG_SOURCE }} 66 curl -sSL https://ziglang.org/download/${{ env.ZIG_VERSION }}/zig-${{ env.ZIG_VERSION }}.tar.xz | tar -xJ --strip-components=1 -C ${{ env.ZIG_SOURCE }} 67 68 - name: Install Binaryen build 69 if: steps.binary-cache.outputs.cache-hit != 'true' 70 run: | 71 mkdir -p ${{ env.BINARYEN_INSTALL }} 72 curl -sSL https://github.com/WebAssembly/binaryen/releases/download/version_${{ env.BINARYEN_VERSION }}/binaryen-version_${{ env.BINARYEN_VERSION }}-x86_64-linux.tar.gz | tar -xz --strip-components=1 -C ${{ env.BINARYEN_INSTALL }} 73 74 - name: Build Stdlib test binary 75 if: steps.binary-cache.outputs.cache-hit != 'true' 76 # --test-no-exec allows building of the test Wasm binary without executing command. 77 # We use find because the test.wasm will be something like ./zig-cache/o/dd6df1361b2134adc5eee9d027495436/test.wasm 78 run: | 79 PATH=${{ env.ZIG_INSTALL }}:${{ env.BINARYEN_INSTALL }}/bin:$PATH 80 cd ${{ env.STDLIB_TESTS }} 81 make build.zig zigroot=${{ env.ZIG_SOURCE }} 82 83 zig: 84 needs: build_zig_test_binary 85 name: Zig (${{ matrix.os.name }}, ${{ matrix.arch }}, ${{ matrix.compiler }}) 86 runs-on: ${{ matrix.os.version }} 87 strategy: 88 fail-fast: false # don't fail fast as sometimes failures are arch/OS specific 89 matrix: 90 # version is too verbose to be present in the name, so we use the name instead. 91 # Note that it'd be better to use runner.os in the name, but the runner context is not available in the name field. 92 os: 93 - version: ubuntu-22.04 94 name: Ubuntu 95 - version: macos-12 96 name: macOS 97 - version: windows-2022 98 name: Windows 99 compiler: [baseline] 100 arch: [amd64] 101 include: 102 - os: 103 version: ubuntu-22.04 104 name: Ubuntu 105 compiler: optimizing 106 arch: "arm64" 107 108 steps: 109 - name: Checkout wazero 110 uses: actions/checkout@v3 111 112 - uses: actions/cache@v3 113 id: binary-cache 114 with: 115 # Use share the cache containing archives across OSes. 116 enableCrossOsArchive: true 117 # We need this cache to run tests. 118 fail-on-cache-miss: true 119 key: zig-stdlib-test-binary-${{ env.ZIG_VERSION }} 120 path: 121 ${{ env.STDLIB_TESTS }}/testdata/zig 122 123 - uses: actions/setup-go@v4 124 with: 125 go-version: ${{ env.GO_VERSION }} 126 127 - if: ${{ matrix.compiler == 'optimizing' }} 128 name: Build wazero 129 run: go build -o ./wazerocli ./cmd/wazero 130 env: 131 GOARCH: ${{ matrix.arch }} 132 133 - name: Set up QEMU 134 if: ${{ matrix.compiler == 'optimizing' && matrix.arch == 'arm64' }} 135 uses: docker/setup-qemu-action@v2 136 with: # Avoid docker.io rate-limits; built with internal-images.yml 137 image: ghcr.io/tetratelabs/wazero/internal-binfmt 138 platforms: ${{ matrix.arch }} 139 140 - name: Build scratch container 141 if: ${{ matrix.compiler == 'optimizing' }} 142 run: | 143 echo 'FROM scratch' >> Dockerfile 144 echo 'CMD ["/test"]' >> Dockerfile 145 docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . 146 147 148 # The following two steps run the previously compiled Zig tests with wazero. 149 # If you need to troubleshoot any of the test, you can add "-hostlogging=filesystem" after 150 # adding filter argument either to step "Run built test binaries" or 151 # "Run built test binaries (container)". 152 # e.g. --test-filter "Dir.Iterator but dir is deleted during iteration" 153 154 - name: Run built test binaries (container) 155 if: ${{ matrix.compiler == 'optimizing' }} 156 run: | 157 docker run --platform linux/${{ matrix.arch }} -v $(pwd)/${{ env.STDLIB_TESTS }}/testdata/zig:/test -v $(pwd)/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ 158 /wazero run -optimizing-compiler -mount=:/ ./test/test.wasm 159 160 - name: Run built test binaries 161 if: ${{ matrix.compiler != 'optimizing' }} 162 run: | 163 cd ${{ env.STDLIB_TESTS }} 164 go test -bench='BenchmarkZig' -benchtime=1x 165 166 build_tinygo_test_binary: 167 name: Build TinyGo test binary 168 runs-on: ubuntu-22.04 169 steps: 170 - name: Checkout wazero 171 uses: actions/checkout@v3 172 173 - uses: actions/cache@v3 174 id: binary-cache 175 with: 176 # Use share the cache containing archives across OSes. 177 enableCrossOsArchive: true 178 key: tinygo-test-binaries-${{ env.TINYGO_VERSION }} 179 path: 180 ${{ env.STDLIB_TESTS }}/testdata/tinygo 181 182 - name: Install TinyGo 183 if: steps.binary-cache.outputs.cache-hit != 'true' 184 run: | # installing via curl so commands are similar on OS/x 185 tinygo_version=${{ env.TINYGO_VERSION }} 186 curl -sSL https://github.com/tinygo-org/tinygo/releases/download/v${tinygo_version}/tinygo${tinygo_version}.linux-amd64.tar.gz | sudo tar -C /usr/local -xzf - 187 echo "TINYGOROOT=/usr/local/tinygo" >> $GITHUB_ENV 188 echo "/usr/local/tinygo/bin" >> $GITHUB_PATH 189 190 - uses: actions/setup-go@v4 191 if: steps.binary-cache.outputs.cache-hit != 'true' 192 with: 193 go-version: ${{ env.GO_VERSION }} 194 195 - name: Build Test Binaries 196 if: steps.binary-cache.outputs.cache-hit != 'true' 197 # The following list of packages is derived from: 198 # https://github.com/tinygo-org/tinygo/blob/v0.28.1/Makefile#L281-L322 199 # Note: 200 # - index/suffixarray is extremely slow, so skip it. 201 # - compress/zlib is skipped as it depends on the local files https://github.com/golang/go/blob/go1.20/src/compress/zlib/writer_test.go#L16-L30 202 # - debug/macho is skipped as it depends on the local files https://github.com/golang/go/blob/go1.20/src/debug/macho/file_test.go#L25 203 run: | 204 cd ${{ env.STDLIB_TESTS }} 205 make build.tinygo 206 207 tinygo: 208 needs: build_tinygo_test_binary 209 name: TinyGo (${{ matrix.os.name }}, ${{ matrix.arch }}, ${{ matrix.compiler }}) 210 runs-on: ${{ matrix.os.version }} 211 strategy: 212 fail-fast: false # don't fail fast as sometimes failures are arch/OS specific 213 matrix: 214 # version is too verbose to be present in the name, so we use the name instead. 215 # Note that it'd be better to use runner.os in the name, but the runner context is not available in the name field. 216 os: 217 - version: ubuntu-22.04 218 name: Ubuntu 219 - version: macos-12 220 name: macOS 221 - version: windows-2022 222 name: Windows 223 compiler: [baseline] 224 arch: [amd64] 225 include: 226 - os: 227 version: ubuntu-22.04 228 name: Ubuntu 229 compiler: optimizing 230 arch: "arm64" 231 232 steps: 233 - name: Checkout wazero 234 uses: actions/checkout@v3 235 236 - uses: actions/cache@v3 237 id: binary-cache 238 with: 239 # Use share the cache containing archives across OSes. 240 enableCrossOsArchive: true 241 # We need this cache to run tests. 242 fail-on-cache-miss: true 243 key: tinygo-test-binaries-${{ env.TINYGO_VERSION }} 244 path: 245 ${{ env.STDLIB_TESTS }}/testdata/tinygo 246 247 - uses: actions/setup-go@v4 248 with: 249 go-version: ${{ env.GO_VERSION }} 250 251 - if: ${{ matrix.compiler == 'optimizing' }} 252 name: Build wazero 253 run: go build -o ~/wazerocli ./cmd/wazero 254 env: 255 GOARCH: ${{ matrix.arch }} 256 257 - name: Set up QEMU 258 if: ${{ matrix.compiler == 'optimizing' && matrix.arch == 'arm64' }} 259 uses: docker/setup-qemu-action@v2 260 with: # Avoid docker.io rate-limits; built with internal-images.yml 261 image: ghcr.io/tetratelabs/wazero/internal-binfmt 262 platforms: ${{ matrix.arch }} 263 264 - name: Build scratch container 265 if: ${{ matrix.compiler == 'optimizing' }} 266 run: | 267 echo 'FROM scratch' >> Dockerfile 268 echo 'CMD ["/test"]' >> Dockerfile 269 docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . 270 271 # The following steps run the previously compiled TinyGo tests with wazero. If you need 272 # to troubleshoot one, you can add "-hostlogging=filesystem" and also a 273 # trailing argument narrowing which test to execute. 274 # e.g. "-test.run '^TestStatBadDir$'" 275 276 - name: Run test binaries (container) 277 if: ${{ matrix.compiler == 'optimizing' }} 278 # This runs all tests compiled above in sequence. Note: This mounts /tmp to allow t.TempDir() in tests. 279 run: | 280 cd ${{ env.STDLIB_TESTS }}/testdata/tinygo 281 for bin in *.test; do 282 echo $bin 283 docker run --platform linux/${{ matrix.arch }} -v $(pwd):/test -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ 284 /wazero run -optimizing-compiler -mount=:/ /test/$bin -- -test.v 285 done 286 287 - name: Run test binaries 288 if: ${{ matrix.compiler != 'optimizing' }} 289 run: | 290 cd ${{ env.STDLIB_TESTS }} 291 go test -bench='BenchmarkTinyGo' -benchtime=1x 292 293 wasi-testsuite: 294 name: wasi-testsuite 295 runs-on: ${{ matrix.os }} 296 strategy: 297 fail-fast: false # don't fail fast as sometimes failures are arch/OS specific 298 matrix: 299 os: [ubuntu-22.04, macos-12, windows-2022] 300 301 steps: 302 - uses: actions/cache@v3 303 id: cache 304 with: 305 path: 306 ~/go/pkg/mod 307 key: integration-test-wasi-testsuite-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ hashFiles('**/go.sum') }} 308 309 - uses: actions/setup-go@v4 310 with: 311 go-version: ${{ env.GO_VERSION }} 312 313 - name: Checkout wazero 314 uses: actions/checkout@v3 315 316 - name: Install wazero 317 run: go install ./cmd/wazero 318 319 - name: Checkout wasi-testsuite 320 uses: actions/checkout@v3 321 with: 322 repository: WebAssembly/wasi-testsuite 323 # prod/testsuite-base branch, as of May 12, 2023. 324 # TODO: once the wasi-testsuite is stable, we should use the latest tag instead of a branch. 325 ref: c9c751586fd86b321d595bbef13f2c7403cfdbc5 326 path: wasi-testsuite 327 328 - name: Initialize Python environment 329 uses: actions/setup-python@v4 330 with: 331 python-version: '3.11' # latest version of python 3 332 cache: pip 333 334 - name: Install dependencies 335 working-directory: wasi-testsuite/test-runner 336 run: | 337 python3 -m pip install -r requirements.txt 338 339 - name: Run all wasi-testsuite 340 working-directory: wasi-testsuite 341 run: | 342 python3 test-runner/wasi_test_runner.py \ 343 -t ./tests/assemblyscript/testsuite/ \ 344 ./tests/c/testsuite/ \ 345 ./tests/rust/testsuite/ \ 346 -f ../.github/wasi_testsuite_skip.json \ 347 -r ../.github/wasi_testsuite_adapter.py 348 349 gojs_stdlib: 350 name: Go (js) (${{ matrix.os }}) 351 runs-on: ${{ matrix.os }} 352 strategy: 353 fail-fast: false # don't fail fast as sometimes failures are arch/OS specific 354 matrix: 355 os: [ubuntu-22.04, macos-12] # GOOS=js isn't supposed to work on windows. See #1222 356 357 steps: 358 - uses: actions/setup-go@v4 359 with: 360 go-version: ${{ env.GO_VERSION }} 361 362 - name: Checkout wazero 363 uses: actions/checkout@v3 364 365 - name: Install wazero 366 run: go install ./cmd/wazero 367 368 - name: Build gojs test binaries 369 env: 370 GOOS: js 371 GOARCH: wasm 372 run: | # Only test os package as this is being replaced by GOOS=wasip1 373 mkdir ~/bin && cd ~/bin 374 go test -c -o os.wasm os 375 376 - name: Run tests 377 run: | # skip tests that use functionality not also used in GOOS=wasip1 378 cd $(go env GOROOT)/src/os; wazero run -mount=/:/ ~/bin/os.wasm -test.v -test.skip '^Test(Chmod|Truncate|LongPath|Chown|FileChown).*$' 379 380 go_tests: 381 # Due to the embedding of the GOROOT of the building env(https://github.com/golang/go/blob/3c59639b902fada0a2e5a6a35bafd10fc9183b89/src/os/os_test.go#L112), 382 # we have to build and cache on each OS unlike others in this file. 383 name: Go-${{ matrix.go-version }} (${{ matrix.os.name }}, ${{ matrix.arch }}, ${{ matrix.compiler }}) 384 runs-on: ${{ matrix.os.version }} 385 strategy: 386 fail-fast: false # don't fail fast as sometimes failures are arch/OS specific 387 matrix: 388 # version is too verbose to be present in the name, so we use the name instead. 389 # Note that it'd be better to use runner.os in the name, but the runner context is not available in the name field. 390 os: 391 - version: ubuntu-22.04 392 name: Ubuntu 393 - version: macos-12 394 name: macOS 395 - version: windows-2022 396 name: Windows 397 compiler: [baseline] 398 arch: [amd64] 399 go-version: 400 - "1.21" # Current Go version && The only version that supports wasip1. 401 include: 402 - os: 403 version: ubuntu-22.04 404 name: Ubuntu 405 compiler: optimizing 406 arch: "arm64" 407 go-version: "1.21" 408 steps: 409 - id: setup-go 410 uses: actions/setup-go@v4 411 with: 412 go-version: ${{ matrix.go-version }} 413 414 - name: Checkout wazero 415 uses: actions/checkout@v3 416 417 - name: Cache Go test binaries 418 id: cache-go-test-binaries 419 uses: actions/cache@v3 420 with: 421 path: 422 ${{ env.STDLIB_TESTS }}/testdata/go 423 # Use precise Go version from setup-go as patch version differences can effect tests. 424 key: go-wasip1-binaries-${{ matrix.os.version }}-${{ steps.setup-go.outputs.go-version }}-${{ matrix.arch }} 425 426 - if: ${{ matrix.compiler == 'optimizing' }} 427 name: Build wazero 428 run: go build -o ~/wazerocli ./cmd/wazero 429 env: 430 GOARCH: ${{ matrix.arch }} 431 432 - if: ${{ steps.cache-go-test-binaries.outputs.cache-hit != 'true' }} 433 name: Build Test Binaries 434 run: | 435 cd ${{ env.STDLIB_TESTS }} 436 make build.gowasip1 437 438 - name: Set up QEMU 439 if: ${{ matrix.compiler == 'optimizing' && matrix.arch == 'arm64' }} 440 uses: docker/setup-qemu-action@v2 441 with: # Avoid docker.io rate-limits; built with internal-images.yml 442 image: ghcr.io/tetratelabs/wazero/internal-binfmt 443 platforms: ${{ matrix.arch }} 444 445 - name: Build scratch container 446 if: ${{ matrix.compiler == 'optimizing' }} 447 run: | 448 echo 'FROM scratch' >> Dockerfile 449 echo 'CMD ["/test"]' >> Dockerfile 450 docker buildx build -t wazero:test --platform linux/${{ matrix.arch }} . 451 452 - if: ${{ matrix.compiler == 'optimizing' }} 453 name: Run test binaries (container) 454 run: | 455 echo "Running $(find ${{ env.STDLIB_TESTS }}/testdata/go -name '*.test' | wc -l) test binaries" 456 457 # Skip tests that are hideously slow (mostly compilation time) for running inside QEMU. 458 skip_targets="src_encoding_json|src_runtime|src_os_exec|src_math_big|src_encoding_gob|src_time|src_archive_tar|src_math_rand|src_expvar|src_testing|src_os" 459 # Go tests often look for files relative to the source. Change to the corresponding directory. 460 for bin in $(find $PWD/${{ env.STDLIB_TESTS }}/testdata/go -name '*.test' | grep -vE "$skip_targets"); do 461 dir=$(basename $bin); dir=${dir%.test}; dir=${dir//_/\/} 462 pushd $(go env GOROOT)/$dir 463 # Mount / as /ROOT in docker and then remount /ROOT as / in wazero; $bin is now in /ROOT/$bin. 464 docker run --platform linux/arm64 -v /:/ROOT -v ~/wazerocli:/wazero -e WAZEROCLI=/wazero --tmpfs /tmp --rm -t wazero:test \ 465 /wazero run -optimizing-compiler -mount=/ROOT:/ -mount=/tmp:/tmp -env PWD=$PWD /ROOT/$bin -- -test.short -test.v 466 popd 467 done 468 469 - name: Run built test binaries 470 if: ${{ matrix.compiler != 'optimizing' }} 471 run: | 472 cd ${{ env.STDLIB_TESTS }} 473 go test -bench='BenchmarkWasip1' -benchtime=1x