Skip to content

Commit f352280

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

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

libcontainer/intelrdt/intelrdt_test.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestIntelRdtSet(t *testing.T) {
105105

106106
for _, tc := range tcs {
107107
t.Run(tc.name, func(t *testing.T) {
108-
helper := NewIntelRdtTestUtil(t)
108+
helper := NewIntelRdtTestUtil(t, "clos-1")
109109
helper.config.IntelRdt = tc.config
110110

111111
intelrdt := newManager(helper.config, "", helper.IntelRdtPath)
@@ -183,19 +183,19 @@ func TestApply(t *testing.T) {
183183

184184
for _, tt := range tests {
185185
t.Run(tt.name, func(t *testing.T) {
186-
NewIntelRdtTestUtil(t)
187186
id := "abcd-1234"
188-
closPath := filepath.Join(intelRdtRoot, id)
187+
closName := id
189188
if tt.config.ClosID != "" {
190-
closPath = filepath.Join(intelRdtRoot, tt.config.ClosID)
189+
closName = tt.config.ClosID
191190
}
192191

192+
preConfiguredClos := ""
193193
if tt.precreateClos {
194-
if err := os.MkdirAll(filepath.Join(closPath, "mon_groups"), 0o755); err != nil {
195-
t.Fatal(err)
196-
}
194+
preConfiguredClos = closName
197195
}
198-
m := newManager(&configs.Config{IntelRdt: &tt.config}, id, closPath)
196+
NewIntelRdtTestUtil(t, preConfiguredClos)
197+
198+
m := newManager(&configs.Config{IntelRdt: &tt.config}, id, filepath.Join(intelRdtRoot, closName))
199199
err := m.Apply(pid)
200200
if tt.isError && err == nil {
201201
t.Fatal("expected error, got nil")
@@ -281,18 +281,16 @@ func TestDestroy(t *testing.T) {
281281

282282
for _, tt := range tests {
283283
t.Run(tt.name, func(t *testing.T) {
284-
NewIntelRdtTestUtil(t)
285-
286284
id := "abcd-1234"
287-
closPath := filepath.Join(intelRdtRoot, id)
285+
closName := id
286+
preConfiguredClos := ""
288287
if tt.config.ClosID != "" {
289-
closPath = filepath.Join(intelRdtRoot, tt.config.ClosID)
290-
// Pre-create the CLOS directory
291-
if err := os.MkdirAll(filepath.Join(closPath, "mon_groups"), 0o755); err != nil {
292-
t.Fatal(err)
293-
}
288+
closName = tt.config.ClosID
289+
preConfiguredClos = closName
294290
}
295-
m := newManager(&configs.Config{IntelRdt: &tt.config}, id, closPath)
291+
NewIntelRdtTestUtil(t, preConfiguredClos)
292+
293+
m := newManager(&configs.Config{IntelRdt: &tt.config}, id, filepath.Join(intelRdtRoot, closName))
296294
if err := m.Apply(1234); err != nil {
297295
t.Fatalf("Apply() failed: %v", err)
298296
}

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,11 +32,12 @@ 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
}

0 commit comments

Comments
 (0)