mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53:57 +08:00
2d2ae8809c
The whole struct intelRdtStatus with its methods and a sync.Once is not needed, since intelrtd.Is*Enabled methods are already run-once (or use run-once and a simple comparison). Yet it is still needed for the test to fake values returned by *Enabled. Simplify to use func pointers which a test case overwrites. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
118 lines
2.3 KiB
Go
118 lines
2.3 KiB
Go
package validate
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/opencontainers/runc/libcontainer/configs"
|
|
"github.com/opencontainers/runc/libcontainer/intelrdt"
|
|
)
|
|
|
|
func TestValidateIntelRdt(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
rdtEnabled bool
|
|
catEnabled bool
|
|
mbaEnabled bool
|
|
config *configs.IntelRdt
|
|
isErr bool
|
|
}{
|
|
{
|
|
name: "rdt not supported, no config",
|
|
},
|
|
{
|
|
name: "rdt not supported, with config",
|
|
config: &configs.IntelRdt{},
|
|
isErr: true,
|
|
},
|
|
{
|
|
name: "empty config",
|
|
rdtEnabled: true,
|
|
config: &configs.IntelRdt{},
|
|
},
|
|
{
|
|
name: "root clos",
|
|
rdtEnabled: true,
|
|
config: &configs.IntelRdt{
|
|
ClosID: "/",
|
|
},
|
|
},
|
|
{
|
|
name: "invalid ClosID (.)",
|
|
rdtEnabled: true,
|
|
config: &configs.IntelRdt{
|
|
ClosID: ".",
|
|
},
|
|
isErr: true,
|
|
},
|
|
{
|
|
name: "invalid ClosID (..)",
|
|
rdtEnabled: true,
|
|
config: &configs.IntelRdt{
|
|
ClosID: "..",
|
|
},
|
|
isErr: true,
|
|
},
|
|
{
|
|
name: "invalid ClosID (contains /)",
|
|
rdtEnabled: true,
|
|
config: &configs.IntelRdt{
|
|
ClosID: "foo/bar",
|
|
},
|
|
isErr: true,
|
|
},
|
|
{
|
|
name: "cat not supported",
|
|
rdtEnabled: true,
|
|
config: &configs.IntelRdt{
|
|
L3CacheSchema: "0=ff",
|
|
},
|
|
isErr: true,
|
|
},
|
|
{
|
|
name: "mba not supported",
|
|
rdtEnabled: true,
|
|
config: &configs.IntelRdt{
|
|
MemBwSchema: "0=100",
|
|
},
|
|
isErr: true,
|
|
},
|
|
{
|
|
name: "valid config",
|
|
rdtEnabled: true,
|
|
catEnabled: true,
|
|
mbaEnabled: true,
|
|
config: &configs.IntelRdt{
|
|
ClosID: "clos-1",
|
|
L3CacheSchema: "0=ff",
|
|
MemBwSchema: "0=100",
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Cleanup(func() {
|
|
intelRdtIsEnabled = intelrdt.IsEnabled
|
|
intelRdtIsCATEnabled = intelrdt.IsCATEnabled
|
|
intelRdtIsMBAEnabled = intelrdt.IsMBAEnabled
|
|
})
|
|
intelRdtIsEnabled = func() bool { return tc.rdtEnabled }
|
|
intelRdtIsCATEnabled = func() bool { return tc.catEnabled }
|
|
intelRdtIsMBAEnabled = func() bool { return tc.mbaEnabled }
|
|
|
|
config := &configs.Config{
|
|
Rootfs: "/var",
|
|
IntelRdt: tc.config,
|
|
}
|
|
|
|
err := Validate(config)
|
|
if tc.isErr && err == nil {
|
|
t.Error("expected error, got nil")
|
|
}
|
|
if !tc.isErr && err != nil {
|
|
t.Error(err)
|
|
}
|
|
})
|
|
}
|
|
}
|