diff options
Diffstat (limited to 'libgo/go/net/packetconn_test.go')
-rw-r--r-- | libgo/go/net/packetconn_test.go | 119 |
1 files changed, 43 insertions, 76 deletions
diff --git a/libgo/go/net/packetconn_test.go b/libgo/go/net/packetconn_test.go index b6e4e76f930..7f3ea8a2d0c 100644 --- a/libgo/go/net/packetconn_test.go +++ b/libgo/go/net/packetconn_test.go @@ -9,49 +9,21 @@ package net import ( "os" - "runtime" - "strings" "testing" "time" ) -func packetConnTestData(t *testing.T, net string, i int) ([]byte, func()) { - switch net { - case "udp": - return []byte("UDP PACKETCONN TEST"), nil - case "ip": - if skip, skipmsg := skipRawSocketTest(t); skip { - return nil, func() { - t.Logf(skipmsg) - } - } - b, err := (&icmpMessage{ - Type: icmpv4EchoRequest, Code: 0, - Body: &icmpEcho{ - ID: os.Getpid() & 0xffff, Seq: i + 1, - Data: []byte("IP PACKETCONN TEST"), - }, - }).Marshal() - if err != nil { - return nil, func() { - t.Fatalf("icmpMessage.Marshal failed: %v", err) - } - } - return b, nil - case "unixgram": - switch runtime.GOOS { - case "nacl", "plan9", "windows": - return nil, func() { - t.Logf("skipping %q test on %q", net, runtime.GOOS) - } - default: - return []byte("UNIXGRAM PACKETCONN TEST"), nil - } - default: - return nil, func() { - t.Logf("skipping %q test", net) - } +// The full stack test cases for IPConn have been moved to the +// following: +// golang.org/x/net/ipv4 +// golang.org/x/net/ipv6 +// golang.org/x/net/icmp + +func packetConnTestData(t *testing.T, network string) ([]byte, func()) { + if !testableNetwork(network) { + return nil, func() { t.Logf("skipping %s test", network) } } + return []byte("PACKETCONN TEST"), nil } var packetConnTests = []struct { @@ -60,7 +32,6 @@ var packetConnTests = []struct { addr2 string }{ {"udp", "127.0.0.1:0", "127.0.0.1:0"}, - {"ip:icmp", "127.0.0.1", "127.0.0.1"}, {"unixgram", testUnixAddr(), testUnixAddr()}, } @@ -74,9 +45,8 @@ func TestPacketConn(t *testing.T) { } } - for i, tt := range packetConnTests { - netstr := strings.Split(tt.net, ":") - wb, skipOrFatalFn := packetConnTestData(t, netstr[0], i) + for _, tt := range packetConnTests { + wb, skipOrFatalFn := packetConnTestData(t, tt.net) if skipOrFatalFn != nil { skipOrFatalFn() continue @@ -84,37 +54,37 @@ func TestPacketConn(t *testing.T) { c1, err := ListenPacket(tt.net, tt.addr1) if err != nil { - t.Fatalf("ListenPacket failed: %v", err) + t.Fatal(err) } - defer closer(c1, netstr[0], tt.addr1, tt.addr2) + defer closer(c1, tt.net, tt.addr1, tt.addr2) c1.LocalAddr() - c1.SetDeadline(time.Now().Add(100 * time.Millisecond)) - c1.SetReadDeadline(time.Now().Add(100 * time.Millisecond)) - c1.SetWriteDeadline(time.Now().Add(100 * time.Millisecond)) + c1.SetDeadline(time.Now().Add(500 * time.Millisecond)) + c1.SetReadDeadline(time.Now().Add(500 * time.Millisecond)) + c1.SetWriteDeadline(time.Now().Add(500 * time.Millisecond)) c2, err := ListenPacket(tt.net, tt.addr2) if err != nil { - t.Fatalf("ListenPacket failed: %v", err) + t.Fatal(err) } - defer closer(c2, netstr[0], tt.addr1, tt.addr2) + defer closer(c2, tt.net, tt.addr1, tt.addr2) c2.LocalAddr() - c2.SetDeadline(time.Now().Add(100 * time.Millisecond)) - c2.SetReadDeadline(time.Now().Add(100 * time.Millisecond)) - c2.SetWriteDeadline(time.Now().Add(100 * time.Millisecond)) + c2.SetDeadline(time.Now().Add(500 * time.Millisecond)) + c2.SetReadDeadline(time.Now().Add(500 * time.Millisecond)) + c2.SetWriteDeadline(time.Now().Add(500 * time.Millisecond)) + rb2 := make([]byte, 128) if _, err := c1.WriteTo(wb, c2.LocalAddr()); err != nil { - t.Fatalf("PacketConn.WriteTo failed: %v", err) + t.Fatal(err) } - rb2 := make([]byte, 128) if _, _, err := c2.ReadFrom(rb2); err != nil { - t.Fatalf("PacketConn.ReadFrom failed: %v", err) + t.Fatal(err) } if _, err := c2.WriteTo(wb, c1.LocalAddr()); err != nil { - t.Fatalf("PacketConn.WriteTo failed: %v", err) + t.Fatal(err) } rb1 := make([]byte, 128) if _, _, err := c1.ReadFrom(rb1); err != nil { - t.Fatalf("PacketConn.ReadFrom failed: %v", err) + t.Fatal(err) } } } @@ -129,10 +99,9 @@ func TestConnAndPacketConn(t *testing.T) { } } - for i, tt := range packetConnTests { + for _, tt := range packetConnTests { var wb []byte - netstr := strings.Split(tt.net, ":") - wb, skipOrFatalFn := packetConnTestData(t, netstr[0], i) + wb, skipOrFatalFn := packetConnTestData(t, tt.net) if skipOrFatalFn != nil { skipOrFatalFn() continue @@ -140,47 +109,45 @@ func TestConnAndPacketConn(t *testing.T) { c1, err := ListenPacket(tt.net, tt.addr1) if err != nil { - t.Fatalf("ListenPacket failed: %v", err) + t.Fatal(err) } - defer closer(c1, netstr[0], tt.addr1, tt.addr2) + defer closer(c1, tt.net, tt.addr1, tt.addr2) c1.LocalAddr() - c1.SetDeadline(time.Now().Add(100 * time.Millisecond)) - c1.SetReadDeadline(time.Now().Add(100 * time.Millisecond)) - c1.SetWriteDeadline(time.Now().Add(100 * time.Millisecond)) + c1.SetDeadline(time.Now().Add(500 * time.Millisecond)) + c1.SetReadDeadline(time.Now().Add(500 * time.Millisecond)) + c1.SetWriteDeadline(time.Now().Add(500 * time.Millisecond)) c2, err := Dial(tt.net, c1.LocalAddr().String()) if err != nil { - t.Fatalf("Dial failed: %v", err) + t.Fatal(err) } defer c2.Close() c2.LocalAddr() c2.RemoteAddr() - c2.SetDeadline(time.Now().Add(100 * time.Millisecond)) - c2.SetReadDeadline(time.Now().Add(100 * time.Millisecond)) - c2.SetWriteDeadline(time.Now().Add(100 * time.Millisecond)) + c2.SetDeadline(time.Now().Add(500 * time.Millisecond)) + c2.SetReadDeadline(time.Now().Add(500 * time.Millisecond)) + c2.SetWriteDeadline(time.Now().Add(500 * time.Millisecond)) if _, err := c2.Write(wb); err != nil { - t.Fatalf("Conn.Write failed: %v", err) + t.Fatal(err) } rb1 := make([]byte, 128) if _, _, err := c1.ReadFrom(rb1); err != nil { - t.Fatalf("PacketConn.ReadFrom failed: %v", err) + t.Fatal(err) } var dst Addr - switch netstr[0] { - case "ip": - dst = &IPAddr{IP: IPv4(127, 0, 0, 1)} + switch tt.net { case "unixgram": continue default: dst = c2.LocalAddr() } if _, err := c1.WriteTo(wb, dst); err != nil { - t.Fatalf("PacketConn.WriteTo failed: %v", err) + t.Fatal(err) } rb2 := make([]byte, 128) if _, err := c2.Read(rb2); err != nil { - t.Fatalf("Conn.Read failed: %v", err) + t.Fatal(err) } } } |