-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libcontainer: add test cases for Intel RDT/CAT
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
- Loading branch information
1 parent
692f6e1
commit 4d2756c
Showing
4 changed files
with
198 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// +build linux | ||
|
||
package intelrdt | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestIntelRdtSetL3CacheSchema(t *testing.T) { | ||
if !IsIntelRdtEnabled() { | ||
return | ||
} | ||
|
||
helper := NewIntelRdtTestUtil(t) | ||
defer helper.cleanup() | ||
|
||
const ( | ||
l3CacheSchemaBefore = "L3:0=f;1=f0" | ||
l3CacheSchemeAfter = "L3:0=f0;1=f" | ||
) | ||
|
||
helper.writeFileContents(map[string]string{ | ||
"schemata": l3CacheSchemaBefore + "\n", | ||
}) | ||
|
||
helper.IntelRdtData.config.IntelRdt.L3CacheSchema = l3CacheSchemeAfter | ||
intelrdt := &IntelRdtManager{ | ||
Config: helper.IntelRdtData.config, | ||
Path: helper.IntelRdtPath, | ||
} | ||
if err := intelrdt.Set(helper.IntelRdtData.config); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
tmpStrings, err := getIntelRdtParamString(helper.IntelRdtPath, "schemata") | ||
if err != nil { | ||
t.Fatalf("Failed to parse file 'schemata' - %s", err) | ||
} | ||
values := strings.Split(tmpStrings, "\n") | ||
value := values[0] | ||
|
||
if value != l3CacheSchemeAfter { | ||
t.Fatal("Got the wrong value, set 'schemata' failed.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// +build linux | ||
|
||
/* | ||
* Utility for testing Intel RDT operations. | ||
* Creates a mock of the Intel RDT "resource control" filesystem for the duration of the test. | ||
*/ | ||
package intelrdt | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/opencontainers/runc/libcontainer/configs" | ||
) | ||
|
||
type intelRdtTestUtil struct { | ||
// intelRdt data to use in tests | ||
IntelRdtData *intelRdtData | ||
|
||
// Path to the mock Intel RDT "resource control" filesystem directory | ||
IntelRdtPath string | ||
|
||
// Temporary directory to store mock Intel RDT "resource control" filesystem | ||
tempDir string | ||
t *testing.T | ||
} | ||
|
||
// Creates a new test util | ||
func NewIntelRdtTestUtil(t *testing.T) *intelRdtTestUtil { | ||
d := &intelRdtData{ | ||
config: &configs.Config{ | ||
IntelRdt: &configs.IntelRdt{}, | ||
}, | ||
} | ||
tempDir, err := ioutil.TempDir("", "intelrdt_test") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
d.root = tempDir | ||
testIntelRdtPath := filepath.Join(d.root, "resctrl") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Ensure the full mock Intel RDT "resource control" filesystem path exists | ||
err = os.MkdirAll(testIntelRdtPath, 0755) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return &intelRdtTestUtil{IntelRdtData: d, IntelRdtPath: testIntelRdtPath, tempDir: tempDir, t: t} | ||
} | ||
|
||
func (c *intelRdtTestUtil) cleanup() { | ||
os.RemoveAll(c.tempDir) | ||
} | ||
|
||
// Write the specified contents on the mock of the specified Intel RDT "resource control" files | ||
func (c *intelRdtTestUtil) writeFileContents(fileContents map[string]string) { | ||
for file, contents := range fileContents { | ||
err := writeFile(c.IntelRdtPath, file, contents) | ||
if err != nil { | ||
c.t.Fatal(err) | ||
} | ||
} | ||
} |