github.com/kubewharf/katalyst-core@v0.5.3/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/util_test.go (about)

     1  //go:build linux
     2  // +build linux
     3  
     4  /*
     5  Copyright 2022 The Katalyst Authors.
     6  
     7  Licensed under the Apache License, Version 2.0 (the "License");
     8  you may not use this file except in compliance with the License.
     9  You may obtain a copy of the License at
    10  
    11      http://www.apache.org/licenses/LICENSE-2.0
    12  
    13  Unless required by applicable law or agreed to in writing, software
    14  distributed under the License is distributed on an "AS IS" BASIS,
    15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  See the License for the specific language governing permissions and
    17  limitations under the License.
    18  */
    19  
    20  package state
    21  
    22  import (
    23  	"io/ioutil"
    24  	"os"
    25  	"testing"
    26  
    27  	"github.com/stretchr/testify/require"
    28  	pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1"
    29  
    30  	"github.com/kubewharf/katalyst-api/pkg/consts"
    31  	cpuconsts "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/consts"
    32  	"github.com/kubewharf/katalyst-core/pkg/util/machine"
    33  )
    34  
    35  func TestGenerateCPUMachineStateByPodEntries(t *testing.T) {
    36  	t.Parallel()
    37  
    38  	as := require.New(t)
    39  	cpuTopology, err := machine.GenerateDummyCPUTopology(16, 2, 4)
    40  	as.Nil(err)
    41  
    42  	testName := "test"
    43  
    44  	testCases := []struct {
    45  		description          string
    46  		podEntries           PodEntries
    47  		expectedMachineState NUMANodeMap
    48  		cpuTopology          *machine.CPUTopology
    49  	}{
    50  		{
    51  			description: "only one pod entry",
    52  			podEntries: PodEntries{
    53  				"373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{
    54  					testName: &AllocationInfo{
    55  						PodUid:                   "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
    56  						PodNamespace:             testName,
    57  						PodName:                  testName,
    58  						ContainerName:            testName,
    59  						ContainerType:            pluginapi.ContainerType_MAIN.String(),
    60  						ContainerIndex:           0,
    61  						RampUp:                   false,
    62  						OwnerPoolName:            PoolNameShare,
    63  						AllocationResult:         machine.MustParse("1,3-4,9,11-12"),
    64  						OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"),
    65  						TopologyAwareAssignments: map[int]machine.CPUSet{
    66  							0: machine.NewCPUSet(1, 9),
    67  							1: machine.NewCPUSet(3, 11),
    68  							2: machine.NewCPUSet(4, 12),
    69  						},
    70  						OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
    71  							0: machine.NewCPUSet(1, 9),
    72  							1: machine.NewCPUSet(3, 11),
    73  							2: machine.NewCPUSet(4, 12),
    74  						},
    75  						Labels: map[string]string{
    76  							consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
    77  						},
    78  						Annotations: map[string]string{
    79  							consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
    80  						},
    81  						QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
    82  						RequestQuantity: 2,
    83  					},
    84  				},
    85  				"ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{
    86  					testName: &AllocationInfo{
    87  						PodUid:                   "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
    88  						PodNamespace:             testName,
    89  						PodName:                  testName,
    90  						ContainerName:            testName,
    91  						ContainerType:            pluginapi.ContainerType_MAIN.String(),
    92  						ContainerIndex:           0,
    93  						RampUp:                   false,
    94  						OwnerPoolName:            PoolNameShare,
    95  						AllocationResult:         machine.MustParse("1,3-4,9,11-12"),
    96  						OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"),
    97  						TopologyAwareAssignments: map[int]machine.CPUSet{
    98  							0: machine.NewCPUSet(1, 9),
    99  							1: machine.NewCPUSet(3, 11),
   100  							2: machine.NewCPUSet(4, 12),
   101  						},
   102  						OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   103  							0: machine.NewCPUSet(1, 9),
   104  							1: machine.NewCPUSet(3, 11),
   105  							2: machine.NewCPUSet(4, 12),
   106  						},
   107  						Labels: map[string]string{
   108  							consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   109  						},
   110  						Annotations: map[string]string{
   111  							consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   112  						},
   113  						QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
   114  						RequestQuantity: 2,
   115  					},
   116  				},
   117  				"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
   118  					testName: &AllocationInfo{
   119  						PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
   120  						PodNamespace:             testName,
   121  						PodName:                  testName,
   122  						ContainerName:            testName,
   123  						ContainerType:            pluginapi.ContainerType_MAIN.String(),
   124  						ContainerIndex:           0,
   125  						RampUp:                   false,
   126  						OwnerPoolName:            PoolNameReclaim,
   127  						AllocationResult:         machine.MustParse("5-8,10,13-15"),
   128  						OriginalAllocationResult: machine.MustParse("5-8,10,13-15"),
   129  						TopologyAwareAssignments: map[int]machine.CPUSet{
   130  							0: machine.NewCPUSet(8),
   131  							1: machine.NewCPUSet(10),
   132  							2: machine.NewCPUSet(5, 13),
   133  							3: machine.NewCPUSet(6, 7, 14, 15),
   134  						},
   135  						OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   136  							0: machine.NewCPUSet(8),
   137  							1: machine.NewCPUSet(10),
   138  							2: machine.NewCPUSet(5, 13),
   139  							3: machine.NewCPUSet(6, 7, 14, 15),
   140  						},
   141  						Labels: map[string]string{
   142  							consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   143  						},
   144  						Annotations: map[string]string{
   145  							consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   146  						},
   147  						QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
   148  						RequestQuantity: 2,
   149  					},
   150  				},
   151  				PoolNameReclaim: ContainerEntries{
   152  					"": &AllocationInfo{
   153  						PodUid:                   PoolNameReclaim,
   154  						OwnerPoolName:            PoolNameReclaim,
   155  						AllocationResult:         machine.MustParse("5-8,10,13-15"),
   156  						OriginalAllocationResult: machine.MustParse("5-8,10,13-15"),
   157  						TopologyAwareAssignments: map[int]machine.CPUSet{
   158  							0: machine.NewCPUSet(8),
   159  							1: machine.NewCPUSet(10),
   160  							2: machine.NewCPUSet(5, 13),
   161  							3: machine.NewCPUSet(6, 7, 14, 15),
   162  						},
   163  						OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   164  							0: machine.NewCPUSet(8),
   165  							1: machine.NewCPUSet(10),
   166  							2: machine.NewCPUSet(5, 13),
   167  							3: machine.NewCPUSet(6, 7, 14, 15),
   168  						},
   169  					},
   170  				},
   171  				PoolNameShare: ContainerEntries{
   172  					"": &AllocationInfo{
   173  						PodUid:                   PoolNameShare,
   174  						OwnerPoolName:            PoolNameShare,
   175  						AllocationResult:         machine.MustParse("1,3-4,9,11-12"),
   176  						OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"),
   177  						TopologyAwareAssignments: map[int]machine.CPUSet{
   178  							0: machine.NewCPUSet(1, 9),
   179  							1: machine.NewCPUSet(3, 11),
   180  							2: machine.NewCPUSet(4, 12),
   181  						},
   182  						OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   183  							0: machine.NewCPUSet(1, 9),
   184  							1: machine.NewCPUSet(3, 11),
   185  							2: machine.NewCPUSet(4, 12),
   186  						},
   187  					},
   188  				},
   189  			},
   190  			expectedMachineState: NUMANodeMap{
   191  				0: &NUMANodeState{
   192  					DefaultCPUSet:   cpuTopology.CPUDetails.CPUsInNUMANodes(0).Clone(),
   193  					AllocatedCPUSet: machine.NewCPUSet(),
   194  					PodEntries: PodEntries{
   195  						"373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{
   196  							testName: &AllocationInfo{
   197  								PodUid:                   "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
   198  								PodNamespace:             testName,
   199  								PodName:                  testName,
   200  								ContainerName:            testName,
   201  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
   202  								ContainerIndex:           0,
   203  								RampUp:                   false,
   204  								OwnerPoolName:            PoolNameShare,
   205  								AllocationResult:         machine.NewCPUSet(1, 9),
   206  								OriginalAllocationResult: machine.NewCPUSet(1, 9),
   207  								TopologyAwareAssignments: map[int]machine.CPUSet{
   208  									0: machine.NewCPUSet(1, 9),
   209  								},
   210  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   211  									0: machine.NewCPUSet(1, 9),
   212  								},
   213  								Labels: map[string]string{
   214  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   215  								},
   216  								Annotations: map[string]string{
   217  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   218  								},
   219  								QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
   220  								RequestQuantity: 2,
   221  							},
   222  						},
   223  						"ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{
   224  							testName: &AllocationInfo{
   225  								PodUid:                   "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
   226  								PodNamespace:             testName,
   227  								PodName:                  testName,
   228  								ContainerName:            testName,
   229  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
   230  								ContainerIndex:           0,
   231  								RampUp:                   false,
   232  								OwnerPoolName:            PoolNameShare,
   233  								AllocationResult:         machine.NewCPUSet(1, 9),
   234  								OriginalAllocationResult: machine.NewCPUSet(1, 9),
   235  								TopologyAwareAssignments: map[int]machine.CPUSet{
   236  									0: machine.NewCPUSet(1, 9),
   237  								},
   238  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   239  									0: machine.NewCPUSet(1, 9),
   240  								},
   241  								Labels: map[string]string{
   242  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   243  								},
   244  								Annotations: map[string]string{
   245  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   246  								},
   247  								QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
   248  								RequestQuantity: 2,
   249  							},
   250  						},
   251  						"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
   252  							testName: &AllocationInfo{
   253  								PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
   254  								PodNamespace:             testName,
   255  								PodName:                  testName,
   256  								ContainerName:            testName,
   257  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
   258  								ContainerIndex:           0,
   259  								RampUp:                   false,
   260  								OwnerPoolName:            PoolNameReclaim,
   261  								AllocationResult:         machine.MustParse("8"),
   262  								OriginalAllocationResult: machine.MustParse("8"),
   263  								TopologyAwareAssignments: map[int]machine.CPUSet{
   264  									0: machine.NewCPUSet(8),
   265  								},
   266  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   267  									0: machine.NewCPUSet(8),
   268  								},
   269  								Labels: map[string]string{
   270  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   271  								},
   272  								Annotations: map[string]string{
   273  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   274  								},
   275  								QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
   276  								RequestQuantity: 2,
   277  							},
   278  						},
   279  					},
   280  				},
   281  				1: &NUMANodeState{
   282  					DefaultCPUSet:   cpuTopology.CPUDetails.CPUsInNUMANodes(1).Clone(),
   283  					AllocatedCPUSet: machine.NewCPUSet(),
   284  					PodEntries: PodEntries{
   285  						"373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{
   286  							testName: &AllocationInfo{
   287  								PodUid:                   "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
   288  								PodNamespace:             testName,
   289  								PodName:                  testName,
   290  								ContainerName:            testName,
   291  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
   292  								ContainerIndex:           0,
   293  								RampUp:                   false,
   294  								OwnerPoolName:            PoolNameShare,
   295  								AllocationResult:         machine.MustParse("3,11"),
   296  								OriginalAllocationResult: machine.MustParse("3,11"),
   297  								TopologyAwareAssignments: map[int]machine.CPUSet{
   298  									1: machine.NewCPUSet(3, 11),
   299  								},
   300  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   301  									1: machine.NewCPUSet(3, 11),
   302  								},
   303  								Labels: map[string]string{
   304  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   305  								},
   306  								Annotations: map[string]string{
   307  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   308  								},
   309  								QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
   310  								RequestQuantity: 2,
   311  							},
   312  						},
   313  						"ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{
   314  							testName: &AllocationInfo{
   315  								PodUid:                   "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
   316  								PodNamespace:             testName,
   317  								PodName:                  testName,
   318  								ContainerName:            testName,
   319  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
   320  								ContainerIndex:           0,
   321  								RampUp:                   false,
   322  								OwnerPoolName:            PoolNameShare,
   323  								AllocationResult:         machine.MustParse("3,11"),
   324  								OriginalAllocationResult: machine.MustParse("3,11"),
   325  								TopologyAwareAssignments: map[int]machine.CPUSet{
   326  									1: machine.NewCPUSet(3, 11),
   327  								},
   328  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   329  									1: machine.NewCPUSet(3, 11),
   330  								},
   331  								Labels: map[string]string{
   332  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   333  								},
   334  								Annotations: map[string]string{
   335  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   336  								},
   337  								QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
   338  								RequestQuantity: 2,
   339  							},
   340  						},
   341  						"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
   342  							testName: &AllocationInfo{
   343  								PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
   344  								PodNamespace:             testName,
   345  								PodName:                  testName,
   346  								ContainerName:            testName,
   347  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
   348  								ContainerIndex:           0,
   349  								RampUp:                   false,
   350  								OwnerPoolName:            PoolNameReclaim,
   351  								AllocationResult:         machine.MustParse("10"),
   352  								OriginalAllocationResult: machine.MustParse("10"),
   353  								TopologyAwareAssignments: map[int]machine.CPUSet{
   354  									1: machine.NewCPUSet(10),
   355  								},
   356  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   357  									1: machine.NewCPUSet(10),
   358  								},
   359  								Labels: map[string]string{
   360  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   361  								},
   362  								Annotations: map[string]string{
   363  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   364  								},
   365  								QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
   366  								RequestQuantity: 2,
   367  							},
   368  						},
   369  					},
   370  				},
   371  				2: &NUMANodeState{
   372  					DefaultCPUSet:   cpuTopology.CPUDetails.CPUsInNUMANodes(2).Clone(),
   373  					AllocatedCPUSet: machine.NewCPUSet(),
   374  					PodEntries: PodEntries{
   375  						"373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{
   376  							testName: &AllocationInfo{
   377  								PodUid:                   "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
   378  								PodNamespace:             testName,
   379  								PodName:                  testName,
   380  								ContainerName:            testName,
   381  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
   382  								ContainerIndex:           0,
   383  								RampUp:                   false,
   384  								OwnerPoolName:            PoolNameShare,
   385  								AllocationResult:         machine.MustParse("4,12"),
   386  								OriginalAllocationResult: machine.MustParse("4,12"),
   387  								TopologyAwareAssignments: map[int]machine.CPUSet{
   388  									2: machine.NewCPUSet(4, 12),
   389  								},
   390  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   391  									2: machine.NewCPUSet(4, 12),
   392  								},
   393  								Labels: map[string]string{
   394  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   395  								},
   396  								Annotations: map[string]string{
   397  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   398  								},
   399  								QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
   400  								RequestQuantity: 2,
   401  							},
   402  						},
   403  						"ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{
   404  							testName: &AllocationInfo{
   405  								PodUid:                   "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
   406  								PodNamespace:             testName,
   407  								PodName:                  testName,
   408  								ContainerName:            testName,
   409  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
   410  								ContainerIndex:           0,
   411  								RampUp:                   false,
   412  								OwnerPoolName:            PoolNameShare,
   413  								AllocationResult:         machine.MustParse("4,12"),
   414  								OriginalAllocationResult: machine.MustParse("4,12"),
   415  								TopologyAwareAssignments: map[int]machine.CPUSet{
   416  									2: machine.NewCPUSet(4, 12),
   417  								},
   418  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   419  									2: machine.NewCPUSet(4, 12),
   420  								},
   421  								Labels: map[string]string{
   422  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   423  								},
   424  								Annotations: map[string]string{
   425  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   426  								},
   427  								QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
   428  								RequestQuantity: 2,
   429  							},
   430  						},
   431  						"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
   432  							testName: &AllocationInfo{
   433  								PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
   434  								PodNamespace:             testName,
   435  								PodName:                  testName,
   436  								ContainerName:            testName,
   437  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
   438  								ContainerIndex:           0,
   439  								RampUp:                   false,
   440  								OwnerPoolName:            PoolNameReclaim,
   441  								AllocationResult:         machine.MustParse("5,13"),
   442  								OriginalAllocationResult: machine.MustParse("5,13"),
   443  								TopologyAwareAssignments: map[int]machine.CPUSet{
   444  									2: machine.NewCPUSet(5, 13),
   445  								},
   446  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   447  									2: machine.NewCPUSet(5, 13),
   448  								},
   449  								Labels: map[string]string{
   450  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   451  								},
   452  								Annotations: map[string]string{
   453  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   454  								},
   455  								QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
   456  								RequestQuantity: 2,
   457  							},
   458  						},
   459  					},
   460  				},
   461  				3: &NUMANodeState{
   462  					DefaultCPUSet:   cpuTopology.CPUDetails.CPUsInNUMANodes(3).Clone(),
   463  					AllocatedCPUSet: machine.NewCPUSet(),
   464  					PodEntries: PodEntries{
   465  						"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
   466  							testName: &AllocationInfo{
   467  								PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
   468  								PodNamespace:             testName,
   469  								PodName:                  testName,
   470  								ContainerName:            testName,
   471  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
   472  								ContainerIndex:           0,
   473  								RampUp:                   false,
   474  								OwnerPoolName:            PoolNameReclaim,
   475  								AllocationResult:         machine.MustParse("6,7,14,15"),
   476  								OriginalAllocationResult: machine.MustParse("6,7,14,15"),
   477  								TopologyAwareAssignments: map[int]machine.CPUSet{
   478  									3: machine.NewCPUSet(6, 7, 14, 15),
   479  								},
   480  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   481  									3: machine.NewCPUSet(6, 7, 14, 15),
   482  								},
   483  								Labels: map[string]string{
   484  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   485  								},
   486  								Annotations: map[string]string{
   487  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   488  								},
   489  								QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
   490  								RequestQuantity: 2,
   491  							},
   492  						},
   493  					},
   494  				},
   495  			},
   496  			cpuTopology: cpuTopology,
   497  		},
   498  	}
   499  
   500  	for _, tc := range testCases {
   501  		tmpDir, err := ioutil.TempDir("", "checkpoint-TestGenerateCPUMachineStateByPodEntries")
   502  		as.Nil(err)
   503  
   504  		machineState, err := GenerateMachineStateFromPodEntries(tc.cpuTopology, tc.podEntries, cpuconsts.CPUResourcePluginPolicyNameDynamic)
   505  		as.Nil(err)
   506  
   507  		as.Equalf(tc.expectedMachineState, machineState, "failed in test case: %s", tc.description)
   508  
   509  		_ = os.RemoveAll(tmpDir)
   510  	}
   511  }
   512  
   513  func TestGetSpecifiedPoolName(t *testing.T) {
   514  	t.Parallel()
   515  
   516  	type args struct {
   517  		qosLevel               string
   518  		cpusetEnhancementValue string
   519  	}
   520  	tests := []struct {
   521  		name string
   522  		args args
   523  		want string
   524  	}{
   525  		{
   526  			name: "shared_cores with empty cpusetEnhancementValue",
   527  			args: args{
   528  				qosLevel: consts.PodAnnotationQoSLevelSharedCores,
   529  			},
   530  			want: PoolNameShare,
   531  		},
   532  		{
   533  			name: "shared_cores with non-empty cpusetEnhancementValue",
   534  			args: args{
   535  				qosLevel:               consts.PodAnnotationQoSLevelSharedCores,
   536  				cpusetEnhancementValue: "offline",
   537  			},
   538  			want: "offline",
   539  		},
   540  		{
   541  			name: "dedicated_cores with empty cpusetEnhancementValue",
   542  			args: args{
   543  				qosLevel: consts.PodAnnotationQoSLevelDedicatedCores,
   544  			},
   545  			want: PoolNameDedicated,
   546  		},
   547  		{
   548  			name: "reclaimed_cores with empty cpusetEnhancementValue",
   549  			args: args{
   550  				qosLevel: consts.PodAnnotationQoSLevelReclaimedCores,
   551  			},
   552  			want: PoolNameReclaim,
   553  		},
   554  	}
   555  	for _, tt := range tests {
   556  		tt := tt
   557  		t.Run(tt.name, func(t *testing.T) {
   558  			t.Parallel()
   559  			if got := GetSpecifiedPoolName(tt.args.qosLevel, tt.args.cpusetEnhancementValue); got != tt.want {
   560  				t.Errorf("GetSpecifiedPoolName() = %v, want %v", got, tt.want)
   561  			}
   562  		})
   563  	}
   564  }