OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [net/] [multicast_test.go] - Blame information for rev 833

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// 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.
4
 
5
package net
6
 
7
import (
8
        "os"
9
        "runtime"
10
        "testing"
11
)
12
 
13
var listenMulticastUDPTests = []struct {
14
        net   string
15
        gaddr *UDPAddr
16
        flags Flags
17
        ipv6  bool
18
}{
19
        // cf. RFC 4727: Experimental Values in IPv4, IPv6, ICMPv4, ICMPv6, UDP, and TCP Headers
20
        {"udp", &UDPAddr{IPv4(224, 0, 0, 254), 12345}, FlagUp | FlagLoopback, false},
21
        {"udp4", &UDPAddr{IPv4(224, 0, 0, 254), 12345}, FlagUp | FlagLoopback, false},
22
        {"udp", &UDPAddr{ParseIP("ff0e::114"), 12345}, FlagUp | FlagLoopback, true},
23
        {"udp6", &UDPAddr{ParseIP("ff01::114"), 12345}, FlagUp | FlagLoopback, true},
24
        {"udp6", &UDPAddr{ParseIP("ff02::114"), 12345}, FlagUp | FlagLoopback, true},
25
        {"udp6", &UDPAddr{ParseIP("ff04::114"), 12345}, FlagUp | FlagLoopback, true},
26
        {"udp6", &UDPAddr{ParseIP("ff05::114"), 12345}, FlagUp | FlagLoopback, true},
27
        {"udp6", &UDPAddr{ParseIP("ff08::114"), 12345}, FlagUp | FlagLoopback, true},
28
        {"udp6", &UDPAddr{ParseIP("ff0e::114"), 12345}, FlagUp | FlagLoopback, true},
29
}
30
 
31
func TestListenMulticastUDP(t *testing.T) {
32
        switch runtime.GOOS {
33
        case "netbsd", "openbsd", "plan9", "windows":
34
                return
35
        case "linux":
36
                if runtime.GOARCH == "arm" || runtime.GOARCH == "alpha" {
37
                        return
38
                }
39
        }
40
 
41
        for _, tt := range listenMulticastUDPTests {
42
                if tt.ipv6 && (!supportsIPv6 || os.Getuid() != 0) {
43
                        continue
44
                }
45
                ift, err := Interfaces()
46
                if err != nil {
47
                        t.Fatalf("Interfaces failed: %v", err)
48
                }
49
                var ifi *Interface
50
                for _, x := range ift {
51
                        if x.Flags&tt.flags == tt.flags {
52
                                ifi = &x
53
                                break
54
                        }
55
                }
56
                if ifi == nil {
57
                        t.Logf("an appropriate multicast interface not found")
58
                        return
59
                }
60
                c, err := ListenMulticastUDP(tt.net, ifi, tt.gaddr)
61
                if err != nil {
62
                        t.Fatalf("ListenMulticastUDP failed: %v", err)
63
                }
64
                defer c.Close() // test to listen concurrently across multiple listeners
65
                if !tt.ipv6 {
66
                        testIPv4MulticastSocketOptions(t, c.fd, ifi)
67
                } else {
68
                        testIPv6MulticastSocketOptions(t, c.fd, ifi)
69
                }
70
                ifmat, err := ifi.MulticastAddrs()
71
                if err != nil {
72
                        t.Fatalf("MulticastAddrs failed: %v", err)
73
                }
74
                var found bool
75
                for _, ifma := range ifmat {
76
                        if ifma.(*IPAddr).IP.Equal(tt.gaddr.IP) {
77
                                found = true
78
                                break
79
                        }
80
                }
81
                if !found {
82
                        t.Fatalf("%q not found in RIB", tt.gaddr.String())
83
                }
84
        }
85
}
86
 
87
func TestSimpleListenMulticastUDP(t *testing.T) {
88
        switch runtime.GOOS {
89
        case "plan9":
90
                return
91
        }
92
 
93
        for _, tt := range listenMulticastUDPTests {
94
                if tt.ipv6 {
95
                        continue
96
                }
97
                tt.flags = FlagUp | FlagMulticast
98
                ift, err := Interfaces()
99
                if err != nil {
100
                        t.Fatalf("Interfaces failed: %v", err)
101
                }
102
                var ifi *Interface
103
                for _, x := range ift {
104
                        if x.Flags&tt.flags == tt.flags {
105
                                ifi = &x
106
                                break
107
                        }
108
                }
109
                if ifi == nil {
110
                        t.Logf("an appropriate multicast interface not found")
111
                        return
112
                }
113
                c, err := ListenMulticastUDP(tt.net, ifi, tt.gaddr)
114
                if err != nil {
115
                        t.Fatalf("ListenMulticastUDP failed: %v", err)
116
                }
117
                c.Close()
118
        }
119
}
120
 
121
func testIPv4MulticastSocketOptions(t *testing.T, fd *netFD, ifi *Interface) {
122
        ifmc, err := ipv4MulticastInterface(fd)
123
        if err != nil {
124
                t.Fatalf("ipv4MulticastInterface failed: %v", err)
125
        }
126
        t.Logf("IPv4 multicast interface: %v", ifmc)
127
        err = setIPv4MulticastInterface(fd, ifi)
128
        if err != nil {
129
                t.Fatalf("setIPv4MulticastInterface failed: %v", err)
130
        }
131
 
132
        ttl, err := ipv4MulticastTTL(fd)
133
        if err != nil {
134
                t.Fatalf("ipv4MulticastTTL failed: %v", err)
135
        }
136
        t.Logf("IPv4 multicast TTL: %v", ttl)
137
        err = setIPv4MulticastTTL(fd, 1)
138
        if err != nil {
139
                t.Fatalf("setIPv4MulticastTTL failed: %v", err)
140
        }
141
 
142
        loop, err := ipv4MulticastLoopback(fd)
143
        if err != nil {
144
                t.Fatalf("ipv4MulticastLoopback failed: %v", err)
145
        }
146
        t.Logf("IPv4 multicast loopback: %v", loop)
147
        err = setIPv4MulticastLoopback(fd, false)
148
        if err != nil {
149
                t.Fatalf("setIPv4MulticastLoopback failed: %v", err)
150
        }
151
}
152
 
153
func testIPv6MulticastSocketOptions(t *testing.T, fd *netFD, ifi *Interface) {
154
        ifmc, err := ipv6MulticastInterface(fd)
155
        if err != nil {
156
                t.Fatalf("ipv6MulticastInterface failed: %v", err)
157
        }
158
        t.Logf("IPv6 multicast interface: %v", ifmc)
159
        err = setIPv6MulticastInterface(fd, ifi)
160
        if err != nil {
161
                t.Fatalf("setIPv6MulticastInterface failed: %v", err)
162
        }
163
 
164
        hoplim, err := ipv6MulticastHopLimit(fd)
165
        if err != nil {
166
                t.Fatalf("ipv6MulticastHopLimit failed: %v", err)
167
        }
168
        t.Logf("IPv6 multicast hop limit: %v", hoplim)
169
        err = setIPv6MulticastHopLimit(fd, 1)
170
        if err != nil {
171
                t.Fatalf("setIPv6MulticastHopLimit failed: %v", err)
172
        }
173
 
174
        loop, err := ipv6MulticastLoopback(fd)
175
        if err != nil {
176
                t.Fatalf("ipv6MulticastLoopback failed: %v", err)
177
        }
178
        t.Logf("IPv6 multicast loopback: %v", loop)
179
        err = setIPv6MulticastLoopback(fd, false)
180
        if err != nil {
181
                t.Fatalf("setIPv6MulticastLoopback failed: %v", err)
182
        }
183
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.