From 4161dfc4feafa08870e347c5ca7da155a9790867 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Mon, 19 Mar 2012 11:12:32 +1100 Subject: [PATCH] syscall: delete passfd_test.go We can revisit the issue of testing in syscall after Go 1. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/5844057 --- src/pkg/syscall/passfd_test.go | 150 --------------------------------- 1 file changed, 150 deletions(-) delete mode 100644 src/pkg/syscall/passfd_test.go diff --git a/src/pkg/syscall/passfd_test.go b/src/pkg/syscall/passfd_test.go deleted file mode 100644 index 96a41316b5..0000000000 --- a/src/pkg/syscall/passfd_test.go +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright 2012 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 linux darwin probablyfreebsd probablyopenbsd - -package syscall_test - -import ( - "flag" - "fmt" - "io/ioutil" - "net" - "os" - "os/exec" - "syscall" - "testing" - "time" -) - -// TestPassFD tests passing a file descriptor over a Unix socket. -func TestPassFD(t *testing.T) { - tempDir, err := ioutil.TempDir("", "TestPassFD") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tempDir) - - fds, err := syscall.Socketpair(syscall.AF_LOCAL, syscall.SOCK_STREAM, 0) - if err != nil { - t.Fatalf("Socketpair: %v", err) - } - defer syscall.Close(fds[0]) - defer syscall.Close(fds[1]) - writeFile := os.NewFile(uintptr(fds[0]), "child-writes") - readFile := os.NewFile(uintptr(fds[1]), "parent-reads") - defer writeFile.Close() - defer readFile.Close() - - cmd := exec.Command(os.Args[0], "-test.run=TestPassFDChild", "--", tempDir) - cmd.Env = append([]string{"GO_WANT_HELPER_PROCESS=1"}, os.Environ()...) - cmd.ExtraFiles = []*os.File{writeFile} - - out, err := cmd.CombinedOutput() - if len(out) > 0 || err != nil { - t.Errorf("child process: %q, %v", out, err) - return // not fatalf, so defers above run. - } - - c, err := net.FileConn(readFile) - if err != nil { - t.Errorf("FileConn: %v", err) - return - } - defer c.Close() - - uc, ok := c.(*net.UnixConn) - if !ok { - t.Errorf("unexpected FileConn type; expected UnixConn, got %T", c) - return - } - - buf := make([]byte, 32) // expect 1 byte - oob := make([]byte, 32) // expect 24 bytes - closeUnix := time.AfterFunc(5*time.Second, func() { - t.Logf("timeout reading from unix socket") - uc.Close() - }) - _, oobn, _, _, err := uc.ReadMsgUnix(buf, oob) - closeUnix.Stop() - - scms, err := syscall.ParseSocketControlMessage(oob[:oobn]) - if err != nil { - t.Errorf("ParseSocketControlMessage: %v", err) - return - } - if len(scms) != 1 { - t.Errorf("expected 1 SocketControlMessage; got scms = %#v", scms) - return - } - scm := scms[0] - gotFds, err := syscall.ParseUnixRights(&scm) - if err != nil { - t.Errorf("syscall.ParseUnixRights: %v", err) - return - } - if len(gotFds) != 1 { - t.Errorf("wanted 1 fd; got %#v", gotFds) - return - } - - f := os.NewFile(uintptr(gotFds[0]), "fd-from-child") - defer f.Close() - - got, err := ioutil.ReadAll(f) - want := "Hello from child process!\n" - if string(got) != want { - t.Errorf("child process ReadAll: %q, %v; want %q", got, err, want) - } -} - -// Not a real test. This is the helper child process for TestPassFD. -func TestPassFDChild(*testing.T) { - if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" { - return - } - defer os.Exit(0) - - // Look for our fd. I