diff mbox series

[4/4] oeqa/selftest/gcc: allowing multiple ssh sessions

Message ID 20240808145042.3914762-4-Harish.Sadineni@windriver.com
State New
Headers show
Series [1/4] gcc-runtime: enabling "network" task specific flag | expand

Commit Message

Sadineni, Harish Aug. 8, 2024, 2:50 p.m. UTC
From: Harish Sadineni <Harish.Sadineni@windriver.com>

Reusing SSH Connection to speed up remote login process
using multiplexing to reduce time taken while running
oe-selftest for gcc.

Signed-off-by: Harish Sadineni <Harish.Sadineni@windriver.com>
---
 meta/lib/oeqa/selftest/cases/gcc.py         | 23 +++++++++++++++++++++
 meta/recipes-devtools/gcc/gcc-testsuite.inc |  3 ++-
 2 files changed, 25 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/meta/lib/oeqa/selftest/cases/gcc.py b/meta/lib/oeqa/selftest/cases/gcc.py
index 4cc0894d42..036c69335b 100644
--- a/meta/lib/oeqa/selftest/cases/gcc.py
+++ b/meta/lib/oeqa/selftest/cases/gcc.py
@@ -5,6 +5,7 @@ 
 #
 import os
 import time
+import subprocess
 from oeqa.core.decorator import OETestTag
 from oeqa.core.case import OEPTestResultTestCase
 from oeqa.selftest.case import OESelftestTestCase
@@ -69,6 +70,19 @@  class GccSelfTestBase(OESelftestTestCase, OEPTestResultTestCase):
                 for test, result in parse_values(f):
                     self.ptest_result(ptestsuite, test, result)
 
+        if ssh is not None:
+            # Define the control path used for the SSH connection
+            control_path = os.path.expanduser("~/.ssh/control-{}@{}:22".format("root", ssh))
+
+            # Check if the control socket exists
+            if os.path.exists(control_path):
+                # Close the master SSH connection
+                close_command = [
+                    "ssh", "-o", "ControlPath={}".format(control_path),
+                    "-O", "exit", "root@{}".format(ssh)
+                ]
+                subprocess.run(close_command, check=True)
+
     def run_check_emulated(self, *args, **kwargs):
         # build core-image-minimal with required packages
         default_installed_packages = ["libgcc", "libstdc++", "libatomic", "libgomp"]
@@ -83,6 +97,15 @@  class GccSelfTestBase(OESelftestTestCase, OEPTestResultTestCase):
             # validate that SSH is working
             status, _ = qemu.run("uname")
             self.assertEqual(status, 0)
+            qemu_ip = qemu.ip
+            ssh_command = [
+            "ssh", "-o", "StrictHostKeyChecking=no",
+            "-o", "UserKnownHostsFile=/dev/null",
+            "-o", "ControlMaster=auto",
+            "-o", "ControlPath=~/.ssh/control-%r@%h:%p",
+            "-o", "Controlpersist=yes", "root@{}".format(qemu_ip),
+            "exit" ]
+            subprocess.run(ssh_command, check=True)
 
             return self.run_check(*args, ssh=qemu.ip, **kwargs)
 
diff --git a/meta/recipes-devtools/gcc/gcc-testsuite.inc b/meta/recipes-devtools/gcc/gcc-testsuite.inc
index 0a950b6c9e..dbb11c8d78 100644
--- a/meta/recipes-devtools/gcc/gcc-testsuite.inc
+++ b/meta/recipes-devtools/gcc/gcc-testsuite.inc
@@ -87,7 +87,8 @@  python check_prepare() {
         content.append("set_board_info username {0}".format(d.getVar("TOOLCHAIN_TEST_HOST_USER")))
 
         port = d.getVar("TOOLCHAIN_TEST_HOST_PORT")
-        content.append("set_board_info rsh_prog \"/usr/bin/ssh -p {0} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no\"".format(port))
+        qemuip_address = d.getVar("TOOLCHAIN_TEST_HOST")
+        content.append("set_board_info rsh_prog \"/usr/bin/ssh -S ~/.ssh/control-root@{0}:{1}   \"".format( qemuip_address, port))
         content.append("set_board_info rcp_prog \"/usr/bin/scp -P {0} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no\"".format(port))
 
         return "\n".join(content)