-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathlow_test.go
More file actions
78 lines (72 loc) · 2.17 KB
/
low_test.go
File metadata and controls
78 lines (72 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2017 Intel Corporation.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package low
import (
"log"
"math/rand"
"testing"
"time"
"unsafe"
)
func init() {
argc, argv := InitDPDKArguments([]string{})
// Default: burstSize=32, mbufNumber=8191, mbufCacheSize=250
if err := InitDPDK(argc, argv, 32, 8191, 250, 0, false, false, false, false); err != nil {
log.Fatalf("fail to initialize with error: %+v\n", err)
}
rand.Seed(time.Now().UTC().UnixNano())
}
func TestReorder(t *testing.T) {
const sliceLength = 500
input := make([]int, sliceLength, sliceLength)
inputPointers := make([]uintptr, sliceLength, sliceLength)
outputPointers := make([]uintptr, sliceLength, sliceLength)
for i := 0; i < sliceLength; i++ {
input[i] = i
inputPointers[i] = uintptr(unsafe.Pointer(&input[i]))
}
// Real usable ring size is count-1
ring := CreateRing(64)
a1 := uint(63)
a2 := uint(29)
a3 := uint(14)
a4 := uint(1)
for k := 0; k < 100; k++ {
if k != 0 {
a1 = uint(rand.Intn(64))
a2 = uint(rand.Intn(64))
a3 = uint(rand.Intn(64))
a4 = uint(rand.Intn(int(64 - a3)))
}
for j := 0; j < 1000; j++ {
if ring.EnqueueBurst(inputPointers[:a1], a1) != a1 {
t.Errorf("Incorrect enqueueBurst 1")
}
if ring.DequeueBurst(outputPointers[:a1], a1) != a1 {
t.Errorf("Incorrect dequeueBurst 1")
}
if ring.EnqueueBurst(inputPointers[a1:a1+a2], a2) != a2 {
t.Errorf("Incorrect enqueueBurst 2")
}
if ring.DequeueBurst(outputPointers[a1:a1+a2], a2) != a2 {
t.Errorf("Incorrect dequeueBurst 2")
}
if ring.EnqueueBurst(inputPointers[a1+a2:a1+a2+a3], a3) != a3 {
t.Errorf("Incorrect enqueueBurst 3")
}
if ring.EnqueueBurst(inputPointers[a1+a2+a3:a1+a2+a3+a4], a4) != a4 {
t.Errorf("Incorrect enqueueBurst 4")
}
if ring.DequeueBurst(outputPointers[a1+a2:a1+a2+a3+a4], a3+a4) != a3+a4 {
t.Errorf("Incorrect dequeueBurst 3")
}
for i := 0; i < int(a1+a2+a3+a4); i++ {
if *(*int)(unsafe.Pointer(outputPointers[i])) != i {
t.Errorf("Ring reorder packet. %d element is %d instead of %d.", i, *(*int)(unsafe.Pointer(outputPointers[i])), i)
t.FailNow()
}
}
}
}
}