aboutsummaryrefslogtreecommitdiffhomepage
path: root/main_test.go
AgeCommit message (Collapse)Author
2022-01-09avr: use a stack size of 512 bytes for testingAyke van Laethem
The goroutine tests are failing with the default 256 byte stack size.
2022-01-07src/testing: support -bench option to run benchmarks matching the given pattern.Dan Kegel
2022-01-03main (test): add tests to `tinygo test`Nia Waldvogel
2022-01-02avr: fix time.Sleep() in init codeAyke van Laethem
In the early days of TinyGo, the idea of `postinit` was to enable interrupts only after initializers have run. Which kind of makes sense... except that `time.Sleep` is allowed in init code and `time.Sleep` requires interrupts to be enabled. Therefore, interrupts must be enabled while initializers are being run. This commit simply moves the enabling of interrupts to a point right before running package initializers. It also removes `runtime.postinit`, which is not necessary anymore (and was only used on AVR).
2022-01-01main (test): run tests on AVRNia
2021-12-30builder: refactor job runner and use a shared semaphore across build jobsNia Waldvogel
Switching to a shared semaphore allows multi-build operations (compiler tests, package tests, etc.) to use the expected degree of parallelism efficiently. While refactoring the job runner, the time complexity was also reduced from O(n^2) to O(n+m) (where n is the number of jobs, and m is the number of dependencies).
2021-12-30main (test): remove global build lockNia Waldvogel
2021-11-17wasm: support -scheduler=noneAyke van Laethem
Previously, -scheduler=none wasn't possible for WASM targets: $ tinygo run -target=wasm -scheduler=none ./testdata/stdlib.go src/runtime/runtime_wasm_js.go:34:2: attempted to start a goroutine without a scheduler With this commit, it works just fine: $ tinygo run -target=wasm -scheduler=none ./testdata/stdlib.go stdin: /dev/stdin stdout: /dev/stdout stderr: /dev/stderr pseudorandom number: 1298498081 strings.IndexByte: 2 strings.Replace: An-example-string Supporting `-scheduler=none` has some benefits: * it reduces file size a lot compared to having a scheduler * it allows JavaScript to call exported functions
2021-11-17ci: move all cross compilation tests to LinuxAyke van Laethem
The idea here is as follows: - Run all Linux and cross compilation tests in the asser-test-linux job. - Only run native tests on MacOS and Windows. This reduces testing time on MacOS and Windows, which are generally more expensive in CI. Also, by not duplicating tests in Windows and MacOS we can reduce overall CI usage a bit. I've also changed the assert-test-linux job a bit to so that the tests that are more likely to break and the tests that are only run in assert-test-linux are run first.
2021-11-16all: add support for windows/amd64Ayke van Laethem
This uses Mingw-w64, which seems to be the de facto standard for porting Unixy programs to Windows.
2021-11-15wasi: restore support for -scheduler=noneAyke van Laethem
The assembly symbols were not marked as hidden and so were exported, leading to unreferenced symbols. Example error message: Error: failed to run main module `/tmp/tinygo3961039405/main` Caused by: 0: failed to instantiate "/tmp/tinygo3961039405/main" 1: unknown import: `asyncify::stop_rewind` has not been defined This commit fixes this issue.
2021-11-15all: add support for GOARMAyke van Laethem
This environment variable can be set to 5, 6, or 7 and controls which ARM version (ARMv5, ARMv6, ARMv7) is used when compiling for GOARCH=arm. I have picked the default value ARMv6, which I believe is supported on most common single board computers including all Raspberry Pis. The difference in code size is pretty big. We could even go further and support ARMv4 if anybody is interested. It should be pretty simple to add this if needed.
2021-10-06main: use emulator exit code instead of parsing test outputAyke van Laethem
This commit changes `tinygo test` to always look at the exit code of the running test, instead of looking for a "PASS" string at the end of the output. This is possible now that the binaries running under qemu-system-arm or qemu-system-riscv32 will signal the correct exit code when they exit. As a side effect, this also makes it possible to avoid the "PASS" line between successful tests. Before: $ tinygo test container/heap container/list PASS ok container/heap 0.001s PASS ok container/list 0.001s After: $ tinygo test container/heap container/list ok container/heap 0.001s ok container/list 0.001s The new behavior is more in line with upstream Go: go test container/heap container/list ok container/heap 0.004s ok container/list 0.004s
2021-10-04main: test other architectures by specifying a different GOARCHAyke van Laethem
... instead of setting a special -target= value. This is more robust and makes sure that the test actually tests different arcitectures as they would be compiled by TinyGo. As an example, the bug of the bugfix in the previous commit ("arm: use armv7 instead of thumbv7") would have been caught if this change was applied earlier. I've decided to put GOOS/GOARCH in compileopts.Options, as it makes sense to me to treat them the same way as command line parameters.
2021-09-28build: normalize target triples to match ClangAyke van Laethem
This commit changes a target triple like "armv6m-none-eabi" to "armv6m-unknown-unknow-eabi". The reason is that while the former is correctly parsed in Clang (due to normalization), it wasn't parsed correctly in LLVM meaning that the environment wasn't set to EABI. This change normalizes all target triples and uses the EABI environment (-eabi in the triple) for Cortex-M targets. This change also drops the `--target=` flag in the target JSON files, the flag is now added implicitly in `(*compileopts.Config).CFlags()`. This removes some duplication in target JSON files. Unfortunately, this change also increases code size for Cortex-M targets. It looks like LLVM now emits calls like __aeabi_memmove instead of memmove, which pull in slightly more code (they basically just call the regular C functions) and the calls themself don't seem to be as efficient as they could be. Perhaps this is a LLVM bug that will be fixed in the future, as this is a very common occurrence.
2021-08-30compiler: add support for new language features of Go 1.17Ayke van Laethem
2021-08-16all: use new testing features of Go 1.14 and 1.15Ayke van Laethem
This simplifies the tests a bit.
2021-08-16ci: drop support for Go 1.13 and 1.14Ayke van Laethem
They aren't supported anymore in CI, and because untested code is broken code, let's remove support for these Go versions altogether.
2021-08-13testing: add support for the -test.v flagAyke van Laethem
This flag is passed automatically with the (new) -v flag for TinyGo. For example, this prints all the test outputs: $ tinygo test -v crypto/md5 === RUN TestGolden --- PASS: TestGolden === RUN TestGoldenMarshal --- PASS: TestGoldenMarshal === RUN TestLarge --- PASS: TestLarge === RUN TestBlockGeneric --- PASS: TestBlockGeneric === RUN TestLargeHashes --- PASS: TestLargeHashes PASS ok crypto/md5 0.002s This prints just a summary: $ tinygo test crypto/md5 PASS ok crypto/md5 0.002s (The superfluous 'PASS' message may be removed in the future). This is especially useful when testing a large number of packages: $ tinygo test crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 PASS ok crypto/md5 0.002s PASS ok crypto/sha1 0.043s PASS ok crypto/sha256 0.002s PASS ok crypto/sha512 0.003s At the moment, the -test.v flag is not supplied to binaries running in emulation. I intend to fix this after https://github.com/tinygo-org/tinygo/pull/2038 lands by refactoring runPackageTest, Run, and runTestWithConfig in the main package which all do something similar.
2021-08-12baremetal,wasm: support command line params and environment variablesAyke van Laethem
This is mainly useful to be able to run `tinygo test`, for example: tinygo test -target=cortex-m-qemu -v math This is not currently supported, but will be in the future.
2021-08-05wasm: add support for the crypto/rand packageAyke van Laethem
This is done via wasi-libc and the WASI interface, for ease of maintenance (only one implementation for both WASI and JS/browsers).
2021-07-15wasm: override dlmalloc heap implementation from wasi-libcAyke van Laethem
These two heaps conflict with each other, so that if any function uses the dlmalloc heap implementation it will eventually result in memory corruption. This commit fixes this by implementing all heap-related functions. This overrides the functions that are implemented in wasi-libc. That's why all of them are implemented (even if they just panic): to make sure no program accidentally uses the wrong one.
2021-05-26main: rename goroutine testsAyke van Laethem
While LLVM coroutines are one implementation of goroutines, it is not the only one. Therefore, rename the tests to 'goroutines' to better describe what they're for.
2021-04-21runtime: implement command line arguments in hosted environmentsAyke van Laethem
Implement command line arguments for Linux, MacOS and WASI.
2021-04-21runtime: implement environment variables for LinuxAyke van Laethem
2021-04-09main: implement -ldflags="-X ..."Ayke van Laethem
This commit implements replacing some global variables with a different value, if the global variable has no initializer. For example, if you have: package main var version string you can replace the value with -ldflags="-X main.version=0.2". Right now it only works for uninitialized globals. The Go tooling also supports initialized globals (var version = "<undefined>") but that is a bit hard to combine with how initialized globals are currently implemented. The current implementation still allows caching package IR files while making sure the values don't end up in the build cache. This means compiling a program multiple times with different values will use the cached package each time, inserting the string value only late in the build process. Fixes #1045
2021-04-09main: add tests for less common build configurationsAyke van Laethem
Don't run the entire test suite for these options, as that would quickly explode the testing time (making it less likely people actually run it). Instead, run just one test for each configuration that should check for most issues.
2021-04-09main: clean up testsAyke van Laethem
- Explicitly list all test cases. This makes it possible to store tests in testdata/ that aren't tested on all platforms. - Clean up filesystem and env test, by running them in a subtest and deduplicating some code and removing the additionalArgs parameter.
2021-03-28WASI & darwin: support basic file io based on libcTakeshi Yoneda
Signed-off-by: Takeshi Yoneda <[email protected]>
2021-02-24WASI & darwin: support env variables based on libcTakeshi Yoneda
Signed-off-by: Takeshi Yoneda <[email protected]>
2020-10-03add wasm-abi field in TargetSpec && set generic for WASI by default (#1421)Takeshi Yoneda
Signed-off-by: mathetake <[email protected]>
2020-10-02main: improve support for x86-32 and add testsAyke van Laethem
To avoid breaking this, make sure we actually test x86-32 (aka i386 aka GOARCH=386) support in CI. Also remove the now-unnecessary binutils-arm-none-eabi package to speed up CI a bit.
2020-09-29support WASI target (#1373)Takeshi Yoneda
* initial commit for WASI support * merge "time" package with wasi build tag * override syscall package with wasi build tag * create runtime_wasm_{js,wasi}.go files * create syscall_wasi.go file * create time/zoneinfo_wasi.go file as the replacement of zoneinfo_js.go * add targets/wasi.json target * set visbility hidden for runtime extern variables Accodring to the WASI docs (https://github.com/WebAssembly/WASI/blob/master/design/application-abi.md#current-unstable-abi), none of exports of WASI executable(Command) should no be accessed. v0.19.0 of bytecodealliance/wasmetime, which is often refered to as the reference implementation of WASI, does not accept any exports except functions and the only limited variables like "table", "memory". * merge syscall_{baremetal,wasi}.go * fix js target build * mv wasi functions to syscall/wasi && implement sleepTicks * WASI: set visibility hidden for globals variables * mv back syscall/wasi/* to runtime package * WASI: add test * unexport wasi types * WASI test: fix wasmtime path * stop changing visibility of runtime.alloc * use GOOS=linux, GOARCH=arm for wasi target Signed-off-by: mathetake <[email protected]> * WASI: fix build tags for os/runtime packages Signed-off-by: mathetake <[email protected]> * run WASI test only on Linux Signed-off-by: mathetake <[email protected]> * set InternalLinkage instead of changing visibility Signed-off-by: mathetake <[email protected]>
2020-08-27arm: automatically determine stack sizesAyke van Laethem
This is a big change that will determine the stack size for many goroutines automatically. Functions that aren't recursive and don't call function pointers can in many cases have an automatically determined worst case stack size. This is useful, as the stack size is usually much lower than the previous hardcoded default of 1024 bytes: somewhere around 200-500 bytes is common. A side effect of this change is that the default stack sizes (including the stack size for other architectures such as AVR) can now be changed in the config JSON file, making it tunable per application.
2020-07-24main: add -target flag to testsAyke van Laethem
This makes it easy to test one particular architecture, for example: go test -v -target=hifive1-qemu This speeds up testing and allows testing targets that are not included in the test by default (such as RISC-V tests on Linux).
2020-05-27builder: move Go version code to goenv packageAyke van Laethem
This is necessary to avoid a circular dependency in the loader (which soon will need to read the Go version) and because it seems like a better place anyway.
2020-04-12wasm: backport "garbage collect references to JavaScript values"Ayke van Laethem
See commit: https://github.com/golang/go/commit/54e6ba6724dfde355070238f9abc16362cac2e3d Warning: this will drop support for Go 1.13 for WebAssembly targets! I have modified the integration tests to specifically blacklist Go 1.13 instead of whitelisting any other version, to avoid accidentally not testing WebAssembly.
2020-04-03builder: run tools (clang, ...) as separate processesAyke van Laethem
This is necessary because LLVM defines many options in global variables that are modified when invoking Clang. In particular, LLVM 10 seems to have a bug in which it always sets the -pgo-warn-misexpect flag. Setting it multiple times (over various cc1 invocations) results in an error: clang (LLVM option parsing): for the --pgo-warn-misexpect option: may only occur zero or one times! This is fixed by running the Clang invocation in a new `tinygo` invocation. Because we've had issues with lld in the past, also run lld in a separate process so similar issues won't happen with lld in the future.
2020-03-26riscv: implement VirtIO targetAyke van Laethem
This allows running RISC-V tests in CI using QEMU, which should help catch bugs.
2020-03-22main: extend test timeout from 1s to 10sAyke van Laethem
This should avoid the rather frequent "test ran too long, terminating..." error message that often occurs in CI and when running `go test` manually. Apparently I was too optimistic: some tests take longer than 1 second to run.
2020-03-16main: improve error reporting while running go testAyke van Laethem
This commit switches integration tests to use the same error reporting mechanism as the tinygo compiler normally uses. It replaces errors like this: main_test.go:139: failed to build: interp: branch on a non-constant With this: main.go:693: # math/rand main.go:695: interp: branch on a non-constant In this particular case the error isn't much better (it gives the relevant package, though) but other errors should also include the source location where they happen.
2020-01-20wasm: don't skip the GC testAyke van Laethem
Finally, all tests run on all targets!
2020-01-20compileopts: fix CGo when cross compilingAyke van Laethem
Use the cross compiling toolchains for compiling/linking. This fixes CGo support, and therefore allows CGo to be used when cross compiling to Linux on a different architecture. This commit also removes some redundant testing code.
2020-01-14main: fix race condition in testsAyke van Laethem
This caused most tests to run the zeroalloc.go test instead of what they should have been tested, and in turn explains most of the performance gains of parallel testing. This commit fixes it by avoiding race conditions. Luckily, no tests started failing since then due to this.
2019-12-28main: kill tests if they run too longAyke van Laethem
Sometimes, tests suddenly hang somewhere (in particular in emulators where crashes often lead to hangs). Setting a limit has two advantages: 1. Quickly killing test processes that are frozen (as opposed to waiting for the default 10min go test timeout). 2. The output becomes visible, hopefully giving a clue what went wrong.
2019-12-21main: avoid leaving files openAyke van Laethem
Eventually, open files should be closed when the GC runs and the finalizer is called. However we shouldn't rely on that. Using `ioutil.ReadFile` as it's a simpler pattern anyway.
2019-12-21run tests partially in parallelJaden Weiss
2019-12-07targets: rename qemu target to cortex-m-qemuAyke van Laethem
The target is intended to emulate the Cortex-M, not to be a generic QEMU target.
2019-11-11main: refactor compile/link part to a builder packageAyke van Laethem
This is a large commit that moves all code directly related to compiling/linking into a new builder package. This has a number of advantages: * It cleanly separates the API between the command line and the full compilation (with a very small API surface). * When the compiler finally compiles one package at a time (instead of everything at once as it does now), something will have to invoke it once per package. This builder package will be the natural place to do that, and also be the place where the whole process can be parallelized. * It allows the TinyGo compiler to be used as a package. A client can simply import the builder package and compile code using it. As part of this refactor, the following additional things changed: * Exported symbols have been made unexported when they weren't needed. * The compilation target has been moved into the compileopts.Options struct. This is done because the target really is just another compiler option, and the API is simplified by moving it in there. * The moveFile function has been duplicated. It does not really belong in the builder API but is used both by the builder and the command line. Moving it into a separate package didn't seem useful either for what is essentially an utility function. * Some doc strings have been improved. Some future changes/refactors I'd like to make after this commit: * Clean up the API between the builder and the compiler package. * Perhaps move the test files (in testdata/) into the builder package. * Perhaps move the loader package into the builder package.
2019-11-04make compiler test names clearerJaden Weiss