2021-08-23 13:14:53 +00:00
|
|
|
//go:build !windows
|
2015-07-09 22:12:36 +00:00
|
|
|
|
2018-02-05 21:05:59 +00:00
|
|
|
package runconfig // import "github.com/docker/docker/runconfig"
|
2015-07-01 08:16:36 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2015-12-18 18:36:17 +00:00
|
|
|
|
2016-09-06 18:18:12 +00:00
|
|
|
"github.com/docker/docker/api/types/container"
|
2016-06-07 19:05:43 +00:00
|
|
|
"github.com/docker/docker/pkg/sysinfo"
|
2015-07-01 08:16:36 +00:00
|
|
|
)
|
|
|
|
|
2016-06-07 19:05:43 +00:00
|
|
|
func TestValidateResources(t *testing.T) {
|
|
|
|
type resourceTest struct {
|
2020-05-22 21:18:06 +00:00
|
|
|
ConfigCPURealtimePeriod int64
|
|
|
|
ConfigCPURealtimeRuntime int64
|
|
|
|
SysInfoCPURealtime bool
|
|
|
|
ErrorExpected bool
|
|
|
|
FailureMsg string
|
2016-06-07 19:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tests := []resourceTest{
|
|
|
|
{
|
2020-05-22 21:18:06 +00:00
|
|
|
ConfigCPURealtimePeriod: 1000,
|
|
|
|
ConfigCPURealtimeRuntime: 1000,
|
|
|
|
SysInfoCPURealtime: true,
|
|
|
|
ErrorExpected: false,
|
|
|
|
FailureMsg: "Expected valid configuration",
|
2016-06-07 19:05:43 +00:00
|
|
|
},
|
|
|
|
{
|
2020-05-22 21:18:06 +00:00
|
|
|
ConfigCPURealtimePeriod: 5000,
|
|
|
|
ConfigCPURealtimeRuntime: 5000,
|
|
|
|
SysInfoCPURealtime: false,
|
|
|
|
ErrorExpected: true,
|
|
|
|
FailureMsg: "Expected failure when cpu-rt-period is set but kernel doesn't support it",
|
2016-06-07 19:05:43 +00:00
|
|
|
},
|
|
|
|
{
|
2020-05-22 21:18:06 +00:00
|
|
|
ConfigCPURealtimePeriod: 5000,
|
|
|
|
ConfigCPURealtimeRuntime: 5000,
|
|
|
|
SysInfoCPURealtime: false,
|
|
|
|
ErrorExpected: true,
|
|
|
|
FailureMsg: "Expected failure when cpu-rt-runtime is set but kernel doesn't support it",
|
2016-06-07 19:05:43 +00:00
|
|
|
},
|
|
|
|
{
|
2020-05-22 21:18:06 +00:00
|
|
|
ConfigCPURealtimePeriod: 5000,
|
|
|
|
ConfigCPURealtimeRuntime: 10000,
|
|
|
|
SysInfoCPURealtime: true,
|
|
|
|
ErrorExpected: true,
|
|
|
|
FailureMsg: "Expected failure when cpu-rt-runtime is greater than cpu-rt-period",
|
2016-06-07 19:05:43 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, rt := range tests {
|
|
|
|
var hc container.HostConfig
|
|
|
|
hc.Resources.CPURealtimePeriod = rt.ConfigCPURealtimePeriod
|
|
|
|
hc.Resources.CPURealtimeRuntime = rt.ConfigCPURealtimeRuntime
|
|
|
|
|
|
|
|
var si sysinfo.SysInfo
|
2020-05-22 21:18:06 +00:00
|
|
|
si.CPURealtime = rt.SysInfoCPURealtime
|
2016-06-07 19:05:43 +00:00
|
|
|
|
2017-03-10 17:39:22 +00:00
|
|
|
if err := validateResources(&hc, &si); (err != nil) != rt.ErrorExpected {
|
2016-06-07 19:05:43 +00:00
|
|
|
t.Fatal(rt.FailureMsg, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|