[V2,5/9] framework/dut: add and modify methods to adapt to MEV testing

Message ID 20230825152825.2831565-6-songx.jiale@intel.com (mailing list archive)
State Superseded
Headers
Series add functions to test MEV |

Commit Message

Jiale Song Aug. 25, 2023, 3:28 p.m. UTC
  add and modify methods to adapt to MEV testing.

Signed-off-by: Jiale Song <songx.jiale@intel.com>
---
 framework/dut.py | 174 ++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 165 insertions(+), 9 deletions(-)
  

Patch

diff --git a/framework/dut.py b/framework/dut.py
index 0adb2786..d2a9cda5 100644
--- a/framework/dut.py
+++ b/framework/dut.py
@@ -2,6 +2,7 @@ 
 # Copyright(c) 2010-2014 Intel Corporation
 #
 
+import copy
 import os
 import re
 import threading
@@ -15,7 +16,16 @@  from nics.net_device import GetNicObj
 from .config import AppNameConf, PortConf
 from .crb import Crb
 from .exception import ParameterInvalidException
-from .settings import LOG_NAME_SEP, NICS
+from .logger import getLogger
+from .settings import (
+    DPDK_QUEUE_MODEL_SETTING,
+    DPDK_RX_VPORT_SETTING,
+    DPDK_TEST_ACC_SETTING,
+    DPDK_TEST_MEV_SETTING,
+    DPDK_VPORT_SETTING,
+    LOG_NAME_SEP,
+    NICS,
+)
 from .ssh_connection import SSHConnection
 from .test_result import ResultTable
 from .utils import RED, remove_old_rsa_key
@@ -62,6 +72,11 @@  class Dut(Crb):
         self.apps_name = {}
         self.dpdk_version = ""
         self.nic = None
+        self.test_mev = settings.load_global_setting(DPDK_TEST_MEV_SETTING).lower()
+        self.test_acc = settings.load_global_setting(DPDK_TEST_ACC_SETTING).lower()
+        if self.test_mev == "true":
+            self.imc_session = None
+            self.set_up_mev_test_env(alt_session)
 
     def filter_cores_from_crb_cfg(self):
         # get core list from crbs.cfg
@@ -188,20 +203,18 @@  class Dut(Crb):
 
         return file_prefix
 
-    def init_host_session(self, vm_name):
+    def init_host_session(self, name):
         """
         Create session for each VM, session will be handled by VM instance
         """
         self.host_session = SSHConnection(
             self.get_ip_address(),
-            vm_name + "_host",
+            name + "_host",
             self.get_username(),
             self.get_password(),
         )
         self.host_session.init_log(self.logger)
-        self.logger.info(
-            "[%s] create new session for VM" % (threading.current_thread().name)
-        )
+        self.logger.info("create new session for %s" % (name))
 
     def new_session(self, suite=""):
         """
@@ -274,6 +287,18 @@  class Dut(Crb):
         """
         self.send_expect("mount -t procfs proc /proc", "# ")
 
+    def get_imc_ip_address(self):
+        """
+        Get MEV imc ip address.
+        """
+        return self.crb["IMC IP"]
+
+    def get_acc_ip_address(self):
+        """
+        Get MEV acc ip address.
+        """
+        return self.crb["ACC IP"]
+
     def get_ip_address(self):
         """
         Get DUT's ip address.
@@ -331,7 +356,6 @@  class Dut(Crb):
         # disable tester port ipv6
         self.disable_tester_ipv6()
         self.get_nic_configurations()
-
         # print latest ports_info
         for port_info in self.ports_info:
             self.logger.info(port_info)
@@ -354,6 +378,26 @@  class Dut(Crb):
             if self.nic.default_driver == "ice":
                 self.get_nic_pkg(retry_times)
 
+    def get_mev_nic_configurations(self):
+        self.vport = settings.load_global_setting(DPDK_VPORT_SETTING).lower()
+        try:
+            vport = self.vport.split("-")
+            vport = list(range(int(vport[0]), int(vport[1]) + 1))
+        except:
+            vport = [
+                int(self.vport),
+            ]
+
+        if len(vport) > 1:
+            for i in range(len(vport) - 1):
+                dut_port_info = copy.copy(self.ports_info[0])
+                tester_port_info = copy.copy(self.tester.ports_info[0])
+                dut_port_info["mac"] = self.ports_info[0]["mac"].replace(
+                    "0", str(i + 1), 2
+                )
+                self.ports_info.append(dut_port_info)
+                self.tester.ports_info.append(tester_port_info)
+
     def get_nic_pkg(self, retry_times=3):
         self.nic.pkg = self.nic.get_nic_pkg()
         while not self.nic.pkg.get("type") and retry_times > 0:
@@ -1363,6 +1407,8 @@  class Dut(Crb):
             self.alt_session = None
         if self.host_init_flag:
             self.host_session.close()
+        if self.imc_session:
+            self.imc_session.close()
 
     def virt_exit(self):
         """
@@ -1382,6 +1428,98 @@  class Dut(Crb):
         self.close()
         self.logger.logger_exit()
 
+    def create_imc_session(self):
+        self.logger.info("create new session for %s" % ("dut_imc"))
+        self.imc_session = SSHConnection(
+            host=self.get_imc_ip_address(),
+            session_name="dut_imc",
+            username=self.get_username(),
+            password=self.get_password(),
+        )
+        self.imc_session.init_log(getLogger("dut_imc"))
+
+    def create_acc_session(self, alt_session=True):
+        self.logger.info("create new session for %s" % ("dut_acc"))
+        self.acc_session = SSHConnection(
+            host=self.get_acc_ip_address(),
+            session_name="dut_acc",
+            username=self.get_username(),
+            password=self.get_password(),
+        )
+        self.acc_session.init_log(getLogger("dut_acc"))
+        if alt_session:
+            self.acc_alt_session = SSHConnection(
+                host=self.get_acc_ip_address(),
+                session_name="dut_acc",
+                username=self.get_username(),
+                password=self.get_password(),
+            )
+
+    def create_session(self, name=""):
+        """
+        Create new session for additional usage. This session will not enable log.
+        """
+        if self.test_acc:
+            logger = getLogger(name)
+            session = SSHConnection(
+                self.get_acc_ip_address(),
+                name,
+                self.get_username(),
+                self.get_password(),
+                dut_id=self.dut_id,
+            )
+            session.init_log(logger)
+        else:
+            logger = getLogger(name)
+            session = SSHConnection(
+                self.get_ip_address(),
+                name,
+                self.get_username(),
+                self.get_password(),
+                dut_id=self.dut_id,
+            )
+            session.init_log(logger)
+        self.sessions.append(session)
+        return session
+
+    def mev_config_rx_port(self, out):
+        rx_vport = settings.load_global_setting(DPDK_RX_VPORT_SETTING).lower()
+        # matching rx vport mac addresses
+        regex = re.compile(
+            "Port\s+%s.*\s*.*:\s*(([0-9A-F]{2}:){5}[0-9A-F]{2})" % rx_vport
+        )
+        match_mac = regex.search(out)
+        if match_mac:
+            mac = match_mac.group(1)
+        else:
+            raise ParameterInvalidException(
+                "Unable to match the mac address of the rx vport!!!"
+            )
+        output = self.imc_session.send_expect(
+            "cli_client --query --config --verbose", "# "
+        )
+        match_vsi_id = re.search(
+            "vsi_id:\s+0x(\w+).*is_created:\s+yes.*mac\s+addr:\s+%s" % (mac.lower()),
+            output,
+        )
+        if match_vsi_id:
+            self.imc_session.send_expect(
+                "devmem 0x202920C100 64 0x80%s" % (match_vsi_id.group(1)), "# "
+            )
+        else:
+            raise ParameterInvalidException(
+                "Unable to match the vsi id of the rx vport!!!"
+            )
+
+    def set_up_mev_test_env(self, alt_session=True):
+        if self.test_acc == "true":
+            self.close()
+            self.create_acc_session(alt_session)
+            self.session = self.acc_session
+            self.alt_session = self.acc_alt_session
+        self.init_host_session("mev_host")
+        self.create_imc_session()
+
 
 class _EalParameter(object):
     def __init__(
@@ -1428,6 +1566,8 @@  class _EalParameter(object):
         param other_eal_param: user defined DPDK eal parameters, eg:
                         other_eal_param='--single-file-segments';
         """
+        self.test_mev = settings.load_global_setting(DPDK_TEST_MEV_SETTING).lower()
+        self.test_acc = settings.load_global_setting(DPDK_TEST_ACC_SETTING).lower()
         self.os_type = dut.get_os_type()
         self.fixed_prefix = fixed_prefix
         self.socket = socket
@@ -1561,7 +1701,11 @@  class _EalParameter(object):
             for port_info in self.dut.ports_info:
                 pci_list.append("%s %s" % (allow_option, port_info["pci"]))
         self.dut.logger.info(pci_list)
-        return " ".join(pci_list)
+        port_param = " ".join(pci_list)
+        if self.test_mev == "true":
+            mev_port_options = self._get_mev_port_options()
+            return port_param + f",{mev_port_options}"
+        return port_param
 
     def _make_b_ports_param(self) -> str:
         b_pci_list = []
@@ -1638,8 +1782,11 @@  class _EalParameter(object):
         port_mac_addr = self.dut.ports_info[port]["pci"] if type(port) == int else port
         port_param = f"{allow_option} {port_mac_addr}"
         port_option = self._get_port_options_from_config(port)
+        if self.test_mev == "true":
+            mev_port_options = self._get_mev_port_options()
+            port_param = port_param + f",{mev_port_options}"
         if port_option:
-            port_param = f"{port_param},{port_option}"
+            port_param = port_param + f",{port_option}"
         return port_param
 
     def _get_port_options_from_config(self, port: Union[str, int]) -> str:
@@ -1680,3 +1827,12 @@  class _EalParameter(object):
             ]
         )
         return _eal_str
+
+    def _get_mev_port_options(self):
+        self.queue_model = settings.load_global_setting(DPDK_QUEUE_MODEL_SETTING)
+        self.vport = settings.load_global_setting(DPDK_VPORT_SETTING)
+        port_options_dict = {
+            "splitq": f"vport={self.vport}",
+            "singleq": f"vport={self.vport},rx_single=1,tx_single=1",
+        }
+        return port_options_dict[self.queue_model]