From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from wes1-so2.wedos.net (wes1-so2.wedos.net [46.28.106.16]) by dpdk.org (Postfix) with ESMTP id 80D3DB3F4 for ; Tue, 10 May 2016 20:15:56 +0200 (CEST) Received: from pcviktorin.fit.vutbr.cz (pcviktorin.fit.vutbr.cz [147.229.13.147]) by wes1-so2.wedos.net (Postfix) with ESMTPSA id 3r46rD28VDz4JW; Tue, 10 May 2016 20:15:56 +0200 (CEST) From: Jan Viktorin To: dev@dpdk.org Cc: Jan Viktorin , Thomas Monjalon , David Marchand , Bruce Richardson Date: Tue, 10 May 2016 20:13:30 +0200 Message-Id: <1462904011-29838-11-git-send-email-viktorin@rehivetech.com> X-Mailer: git-send-email 2.8.0 In-Reply-To: <1462904011-29838-1-git-send-email-viktorin@rehivetech.com> References: <1462904011-29838-1-git-send-email-viktorin@rehivetech.com> In-Reply-To: <1461935496-20367-1-git-send-email-viktorin@rehivetech.com> References: <1461935496-20367-1-git-send-email-viktorin@rehivetech.com> Subject: [dpdk-dev] [PATCH v2 10/11] app/test: scan PCI bus using a fake sysfs X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 May 2016 18:15:56 -0000 Scan the PCI bus by providing a fake sysfs with a PCI device. The fake sysfs is a packed file hierarchy linked into the test. Signed-off-by: Jan Viktorin --- app/test/Makefile | 1 + app/test/test_pci.c | 58 +++++++++++++++++++-- .../bus/pci/devices/0000:01:00.0/class | 1 + .../bus/pci/devices/0000:01:00.0/config | Bin 0 -> 64 bytes .../devices/0000:01:00.0/consistent_dma_mask_bits | 1 + .../bus/pci/devices/0000:01:00.0/device | 1 + .../bus/pci/devices/0000:01:00.0/dma_mask_bits | 1 + .../bus/pci/devices/0000:01:00.0/enable | 1 + .../bus/pci/devices/0000:01:00.0/irq | 1 + .../bus/pci/devices/0000:01:00.0/modalias | 1 + .../bus/pci/devices/0000:01:00.0/msi_bus | 1 + .../bus/pci/devices/0000:01:00.0/numa_node | 1 + .../bus/pci/devices/0000:01:00.0/resource | 13 +++++ .../bus/pci/devices/0000:01:00.0/sriov_numvfs | 1 + .../bus/pci/devices/0000:01:00.0/sriov_totalvfs | 1 + .../bus/pci/devices/0000:01:00.0/subsystem_device | 1 + .../bus/pci/devices/0000:01:00.0/subsystem_vendor | 1 + .../bus/pci/devices/0000:01:00.0/uevent | 6 +++ .../bus/pci/devices/0000:01:00.0/vendor | 1 + 19 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/class create mode 100644 app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/config create mode 100644 app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/consistent_dma_mask_bits create mode 100644 app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/device create mode 100644 app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/dma_mask_bits create mode 100644 app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/enable create mode 100644 app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/irq create mode 100644 app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/modalias create mode 100644 app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/msi_bus create mode 100644 app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/numa_node create mode 100644 app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/resource create mode 100644 app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_numvfs create mode 100644 app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_totalvfs create mode 100644 app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_device create mode 100644 app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_vendor create mode 100644 app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/uevent create mode 100644 app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/vendor diff --git a/app/test/Makefile b/app/test/Makefile index de5fa50..1c6c29e 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -73,6 +73,7 @@ SRCS-y += test_resource.c $(eval $(call linked_resource,test_resource_c,resource.c)) $(eval $(call linked_tar_resource,test_resource_tar,test_resource.c)) SRCS-y += test_pci.c +$(eval $(call linked_tar_resource,test_pci_sysfs,test_pci_sysfs)) SRCS-y += test_prefetch.c SRCS-y += test_byteorder.c SRCS-y += test_per_lcore.c diff --git a/app/test/test_pci.c b/app/test/test_pci.c index df12bb2..3c6c955 100644 --- a/app/test/test_pci.c +++ b/app/test/test_pci.c @@ -43,6 +43,7 @@ #include #include "test.h" +#include "resource.h" /* Generic maximum number of drivers to have room to allocate all drivers */ #define NUM_MAX_DRIVERS 256 @@ -215,37 +216,88 @@ static int test_pci_sysfs(void) return 0; } -/* real drivers (not used for testing) */ +/* real devices & drivers (not used for testing) */ struct pci_driver_list real_pci_driver_list = TAILQ_HEAD_INITIALIZER(real_pci_driver_list); +struct pci_device_list real_pci_device_list = + TAILQ_HEAD_INITIALIZER(real_pci_device_list); + +REGISTER_LINKED_RESOURCE(test_pci_sysfs); static int test_pci_setup(void) { + struct rte_pci_device *dev; struct rte_pci_driver *dr; + const struct resource *r; + int ret; + + r = resource_find("test_pci_sysfs"); + TEST_ASSERT_NOT_NULL(r, "missing resource test_pci_sysfs"); + + ret = resource_untar(r); + TEST_ASSERT_SUCCESS(ret, "failed to untar %s", r->name); + + ret = setenv("SYSFS_PCI_DEVICES", "test_pci_sysfs/bus/pci/devices", 1); + TEST_ASSERT_SUCCESS(ret, "failed to setenv"); - /* Unregister original driver list */ + /* Unregister original devices & drivers lists */ while (!TAILQ_EMPTY(&pci_driver_list)) { dr = TAILQ_FIRST(&pci_driver_list); rte_eal_pci_unregister(dr); TAILQ_INSERT_TAIL(&real_pci_driver_list, dr, next); } + while (!TAILQ_EMPTY(&pci_device_list)) { + dev = TAILQ_FIRST(&pci_device_list); + TAILQ_REMOVE(&pci_device_list, dev, next); + TAILQ_INSERT_TAIL(&real_pci_device_list, dev, next); + } + + ret = rte_eal_pci_scan(); + TEST_ASSERT_SUCCESS(ret, "failed to scan PCI bus"); + rte_eal_pci_dump(stdout); + return 0; } static int test_pci_cleanup(void) { + struct rte_pci_device *dev; struct rte_pci_driver *dr; + const struct resource *r; + int ret; + + unsetenv("SYSFS_PCI_DEVICES"); + + r = resource_find("test_pci_sysfs"); + TEST_ASSERT_NOT_NULL(r, "missing resource test_pci_sysfs"); + + ret = resource_rm_by_tar(r); + TEST_ASSERT_SUCCESS(ret, "Failed to delete resource %s", r->name); - /* Restore original driver list */ + /* FIXME: there is no API in DPDK to free a rte_pci_device so we + cannot free the devices in the right way. Let's assume that we + don't care for tests. */ + while (!TAILQ_EMPTY(&pci_device_list)) { + dev = TAILQ_FIRST(&pci_device_list); + TAILQ_REMOVE(&pci_device_list, dev, next); + } + + /* Restore original devices & drivers lists */ while (!TAILQ_EMPTY(&real_pci_driver_list)) { dr = TAILQ_FIRST(&real_pci_driver_list); TAILQ_REMOVE(&real_pci_driver_list, dr, next); rte_eal_pci_register(dr); } + while (!TAILQ_EMPTY(&real_pci_device_list)) { + dev = TAILQ_FIRST(&real_pci_device_list); + TAILQ_REMOVE(&real_pci_device_list, dev, next); + TAILQ_INSERT_TAIL(&pci_device_list, dev, next); + } + return 0; } diff --git a/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/class b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/class new file mode 100644 index 0000000..2f9c1da --- /dev/null +++ b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/class @@ -0,0 +1 @@ +0x020000 diff --git a/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/config b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/config new file mode 100644 index 0000000000000000000000000000000000000000..7752421cf13a5aa00a28eaee02cac2add9ce5566 GIT binary patch literal 64 zcmZo`_$|QBBEZ1Nz`(@7(7?dMz;S^A2oxWHNCpNT2LUi2#BOU~22l(SV3L7>8>k5Y DD^Ld( literal 0 HcmV?d00001 diff --git a/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/consistent_dma_mask_bits b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/consistent_dma_mask_bits new file mode 100644 index 0000000..900731f --- /dev/null +++ b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/consistent_dma_mask_bits @@ -0,0 +1 @@ +64 diff --git a/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/device b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/device new file mode 100644 index 0000000..9e4789e --- /dev/null +++ b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/device @@ -0,0 +1 @@ +0x10fb diff --git a/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/dma_mask_bits b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/dma_mask_bits new file mode 100644 index 0000000..900731f --- /dev/null +++ b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/dma_mask_bits @@ -0,0 +1 @@ +64 diff --git a/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/enable b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/enable new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/enable @@ -0,0 +1 @@ +1 diff --git a/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/irq b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/irq new file mode 100644 index 0000000..573541a --- /dev/null +++ b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/irq @@ -0,0 +1 @@ +0 diff --git a/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/modalias b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/modalias new file mode 100644 index 0000000..f4c76ed --- /dev/null +++ b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/modalias @@ -0,0 +1 @@ +pci:v00008086d000010FBsv00008086sd00000003bc02sc00i00 diff --git a/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/msi_bus b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/msi_bus new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/msi_bus @@ -0,0 +1 @@ +1 diff --git a/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/numa_node b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/numa_node new file mode 100644 index 0000000..3a2e3f4 --- /dev/null +++ b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/numa_node @@ -0,0 +1 @@ +-1 diff --git a/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/resource b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/resource new file mode 100644 index 0000000..f388929 --- /dev/null +++ b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/resource @@ -0,0 +1,13 @@ +0x00000000d0080000 0x00000000d00fffff 0x000000000014220c +0x0000000000000000 0x0000000000000000 0x0000000000000000 +0x000000000000e020 0x000000000000e03f 0x0000000000040101 +0x0000000000000000 0x0000000000000000 0x0000000000000000 +0x00000000d0104000 0x00000000d0107fff 0x000000000014220c +0x0000000000000000 0x0000000000000000 0x0000000000000000 +0x0000000000000000 0x0000000000000000 0x0000000000000000 +0x00000000ab000000 0x00000000ab0fffff 0x0000000000140204 +0x0000000000000000 0x0000000000000000 0x0000000000000000 +0x0000000000000000 0x0000000000000000 0x0000000000000000 +0x00000000ab100000 0x00000000ab1fffff 0x0000000000140204 +0x0000000000000000 0x0000000000000000 0x0000000000000000 +0x0000000000000000 0x0000000000000000 0x0000000000000000 diff --git a/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_numvfs b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_numvfs new file mode 100644 index 0000000..573541a --- /dev/null +++ b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_numvfs @@ -0,0 +1 @@ +0 diff --git a/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_totalvfs b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_totalvfs new file mode 100644 index 0000000..4b9026d --- /dev/null +++ b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_totalvfs @@ -0,0 +1 @@ +63 diff --git a/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_device b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_device new file mode 100644 index 0000000..89a932c --- /dev/null +++ b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_device @@ -0,0 +1 @@ +0x0003 diff --git a/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_vendor b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_vendor new file mode 100644 index 0000000..ce6dc4d --- /dev/null +++ b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_vendor @@ -0,0 +1 @@ +0x8086 diff --git a/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/uevent b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/uevent new file mode 100644 index 0000000..1dbe34d --- /dev/null +++ b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/uevent @@ -0,0 +1,6 @@ +DRIVER=ixgbe +PCI_CLASS=20000 +PCI_ID=8086:10FB +PCI_SUBSYS_ID=8086:0003 +PCI_SLOT_NAME=0000:01:00.0 +MODALIAS=pci:v00008086d000010FBsv00008086sd00000003bc02sc00i00 diff --git a/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/vendor b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/vendor new file mode 100644 index 0000000..ce6dc4d --- /dev/null +++ b/app/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/vendor @@ -0,0 +1 @@ +0x8086 -- 2.8.0