Skip to content

Commit

Permalink
topology-aware: update unit tests.
Browse files Browse the repository at this point in the history
Update unit tests after libmem conversion.

Signed-off-by: Krisztian Litkey <[email protected]>
  • Loading branch information
klihub committed Sep 2, 2024
1 parent 8755f93 commit e8e80d5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 397 deletions.
8 changes: 4 additions & 4 deletions cmd/plugins/topology-aware/policy/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ func TestAllocationMarshalling(t *testing.T) {
}{
{
name: "non-zero Exclusive",
data: []byte(`{"key1":{"Exclusive":"1","Part":1,"CPUType":0,"Container":"1","Pool":"testnode","MemoryPool":"testnode","MemType":"DRAM,PMEM,HBM","Memset":"","MemoryLimit":{},"ColdStart":0}}`),
data: []byte(`{"key1":{"Exclusive":"1","Part":1,"CPUType":0,"Container":"1","Pool":"testnode","MemoryPool":0,"MemType":"DRAM,PMEM,HBM","MemSize":0,"ColdStart":0}}`),
},
{
name: "zero Exclusive",
data: []byte(`{"key1":{"Exclusive":"","Part":1,"CPUType":0,"Container":"1","Pool":"testnode","MemoryPool":"testnode","MemType":"DRAM,PMEM,HBM","Memset":"","MemoryLimit":{},"ColdStart":0}}`),
data: []byte(`{"key1":{"Exclusive":"","Part":1,"CPUType":0,"Container":"1","Pool":"testnode","MemoryPool":0,"MemType":"DRAM,PMEM,HBM","MemSize":0,"ColdStart":0}}`),
},
}
for _, tc := range tcases {
Expand All @@ -104,8 +104,8 @@ func TestAllocationMarshalling(t *testing.T) {
node: node{
name: "testnode",
kind: UnknownNode,
noderes: newSupply(&node{}, cpuset.New(), cpuset.New(), cpuset.New(), 0, 0, createMemoryMap(0, 0, 0), createMemoryMap(0, 0, 0)),
freeres: newSupply(&node{}, cpuset.New(), cpuset.New(), cpuset.New(), 0, 0, createMemoryMap(0, 0, 0), createMemoryMap(0, 0, 0)),
noderes: newSupply(&node{}, cpuset.New(), cpuset.New(), cpuset.New(), 0, 0),
freeres: newSupply(&node{}, cpuset.New(), cpuset.New(), cpuset.New(), 0, 0),
},
},
},
Expand Down
26 changes: 16 additions & 10 deletions cmd/plugins/topology-aware/policy/coldstart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/containers/nri-plugins/pkg/resmgr/cache"
"github.com/containers/nri-plugins/pkg/resmgr/events"
libmem "github.com/containers/nri-plugins/pkg/resmgr/lib/memory"
policyapi "github.com/containers/nri-plugins/pkg/resmgr/policy"
system "github.com/containers/nri-plugins/pkg/sysfs"
idset "github.com/intel/goresctrl/pkg/utils"
Expand Down Expand Up @@ -62,8 +63,8 @@ func TestColdStart(t *testing.T) {
{
name: "three node cold start",
numaNodes: []system.Node{
&mockSystemNode{id: 1, memFree: 10000, memTotal: 10000, memType: system.MemoryTypeDRAM, distance: []int{5, 5, 1}},
&mockSystemNode{id: 2, memFree: 50000, memTotal: 50000, memType: system.MemoryTypePMEM, distance: []int{5, 1, 5}},
&mockSystemNode{id: 0, memFree: 10000, memTotal: 10000, memType: system.MemoryTypeDRAM, distance: []int{1, 5}},
&mockSystemNode{id: 1, memFree: 50000, memTotal: 50000, memType: system.MemoryTypePMEM, distance: []int{5, 1}},
},
container: &mockContainer{
name: "demo-coldstart-container",
Expand All @@ -77,8 +78,8 @@ func TestColdStart(t *testing.T) {
},
expectedColdStartTimeout: 1000 * time.Millisecond,
expectedDRAMNodeID: 101,
expectedDRAMSystemNodeID: idset.ID(1),
expectedPMEMSystemNodeID: idset.ID(2),
expectedDRAMSystemNodeID: 0,
expectedPMEMSystemNodeID: 1,
expectedPMEMNodeID: 102,
},
}
Expand All @@ -100,6 +101,11 @@ func TestColdStart(t *testing.T) {
}
policy.allocations.policy = policy
policy.options.SendEvent = sendEvent
ma, err := libmem.NewAllocator(libmem.WithSystemNodes(policy.sys))
if err != nil {
panic(err)
}
policy.memAllocator = ma

if err := policy.buildPoolsByTopology(); err != nil {
t.Errorf("failed to build topology pool")
Expand All @@ -115,8 +121,8 @@ func TestColdStart(t *testing.T) {

policy.allocations.grants[tc.container.GetID()] = grant

mems := grant.Memset()
if len(mems) != 1 || mems.Members()[0] != tc.expectedPMEMSystemNodeID {
mems := grant.GetMemoryZone()
if mems.Size() != 1 || mems.Slice()[0] != tc.expectedPMEMSystemNodeID {
t.Errorf("Expected one memory controller %v, got: %v", tc.expectedPMEMSystemNodeID, mems)
}

Expand All @@ -135,11 +141,11 @@ func TestColdStart(t *testing.T) {

time.Sleep(tc.expectedColdStartTimeout * 2)

newMems := grant.Memset()
if len(newMems) != 2 {
t.Errorf("Expected two memory controllers, got %d: %v", len(newMems), newMems)
newMems := grant.GetMemoryZone()
if newMems.Size() != 2 {
t.Errorf("Expected two memory controllers, got %d: %s", newMems.Size(), newMems)
}
if !newMems.Has(tc.expectedPMEMSystemNodeID) || !newMems.Has(tc.expectedDRAMSystemNodeID) {
if !newMems.Contains(tc.expectedPMEMSystemNodeID) || !newMems.Contains(tc.expectedDRAMSystemNodeID) {
t.Errorf("Didn't get all expected system nodes in mems, got: %v", newMems)
}
})
Expand Down
3 changes: 3 additions & 0 deletions cmd/plugins/topology-aware/policy/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ func (fake *mockSystem) OfflineCPUs() cpuset.CPUSet {
func (fake *mockSystem) CoreKindCPUs(sysfs.CoreKind) cpuset.CPUSet {
return cpuset.New()
}
func (fake *mockSystem) CoreKinds() []sysfs.CoreKind {
return nil
}
func (fake *mockSystem) AllThreadsForCPUs(cpuset.CPUSet) cpuset.CPUSet {
return cpuset.New()
}
Expand Down
Loading

0 comments on commit e8e80d5

Please sign in to comment.