diff options
author | Giuliano Belinassi <giuliano.belinassi@usp.br> | 2020-08-22 17:43:43 -0300 |
---|---|---|
committer | Giuliano Belinassi <giuliano.belinassi@usp.br> | 2020-08-22 17:43:43 -0300 |
commit | a926878ddbd5a98b272c22171ce58663fc04c3e0 (patch) | |
tree | 86af256e5d9a9c06263c00adc90e5fe348008c43 /libgo/go/os/os_test.go | |
parent | 542730f087133690b47e036dfd43eb0db8a650ce (diff) | |
parent | 07cbaed8ba7d1b6e4ab3a9f44175502a4e1ecdb1 (diff) | |
download | gcc-devel/autopar_devel.zip gcc-devel/autopar_devel.tar.gz gcc-devel/autopar_devel.tar.bz2 |
Merge branch 'autopar_rebase2' into autopar_develdevel/autopar_devel
Quickly commit changes in the rebase branch.
Diffstat (limited to 'libgo/go/os/os_test.go')
-rw-r--r-- | libgo/go/os/os_test.go | 136 |
1 files changed, 129 insertions, 7 deletions
diff --git a/libgo/go/os/os_test.go b/libgo/go/os/os_test.go index a19b46d..8a2f917 100644 --- a/libgo/go/os/os_test.go +++ b/libgo/go/os/os_test.go @@ -52,7 +52,7 @@ var sysdir = func() *sysDir { } case "darwin": switch runtime.GOARCH { - case "arm", "arm64": + case "arm64": wd, err := syscall.Getwd() if err != nil { wd = err.Error() @@ -144,7 +144,7 @@ func localTmp() string { return TempDir() case "darwin": switch runtime.GOARCH { - case "arm", "arm64": + case "arm64": return TempDir() } } @@ -481,7 +481,7 @@ func TestReaddirnamesOneAtATime(t *testing.T) { dir = "/system/bin" case "darwin": switch runtime.GOARCH { - case "arm", "arm64": + case "arm64": wd, err := Getwd() if err != nil { t.Fatal(err) @@ -1240,6 +1240,41 @@ func testChtimes(t *testing.T, name string) { } } +func TestFileChdir(t *testing.T) { + // TODO(brainman): file.Chdir() is not implemented on windows. + if runtime.GOOS == "windows" { + return + } + + wd, err := Getwd() + if err != nil { + t.Fatalf("Getwd: %s", err) + } + defer Chdir(wd) + + fd, err := Open(".") + if err != nil { + t.Fatalf("Open .: %s", err) + } + defer fd.Close() + + if err := Chdir("/"); err != nil { + t.Fatalf("Chdir /: %s", err) + } + + if err := fd.Chdir(); err != nil { + t.Fatalf("fd.Chdir: %s", err) + } + + wdNew, err := Getwd() + if err != nil { + t.Fatalf("Getwd: %s", err) + } + if wdNew != wd { + t.Fatalf("fd.Chdir failed, got %s, want %s", wdNew, wd) + } +} + func TestChdirAndGetwd(t *testing.T) { // TODO(brainman): file.Chdir() is not implemented on windows. if runtime.GOOS == "windows" { @@ -1260,7 +1295,7 @@ func TestChdirAndGetwd(t *testing.T) { dirs = []string{"/", "/usr"} case "darwin": switch runtime.GOARCH { - case "arm", "arm64": + case "arm64": dirs = nil for _, d := range []string{"d1", "d2"} { dir, err := ioutil.TempDir("", d) @@ -1323,8 +1358,9 @@ func TestChdirAndGetwd(t *testing.T) { // Test that Chdir+Getwd is program-wide. func TestProgWideChdir(t *testing.T) { const N = 10 + const ErrPwd = "Error!" c := make(chan bool) - cpwd := make(chan string) + cpwd := make(chan string, N) for i := 0; i < N; i++ { go func(i int) { // Lock half the goroutines in their own operating system @@ -1337,10 +1373,15 @@ func TestProgWideChdir(t *testing.T) { // See issue 9428. runtime.LockOSThread() } - <-c + hasErr, closed := <-c + if !closed && hasErr { + cpwd <- ErrPwd + return + } pwd, err := Getwd() if err != nil { t.Errorf("Getwd on goroutine %d: %v", i, err) + cpwd <- ErrPwd return } cpwd <- pwd @@ -1348,10 +1389,12 @@ func TestProgWideChdir(t *testing.T) { } oldwd, err := Getwd() if err != nil { + c <- true t.Fatalf("Getwd: %v", err) } d, err := ioutil.TempDir("", "test") if err != nil { + c <- true t.Fatalf("TempDir: %v", err) } defer func() { @@ -1361,17 +1404,22 @@ func TestProgWideChdir(t *testing.T) { RemoveAll(d) }() if err := Chdir(d); err != nil { + c <- true t.Fatalf("Chdir: %v", err) } // OS X sets TMPDIR to a symbolic link. // So we resolve our working directory again before the test. d, err = Getwd() if err != nil { + c <- true t.Fatalf("Getwd: %v", err) } close(c) for i := 0; i < N; i++ { pwd := <-cpwd + if pwd == ErrPwd { + t.FailNow() + } if pwd != d { t.Errorf("Getwd returned %q; want %q", pwd, d) } @@ -1787,7 +1835,7 @@ func TestAppend(t *testing.T) { func TestStatDirWithTrailingSlash(t *testing.T) { // Create new temporary directory and arrange to clean it up. - path, err := ioutil.TempDir("", "/_TestStatDirWithSlash_") + path, err := ioutil.TempDir("", "_TestStatDirWithSlash_") if err != nil { t.Fatalf("TempDir: %s", err) } @@ -2450,3 +2498,77 @@ func TestDirSeek(t *testing.T) { } } } + +func TestReaddirSmallSeek(t *testing.T) { + // See issue 37161. Read only one entry from a directory, + // seek to the beginning, and read again. We should not see + // duplicate entries. + if runtime.GOOS == "windows" { + testenv.SkipFlaky(t, 36019) + } + wd, err := Getwd() + if err != nil { + t.Fatal(err) + } + df, err := Open(filepath.Join(wd, "testdata", "issue37161")) + if err != nil { + t.Fatal(err) + } + names1, err := df.Readdirnames(1) + if err != nil { + t.Fatal(err) + } + if _, err = df.Seek(0, 0); err != nil { + t.Fatal(err) + } + names2, err := df.Readdirnames(0) + if err != nil { + t.Fatal(err) + } + if len(names2) != 3 { + t.Fatalf("first names: %v, second names: %v", names1, names2) + } +} + +// isDeadlineExceeded reports whether err is or wraps os.ErrDeadlineExceeded. +// We also check that the error has a Timeout method that returns true. +func isDeadlineExceeded(err error) bool { + if !IsTimeout(err) { + return false + } + if !errors.Is(err, ErrDeadlineExceeded) { + return false + } + return true +} + +// Test that opening a file does not change its permissions. Issue 38225. +func TestOpenFileKeepsPermissions(t *testing.T) { + t.Parallel() + dir := t.TempDir() + name := filepath.Join(dir, "x") + f, err := Create(name) + if err != nil { + t.Fatal(err) + } + if err := f.Close(); err != nil { + t.Error(err) + } + f, err = OpenFile(name, O_WRONLY|O_CREATE|O_TRUNC, 0) + if err != nil { + t.Fatal(err) + } + if fi, err := f.Stat(); err != nil { + t.Error(err) + } else if fi.Mode()&0222 == 0 { + t.Errorf("f.Stat.Mode after OpenFile is %v, should be writable", fi.Mode()) + } + if err := f.Close(); err != nil { + t.Error(err) + } + if fi, err := Stat(name); err != nil { + t.Error(err) + } else if fi.Mode()&0222 == 0 { + t.Errorf("Stat after OpenFile is %v, should be writable", fi.Mode()) + } +} |