From ebf70ab18ebe9e6bbcd2ce76c2cc2c16d86ba633 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Fri, 7 Mar 2025 11:40:37 +0100 Subject: [PATCH] ci: add more tests for wasm and baremetal Run a range of tests in CI, to make sure browser wasm and baremetal don't regress too badly. I have intentionally filtered out tests, so that newly added tests to TEST_PACKAGES_FAST will be added here as well (and can be excluded if needed). --- .github/workflows/linux.yml | 2 +- GNUmakefile | 50 +++++++++++++++++++++++++++++++------ targets/riscv-qemu.ld | 10 ++++---- 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index a0a908635..0a8fabf1f 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -278,7 +278,7 @@ jobs: run: make tinygo-test - run: make smoketest - run: make wasmtest - - run: make tinygo-baremetal + - run: make tinygo-test-baremetal build-linux-cross: # Build ARM Linux binaries, ready for release. # This intentionally uses an older Linux image, so that we compile against diff --git a/GNUmakefile b/GNUmakefile index 13481aab7..6e626a488 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -407,8 +407,45 @@ TEST_PACKAGES_WINDOWS := \ text/template/parse \ $(nil) -TEST_PACKAGES_WASM := \ - crypto/sha256 + +# These packages cannot be tested on wasm, mostly because these tests assume a +# working filesystem. This could perhaps be fixed, by supporting filesystem +# access when running inside Node.js. +TEST_PACKAGES_WASM = $(filter-out $(TEST_PACKAGES_NONWASM), $(TEST_PACKAGES_FAST)) +TEST_PACKAGES_NONWASM = \ + compress/lzw \ + compress/zlib \ + crypto/ecdsa \ + debug/macho \ + embed/internal/embedtest \ + go/format \ + os \ + testing \ + $(nil) + +# These packages cannot be tested on baremetal. +# +# Some reasons why the tests don't pass on baremetal: +# +# * No filesystem is available, so packages like compress/zlib can't be tested +# (just like wasm). +# * There is no RNG implemented (TODO, I think this is fixable). +# * picolibc math functions apparently are less precise, the math package +# fails on baremetal. +# * Some packages fail or hang for an unknown reason, this should be +# investigated and fixed. +TEST_PACKAGES_BAREMETAL = $(filter-out $(TEST_PACKAGES_NONBAREMETAL), $(TEST_PACKAGES_FAST)) +TEST_PACKAGES_NONBAREMETAL = \ + $(TEST_PACKAGES_NONWASM) \ + crypto/elliptic \ + crypto/md5 \ + crypto/sha1 \ + math \ + reflect \ + encoding/asn1 \ + encoding/base32 \ + go/ast \ + $(nil) # Report platforms on which each standard library package is known to pass tests jointmp := $(shell echo /tmp/join.$$$$) @@ -489,6 +526,10 @@ tinygo-bench-wasip2: tinygo-bench-wasip2-fast: $(TINYGO) test -target wasip2 -bench . $(TEST_PACKAGES_FAST) +# Run tests on riscv-qemu since that one provides a large amount of memory. +tinygo-test-baremetal: + $(TINYGO) test -target riscv-qemu $(TEST_PACKAGES_BAREMETAL) + # Test external packages in a large corpus. test-corpus: CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus . -corpus=testdata/corpus.yaml @@ -499,11 +540,6 @@ test-corpus-wasi: wasi-libc test-corpus-wasip2: wasi-libc CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus . -corpus=testdata/corpus.yaml -target=wasip2 -tinygo-baremetal: - # Regression tests that run on a baremetal target and don't fit in either main_test.go or smoketest. - # regression test for #2666: e.g. encoding/hex must pass on baremetal - $(TINYGO) test -target cortex-m-qemu encoding/hex - .PHONY: testchdir testchdir: # test 'build' command with{,out} -C argument diff --git a/targets/riscv-qemu.ld b/targets/riscv-qemu.ld index ab344571e..822c00d10 100644 --- a/targets/riscv-qemu.ld +++ b/targets/riscv-qemu.ld @@ -1,16 +1,16 @@ /* Memory map: * https://github.com/qemu/qemu/blob/master/hw/riscv/virt.c - * RAM and flash are set to 1MB each. That should be enough for the foreseeable - * future. QEMU does not seem to limit the flash/RAM size and in fact doesn't - * seem to differentiate between it. + * Looks like we can use any address starting from 0x80000000 (so 2GB of space). + * However, using a large space slows down tests. */ MEMORY { - FLASH_TEXT (rw) : ORIGIN = 0x80000000, LENGTH = 0x100000 - RAM (xrw) : ORIGIN = 0x80100000, LENGTH = 0x100000 + RAM (rwx) : ORIGIN = 0x80000000, LENGTH = 100M } +REGION_ALIAS("FLASH_TEXT", RAM) + _stack_size = 2K; INCLUDE "targets/riscv.ld"