mirror of
https://github.com/opencontainers/runc.git
synced 2025-10-13 03:03:56 +08:00

Since commit7296dc1712
, type intelRdtData is only used by tests, and since commit79d292b9f
, its only member is config. Change the test to use config directly, and remove the type. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
/*
|
|
* 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 (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/opencontainers/runc/libcontainer/configs"
|
|
)
|
|
|
|
type intelRdtTestUtil struct {
|
|
config *configs.Config
|
|
|
|
// Path to the mock Intel RDT "resource control" filesystem directory
|
|
IntelRdtPath string
|
|
|
|
t *testing.T
|
|
}
|
|
|
|
// Creates a new test util
|
|
func NewIntelRdtTestUtil(t *testing.T) *intelRdtTestUtil {
|
|
config := &configs.Config{
|
|
IntelRdt: &configs.IntelRdt{},
|
|
}
|
|
intelRdtRoot = t.TempDir()
|
|
testIntelRdtPath := filepath.Join(intelRdtRoot, "resctrl")
|
|
|
|
// Ensure the full mock Intel RDT "resource control" filesystem path exists
|
|
if err := os.MkdirAll(testIntelRdtPath, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return &intelRdtTestUtil{config: config, IntelRdtPath: testIntelRdtPath, t: t}
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
}
|
|
}
|