OLD | NEW |
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 ( |
11 "os" | 11 "os" |
12 "runtime" | 12 "runtime" |
13 "strings" | 13 "strings" |
14 "testing" | 14 "testing" |
15 "time" | 15 "time" |
16 ) | 16 ) |
17 | 17 |
18 func strfunc(s string) func() string { | 18 func strfunc(s string) func() string { |
19 return func() string { | 19 return func() string { |
20 return s | 20 return s |
21 } | 21 } |
22 } | 22 } |
23 | 23 |
24 func packetConnTestData(t *testing.T, net string, i int) ([]byte, func()) { | 24 func packetConnTestData(t *testing.T, net string, i int) ([]byte, func()) { |
25 switch net { | 25 switch net { |
26 case "udp": | 26 case "udp": |
27 return []byte("UDP PACKETCONN TEST"), nil | 27 return []byte("UDP PACKETCONN TEST"), nil |
28 case "ip": | 28 case "ip": |
29 » » switch runtime.GOOS { | 29 » » if skip, skipmsg := skipRawSocketTest(t); skip { |
30 » » case "plan9": | |
31 return nil, func() { | 30 return nil, func() { |
32 » » » » t.Logf("skipping %q test on %q", net, runtime.GO
OS) | 31 » » » » t.Logf(skipmsg) |
33 » » » } | |
34 » » case "windows": | |
35 » » » if testing.Short() || !*testExternal { | |
36 » » » » t.Skipf("skipping test on %q to avoid network fi
rewall", runtime.GOOS) | |
37 » » » } | |
38 » » default: | |
39 » » » if os.Getuid() != 0 { | |
40 » » » » return nil, func() { | |
41 » » » » » t.Logf("skipping %q test; must be root",
net) | |
42 » » » » } | |
43 } | 32 } |
44 } | 33 } |
45 b, err := (&icmpMessage{ | 34 b, err := (&icmpMessage{ |
46 Type: icmpv4EchoRequest, Code: 0, | 35 Type: icmpv4EchoRequest, Code: 0, |
47 Body: &icmpEcho{ | 36 Body: &icmpEcho{ |
48 ID: os.Getpid() & 0xffff, Seq: i + 1, | 37 ID: os.Getpid() & 0xffff, Seq: i + 1, |
49 Data: []byte("IP PACKETCONN TEST"), | 38 Data: []byte("IP PACKETCONN TEST"), |
50 }, | 39 }, |
51 }).Marshal() | 40 }).Marshal() |
52 if err != nil { | 41 if err != nil { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } | 185 } |
197 if _, err := c1.WriteTo(wb, dst); err != nil { | 186 if _, err := c1.WriteTo(wb, dst); err != nil { |
198 t.Fatalf("PacketConn.WriteTo failed: %v", err) | 187 t.Fatalf("PacketConn.WriteTo failed: %v", err) |
199 } | 188 } |
200 rb2 := make([]byte, 128) | 189 rb2 := make([]byte, 128) |
201 if _, err := c2.Read(rb2); err != nil { | 190 if _, err := c2.Read(rb2); err != nil { |
202 t.Fatalf("Conn.Read failed: %v", err) | 191 t.Fatalf("Conn.Read failed: %v", err) |
203 } | 192 } |
204 } | 193 } |
205 } | 194 } |
OLD | NEW |