From 82313667ea4bd56d64dd1f7898aa80942684ca2c Mon Sep 17 00:00:00 2001 From: Tony Gong Date: Fri, 12 Jun 2020 15:06:01 -0700 Subject: Make GenerateRandomPayload available to all tests Moved the function for generating a payload of random byets of a specified length into the testbench package so that it's availbale for all tests to use. Added a test case to the IPv4 ID uniqueness test which uses a payload length of 512 bytes. This test case passes for gVisor currently, whereas the test case with a small payload of 11 bytes fails because gVisor only assigns the ID field if the IP payload is sufficiently large. PiperOrigin-RevId: 316185097 --- test/packetimpact/testbench/testbench.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/packetimpact/testbench') diff --git a/test/packetimpact/testbench/testbench.go b/test/packetimpact/testbench/testbench.go index 82eda6565..d64f32a5b 100644 --- a/test/packetimpact/testbench/testbench.go +++ b/test/packetimpact/testbench/testbench.go @@ -17,8 +17,10 @@ package testbench import ( "flag" "fmt" + "math/rand" "net" "os/exec" + "testing" "time" "gvisor.dev/gvisor/test/packetimpact/netdevs" @@ -91,3 +93,14 @@ func genPseudoFlags() error { return nil } + +// GenerateRandomPayload generates a random byte slice of the specified length, +// causing a fatal test failure if it is unable to do so. +func GenerateRandomPayload(t *testing.T, n int) []byte { + t.Helper() + buf := make([]byte, n) + if _, err := rand.Read(buf); err != nil { + t.Fatalf("rand.Read(buf) failed: %s", err) + } + return buf +} -- cgit v1.2.3