Skip to content

Commit 3d578af

Browse files
manninglucasgvisor-bot
authored andcommitted
Add leak checking to ethernet and muxed tests.
PiperOrigin-RevId: 422698888
1 parent 4ce5c43 commit 3d578af

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

pkg/tcpip/link/ethernet/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ go_test(
2020
srcs = ["ethernet_test.go"],
2121
deps = [
2222
":ethernet",
23+
"//pkg/refs",
24+
"//pkg/refsvfs2",
2325
"//pkg/tcpip",
2426
"//pkg/tcpip/buffer",
2527
"//pkg/tcpip/header",

pkg/tcpip/link/ethernet/ethernet_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ package ethernet_test
1616

1717
import (
1818
"fmt"
19+
"os"
1920
"testing"
2021

22+
"gvisor.dev/gvisor/pkg/refs"
23+
"gvisor.dev/gvisor/pkg/refsvfs2"
2124
"gvisor.dev/gvisor/pkg/tcpip"
2225
"gvisor.dev/gvisor/pkg/tcpip/buffer"
2326
"gvisor.dev/gvisor/pkg/tcpip/header"
@@ -63,9 +66,9 @@ func TestDeliverNetworkPacket(t *testing.T) {
6366
DstAddr: otherLinkAddr2,
6467
Type: header.IPv4ProtocolNumber,
6568
})
66-
e.DeliverNetworkPacket("", "", 0, stack.NewPacketBuffer(stack.PacketBufferOptions{
67-
Data: eth.ToVectorisedView(),
68-
}))
69+
p := stack.NewPacketBuffer(stack.PacketBufferOptions{Data: eth.ToVectorisedView()})
70+
defer p.DecRef()
71+
e.DeliverNetworkPacket("", "", 0, p)
6972
if networkDispatcher.networkPackets != 1 {
7073
t.Fatalf("got networkDispatcher.networkPackets = %d, want = 1", networkDispatcher.networkPackets)
7174
}
@@ -135,6 +138,7 @@ func TestWritePacketsAddHeader(t *testing.T) {
135138
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
136139
ReserveHeaderBytes: int(e.MaxHeaderLength()),
137140
})
141+
defer pkt.DecRef()
138142
pkt.NetworkProtocolNumber = netProto
139143
pkt.EgressRoute.RemoteLinkAddress = remoteLinkAddr
140144

@@ -165,3 +169,10 @@ func TestWritePacketsAddHeader(t *testing.T) {
165169
}
166170
}
167171
}
172+
173+
func TestMain(m *testing.M) {
174+
refs.SetLeakMode(refs.LeaksPanic)
175+
code := m.Run()
176+
refsvfs2.DoLeakCheck()
177+
os.Exit(code)
178+
}

pkg/tcpip/link/muxed/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ go_test(
1919
srcs = ["injectable_test.go"],
2020
library = ":muxed",
2121
deps = [
22+
"//pkg/refs",
23+
"//pkg/refsvfs2",
2224
"//pkg/tcpip",
2325
"//pkg/tcpip/buffer",
2426
"//pkg/tcpip/link/fdbased",

pkg/tcpip/link/muxed/injectable_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"testing"
2222

2323
"golang.org/x/sys/unix"
24+
"gvisor.dev/gvisor/pkg/refs"
25+
"gvisor.dev/gvisor/pkg/refsvfs2"
2426
"gvisor.dev/gvisor/pkg/tcpip"
2527
"gvisor.dev/gvisor/pkg/tcpip/buffer"
2628
"gvisor.dev/gvisor/pkg/tcpip/link/fdbased"
@@ -50,6 +52,7 @@ func TestInjectableEndpointDispatch(t *testing.T) {
5052
ReserveHeaderBytes: 1,
5153
Data: buffer.NewViewFromBytes([]byte{0xFB}).ToVectorisedView(),
5254
})
55+
defer pkt.DecRef()
5356
pkt.TransportHeader().Push(1)[0] = 0xFA
5457
pkt.EgressRoute.RemoteAddress = dstIP
5558
pkt.NetworkProtocolNumber = ipv4.ProtocolNumber
@@ -77,6 +80,7 @@ func TestInjectableEndpointDispatchHdrOnly(t *testing.T) {
7780
ReserveHeaderBytes: 1,
7881
Data: buffer.NewView(0).ToVectorisedView(),
7982
})
83+
defer pkt.DecRef()
8084
pkt.TransportHeader().Push(1)[0] = 0xFA
8185
pkt.EgressRoute.RemoteAddress = dstIP
8286
pkt.NetworkProtocolNumber = ipv4.ProtocolNumber
@@ -108,3 +112,10 @@ func makeTestInjectableEndpoint(t *testing.T) (*InjectableEndpoint, *os.File, tc
108112
endpoint := NewInjectableEndpoint(routes)
109113
return endpoint, os.NewFile(uintptr(pair[0]), "test route end"), dstIP
110114
}
115+
116+
func TestMain(m *testing.M) {
117+
refs.SetLeakMode(refs.LeaksPanic)
118+
code := m.Run()
119+
refsvfs2.DoLeakCheck()
120+
os.Exit(code)
121+
}

0 commit comments

Comments
 (0)