]> Cypherpunks.ru repositories - gostls13.git/commitdiff
all: enable more tests on macOS/ARM64
authorCherry Zhang <cherryyz@google.com>
Wed, 7 Oct 2020 22:29:51 +0000 (18:29 -0400)
committerCherry Zhang <cherryyz@google.com>
Fri, 9 Oct 2020 01:09:06 +0000 (01:09 +0000)
On macOS, we can do "go build", can exec, and have the source
tree available, so we can enable more tests.

Skip ones that don't work. Most of them are due to that it
requires external linking (for now) and some tests don't work
with external linking (e.g. runtime deadlock detection). For
them, helper functions CanInternalLink/MustInternalLink are
introduced. I still want to have internal linking implemented,
but it is still a good idea to identify which tests don't work
with external linking.

Updates #38485.

Change-Id: I6b14697573cf3f371daf54b9ddd792acf232f2f2
Reviewed-on: https://go-review.googlesource.com/c/go/+/260719
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
13 files changed:
src/cmd/go/go_test.go
src/cmd/internal/sys/supported.go
src/cmd/internal/sys/supported_test.go [new file with mode: 0644]
src/cmd/link/internal/ld/dwarf_test.go
src/cmd/link/internal/ld/ld_test.go
src/cmd/link/link_test.go
src/cmd/nm/nm_cgo_test.go
src/cmd/nm/nm_test.go
src/internal/cpu/cpu_test.go
src/internal/testenv/testenv.go
src/os/exec/exec_test.go
src/runtime/crash_test.go
src/runtime/time_test.go

index 66a52c86ad92fa04e2ffe434fec9c9e3167a65f7..093ea2ffa13af88febf23e5140fd08291759796c 100644 (file)
@@ -58,11 +58,10 @@ func init() {
        switch runtime.GOOS {
        case "android", "js":
                canRun = false
-       case "darwin", "ios":
-               switch runtime.GOARCH {
-               case "arm64":
-                       canRun = false
-               }
+       case "darwin":
+               // nothing to do
+       case "ios":
+               canRun = false
        case "linux":
                switch runtime.GOARCH {
                case "arm":
index 8d87e95655f1741f438a3408fe014f51a8101b64..41e5ec1432ce3feaadae05e6885fb053673b1195 100644 (file)
@@ -32,6 +32,7 @@ func MSanSupported(goos, goarch string) bool {
 }
 
 // MustLinkExternal reports whether goos/goarch requires external linking.
+// (This is the opposite of internal/testenv.CanInternalLink. Keep them in sync.)
 func MustLinkExternal(goos, goarch string) bool {
        switch goos {
        case "android":
diff --git a/src/cmd/internal/sys/supported_test.go b/src/cmd/internal/sys/supported_test.go
new file mode 100644 (file)
index 0000000..1217814
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package sys
+
+import (
+       "internal/testenv"
+       "runtime"
+       "testing"
+)
+
+func TestMustLinkExternalMatchesTestenv(t *testing.T) {
+       // MustLinkExternal and testenv.CanInternalLink are the exact opposite.
+       if b := MustLinkExternal(runtime.GOOS, runtime.GOARCH); b != !testenv.CanInternalLink() {
+               t.Fatalf("MustLinkExternal() == %v, testenv.CanInternalLink() == %v, don't match", b, testenv.CanInternalLink())
+       }
+}
index 22948521f5c7881e553ee2040cb6f55035c8c848..a66506d39284a81086b6348e4a229bd1f4ce39b1 100644 (file)
@@ -238,6 +238,10 @@ func TestSizes(t *testing.T) {
        if runtime.GOOS == "plan9" {
                t.Skip("skipping on plan9; no DWARF symbol table in executables")
        }
+
+       // External linking may bring in C symbols with unknown size. Skip.
+       testenv.MustInternalLink(t)
+
        t.Parallel()
 
        // DWARF sizes should never be -1.
@@ -919,6 +923,7 @@ func TestAbstractOriginSanityIssue26237(t *testing.T) {
 
 func TestRuntimeTypeAttrInternal(t *testing.T) {
        testenv.MustHaveGoBuild(t)
+       testenv.MustInternalLink(t)
 
        if runtime.GOOS == "plan9" {
                t.Skip("skipping on plan9; no DWARF symbol table in executables")
@@ -1018,6 +1023,9 @@ func main() {
                t.Fatalf("*main.X DIE had no runtime type attr. DIE: %v", dies[0])
        }
 
+       if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
+               return // everything is PIE on ARM64, addresses are relocated
+       }
        if rtAttr.(uint64)+types.Addr != addr {
                t.Errorf("DWARF type offset was %#x+%#x, but test program said %#x", rtAttr.(uint64), types.Addr, addr)
        }
@@ -1203,6 +1211,15 @@ func main() {
                }
        }
 
+       // When external linking, we put all symbols in the symbol table (so the
+       // external linker can find them). Skip the symbol table check.
+       // TODO: maybe there is some way to tell the external linker not to put
+       // those symbols in the executable's symbol table? Prefix the symbol name
+       // with "." or "L" to pretend it is a label?
+       if !testenv.CanInternalLink() {
+               return
+       }
+
        syms, err := f.Symbols()
        if err != nil {
                t.Fatalf("error reading symbols: %v", err)
index 4367c1028ead111cf0c3d73bfe0b38320c9daf47..cdfaadb17de7d1a554e1861b43d8e5906f02f5cb 100644 (file)
@@ -18,8 +18,13 @@ import (
 )
 
 func TestUndefinedRelocErrors(t *testing.T) {
-       t.Parallel()
        testenv.MustHaveGoBuild(t)
+
+       // When external linking, symbols may be defined externally, so we allow
+       // undefined symbols and let external linker resolve. Skip the test.
+       testenv.MustInternalLink(t)
+
+       t.Parallel()
        dir, err := ioutil.TempDir("", "go-build")
        if err != nil {
                t.Fatal(err)
index b7611f207cfb4e93d0716601553b0a057c1ef63f..6729568766b0da1e085d3e1648b2aa49e1c91973 100644 (file)
@@ -181,6 +181,7 @@ main.x: relocation target main.zero not defined
 func TestIssue33979(t *testing.T) {
        testenv.MustHaveGoBuild(t)
        testenv.MustHaveCGO(t)
+       testenv.MustInternalLink(t)
 
        // Skip test on platforms that do not support cgo internal linking.
        switch runtime.GOARCH {
index 9a257e0ed2eced69d18e9e6385aafe3d6286528f..58f2c24908d0e04066abdcf36195a3f3fac38522 100644 (file)
@@ -15,6 +15,11 @@ func canInternalLink() bool {
        switch runtime.GOOS {
        case "aix":
                return false
+       case "darwin":
+               switch runtime.GOARCH {
+               case "arm64":
+                       return false
+               }
        case "dragonfly":
                return false
        case "freebsd":
index 413a4eb06f34b45ec26f38d75fba5992dc5b764d..382446e9fe1bea01e42368845e783715d5d46509 100644 (file)
@@ -173,6 +173,9 @@ func testGoExec(t *testing.T, iscgo, isexternallinker bool) {
                if runtime.GOOS == "windows" {
                        return true
                }
+               if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
+                       return true // On darwin/arm64 everything is PIE
+               }
                return false
        }
 
index e09bd2d8b99f705d404d70567bb470dd88cef953..919bbd5ed72e4196168c987cab48a0ed15dc869e 100644 (file)
@@ -15,6 +15,7 @@ import (
 )
 
 func TestMinimalFeatures(t *testing.T) {
+       // TODO: maybe do MustSupportFeatureDectection(t) ?
        if runtime.GOARCH == "arm64" {
                switch runtime.GOOS {
                case "linux", "android":
@@ -36,6 +37,13 @@ func MustHaveDebugOptionsSupport(t *testing.T) {
        }
 }
 
+func MustSupportFeatureDectection(t *testing.T) {
+       if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
+               t.Skipf("CPU feature detection is not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
+       }
+       // TODO: maybe there are other platforms?
+}
+
 func runDebugOptionsTest(t *testing.T, test string, options string) {
        MustHaveDebugOptionsSupport(t)
 
@@ -58,6 +66,7 @@ func runDebugOptionsTest(t *testing.T, test string, options string) {
 }
 
 func TestDisableAllCapabilities(t *testing.T) {
+       MustSupportFeatureDectection(t)
        runDebugOptionsTest(t, "TestAllCapabilitiesDisabled", "cpu.all=off")
 }
 
index cfb033b2a2c04fec5980aac7c351c96db09f67c4..0ee6355ee38c443cd6ad4490fb31385fb0fc6bce 100644 (file)
@@ -43,12 +43,8 @@ func HasGoBuild() bool {
                return false
        }
        switch runtime.GOOS {
-       case "android", "js":
+       case "android", "js", "ios":
                return false
-       case "darwin", "ios":
-               if runtime.GOARCH == "arm64" {
-                       return false
-               }
        }
        return true
 }
@@ -122,12 +118,8 @@ func GoTool() (string, error) {
 // using os.StartProcess or (more commonly) exec.Command.
 func HasExec() bool {
        switch runtime.GOOS {
-       case "js":
+       case "js", "ios":
                return false
-       case "darwin", "ios":
-               if runtime.GOARCH == "arm64" {
-                       return false
-               }
        }
        return true
 }
@@ -135,10 +127,8 @@ func HasExec() bool {
 // HasSrc reports whether the entire source tree is available under GOROOT.
 func HasSrc() bool {
        switch runtime.GOOS {
-       case "darwin", "ios":
-               if runtime.GOARCH == "arm64" {
-                       return false
-               }
+       case "ios":
+               return false
        }
        return true
 }
@@ -202,6 +192,32 @@ func MustHaveCGO(t testing.TB) {
        }
 }
 
+// CanInternalLink reports whether the current system can link programs with
+// internal linking.
+// (This is the opposite of cmd/internal/sys.MustLinkExternal. Keep them in sync.)
+func CanInternalLink() bool {
+       switch runtime.GOOS {
+       case "android":
+               if runtime.GOARCH != "arm64" {
+                       return false
+               }
+       case "darwin", "ios":
+               if runtime.GOARCH == "arm64" {
+                       return false
+               }
+       }
+       return true
+}
+
+// MustInternalLink checks that the current system can link programs with internal
+// linking.
+// If not, MustInternalLink calls t.Skip with an explanation.
+func MustInternalLink(t testing.TB) {
+       if !CanInternalLink() {
+               t.Skipf("skipping test: internal linking on %s/%s is not supported", runtime.GOOS, runtime.GOARCH)
+       }
+}
+
 // HasSymlink reports whether the current system can use os.Symlink.
 func HasSymlink() bool {
        ok, _ := hasSymlink()
index dafbc64a17c590f2ff2fa4cbd03d7054a3e375bc..9746722980572e4914551f999d19c7e21e63a289 100644 (file)
@@ -605,6 +605,10 @@ func TestExtraFiles(t *testing.T) {
        testenv.MustHaveExec(t)
        testenv.MustHaveGoBuild(t)
 
+       // This test runs with cgo disabled. External linking needs cgo, so
+       // it doesn't work if external linking is required.
+       testenv.MustInternalLink(t)
+
        if runtime.GOOS == "windows" {
                t.Skipf("skipping test on %q", runtime.GOOS)
        }
index eae4f538c1c4206347160d62169d1e2982a59850..5e22b7593ecd298ca0e824b03a59e862447d92c6 100644 (file)
@@ -181,6 +181,9 @@ func TestCrashHandler(t *testing.T) {
 }
 
 func testDeadlock(t *testing.T, name string) {
+       // External linking brings in cgo, causing deadlock detection not working.
+       testenv.MustInternalLink(t)
+
        output := runTestProg(t, "testprog", name)
        want := "fatal error: all goroutines are asleep - deadlock!\n"
        if !strings.HasPrefix(output, want) {
@@ -205,6 +208,9 @@ func TestLockedDeadlock2(t *testing.T) {
 }
 
 func TestGoexitDeadlock(t *testing.T) {
+       // External linking brings in cgo, causing deadlock detection not working.
+       testenv.MustInternalLink(t)
+
        output := runTestProg(t, "testprog", "GoexitDeadlock")
        want := "no goroutines (main called runtime.Goexit) - deadlock!"
        if !strings.Contains(output, want) {
@@ -290,6 +296,9 @@ func TestRecursivePanic4(t *testing.T) {
 }
 
 func TestGoexitCrash(t *testing.T) {
+       // External linking brings in cgo, causing deadlock detection not working.
+       testenv.MustInternalLink(t)
+
        output := runTestProg(t, "testprog", "GoexitExit")
        want := "no goroutines (main called runtime.Goexit) - deadlock!"
        if !strings.Contains(output, want) {
@@ -348,6 +357,9 @@ func TestBreakpoint(t *testing.T) {
 }
 
 func TestGoexitInPanic(t *testing.T) {
+       // External linking brings in cgo, causing deadlock detection not working.
+       testenv.MustInternalLink(t)
+
        // see issue 8774: this code used to trigger an infinite recursion
        output := runTestProg(t, "testprog", "GoexitInPanic")
        want := "fatal error: no goroutines (main called runtime.Goexit) - deadlock!"
@@ -412,6 +424,9 @@ func TestPanicAfterGoexit(t *testing.T) {
 }
 
 func TestRecoveredPanicAfterGoexit(t *testing.T) {
+       // External linking brings in cgo, causing deadlock detection not working.
+       testenv.MustInternalLink(t)
+
        output := runTestProg(t, "testprog", "RecoveredPanicAfterGoexit")
        want := "fatal error: no goroutines (main called runtime.Goexit) - deadlock!"
        if !strings.HasPrefix(output, want) {
@@ -420,6 +435,9 @@ func TestRecoveredPanicAfterGoexit(t *testing.T) {
 }
 
 func TestRecoverBeforePanicAfterGoexit(t *testing.T) {
+       // External linking brings in cgo, causing deadlock detection not working.
+       testenv.MustInternalLink(t)
+
        t.Parallel()
        output := runTestProg(t, "testprog", "RecoverBeforePanicAfterGoexit")
        want := "fatal error: no goroutines (main called runtime.Goexit) - deadlock!"
@@ -429,6 +447,9 @@ func TestRecoverBeforePanicAfterGoexit(t *testing.T) {
 }
 
 func TestRecoverBeforePanicAfterGoexit2(t *testing.T) {
+       // External linking brings in cgo, causing deadlock detection not working.
+       testenv.MustInternalLink(t)
+
        t.Parallel()
        output := runTestProg(t, "testprog", "RecoverBeforePanicAfterGoexit2")
        want := "fatal error: no goroutines (main called runtime.Goexit) - deadlock!"
index a8dab7db8eb6c4090b081a87ff76214a41550963..afd9af2af4796537a63f10d8f3e66d023d9e26af 100644 (file)
@@ -20,6 +20,10 @@ func TestFakeTime(t *testing.T) {
                t.Skip("faketime not supported on windows")
        }
 
+       // Faketime is advanced in checkdead. External linking brings in cgo,
+       // causing checkdead not working.
+       testenv.MustInternalLink(t)
+
        t.Parallel()
 
        exe, err := buildTestProg(t, "testfaketime", "-tags=faketime")