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

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

Issue 6497044: code review 6497044: net: delete unused IP-level socket option helpers (Closed)
Patch Set: diff -r dbcfb4459ab8 https://code.google.com/p/go Created 11 years, 6 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 | src/pkg/net/sockoptip_bsd.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 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 // +build !plan9 5 // +build !plan9
6 6
7 package net 7 package net
8 8
9 import ( 9 import (
10 "errors" 10 "errors"
11 "os" 11 "os"
12 "runtime" 12 "runtime"
13 "syscall"
14 "testing" 13 "testing"
15 ) 14 )
16 15
17 var multicastListenerTests = []struct { 16 var multicastListenerTests = []struct {
18 net string 17 net string
19 gaddr *UDPAddr 18 gaddr *UDPAddr
20 flags Flags 19 flags Flags
21 ipv6 bool // test with underlying AF_INET6 socket 20 ipv6 bool // test with underlying AF_INET6 socket
22 }{ 21 }{
23 // cf. RFC 4727: Experimental Values in IPv4, IPv6, ICMPv4, ICMPv6, UDP, and TCP Headers 22 // cf. RFC 4727: Experimental Values in IPv4, IPv6, ICMPv4, ICMPv6, UDP, and TCP Headers
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 if err != nil { 69 if err != nil {
71 t.Fatalf("First ListenMulticastUDP failed: %v", err) 70 t.Fatalf("First ListenMulticastUDP failed: %v", err)
72 } 71 }
73 checkMulticastListener(t, err, c1, tt.gaddr) 72 checkMulticastListener(t, err, c1, tt.gaddr)
74 c2, err := ListenMulticastUDP(tt.net, ifi, tt.gaddr) 73 c2, err := ListenMulticastUDP(tt.net, ifi, tt.gaddr)
75 if err != nil { 74 if err != nil {
76 t.Fatalf("Second ListenMulticastUDP failed: %v", err) 75 t.Fatalf("Second ListenMulticastUDP failed: %v", err)
77 } 76 }
78 checkMulticastListener(t, err, c2, tt.gaddr) 77 checkMulticastListener(t, err, c2, tt.gaddr)
79 c2.Close() 78 c2.Close()
80 switch c1.fd.family {
81 case syscall.AF_INET:
82 testIPv4MulticastSocketOptions(t, c1.fd, ifi)
83 case syscall.AF_INET6:
84 testIPv6MulticastSocketOptions(t, c1.fd, ifi)
85 }
86 c1.Close() 79 c1.Close()
87 } 80 }
88 } 81 }
89 82
90 func TestSimpleMulticastListener(t *testing.T) { 83 func TestSimpleMulticastListener(t *testing.T) {
91 switch runtime.GOOS { 84 switch runtime.GOOS {
92 case "plan9": 85 case "plan9":
93 t.Logf("skipping test on %q", runtime.GOOS) 86 t.Logf("skipping test on %q", runtime.GOOS)
94 return 87 return
95 case "windows": 88 case "windows":
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 t.Fatalf("MulticastAddrs failed: %v", err) 162 t.Fatalf("MulticastAddrs failed: %v", err)
170 } 163 }
171 for _, ifma := range ifmat { 164 for _, ifma := range ifmat {
172 if ifma.(*IPAddr).IP.Equal(ip) { 165 if ifma.(*IPAddr).IP.Equal(ip) {
173 return true 166 return true
174 } 167 }
175 } 168 }
176 } 169 }
177 return false 170 return false
178 } 171 }
179
180 func testIPv4MulticastSocketOptions(t *testing.T, fd *netFD, ifi *Interface) {
181 _, err := ipv4MulticastInterface(fd)
182 if err != nil {
183 t.Fatalf("ipv4MulticastInterface failed: %v", err)
184 }
185 if ifi != nil {
186 err = setIPv4MulticastInterface(fd, ifi)
187 if err != nil {
188 t.Fatalf("setIPv4MulticastInterface failed: %v", err)
189 }
190 }
191 _, err = ipv4MulticastTTL(fd)
192 if err != nil {
193 t.Fatalf("ipv4MulticastTTL failed: %v", err)
194 }
195 err = setIPv4MulticastTTL(fd, 1)
196 if err != nil {
197 t.Fatalf("setIPv4MulticastTTL failed: %v", err)
198 }
199 _, err = ipv4MulticastLoopback(fd)
200 if err != nil {
201 t.Fatalf("ipv4MulticastLoopback failed: %v", err)
202 }
203 err = setIPv4MulticastLoopback(fd, false)
204 if err != nil {
205 t.Fatalf("setIPv4MulticastLoopback failed: %v", err)
206 }
207 }
208
209 func testIPv6MulticastSocketOptions(t *testing.T, fd *netFD, ifi *Interface) {
210 _, err := ipv6MulticastInterface(fd)
211 if err != nil {
212 t.Fatalf("ipv6MulticastInterface failed: %v", err)
213 }
214 if ifi != nil {
215 err = setIPv6MulticastInterface(fd, ifi)
216 if err != nil {
217 t.Fatalf("setIPv6MulticastInterface failed: %v", err)
218 }
219 }
220 _, err = ipv6MulticastHopLimit(fd)
221 if err != nil {
222 t.Fatalf("ipv6MulticastHopLimit failed: %v", err)
223 }
224 err = setIPv6MulticastHopLimit(fd, 1)
225 if err != nil {
226 t.Fatalf("setIPv6MulticastHopLimit failed: %v", err)
227 }
228 _, err = ipv6MulticastLoopback(fd)
229 if err != nil {
230 t.Fatalf("ipv6MulticastLoopback failed: %v", err)
231 }
232 err = setIPv6MulticastLoopback(fd, false)
233 if err != nil {
234 t.Fatalf("setIPv6MulticastLoopback failed: %v", err)
235 }
236 }
OLDNEW
« no previous file with comments | « no previous file | src/pkg/net/sockoptip_bsd.go » ('j') | no next file with comments »

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