forked from jaypipes/ghw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pci_test.go
83 lines (77 loc) · 1.7 KB
/
pci_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
//
// Use and distribution licensed under the Apache license version 2.
//
// See the COPYING file in the root project directory for full text.
//
package ghw
import (
"os"
"reflect"
"testing"
)
func TestPCIAddressFromString(t *testing.T) {
tests := []struct {
addrStr string
expected *PCIAddress
}{
{
addrStr: "00:00.0",
expected: &PCIAddress{
Domain: "0000",
Bus: "00",
Slot: "00",
Function: "0",
},
},
{
addrStr: "0000:00:00.0",
expected: &PCIAddress{
Domain: "0000",
Bus: "00",
Slot: "00",
Function: "0",
},
},
{
addrStr: "0000:03:00.0",
expected: &PCIAddress{
Domain: "0000",
Bus: "03",
Slot: "00",
Function: "0",
},
},
{
addrStr: "0000:03:00.A",
expected: &PCIAddress{
Domain: "0000",
Bus: "03",
Slot: "00",
Function: "a",
},
},
}
for x, test := range tests {
got := PCIAddressFromString(test.addrStr)
if !reflect.DeepEqual(got, test.expected) {
t.Fatalf("Test #%d failed. Expected %v but got %v", x, test.expected, got)
}
}
}
func TestPCI(t *testing.T) {
if _, ok := os.LookupEnv("GHW_TESTING_SKIP_PCI"); ok {
t.Skip("Skipping PCI tests.")
}
info, err := PCI()
if err != nil {
t.Fatalf("Expected no error creating PciInfo, but got %v", err)
}
// Since we can't count on a specific device being present on the machine
// being tested (and we haven't built in fixtures/mocks for things yet)
// about all we can do is verify that the returned list of pointers to
// PCIDevice structs is non-empty
devs := info.ListDevices()
if len(devs) == 0 {
t.Fatalf("Expected to find >0 PCI devices from PCIInfo.ListDevices() but got 0.")
}
}