[dpdk-dev] [RFC 6/7] eal/soc: make SoC infra testable on any platform

Jan Viktorin viktorin at rehivetech.com
Fri Jan 1 22:05:25 CET 2016


The hardcoded constant paths to sysfs and device-tree locations
makes the SoC infra difficult to test. With this code, it is
possible to override the default path by setting the appropriate
environment variables.

A test can provide a fake sysfs and device-tree hierarchy of devices.

Signed-off-by: Jan Viktorin <viktorin at rehivetech.com>
---
 lib/librte_eal/common/include/rte_soc.h |  6 ++++--
 lib/librte_eal/linuxapp/eal/eal_soc.c   | 15 +++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_soc.h b/lib/librte_eal/common/include/rte_soc.h
index 7c279b1..d7d6827 100644
--- a/lib/librte_eal/common/include/rte_soc.h
+++ b/lib/librte_eal/common/include/rte_soc.h
@@ -56,9 +56,11 @@ extern struct soc_device_list soc_device_list;
 extern struct soc_driver_list soc_driver_list;
 
 /* Path to detect platform devices (in architecture-specific bus systems). */
-#define SYSFS_SOC_DEVICES "/sys/bus/platform/devices"
+#define SYSFS_SOC_DEVICES __sysfs_soc_devices
+extern const char *__sysfs_soc_devices;
 /* Flat Device Tree location in the system. */
-#define FDT_ROOT "/proc/device-tree"
+#define FDT_ROOT __fdt_root
+extern const char *__fdt_root;
 
 struct rte_soc_resource {
 	uint64_t phys_addr; /**< Physical address, 0 if no resource. */
diff --git a/lib/librte_eal/linuxapp/eal/eal_soc.c b/lib/librte_eal/linuxapp/eal/eal_soc.c
index be0e44d..aafb9c3 100644
--- a/lib/librte_eal/linuxapp/eal/eal_soc.c
+++ b/lib/librte_eal/linuxapp/eal/eal_soc.c
@@ -46,6 +46,9 @@
 #include "eal_private.h"
 #include "eal_pci_init.h"
 
+const char *__sysfs_soc_devices = "/sys/bus/platform/devices";
+const char *__fdt_root = "/proc/device-tree";
+
 int
 soc_map_device(struct rte_soc_device *dev)
 {
@@ -378,12 +381,24 @@ error:
 int
 rte_eal_soc_init(void)
 {
+	char *tmp;
+
 	TAILQ_INIT(&soc_driver_list);
 	TAILQ_INIT(&soc_device_list);
 
 	if (internal_config.no_soc)
 		return 0;
 
+	if ((tmp = getenv("SYSFS_SOC_DEVICES")))
+		__sysfs_soc_devices = tmp;
+	else
+		__sysfs_soc_devices = "/sys/bus/platform/devices";
+
+	if ((tmp = getenv("FDT_ROOT")))
+		__fdt_root = tmp;
+	else
+		__fdt_root = "/proc/device-tree";
+
 	if (rte_eal_soc_scan() < 0) {
 		RTE_LOG(ERR, EAL, "%s(): Failed to scan for SoC devices\n",
 			__func__);
-- 
2.6.3



More information about the dev mailing list