]> Cypherpunks repositories - gostls13.git/commitdiff
os/exec: make exec_test.go:TestExtraFilesFDShuffle portable.
authorCosmos Nicolaou <cnicolaou@google.com>
Tue, 18 Jun 2013 15:55:32 +0000 (08:55 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 18 Jun 2013 15:55:32 +0000 (08:55 -0700)
R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/9103045

src/pkg/os/exec/exec_test.go

index eae9fb14411737247a5b35913b7292c15a049d41..ec26e298c850db68ea7fe316cc69caf326ecd0e4 100644 (file)
@@ -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