github.com/kata-containers/runtime@v0.0.0-20210505125100-04f29832a923/virtcontainers/qemu_s390x_test.go (about) 1 // Copyright (c) 2018 IBM 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 6 package virtcontainers 7 8 import ( 9 "fmt" 10 "testing" 11 12 govmmQemu "github.com/kata-containers/govmm/qemu" 13 "github.com/kata-containers/runtime/virtcontainers/device/config" 14 "github.com/stretchr/testify/assert" 15 ) 16 17 func newTestQemu(machineType string) qemuArch { 18 config := HypervisorConfig{ 19 HypervisorMachineType: machineType, 20 } 21 return newQemuArch(config) 22 } 23 24 func TestQemuS390xCPUModel(t *testing.T) { 25 assert := assert.New(t) 26 s390x := newTestQemu(QemuCCWVirtio) 27 28 expectedOut := defaultCPUModel 29 model := s390x.cpuModel() 30 assert.Equal(expectedOut, model) 31 32 s390x.enableNestingChecks() 33 expectedOut = defaultCPUModel 34 model = s390x.cpuModel() 35 assert.Equal(expectedOut, model) 36 } 37 38 func TestQemuS390xMemoryTopology(t *testing.T) { 39 assert := assert.New(t) 40 s390x := newTestQemu(QemuCCWVirtio) 41 42 hostMem := uint64(1024) 43 mem := uint64(120) 44 slots := uint8(10) 45 expectedMemory := govmmQemu.Memory{ 46 Size: fmt.Sprintf("%dM", mem), 47 Slots: slots, 48 MaxMem: fmt.Sprintf("%dM", hostMem), 49 } 50 51 m := s390x.memoryTopology(mem, hostMem, slots) 52 assert.Equal(expectedMemory, m) 53 } 54 55 func TestQemuS390xAppendVhostUserDevice(t *testing.T) { 56 macAddress := "00:11:22:33:44:55:66" 57 qemu := qemuS390x{} 58 assert := assert.New(t) 59 60 vhostUserDevice := config.VhostUserDeviceAttrs{ 61 Type: config.VhostUserNet, 62 MacAddress: macAddress, 63 } 64 65 _, err := qemu.appendVhostUserDevice(nil, vhostUserDevice) 66 assert.Error(err) 67 }