-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathq_fq_test.go
94 lines (89 loc) · 2.26 KB
/
q_fq_test.go
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package tc
import (
"errors"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestFq(t *testing.T) {
weights := []int32{589824, 196608, 65536}
tests := map[string]struct {
val Fq
err1 error
err2 error
}{
"simple": {
val: Fq{
PLimit: uint32Ptr(1),
FlowPLimit: uint32Ptr(2),
Quantum: uint32Ptr(3),
InitQuantum: uint32Ptr(4),
RateEnable: uint32Ptr(5),
FlowDefaultRate: uint32Ptr(6),
FlowMaxRate: uint32Ptr(7),
BucketsLog: uint32Ptr(8),
FlowRefillDelay: uint32Ptr(9),
OrphanMask: uint32Ptr(10),
LowRateThreshold: uint32Ptr(11),
CEThreshold: uint32Ptr(12),
},
},
"defaults": {
val: Fq{
PLimit: uint32Ptr(10000),
FlowPLimit: uint32Ptr(100),
Quantum: uint32Ptr(3028),
InitQuantum: uint32Ptr(15140),
RateEnable: uint32Ptr(1),
FlowMaxRate: uint32Ptr(4294967295),
BucketsLog: uint32Ptr(10),
FlowRefillDelay: uint32Ptr(40000),
OrphanMask: uint32Ptr(1023),
LowRateThreshold: uint32Ptr(68750),
CEThreshold: uint32Ptr(4294967295),
TimerSlack: uint32Ptr(10000),
Horizon: uint32Ptr(10000000),
HorizonDrop: uint8Ptr(1),
PrioMap: &FqPrioQopt{
Bands: 3,
PrioMap: [16]uint8{1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
},
Weights: &weights,
OffloadHorizon: uint32Ptr(73),
},
},
}
for name, testcase := range tests {
t.Run(name, func(t *testing.T) {
data, err1 := marshalFq(&testcase.val)
if err1 != nil {
if errors.Is(err1, testcase.err1) {
return
}
t.Fatalf("Unexpected error: %v", err1)
}
val := Fq{}
err2 := unmarshalFq(data, &val)
if err2 != nil {
if errors.Is(err2, testcase.err2) {
return
}
t.Fatalf("Unexpected error: %v", err2)
}
if diff := cmp.Diff(val, testcase.val); diff != "" {
t.Fatalf("Fq missmatch (want +got):\n%s", diff)
}
})
}
t.Run("nil", func(t *testing.T) {
_, err := marshalFq(nil)
if !errors.Is(err, ErrNoArg) {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("unmarshalFq(0x0)", func(t *testing.T) {
err := unmarshalFq([]byte{0x0}, nil)
if err == nil {
t.Fatalf("expected error but got none")
}
})
}