forked from kata-containers/kata-containers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qemu_s390x_test.go
150 lines (123 loc) · 3.65 KB
/
qemu_s390x_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright (c) 2018 IBM
//
// SPDX-License-Identifier: Apache-2.0
//
package virtcontainers
import (
"context"
"fmt"
"testing"
govmmQemu "github.com/kata-containers/govmm/qemu"
"github.com/stretchr/testify/assert"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
)
func newTestQemu(assert *assert.Assertions, machineType string) qemuArch {
config := HypervisorConfig{
HypervisorMachineType: machineType,
}
arch, err := newQemuArch(config)
assert.NoError(err)
return arch
}
func TestQemuS390xCPUModel(t *testing.T) {
assert := assert.New(t)
s390x := newTestQemu(assert, QemuCCWVirtio)
expectedOut := defaultCPUModel
model := s390x.cpuModel()
assert.Equal(expectedOut, model)
s390x.enableNestingChecks()
expectedOut = defaultCPUModel
model = s390x.cpuModel()
assert.Equal(expectedOut, model)
}
func TestQemuS390xMemoryTopology(t *testing.T) {
assert := assert.New(t)
s390x := newTestQemu(assert, QemuCCWVirtio)
hostMem := uint64(1024)
mem := uint64(120)
slots := uint8(10)
expectedMemory := govmmQemu.Memory{
Size: fmt.Sprintf("%dM", mem),
Slots: slots,
MaxMem: fmt.Sprintf("%dM", hostMem),
}
m := s390x.memoryTopology(mem, hostMem, slots)
assert.Equal(expectedMemory, m)
}
func TestQemuS390xAppendVhostUserDevice(t *testing.T) {
assert := assert.New(t)
qemu := newTestQemu(assert, QemuCCWVirtio)
// test devices that should not work
for _, deviceType := range []config.DeviceType{config.VhostUserSCSI, config.VhostUserNet, config.VhostUserBlk} {
vhostUserDevice := config.VhostUserDeviceAttrs{
Type: deviceType,
}
_, err := qemu.appendVhostUserDevice(context.Background(), nil, vhostUserDevice)
assert.Error(err)
}
// test vhost user fs (virtio-fs)
socketPath := "nonexistentpath.sock"
id := "deadbeef"
tag := "shared"
var cacheSize uint32 = 0
expected := []govmmQemu.Device{
govmmQemu.VhostUserDevice{
SocketPath: socketPath,
CharDevID: fmt.Sprintf("char-%s", id),
TypeDevID: fmt.Sprintf("fs-%s", id),
Tag: tag,
CacheSize: cacheSize,
VhostUserType: govmmQemu.VhostUserFS,
DevNo: "fe.0.0001",
},
}
vhostUserDevice := config.VhostUserDeviceAttrs{
DevID: id,
SocketPath: socketPath,
Type: config.VhostUserFS,
Tag: tag,
CacheSize: cacheSize,
}
var devices []govmmQemu.Device
devices, err := qemu.appendVhostUserDevice(context.Background(), devices, vhostUserDevice)
assert.NoError(err)
assert.Equal(devices, expected)
}
func TestQemuS390xAppendProtectionDevice(t *testing.T) {
assert := assert.New(t)
s390x := newTestQemu(assert, QemuCCWVirtio)
var devices []govmmQemu.Device
var bios, firmware string
var err error
devices, bios, err = s390x.appendProtectionDevice(devices, firmware)
assert.NoError(err)
// no protection
assert.Empty(bios)
// PEF protection
s390x.(*qemuS390x).protection = pefProtection
devices, bios, err = s390x.appendProtectionDevice(devices, firmware)
assert.Error(err)
assert.Empty(bios)
// TDX protection
s390x.(*qemuS390x).protection = tdxProtection
devices, bios, err = s390x.appendProtectionDevice(devices, firmware)
assert.Error(err)
assert.Empty(bios)
// SEV protection
s390x.(*qemuS390x).protection = sevProtection
devices, bios, err = s390x.appendProtectionDevice(devices, firmware)
assert.Error(err)
assert.Empty(bios)
// Secure Execution protection
s390x.(*qemuS390x).protection = seProtection
devices, bios, err = s390x.appendProtectionDevice(devices, firmware)
assert.NoError(err)
assert.Empty(bios)
expectedOut := []govmmQemu.Device{
govmmQemu.Object{
Type: govmmQemu.SecExecGuest,
ID: secExecID,
},
}
assert.Equal(expectedOut, devices)
}