diff options
Diffstat (limited to 'pkg/tcpip/network')
-rw-r--r-- | pkg/tcpip/network/ipv6/icmp_test.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/pkg/tcpip/network/ipv6/icmp_test.go b/pkg/tcpip/network/ipv6/icmp_test.go index 4374d0198..60404c78b 100644 --- a/pkg/tcpip/network/ipv6/icmp_test.go +++ b/pkg/tcpip/network/ipv6/icmp_test.go @@ -492,6 +492,8 @@ func visitStats(v reflect.Value, f func(string, *tcpip.StatCounter)) { } type testContext struct { + t *testing.T + s0 *stack.Stack s1 *stack.Stack @@ -509,6 +511,8 @@ func (e endpointWithResolutionCapability) Capabilities() stack.LinkEndpointCapab func newTestContext(t *testing.T) *testContext { c := &testContext{ + t: t, + s0: stack.New(stack.Options{ NetworkProtocols: []stack.NetworkProtocolFactory{NewProtocol}, TransportProtocols: []stack.TransportProtocolFactory{icmp.NewProtocol6}, @@ -562,10 +566,19 @@ func newTestContext(t *testing.T) *testContext { }}, ) + t.Cleanup(c.cleanup) + return c } func (c *testContext) cleanup() { + if err := c.s0.RemoveNIC(nicID); err != nil { + c.t.Errorf("c.s0.RemoveNIC(%d): %s", nicID, err) + } + if err := c.s1.RemoveNIC(nicID); err != nil { + c.t.Errorf("c.s1.RemoveNIC(%d): %s", nicID, err) + } + c.linkEP0.Close() c.linkEP1.Close() } @@ -617,7 +630,6 @@ func routeICMPv6Packet(t *testing.T, args routeArgs, fn func(*testing.T, header. func TestLinkResolution(t *testing.T) { c := newTestContext(t) - defer c.cleanup() r, err := c.s0.FindRoute(nicID, lladdr0, lladdr1, ProtocolNumber, false /* multicastLoop */) if err != nil { |