Add leak checker to waitable tests.

PiperOrigin-RevId: 422605449
This commit is contained in:
Lucas Manning
2022-01-18 11:31:16 -08:00
committed by gVisor bot
parent 82fa6d300b
commit 2f6454681c
2 changed files with 38 additions and 11 deletions
+2
View File
@@ -23,6 +23,8 @@ go_test(
],
library = ":waitable",
deps = [
"//pkg/refs",
"//pkg/refsvfs2",
"//pkg/tcpip",
"//pkg/tcpip/header",
"//pkg/tcpip/stack",
+36 -11
View File
@@ -15,8 +15,11 @@
package waitable
import (
"os"
"testing"
"gvisor.dev/gvisor/pkg/refs"
"gvisor.dev/gvisor/pkg/refsvfs2"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/header"
"gvisor.dev/gvisor/pkg/tcpip/stack"
@@ -110,6 +113,7 @@ func TestWaitWrite(t *testing.T) {
if want := 1; ep.writeCount != want {
t.Fatalf("Unexpected writeCount: got=%v, want=%v", ep.writeCount, want)
}
pkts.DecRef()
}
{
var pkts stack.PacketBufferList
@@ -124,6 +128,7 @@ func TestWaitWrite(t *testing.T) {
if want := 2; ep.writeCount != want {
t.Fatalf("Unexpected writeCount: got=%v, want=%v", ep.writeCount, want)
}
pkts.DecRef()
}
{
@@ -139,6 +144,7 @@ func TestWaitWrite(t *testing.T) {
if want := 2; ep.writeCount != want {
t.Fatalf("Unexpected writeCount: got=%v, want=%v", ep.writeCount, want)
}
pkts.DecRef()
}
}
@@ -153,23 +159,35 @@ func TestWaitDispatch(t *testing.T) {
}
// Dispatch and check that it goes through.
ep.dispatcher.DeliverNetworkPacket("", "", 0, stack.NewPacketBuffer(stack.PacketBufferOptions{}))
if want := 1; ep.dispatchCount != want {
t.Fatalf("Unexpected dispatchCount: got=%v, want=%v", ep.dispatchCount, want)
{
p := stack.NewPacketBuffer(stack.PacketBufferOptions{})
ep.dispatcher.DeliverNetworkPacket("", "", 0, p)
if want := 1; ep.dispatchCount != want {
t.Fatalf("Unexpected dispatchCount: got=%v, want=%v", ep.dispatchCount, want)
}
p.DecRef()
}
// Wait on writes, then try to dispatch. It must go through.
wep.WaitWrite()
ep.dispatcher.DeliverNetworkPacket("", "", 0, stack.NewPacketBuffer(stack.PacketBufferOptions{}))
if want := 2; ep.dispatchCount != want {
t.Fatalf("Unexpected dispatchCount: got=%v, want=%v", ep.dispatchCount, want)
{
wep.WaitWrite()
p := stack.NewPacketBuffer(stack.PacketBufferOptions{})
ep.dispatcher.DeliverNetworkPacket("", "", 0, p)
if want := 2; ep.dispatchCount != want {
t.Fatalf("Unexpected dispatchCount: got=%v, want=%v", ep.dispatchCount, want)
}
p.DecRef()
}
// Wait on dispatches, then try to dispatch. It must not go through.
wep.WaitDispatch()
ep.dispatcher.DeliverNetworkPacket("", "", 0, stack.NewPacketBuffer(stack.PacketBufferOptions{}))
if want := 2; ep.dispatchCount != want {
t.Fatalf("Unexpected dispatchCount: got=%v, want=%v", ep.dispatchCount, want)
{
wep.WaitDispatch()
p := stack.NewPacketBuffer(stack.PacketBufferOptions{})
ep.dispatcher.DeliverNetworkPacket("", "", 0, p)
if want := 2; ep.dispatchCount != want {
t.Fatalf("Unexpected dispatchCount: got=%v, want=%v", ep.dispatchCount, want)
}
p.DecRef()
}
}
@@ -204,3 +222,10 @@ func TestOtherMethods(t *testing.T) {
t.Fatalf("Unexpected LinkAddress: got=%q, want=%q", v, linkAddr)
}
}
func TestMain(m *testing.M) {
refs.SetLeakMode(refs.LeaksPanic)
code := m.Run()
refsvfs2.DoLeakCheck()
os.Exit(code)
}