mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-19 07:14:22 +01: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:
@@ -28,7 +28,12 @@ const volumeUUID = "67d86208-b46c-4465-9018-e14187d4010"
|
||||
|
||||
func testAppend(structure interface{}, expected string, t *testing.T) {
|
||||
var config Config
|
||||
testConfigAppend(&config, structure, expected, t)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func testConfigAppend(config *Config, structure interface{}, expected string, t *testing.T) {
|
||||
switch s := structure.(type) {
|
||||
case Machine:
|
||||
config.Machine = s
|
||||
@@ -425,6 +430,97 @@ func TestAppendKnobsAllFalse(t *testing.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"
|
||||
|
||||
func TestAppendKernel(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user