Fix "PR c++/92804 ICE trying to use concept as a nested-name-specifier"
[official-gcc.git] / libgo / go / net / interface_linux_test.go
blob0699fec636833f8fe36469012ebb569222e60c1b
1 // Copyright 2012 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.
5 package net
7 import (
8 "fmt"
9 "os/exec"
10 "testing"
13 func (ti *testInterface) setBroadcast(suffix int) error {
14 ti.name = fmt.Sprintf("gotest%d", suffix)
15 xname, err := exec.LookPath("ip")
16 if err != nil {
17 return err
19 ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
20 Path: xname,
21 Args: []string{"ip", "link", "add", ti.name, "type", "dummy"},
23 ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
24 Path: xname,
25 Args: []string{"ip", "address", "add", ti.local, "peer", ti.remote, "dev", ti.name},
27 ti.teardownCmds = append(ti.teardownCmds, &exec.Cmd{
28 Path: xname,
29 Args: []string{"ip", "address", "del", ti.local, "peer", ti.remote, "dev", ti.name},
31 ti.teardownCmds = append(ti.teardownCmds, &exec.Cmd{
32 Path: xname,
33 Args: []string{"ip", "link", "delete", ti.name, "type", "dummy"},
35 return nil
38 func (ti *testInterface) setLinkLocal(suffix int) error {
39 ti.name = fmt.Sprintf("gotest%d", suffix)
40 xname, err := exec.LookPath("ip")
41 if err != nil {
42 return err
44 ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
45 Path: xname,
46 Args: []string{"ip", "link", "add", ti.name, "type", "dummy"},
48 ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
49 Path: xname,
50 Args: []string{"ip", "address", "add", ti.local, "dev", ti.name},
52 ti.teardownCmds = append(ti.teardownCmds, &exec.Cmd{
53 Path: xname,
54 Args: []string{"ip", "address", "del", ti.local, "dev", ti.name},
56 ti.teardownCmds = append(ti.teardownCmds, &exec.Cmd{
57 Path: xname,
58 Args: []string{"ip", "link", "delete", ti.name, "type", "dummy"},
60 return nil
63 func (ti *testInterface) setPointToPoint(suffix int) error {
64 ti.name = fmt.Sprintf("gotest%d", suffix)
65 xname, err := exec.LookPath("ip")
66 if err != nil {
67 return err
69 ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
70 Path: xname,
71 Args: []string{"ip", "tunnel", "add", ti.name, "mode", "gre", "local", ti.local, "remote", ti.remote},
73 ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
74 Path: xname,
75 Args: []string{"ip", "address", "add", ti.local, "peer", ti.remote, "dev", ti.name},
77 ti.teardownCmds = append(ti.teardownCmds, &exec.Cmd{
78 Path: xname,
79 Args: []string{"ip", "address", "del", ti.local, "peer", ti.remote, "dev", ti.name},
81 ti.teardownCmds = append(ti.teardownCmds, &exec.Cmd{
82 Path: xname,
83 Args: []string{"ip", "tunnel", "del", ti.name, "mode", "gre", "local", ti.local, "remote", ti.remote},
85 return nil
88 const (
89 numOfTestIPv4MCAddrs = 14
90 numOfTestIPv6MCAddrs = 18
93 var (
94 igmpInterfaceTable = []Interface{
95 {Name: "lo"},
96 {Name: "eth0"}, {Name: "eth1"}, {Name: "eth2"},
97 {Name: "eth0.100"}, {Name: "eth0.101"}, {Name: "eth0.102"}, {Name: "eth0.103"},
98 {Name: "device1tap2"},
100 igmp6InterfaceTable = []Interface{
101 {Name: "lo"},
102 {Name: "eth0"}, {Name: "eth1"}, {Name: "eth2"},
103 {Name: "eth0.100"}, {Name: "eth0.101"}, {Name: "eth0.102"}, {Name: "eth0.103"},
104 {Name: "device1tap2"},
105 {Name: "pan0"},
109 func TestParseProcNet(t *testing.T) {
110 defer func() {
111 if p := recover(); p != nil {
112 t.Fatalf("panicked: %v", p)
116 var ifmat4 []Addr
117 for _, ifi := range igmpInterfaceTable {
118 ifmat := parseProcNetIGMP("testdata/igmp", &ifi)
119 ifmat4 = append(ifmat4, ifmat...)
121 if len(ifmat4) != numOfTestIPv4MCAddrs {
122 t.Fatalf("got %d; want %d", len(ifmat4), numOfTestIPv4MCAddrs)
125 var ifmat6 []Addr
126 for _, ifi := range igmp6InterfaceTable {
127 ifmat := parseProcNetIGMP6("testdata/igmp6", &ifi)
128 ifmat6 = append(ifmat6, ifmat...)
130 if len(ifmat6) != numOfTestIPv6MCAddrs {
131 t.Fatalf("got %d; want %d", len(ifmat6), numOfTestIPv6MCAddrs)