~ubuntu-branches/ubuntu/saucy/juju-core/saucy-proposed

« back to all changes in this revision

Viewing changes to src/code.google.com/p/go.net/ipv6/unicastsockopt_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-07-11 17:18:27 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130711171827-vjqkg40r0dlf7ys2
Tags: 1.11.2-0ubuntu1
* New upstream release.
* Make juju-core the default juju (LP: #1190634):
  - d/control: Add virtual package juju -> juju-core.
  - d/juju-core.postinst.in: Bump priority of alternatives over that of
    python juju packages.
* Enable for all architectures (LP: #1172505):
  - d/control: Version BD on golang-go to >= 2:1.1.1 to ensure CGO
    support for non-x86 archs, make juju-core Arch: any.
  - d/README.source: Dropped - no longer required.
* d/watch: Updated for new upstream tarball naming.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 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 ipv6_test
 
6
 
 
7
import (
 
8
        "code.google.com/p/go.net/ipv6"
 
9
        "net"
 
10
        "os"
 
11
        "runtime"
 
12
        "testing"
 
13
)
 
14
 
 
15
func TestConnUnicastSocketOptions(t *testing.T) {
 
16
        switch runtime.GOOS {
 
17
        case "plan9", "windows":
 
18
                t.Skipf("not supported on %q", runtime.GOOS)
 
19
        }
 
20
        if !supportsIPv6 {
 
21
                t.Skip("ipv6 is not supported")
 
22
        }
 
23
 
 
24
        ln, err := net.Listen("tcp6", "[::1]:0")
 
25
        if err != nil {
 
26
                t.Fatalf("net.Listen failed: %v", err)
 
27
        }
 
28
        defer ln.Close()
 
29
 
 
30
        done := make(chan bool)
 
31
        go acceptor(t, ln, done)
 
32
 
 
33
        c, err := net.Dial("tcp6", ln.Addr().String())
 
34
        if err != nil {
 
35
                t.Fatalf("net.Dial failed: %v", err)
 
36
        }
 
37
        defer c.Close()
 
38
 
 
39
        testUnicastSocketOptions(t, ipv6.NewConn(c))
 
40
 
 
41
        <-done
 
42
}
 
43
 
 
44
var packetConnUnicastSocketOptionTests = []struct {
 
45
        net, proto, addr string
 
46
}{
 
47
        {"udp6", "", "[::1]:0"},
 
48
        {"ip6", ":ipv6-icmp", "::1"},
 
49
}
 
50
 
 
51
func TestPacketConnUnicastSocketOptions(t *testing.T) {
 
52
        switch runtime.GOOS {
 
53
        case "plan9", "windows":
 
54
                t.Skipf("not supported on %q", runtime.GOOS)
 
55
        }
 
56
        if !supportsIPv6 {
 
57
                t.Skip("ipv6 is not supported")
 
58
        }
 
59
 
 
60
        for _, tt := range packetConnUnicastSocketOptionTests {
 
61
                if tt.net == "ip6" && os.Getuid() != 0 {
 
62
                        t.Skip("must be root")
 
63
                }
 
64
                c, err := net.ListenPacket(tt.net+tt.proto, tt.addr)
 
65
                if err != nil {
 
66
                        t.Fatalf("net.ListenPacket(%q, %q) failed: %v", tt.net+tt.proto, tt.addr, err)
 
67
                }
 
68
                defer c.Close()
 
69
 
 
70
                testUnicastSocketOptions(t, ipv6.NewPacketConn(c))
 
71
        }
 
72
}
 
73
 
 
74
type testIPv6UnicastConn interface {
 
75
        TrafficClass() (int, error)
 
76
        SetTrafficClass(int) error
 
77
        HopLimit() (int, error)
 
78
        SetHopLimit(int) error
 
79
}
 
80
 
 
81
func testUnicastSocketOptions(t *testing.T, c testIPv6UnicastConn) {
 
82
        tclass := DiffServCS0 | NotECNTransport
 
83
        if err := c.SetTrafficClass(tclass); err != nil {
 
84
                t.Fatalf("ipv6.Conn.SetTrafficClass failed: %v", err)
 
85
        }
 
86
        if v, err := c.TrafficClass(); err != nil {
 
87
                t.Fatalf("ipv6.Conn.TrafficClass failed: %v", err)
 
88
        } else if v != tclass {
 
89
                t.Fatalf("got unexpected traffic class %v; expected %v", v, tclass)
 
90
        }
 
91
 
 
92
        hoplim := 255
 
93
        if err := c.SetHopLimit(hoplim); err != nil {
 
94
                t.Fatalf("ipv6.Conn.SetHopLimit failed: %v", err)
 
95
        }
 
96
        if v, err := c.HopLimit(); err != nil {
 
97
                t.Fatalf("ipv6.Conn.HopLimit failed: %v", err)
 
98
        } else if v != hoplim {
 
99
                t.Fatalf("got unexpected hop limit %v; expected %v", v, hoplim)
 
100
        }
 
101
}