Fix PCI devices with device > 16
This commit is contained in:
parent
8e31e6f2dc
commit
8ab8ae3c7f
2 changed files with 21 additions and 5 deletions
5
pci.go
5
pci.go
|
@ -11,7 +11,6 @@ import (
|
|||
const (
|
||||
pciLength uint16 = 6
|
||||
pciPrefix string = "Pci"
|
||||
pciStringLength int = 12
|
||||
)
|
||||
|
||||
type PCIDevicePath struct {
|
||||
|
@ -42,10 +41,10 @@ func (pcp *PCIDevicePath) String() string {
|
|||
}
|
||||
|
||||
func (pcp *PCIDevicePath) ParseString(raw string) error {
|
||||
if !checkStringFormat(raw, pciPrefix, pciStringLength) {
|
||||
if !checkStringFormat(raw, pciPrefix, -1) {
|
||||
return ErrMalformedString
|
||||
}
|
||||
args := strings.Split(raw[len(pciPrefix)+1:pciStringLength-1], ",")
|
||||
args := strings.Split(raw[len(pciPrefix)+1:len(raw)-1], ",")
|
||||
if len(args) != 2 {
|
||||
return errors.New("unexpected number of arguments")
|
||||
}
|
||||
|
|
17
pci_test.go
17
pci_test.go
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"git.faercol.me/faercol/devicepath"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestToString(t *testing.T) {
|
||||
|
@ -20,3 +21,19 @@ func TestToString(t *testing.T) {
|
|||
assert.Equal(t, expected, dev.String())
|
||||
})
|
||||
}
|
||||
|
||||
func TestParsePCIString(t *testing.T) {
|
||||
t.Run("OK device < 16", func(t *testing.T) {
|
||||
rawStr := "Pci(0x0,0x1)"
|
||||
var dev devicepath.PCIDevicePath
|
||||
require.NoError(t, dev.ParseString(rawStr))
|
||||
assert.Equal(t, rawStr, dev.String())
|
||||
})
|
||||
|
||||
t.Run("OK device > 16", func(t *testing.T) {
|
||||
rawStr := "Pci(0x1f,0x2)"
|
||||
var dev devicepath.PCIDevicePath
|
||||
require.NoError(t, dev.ParseString(rawStr))
|
||||
assert.Equal(t, rawStr, dev.String())
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue