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 // +build darwin freebsd linux netbsd openbsd | 5 // +build darwin freebsd linux netbsd openbsd |
6 | 6 |
7 package net | 7 package net |
8 | 8 |
9 import ( | 9 import ( |
10 "io" | 10 "io" |
11 "syscall" | 11 "syscall" |
12 "testing" | 12 "testing" |
| 13 "unsafe" |
13 ) | 14 ) |
14 | 15 |
15 // Issue 3590. netFd.AddFD should return an error | 16 // Issue 3590. netFd.AddFD should return an error |
16 // from the underlying pollster rather than panicing. | 17 // from the underlying pollster rather than panicing. |
17 func TestAddFDReturnsError(t *testing.T) { | 18 func TestAddFDReturnsError(t *testing.T) { |
18 ln := newLocalListener(t).(*TCPListener) | 19 ln := newLocalListener(t).(*TCPListener) |
19 defer ln.Close() | 20 defer ln.Close() |
20 connected := make(chan bool) | 21 connected := make(chan bool) |
21 go func() { | 22 go func() { |
22 for { | 23 for { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 98 } |
98 | 99 |
99 func TestChkReadErr(t *testing.T) { | 100 func TestChkReadErr(t *testing.T) { |
100 for _, tt := range chkReadErrTests { | 101 for _, tt := range chkReadErrTests { |
101 actual := chkReadErr(tt.n, tt.err, tt.fd) | 102 actual := chkReadErr(tt.n, tt.err, tt.fd) |
102 if actual != tt.expected { | 103 if actual != tt.expected { |
103 t.Errorf("chkReadError(%v, %v, %v): expected %v, actual
%v", tt.n, tt.err, tt.fd.sotype, tt.expected, actual) | 104 t.Errorf("chkReadError(%v, %v, %v): expected %v, actual
%v", tt.n, tt.err, tt.fd.sotype, tt.expected, actual) |
104 } | 105 } |
105 } | 106 } |
106 } | 107 } |
| 108 |
| 109 // see comment in fd_unix.go |
| 110 func TestDeadlineFieldAlignment(t *testing.T) { |
| 111 var fd netFD |
| 112 if size := unsafe.Sizeof(fd) % 8; size != 0 { |
| 113 t.Errorf("size of fd %% 8 is %d not 0", size) |
| 114 } |
| 115 if offset := unsafe.Offsetof(fd.rdeadline) % 8; offset != 0 { |
| 116 t.Errorf("offset of fd.rdeadline %% 8 is %d not 0", offset) |
| 117 } |
| 118 if offset := unsafe.Offsetof(fd.wdeadline) % 8; offset != 0 { |
| 119 t.Errorf("offset of fd.wdeadline %% 8 is %d not 0", offset) |
| 120 } |
| 121 } |
OLD | NEW |