Add a new TestTakeByTopologyNUMADistributed() test to the CPUManager

As part of this, pull out all of the existing "TakeByTopology" tests and have
them be called by the original TestTakeByTopologyNUMAPacked() as well as the
new TestTakeByTopologyNUMADistributed() test. In a subsequent commit, we will
add some tests that should differ between these two algorithms.

Signed-off-by: Kevin Klues <kklues@nvidia.com>
This commit is contained in:
Kevin Klues
2021-10-13 14:07:49 +00:00
parent 876dd9b078
commit eb78e2406b

View File

@@ -506,15 +506,17 @@ func TestCPUAccumulatorTake(t *testing.T) {
} }
} }
func TestTakeByTopologyNUMAPacked(t *testing.T) { type takeByTopologyTestCase struct {
testCases := []struct { description string
description string topo *topology.CPUTopology
topo *topology.CPUTopology availableCPUs cpuset.CPUSet
availableCPUs cpuset.CPUSet numCPUs int
numCPUs int expErr string
expErr string expResult cpuset.CPUSet
expResult cpuset.CPUSet }
}{
func commonTakeByTopologyTestCases(t *testing.T) []takeByTopologyTestCase {
return []takeByTopologyTestCase{
{ {
"take more cpus than are available from single socket with HT", "take more cpus than are available from single socket with HT",
topoSingleSocketHT, topoSingleSocketHT,
@@ -628,7 +630,10 @@ func TestTakeByTopologyNUMAPacked(t *testing.T) {
mustParseCPUSet(t, "10-39,50-79"), mustParseCPUSet(t, "10-39,50-79"),
}, },
} }
}
func TestTakeByTopologyNUMAPacked(t *testing.T) {
testCases := commonTakeByTopologyTestCases(t)
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) { t.Run(tc.description, func(t *testing.T) {
result, err := takeByTopologyNUMAPacked(tc.topo, tc.availableCPUs, tc.numCPUs) result, err := takeByTopologyNUMAPacked(tc.topo, tc.availableCPUs, tc.numCPUs)
@@ -642,6 +647,21 @@ func TestTakeByTopologyNUMAPacked(t *testing.T) {
} }
} }
func TestTakeByTopologyNUMADistributed(t *testing.T) {
testCases := commonTakeByTopologyTestCases(t)
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
result, err := takeByTopologyNUMADistributed(tc.topo, tc.availableCPUs, tc.numCPUs)
if tc.expErr != "" && err.Error() != tc.expErr {
t.Errorf("expected error to be [%v] but it was [%v]", tc.expErr, err)
}
if !result.Equals(tc.expResult) {
t.Errorf("expected result [%s] to equal [%s]", result, tc.expResult)
}
})
}
}
func mustParseCPUSet(t *testing.T, s string) cpuset.CPUSet { func mustParseCPUSet(t *testing.T, s string) cpuset.CPUSet {
cpus, err := cpuset.Parse(s) cpus, err := cpuset.Parse(s)
if err != nil { if err != nil {