Skip to content

Commit 70e3732

Browse files
committed
libcontainer: intelrdt: add test cases for Intel RDT/MBA
Signed-off-by: Xiaochen Shen <[email protected]>
1 parent 8d6f5ad commit 70e3732

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

libcontainer/container_linux_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ func TestGetContainerStats(t *testing.T) {
148148
intelRdtManager: &mockIntelRdtManager{
149149
stats: &intelrdt.Stats{
150150
L3CacheSchema: "L3:0=f;1=f0",
151+
MemBwSchema: "MB:0=20;1=70",
151152
},
152153
},
153154
}
@@ -161,14 +162,22 @@ func TestGetContainerStats(t *testing.T) {
161162
if stats.CgroupStats.MemoryStats.Usage.Usage != 1024 {
162163
t.Fatalf("expected memory usage 1024 but recevied %d", stats.CgroupStats.MemoryStats.Usage.Usage)
163164
}
164-
if intelrdt.IsEnabled() {
165+
if intelrdt.IsCatEnabled() {
165166
if stats.IntelRdtStats == nil {
166167
t.Fatal("intel rdt stats are nil")
167168
}
168169
if stats.IntelRdtStats.L3CacheSchema != "L3:0=f;1=f0" {
169170
t.Fatalf("expected L3CacheSchema L3:0=f;1=f0 but recevied %s", stats.IntelRdtStats.L3CacheSchema)
170171
}
171172
}
173+
if intelrdt.IsMbaEnabled() {
174+
if stats.IntelRdtStats == nil {
175+
t.Fatal("intel rdt stats are nil")
176+
}
177+
if stats.IntelRdtStats.MemBwSchema != "MB:0=20;1=70" {
178+
t.Fatalf("expected MemBwSchema MB:0=20;1=70 but recevied %s", stats.IntelRdtStats.MemBwSchema)
179+
}
180+
}
172181
}
173182

174183
func TestGetContainerState(t *testing.T) {
@@ -210,6 +219,7 @@ func TestGetContainerState(t *testing.T) {
210219
intelRdtManager: &mockIntelRdtManager{
211220
stats: &intelrdt.Stats{
212221
L3CacheSchema: "L3:0=f0;1=f",
222+
MemBwSchema: "MB:0=70;1=20",
213223
},
214224
path: expectedIntelRdtPath,
215225
},
@@ -232,7 +242,7 @@ func TestGetContainerState(t *testing.T) {
232242
if memPath := paths["memory"]; memPath != expectedMemoryPath {
233243
t.Fatalf("expected memory path %q but received %q", expectedMemoryPath, memPath)
234244
}
235-
if intelrdt.IsEnabled() {
245+
if intelrdt.IsCatEnabled() || intelrdt.IsMbaEnabled() {
236246
intelRdtPath := state.IntelRdtPath
237247
if intelRdtPath == "" {
238248
t.Fatal("intel rdt path should not be empty")

libcontainer/intelrdt/intelrdt_test.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func TestIntelRdtSetL3CacheSchema(t *testing.T) {
11-
if !IsEnabled() {
11+
if !IsCatEnabled() {
1212
return
1313
}
1414

@@ -44,3 +44,41 @@ func TestIntelRdtSetL3CacheSchema(t *testing.T) {
4444
t.Fatal("Got the wrong value, set 'schemata' failed.")
4545
}
4646
}
47+
48+
func TestIntelRdtSetMemBwSchema(t *testing.T) {
49+
if !IsMbaEnabled() {
50+
return
51+
}
52+
53+
helper := NewIntelRdtTestUtil(t)
54+
defer helper.cleanup()
55+
56+
const (
57+
memBwSchemaBefore = "MB:0=20;1=70"
58+
memBwSchemeAfter = "MB:0=70;1=20"
59+
)
60+
61+
helper.writeFileContents(map[string]string{
62+
"schemata": memBwSchemaBefore + "\n",
63+
})
64+
65+
helper.IntelRdtData.config.IntelRdt.MemBwSchema = memBwSchemeAfter
66+
intelrdt := &IntelRdtManager{
67+
Config: helper.IntelRdtData.config,
68+
Path: helper.IntelRdtPath,
69+
}
70+
if err := intelrdt.Set(helper.IntelRdtData.config); err != nil {
71+
t.Fatal(err)
72+
}
73+
74+
tmpStrings, err := getIntelRdtParamString(helper.IntelRdtPath, "schemata")
75+
if err != nil {
76+
t.Fatalf("Failed to parse file 'schemata' - %s", err)
77+
}
78+
values := strings.Split(tmpStrings, "\n")
79+
value := values[0]
80+
81+
if value != memBwSchemeAfter {
82+
t.Fatal("Got the wrong value, set 'schemata' failed.")
83+
}
84+
}

0 commit comments

Comments
 (0)