Add a facility to bind drivers for DPDK on runtimes where the DPDK build
is lacking. This is needed to execute any program that is based on DPDK,
but is unrelated to the testing.

Bugzilla ID: 1420

Signed-off-by: Luca Vizzarro <luca.vizza...@arm.com>
Reviewed-by: Paul Szczepanek <paul.szczepa...@arm.com>
---
 dts/framework/remote_session/dpdk.py | 34 +++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/dts/framework/remote_session/dpdk.py 
b/dts/framework/remote_session/dpdk.py
index 50c22769c1..8d9f3b8948 100644
--- a/dts/framework/remote_session/dpdk.py
+++ b/dts/framework/remote_session/dpdk.py
@@ -419,6 +419,7 @@ def setup(self, ports: Iterable[Port]):
         """Set up the DPDK runtime on the target node."""
         if self.build:
             self.build.setup()
+        self._prepare_devbind_script()
         self.bind_ports_to_driver(ports)
 
     def teardown(self, ports: Iterable[Port]) -> None:
@@ -467,21 +468,38 @@ def bind_ports_to_driver(self, ports: Iterable[Port], 
for_dpdk: bool = True) ->
             )
             port.bound_for_dpdk = for_dpdk
 
-    @cached_property
-    def devbind_script_path(self) -> PurePath:
-        """The path to the dpdk-devbind.py script on the node.
+    def _prepare_devbind_script(self) -> None:
+        """Prepare the devbind script.
+
+        If the environment has a build associated with it, then use the script 
within that build's
+        tree. Otherwise, copy the script from the local repository.
 
         Raises:
-            InternalError: If attempting to retrieve the devbind script in a 
build-less runtime.
+            InternalError: If dpdk-devbind.py could not be found.
         """
         if self.build:
-            return self._node.main_session.join_remote_path(
+            self.devbind_script_path = 
self._node.main_session.join_remote_path(
                 self.build.remote_dpdk_tree_path, "usertools", 
"dpdk-devbind.py"
             )
+        else:
+            local_script_path = Path("..", "usertools", 
"dpdk-devbind.py").resolve()
+            if not local_script_path.exists():
+                raise InternalError("Could not find dpdk-devbind.py locally.")
 
-        raise InternalError(
-            "DPDK runtime is not associated with any DPDK build. Can't 
retrieve dpdk-devbind.py."
-        )
+            self.devbind_script_path = 
self._node.main_session.join_remote_path(
+                self._node.tmp_dir, local_script_path.name
+            )
+
+            self._node.main_session.copy_to(local_script_path, 
self.devbind_script_path)
+
+    @cached_property
+    def devbind_script_path(self) -> PurePath:
+        """The path to the dpdk-devbind.py script on the node.
+
+        Raises:
+            InternalError: If accessed before environment setup.
+        """
+        raise InternalError("Accessed devbind script path before setup.")
 
     def filter_lcores(
         self,
-- 
2.43.0

Reply via email to