...
1
2
3
4
5
6
7 package socktest_test
8
9 import (
10 "net/internal/socktest"
11 "os"
12 "sync"
13 "syscall"
14 "testing"
15 )
16
17 var sw socktest.Switch
18
19 func TestMain(m *testing.M) {
20 installTestHooks()
21
22 st := m.Run()
23
24 for s := range sw.Sockets() {
25 closeFunc(s)
26 }
27 uninstallTestHooks()
28 os.Exit(st)
29 }
30
31 func TestSwitch(t *testing.T) {
32 const N = 10
33 var wg sync.WaitGroup
34 wg.Add(N)
35 for i := 0; i < N; i++ {
36 go func() {
37 defer wg.Done()
38 for _, family := range []int{syscall.AF_INET, syscall.AF_INET6} {
39 socketFunc(family, syscall.SOCK_STREAM, syscall.IPPROTO_TCP)
40 }
41 }()
42 }
43 wg.Wait()
44 }
45
46 func TestSocket(t *testing.T) {
47 for _, f := range []socktest.Filter{
48 func(st *socktest.Status) (socktest.AfterFilter, error) { return nil, nil },
49 nil,
50 } {
51 sw.Set(socktest.FilterSocket, f)
52 for _, family := range []int{syscall.AF_INET, syscall.AF_INET6} {
53 socketFunc(family, syscall.SOCK_STREAM, syscall.IPPROTO_TCP)
54 }
55 }
56 }
57
View as plain text