Skip to content
Permalink
Browse files
PCI: Add KUnit tests for __pci_read_base()
Currently it is hard to debug issues in the resource assignment code due
to long reporduction cycles between the developer trying to fix the code
and the user testing it due to the lack of hardware device with the
developer [1].

[1]:
https://lore.kernel.org/all/20210621123714.GA3286648@bjorn-Precision-5520/

This adds KUnit tests for __pci_read_base() which is only  dependent
on software structures, so no hardware is needed to run these.

This lays the foundation for test fixtures we can use to reproduce the
resource assignment code path of PCI.

Sample output from KUnit Test run:

      # Subtest: __pci_read_base()
      1..3
      # test_pci_read_base_type_0_hdr_approach_1: initializing __pci_read_base() tests
   (null): reg 0x18: [mem 0x4f400000-0x4f400fff]
      ok 1 - test_pci_read_base_type_0_hdr_approach_1
      # test_pci_read_base_type_0_hdr_approach_2: initializing __pci_read_base() tests
   (null): reg 0x18: [mem 0x4f400000-0x4f400fff]
   (null): reg 0x1c: [mem 0xaf400000-0xaf4000ff]
      ok 2 - test_pci_read_base_type_0_hdr_approach_2
      # test_pci_read_base_type_1_hdr: initializing __pci_read_base() tests
   (null): reg 0x10: [mem 0xaf400000-0xaf4000ff]
      ok 3 - test_pci_read_base_type_1_hdr
  # __pci_read_base(): pass:3 fail:0 skip:0 total:3
  # Totals: pass:3 fail:0 skip:0 total:3
  # ok 8 - __pci_read_base()

Suggested-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Naveen Naidu <naveennaidu479@gmail.com>
  • Loading branch information
Naveenaidu authored and intel-lab-lkp committed Nov 15, 2021
1 parent dda4b38 commit b8f5b94d52de6904d367ff34aa924593d931a853
Show file tree
Hide file tree
Showing 3 changed files with 810 additions and 0 deletions.
@@ -252,6 +252,10 @@ config PCIE_BUS_PEER2PEER

endchoice

config PCI_READ_BASE_KUNIT_TEST
tristate "KUnit tests for __pci_read_base() in probe.c"
depends on PCI && KUNIT=y

source "drivers/pci/hotplug/Kconfig"
source "drivers/pci/controller/Kconfig"
source "drivers/pci/endpoint/Kconfig"
@@ -36,4 +36,7 @@ obj-$(CONFIG_PCI_ENDPOINT) += endpoint/
obj-y += controller/
obj-y += switch/

# KUnit test files
obj-$(CONFIG_PCI_READ_BASE_KUNIT_TEST) += pci-read-base-test.o

subdir-ccflags-$(CONFIG_PCI_DEBUG) := -DDEBUG

0 comments on commit b8f5b94

Please sign in to comment.