1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
17 // The full stack test cases for IPConn have been moved to the
19 // golang.org/x/net/ipv4
20 // golang.org/x/net/ipv6
21 // golang.org/x/net/icmp
23 var fileConnTests
= []struct {
32 func TestFileConn(t
*testing
.T
) {
34 case "plan9", "windows":
35 t
.Skipf("not supported on %s", runtime
.GOOS
)
38 for _
, tt
:= range fileConnTests
{
39 if !testableNetwork(tt
.network
) {
40 t
.Logf("skipping %s test", tt
.network
)
44 var network
, address
string
47 c
:= newLocalPacketListener(t
, tt
.network
)
49 network
= c
.LocalAddr().Network()
50 address
= c
.LocalAddr().String()
52 handler
:= func(ls
*localServer
, ln Listener
) {
61 ls
:= newLocalServer(t
, tt
.network
)
63 if err
:= ls
.buildup(handler
); err
!= nil {
66 network
= ls
.Listener
.Addr().Network()
67 address
= ls
.Listener
.Addr().String()
70 c1
, err
:= Dial(network
, address
)
72 if perr
:= parseDialError(err
); perr
!= nil {
77 addr
:= c1
.LocalAddr()
80 switch c1
:= c1
.(type) {
88 if err
:= c1
.Close(); err
!= nil {
89 if perr
:= parseCloseError(err
, false); perr
!= nil {
95 if perr
:= parseCommonError(err
); perr
!= nil {
101 c2
, err
:= FileConn(f
)
102 if err
:= f
.Close(); err
!= nil {
106 if perr
:= parseCommonError(err
); perr
!= nil {
113 if _
, err
:= c2
.Write([]byte("FILECONN TEST")); err
!= nil {
114 if perr
:= parseWriteError(err
); perr
!= nil {
119 if !reflect
.DeepEqual(c2
.LocalAddr(), addr
) {
120 t
.Fatalf("got %#v; want %#v", c2
.LocalAddr(), addr
)
125 var fileListenerTests
= []struct {
133 func TestFileListener(t
*testing
.T
) {
134 switch runtime
.GOOS
{
135 case "plan9", "windows":
136 t
.Skipf("not supported on %s", runtime
.GOOS
)
139 for _
, tt
:= range fileListenerTests
{
140 if !testableNetwork(tt
.network
) {
141 t
.Logf("skipping %s test", tt
.network
)
145 ln1
:= newLocalListener(t
, tt
.network
)
147 case "unix", "unixpacket":
148 defer os
.Remove(ln1
.Addr().String())
156 switch ln1
:= ln1
.(type) {
163 case "unix", "unixpacket":
164 defer ln1
.Close() // UnixListener.Close calls syscall.Unlink internally
166 if err
:= ln1
.Close(); err
!= nil {
171 if perr
:= parseCommonError(err
); perr
!= nil {
177 ln2
, err
:= FileListener(f
)
178 if err
:= f
.Close(); err
!= nil {
182 if perr
:= parseCommonError(err
); perr
!= nil {
189 var wg sync
.WaitGroup
193 c
, err
:= Dial(ln2
.Addr().Network(), ln2
.Addr().String())
195 if perr
:= parseDialError(err
); perr
!= nil {
203 c
, err
:= ln2
.Accept()
205 if perr
:= parseAcceptError(err
); perr
!= nil {
212 if !reflect
.DeepEqual(ln2
.Addr(), addr
) {
213 t
.Fatalf("got %#v; want %#v", ln2
.Addr(), addr
)
218 var filePacketConnTests
= []struct {
225 func TestFilePacketConn(t
*testing
.T
) {
226 switch runtime
.GOOS
{
227 case "plan9", "windows":
228 t
.Skipf("not supported on %s", runtime
.GOOS
)
231 for _
, tt
:= range filePacketConnTests
{
232 if !testableNetwork(tt
.network
) {
233 t
.Logf("skipping %s test", tt
.network
)
237 c1
:= newLocalPacketListener(t
, tt
.network
)
240 defer os
.Remove(c1
.LocalAddr().String())
242 addr
:= c1
.LocalAddr()
248 switch c1
:= c1
.(type) {
254 if err
:= c1
.Close(); err
!= nil {
255 if perr
:= parseCloseError(err
, false); perr
!= nil {
261 if perr
:= parseCommonError(err
); perr
!= nil {
267 c2
, err
:= FilePacketConn(f
)
268 if err
:= f
.Close(); err
!= nil {
272 if perr
:= parseCommonError(err
); perr
!= nil {
279 if _
, err
:= c2
.WriteTo([]byte("FILEPACKETCONN TEST"), addr
); err
!= nil {
280 if perr
:= parseWriteError(err
); perr
!= nil {
285 if !reflect
.DeepEqual(c2
.LocalAddr(), addr
) {
286 t
.Fatalf("got %#v; want %#v", c2
.LocalAddr(), addr
)
292 func TestFileCloseRace(t
*testing
.T
) {
293 switch runtime
.GOOS
{
294 case "plan9", "windows":
295 t
.Skipf("not supported on %s", runtime
.GOOS
)
297 if !testableNetwork("tcp") {
298 t
.Skip("tcp not supported")
301 handler
:= func(ls
*localServer
, ln Listener
) {
302 c
, err
:= ln
.Accept()
311 ls
:= newLocalServer(t
, "tcp")
313 if err
:= ls
.buildup(handler
); err
!= nil {
318 for i
:= 0; i
< tries
; i
++ {
319 c1
, err
:= Dial(ls
.Listener
.Addr().Network(), ls
.Listener
.Addr().String())
325 var wg sync
.WaitGroup