summaryrefslogtreecommitdiffhomepage
path: root/test/packetimpact/testbench/testbench.go
diff options
context:
space:
mode:
authorTony Gong <gongt@google.com>2020-06-12 15:06:01 -0700
committergVisor bot <gvisor-bot@google.com>2020-06-12 15:07:17 -0700
commit82313667ea4bd56d64dd1f7898aa80942684ca2c (patch)
treec4161a0448d6d06796172ecd2a4efd86bbb60ee4 /test/packetimpact/testbench/testbench.go
parent6ec9d60403fdf7a33072eaa023e62bfd56ed9f5c (diff)
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
Diffstat (limited to 'test/packetimpact/testbench/testbench.go')
-rw-r--r--test/packetimpact/testbench/testbench.go13
1 files changed, 13 insertions, 0 deletions
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
+}