@@ -70,7 +70,10 @@ func (spt staticPolicyTest) PseudoClone() staticPolicyTest {
70
70
}
71
71
72
72
func TestStaticPolicyName (t * testing.T ) {
73
- policy , _ := NewStaticPolicy (topoSingleSocketHT , 1 , cpuset .New (), topologymanager .NewFakeManager (), nil )
73
+ policy , err := NewStaticPolicy (topoSingleSocketHT , 1 , cpuset .New (), topologymanager .NewFakeManager (), nil )
74
+ if err != nil {
75
+ t .Fatalf ("NewStaticPolicy() failed: %v" , err )
76
+ }
74
77
75
78
policyName := policy .Name ()
76
79
if policyName != "static" {
@@ -168,13 +171,16 @@ func TestStaticPolicyStart(t *testing.T) {
168
171
for _ , testCase := range testCases {
169
172
t .Run (testCase .description , func (t * testing.T ) {
170
173
featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , pkgfeatures .CPUManagerPolicyAlphaOptions , true )
171
- p , _ := NewStaticPolicy (testCase .topo , testCase .numReservedCPUs , cpuset .New (), topologymanager .NewFakeManager (), testCase .options )
174
+ p , err := NewStaticPolicy (testCase .topo , testCase .numReservedCPUs , cpuset .New (), topologymanager .NewFakeManager (), testCase .options )
175
+ if err != nil {
176
+ t .Fatalf ("NewStaticPolicy() failed: %v" , err )
177
+ }
172
178
policy := p .(* staticPolicy )
173
179
st := & mockState {
174
180
assignments : testCase .stAssignments ,
175
181
defaultCPUSet : testCase .stDefaultCPUSet ,
176
182
}
177
- err : = policy .Start (st )
183
+ err = policy .Start (st )
178
184
if ! reflect .DeepEqual (err , testCase .expErr ) {
179
185
t .Errorf ("StaticPolicy Start() error (%v). expected error: %v but got: %v" ,
180
186
testCase .description , testCase .expErr , err )
@@ -637,15 +643,18 @@ func runStaticPolicyTestCase(t *testing.T, testCase staticPolicyTest) {
637
643
if testCase .reservedCPUs != nil {
638
644
cpus = testCase .reservedCPUs .Clone ()
639
645
}
640
- policy , _ := NewStaticPolicy (testCase .topo , testCase .numReservedCPUs , cpus , tm , testCase .options )
646
+ policy , err := NewStaticPolicy (testCase .topo , testCase .numReservedCPUs , cpus , tm , testCase .options )
647
+ if err != nil {
648
+ t .Fatalf ("NewStaticPolicy() failed: %v" , err )
649
+ }
641
650
642
651
st := & mockState {
643
652
assignments : testCase .stAssignments ,
644
653
defaultCPUSet : testCase .stDefaultCPUSet ,
645
654
}
646
655
647
656
container := & testCase .pod .Spec .Containers [0 ]
648
- err : = policy .Allocate (st , testCase .pod , container )
657
+ err = policy .Allocate (st , testCase .pod , container )
649
658
if ! reflect .DeepEqual (err , testCase .expErr ) {
650
659
t .Errorf ("StaticPolicy Allocate() error (%v). expected add error: %q but got: %q" ,
651
660
testCase .description , testCase .expErr , err )
@@ -658,13 +667,13 @@ func runStaticPolicyTestCase(t *testing.T, testCase staticPolicyTest) {
658
667
testCase .description , container .Name , st .assignments )
659
668
}
660
669
661
- if ! reflect . DeepEqual ( cset , testCase .expCSet ) {
662
- t .Errorf ("StaticPolicy Allocate() error (%v). expected cpuset %v but got %v " ,
670
+ if ! cset . Equals ( testCase .expCSet ) {
671
+ t .Errorf ("StaticPolicy Allocate() error (%v). expected cpuset %s but got %s " ,
663
672
testCase .description , testCase .expCSet , cset )
664
673
}
665
674
666
675
if ! cset .Intersection (st .defaultCPUSet ).IsEmpty () {
667
- t .Errorf ("StaticPolicy Allocate() error (%v). expected cpuset %v to be disoint from the shared cpuset %v " ,
676
+ t .Errorf ("StaticPolicy Allocate() error (%v). expected cpuset %s to be disoint from the shared cpuset %s " ,
668
677
testCase .description , cset , st .defaultCPUSet )
669
678
}
670
679
}
@@ -708,7 +717,10 @@ func TestStaticPolicyReuseCPUs(t *testing.T) {
708
717
}
709
718
710
719
for _ , testCase := range testCases {
711
- policy , _ := NewStaticPolicy (testCase .topo , testCase .numReservedCPUs , cpuset .New (), topologymanager .NewFakeManager (), nil )
720
+ policy , err := NewStaticPolicy (testCase .topo , testCase .numReservedCPUs , cpuset .New (), topologymanager .NewFakeManager (), nil )
721
+ if err != nil {
722
+ t .Fatalf ("NewStaticPolicy() failed: %v" , err )
723
+ }
712
724
713
725
st := & mockState {
714
726
assignments : testCase .stAssignments ,
@@ -720,16 +732,16 @@ func TestStaticPolicyReuseCPUs(t *testing.T) {
720
732
for _ , container := range append (pod .Spec .InitContainers , pod .Spec .Containers ... ) {
721
733
policy .Allocate (st , pod , & container )
722
734
}
723
- if ! reflect . DeepEqual ( st .defaultCPUSet , testCase .expCSetAfterAlloc ) {
724
- t .Errorf ("StaticPolicy Allocate() error (%v). expected default cpuset %v but got %v " ,
735
+ if ! st .defaultCPUSet . Equals ( testCase .expCSetAfterAlloc ) {
736
+ t .Errorf ("StaticPolicy Allocate() error (%v). expected default cpuset %s but got %s " ,
725
737
testCase .description , testCase .expCSetAfterAlloc , st .defaultCPUSet )
726
738
}
727
739
728
740
// remove
729
741
policy .RemoveContainer (st , string (pod .UID ), testCase .containerName )
730
742
731
- if ! reflect . DeepEqual ( st .defaultCPUSet , testCase .expCSetAfterRemove ) {
732
- t .Errorf ("StaticPolicy RemoveContainer() error (%v). expected default cpuset %v but got %v " ,
743
+ if ! st .defaultCPUSet . Equals ( testCase .expCSetAfterRemove ) {
744
+ t .Errorf ("StaticPolicy RemoveContainer() error (%v). expected default cpuset %sv but got %s " ,
733
745
testCase .description , testCase .expCSetAfterRemove , st .defaultCPUSet )
734
746
}
735
747
if _ , found := st .assignments [string (pod .UID )][testCase .containerName ]; found {
@@ -761,7 +773,10 @@ func TestStaticPolicyDoNotReuseCPUs(t *testing.T) {
761
773
}
762
774
763
775
for _ , testCase := range testCases {
764
- policy , _ := NewStaticPolicy (testCase .topo , testCase .numReservedCPUs , cpuset .New (), topologymanager .NewFakeManager (), nil )
776
+ policy , err := NewStaticPolicy (testCase .topo , testCase .numReservedCPUs , cpuset .New (), topologymanager .NewFakeManager (), nil )
777
+ if err != nil {
778
+ t .Fatalf ("NewStaticPolicy() failed: %v" , err )
779
+ }
765
780
766
781
st := & mockState {
767
782
assignments : testCase .stAssignments ,
@@ -777,8 +792,8 @@ func TestStaticPolicyDoNotReuseCPUs(t *testing.T) {
777
792
testCase .description , err )
778
793
}
779
794
}
780
- if ! reflect . DeepEqual ( st .defaultCPUSet , testCase .expCSetAfterAlloc ) {
781
- t .Errorf ("StaticPolicy Allocate() error (%v). expected default cpuset %v but got %v " ,
795
+ if ! st .defaultCPUSet . Equals ( testCase .expCSetAfterAlloc ) {
796
+ t .Errorf ("StaticPolicy Allocate() error (%v). expected default cpuset %s but got %s " ,
782
797
testCase .description , testCase .expCSetAfterAlloc , st .defaultCPUSet )
783
798
}
784
799
}
@@ -843,7 +858,10 @@ func TestStaticPolicyRemove(t *testing.T) {
843
858
}
844
859
845
860
for _ , testCase := range testCases {
846
- policy , _ := NewStaticPolicy (testCase .topo , testCase .numReservedCPUs , cpuset .New (), topologymanager .NewFakeManager (), nil )
861
+ policy , err := NewStaticPolicy (testCase .topo , testCase .numReservedCPUs , cpuset .New (), topologymanager .NewFakeManager (), nil )
862
+ if err != nil {
863
+ t .Fatalf ("NewStaticPolicy() failed: %v" , err )
864
+ }
847
865
848
866
st := & mockState {
849
867
assignments : testCase .stAssignments ,
@@ -852,8 +870,8 @@ func TestStaticPolicyRemove(t *testing.T) {
852
870
853
871
policy .RemoveContainer (st , testCase .podUID , testCase .containerName )
854
872
855
- if ! reflect . DeepEqual ( st .defaultCPUSet , testCase .expCSet ) {
856
- t .Errorf ("StaticPolicy RemoveContainer() error (%v). expected default cpuset %v but got %v " ,
873
+ if ! st .defaultCPUSet . Equals ( testCase .expCSet ) {
874
+ t .Errorf ("StaticPolicy RemoveContainer() error (%v). expected default cpuset %s but got %s " ,
857
875
testCase .description , testCase .expCSet , st .defaultCPUSet )
858
876
}
859
877
@@ -933,28 +951,31 @@ func TestTopologyAwareAllocateCPUs(t *testing.T) {
933
951
},
934
952
}
935
953
for _ , tc := range testCases {
936
- p , _ := NewStaticPolicy (tc .topo , 0 , cpuset .New (), topologymanager .NewFakeManager (), nil )
954
+ p , err := NewStaticPolicy (tc .topo , 0 , cpuset .New (), topologymanager .NewFakeManager (), nil )
955
+ if err != nil {
956
+ t .Fatalf ("NewStaticPolicy() failed: %v" , err )
957
+ }
937
958
policy := p .(* staticPolicy )
938
959
st := & mockState {
939
960
assignments : tc .stAssignments ,
940
961
defaultCPUSet : tc .stDefaultCPUSet ,
941
962
}
942
- err : = policy .Start (st )
963
+ err = policy .Start (st )
943
964
if err != nil {
944
965
t .Errorf ("StaticPolicy Start() error (%v)" , err )
945
966
continue
946
967
}
947
968
948
- cset , err := policy .allocateCPUs (st , tc .numRequested , tc .socketMask , cpuset .New ())
969
+ cpuAlloc , err := policy .allocateCPUs (st , tc .numRequested , tc .socketMask , cpuset .New ())
949
970
if err != nil {
950
971
t .Errorf ("StaticPolicy allocateCPUs() error (%v). expected CPUSet %v not error %v" ,
951
972
tc .description , tc .expCSet , err )
952
973
continue
953
974
}
954
975
955
- if ! reflect . DeepEqual ( tc .expCSet , cset ) {
976
+ if ! tc .expCSet . Equals ( cpuAlloc . CPUs ) {
956
977
t .Errorf ("StaticPolicy allocateCPUs() error (%v). expected CPUSet %v but got %v" ,
957
- tc .description , tc .expCSet , cset )
978
+ tc .description , tc .expCSet , cpuAlloc . CPUs )
958
979
}
959
980
}
960
981
}
@@ -1107,15 +1128,18 @@ func TestStaticPolicyAddWithResvList(t *testing.T) {
1107
1128
}
1108
1129
1109
1130
for _ , testCase := range testCases {
1110
- policy , _ := NewStaticPolicy (testCase .topo , testCase .numReservedCPUs , testCase .reserved , topologymanager .NewFakeManager (), nil )
1131
+ policy , err := NewStaticPolicy (testCase .topo , testCase .numReservedCPUs , testCase .reserved , topologymanager .NewFakeManager (), nil )
1132
+ if err != nil {
1133
+ t .Fatalf ("NewStaticPolicy() failed: %v" , err )
1134
+ }
1111
1135
1112
1136
st := & mockState {
1113
1137
assignments : testCase .stAssignments ,
1114
1138
defaultCPUSet : testCase .stDefaultCPUSet ,
1115
1139
}
1116
1140
1117
1141
container := & testCase .pod .Spec .Containers [0 ]
1118
- err : = policy .Allocate (st , testCase .pod , container )
1142
+ err = policy .Allocate (st , testCase .pod , container )
1119
1143
if ! reflect .DeepEqual (err , testCase .expErr ) {
1120
1144
t .Errorf ("StaticPolicy Allocate() error (%v). expected add error: %v but got: %v" ,
1121
1145
testCase .description , testCase .expErr , err )
@@ -1128,13 +1152,13 @@ func TestStaticPolicyAddWithResvList(t *testing.T) {
1128
1152
testCase .description , container .Name , st .assignments )
1129
1153
}
1130
1154
1131
- if ! reflect . DeepEqual ( cset , testCase .expCSet ) {
1132
- t .Errorf ("StaticPolicy Allocate() error (%v). expected cpuset %v but got %v " ,
1155
+ if ! cset . Equals ( testCase .expCSet ) {
1156
+ t .Errorf ("StaticPolicy Allocate() error (%v). expected cpuset %s but got %s " ,
1133
1157
testCase .description , testCase .expCSet , cset )
1134
1158
}
1135
1159
1136
1160
if ! cset .Intersection (st .defaultCPUSet ).IsEmpty () {
1137
- t .Errorf ("StaticPolicy Allocate() error (%v). expected cpuset %v to be disoint from the shared cpuset %v " ,
1161
+ t .Errorf ("StaticPolicy Allocate() error (%v). expected cpuset %s to be disoint from the shared cpuset %s " ,
1138
1162
testCase .description , cset , st .defaultCPUSet )
1139
1163
}
1140
1164
}
0 commit comments