Commit 7bc3e588 authored by Russ Cox's avatar Russ Cox

all: extract "can I exec?" check from tests into internal/testenv

Change-Id: I7b54be9d8b50b39e01c6be21f310ae9a10404e9d
Reviewed-on: https://go-review.googlesource.com/10753Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 047f07a2
...@@ -7,6 +7,7 @@ package main ...@@ -7,6 +7,7 @@ package main
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"internal/testenv"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
...@@ -85,22 +86,14 @@ func testAddr2Line(t *testing.T, exepath, addr string) { ...@@ -85,22 +86,14 @@ func testAddr2Line(t *testing.T, exepath, addr string) {
if !os.SameFile(fi1, fi2) { if !os.SameFile(fi1, fi2) {
t.Fatalf("addr2line_test.go and %s are not same file", srcPath) t.Fatalf("addr2line_test.go and %s are not same file", srcPath)
} }
if srcLineNo != "94" { if srcLineNo != "95" {
t.Fatalf("line number = %v; want 94", srcLineNo) t.Fatalf("line number = %v; want 95", srcLineNo)
} }
} }
// This is line 93. The test depends on that. // This is line 94. The test depends on that.
func TestAddr2Line(t *testing.T) { func TestAddr2Line(t *testing.T) {
switch runtime.GOOS { testenv.MustHaveGoBuild(t)
case "nacl", "android":
t.Skipf("skipping on %s", runtime.GOOS)
case "darwin":
switch runtime.GOARCH {
case "arm", "arm64":
t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
}
}
syms := loadSyms(t) syms := loadSyms(t)
......
...@@ -7,11 +7,11 @@ package main_test ...@@ -7,11 +7,11 @@ package main_test
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"internal/testenv"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime"
"testing" "testing"
) )
...@@ -41,15 +41,8 @@ var debug = false // Keeps the rewritten files around if set. ...@@ -41,15 +41,8 @@ var debug = false // Keeps the rewritten files around if set.
// go run ./testdata/main.go ./testdata/test.go // go run ./testdata/main.go ./testdata/test.go
// //
func TestCover(t *testing.T) { func TestCover(t *testing.T) {
switch runtime.GOOS { testenv.MustHaveGoBuild(t)
case "nacl":
t.Skipf("skipping; %v/%v no support for forking", runtime.GOOS, runtime.GOARCH)
case "darwin", "android":
switch runtime.GOARCH {
case "arm", "arm64":
t.Skipf("skipping; %v/%v no support for forking", runtime.GOOS, runtime.GOARCH)
}
}
// Read in the test file (testTest) and write it, with LINEs specified, to coverInput. // Read in the test file (testTest) and write it, with LINEs specified, to coverInput.
file, err := ioutil.ReadFile(testTest) file, err := ioutil.ReadFile(testTest)
if err != nil { if err != nil {
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"bytes" "bytes"
"flag" "flag"
"fmt" "fmt"
"internal/testenv"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
...@@ -129,19 +130,7 @@ type testgoData struct { ...@@ -129,19 +130,7 @@ type testgoData struct {
// testgo sets up for a test that runs testgo. // testgo sets up for a test that runs testgo.
func testgo(t *testing.T) *testgoData { func testgo(t *testing.T) *testgoData {
if !canRun { testenv.MustHaveGoBuild(t)
switch runtime.GOOS {
case "android", "nacl":
t.Skipf("skipping on %s", runtime.GOOS)
case "darwin":
switch runtime.GOARCH {
case "arm", "arm64":
t.Skipf("skipping on %s/%s, no fork", runtime.GOOS, runtime.GOARCH)
}
default:
t.Skip("skipping for unknown reason")
}
}
return &testgoData{t: t} return &testgoData{t: t}
} }
...@@ -835,9 +824,8 @@ func TestInternalPackagesOutsideGOROOTAreRespected(t *testing.T) { ...@@ -835,9 +824,8 @@ func TestInternalPackagesOutsideGOROOTAreRespected(t *testing.T) {
} }
func testMove(t *testing.T, vcs, url, base, config string) { func testMove(t *testing.T, vcs, url, base, config string) {
if testing.Short() { testenv.MustHaveExternalNetwork(t)
t.Skip("skipping test that uses network in short mode")
}
tg := testgo(t) tg := testgo(t)
defer tg.cleanup() defer tg.cleanup()
tg.parallel() tg.parallel()
...@@ -1053,9 +1041,7 @@ func TestInstallToGOBINCommandLinePackage(t *testing.T) { ...@@ -1053,9 +1041,7 @@ func TestInstallToGOBINCommandLinePackage(t *testing.T) {
} }
func TestGodocInstalls(t *testing.T) { func TestGodocInstalls(t *testing.T) {
if testing.Short() { testenv.MustHaveExternalNetwork(t)
t.Skip("skipping test that uses network in short mode")
}
// godoc installs into GOBIN // godoc installs into GOBIN
tg := testgo(t) tg := testgo(t)
...@@ -1248,9 +1234,7 @@ func TestMissingGOPATHIsReported(t *testing.T) { ...@@ -1248,9 +1234,7 @@ func TestMissingGOPATHIsReported(t *testing.T) {
// Issue 4186. go get cannot be used to download packages to $GOROOT. // Issue 4186. go get cannot be used to download packages to $GOROOT.
// Test that without GOPATH set, go get should fail. // Test that without GOPATH set, go get should fail.
func TestWithoutGOPATHGoGetFails(t *testing.T) { func TestWithoutGOPATHGoGetFails(t *testing.T) {
if testing.Short() { testenv.MustHaveExternalNetwork(t)
t.Skip("skipping test that uses network in short mode")
}
tg := testgo(t) tg := testgo(t)
defer tg.cleanup() defer tg.cleanup()
...@@ -1263,9 +1247,7 @@ func TestWithoutGOPATHGoGetFails(t *testing.T) { ...@@ -1263,9 +1247,7 @@ func TestWithoutGOPATHGoGetFails(t *testing.T) {
// Test that with GOPATH=$GOROOT, go get should fail. // Test that with GOPATH=$GOROOT, go get should fail.
func TestWithGOPATHEqualsGOROOTGoGetFails(t *testing.T) { func TestWithGOPATHEqualsGOROOTGoGetFails(t *testing.T) {
if testing.Short() { testenv.MustHaveExternalNetwork(t)
t.Skip("skipping test that uses network in short mode")
}
tg := testgo(t) tg := testgo(t)
defer tg.cleanup() defer tg.cleanup()
...@@ -1799,9 +1781,7 @@ func TestGoGenerateRunFlag(t *testing.T) { ...@@ -1799,9 +1781,7 @@ func TestGoGenerateRunFlag(t *testing.T) {
} }
func TestGoGetWorksWithVanityWildcards(t *testing.T) { func TestGoGetWorksWithVanityWildcards(t *testing.T) {
if testing.Short() { testenv.MustHaveExternalNetwork(t)
t.Skip("skipping test that uses network in short mode")
}
tg := testgo(t) tg := testgo(t)
defer tg.cleanup() defer tg.cleanup()
...@@ -1812,9 +1792,7 @@ func TestGoGetWorksWithVanityWildcards(t *testing.T) { ...@@ -1812,9 +1792,7 @@ func TestGoGetWorksWithVanityWildcards(t *testing.T) {
} }
func TestGoVetWithExternalTests(t *testing.T) { func TestGoVetWithExternalTests(t *testing.T) {
if testing.Short() { testenv.MustHaveExternalNetwork(t)
t.Skip("skipping test that uses network in short mode")
}
tg := testgo(t) tg := testgo(t)
defer tg.cleanup() defer tg.cleanup()
...@@ -1827,9 +1805,7 @@ func TestGoVetWithExternalTests(t *testing.T) { ...@@ -1827,9 +1805,7 @@ func TestGoVetWithExternalTests(t *testing.T) {
} }
func TestGoVetWithTags(t *testing.T) { func TestGoVetWithTags(t *testing.T) {
if testing.Short() { testenv.MustHaveExternalNetwork(t)
t.Skip("skipping test that uses network in short mode")
}
tg := testgo(t) tg := testgo(t)
defer tg.cleanup() defer tg.cleanup()
...@@ -1843,9 +1819,7 @@ func TestGoVetWithTags(t *testing.T) { ...@@ -1843,9 +1819,7 @@ func TestGoVetWithTags(t *testing.T) {
// Issue 9767. // Issue 9767.
func TestGoGetRscIoToolstash(t *testing.T) { func TestGoGetRscIoToolstash(t *testing.T) {
if testing.Short() { testenv.MustHaveExternalNetwork(t)
t.Skip("skipping test that uses network in short mode")
}
tg := testgo(t) tg := testgo(t)
defer tg.cleanup() defer tg.cleanup()
......
...@@ -13,14 +13,7 @@ import ( ...@@ -13,14 +13,7 @@ import (
) )
func TestNoteReading(t *testing.T) { func TestNoteReading(t *testing.T) {
// No file system access on these systems. testenv.MustHaveGoBuild(t)
switch sys := runtime.GOOS + "/" + runtime.GOARCH; sys {
case "darwin/arm", "darwin/arm64", "nacl/386", "nacl/amd64p32", "nacl/arm":
t.Skipf("skipping on %s/%s - no file system", runtime.GOOS, runtime.GOARCH)
}
if runtime.GOOS == "android" {
t.Skipf("skipping; requires go tool")
}
// TODO: Replace with new test scaffolding by iant. // TODO: Replace with new test scaffolding by iant.
d, err := ioutil.TempDir("", "go-test-") d, err := ioutil.TempDir("", "go-test-")
......
...@@ -5,20 +5,15 @@ ...@@ -5,20 +5,15 @@
package main package main
import ( import (
"runtime" "internal/testenv"
"testing" "testing"
) )
// Test that RepoRootForImportPath creates the correct RepoRoot for a given importPath. // Test that RepoRootForImportPath creates the correct RepoRoot for a given importPath.
// TODO(cmang): Add tests for SVN and BZR. // TODO(cmang): Add tests for SVN and BZR.
func TestRepoRootForImportPath(t *testing.T) { func TestRepoRootForImportPath(t *testing.T) {
if testing.Short() { testenv.MustHaveExternalNetwork(t)
t.Skip("skipping test to avoid external network")
}
switch runtime.GOOS {
case "nacl", "android":
t.Skipf("no networking available on %s", runtime.GOOS)
}
tests := []struct { tests := []struct {
path string path string
want *repoRoot want *repoRoot
......
...@@ -5,12 +5,12 @@ import ( ...@@ -5,12 +5,12 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"go/build" "go/build"
"internal/testenv"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"regexp" "regexp"
"runtime"
"strconv" "strconv"
"strings" "strings"
"testing" "testing"
...@@ -148,10 +148,8 @@ func parseOutput(t *testing.T, td *ParsedTestData, asmout []byte) { ...@@ -148,10 +148,8 @@ func parseOutput(t *testing.T, td *ParsedTestData, asmout []byte) {
} }
func TestDynlink(t *testing.T) { func TestDynlink(t *testing.T) {
iOS := runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") testenv.MustHaveGoBuild(t)
if runtime.GOOS == "nacl" || runtime.GOOS == "android" || iOS {
t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
}
testdata := parseTestData(t) testdata := parseTestData(t)
asmout := asmOutput(t, testdata.input) asmout := asmOutput(t, testdata.input)
parseOutput(t, testdata, asmout) parseOutput(t, testdata, asmout)
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"fmt" "fmt"
"internal/testenv"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
...@@ -55,15 +56,7 @@ func checkSymbols(t *testing.T, nmoutput []byte) { ...@@ -55,15 +56,7 @@ func checkSymbols(t *testing.T, nmoutput []byte) {
} }
func TestNM(t *testing.T) { func TestNM(t *testing.T) {
switch runtime.GOOS { testenv.MustHaveGoBuild(t)
case "android", "nacl":
t.Skipf("skipping on %s", runtime.GOOS)
case "darwin":
switch runtime.GOARCH {
case "arm", "arm64":
t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
}
}
tmpDir, err := ioutil.TempDir("", "TestNM") tmpDir, err := ioutil.TempDir("", "TestNM")
if err != nil { if err != nil {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package main package main
import ( import (
"internal/testenv"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
...@@ -15,15 +16,7 @@ import ( ...@@ -15,15 +16,7 @@ import (
) )
func buildObjdump(t *testing.T) (tmp, exe string) { func buildObjdump(t *testing.T) (tmp, exe string) {
switch runtime.GOOS { testenv.MustHaveGoBuild(t)
case "android", "nacl":
t.Skipf("skipping on %s", runtime.GOOS)
case "darwin":
switch runtime.GOARCH {
case "arm", "arm64":
t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
}
}
tmp, err := ioutil.TempDir("", "TestObjDump") tmp, err := ioutil.TempDir("", "TestObjDump")
if err != nil { if err != nil {
......
...@@ -8,12 +8,12 @@ import ( ...@@ -8,12 +8,12 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"fmt" "fmt"
"internal/testenv"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime"
"testing" "testing"
"time" "time"
"unicode/utf8" "unicode/utf8"
...@@ -198,15 +198,7 @@ func TestExtract(t *testing.T) { ...@@ -198,15 +198,7 @@ func TestExtract(t *testing.T) {
// Test that pack-created archives can be understood by the tools. // Test that pack-created archives can be understood by the tools.
func TestHello(t *testing.T) { func TestHello(t *testing.T) {
switch runtime.GOOS { testenv.MustHaveGoBuild(t)
case "android", "nacl":
t.Skipf("skipping on %s", runtime.GOOS)
case "darwin":
switch runtime.GOARCH {
case "arm", "arm64":
t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
}
}
dir := tmpDir(t) dir := tmpDir(t)
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
...@@ -238,15 +230,7 @@ func TestHello(t *testing.T) { ...@@ -238,15 +230,7 @@ func TestHello(t *testing.T) {
// Test that pack works with very long lines in PKGDEF. // Test that pack works with very long lines in PKGDEF.
func TestLargeDefs(t *testing.T) { func TestLargeDefs(t *testing.T) {
switch runtime.GOOS { testenv.MustHaveGoBuild(t)
case "android", "nacl":
t.Skipf("skipping on %s", runtime.GOOS)
case "darwin":
switch runtime.GOARCH {
case "arm", "arm64":
t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
}
}
dir := tmpDir(t) dir := tmpDir(t)
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
......
...@@ -6,11 +6,11 @@ package main_test ...@@ -6,11 +6,11 @@ package main_test
import ( import (
"bytes" "bytes"
"internal/testenv"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings"
"testing" "testing"
) )
...@@ -25,18 +25,12 @@ const ( ...@@ -25,18 +25,12 @@ const (
// rm testvet // rm testvet
// //
func TestVet(t *testing.T) { func TestVet(t *testing.T) {
testenv.MustHaveGoBuild(t)
switch runtime.GOOS { switch runtime.GOOS {
case "plan9", "windows": case "plan9", "windows":
// Plan 9 and Windows systems can't be guaranteed to have Perl and so can't run errchk. // Plan 9 and Windows systems can't be guaranteed to have Perl and so can't run errchk.
t.Skipf("skipping test; no Perl on %q", runtime.GOOS) t.Skipf("skipping test; no Perl on %q", runtime.GOOS)
case "nacl":
t.Skip("skipping test; no command execution on nacl")
case "darwin":
if strings.HasPrefix(runtime.GOARCH, "arm") {
t.Skipf("skipping test; no command execution on darwin/%s", runtime.GOARCH)
}
case "android":
t.Skip("skipping test; no go toolchain available")
} }
// go build // go build
...@@ -84,16 +78,7 @@ func run(c *exec.Cmd, t *testing.T) bool { ...@@ -84,16 +78,7 @@ func run(c *exec.Cmd, t *testing.T) bool {
// TestTags verifies that the -tags argument controls which files to check. // TestTags verifies that the -tags argument controls which files to check.
func TestTags(t *testing.T) { func TestTags(t *testing.T) {
switch runtime.GOOS { testenv.MustHaveGoBuild(t)
case "nacl":
t.Skip("skipping test; no command execution on nacl")
case "darwin":
if strings.HasPrefix(runtime.GOARCH, "arm") {
t.Skip("skipping test; no command execution on darwin/%s", runtime.GOARCH)
}
case "android":
t.Skip("skipping test; no go toolchain available")
}
// go build // go build
cmd := exec.Command("go", "build", "-o", binary) cmd := exec.Command("go", "build", "-o", binary)
......
...@@ -18,11 +18,11 @@ import ( ...@@ -18,11 +18,11 @@ import (
"encoding/base64" "encoding/base64"
"encoding/hex" "encoding/hex"
"encoding/pem" "encoding/pem"
"internal/testenv"
"math/big" "math/big"
"net" "net"
"os/exec" "os/exec"
"reflect" "reflect"
"runtime"
"testing" "testing"
"time" "time"
) )
...@@ -848,15 +848,7 @@ func TestParsePEMCRL(t *testing.T) { ...@@ -848,15 +848,7 @@ func TestParsePEMCRL(t *testing.T) {
} }
func TestImports(t *testing.T) { func TestImports(t *testing.T) {
switch runtime.GOOS { testenv.MustHaveGoRun(t)
case "android", "nacl":
t.Skipf("skipping on %s", runtime.GOOS)
case "darwin":
switch runtime.GOARCH {
case "arm", "arm64":
t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
}
}
if err := exec.Command("go", "run", "x509_test_import.go").Run(); err != nil { if err := exec.Command("go", "run", "x509_test_import.go").Run(); err != nil {
t.Errorf("failed to run x509_test_import.go: %s", err) t.Errorf("failed to run x509_test_import.go: %s", err)
......
...@@ -352,6 +352,7 @@ var pkgDeps = map[string][]string{ ...@@ -352,6 +352,7 @@ var pkgDeps = map[string][]string{
"internal/syscall/unix": {"runtime", "sync/atomic", "syscall", "unsafe"}, "internal/syscall/unix": {"runtime", "sync/atomic", "syscall", "unsafe"},
"internal/syscall/windows": {"syscall", "unsafe"}, "internal/syscall/windows": {"syscall", "unsafe"},
"internal/syscall/windows/registry": {"errors", "io", "syscall", "unicode/utf16", "unsafe"}, "internal/syscall/windows/registry": {"errors", "io", "syscall", "unicode/utf16", "unsafe"},
"internal/testenv": {"runtime", "strings", "testing"},
"internal/trace": {"bufio", "bytes", "fmt", "io", "os", "os/exec", "sort", "strconv", "strings"}, "internal/trace": {"bufio", "bytes", "fmt", "io", "os", "os/exec", "sort", "strconv", "strings"},
"net/http/cookiejar": {"errors", "fmt", "net", "net/http", "net/url", "sort", "strings", "sync", "time", "unicode/utf8"}, "net/http/cookiejar": {"errors", "fmt", "net", "net/http", "net/url", "sort", "strings", "sync", "time", "unicode/utf8"},
"net/http/internal": {"bufio", "bytes", "errors", "fmt", "io"}, "net/http/internal": {"bufio", "bytes", "errors", "fmt", "io"},
......
// Copyright 2015 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 testenv provides information about what functionality
// is available in different testing environments run by the Go team.
//
// It is an internal package because these details are specific
// to the Go team's test setup (on build.golang.org) and not
// fundamental to tests in general.
package testenv
import (
"runtime"
"strings"
"testing"
)
// HasGoBuild reports whether the current system can build programs with ``go build''
// and then run them with os.StartProcess or exec.Command.
func HasGoBuild() bool {
switch runtime.GOOS {
case "android", "nacl":
return false
case "darwin":
if strings.HasPrefix(runtime.GOARCH, "arm") {
return false
}
}
return true
}
// MustHaveGoBuild checks that the current system can build programs with ``go build''
// and then run them with os.StartProcess or exec.Command.
// If not, MustHaveGoBuild calls t.Skip with an explanation.
func MustHaveGoBuild(t *testing.T) {
if !HasGoBuild() {
t.Skipf("skipping test: 'go build' not available on %s/%s", runtime.GOOS, runtime.GOARCH)
}
}
// HasGoRun reports whether the current system can run programs with ``go run.''
func HasGoRun() bool {
// For now, having go run and having go build are the same.
return HasGoBuild()
}
// MustHaveGoRun checks that the current system can run programs with ``go run.''
// If not, MustHaveGoRun calls t.Skip with an explanation.
func MustHaveGoRun(t *testing.T) {
if !HasGoRun() {
t.Skipf("skipping test: 'go run' not available on %s/%s", runtime.GOOS, runtime.GOARCH)
}
}
// HasExec reports whether the current system can start new processes
// using os.StartProcess or (more commonly) exec.Command.
func HasExec() bool {
switch runtime.GOOS {
case "nacl":
return false
case "darwin":
if strings.HasPrefix(runtime.GOARCH, "arm") {
return false
}
}
return true
}
// MustHaveExec checks that the current system can start new processes
// using os.StartProcess or (more commonly) exec.Command.
// If not, MustHaveExec calls t.Skip with an explanation.
func MustHaveExec(t *testing.T) {
if !HasExec() {
t.Skipf("skipping test: cannot exec subprocess on %s/%s", runtime.GOOS, runtime.GOARCH)
}
}
// HasExternalNetwork reports whether the current system can use
// external (non-localhost) networks.
func HasExternalNetwork() bool {
return !testing.Short()
}
// MustHaveExternalNetwork checks that the current system can use
// external (non-localhost) networks.
// If not, MustHaveExternalNetwork calls t.Skip with an explanation.
func MustHaveExternalNetwork(t *testing.T) {
t.Skipf("skipping test: no external network in -short mode")
}
...@@ -12,24 +12,19 @@ import ( ...@@ -12,24 +12,19 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"internal/testenv"
"io" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os" "os"
"runtime"
"testing" "testing"
"time" "time"
) )
// iOS cannot fork, so we skip some tests
var iOS = runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64")
// This test is a CGI host (testing host.go) that runs its own binary // This test is a CGI host (testing host.go) that runs its own binary
// as a child process testing the other half of CGI (child.go). // as a child process testing the other half of CGI (child.go).
func TestHostingOurselves(t *testing.T) { func TestHostingOurselves(t *testing.T) {
if runtime.GOOS == "nacl" || iOS { testenv.MustHaveExec(t)
t.Skipf("skipping on %s/%s", runtime.GOOS, runtime.GOARCH)
}
h := &Handler{ h := &Handler{
Path: os.Args[0], Path: os.Args[0],
...@@ -96,9 +91,7 @@ func (w *limitWriter) Write(p []byte) (n int, err error) { ...@@ -96,9 +91,7 @@ func (w *limitWriter) Write(p []byte) (n int, err error) {
// If there's an error copying the child's output to the parent, test // If there's an error copying the child's output to the parent, test
// that we kill the child. // that we kill the child.
func TestKillChildAfterCopyError(t *testing.T) { func TestKillChildAfterCopyError(t *testing.T) {
if runtime.GOOS == "nacl" || iOS { testenv.MustHaveExec(t)
t.Skipf("skipping on %s/%s", runtime.GOOS, runtime.GOARCH)
}
defer func() { testHookStartProcess = nil }() defer func() { testHookStartProcess = nil }()
proc := make(chan *os.Process, 1) proc := make(chan *os.Process, 1)
...@@ -143,9 +136,7 @@ func TestKillChildAfterCopyError(t *testing.T) { ...@@ -143,9 +136,7 @@ func TestKillChildAfterCopyError(t *testing.T) {
// Test that a child handler writing only headers works. // Test that a child handler writing only headers works.
// golang.org/issue/7196 // golang.org/issue/7196
func TestChildOnlyHeaders(t *testing.T) { func TestChildOnlyHeaders(t *testing.T) {
if runtime.GOOS == "nacl" || iOS { testenv.MustHaveExec(t)
t.Skipf("skipping on %s/%s", runtime.GOOS, runtime.GOARCH)
}
h := &Handler{ h := &Handler{
Path: os.Args[0], Path: os.Args[0],
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"fmt" "fmt"
"internal/testenv"
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
...@@ -27,13 +28,9 @@ import ( ...@@ -27,13 +28,9 @@ import (
"time" "time"
) )
// iOS cannot fork
var iOS = runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64")
func helperCommand(t *testing.T, s ...string) *exec.Cmd { func helperCommand(t *testing.T, s ...string) *exec.Cmd {
if runtime.GOOS == "nacl" || iOS { testenv.MustHaveExec(t)
t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
}
cs := []string{"-test.run=TestHelperProcess", "--"} cs := []string{"-test.run=TestHelperProcess", "--"}
cs = append(cs, s...) cs = append(cs, s...)
cmd := exec.Command(os.Args[0], cs...) cmd := exec.Command(os.Args[0], cs...)
...@@ -52,9 +49,7 @@ func TestEcho(t *testing.T) { ...@@ -52,9 +49,7 @@ func TestEcho(t *testing.T) {
} }
func TestCommandRelativeName(t *testing.T) { func TestCommandRelativeName(t *testing.T) {
if iOS { testenv.MustHaveExec(t)
t.Skip("skipping on darwin/%s, cannot fork", runtime.GOARCH)
}
// Run our own binary as a relative path // Run our own binary as a relative path
// (e.g. "_test/exec.test") our parent directory. // (e.g. "_test/exec.test") our parent directory.
...@@ -427,13 +422,11 @@ func TestExtraFilesFDShuffle(t *testing.T) { ...@@ -427,13 +422,11 @@ func TestExtraFilesFDShuffle(t *testing.T) {
} }
func TestExtraFiles(t *testing.T) { func TestExtraFiles(t *testing.T) {
switch runtime.GOOS { testenv.MustHaveExec(t)
case "nacl", "windows":
if runtime.GOOS == "windows" {
t.Skipf("skipping test on %q", runtime.GOOS) t.Skipf("skipping test on %q", runtime.GOOS)
} }
if iOS {
t.Skipf("skipping test on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
}
// Ensure that file descriptors have not already been leaked into // Ensure that file descriptors have not already been leaked into
// our environment. // our environment.
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"internal/testenv"
"io" "io"
"io/ioutil" "io/ioutil"
. "os" . "os"
...@@ -794,15 +795,7 @@ func exec(t *testing.T, dir, cmd string, args []string, expect string) { ...@@ -794,15 +795,7 @@ func exec(t *testing.T, dir, cmd string, args []string, expect string) {
} }
func TestStartProcess(t *testing.T) { func TestStartProcess(t *testing.T) {
switch runtime.GOOS { testenv.MustHaveExec(t)
case "android", "nacl":
t.Skipf("skipping on %s", runtime.GOOS)
case "darwin":
switch runtime.GOARCH {
case "arm", "arm64":
t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
}
}
var dir, cmd string var dir, cmd string
var args []string var args []string
...@@ -1258,19 +1251,13 @@ func testWindowsHostname(t *testing.T) { ...@@ -1258,19 +1251,13 @@ func testWindowsHostname(t *testing.T) {
func TestHostname(t *testing.T) { func TestHostname(t *testing.T) {
// There is no other way to fetch hostname on windows, but via winapi. // There is no other way to fetch hostname on windows, but via winapi.
// On Plan 9 it can be taken from #c/sysname as Hostname() does. // On Plan 9 it can be taken from #c/sysname as Hostname() does.
switch runtime.GOOS { if runtime.GOOS == "windows" {
case "android", "nacl", "plan9":
t.Skipf("skipping on %s", runtime.GOOS)
case "darwin":
switch runtime.GOARCH {
case "arm", "arm64":
t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
}
case "windows":
testWindowsHostname(t) testWindowsHostname(t)
return return
} }
testenv.MustHaveExec(t)
// Check internal Hostname() against the output of /bin/hostname. // Check internal Hostname() against the output of /bin/hostname.
// Allow that the internal Hostname returns a Fully Qualified Domain Name // Allow that the internal Hostname returns a Fully Qualified Domain Name
// and the /bin/hostname only returns the first component // and the /bin/hostname only returns the first component
...@@ -1529,15 +1516,7 @@ func TestReadAtEOF(t *testing.T) { ...@@ -1529,15 +1516,7 @@ func TestReadAtEOF(t *testing.T) {
} }
func testKillProcess(t *testing.T, processKiller func(p *Process)) { func testKillProcess(t *testing.T, processKiller func(p *Process)) {
switch runtime.GOOS { testenv.MustHaveExec(t)
case "android", "nacl":
t.Skipf("skipping on %s", runtime.GOOS)
case "darwin":
switch runtime.GOARCH {
case "arm", "arm64":
t.Skipf("skipping on %s/%s", runtime.GOOS, runtime.GOARCH)
}
}
// Re-exec the test binary itself to emulate "sleep 1". // Re-exec the test binary itself to emulate "sleep 1".
cmd := osexec.Command(Args[0], "-test.run", "TestSleep") cmd := osexec.Command(Args[0], "-test.run", "TestSleep")
...@@ -1574,19 +1553,13 @@ func TestKillStartProcess(t *testing.T) { ...@@ -1574,19 +1553,13 @@ func TestKillStartProcess(t *testing.T) {
} }
func TestGetppid(t *testing.T) { func TestGetppid(t *testing.T) {
switch runtime.GOOS { if runtime.GOOS == "plan9" {
case "nacl":
t.Skip("skipping on nacl")
case "plan9":
// TODO: golang.org/issue/8206 // TODO: golang.org/issue/8206
t.Skipf("skipping test on plan9; see issue 8206") t.Skipf("skipping test on plan9; see issue 8206")
case "darwin":
switch runtime.GOARCH {
case "arm", "arm64":
t.Skipf("skipping test on %s/%s, no fork", runtime.GOOS, runtime.GOARCH)
}
} }
testenv.MustHaveExec(t)
if Getenv("GO_WANT_HELPER_PROCESS") == "1" { if Getenv("GO_WANT_HELPER_PROCESS") == "1" {
fmt.Print(Getppid()) fmt.Print(Getppid())
Exit(0) Exit(0)
......
...@@ -6,6 +6,7 @@ package runtime_test ...@@ -6,6 +6,7 @@ package runtime_test
import ( import (
"fmt" "fmt"
"internal/testenv"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
...@@ -38,15 +39,7 @@ func testEnv(cmd *exec.Cmd) *exec.Cmd { ...@@ -38,15 +39,7 @@ func testEnv(cmd *exec.Cmd) *exec.Cmd {
} }
func executeTest(t *testing.T, templ string, data interface{}, extra ...string) string { func executeTest(t *testing.T, templ string, data interface{}, extra ...string) string {
switch runtime.GOOS { testenv.MustHaveGoBuild(t)
case "android", "nacl":
t.Skipf("skipping on %s", runtime.GOOS)
case "darwin":
switch runtime.GOARCH {
case "arm", "arm64":
t.Skipf("skipping on %s/%s, no fork", runtime.GOOS, runtime.GOARCH)
}
}
checkStaleRuntime(t) checkStaleRuntime(t)
......
...@@ -9,6 +9,7 @@ package pprof_test ...@@ -9,6 +9,7 @@ package pprof_test
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"internal/testenv"
"math/big" "math/big"
"os" "os"
"os/exec" "os/exec"
...@@ -209,12 +210,7 @@ func testCPUProfile(t *testing.T, need []string, f func()) { ...@@ -209,12 +210,7 @@ func testCPUProfile(t *testing.T, need []string, f func()) {
// Fork can hang if preempted with signals frequently enough (see issue 5517). // Fork can hang if preempted with signals frequently enough (see issue 5517).
// Ensure that we do not do this. // Ensure that we do not do this.
func TestCPUProfileWithFork(t *testing.T) { func TestCPUProfileWithFork(t *testing.T) {
if runtime.GOOS == "darwin" { testenv.MustHaveExec(t)
switch runtime.GOARCH {
case "arm", "arm64":
t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
}
}
heap := 1 << 30 heap := 1 << 30
if runtime.GOOS == "android" { if runtime.GOOS == "android" {
......
...@@ -24,6 +24,8 @@ func skipTraceTestsIfNeeded(t *testing.T) { ...@@ -24,6 +24,8 @@ func skipTraceTestsIfNeeded(t *testing.T) {
case "darwin": case "darwin":
switch runtime.GOARCH { switch runtime.GOARCH {
case "arm", "arm64": case "arm", "arm64":
// TODO(rsc): What does this have to do with the trace tests?
// There is no forking here.
t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH) t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
} }
} }
......
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
package syscall_test package syscall_test
import ( import (
"internal/testenv"
"io" "io"
"os" "os"
"os/exec" "os/exec"
"os/signal" "os/signal"
"runtime"
"syscall" "syscall"
"testing" "testing"
"unsafe" "unsafe"
...@@ -48,9 +48,8 @@ func (c *command) Stop() { ...@@ -48,9 +48,8 @@ func (c *command) Stop() {
} }
func create(t *testing.T) *command { func create(t *testing.T) *command {
if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") { testenv.MustHaveExec(t)
t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
}
proc := exec.Command("cat") proc := exec.Command("cat")
stdin, err := proc.StdinPipe() stdin, err := proc.StdinPipe()
if err != nil { if err != nil {
......
...@@ -9,6 +9,7 @@ package syscall_test ...@@ -9,6 +9,7 @@ package syscall_test
import ( import (
"flag" "flag"
"fmt" "fmt"
"internal/testenv"
"io/ioutil" "io/ioutil"
"net" "net"
"os" "os"
...@@ -130,12 +131,10 @@ func TestPassFD(t *testing.T) { ...@@ -130,12 +131,10 @@ func TestPassFD(t *testing.T) {
case "solaris": case "solaris":
// TODO(aram): Figure out why ReadMsgUnix is returning empty message. // TODO(aram): Figure out why ReadMsgUnix is returning empty message.
t.Skip("skipping test on solaris, see issue 7402") t.Skip("skipping test on solaris, see issue 7402")
case "darwin":
switch runtime.GOARCH {
case "arm", "arm64":
t.Skipf("skipping test on %d/%s, no fork", runtime.GOOS, runtime.GOARCH)
}
} }
testenv.MustHaveExec(t)
if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" { if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" {
passFDChild() passFDChild()
return return
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment