Add leak checking to transport internal network tests.

PiperOrigin-RevId: 424267559
This commit is contained in:
Bhasker Hariharan
2022-01-25 23:17:26 -08:00
committed by gVisor bot
parent c89b6d2611
commit ee08e56d4c
2 changed files with 16 additions and 2 deletions
@@ -28,6 +28,8 @@ go_test(
srcs = ["endpoint_test.go"],
deps = [
":network",
"//pkg/refs",
"//pkg/refsvfs2",
"//pkg/tcpip",
"//pkg/tcpip/buffer",
"//pkg/tcpip/checker",
@@ -16,9 +16,12 @@ package network_test
import (
"fmt"
"os"
"testing"
"github.com/google/go-cmp/cmp"
"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/checker"
@@ -198,10 +201,12 @@ func TestEndpointStateTransitions(t *testing.T) {
}, info); diff != "" {
t.Errorf("write packet info mismatch (-want +got):\n%s", diff)
}
if err := ctx.WritePacket(stack.NewPacketBuffer(stack.PacketBufferOptions{
injectPkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
ReserveHeaderBytes: int(info.MaxHeaderLength),
Data: data.ToVectorisedView(),
}), false /* headerIncluded */); err != nil {
})
defer injectPkt.DecRef()
if err := ctx.WritePacket(injectPkt, false /* headerIncluded */); err != nil {
t.Fatalf("ctx.WritePacket(_, false): %s", err)
}
if pkt := e.Read(); pkt == nil {
@@ -316,3 +321,10 @@ func TestBindNICID(t *testing.T) {
})
}
}
func TestMain(m *testing.M) {
refs.SetLeakMode(refs.LeaksPanic)
code := m.Run()
refsvfs2.DoLeakCheck()
os.Exit(code)
}