k8s.io/kubernetes@v1.29.3/pkg/kubelet/cm/topologymanager/policy_restricted_test.go (about) 1 /* 2 Copyright 2019 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package topologymanager 18 19 import ( 20 "testing" 21 ) 22 23 func TestPolicyRestrictedName(t *testing.T) { 24 tcases := []struct { 25 name string 26 expected string 27 }{ 28 { 29 name: "New Restricted Policy", 30 expected: "restricted", 31 }, 32 } 33 numaInfo := commonNUMAInfoTwoNodes() 34 for _, tc := range tcases { 35 policy := &restrictedPolicy{bestEffortPolicy{numaInfo: numaInfo, opts: PolicyOptions{}}} 36 if policy.Name() != tc.expected { 37 t.Errorf("Expected Policy Name to be %s, got %s", tc.expected, policy.Name()) 38 } 39 } 40 } 41 42 func TestPolicyRestrictedCanAdmitPodResult(t *testing.T) { 43 tcases := []struct { 44 name string 45 hint TopologyHint 46 expected bool 47 }{ 48 { 49 name: "Preferred is set to false in topology hints", 50 hint: TopologyHint{nil, false}, 51 expected: false, 52 }, 53 { 54 name: "Preferred is set to true in topology hints", 55 hint: TopologyHint{nil, true}, 56 expected: true, 57 }, 58 } 59 60 for _, tc := range tcases { 61 numaInfo := commonNUMAInfoTwoNodes() 62 policy := &restrictedPolicy{bestEffortPolicy{numaInfo: numaInfo}} 63 result := policy.canAdmitPodResult(&tc.hint) 64 65 if result != tc.expected { 66 t.Errorf("Expected result to be %t, got %t", tc.expected, result) 67 } 68 } 69 } 70 71 func TestPolicyRestrictedMerge(t *testing.T) { 72 numaInfo := commonNUMAInfoFourNodes() 73 policy := &restrictedPolicy{bestEffortPolicy{numaInfo: numaInfo}} 74 75 tcases := commonPolicyMergeTestCases(numaInfo.Nodes) 76 tcases = append(tcases, policy.mergeTestCases(numaInfo.Nodes)...) 77 tcases = append(tcases, policy.mergeTestCasesNoPolicies(numaInfo.Nodes)...) 78 79 testPolicyMerge(policy, tcases, t) 80 } 81 82 func TestPolicyRestrictedMergeClosestNUMA(t *testing.T) { 83 numaInfo := commonNUMAInfoEightNodes() 84 policy := &restrictedPolicy{bestEffortPolicy{numaInfo: numaInfo, opts: PolicyOptions{PreferClosestNUMA: true}}} 85 86 tcases := commonPolicyMergeTestCases(numaInfo.Nodes) 87 tcases = append(tcases, policy.mergeTestCases(numaInfo.Nodes)...) 88 tcases = append(tcases, policy.mergeTestCasesClosestNUMA(numaInfo.Nodes)...) 89 90 testPolicyMerge(policy, tcases, t) 91 }