diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-01-29 20:52:43 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-01-29 20:52:43 +0000 |
commit | 12ebd6294172cc1108bbadab78fea03e890a6da4 (patch) | |
tree | 4f2fad1f4b778519bdd5941185c7e1d032af055b /libgo/go/os | |
parent | 6effa4dc115122a3a4838de0a302dfcadcefeeca (diff) | |
download | ppe42-gcc-12ebd6294172cc1108bbadab78fea03e890a6da4.tar.gz ppe42-gcc-12ebd6294172cc1108bbadab78fea03e890a6da4.zip |
libgo: Update Go library to master revision 15489/921e53d4863c.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@195560 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/os')
-rw-r--r-- | libgo/go/os/exec/exec_test.go | 19 | ||||
-rw-r--r-- | libgo/go/os/exec_plan9.go | 16 | ||||
-rw-r--r-- | libgo/go/os/file_unix.go | 19 | ||||
-rw-r--r-- | libgo/go/os/os_test.go | 20 | ||||
-rw-r--r-- | libgo/go/os/path_test.go | 3 | ||||
-rw-r--r-- | libgo/go/os/pipe_bsd.go | 28 | ||||
-rw-r--r-- | libgo/go/os/pipe_linux.go | 33 | ||||
-rw-r--r-- | libgo/go/os/proc.go | 2 | ||||
-rw-r--r-- | libgo/go/os/signal/signal_test.go | 41 | ||||
-rw-r--r-- | libgo/go/os/user/user_test.go | 28 |
10 files changed, 138 insertions, 71 deletions
diff --git a/libgo/go/os/exec/exec_test.go b/libgo/go/os/exec/exec_test.go index af07452b464..ff8954fd020 100644 --- a/libgo/go/os/exec/exec_test.go +++ b/libgo/go/os/exec/exec_test.go @@ -144,18 +144,22 @@ func TestPipes(t *testing.T) { check("Wait", err) } +var testedAlreadyLeaked = false + func TestExtraFiles(t *testing.T) { if runtime.GOOS == "windows" { - t.Logf("no operating system support; skipping") - return + t.Skip("no operating system support; skipping") } // Ensure that file descriptors have not already been leaked into // our environment. - for fd := os.Stderr.Fd() + 1; fd <= 101; fd++ { - err := os.NewFile(fd, "").Close() - if err == nil { - t.Logf("Something already leaked - closed fd %d", fd) + if !testedAlreadyLeaked { + testedAlreadyLeaked = true + for fd := os.Stderr.Fd() + 1; fd <= 101; fd++ { + err := os.NewFile(fd, "").Close() + if err == nil { + t.Logf("Something already leaked - closed fd %d", fd) + } } } @@ -217,8 +221,7 @@ func TestExtraFiles(t *testing.T) { func TestExtraFilesRace(t *testing.T) { if runtime.GOOS == "windows" { - t.Logf("no operating system support; skipping") - return + t.Skip("no operating system support; skipping") } listen := func() net.Listener { ln, err := net.Listen("tcp", "127.0.0.1:0") diff --git a/libgo/go/os/exec_plan9.go b/libgo/go/os/exec_plan9.go index 2a7a5976373..2bd5b6888d9 100644 --- a/libgo/go/os/exec_plan9.go +++ b/libgo/go/os/exec_plan9.go @@ -75,20 +75,12 @@ func (p *Process) wait() (ps *ProcessState, err error) { if p.Pid == -1 { return nil, ErrInvalid } - - for true { - err = syscall.Await(&waitmsg) - - if err != nil { - return nil, NewSyscallError("wait", err) - } - - if waitmsg.Pid == p.Pid { - p.setDone() - break - } + err = syscall.WaitProcess(p.Pid, &waitmsg) + if err != nil { + return nil, NewSyscallError("wait", err) } + p.setDone() ps = &ProcessState{ pid: waitmsg.Pid, status: &waitmsg, diff --git a/libgo/go/os/file_unix.go b/libgo/go/os/file_unix.go index 68f4be88d06..38adcf95c79 100644 --- a/libgo/go/os/file_unix.go +++ b/libgo/go/os/file_unix.go @@ -285,25 +285,6 @@ func basename(name string) string { return name } -// Pipe returns a connected pair of Files; reads from r return bytes written to w. -// It returns the files and an error, if any. -func Pipe() (r *File, w *File, err error) { - var p [2]int - - // See ../syscall/exec.go for description of lock. - syscall.ForkLock.RLock() - e := syscall.Pipe(p[0:]) - if e != nil { - syscall.ForkLock.RUnlock() - return nil, nil, NewSyscallError("pipe", e) - } - syscall.CloseOnExec(p[0]) - syscall.CloseOnExec(p[1]) - syscall.ForkLock.RUnlock() - - return NewFile(uintptr(p[0]), "|0"), NewFile(uintptr(p[1]), "|1"), nil -} - // TempDir returns the default directory to use for temporary files. func TempDir() string { dir := Getenv("TMPDIR") diff --git a/libgo/go/os/os_test.go b/libgo/go/os/os_test.go index 9f0bbdc25cc..560f7a0c324 100644 --- a/libgo/go/os/os_test.go +++ b/libgo/go/os/os_test.go @@ -309,8 +309,7 @@ func TestReaddirnamesOneAtATime(t *testing.T) { func TestReaddirNValues(t *testing.T) { if testing.Short() { - t.Logf("test.short; skipping") - return + t.Skip("test.short; skipping") } dir, err := ioutil.TempDir("", "") if err != nil { @@ -534,8 +533,10 @@ func exec(t *testing.T, dir, cmd string, args []string, expect string) { var b bytes.Buffer io.Copy(&b, r) output := b.String() - // Accept /usr prefix because Solaris /bin is symlinked to /usr/bin. - if output != expect && output != "/usr"+expect { + + fi1, _ := Stat(strings.TrimSpace(output)) + fi2, _ := Stat(expect) + if !SameFile(fi1, fi2) { t.Errorf("exec %q returned %q wanted %q", strings.Join(append([]string{cmd}, args...), " "), output, expect) } @@ -543,15 +544,13 @@ func exec(t *testing.T, dir, cmd string, args []string, expect string) { } func TestStartProcess(t *testing.T) { - var dir, cmd, le string + var dir, cmd string var args []string if runtime.GOOS == "windows" { - le = "\r\n" cmd = Getenv("COMSPEC") dir = Getenv("SystemRoot") args = []string{"/c", "cd"} } else { - le = "\n" cmd = "/bin/pwd" dir = "/" args = []string{} @@ -559,9 +558,9 @@ func TestStartProcess(t *testing.T) { cmddir, cmdbase := filepath.Split(cmd) args = append([]string{cmdbase}, args...) // Test absolute executable path. - exec(t, dir, cmd, args, dir+le) + exec(t, dir, cmd, args, dir) // Test relative executable path. - exec(t, cmddir, cmdbase, args, filepath.Clean(cmddir)+le) + exec(t, cmddir, cmdbase, args, cmddir) } func checkMode(t *testing.T, path string, mode FileMode) { @@ -1070,8 +1069,7 @@ var testLargeWrite = flag.Bool("large_write", false, "run TestLargeWriteToConsol func TestLargeWriteToConsole(t *testing.T) { if !*testLargeWrite { - t.Logf("skipping console-flooding test; enable with -large_write") - return + t.Skip("skipping console-flooding test; enable with -large_write") } b := make([]byte, 32000) for i := range b { diff --git a/libgo/go/os/path_test.go b/libgo/go/os/path_test.go index 96f0f41e639..16c4120dc6c 100644 --- a/libgo/go/os/path_test.go +++ b/libgo/go/os/path_test.go @@ -168,8 +168,7 @@ func TestRemoveAll(t *testing.T) { func TestMkdirAllWithSymlink(t *testing.T) { if runtime.GOOS == "windows" || runtime.GOOS == "plan9" { - t.Log("Skipping test: symlinks don't exist under Windows/Plan 9") - return + t.Skip("Skipping test: symlinks don't exist under Windows/Plan 9") } tmpDir, err := ioutil.TempDir("", "TestMkdirAllWithSymlink-") diff --git a/libgo/go/os/pipe_bsd.go b/libgo/go/os/pipe_bsd.go new file mode 100644 index 00000000000..a2ce9a39f56 --- /dev/null +++ b/libgo/go/os/pipe_bsd.go @@ -0,0 +1,28 @@ +// Copyright 2009 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. + +// +build darwin freebsd netbsd openbsd + +package os + +import "syscall" + +// Pipe returns a connected pair of Files; reads from r return bytes written to w. +// It returns the files and an error, if any. +func Pipe() (r *File, w *File, err error) { + var p [2]int + + // See ../syscall/exec.go for description of lock. + syscall.ForkLock.RLock() + e := syscall.Pipe(p[0:]) + if e != nil { + syscall.ForkLock.RUnlock() + return nil, nil, NewSyscallError("pipe", e) + } + syscall.CloseOnExec(p[0]) + syscall.CloseOnExec(p[1]) + syscall.ForkLock.RUnlock() + + return NewFile(uintptr(p[0]), "|0"), NewFile(uintptr(p[1]), "|1"), nil +} diff --git a/libgo/go/os/pipe_linux.go b/libgo/go/os/pipe_linux.go new file mode 100644 index 00000000000..9bafad84f9f --- /dev/null +++ b/libgo/go/os/pipe_linux.go @@ -0,0 +1,33 @@ +// Copyright 2013 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 os + +import "syscall" + +// Pipe returns a connected pair of Files; reads from r return bytes written to w. +// It returns the files and an error, if any. +func Pipe() (r *File, w *File, err error) { + var p [2]int + + e := syscall.Pipe2(p[0:], syscall.O_CLOEXEC) + // pipe2 was added in 2.6.27 and our minimum requirement is 2.6.23, so it + // might not be implemented. + if e == syscall.ENOSYS { + // See ../syscall/exec.go for description of lock. + syscall.ForkLock.RLock() + e = syscall.Pipe(p[0:]) + if e != nil { + syscall.ForkLock.RUnlock() + return nil, nil, NewSyscallError("pipe", e) + } + syscall.CloseOnExec(p[0]) + syscall.CloseOnExec(p[1]) + syscall.ForkLock.RUnlock() + } else if e != nil { + return nil, nil, NewSyscallError("pipe2", e) + } + + return NewFile(uintptr(p[0]), "|0"), NewFile(uintptr(p[1]), "|1"), nil +} diff --git a/libgo/go/os/proc.go b/libgo/go/os/proc.go index 61545f4456a..38c436ec54d 100644 --- a/libgo/go/os/proc.go +++ b/libgo/go/os/proc.go @@ -31,4 +31,6 @@ func Getgroups() ([]int, error) { // Exit causes the current program to exit with the given status code. // Conventionally, code zero indicates success, non-zero an error. +// The program terminates immediately; deferred functions are +// not run. func Exit(code int) { syscall.Exit(code) } diff --git a/libgo/go/os/signal/signal_test.go b/libgo/go/os/signal/signal_test.go index 3494f8c34cb..509b273aa2f 100644 --- a/libgo/go/os/signal/signal_test.go +++ b/libgo/go/os/signal/signal_test.go @@ -8,6 +8,7 @@ package signal import ( "os" + "runtime" "syscall" "testing" "time" @@ -58,3 +59,43 @@ func TestSignal(t *testing.T) { // The first SIGHUP should be waiting for us on c. waitSig(t, c, syscall.SIGHUP) } + +func TestStress(t *testing.T) { + dur := 3 * time.Second + if testing.Short() { + dur = 100 * time.Millisecond + } + defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(4)) + done := make(chan bool) + finished := make(chan bool) + go func() { + sig := make(chan os.Signal, 1) + Notify(sig, syscall.SIGUSR1) + Loop: + for { + select { + case <-sig: + case <-done: + break Loop + } + } + finished <- true + }() + go func() { + Loop: + for { + select { + case <-done: + break Loop + default: + syscall.Kill(syscall.Getpid(), syscall.SIGUSR1) + runtime.Gosched() + } + } + finished <- true + }() + time.Sleep(dur) + close(done) + <-finished + <-finished +} diff --git a/libgo/go/os/user/user_test.go b/libgo/go/os/user/user_test.go index 1486fb84751..444a9aacd47 100644 --- a/libgo/go/os/user/user_test.go +++ b/libgo/go/os/user/user_test.go @@ -9,25 +9,20 @@ import ( "testing" ) -func skip(t *testing.T) bool { +func check(t *testing.T) { if !implemented { - t.Logf("user: not implemented; skipping tests") - return true + t.Skip("user: not implemented; skipping tests") } - switch runtime.GOOS { case "linux", "freebsd", "darwin", "windows": - return false + // test supported + default: + t.Skipf("user: Lookup not implemented on %q; skipping test", runtime.GOOS) } - - t.Logf("user: Lookup not implemented on %s; skipping test", runtime.GOOS) - return true } func TestCurrent(t *testing.T) { - if skip(t) { - return - } + check(t) u, err := Current() if err != nil { @@ -53,8 +48,7 @@ func compare(t *testing.T, want, got *User) { } // TODO(brainman): fix it once we know how. if runtime.GOOS == "windows" { - t.Log("skipping Gid and HomeDir comparisons") - return + t.Skip("skipping Gid and HomeDir comparisons") } if want.Gid != got.Gid { t.Errorf("got Gid=%q; want %q", got.Gid, want.Gid) @@ -65,9 +59,7 @@ func compare(t *testing.T, want, got *User) { } func TestLookup(t *testing.T) { - if skip(t) { - return - } + check(t) want, err := Current() if err != nil { @@ -81,9 +73,7 @@ func TestLookup(t *testing.T) { } func TestLookupId(t *testing.T) { - if skip(t) { - return - } + check(t) want, err := Current() if err != nil { |