From 525ded3d9085c53ebc37c4c0e01d8501c40ad44e Mon Sep 17 00:00:00 2001 From: Jaden Weiss Date: Fri, 20 Dec 2019 17:13:00 -0500 Subject: [PATCH] run tests partially in parallel --- main_test.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/main_test.go b/main_test.go index 9e4a6216..3568f4c9 100644 --- a/main_test.go +++ b/main_test.go @@ -12,6 +12,7 @@ import ( "path/filepath" "runtime" "sort" + "sync" "testing" "github.com/tinygo-org/tinygo/compileopts" @@ -67,6 +68,8 @@ func TestCompiler(t *testing.T) { } func runPlatTests(target string, matches []string, t *testing.T) { + t.Parallel() + for _, path := range matches { switch { case target == "wasm": @@ -86,11 +89,25 @@ func runPlatTests(target string, matches []string, t *testing.T) { } t.Run(filepath.Base(path), func(t *testing.T) { + t.Parallel() + runTest(path, target, t) }) } } +// Due to some problems with LLD, we cannot run links in parallel, or in parallel with compiles. +// Therefore, we put a lock around builds and run everything else in parallel. +var buildLock sync.Mutex + +// runBuild is a thread-safe wrapper around Build. +func runBuild(src, out string, opts *compileopts.Options) error { + buildLock.Lock() + defer buildLock.Unlock() + + return Build(src, out, opts) +} + func runTest(path, target string, t *testing.T) { // Get the expected output for this test. txtpath := path[:len(path)-3] + ".txt" @@ -130,7 +147,7 @@ func runTest(path, target string, t *testing.T) { WasmAbi: "js", } binary := filepath.Join(tmpdir, "test") - err = Build("./"+path, binary, config) + err = runBuild("./"+path, binary, config) if err != nil { if errLoader, ok := err.(loader.Errors); ok { for _, err := range errLoader.Errs {