-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrngdevice_test.go
79 lines (59 loc) · 1.81 KB
/
rngdevice_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
package qcli
import (
"fmt"
"testing"
)
func TestAppendVirtioRng(t *testing.T) {
var objectString = "-object rng-random,id=rng0"
var deviceString = "-device " + string(VirtioRng)
rngDevice := RngDevice{
ID: "rng0",
Driver: VirtioRng,
ROMFile: romfile,
Addr: "3",
}
deviceString += "-" + rngDevice.Transport.getName(nil) + ",rng=rng0,addr=0x03"
if romfile != "" {
deviceString = deviceString + ",romfile=efi-virtio.rom"
}
if rngDevice.Transport.isVirtioCCW(nil) {
rngDevice.DevNo = DevNo
deviceString += ",devno=" + rngDevice.DevNo
}
testAppend(rngDevice, objectString+" "+deviceString, t)
rngDevice.Filename = "/dev/urandom"
objectString += ",filename=" + rngDevice.Filename
testAppend(rngDevice, objectString+" "+deviceString, t)
rngDevice.MaxBytes = 20
deviceString += fmt.Sprintf(",max-bytes=%d", rngDevice.MaxBytes)
testAppend(rngDevice, objectString+" "+deviceString, t)
rngDevice.Period = 500
deviceString += fmt.Sprintf(",period=%d", rngDevice.Period)
testAppend(rngDevice, objectString+" "+deviceString, t)
}
func TestVirtioRngValid(t *testing.T) {
rng := RngDevice{}
if err := rng.Valid(); err == nil {
t.Fatalf("rng should not be valid when ID is empty")
}
rng.ID = "rng0"
if err := rng.Valid(); err == nil {
t.Fatalf("rng should not be valid when Driver is empty")
}
rng.Driver = VirtioRng
if err := rng.Valid(); err != nil {
t.Fatalf("rng should be valid")
}
}
func TestAppendVirtioRngPCIEBusAddr(t *testing.T) {
deviceRngPCIeBusAddr := "-object rng-random,id=rng0,filename=/dev/urandom -device virtio-rng-pci,rng=rng0,bus=pcie.0,addr=0x03"
rngDevice := RngDevice{
Driver: VirtioRng,
ID: "rng0",
Bus: "pcie.0",
Addr: "3",
Transport: TransportPCI,
Filename: RngDevUrandom,
}
testAppend(rngDevice, deviceRngPCIeBusAddr, t)
}