Skip to content

Commit

Permalink
Merge pull request #327 from eliaskoromilas/fix-class-lookup
Browse files Browse the repository at this point in the history
Fix class name lookups
  • Loading branch information
ffromani committed Nov 29, 2022
2 parents dac2f19 + f17c871 commit 37ab771
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pkg/pci/pci_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ func parseModaliasData(data string) *deviceModaliasInfo {
productID := strings.ToLower(data[18:22])
subvendorID := strings.ToLower(data[28:32])
subproductID := strings.ToLower(data[38:42])
classID := data[44:46]
subclassID := data[48:50]
progIfaceID := data[51:53]
classID := strings.ToLower(data[44:46])
subclassID := strings.ToLower(data[48:50])
progIfaceID := strings.ToLower(data[51:53])
return &deviceModaliasInfo{
vendorID: vendorID,
productID: productID,
Expand Down
24 changes: 23 additions & 1 deletion pkg/pci/pci_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/jaypipes/ghw/pkg/marshal"
"github.com/jaypipes/ghw/pkg/option"
"github.com/jaypipes/ghw/pkg/pci"
"github.com/jaypipes/ghw/pkg/util"

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

dev := info.ParseDevice("0000:3c:00.0", "pci:v0000144Dd0000A804sv0000144Dsd0000A801bc01sc08i02")
dev := info.ParseDevice("0000:3c:00.0", "pci:v0000144Dd0000A804sv0000144Dsd0000A801bc01sc08i02\n")
if dev == nil {
t.Fatalf("Failed to parse valid modalias")
}
s := marshal.SafeJSON(context.FromEnv(), dev, true)
if s == "" {
t.Fatalf("Error marshalling device: %v", dev)
Expand Down Expand Up @@ -211,3 +215,21 @@ func TestPCIMarshalUnmarshal(t *testing.T) {
t.Fatalf("Expected no error unmarshaling pci.Info, but got %v", err)
}
}

func TestPCIModaliasWithUpperCaseClassID(t *testing.T) {
if _, ok := os.LookupEnv("GHW_TESTING_SKIP_PCI"); ok {
t.Skip("Skipping PCI tests.")
}
info, err := pci.New()
if err != nil {
t.Fatalf("Expected no error creating PciInfo, but got %v", err)
}

dev := info.ParseDevice("0000:00:1f.4", "pci:v00008086d00009D23sv00001028sd000007EAbc0Csc05i00\n")
if dev == nil {
t.Fatalf("Failed to parse valid modalias")
}
if dev.Class.Name == util.UNKNOWN {
t.Fatalf("Failed to lookup class name")
}
}

0 comments on commit 37ab771

Please sign in to comment.