diff options
Diffstat (limited to 'libgo/go/runtime/semasleep_test.go')
-rw-r--r-- | libgo/go/runtime/semasleep_test.go | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/libgo/go/runtime/semasleep_test.go b/libgo/go/runtime/semasleep_test.go index 5b2cc64..f5b4a50 100644 --- a/libgo/go/runtime/semasleep_test.go +++ b/libgo/go/runtime/semasleep_test.go @@ -7,11 +7,7 @@ package runtime_test import ( - "internal/testenv" - "io/ioutil" - "os" "os/exec" - "path/filepath" "syscall" "testing" "time" @@ -21,39 +17,17 @@ import ( // shouldn't cause semasleep to retry with the same timeout which would // cause indefinite spinning. func TestSpuriousWakeupsNeverHangSemasleep(t *testing.T) { - testenv.MustHaveGoBuild(t) - tempDir, err := ioutil.TempDir("", "issue-27250") - if err != nil { - t.Fatalf("Failed to create the temp directory: %v", err) + if *flagQuick { + t.Skip("-quick") } - defer os.RemoveAll(tempDir) - - repro := ` - package main - import "time" - - func main() { - <-time.After(1 * time.Second) - } - ` - mainPath := filepath.Join(tempDir, "main.go") - if err := ioutil.WriteFile(mainPath, []byte(repro), 0644); err != nil { - t.Fatalf("Failed to create temp file for repro.go: %v", err) - } - binaryPath := filepath.Join(tempDir, "binary") - - // Build the binary so that we can send the signal to its PID. - out, err := exec.Command(testenv.GoToolPath(t), "build", "-o", binaryPath, mainPath).CombinedOutput() + exe, err := buildTestProg(t, "testprog") if err != nil { - t.Fatalf("Failed to compile the binary: err: %v\nOutput: %s\n", err, out) - } - if err := os.Chmod(binaryPath, 0755); err != nil { - t.Fatalf("Failed to chmod binary: %v", err) + t.Fatal(err) } - // Now run the binary. - cmd := exec.Command(binaryPath) + start := time.Now() + cmd := exec.Command(exe, "After1") if err := cmd.Start(); err != nil { t.Fatalf("Failed to start command: %v", err) } @@ -82,6 +56,9 @@ func TestSpuriousWakeupsNeverHangSemasleep(t *testing.T) { if err != nil { t.Fatalf("The program returned but unfortunately with an error: %v", err) } + if time.Since(start) < 100*time.Millisecond { + t.Fatalf("The program stopped too quickly.") + } return } } |