Skip to content

Commit bb35f6c

Browse files
committed
libcontainer/intelrdt: make mock clos name an arg of test helper
Signed-off-by: Markus Lehtonen <[email protected]>
1 parent 04b55ac commit bb35f6c

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

libcontainer/intelrdt/intelrdt_test.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
func TestIntelRdtSetL3CacheSchema(t *testing.T) {
14-
helper := NewIntelRdtTestUtil(t)
14+
helper := NewIntelRdtTestUtil(t, "clos-1")
1515

1616
const (
1717
l3CacheSchemaBefore = "L3:0=f;1=f0"
@@ -41,7 +41,7 @@ func TestIntelRdtSetL3CacheSchema(t *testing.T) {
4141
}
4242

4343
func TestIntelRdtSetMemBwSchema(t *testing.T) {
44-
helper := NewIntelRdtTestUtil(t)
44+
helper := NewIntelRdtTestUtil(t, "clos-1")
4545

4646
const (
4747
memBwSchemaBefore = "MB:0=20;1=70"
@@ -71,7 +71,7 @@ func TestIntelRdtSetMemBwSchema(t *testing.T) {
7171
}
7272

7373
func TestIntelRdtSetMemBwScSchema(t *testing.T) {
74-
helper := NewIntelRdtTestUtil(t)
74+
helper := NewIntelRdtTestUtil(t, "clos-1")
7575

7676
const (
7777
memBwScSchemaBefore = "MB:0=5000;1=7000"
@@ -157,19 +157,19 @@ func TestApply(t *testing.T) {
157157

158158
for _, tt := range tests {
159159
t.Run(tt.name, func(t *testing.T) {
160-
NewIntelRdtTestUtil(t)
161160
id := "abcd-1234"
162-
closPath := filepath.Join(intelRdtRoot, id)
161+
closName := id
163162
if tt.config.ClosID != "" {
164-
closPath = filepath.Join(intelRdtRoot, tt.config.ClosID)
163+
closName = tt.config.ClosID
165164
}
166165

166+
preConfiguredClos := ""
167167
if tt.precreateClos {
168-
if err := os.MkdirAll(filepath.Join(closPath, "mon_groups"), 0o755); err != nil {
169-
t.Fatal(err)
170-
}
168+
preConfiguredClos = closName
171169
}
172-
m := newManager(&configs.Config{IntelRdt: &tt.config}, id, closPath)
170+
NewIntelRdtTestUtil(t, preConfiguredClos)
171+
172+
m := newManager(&configs.Config{IntelRdt: &tt.config}, id, filepath.Join(intelRdtRoot, closName))
173173
err := m.Apply(pid)
174174
if tt.isError && err == nil {
175175
t.Fatal("expected error, got nil")
@@ -255,18 +255,16 @@ func TestDestroy(t *testing.T) {
255255

256256
for _, tt := range tests {
257257
t.Run(tt.name, func(t *testing.T) {
258-
NewIntelRdtTestUtil(t)
259-
260258
id := "abcd-1234"
261-
closPath := filepath.Join(intelRdtRoot, id)
259+
closName := id
260+
preConfiguredClos := ""
262261
if tt.config.ClosID != "" {
263-
closPath = filepath.Join(intelRdtRoot, tt.config.ClosID)
264-
// Pre-create the CLOS directory
265-
if err := os.MkdirAll(filepath.Join(closPath, "mon_groups"), 0o755); err != nil {
266-
t.Fatal(err)
267-
}
262+
closName = tt.config.ClosID
263+
preConfiguredClos = closName
268264
}
269-
m := newManager(&configs.Config{IntelRdt: &tt.config}, id, closPath)
265+
NewIntelRdtTestUtil(t, preConfiguredClos)
266+
267+
m := newManager(&configs.Config{IntelRdt: &tt.config}, id, filepath.Join(intelRdtRoot, closName))
270268
if err := m.Apply(1234); err != nil {
271269
t.Fatalf("Apply() failed: %v", err)
272270
}

libcontainer/intelrdt/util_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import (
1515
type intelRdtTestUtil struct {
1616
config *configs.Config
1717

18-
// Path to the mock Intel RDT "resource control" filesystem directory
18+
// Path to the mock pre-existing CLOS (or resctrl root if no CLOS is specified)
1919
IntelRdtPath string
2020

2121
t *testing.T
2222
}
2323

24-
// Creates a new test util
25-
func NewIntelRdtTestUtil(t *testing.T) *intelRdtTestUtil {
24+
// Creates a new test util. If mockClosName is non-empty, a mock CLOS with that name will be created.
25+
func NewIntelRdtTestUtil(t *testing.T, mockClosName string) *intelRdtTestUtil {
2626
config := &configs.Config{
2727
IntelRdt: &configs.IntelRdt{},
2828
}
@@ -32,12 +32,13 @@ func NewIntelRdtTestUtil(t *testing.T) *intelRdtTestUtil {
3232
// Make sure Root() won't even try to parse mountinfo.
3333
rootOnce.Do(func() {})
3434

35-
testIntelRdtPath := filepath.Join(intelRdtRoot, "resctrl")
35+
testIntelRdtPath := filepath.Join(intelRdtRoot, mockClosName)
3636

37-
// Ensure the full mock Intel RDT "resource control" filesystem path exists
38-
if err := os.MkdirAll(testIntelRdtPath, 0o755); err != nil {
37+
// Ensure the mocked CLOS exists
38+
if err := os.MkdirAll(filepath.Join(testIntelRdtPath, "mon_groups"), 0o755); err != nil {
3939
t.Fatal(err)
4040
}
41+
4142
return &intelRdtTestUtil{config: config, IntelRdtPath: testIntelRdtPath, t: t}
4243
}
4344

0 commit comments

Comments
 (0)