Add leak checking to qdisc and nested tests.

PiperOrigin-RevId: 422685326
This commit is contained in:
Lucas Manning
2022-01-18 17:24:41 -08:00
committed by gVisor bot
parent 30f36c9c87
commit 4ce5c43a30
4 changed files with 38 additions and 7 deletions
+2
View File
@@ -23,6 +23,8 @@ go_test(
"nested_test.go",
],
deps = [
"//pkg/refs",
"//pkg/refsvfs2",
"//pkg/tcpip",
"//pkg/tcpip/header",
"//pkg/tcpip/link/nested",
+24 -7
View File
@@ -15,8 +15,11 @@
package nested_test
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/link/nested"
@@ -87,9 +90,13 @@ func TestNestedLinkEndpoint(t *testing.T) {
t.Error("After attach, nestedEP.IsAttached() = false, want = true")
}
nestedEP.DeliverNetworkPacket(emptyAddress, emptyAddress, header.IPv4ProtocolNumber, stack.NewPacketBuffer(stack.PacketBufferOptions{}))
if disp.count != 1 {
t.Errorf("After first packet with dispatcher attached, got disp.count = %d, want = 1", disp.count)
{
p := stack.NewPacketBuffer(stack.PacketBufferOptions{})
nestedEP.DeliverNetworkPacket(emptyAddress, emptyAddress, header.IPv4ProtocolNumber, p)
p.DecRef()
if disp.count != 1 {
t.Errorf("After first packet with dispatcher attached, got disp.count = %d, want = 1", disp.count)
}
}
nestedEP.Attach(nil)
@@ -100,10 +107,20 @@ func TestNestedLinkEndpoint(t *testing.T) {
t.Error("After detach, nestedEP.IsAttached() = true, want = false")
}
disp.count = 0
nestedEP.DeliverNetworkPacket(emptyAddress, emptyAddress, header.IPv4ProtocolNumber, stack.NewPacketBuffer(stack.PacketBufferOptions{}))
if disp.count != 0 {
t.Errorf("After second packet with dispatcher detached, got disp.count = %d, want = 0", disp.count)
{
disp.count = 0
p := stack.NewPacketBuffer(stack.PacketBufferOptions{})
nestedEP.DeliverNetworkPacket(emptyAddress, emptyAddress, header.IPv4ProtocolNumber, p)
p.DecRef()
if disp.count != 0 {
t.Errorf("After second packet with dispatcher detached, got disp.count = %d, want = 0", disp.count)
}
}
}
func TestMain(m *testing.M) {
refs.SetLeakMode(refs.LeaksPanic)
code := m.Run()
refsvfs2.DoLeakCheck()
os.Exit(code)
}
+2
View File
@@ -22,6 +22,8 @@ go_test(
srcs = ["qdisc_test.go"],
deps = [
":fifo",
"//pkg/refs",
"//pkg/refsvfs2",
"//pkg/sync",
"//pkg/tcpip",
"//pkg/tcpip/buffer",
+10
View File
@@ -16,8 +16,11 @@ package qdisc_test
import (
"math/rand"
"os"
"testing"
"gvisor.dev/gvisor/pkg/refs"
"gvisor.dev/gvisor/pkg/refsvfs2"
"gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/buffer"
@@ -63,3 +66,10 @@ func TestFastSimultaneousWrites(t *testing.T) {
}()
}
}
func TestMain(m *testing.M) {
refs.SetLeakMode(refs.LeaksPanic)
code := m.Run()
refsvfs2.DoLeakCheck()
os.Exit(code)
}