diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-11-07 07:25:23 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-11-10 07:25:32 -0800 |
commit | cf392dbdf17e38026f8e3c0e9af7f5b87f63be56 (patch) | |
tree | 6b1df9cdc36cc47b6164db69a14bc86a63dc77c6 /libgo/go/syscall/exec_unix_test.go | |
parent | 0000ea4fb4eaacbd2c954d78d7f8e9f03c7be739 (diff) | |
download | gcc-cf392dbdf17e38026f8e3c0e9af7f5b87f63be56.zip gcc-cf392dbdf17e38026f8e3c0e9af7f5b87f63be56.tar.gz gcc-cf392dbdf17e38026f8e3c0e9af7f5b87f63be56.tar.bz2 |
libgo: update to Go 1.15.4 release
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/268177
Diffstat (limited to 'libgo/go/syscall/exec_unix_test.go')
-rw-r--r-- | libgo/go/syscall/exec_unix_test.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/libgo/go/syscall/exec_unix_test.go b/libgo/go/syscall/exec_unix_test.go index fab80e7..1399149 100644 --- a/libgo/go/syscall/exec_unix_test.go +++ b/libgo/go/syscall/exec_unix_test.go @@ -9,12 +9,14 @@ package syscall_test import ( "internal/testenv" "io" + "math/rand" "os" "os/exec" "os/signal" "runtime" "syscall" "testing" + "time" "unsafe" ) @@ -245,3 +247,46 @@ func TestInvalidExec(t *testing.T) { } }) } + +// TestExec is for issue #41702. +func TestExec(t *testing.T) { + testenv.MustHaveExec(t) + cmd := exec.Command(os.Args[0], "-test.run=TestExecHelper") + cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=2") + o, err := cmd.CombinedOutput() + if err != nil { + t.Errorf("%s\n%v", o, err) + } +} + +// TestExecHelper is used by TestExec. It does nothing by itself. +// In testing on macOS 10.14, this used to fail with +// "signal: illegal instruction" more than half the time. +func TestExecHelper(t *testing.T) { + if os.Getenv("GO_WANT_HELPER_PROCESS") != "2" { + return + } + + // We don't have to worry about restoring these values. + // We are in a child process that only runs this test, + // and we are going to call syscall.Exec anyhow. + runtime.GOMAXPROCS(50) + os.Setenv("GO_WANT_HELPER_PROCESS", "3") + + stop := time.Now().Add(time.Second) + for i := 0; i < 100; i++ { + go func(i int) { + r := rand.New(rand.NewSource(int64(i))) + for time.Now().Before(stop) { + r.Uint64() + } + }(i) + } + + time.Sleep(10 * time.Millisecond) + + argv := []string{os.Args[0], "-test.run=TestExecHelper"} + syscall.Exec(os.Args[0], argv, os.Environ()) + + t.Error("syscall.Exec returned") +} |