]> Cypherpunks repositories - gostls13.git/commitdiff
net: move some Linux-specific tests to unixsock_linux_test.go file
authorIan Lance Taylor <iant@golang.org>
Tue, 26 Sep 2017 23:42:03 +0000 (16:42 -0700)
committerIan Lance Taylor <iant@golang.org>
Thu, 28 Sep 2017 03:00:34 +0000 (03:00 +0000)
Also changed name from TestUnix... to TestUnixgram....

Updates #21965

Change-Id: I2833110b77e9fe1b28d4a15feb3d70453ab98d3b
Reviewed-on: https://go-review.googlesource.com/66333
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Rob Pike <r@golang.org>
src/net/unixsock_linux_test.go [new file with mode: 0644]
src/net/unixsock_test.go

diff --git a/src/net/unixsock_linux_test.go b/src/net/unixsock_linux_test.go
new file mode 100644 (file)
index 0000000..d04007c
--- /dev/null
@@ -0,0 +1,104 @@
+// Copyright 2017 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 net
+
+import (
+       "bytes"
+       "reflect"
+       "syscall"
+       "testing"
+       "time"
+)
+
+func TestUnixgramAutobind(t *testing.T) {
+       laddr := &UnixAddr{Name: "", Net: "unixgram"}
+       c1, err := ListenUnixgram("unixgram", laddr)
+       if err != nil {
+               t.Fatal(err)
+       }
+       defer c1.Close()
+
+       // retrieve the autobind address
+       autoAddr := c1.LocalAddr().(*UnixAddr)
+       if len(autoAddr.Name) <= 1 {
+               t.Fatalf("invalid autobind address: %v", autoAddr)
+       }
+       if autoAddr.Name[0] != '@' {
+               t.Fatalf("invalid autobind address: %v", autoAddr)
+       }
+
+       c2, err := DialUnix("unixgram", nil, autoAddr)
+       if err != nil {
+               t.Fatal(err)
+       }
+       defer c2.Close()
+
+       if !reflect.DeepEqual(c1.LocalAddr(), c2.RemoteAddr()) {
+               t.Fatalf("expected autobind address %v, got %v", c1.LocalAddr(), c2.RemoteAddr())
+       }
+}
+
+func TestUnixAutobindClose(t *testing.T) {
+       laddr := &UnixAddr{Name: "", Net: "unix"}
+       ln, err := ListenUnix("unix", laddr)
+       if err != nil {
+               t.Fatal(err)
+       }
+       ln.Close()
+}
+
+func TestUnixgramLinuxAbstractLongName(t *testing.T) {
+       if !testableNetwork("unixgram") {
+               t.Skip("abstract unix socket long name test")
+       }
+
+       // Create an abstract socket name whose length is exactly
+       // the maximum RawSockkaddrUnix Path len
+       rsu := syscall.RawSockaddrUnix{}
+       addrBytes := make([]byte, len(rsu.Path))
+       copy(addrBytes, "@abstract_test")
+       addr := string(addrBytes)
+
+       la, err := ResolveUnixAddr("unixgram", addr)
+       if err != nil {
+               t.Fatal(err)
+       }
+       c, err := ListenUnixgram("unixgram", la)
+       if err != nil {
+               t.Fatal(err)
+       }
+       defer c.Close()
+
+       off := make(chan bool)
+       data := [5]byte{1, 2, 3, 4, 5}
+       go func() {
+               defer func() { off <- true }()
+               s, err := syscall.Socket(syscall.AF_UNIX, syscall.SOCK_DGRAM, 0)
+               if err != nil {
+                       t.Error(err)
+                       return
+               }
+               defer syscall.Close(s)
+               rsa := &syscall.SockaddrUnix{Name: addr}
+               if err := syscall.Sendto(s, data[:], 0, rsa); err != nil {
+                       t.Error(err)
+                       return
+               }
+       }()
+
+       <-off
+       b := make([]byte, 64)
+       c.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
+       n, from, err := c.ReadFrom(b)
+       if err != nil {
+               t.Fatal(err)
+       }
+       if from != nil {
+               t.Fatalf("unexpected peer address: %v", from)
+       }
+       if !bytes.Equal(b[:n], data[:]) {
+               t.Fatalf("got %v; want %v", b[:n], data[:])
+       }
+}
index ac69a9abc6b0f1b9ef9a0845354f4a7e01358351..3e5c8bc3769c6b25e2ffadf760019ccd5ee0c3eb 100644 (file)
@@ -170,51 +170,6 @@ func TestUnixgramZeroByteBuffer(t *testing.T) {
        }
 }
 
-func TestUnixgramAutobind(t *testing.T) {
-       if runtime.GOOS != "linux" {
-               t.Skip("autobind is linux only")
-       }
-
-       laddr := &UnixAddr{Name: "", Net: "unixgram"}
-       c1, err := ListenUnixgram("unixgram", laddr)
-       if err != nil {
-               t.Fatal(err)
-       }
-       defer c1.Close()
-
-       // retrieve the autobind address
-       autoAddr := c1.LocalAddr().(*UnixAddr)
-       if len(autoAddr.Name) <= 1 {
-               t.Fatalf("invalid autobind address: %v", autoAddr)
-       }
-       if autoAddr.Name[0] != '@' {
-               t.Fatalf("invalid autobind address: %v", autoAddr)
-       }
-
-       c2, err := DialUnix("unixgram", nil, autoAddr)
-       if err != nil {
-               t.Fatal(err)
-       }
-       defer c2.Close()
-
-       if !reflect.DeepEqual(c1.LocalAddr(), c2.RemoteAddr()) {
-               t.Fatalf("expected autobind address %v, got %v", c1.LocalAddr(), c2.RemoteAddr())
-       }
-}
-
-func TestUnixAutobindClose(t *testing.T) {
-       if runtime.GOOS != "linux" {
-               t.Skip("autobind is linux only")
-       }
-
-       laddr := &UnixAddr{Name: "", Net: "unix"}
-       ln, err := ListenUnix("unix", laddr)
-       if err != nil {
-               t.Fatal(err)
-       }
-       ln.Close()
-}
-
 func TestUnixgramWrite(t *testing.T) {
        if !testableNetwork("unixgram") {
                t.Skip("unixgram test")
@@ -516,57 +471,3 @@ func TestUnixUnlink(t *testing.T) {
                l.Close()
        })
 }
-
-func TestUnixLinuxAbstractLongName(t *testing.T) {
-       if runtime.GOOS != "linux" || !testableNetwork("unixgram") {
-               t.Skip("abstract unix socket long name test")
-       }
-
-       // Create an abstract socket name whose length is exactly
-       // the maximum RawSockkaddrUnix Path len
-       rsu := syscall.RawSockaddrUnix{}
-       addrBytes := make([]byte, len(rsu.Path))
-       copy(addrBytes, "@abstract_test")
-       addr := string(addrBytes)
-
-       la, err := ResolveUnixAddr("unixgram", addr)
-       if err != nil {
-               t.Fatal(err)
-       }
-       c, err := ListenUnixgram("unixgram", la)
-       if err != nil {
-               t.Fatal(err)
-       }
-       defer c.Close()
-
-       off := make(chan bool)
-       data := [5]byte{1, 2, 3, 4, 5}
-       go func() {
-               defer func() { off <- true }()
-               s, err := syscall.Socket(syscall.AF_UNIX, syscall.SOCK_DGRAM, 0)
-               if err != nil {
-                       t.Error(err)
-                       return
-               }
-               defer syscall.Close(s)
-               rsa := &syscall.SockaddrUnix{Name: addr}
-               if err := syscall.Sendto(s, data[:], 0, rsa); err != nil {
-                       t.Error(err)
-                       return
-               }
-       }()
-
-       <-off
-       b := make([]byte, 64)
-       c.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
-       n, from, err := c.ReadFrom(b)
-       if err != nil {
-               t.Fatal(err)
-       }
-       if from != nil {
-               t.Fatalf("unexpected peer address: %v", from)
-       }
-       if !bytes.Equal(b[:n], data[:]) {
-               t.Fatalf("got %v; want %v", b[:n], data[:])
-       }
-}