PCI: Intial KUnit test fixture for resource assignment
cover PCI: Intial 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
Naveen Naidu (1):
PCI: Add KUnit tests for __pci_read_base()
drivers/pci/Kconfig | 4 + drivers/pci/Makefile | 3 + drivers/pci/pci-read-base-test.c | 740 +++++++++++++++++++++++++++++++ 3 files changed, 747 insertions(+) create mode 100644 drivers/pci/pci-read-base-test.c
Signature · 6 lines
2.25.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 1/1 PCI: Add KUnit tests for __pci_read_base()
It is usually 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.
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..2
# 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]
ok 2 - test_pci_read_base_type_0_hdr_approach_2
# __pci_read_base(): pass:2 fail:0 skip:0 total:2 # Totals: pass:2 fail:0 skip:0 total:2
ok 2 - __pci_read_base()
--- drivers/pci/Kconfig | 4 + drivers/pci/Makefile | 3 + drivers/pci/pci-read-base-test.c | 740 +++++++++++++++++++++++++++++++ 3 files changed, 747 insertions(+) create mode 100644 drivers/pci/pci-read-base-test.c
drivers/pci/Kconfig +4 -0
@@ -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
@@ -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 +740 -0
740 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
kernel test robot
build botRe: [PATCH 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-20211115]
[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-Intial-KUnit-test-fixture-for-resource-assignment/20211115-041125 base: https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next config: xtensa-allyesconfig (attached as .config) compiler: xtensa-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/57b950c5684fcfff54e46f4369fd7f708a29ca60
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Naveen-Naidu/PCI-Intial-KUnit-test-fixture-for-resource-assignment/20211115-041125 git checkout 57b950c5684fcfff54e46f4369fd7f708a29ca60
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=xtensa
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> drivers/pci/pci-read-base-test.c:538:6: error: no previous prototype for 'set_test_data_type_1_headers' [-Werror=missing-prototypes]
538 | void set_test_data_type_1_headers(
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~cc1: all warnings being treated as errors
vim +/set_test_data_type_1_headers +538 drivers/pci/pci-read-base-test.c
537
> 538 void set_test_data_type_1_headers(
539 const struct type_1_header_test_data test_data, struct resource *res)
540 {
541 res->start = 0;
542 res->end = 0;
543 res->flags = test_data.res_flags;
544
545 type_1_header[BAR0].value = test_data.BAR0_value;
546 type_1_header[BAR1].value = test_data.BAR1_value;
547
548 type_1_BARS_config[config_BAR0].allocated_size =
549 test_data.BAR0_allocated_size;
550
551 type_1_BARS_config[config_BAR1].allocated_size =
552 test_data.BAR1_allocated_size;
553
554 init_registers();
555 }
556
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH 1/1] PCI: Add KUnit tests for __pci_read_base()
In reply to Naveen NaiduThank you for the patch! Perhaps something to improve:
Hi Naveen,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on helgaas-pci/next]
[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-Intial-KUnit-test-fixture-for-resource-assignment/20211115-041125 base: https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next config: parisc-randconfig-c024-20211115 (attached as .config) compiler: hppa-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/57b950c5684fcfff54e46f4369fd7f708a29ca60
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Naveen-Naidu/PCI-Intial-KUnit-test-fixture-for-resource-assignment/20211115-041125 git checkout 57b950c5684fcfff54e46f4369fd7f708a29ca60
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=parisc
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/pci/pci-read-base-test.c:538:6: warning: no previous prototype for 'set_test_data_type_1_headers' [-Wmissing-prototypes]
538 | void set_test_data_type_1_headers(
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~vim +/set_test_data_type_1_headers +538 drivers/pci/pci-read-base-test.c
537
> 538 void set_test_data_type_1_headers(
539 const struct type_1_header_test_data test_data, struct resource *res)
540 {
541 res->start = 0;
542 res->end = 0;
543 res->flags = test_data.res_flags;
544
545 type_1_header[BAR0].value = test_data.BAR0_value;
546 type_1_header[BAR1].value = test_data.BAR1_value;
547
548 type_1_BARS_config[config_BAR0].allocated_size =
549 test_data.BAR0_allocated_size;
550
551 type_1_BARS_config[config_BAR1].allocated_size =
552 test_data.BAR1_allocated_size;
553
554 init_registers();
555 }
556
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org