Skip to contentSkip to conversation

PCI: Initial KUnit test fixture for resource assignment

PATCH Superseded Naveen Naidu 2 participants 3 messages Nov 15, 2021 – Nov 18, 2021 PCI

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 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
=========

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 v2 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 | 803 +++++++++++++++++++++++++++++++
 3 files changed, 810 insertions(+)
 create mode 100644 drivers/pci/pci-read-base-test.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 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.

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()
---
 drivers/pci/Kconfig              |   4 +
 drivers/pci/Makefile             |   3 +
 drivers/pci/pci-read-base-test.c | 803 +++++++++++++++++++++++++++++++
 3 files changed, 810 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 +803 -0

803 lines not on this page · raw message

Signature · 6 lines
2.25.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#2 lore raw

Re: [PATCH v2 1/1] PCI: Add KUnit tests for __pci_read_base()

Thank you for the patch! Yet something to improve:

Hi Naveen,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on helgaas-pci/next]
[also build test ERROR on v5.16-rc1 next-20211117]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Naveen-Naidu/PCI-Initial-KUnit-test-fixture-for-resource-assignment/20211115-142802
base:   https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next
config: um-allyesconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/b8f5b94d52de6904d367ff34aa924593d931a853
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Naveen-Naidu/PCI-Initial-KUnit-test-fixture-for-resource-assignment/20211115-142802 git checkout b8f5b94d52de6904d367ff34aa924593d931a853
# save the attached .config to linux build tree
mkdir build_dir
make W=1 O=build_dir ARCH=um SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

>> drivers/pci/pci-read-base-test.c:355:13: error: conflicting types for 'init_registers'
     355 | static void init_registers(void)
         |             ^~~~~~~~~~~~~~
   In file included from arch/um/include/asm/processor-generic.h:14,
                    from arch/x86/um/asm/processor.h:41,
                    from include/linux/spinlock_up.h:8,
                    from include/linux/spinlock.h:96,
                    from include/linux/mm_types.h:9,
                    from include/linux/buildid.h:5,
                    from include/linux/module.h:14,
                    from include/kunit/test.h:15,
                    from drivers/pci/pci-read-base-test.c:7:
   arch/um/include/shared/registers.h:20:12: note: previous declaration of 'init_registers' was here
      20 | extern int init_registers(int pid);
         |            ^~~~~~~~~~~~~~

vim +/init_registers +355 drivers/pci/pci-read-base-test.c

348
349 /*
350 * -----------------------------------------------------------------------
351 * Functions for managing test values
352 * -----------------------------------------------------------------------
353 */
354

 > 355	static void init_registers(void)

356 {
357 unsigned int i, array_size;
358 struct config_space_bitfield *type_hdr;
359
360 if (type_header_test_case == PCI_HEADER_TYPE_NORMAL) {
361 type_hdr = type_0_header;
362 array_size = ARRAY_SIZE(type_0_header);
363 } else {
364 type_hdr = type_1_header;
365 array_size = ARRAY_SIZE(type_1_header);
366 }
367
368 for (i = 0; i < array_size; i++, type_hdr++)
369 set_register(type_hdr->offset, type_hdr->value, type_hdr->size);
370 }
371

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org