Skip to content

Commit

Permalink
Add leak checking to ethernet and muxed tests.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 422698888
  • Loading branch information
manninglucas authored and gvisor-bot committed Jan 19, 2022
1 parent 4ce5c43 commit 3d578af
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/tcpip/link/ethernet/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ go_test(
srcs = ["ethernet_test.go"],
deps = [
":ethernet",
"//pkg/refs",
"//pkg/refsvfs2",
"//pkg/tcpip",
"//pkg/tcpip/buffer",
"//pkg/tcpip/header",
Expand Down
17 changes: 14 additions & 3 deletions pkg/tcpip/link/ethernet/ethernet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ package ethernet_test

import (
"fmt"
"os"
"testing"

"gvisor.dev/gvisor/pkg/refs"
"gvisor.dev/gvisor/pkg/refsvfs2"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/buffer"
"gvisor.dev/gvisor/pkg/tcpip/header"
Expand Down Expand Up @@ -63,9 +66,9 @@ func TestDeliverNetworkPacket(t *testing.T) {
DstAddr: otherLinkAddr2,
Type: header.IPv4ProtocolNumber,
})
e.DeliverNetworkPacket("", "", 0, stack.NewPacketBuffer(stack.PacketBufferOptions{
Data: eth.ToVectorisedView(),
}))
p := stack.NewPacketBuffer(stack.PacketBufferOptions{Data: eth.ToVectorisedView()})
defer p.DecRef()
e.DeliverNetworkPacket("", "", 0, p)
if networkDispatcher.networkPackets != 1 {
t.Fatalf("got networkDispatcher.networkPackets = %d, want = 1", networkDispatcher.networkPackets)
}
Expand Down Expand Up @@ -135,6 +138,7 @@ func TestWritePacketsAddHeader(t *testing.T) {
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
ReserveHeaderBytes: int(e.MaxHeaderLength()),
})
defer pkt.DecRef()
pkt.NetworkProtocolNumber = netProto
pkt.EgressRoute.RemoteLinkAddress = remoteLinkAddr

Expand Down Expand Up @@ -165,3 +169,10 @@ func TestWritePacketsAddHeader(t *testing.T) {
}
}
}

func TestMain(m *testing.M) {
refs.SetLeakMode(refs.LeaksPanic)
code := m.Run()
refsvfs2.DoLeakCheck()
os.Exit(code)
}
2 changes: 2 additions & 0 deletions pkg/tcpip/link/muxed/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ go_test(
srcs = ["injectable_test.go"],
library = ":muxed",
deps = [
"//pkg/refs",
"//pkg/refsvfs2",
"//pkg/tcpip",
"//pkg/tcpip/buffer",
"//pkg/tcpip/link/fdbased",
Expand Down
11 changes: 11 additions & 0 deletions pkg/tcpip/link/muxed/injectable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"testing"

"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/refs"
"gvisor.dev/gvisor/pkg/refsvfs2"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/buffer"
"gvisor.dev/gvisor/pkg/tcpip/link/fdbased"
Expand Down Expand Up @@ -50,6 +52,7 @@ func TestInjectableEndpointDispatch(t *testing.T) {
ReserveHeaderBytes: 1,
Data: buffer.NewViewFromBytes([]byte{0xFB}).ToVectorisedView(),
})
defer pkt.DecRef()
pkt.TransportHeader().Push(1)[0] = 0xFA
pkt.EgressRoute.RemoteAddress = dstIP
pkt.NetworkProtocolNumber = ipv4.ProtocolNumber
Expand Down Expand Up @@ -77,6 +80,7 @@ func TestInjectableEndpointDispatchHdrOnly(t *testing.T) {
ReserveHeaderBytes: 1,
Data: buffer.NewView(0).ToVectorisedView(),
})
defer pkt.DecRef()
pkt.TransportHeader().Push(1)[0] = 0xFA
pkt.EgressRoute.RemoteAddress = dstIP
pkt.NetworkProtocolNumber = ipv4.ProtocolNumber
Expand Down Expand Up @@ -108,3 +112,10 @@ func makeTestInjectableEndpoint(t *testing.T) (*InjectableEndpoint, *os.File, tc
endpoint := NewInjectableEndpoint(routes)
return endpoint, os.NewFile(uintptr(pair[0]), "test route end"), dstIP
}

func TestMain(m *testing.M) {
refs.SetLeakMode(refs.LeaksPanic)
code := m.Run()
refsvfs2.DoLeakCheck()
os.Exit(code)
}

0 comments on commit 3d578af

Please sign in to comment.