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

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

Issue 6816116: code review 6816116: net: support IPv6 scoped addressing zone (Closed)
Patch Set: diff -r f5c69f87ef34 https://code.google.com/p/go Created 12 years, 5 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 | « src/pkg/net/multicast_posix_test.go ('k') | src/pkg/net/tcpsock.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Go Authors. All rights reserved. 1 // Copyright 2012 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 "reflect"
8 "runtime" 9 "runtime"
9 "testing" 10 "testing"
10 "time" 11 "time"
11 ) 12 )
12 13
13 func BenchmarkTCPOneShot(b *testing.B) { 14 func BenchmarkTCPOneShot(b *testing.B) {
14 benchmarkTCP(b, false, false) 15 benchmarkTCP(b, false, false)
15 } 16 }
16 17
17 func BenchmarkTCPOneShotTimeout(b *testing.B) { 18 func BenchmarkTCPOneShotTimeout(b *testing.B) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 if !sendMsg(c, buf[:]) || !recvMsg(c, buf[:]) { 110 if !sendMsg(c, buf[:]) || !recvMsg(c, buf[:]) {
110 break 111 break
111 } 112 }
112 } 113 }
113 }() 114 }()
114 } 115 }
115 for i := 0; i < cap(sem); i++ { 116 for i := 0; i < cap(sem); i++ {
116 sem <- true 117 sem <- true
117 } 118 }
118 } 119 }
120
121 var resolveTCPAddrTests = []struct {
122 net string
123 litAddr string
124 addr *TCPAddr
125 }{
126 {"tcp", "127.0.0.1:1", &TCPAddr{IP: IPv4(127, 0, 0, 1), Port: 1}},
127 {"tcp4", "127.0.0.1:65535", &TCPAddr{IP: IPv4(127, 0, 0, 1), Port: 65535 }},
128
129 {"tcp", "[::1]:0", &TCPAddr{IP: ParseIP("::1"), Port: 0}},
130 {"tcp", "[::1%1]:1", &TCPAddr{IP: ParseIP("::1"), Port: 1, zoneId: 1}},
131 {"tcp6", "[::1]:2", &TCPAddr{IP: ParseIP("::1"), Port: 2}},
132 {"tcp6", "[::1%2]:3", &TCPAddr{IP: ParseIP("::1"), Port: 3, zoneId: 2}},
133 {"tcp6", "[::1]:4", &TCPAddr{IP: ParseIP("::1"), Port: 4, zoneId: -1}},
134 }
135
136 func TestResolveTCPAddr(t *testing.T) {
137 for _, tt := range resolveTCPAddrTests {
138 if tt.addr.zoneId == -1 {
139 ifi := loopbackInterface()
140 if ifi == nil {
141 continue
142 }
143 i := last(tt.litAddr, ']')
144 if i > 0 {
145 tt.litAddr = tt.litAddr[:i] + "%" + ifi.Name + t t.litAddr[i:]
146 tt.addr.zoneId = ifi.Index
147 }
148 }
149 addr, err := ResolveTCPAddr(tt.net, tt.litAddr)
150 if err != nil {
151 t.Fatalf("ResolveTCPAddr(%v, %v) failed: %v", tt.net, tt .litAddr, err)
152 }
153 if !reflect.DeepEqual(addr, tt.addr) {
154 t.Fatalf("got %#v; expected %#v", addr, tt.addr)
155 }
156 }
157 }
OLDNEW
« no previous file with comments | « src/pkg/net/multicast_posix_test.go ('k') | src/pkg/net/tcpsock.go » ('j') | no next file with comments »

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