Skip to content

Commit

Permalink
topology-aware: fix uncompilable unit tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
  • Loading branch information
klihub committed Mar 15, 2024
1 parent b28c867 commit 58377bf
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 69 deletions.
53 changes: 0 additions & 53 deletions cmd/plugins/topology-aware/policy/hint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,56 +213,3 @@ func TestHintCpus(t *testing.T) {
})
}
}

func TestString(t *testing.T) {
tcases := []struct {
name string
fh fakehints
// maps are unordered, so there might be different legitimate results
expected1 string
expected2 string
}{
{
name: "Empty",
},
{
name: "non-empty CPUs",
fh: fakehints{
"key1": topology.Hints{
"testkey3": topology.Hint{ // TODO(rojkov): this is bug - this value gets ignored
CPUs: "2",
NUMAs: "2",
Sockets: "2",
},
"testkey2": topology.Hint{
CPUs: "2",
NUMAs: "2",
Sockets: "2",
},
},
"key2": topology.Hints{
"testkey3": topology.Hint{ // TODO(rojkov): this is bug - this value gets ignored
CPUs: "2",
NUMAs: "2",
Sockets: "2",
},
"testkey2": topology.Hint{
CPUs: "2",
NUMAs: "2",
Sockets: "2",
},
},
},
expected1: "key1=cpus:2/nodes:2/sockets:2;key2=cpus:2/nodes:2/sockets:2",
expected2: "key2=cpus:2/nodes:2/sockets:2;key1=cpus:2/nodes:2/sockets:2",
},
}
for _, tc := range tcases {
t.Run(tc.name, func(t *testing.T) {
actual := tc.fh.String()
if actual != tc.expected1 && actual != tc.expected2 {
t.Errorf("Expected %q, but got %q", tc.expected1, actual)
}
})
}
}
36 changes: 36 additions & 0 deletions cmd/plugins/topology-aware/policy/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ func (m *mockContainer) SetCpusetMems(string) {
func (m *mockContainer) SetMemoryLimit(int64) {
panic("unimplemented")
}
func (m *mockContainer) SetMemorySwap(int64) {
panic("unimplemented")
}
func (m *mockContainer) GetPendingAdjustment() *nri.ContainerAdjustment {
panic("unimplemented")
}
Expand Down Expand Up @@ -426,6 +429,36 @@ func (m *mockContainer) GetProcesses() ([]string, error) {
func (m *mockContainer) GetTasks() ([]string, error) {
panic("unimplemented")
}
func (m *mockContainer) GetCPUShares() int64 {
panic("unimplemented")
}
func (m *mockContainer) GetCPUQuota() int64 {
panic("unimplemented")
}
func (m *mockContainer) GetCPUPeriod() int64 {
panic("unimplemented")
}
func (m *mockContainer) GetCpusetCpus() string {
panic("unimplemented")
}
func (m *mockContainer) GetCpusetMems() string {
panic("unimplemented")
}
func (m *mockContainer) GetMemoryLimit() int64 {
panic("unimplemented")
}
func (m *mockContainer) GetMemorySwap() int64 {
panic("unimplemented")
}
func (m *mockContainer) GetCtime() time.Time {
panic("unimplemented")
}
func (m *mockContainer) PreserveCpuResources() bool {
return false
}
func (m *mockContainer) PreserveMemoryResources() bool {
return false
}

type mockPod struct {
name string
Expand Down Expand Up @@ -510,6 +543,9 @@ func (m *mockPod) GetProcesses(bool) ([]string, error) {
func (m *mockPod) GetTasks(bool) ([]string, error) {
panic("unimplemented")
}
func (m *mockPod) GetCtime() time.Time {
panic("unimplemented")
}

type mockCache struct {
returnValueForGetPolicyEntry bool
Expand Down
41 changes: 25 additions & 16 deletions cmd/plugins/topology-aware/policy/pools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"path"
"testing"

cfgapi "github.com/containers/nri-plugins/pkg/apis/config/v1alpha1/resmgr/policy/topologyaware"
"github.com/containers/nri-plugins/pkg/resmgr/cache"
policyapi "github.com/containers/nri-plugins/pkg/resmgr/policy"

Expand Down Expand Up @@ -373,17 +374,19 @@ func TestPoolCreation(t *testing.T) {
panic(err)
}

reserved, _ := resapi.ParseQuantity("750m")
policyOptions := &policyapi.BackendOptions{
Cache: &mockCache{},
System: sys,
Reserved: policyapi.ConstraintSet{
policyapi.DomainCPU: reserved,
Config: &cfgapi.Config{
ReservedResources: cfgapi.Constraints{
cfgapi.CPU: "750m",
},
},
}

log.EnableDebug(true)
policy := CreateTopologyAwarePolicy(policyOptions).(*policy)
policy := New().(*policy)
policy.Setup(policyOptions)
log.EnableDebug(false)

if policy.root.GetSupply().SharableCPUs().Size()+policy.root.GetSupply().IsolatedCPUs().Size()+policy.root.GetSupply().ReservedCPUs().Size() != tc.expectedRootNodeCPUs {
Expand Down Expand Up @@ -508,17 +511,19 @@ func TestWorkloadPlacement(t *testing.T) {
panic(err)
}

reserved, _ := resapi.ParseQuantity("750m")
policyOptions := &policyapi.BackendOptions{
Cache: &mockCache{},
System: sys,
Reserved: policyapi.ConstraintSet{
policyapi.DomainCPU: reserved,
Config: &cfgapi.Config{
ReservedResources: cfgapi.Constraints{
cfgapi.CPU: "750m",
},
},
}

log.EnableDebug(true)
policy := CreateTopologyAwarePolicy(policyOptions).(*policy)
policy := New().(*policy)
policy.Setup(policyOptions)
log.EnableDebug(false)

scores, filteredPools := policy.sortPoolsByScore(tc.req, tc.affinities)
Expand Down Expand Up @@ -660,17 +665,19 @@ func TestContainerMove(t *testing.T) {
panic(err)
}

reserved, _ := resapi.ParseQuantity("750m")
policyOptions := &policyapi.BackendOptions{
Cache: &mockCache{},
System: sys,
Reserved: policyapi.ConstraintSet{
policyapi.DomainCPU: reserved,
Config: &cfgapi.Config{
ReservedResources: cfgapi.Constraints{
cfgapi.CPU: "750m",
},
},
}

log.EnableDebug(true)
policy := CreateTopologyAwarePolicy(policyOptions).(*policy)
policy := New().(*policy)
policy.Setup(policyOptions)
log.EnableDebug(false)

grant1, err := policy.allocatePool(tc.container1, "")
Expand Down Expand Up @@ -931,17 +938,19 @@ func TestAffinities(t *testing.T) {
panic(err)
}

reserved, _ := resapi.ParseQuantity("750m")
policyOptions := &policyapi.BackendOptions{
Cache: &mockCache{},
System: sys,
Reserved: policyapi.ConstraintSet{
policyapi.DomainCPU: reserved,
Config: &cfgapi.Config{
ReservedResources: cfgapi.Constraints{
cfgapi.CPU: "750m",
},
},
}

log.EnableDebug(true)
policy := CreateTopologyAwarePolicy(policyOptions).(*policy)
policy := New().(*policy)
policy.Setup(policyOptions)
log.EnableDebug(false)

affinities := map[int]int32{}
Expand Down

0 comments on commit 58377bf

Please sign in to comment.