mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-23 05:58:04 +00:00
qemu: add appendMemoryKnobs helper
To fix travis failure about cyclomatic complexity in appendKnobs(). Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
parent
8aeca15388
commit
e66a9b481b
38
qemu/qemu.go
38
qemu/qemu.go
@ -1468,23 +1468,7 @@ func (config *Config) appendKernel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) appendKnobs() {
|
func (config *Config) appendMemoryKnobs() {
|
||||||
if config.Knobs.NoUserConfig == true {
|
|
||||||
config.qemuParams = append(config.qemuParams, "-no-user-config")
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.Knobs.NoDefaults == true {
|
|
||||||
config.qemuParams = append(config.qemuParams, "-nodefaults")
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.Knobs.NoGraphic == true {
|
|
||||||
config.qemuParams = append(config.qemuParams, "-nographic")
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.Knobs.Daemonize == true {
|
|
||||||
config.qemuParams = append(config.qemuParams, "-daemonize")
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.Knobs.HugePages == true {
|
if config.Knobs.HugePages == true {
|
||||||
if config.Memory.Size != "" {
|
if config.Memory.Size != "" {
|
||||||
dimmName := "dimm1"
|
dimmName := "dimm1"
|
||||||
@ -1525,6 +1509,26 @@ func (config *Config) appendKnobs() {
|
|||||||
config.qemuParams = append(config.qemuParams, numaMemParam)
|
config.qemuParams = append(config.qemuParams, numaMemParam)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (config *Config) appendKnobs() {
|
||||||
|
if config.Knobs.NoUserConfig == true {
|
||||||
|
config.qemuParams = append(config.qemuParams, "-no-user-config")
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Knobs.NoDefaults == true {
|
||||||
|
config.qemuParams = append(config.qemuParams, "-nodefaults")
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Knobs.NoGraphic == true {
|
||||||
|
config.qemuParams = append(config.qemuParams, "-nographic")
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Knobs.Daemonize == true {
|
||||||
|
config.qemuParams = append(config.qemuParams, "-daemonize")
|
||||||
|
}
|
||||||
|
|
||||||
|
config.appendMemoryKnobs()
|
||||||
|
|
||||||
if config.Knobs.Realtime == true {
|
if config.Knobs.Realtime == true {
|
||||||
config.qemuParams = append(config.qemuParams, "-realtime")
|
config.qemuParams = append(config.qemuParams, "-realtime")
|
||||||
|
@ -28,7 +28,12 @@ const volumeUUID = "67d86208-b46c-4465-9018-e14187d4010"
|
|||||||
|
|
||||||
func testAppend(structure interface{}, expected string, t *testing.T) {
|
func testAppend(structure interface{}, expected string, t *testing.T) {
|
||||||
var config Config
|
var config Config
|
||||||
|
testConfigAppend(&config, structure, expected, t)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func testConfigAppend(config *Config, structure interface{}, expected string, t *testing.T) {
|
||||||
switch s := structure.(type) {
|
switch s := structure.(type) {
|
||||||
case Machine:
|
case Machine:
|
||||||
config.Machine = s
|
config.Machine = s
|
||||||
@ -425,6 +430,97 @@ func TestAppendKnobsAllFalse(t *testing.T) {
|
|||||||
testAppend(knobs, knobsString, t)
|
testAppend(knobs, knobsString, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAppendMemoryHugePages(t *testing.T) {
|
||||||
|
conf := &Config{
|
||||||
|
Memory: Memory{
|
||||||
|
Size: "1G",
|
||||||
|
Slots: 8,
|
||||||
|
MaxMem: "3G",
|
||||||
|
Path: "foobar",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
memString := "-m 1G,slots=8,maxmem=3G"
|
||||||
|
testConfigAppend(conf, conf.Memory, memString, t)
|
||||||
|
|
||||||
|
knobs := Knobs{
|
||||||
|
HugePages: true,
|
||||||
|
MemPrealloc: true,
|
||||||
|
FileBackedMem: true,
|
||||||
|
FileBackedMemShared: true,
|
||||||
|
}
|
||||||
|
knobsString := "-object memory-backend-file,id=dimm1,size=1G,mem-path=/dev/hugepages,share=on,prealloc=on -numa node,memdev=dimm1"
|
||||||
|
mlockFalseString := "-realtime mlock=off"
|
||||||
|
|
||||||
|
testConfigAppend(conf, knobs, memString+" "+knobsString+" "+mlockFalseString, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAppendMemoryMemPrealloc(t *testing.T) {
|
||||||
|
conf := &Config{
|
||||||
|
Memory: Memory{
|
||||||
|
Size: "1G",
|
||||||
|
Slots: 8,
|
||||||
|
MaxMem: "3G",
|
||||||
|
Path: "foobar",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
memString := "-m 1G,slots=8,maxmem=3G"
|
||||||
|
testConfigAppend(conf, conf.Memory, memString, t)
|
||||||
|
|
||||||
|
knobs := Knobs{
|
||||||
|
MemPrealloc: true,
|
||||||
|
FileBackedMem: true,
|
||||||
|
FileBackedMemShared: true,
|
||||||
|
}
|
||||||
|
knobsString := "-object memory-backend-ram,id=dimm1,size=1G,prealloc=on -device pc-dimm,id=dimm1,memdev=dimm1"
|
||||||
|
mlockFalseString := "-realtime mlock=off"
|
||||||
|
|
||||||
|
testConfigAppend(conf, knobs, memString+" "+knobsString+" "+mlockFalseString, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAppendMemoryFileBackedMemShared(t *testing.T) {
|
||||||
|
conf := &Config{
|
||||||
|
Memory: Memory{
|
||||||
|
Size: "1G",
|
||||||
|
Slots: 8,
|
||||||
|
MaxMem: "3G",
|
||||||
|
Path: "foobar",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
memString := "-m 1G,slots=8,maxmem=3G"
|
||||||
|
testConfigAppend(conf, conf.Memory, memString, t)
|
||||||
|
|
||||||
|
knobs := Knobs{
|
||||||
|
FileBackedMem: true,
|
||||||
|
FileBackedMemShared: true,
|
||||||
|
}
|
||||||
|
knobsString := "-object memory-backend-file,id=dimm1,size=1G,mem-path=foobar,share=on -numa node,memdev=dimm1"
|
||||||
|
mlockFalseString := "-realtime mlock=off"
|
||||||
|
|
||||||
|
testConfigAppend(conf, knobs, memString+" "+knobsString+" "+mlockFalseString, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAppendMemoryFileBackedMem(t *testing.T) {
|
||||||
|
conf := &Config{
|
||||||
|
Memory: Memory{
|
||||||
|
Size: "1G",
|
||||||
|
Slots: 8,
|
||||||
|
MaxMem: "3G",
|
||||||
|
Path: "foobar",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
memString := "-m 1G,slots=8,maxmem=3G"
|
||||||
|
testConfigAppend(conf, conf.Memory, memString, t)
|
||||||
|
|
||||||
|
knobs := Knobs{
|
||||||
|
FileBackedMem: true,
|
||||||
|
FileBackedMemShared: false,
|
||||||
|
}
|
||||||
|
knobsString := "-object memory-backend-file,id=dimm1,size=1G,mem-path=foobar -numa node,memdev=dimm1"
|
||||||
|
mlockFalseString := "-realtime mlock=off"
|
||||||
|
|
||||||
|
testConfigAppend(conf, knobs, memString+" "+knobsString+" "+mlockFalseString, t)
|
||||||
|
}
|
||||||
|
|
||||||
var kernelString = "-kernel /opt/vmlinux.container -initrd /opt/initrd.container -append root=/dev/pmem0p1 rootflags=dax,data=ordered,errors=remount-ro rw rootfstype=ext4 tsc=reliable"
|
var kernelString = "-kernel /opt/vmlinux.container -initrd /opt/initrd.container -append root=/dev/pmem0p1 rootflags=dax,data=ordered,errors=remount-ro rw rootfstype=ext4 tsc=reliable"
|
||||||
|
|
||||||
func TestAppendKernel(t *testing.T) {
|
func TestAppendKernel(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user