From e43c601762b9a486c184f22268a43d5bfeee2ec8 Mon Sep 17 00:00:00 2001 From: fearful-symmetry Date: Tue, 24 Sep 2024 09:14:55 -0700 Subject: [PATCH] clean up network tests --- testing/testrunner/ebpf_test.go | 49 +++++---------------------------- testing/testrunner/utils.go | 8 +++++- 2 files changed, 14 insertions(+), 43 deletions(-) diff --git a/testing/testrunner/ebpf_test.go b/testing/testrunner/ebpf_test.go index 7d664864..cc654eb4 100644 --- a/testing/testrunner/ebpf_test.go +++ b/testing/testrunner/ebpf_test.go @@ -406,12 +406,7 @@ func TtyWrite(t *testing.T, et *Runner) { } func Tcpv4ConnectionAttempt(t *testing.T, et *Runner) { - var binOutput struct { - PidInfo TestPidInfo `json:"pid_info"` - ClientPort int64 `json:"client_port"` - ServerPort int64 `json:"server_port"` - NetNs int64 `json:"netns"` - } + binOutput := NetBinOut{} runTestUnmarshalOutput(t, "tcpv4_connect", &binOutput) var ev NetConnAttemptEvent @@ -435,12 +430,7 @@ func Tcpv4ConnectionAttempt(t *testing.T, et *Runner) { } func Tcpv4ConnectionAccept(t *testing.T, et *Runner) { - var binOutput struct { - PidInfo TestPidInfo `json:"pid_info"` - ClientPort int64 `json:"client_port"` - ServerPort int64 `json:"server_port"` - NetNs int64 `json:"netns"` - } + binOutput := NetBinOut{} runTestUnmarshalOutput(t, "tcpv4_connect", &binOutput) var ev NetConnAcceptEvent @@ -463,12 +453,7 @@ func Tcpv4ConnectionAccept(t *testing.T, et *Runner) { } func Tcpv4ConnectionClose(t *testing.T, et *Runner) { - var binOutput struct { - PidInfo TestPidInfo `json:"pid_info"` - ClientPort int64 `json:"client_port"` - ServerPort int64 `json:"server_port"` - NetNs int64 `json:"netns"` - } + binOutput := NetBinOut{} runTestUnmarshalOutput(t, "tcpv4_connect", &binOutput) var ev NetConnCloseEvent @@ -511,12 +496,7 @@ func Tcpv4ConnectionClose(t *testing.T, et *Runner) { } func Tcpv6ConnectionAttempt(t *testing.T, et *Runner) { - var binOutput struct { - PidInfo TestPidInfo `json:"pid_info"` - ClientPort int64 `json:"client_port"` - ServerPort int64 `json:"server_port"` - NetNs int64 `json:"netns"` - } + binOutput := NetBinOut{} runTestUnmarshalOutput(t, "tcpv6_connect", &binOutput) var ev NetConnAttemptEvent @@ -539,12 +519,7 @@ func Tcpv6ConnectionAttempt(t *testing.T, et *Runner) { } func Tcpv6ConnectionAccept(t *testing.T, et *Runner) { - var binOutput struct { - PidInfo TestPidInfo `json:"pid_info"` - ClientPort int64 `json:"client_port"` - ServerPort int64 `json:"server_port"` - NetNs int64 `json:"netns"` - } + binOutput := NetBinOut{} runTestUnmarshalOutput(t, "tcpv6_connect", &binOutput) var ev NetConnAttemptEvent @@ -567,12 +542,7 @@ func Tcpv6ConnectionAccept(t *testing.T, et *Runner) { } func Tcpv6ConnectionClose(t *testing.T, et *Runner) { - var binOutput struct { - PidInfo TestPidInfo `json:"pid_info"` - ClientPort int64 `json:"client_port"` - ServerPort int64 `json:"server_port"` - NetNs int64 `json:"netns"` - } + binOutput := NetBinOut{} runTestUnmarshalOutput(t, "tcpv6_connect", &binOutput) var ev NetConnCloseEvent @@ -595,12 +565,7 @@ func Tcpv6ConnectionClose(t *testing.T, et *Runner) { } func DNSMonitor(t *testing.T, et *Runner) { - var binOutput struct { - PidInfo TestPidInfo `json:"pid_info"` - ClientPort int64 `json:"client_port"` - ServerPort int64 `json:"server_port"` - NetNs int64 `json:"netns"` - } + binOutput := NetBinOut{} runTestUnmarshalOutput(t, "udp_send", &binOutput) type dnsOutput struct { Data []uint8 `json:"data"` diff --git a/testing/testrunner/utils.go b/testing/testrunner/utils.go index eb9879d3..301ed07a 100644 --- a/testing/testrunner/utils.go +++ b/testing/testrunner/utils.go @@ -175,6 +175,13 @@ type NetConnAcceptEvent struct { Comm string `json:"comm"` } +type NetBinOut struct { + PidInfo TestPidInfo `json:"pid_info"` + ClientPort int64 `json:"client_port"` + ServerPort int64 `json:"server_port"` + NetNs int64 `json:"netns"` +} + type NetConnCloseEvent struct { Pids PidInfo `json:"pids"` Net NetInfo `json:"net"` @@ -189,7 +196,6 @@ var eventsTracePath = "/EventsTrace" // Path to the TC filter test binary and probe. This one is weird and lives outside the rest of the test binaries var tcTestPath = "/BPFTcFilterTests" - var tcObjPath = "/TcFilter.bpf.o" // init will run at startup and figure out if we're running in the bluebox test env or not,