summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2017-09-14 03:16:31 +0200
committerChristian Pointner <equinox@anytun.org>2017-09-14 03:16:31 +0200
commit5c74d46d95e8f914afa170e770629e1da8e0db1c (patch)
treea4352fd62e801c39fcba25c05d3477580d53d1ba
parentfix benchmarks (diff)
make the random tests more random
-rw-r--r--satp/packet_test.go23
1 files changed, 16 insertions, 7 deletions
diff --git a/satp/packet_test.go b/satp/packet_test.go
index 5db7828..3640570 100644
--- a/satp/packet_test.go
+++ b/satp/packet_test.go
@@ -34,10 +34,11 @@ import (
"bytes"
"math/rand"
"testing"
+ "time"
)
const (
- NUM_RANDOM_DATASETS = 100
+ NUM_RANDOM_DATASETS = 1000
)
var (
@@ -65,8 +66,14 @@ var (
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC6, 0x5A, 0xD4, 0xC7, 0x23, 0x43, 0x08, 0x06, 0x00, 0x01,
0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0xC6, 0x5A, 0xD4, 0xC7, 0x23, 0x43, 0xC0, 0xA8, 0x2A, 0x17,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xA8, 0x2A, 0x01}
+
+ tRand *rand.Rand
)
+func init() {
+ tRand = rand.New(rand.NewSource(time.Now().UnixNano()))
+}
+
func TestPlainPacketHeader(t *testing.T) {
testvectors := []uint16{0, IPv4Type, IPv6Type, EthernetType, 0xAA55, 0xF00F}
@@ -157,11 +164,11 @@ func TestPlainPacketWriteTo(t *testing.T) {
}
func generateRandomTestDataPlainPacket() (payloadType uint16, payload []byte) {
- payloadType = uint16(rand.Uint32())
+ payloadType = uint16(tRand.Uint32())
- packetLen := uint(2 + rand.Int31n(PACKET_BUFFER_SIZE-2))
+ packetLen := uint(2 + tRand.Int31n(PACKET_BUFFER_SIZE-2))
payload = make([]byte, packetLen)
- rand.Read(payload)
+ tRand.Read(payload)
return
}
@@ -309,10 +316,12 @@ func TestEncryptedPacketReadFrom(t *testing.T) {
func generateRandomTestDataEncryptedPacket() (authTagLen int, packetData []byte) {
minLen := int32(8 + 2)
- packetLen := uint(minLen + rand.Int31n(PACKET_BUFFER_SIZE-minLen))
- authTagLen = int(rand.Int31n(int32(packetLen) - minLen))
+ packetLen := uint(minLen + tRand.Int31n(PACKET_BUFFER_SIZE-minLen))
+ if packetLen > uint(minLen) {
+ authTagLen = int(tRand.Int31n(int32(packetLen) - minLen))
+ }
packetData = make([]byte, packetLen)
- rand.Read(packetData)
+ tRand.Read(packetData)
return
}