Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1221)

Side by Side Diff: src/pkg/net/unicast_test.go

Issue 5558056: code review 5558056: net: fix linux build (Closed)
Patch Set: diff -r cc1fb54d8263 https://go.googlecode.com/hg/ Created 12 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package net 5 package net
6 6
7 import ( 7 import (
8 "io"
8 "runtime" 9 "runtime"
9 "testing" 10 "testing"
10 ) 11 )
11 12
12 var unicastTests = []struct { 13 var unicastTests = []struct {
13 net string 14 net string
14 laddr string 15 laddr string
15 ipv6 bool 16 ipv6 bool
16 packet bool 17 packet bool
17 }{ 18 }{
18 {net: "tcp4", laddr: "127.0.0.1:0"}, 19 {net: "tcp4", laddr: "127.0.0.1:0"},
19 {net: "tcp4", laddr: "previous"}, 20 {net: "tcp4", laddr: "previous"},
20 {net: "tcp6", laddr: "[::1]:0", ipv6: true}, 21 {net: "tcp6", laddr: "[::1]:0", ipv6: true},
21 {net: "tcp6", laddr: "previous", ipv6: true}, 22 {net: "tcp6", laddr: "previous", ipv6: true},
22 {net: "udp4", laddr: "127.0.0.1:0", packet: true}, 23 {net: "udp4", laddr: "127.0.0.1:0", packet: true},
23 {net: "udp6", laddr: "[::1]:0", ipv6: true, packet: true}, 24 {net: "udp6", laddr: "[::1]:0", ipv6: true, packet: true},
24 } 25 }
25 26
26 func TestUnicastTCPAndUDP(t *testing.T) { 27 func TestUnicastTCPAndUDP(t *testing.T) {
27 if runtime.GOOS == "plan9" || runtime.GOOS == "windows" { 28 if runtime.GOOS == "plan9" || runtime.GOOS == "windows" {
28 return 29 return
29 } 30 }
30 31
31 prevladdr := "" 32 prevladdr := ""
32 for _, tt := range unicastTests { 33 for _, tt := range unicastTests {
33 if tt.ipv6 && !supportsIPv6 { 34 if tt.ipv6 && !supportsIPv6 {
34 continue 35 continue
35 } 36 }
36 » » var fd *netFD 37 » » var (
38 » » » fd *netFD
39 » » » closer io.Closer
40 » » )
37 if !tt.packet { 41 if !tt.packet {
38 if tt.laddr == "previous" { 42 if tt.laddr == "previous" {
39 tt.laddr = prevladdr 43 tt.laddr = prevladdr
40 } 44 }
41 » » » c, err := Listen(tt.net, tt.laddr) 45 » » » l, err := Listen(tt.net, tt.laddr)
42 if err != nil { 46 if err != nil {
43 t.Fatalf("Listen failed: %v", err) 47 t.Fatalf("Listen failed: %v", err)
44 } 48 }
45 » » » prevladdr = c.Addr().String() 49 » » » prevladdr = l.Addr().String()
46 » » » defer c.Close() 50 » » » closer = l
47 » » » fd = c.(*TCPListener).fd 51 » » » fd = l.(*TCPListener).fd
48 } else { 52 } else {
49 c, err := ListenPacket(tt.net, tt.laddr) 53 c, err := ListenPacket(tt.net, tt.laddr)
50 if err != nil { 54 if err != nil {
51 t.Fatalf("ListenPacket failed: %v", err) 55 t.Fatalf("ListenPacket failed: %v", err)
52 } 56 }
53 » » » defer c.Close() 57 » » » closer = c
54 fd = c.(*UDPConn).fd 58 fd = c.(*UDPConn).fd
55 } 59 }
56 if !tt.ipv6 { 60 if !tt.ipv6 {
57 testIPv4UnicastSocketOptions(t, fd) 61 testIPv4UnicastSocketOptions(t, fd)
58 } else { 62 } else {
59 testIPv6UnicastSocketOptions(t, fd) 63 testIPv6UnicastSocketOptions(t, fd)
60 } 64 }
65 closer.Close()
61 } 66 }
62 } 67 }
63 68
64 func testIPv4UnicastSocketOptions(t *testing.T, fd *netFD) { 69 func testIPv4UnicastSocketOptions(t *testing.T, fd *netFD) {
65 tos, err := ipv4TOS(fd) 70 tos, err := ipv4TOS(fd)
66 if err != nil { 71 if err != nil {
67 t.Fatalf("ipv4TOS failed: %v", err) 72 t.Fatalf("ipv4TOS failed: %v", err)
68 } 73 }
69 t.Logf("IPv4 TOS: %v", tos) 74 t.Logf("IPv4 TOS: %v", tos)
70 err = setIPv4TOS(fd, 1) 75 err = setIPv4TOS(fd, 1)
(...skipping 26 matching lines...) Expand all
97 hoplim, err := ipv6HopLimit(fd) 102 hoplim, err := ipv6HopLimit(fd)
98 if err != nil { 103 if err != nil {
99 t.Fatalf("ipv6HopLimit failed: %v", err) 104 t.Fatalf("ipv6HopLimit failed: %v", err)
100 } 105 }
101 t.Logf("IPv6 HopLimit: %v", hoplim) 106 t.Logf("IPv6 HopLimit: %v", hoplim)
102 err = setIPv6HopLimit(fd, 1) 107 err = setIPv6HopLimit(fd, 1)
103 if err != nil { 108 if err != nil {
104 t.Fatalf("setIPv6HopLimit failed: %v", err) 109 t.Fatalf("setIPv6HopLimit failed: %v", err)
105 } 110 }
106 } 111 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b