diff options
author | Ian Gudger <igudger@google.com> | 2020-05-28 14:42:01 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-05-28 14:43:48 -0700 |
commit | 7b79370c105b28a1cffa2d12d81898fc6b278728 (patch) | |
tree | 642a354bf85cb92e4d484076bb915eddf7db697c | |
parent | 226cba97fb2f71a96839e892250e5c868ad72dc0 (diff) |
Add pcap logging to pcaketimpact.
This makes debugging packetimpact tests much easier.
PiperOrigin-RevId: 313662654
-rw-r--r-- | test/packetimpact/runner/packetimpact_test.go | 24 |
1 files changed, 22 insertions, 2 deletions
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) } |