summaryrefslogtreecommitdiffhomepage
path: root/test/packetimpact/testbench/testbench.go
diff options
context:
space:
mode:
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
+}