From: Cosmos Nicolaou Date: Tue, 18 Jun 2013 15:55:32 +0000 (-0700) Subject: os/exec: make exec_test.go:TestExtraFilesFDShuffle portable. X-Git-Tag: go1.2rc2~1222 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f882bc8708e52ccc1a6844294ac29d73fc04dd41;p=gostls13.git os/exec: make exec_test.go:TestExtraFilesFDShuffle portable. R=golang-dev, minux.ma CC=golang-dev https://golang.org/cl/9103045 --- diff --git a/src/pkg/os/exec/exec_test.go b/src/pkg/os/exec/exec_test.go index eae9fb1441..ec26e298c8 100644 --- a/src/pkg/os/exec/exec_test.go +++ b/src/pkg/os/exec/exec_test.go @@ -195,8 +195,28 @@ func basefds() uintptr { return n } +func closeUnexpectedFds(t *testing.T, m string) { + for fd := basefds(); fd <= 101; fd++ { + err := os.NewFile(fd, "").Close() + if err == nil { + t.Logf("%s: Something already leaked - closed fd %d", m, fd) + } + } +} + func TestExtraFilesFDShuffle(t *testing.T) { - t.Skip("TODO: TestExtraFilesFDShuffle is too non-portable; skipping") + switch runtime.GOOS { + case "darwin": + // TODO(cnicolaou): http://golang.org/issue/2603 + // leads to leaked file descriptors in this test when it's + // run from a builder. + closeUnexpectedFds(t, "TestExtraFilesFDShuffle") + case "netbsd": + // http://golang.org/issue/3955 + closeUnexpectedFds(t, "TestExtraFilesFDShuffle") + case "windows": + t.Skip("no operating system support; skipping") + } // syscall.StartProcess maps all the FDs passed to it in // ProcAttr.Files (the concatenation of stdin,stdout,stderr and @@ -296,12 +316,7 @@ func TestExtraFiles(t *testing.T) { // our environment. if !testedAlreadyLeaked { testedAlreadyLeaked = true - for fd := basefds(); fd <= 101; fd++ { - err := os.NewFile(fd, "").Close() - if err == nil { - t.Logf("Something already leaked - closed fd %d", fd) - } - } + closeUnexpectedFds(t, "TestExtraFiles") } // Force network usage, to verify the epoll (or whatever) fd