Skip to content

Commit 37ab771

Browse files
authored
Merge pull request #327 from eliaskoromilas/fix-class-lookup
Fix class name lookups
2 parents dac2f19 + f17c871 commit 37ab771

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

pkg/pci/pci_linux.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ func parseModaliasData(data string) *deviceModaliasInfo {
160160
productID := strings.ToLower(data[18:22])
161161
subvendorID := strings.ToLower(data[28:32])
162162
subproductID := strings.ToLower(data[38:42])
163-
classID := data[44:46]
164-
subclassID := data[48:50]
165-
progIfaceID := data[51:53]
163+
classID := strings.ToLower(data[44:46])
164+
subclassID := strings.ToLower(data[48:50])
165+
progIfaceID := strings.ToLower(data[51:53])
166166
return &deviceModaliasInfo{
167167
vendorID: vendorID,
168168
productID: productID,

pkg/pci/pci_linux_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/jaypipes/ghw/pkg/marshal"
1818
"github.com/jaypipes/ghw/pkg/option"
1919
"github.com/jaypipes/ghw/pkg/pci"
20+
"github.com/jaypipes/ghw/pkg/util"
2021

2122
"github.com/jaypipes/ghw/testdata"
2223
)
@@ -133,7 +134,10 @@ func TestPCIMarshalJSON(t *testing.T) {
133134
t.Fatalf("Expected no error creating PciInfo, but got %v", err)
134135
}
135136

136-
dev := info.ParseDevice("0000:3c:00.0", "pci:v0000144Dd0000A804sv0000144Dsd0000A801bc01sc08i02")
137+
dev := info.ParseDevice("0000:3c:00.0", "pci:v0000144Dd0000A804sv0000144Dsd0000A801bc01sc08i02\n")
138+
if dev == nil {
139+
t.Fatalf("Failed to parse valid modalias")
140+
}
137141
s := marshal.SafeJSON(context.FromEnv(), dev, true)
138142
if s == "" {
139143
t.Fatalf("Error marshalling device: %v", dev)
@@ -211,3 +215,21 @@ func TestPCIMarshalUnmarshal(t *testing.T) {
211215
t.Fatalf("Expected no error unmarshaling pci.Info, but got %v", err)
212216
}
213217
}
218+
219+
func TestPCIModaliasWithUpperCaseClassID(t *testing.T) {
220+
if _, ok := os.LookupEnv("GHW_TESTING_SKIP_PCI"); ok {
221+
t.Skip("Skipping PCI tests.")
222+
}
223+
info, err := pci.New()
224+
if err != nil {
225+
t.Fatalf("Expected no error creating PciInfo, but got %v", err)
226+
}
227+
228+
dev := info.ParseDevice("0000:00:1f.4", "pci:v00008086d00009D23sv00001028sd000007EAbc0Csc05i00\n")
229+
if dev == nil {
230+
t.Fatalf("Failed to parse valid modalias")
231+
}
232+
if dev.Class.Name == util.UNKNOWN {
233+
t.Fatalf("Failed to lookup class name")
234+
}
235+
}

0 commit comments

Comments
 (0)