LEFT | RIGHT |
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 // This file implements API tests across platforms and will never have a build | 5 // This file implements API tests across platforms and will never have a build |
6 // tag. | 6 // tag. |
7 | 7 |
8 package net | 8 package net |
9 | 9 |
10 import ( | 10 import ( |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 154 } |
155 if _, _, _, _, err := c.ReadMsgUDP(rb, nil); err != nil { | 155 if _, _, _, _, err := c.ReadMsgUDP(rb, nil); err != nil { |
156 condFatalf(t, "UDPConn.ReadMsgUDP failed: %v", err) | 156 condFatalf(t, "UDPConn.ReadMsgUDP failed: %v", err) |
157 } | 157 } |
158 | 158 |
159 if f, err := c.File(); err != nil { | 159 if f, err := c.File(); err != nil { |
160 condFatalf(t, "UDPConn.File failed: %v", err) | 160 condFatalf(t, "UDPConn.File failed: %v", err) |
161 } else { | 161 } else { |
162 f.Close() | 162 f.Close() |
163 } | 163 } |
| 164 |
| 165 defer func() { |
| 166 if p := recover(); p != nil { |
| 167 t.Fatalf("UDPConn.WriteToUDP or WriteMsgUDP panicked: %v
", p) |
| 168 } |
| 169 }() |
| 170 |
| 171 c.WriteToUDP(wb, nil) |
| 172 c.WriteMsgUDP(wb, nil, nil) |
164 } | 173 } |
165 | 174 |
166 func TestIPConnSpecificMethods(t *testing.T) { | 175 func TestIPConnSpecificMethods(t *testing.T) { |
167 switch runtime.GOOS { | 176 switch runtime.GOOS { |
168 case "plan9": | 177 case "plan9": |
169 t.Skipf("skipping test on %q", runtime.GOOS) | 178 t.Skipf("skipping test on %q", runtime.GOOS) |
| 179 case "windows": |
170 default: | 180 default: |
171 » » if !*testRawIP { | 181 » » if os.Getuid() != 0 { |
172 » » » t.Skip("test disabled; use -rawip to enable") | 182 » » » t.Skipf("skipping test; must be root") |
173 } | 183 } |
174 } | 184 } |
175 | 185 |
176 la, err := ResolveIPAddr("ip4", "127.0.0.1") | 186 la, err := ResolveIPAddr("ip4", "127.0.0.1") |
177 if err != nil { | 187 if err != nil { |
178 t.Fatalf("ResolveIPAddr failed: %v", err) | 188 t.Fatalf("ResolveIPAddr failed: %v", err) |
179 } | 189 } |
180 c, err := ListenIP("ip4:icmp", la) | 190 c, err := ListenIP("ip4:icmp", la) |
181 if err != nil { | 191 if err != nil { |
182 t.Fatalf("ListenIP failed: %v", err) | 192 t.Fatalf("ListenIP failed: %v", err) |
(...skipping 10 matching lines...) Expand all Loading... |
193 wb, err := (&icmpMessage{ | 203 wb, err := (&icmpMessage{ |
194 Type: icmpv4EchoRequest, Code: 0, | 204 Type: icmpv4EchoRequest, Code: 0, |
195 Body: &icmpEcho{ | 205 Body: &icmpEcho{ |
196 ID: os.Getpid() & 0xffff, Seq: 1, | 206 ID: os.Getpid() & 0xffff, Seq: 1, |
197 Data: []byte("IPCONN TEST "), | 207 Data: []byte("IPCONN TEST "), |
198 }, | 208 }, |
199 }).Marshal() | 209 }).Marshal() |
200 if err != nil { | 210 if err != nil { |
201 t.Fatalf("icmpMessage.Marshal failed: %v", err) | 211 t.Fatalf("icmpMessage.Marshal failed: %v", err) |
202 } | 212 } |
203 » rb := make([]byte, 20+128) | 213 » rb := make([]byte, 20+len(wb)) |
204 if _, err := c.WriteToIP(wb, c.LocalAddr().(*IPAddr)); err != nil { | 214 if _, err := c.WriteToIP(wb, c.LocalAddr().(*IPAddr)); err != nil { |
205 t.Fatalf("IPConn.WriteToIP failed: %v", err) | 215 t.Fatalf("IPConn.WriteToIP failed: %v", err) |
206 } | 216 } |
207 if _, _, err := c.ReadFromIP(rb); err != nil { | 217 if _, _, err := c.ReadFromIP(rb); err != nil { |
208 t.Fatalf("IPConn.ReadFromIP failed: %v", err) | 218 t.Fatalf("IPConn.ReadFromIP failed: %v", err) |
209 } | 219 } |
210 if _, _, err := c.WriteMsgIP(wb, nil, c.LocalAddr().(*IPAddr)); err != n
il { | 220 if _, _, err := c.WriteMsgIP(wb, nil, c.LocalAddr().(*IPAddr)); err != n
il { |
211 condFatalf(t, "IPConn.WriteMsgIP failed: %v", err) | 221 condFatalf(t, "IPConn.WriteMsgIP failed: %v", err) |
212 } | 222 } |
213 if _, _, _, _, err := c.ReadMsgIP(rb, nil); err != nil { | 223 if _, _, _, _, err := c.ReadMsgIP(rb, nil); err != nil { |
214 condFatalf(t, "IPConn.ReadMsgIP failed: %v", err) | 224 condFatalf(t, "IPConn.ReadMsgIP failed: %v", err) |
215 } | 225 } |
216 | 226 |
217 if f, err := c.File(); err != nil { | 227 if f, err := c.File(); err != nil { |
218 condFatalf(t, "IPConn.File failed: %v", err) | 228 condFatalf(t, "IPConn.File failed: %v", err) |
219 } else { | 229 } else { |
220 f.Close() | 230 f.Close() |
221 } | 231 } |
| 232 |
| 233 defer func() { |
| 234 if p := recover(); p != nil { |
| 235 t.Fatalf("IPConn.WriteToIP or WriteMsgIP panicked: %v",
p) |
| 236 } |
| 237 }() |
| 238 |
| 239 c.WriteToIP(wb, nil) |
| 240 c.WriteMsgIP(wb, nil, nil) |
222 } | 241 } |
223 | 242 |
224 func TestUnixListenerSpecificMethods(t *testing.T) { | 243 func TestUnixListenerSpecificMethods(t *testing.T) { |
225 switch runtime.GOOS { | 244 switch runtime.GOOS { |
226 case "plan9", "windows": | 245 case "plan9", "windows": |
227 t.Skipf("skipping test on %q", runtime.GOOS) | 246 t.Skipf("skipping test on %q", runtime.GOOS) |
228 } | 247 } |
229 | 248 |
230 addr := testUnixAddr() | 249 addr := testUnixAddr() |
231 la, err := ResolveUnixAddr("unix", addr) | 250 la, err := ResolveUnixAddr("unix", addr) |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 } | 371 } |
353 if _, _, err := c3.ReadFromUnix(rb3); err != nil { | 372 if _, _, err := c3.ReadFromUnix(rb3); err != nil { |
354 t.Fatalf("UnixConn.ReadFromUnix failed: %v", err) | 373 t.Fatalf("UnixConn.ReadFromUnix failed: %v", err) |
355 } | 374 } |
356 | 375 |
357 if f, err := c1.File(); err != nil { | 376 if f, err := c1.File(); err != nil { |
358 t.Fatalf("UnixConn.File failed: %v", err) | 377 t.Fatalf("UnixConn.File failed: %v", err) |
359 } else { | 378 } else { |
360 f.Close() | 379 f.Close() |
361 } | 380 } |
362 } | 381 |
| 382 » defer func() { |
| 383 » » if p := recover(); p != nil { |
| 384 » » » t.Fatalf("UnixConn.WriteToUnix or WriteMsgUnix panicked:
%v", p) |
| 385 » » } |
| 386 » }() |
| 387 |
| 388 » c1.WriteToUnix(wb, nil) |
| 389 » c1.WriteMsgUnix(wb, nil, nil) |
| 390 » c3.WriteToUnix(wb, nil) |
| 391 » c3.WriteMsgUnix(wb, nil, nil) |
| 392 } |
LEFT | RIGHT |