Skip to content

Commit

Permalink
pillar/assignableadapters: clear error strings
Browse files Browse the repository at this point in the history
1. create two usb adapters with collision
2. change the usbaddr of one of the adapters

now the collision should be gone, but
as the error string for both adapters has been set, it was
not cleared

Signed-off-by: Christoph Ostarek <christoph@zededa.com>
  • Loading branch information
christoph-zededa committed Sep 11, 2024
1 parent 313feed commit 0188042
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
6 changes: 5 additions & 1 deletion pkg/pillar/types/assignableadapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,17 @@ func (aa *AssignableAdapters) CheckParentAssigngrp() bool {

// CheckBadUSBBundles sets ib.Error/ErrorTime if bundle collides in regards of USB
func (aa *AssignableAdapters) CheckBadUSBBundles() {
collisionErrStrPrefix := "ioBundle collision:"
usbProductsAddressMap := make(map[[4]string][]*IoBundle)
for i := range aa.IoBundleList {
ioBundle := &aa.IoBundleList[i]
if ioBundle.UsbAddr == "" && ioBundle.UsbProduct == "" && ioBundle.PciLong == "" {
continue
}

if strings.HasPrefix(ioBundle.Error, collisionErrStrPrefix) {
ioBundle.Error = ""
}
id := [4]string{ioBundle.UsbAddr, ioBundle.UsbProduct, ioBundle.PciLong, ioBundle.AssignmentGroup}
if usbProductsAddressMap[id] == nil {
usbProductsAddressMap[id] = make([]*IoBundle, 0)
Expand All @@ -545,7 +549,7 @@ func (aa *AssignableAdapters) CheckBadUSBBundles() {
continue
}

errStr := "ioBundle collision:||"
errStr := collisionErrStrPrefix + "||"

for _, bundle := range bundles {
errStr += fmt.Sprintf("phylabel %s - usbaddr: %s usbproduct: %s pcilong: %s assigngrp: %s||",
Expand Down
37 changes: 33 additions & 4 deletions pkg/pillar/types/assignableadapters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ type expandControllersTestEntry struct {
}

func TestExpandControllers(t *testing.T) {
var testMatrix = map[string]expandControllersTestEntry{
testMatrix := map[string]expandControllersTestEntry{
"eth0-3": {
assignmentGroup: "eth0-1",
preLen: 2,
Expand Down Expand Up @@ -500,8 +500,39 @@ func alternativeCheckBadUSBBundlesImpl(bundles []IoBundle) {
}
}

func FuzzCheckBadUSBBundles(f *testing.F) {
func TestClearingUSBCollision(t *testing.T) {
aa := AssignableAdapters{}
bundles := make([]IoBundle, 2)

bundles[0].Phylabel = "usb1"
bundles[1].Phylabel = "usb2"

bundles[0].UsbAddr = "1:1"
bundles[1].UsbAddr = bundles[0].UsbAddr
aa.IoBundleList = bundles

aa.CheckBadUSBBundles()

for _, ioBundle := range aa.IoBundleList {
t.Logf("%s / %s", ioBundle.Phylabel, ioBundle.Error)
if ioBundle.Error == "" {
t.Fatalf("expected collision for ioBundle %s", ioBundle.Phylabel)
}
}

aa.IoBundleList[0].UsbAddr = "1:2"
aa.IoBundleList[0].Error = ""

aa.CheckBadUSBBundles()
for _, ioBundle := range aa.IoBundleList {
t.Logf("%s / %s", ioBundle.Phylabel, ioBundle.Error)
if ioBundle.Error != "" {
t.Fatalf("expected no collision for ioBundle %s", ioBundle.Phylabel)
}
}
}

func FuzzCheckBadUSBBundles(f *testing.F) {
f.Fuzz(func(t *testing.T,
// ioBundle 1
pciLong1 string,
Expand Down Expand Up @@ -652,12 +683,10 @@ func TestCheckBadParentAssigngrpLoop(t *testing.T) {
errorSet = true
break
}

}
if !errorSet {
t.Fatal("wrong error message")
}

}

func TestCheckBadUSBBundles(t *testing.T) {
Expand Down

0 comments on commit 0188042

Please sign in to comment.