Append warning about invalid IRQ resources
authorReto Buerki <reet@codelabs.ch>
Thu, 14 Sep 2017 13:46:10 +0000 (15:46 +0200)
committerReto Buerki <reet@codelabs.ch>
Fri, 15 Sep 2017 07:16:18 +0000 (09:16 +0200)
On some systems, Linux exposes IRQs which are not in our allowed range,
which results in an ugly schema validation exception.

Catch this exception and add proper warning that the resource has been
skipped.

data/creator/devicescreator/devices_testirq/dev4/irq [new file with mode: 0644]
data/creator/devicescreator/devices_testirq/dev4/msi_irqs/327 [new file with mode: 0644]
src/creator.py
test/test_creator.py

diff --git a/data/creator/devicescreator/devices_testirq/dev4/irq b/data/creator/devicescreator/devices_testirq/dev4/irq
new file mode 100644 (file)
index 0000000..3d4db09
--- /dev/null
@@ -0,0 +1 @@
+123123
diff --git a/data/creator/devicescreator/devices_testirq/dev4/msi_irqs/327 b/data/creator/devicescreator/devices_testirq/dev4/msi_irqs/327
new file mode 100644 (file)
index 0000000..eca5c52
--- /dev/null
@@ -0,0 +1 @@
+msi
index e02f8f1..f75853b 100644 (file)
@@ -539,9 +539,14 @@ class PciDevicesCreator():
                              os.path.basename(devicepath), False)
         else:
             if irqNo is not "0":
-                irq = schemadata.schema.irqType(
-                    name="irq%d" % RESOURCE_START_IDX, number=irqNo)
-                irqs.append(irq)
+                try:
+                    irq = schemadata.schema.irqType(
+                        name="irq%d" % RESOURCE_START_IDX, number=irqNo)
+                    irqs.append(irq)
+                except:
+                    message.addWarning("Skipping invalid IRQ resource for " +
+                                       "device " + os.path.basename(devicepath)
+                                       + ": " + irqNo)
 
         return irqs
 
@@ -552,8 +557,14 @@ class PciDevicesCreator():
         if os.path.exists(path):
             for c, file in enumerate(sorted(os.listdir(path)),
                                      start=RESOURCE_START_IDX):
-                irq = schemadata.schema.irqType(name="irq%d" % c, number=file)
-                irqs.append(irq)
+                try:
+                    irq = schemadata.schema.irqType(name="irq%d" % c,
+                                                    number=file)
+                    irqs.append(irq)
+                except:
+                    message.addWarning("Skipping invalid IRQ resource for " +
+                                       "device " + os.path.basename(devicepath)
+                                       + ": " + file)
 
         return irqs
 
index 3a8b16f..060c444 100644 (file)
@@ -464,15 +464,18 @@ class TestPciDevicesCreator:
         testloc = os.path.join(self.testdir, "devices_testirq")
         dev0 = os.path.join(testloc, "dev0")
         dev1 = os.path.join(testloc, "dev1")
+        dev4 = os.path.join(testloc, "dev4")
         dev_invalid = "test_getirq_invalid"
 
         dev0_irq = self.pcicreator.getLegacyIrq(dev0)
         dev1_irq = self.pcicreator.getLegacyIrq(dev1)
+        dev4_irq = self.pcicreator.getLegacyIrq(dev4)
         dev_invalid_irq = self.pcicreator.getLegacyIrq(dev_invalid)
 
         assert dev1_irq[0].number == 15
         assert dev1_irq[0].name == "irq1"
         assert not dev0_irq
+        assert not dev4_irq
         assert not dev_invalid_irq
 
     def test_getMsiIrqs(self):
@@ -480,14 +483,17 @@ class TestPciDevicesCreator:
         dev1 = os.path.join(testloc, "dev1")
         dev2 = os.path.join(testloc, "dev2")
         dev3 = os.path.join(testloc, "dev3")
+        dev4 = os.path.join(testloc, "dev4")
         dev_invalid = "test_getirq_invalid"
 
         dev1_irqs = self.pcicreator.getMsiIrqs(dev1)
         dev2_irqs = self.pcicreator.getMsiIrqs(dev2)
         dev3_irqs = self.pcicreator.getMsiIrqs(dev3)
+        dev4_irqs = self.pcicreator.getMsiIrqs(dev4)
         dev_invalid_irqs = self.pcicreator.getMsiIrqs(dev_invalid)
 
         assert not dev1_irqs
+        assert not dev4_irqs
         assert dev2_irqs[0].number == 40
         assert dev2_irqs[0].name == "irq1"
         assert dev2_irqs[1].number == 41