-
Notifications
You must be signed in to change notification settings - Fork 2
/
chardevice_test.go
121 lines (110 loc) · 3.11 KB
/
chardevice_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
package qcli
import "testing"
var (
deviceCharDeviceBackendFile = "-chardev file,id=serial0,path=/tmp/serial.log"
deviceCharDeviceBackendSocket = "-chardev socket,id=serial0,path=/tmp/console.sock,server=on,wait=off"
deviceCharDeviceBackendStdioMux = "-chardev stdio,id=serial0,mux=on,signal=off"
deviceCharDeviceMultiple = "-chardev socket,id=serial0,path=/tmp/console.sock,server=on,wait=off -chardev socket,id=monitor0,path=/tmp/monitor.sock,server=on,wait=off"
deviceCharDevicePCIDriver = "-serial none -chardev socket,id=serial0,path=/tmp/console.sock,server=on,wait=off -device pci-serial,id=pciser0,chardev=serial0"
deviceCharDevicePCIDriver2x = "-serial none -chardev socket,id=serial0,path=/tmp/console.sock,server=on,wait=off -device pci-serial-2x,id=pciser0,chardev1=serial0"
)
func TestBadCharDevice(t *testing.T) {
c := &Config{
CharDevices: []CharDevice{
CharDevice{},
CharDevice{
ID: "id1",
Path: "",
},
CharDevice{
ID: "",
Path: "/tmp/foo",
},
},
}
c.appendDevices()
if len(c.qemuParams) != 0 {
t.Errorf("Expected empty qemuParams for BadCharDevices, found %s", c.qemuParams)
}
}
func TestAppendCharDeviceFile(t *testing.T) {
chardev := CharDevice{
Driver: LegacySerial,
Backend: File,
ID: "serial0",
Path: "/tmp/serial.log",
}
testAppend(chardev, deviceCharDeviceBackendFile, t)
}
func TestAppendCharDeviceBackendStdioMux(t *testing.T) {
chardev := CharDevice{
Driver: LegacySerial,
Backend: Stdio,
ID: "serial0",
Mux: "on",
Signal: "off",
}
testAppend(chardev, deviceCharDeviceBackendStdioMux, t)
}
func TestAppendCharDeviceBackendSocket(t *testing.T) {
chardev := CharDevice{
Driver: LegacySerial,
Backend: Socket,
ID: "serial0",
Path: "/tmp/console.sock",
}
testAppend(chardev, deviceCharDeviceBackendSocket, t)
}
func TestAppendMultipleCharDevices(t *testing.T) {
c := &Config{}
serial := CharDevice{
Driver: LegacySerial,
Backend: Socket,
ID: "serial0",
Path: "/tmp/console.sock",
}
mon := CharDevice{
Driver: LegacySerial,
Backend: Socket,
ID: "monitor0",
Path: "/tmp/monitor.sock",
}
c.CharDevices = []CharDevice{serial, mon}
testConfig(c, deviceCharDeviceMultiple, t)
}
func TestAppendPCIDriver1x(t *testing.T) {
c := &Config{}
serial := CharDevice{
Driver: PCISerialDevice,
Backend: Socket,
ID: "serial0",
Path: "/tmp/console.sock",
}
pcidev := SerialDevice{
Driver: PCISerialDevice,
ID: "pciser0",
ChardevIDs: []string{"serial0"},
MaxPorts: 1,
}
c.CharDevices = []CharDevice{serial}
c.SerialDevices = []SerialDevice{pcidev}
testConfig(c, deviceCharDevicePCIDriver, t)
}
func TestAppendPCIDriver2x1(t *testing.T) {
c := &Config{}
serial := CharDevice{
Driver: PCISerialDevice,
Backend: Socket,
ID: "serial0",
Path: "/tmp/console.sock",
}
pcidev := SerialDevice{
Driver: PCISerialDevice,
ID: "pciser0",
ChardevIDs: []string{"serial0"},
MaxPorts: 2,
}
c.CharDevices = []CharDevice{serial}
c.SerialDevices = []SerialDevice{pcidev}
testConfig(c, deviceCharDevicePCIDriver2x, t)
}