Skip to content

Commit c019114

Browse files
committed
memorymanager:unit-tests for isAffinityViolatingNUMAAllocations function
Signed-off-by: Talor Itzhak <[email protected]>
1 parent 37399c8 commit c019114

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

pkg/kubelet/cm/memorymanager/policy_static_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3896,3 +3896,79 @@ func Test_getPodRequestedResources(t *testing.T) {
38963896
})
38973897
}
38983898
}
3899+
3900+
func Test_isAffinityViolatingNUMAAllocations(t *testing.T) {
3901+
testsCases := []struct {
3902+
description string
3903+
machineState map[int]*state.NUMANodeState
3904+
topologyHint *topologymanager.TopologyHint
3905+
isViolationExpected bool
3906+
}{
3907+
{
3908+
description: "violating NUMA allocations because given affinity asks for NUMA ID 1 which is on different cells group",
3909+
machineState: map[int]*state.NUMANodeState{
3910+
0: {
3911+
NumberOfAssignments: 1,
3912+
Cells: []int{0, 1},
3913+
},
3914+
1: {
3915+
NumberOfAssignments: 1,
3916+
Cells: []int{0, 1},
3917+
},
3918+
2: {
3919+
NumberOfAssignments: 1,
3920+
Cells: []int{2},
3921+
},
3922+
3: {
3923+
NumberOfAssignments: 0,
3924+
Cells: []int{3},
3925+
},
3926+
},
3927+
topologyHint: &topologymanager.TopologyHint{
3928+
NUMANodeAffinity: newNUMAAffinity(1, 2),
3929+
},
3930+
isViolationExpected: true,
3931+
},
3932+
{
3933+
description: "violating NUMA allocations because given affinity with multiple nodes asks for NUMA ID 1 which is used for a single NUMA node memory allocation",
3934+
machineState: map[int]*state.NUMANodeState{
3935+
0: {
3936+
NumberOfAssignments: 0,
3937+
Cells: []int{0, 1},
3938+
},
3939+
1: {
3940+
NumberOfAssignments: 1,
3941+
Cells: []int{1},
3942+
},
3943+
},
3944+
topologyHint: &topologymanager.TopologyHint{
3945+
NUMANodeAffinity: newNUMAAffinity(0, 1),
3946+
},
3947+
isViolationExpected: true,
3948+
},
3949+
{
3950+
description: "valid affinity, no prior assignments",
3951+
machineState: map[int]*state.NUMANodeState{
3952+
0: {
3953+
NumberOfAssignments: 0,
3954+
Cells: []int{0},
3955+
},
3956+
1: {
3957+
NumberOfAssignments: 0,
3958+
Cells: []int{1},
3959+
},
3960+
},
3961+
topologyHint: &topologymanager.TopologyHint{
3962+
NUMANodeAffinity: newNUMAAffinity(0, 1),
3963+
},
3964+
isViolationExpected: false,
3965+
},
3966+
}
3967+
for _, tc := range testsCases {
3968+
t.Run(tc.description, func(t *testing.T) {
3969+
if isAffinityViolatingNUMAAllocations(tc.machineState, tc.topologyHint.NUMANodeAffinity) != tc.isViolationExpected {
3970+
t.Errorf("isAffinityViolatingNUMAAllocations with affinity %v expected to return %t, got %t", tc.topologyHint.NUMANodeAffinity.GetBits(), tc.isViolationExpected, !tc.isViolationExpected)
3971+
}
3972+
})
3973+
}
3974+
}

0 commit comments

Comments
 (0)