From 7b79370c105b28a1cffa2d12d81898fc6b278728 Mon Sep 17 00:00:00 2001 From: Ian Gudger Date: Thu, 28 May 2020 14:42:01 -0700 Subject: Add pcap logging to pcaketimpact. This makes debugging packetimpact tests much easier. PiperOrigin-RevId: 313662654 --- test/packetimpact/runner/packetimpact_test.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'test/packetimpact') diff --git a/test/packetimpact/runner/packetimpact_test.go b/test/packetimpact/runner/packetimpact_test.go index ac13c8543..e58a1fb1b 100644 --- a/test/packetimpact/runner/packetimpact_test.go +++ b/test/packetimpact/runner/packetimpact_test.go @@ -18,9 +18,12 @@ package packetimpact_test import ( "flag" "fmt" + "io/ioutil" "log" "math/rand" "net" + "os" + "os/exec" "path" "strings" "testing" @@ -117,10 +120,18 @@ func TestOne(t *testing.T) { }(dn) } + tmpDir, err := ioutil.TempDir("", "container-output") + if err != nil { + t.Fatal("creating temp dir:", err) + } + defer os.RemoveAll(tmpDir) + + const testOutputDir = "/tmp/testoutput" + runOpts := dockerutil.RunOpts{ Image: "packetimpact", CapAdd: []string{"NET_ADMIN"}, - Extra: []string{"--sysctl", "net.ipv6.conf.all.disable_ipv6=0", "--rm"}, + Extra: []string{"--sysctl", "net.ipv6.conf.all.disable_ipv6=0", "--rm", "-v", tmpDir + ":" + testOutputDir}, Foreground: true, } @@ -187,7 +198,10 @@ func TestOne(t *testing.T) { // Run tcpdump in the test bench unbuffered, without DNS resolution, just on // the interface with the test packets. snifferArgs := []string{ - "tcpdump", "-S", "-vvv", "-U", "-n", "-i", testNetDev, + "tcpdump", + "-S", "-vvv", "-U", "-n", + "-i", testNetDev, + "-w", testOutputDir + "/dump.pcap", } snifferRegex := "tcpdump: listening.*\n" if *tshark { @@ -201,6 +215,12 @@ func TestOne(t *testing.T) { snifferRegex = "Capturing on.*\n" } + defer func() { + if err := exec.Command("/bin/cp", "-r", tmpDir, os.Getenv("TEST_UNDECLARED_OUTPUTS_DIR")).Run(); err != nil { + t.Error("unable to copy container output files:", err) + } + }() + if err := testbench.Create(runOpts, snifferArgs...); err != nil { t.Fatalf("unable to create container %s: %s", testbench.Name, err) } -- cgit v1.2.3