Skip to contentSkip to conversation

PCI: Initial KUnit test fixture for resource assignment

PATCH In review Naveen Naidu 1 participant 3 messages Nov 19, 2021 PCI

lore
Share & tools
lore
#0 lore raw

v4 cover PCI: Initial KUnit test fixture for resource assignment

Currently it's hard to deubg issues in the resource assignment code of the PCI because of the long reproduction 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/

Bjorn, suggested that it would be really good if we could have a test fixture for debugging/testing resource assignment.

The patch attached along with the cover letter is an attempt to lay the foundation and also have a proof of concept to show that it is possible to have a test fixture to debug the resource assignment code.

Since there are a lot of things which happens during the resource assignement phase, the first version only tests the __pci_read_base() function since that was the most easiest to set up.

Hopefully, in the future patches I'll be able to write more KUnit tests for the other parts responsible during the resource assignment phase and get closer to the goal of having a complete test fixtures :)

Thanks,
Naveen

Changelog
=========
v4:
- Fix datatypes of the global variables and the fields of data structures.
- Fix code formatting
v3:
- Rename init_registers to init_test_registers
v2:
- Add test cases to test resource assignment for Type 1 devices
- Fix a error (a function was not static) found by Kernel Test Robot

Naveen Naidu (1):
[PATCH v4 1/1] PCI: Add KUnit tests for __pci_read_base()

 drivers/pci/Kconfig              |   4 +
 drivers/pci/Makefile             |   3 +
 drivers/pci/pci-read-base-test.c | 795 +++++++++++++++++++++++++++++++
 3 files changed, 802 insertions(+)
 create mode 100644 drivers/pci/pci-read-base-test.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH v4 1/1 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.

The tests can be setup by following [2]

[2]: https://www.kernel.org/doc/html/latest/dev-tools/kunit/usage.html#running-existing-kunit-tests-on-non-uml-architectures

Sample output from KUnit Test run:

      # Subtest: __pci_read_base()
      1..3
   (null): reg 0x18: [mem 0x4f400000-0x4f400fff]
      ok 1 - test_pci_read_base_type_0_hdr_approach_1
   (null): reg 0x18: [mem 0x4f400000-0x4f400fff]
   (null): reg 0x1c: [mem 0xaf400000-0xaf4000ff]
      ok 2 - test_pci_read_base_type_0_hdr_approach_2

(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 1 - __pci_read_base()

---
 drivers/pci/Kconfig              |   4 +
 drivers/pci/Makefile             |   3 +
 drivers/pci/pci-read-base-test.c | 795 +++++++++++++++++++++++++++++++
 3 files changed, 802 insertions(+)
 create mode 100644 drivers/pci/pci-read-base-test.c
drivers/pci/Kconfig +4 -0
index 43e615aa12ff..12b3779fb640 100644
@@ -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"
drivers/pci/Makefile +3 -0
index d62c4ac4ae1b..010a903c3d5d 100644
@@ -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
drivers/pci/pci-read-base-test.c new file +795 -0

795 lines not on this page · raw message

Signature · 1 line
2.25.1