From 645a53f3858f206dad94d481b2ea006c2f9196ce Mon Sep 17 00:00:00 2001 From: Matthew McGovern Date: Wed, 27 Sep 2023 15:56:24 -0700 Subject: [PATCH] refactor and add kconfig only test --- microsoft/testsuites/core/mana.py | 197 ++++++++++++++++++------------ 1 file changed, 117 insertions(+), 80 deletions(-) diff --git a/microsoft/testsuites/core/mana.py b/microsoft/testsuites/core/mana.py index 0b650e7f6c..5f74ce3ef1 100644 --- a/microsoft/testsuites/core/mana.py +++ b/microsoft/testsuites/core/mana.py @@ -1,4 +1,5 @@ import re +from typing import Pattern from lisa import ( LisaException, @@ -11,7 +12,7 @@ ) from lisa.operating_system import Linux, Posix from lisa.sut_orchestrator import AZURE -from lisa.tools import Dmesg, KernelConfig, Modprobe +from lisa.tools import Dmesg, KernelConfig, Lsmod, Modprobe @TestSuiteMetadata( @@ -24,76 +25,103 @@ class ManaDriverCheck(TestSuite): MANA_DRIVER_MESSAGE_PATTERN = re.compile(r"\[\s*[0-9.]+\s*\]\s+mana\s+.*") MANA_IB_DRIVER_MESSAGE_PATTERN = re.compile(r"\[\s*[0-9.]+\s*\]\s+mana_ib\s+.*") - - @TestCaseMetadata( - description=""" - This test case checks for the mana ethernet driver. - """, - priority=3, - requirement=simple_requirement( - supported_platform_type=[AZURE], supported_os=[Posix] - ), - ) - def verify_mana_en_driver_present(self, node: Node) -> None: - if not node.nics.is_mana_device_present(): - raise SkippedException( - "MANA driver tests should be run in a MANA VM environment" - ) - - distro = node.os - if isinstance(distro, Linux): - if distro.get_kernel_information().version < "5.15.0": - raise SkippedException("MANA is not available for kernels < 5.15") - - mana_driver_name = "mana" + MANA_EN_KCONFIG = "CONFIG_MICROSOFT_MANA" + MANA_IB_KCONFIG = "CONFIG_MANA_INFINIBAND" + + def _check_for_driver( + self, + node: Node, + driver_name: str, + kconfig_variable: str, + dmesg_pattern: Pattern[str], + verify_module_loads: bool = False, + ) -> None: dmesg = node.tools[Dmesg] + lsmod = node.tools[Lsmod] modprobe = node.tools[Modprobe] kconfig = node.tools[KernelConfig] # Check kconfig for mana - mana_is_builtin = kconfig.is_built_in(mana_driver_name) - mana_is_module = kconfig.is_built_as_module(mana_driver_name) + mana_is_builtin = kconfig.is_built_in(kconfig_variable) + mana_is_module = kconfig.is_built_as_module(kconfig_variable) if mana_is_builtin: - node.log.info(f"{mana_driver_name} is reported as builtin in kconfig") + node.log.info(f"{driver_name} is reported as builtin in kconfig") elif mana_is_module: node.log.info( - f"{mana_driver_name} is reported as a loadable kernel module in kconfig" + f"{driver_name} is reported as a loadable kernel module in kconfig" ) else: node.log.info( ( - f"{mana_driver_name} is not in kconfig for this image, " + f"{driver_name} is not in kconfig for this image, " "checking if driver is present (possible out of tree build)" ) ) # check modprobe for loadable module - module_exists = modprobe.module_exists(mana_driver_name) - module_loaded = modprobe.is_module_loaded(mana_driver_name) + module_exists = modprobe.module_exists(driver_name) + module_loaded = modprobe.is_module_loaded(driver_name) # if it isn't loaded, will not load, and isn't builtin, fail fast. if not any([module_loaded, module_exists, mana_is_builtin]): - raise LisaException(f"{mana_driver_name} is not present on this system") + raise LisaException(f"{driver_name} is not present on this system") + + # allow return before loading check to enable kconfig only test + if not verify_module_loads: + return # If module is not loaded, but is loadable, attempt to load the module # This will throw if the module isn't found. if module_exists and not (mana_is_builtin or module_loaded): - node.log.info( - f"Attempting to load {mana_driver_name} driver with modprobe..." - ) - modprobe.load(mana_driver_name) + node.log.info(f"Attempting to load {driver_name} driver with modprobe...") + modprobe.load(driver_name) + # verify driver is loaded with lsmod + module_loaded = lsmod.module_exists(driver_name, force_run=True) + if not module_loaded: + raise LisaException( + f"MANA driver {driver_name} was not detected after loading." + ) # finally, verify that mana driver logs are present after loading. kernel_driver_output = dmesg.get_output(force_run=True) - matches = self.MANA_DRIVER_MESSAGE_PATTERN.search(kernel_driver_output) + matches = dmesg_pattern.search(kernel_driver_output) if not matches: raise LisaException( ( - f"{mana_driver_name} driver reported as present but " - f"no {mana_driver_name} logs in driver messages." + f"{driver_name} driver reported as present but " + f"no {driver_name} logs in driver messages." ) ) + @TestCaseMetadata( + description=""" + This test case checks for the mana ethernet driver. + """, + priority=3, + requirement=simple_requirement( + supported_platform_type=[AZURE], supported_os=[Posix] + ), + ) + def verify_mana_en_driver_present(self, node: Node) -> None: + if not node.nics.is_mana_device_present(): + raise SkippedException( + "MANA driver tests should be run in a MANA VM environment" + ) + + distro = node.os + if isinstance(distro, Linux): + if distro.get_kernel_information().version < "5.15.0": + raise SkippedException("MANA is not available for kernels < 5.15") + + mana_driver_name = "mana" + self._check_for_driver( + node, + driver_name=mana_driver_name, + kconfig_variable=self.MANA_EN_KCONFIG, + dmesg_pattern=self.MANA_DRIVER_MESSAGE_PATTERN, + verify_module_loads=True, + ) + @TestCaseMetadata( description=""" This test case checks for the mana ethernet driver. @@ -115,50 +143,59 @@ def verify_mana_ib_driver_present(self, node: Node) -> None: raise SkippedException("MANA is not available for kernels < 5.15") mana_driver_name = "mana_ib" - dmesg = node.tools[Dmesg] - modprobe = node.tools[Modprobe] - kconfig = node.tools[KernelConfig] - # Check kconfig for mana - mana_is_builtin = kconfig.is_built_in(mana_driver_name) - mana_is_module = kconfig.is_built_as_module(mana_driver_name) - if mana_is_builtin: - node.log.info(f"{mana_driver_name} is reported as builtin in kconfig") - elif mana_is_module: - node.log.info( - f"{mana_driver_name} is reported as a loadable kernel module in kconfig" - ) - else: - node.log.info( - ( - f"{mana_driver_name} is not in kconfig for this image, " - "checking if driver is present (possible out of tree build)" - ) - ) + self._check_for_driver( + node, + driver_name=mana_driver_name, + kconfig_variable=self.MANA_IB_KCONFIG, + dmesg_pattern=self.MANA_IB_DRIVER_MESSAGE_PATTERN, + verify_module_loads=True, + ) - # check modprobe for loadable module - module_exists = modprobe.module_exists(mana_driver_name) - module_loaded = modprobe.is_module_loaded(mana_driver_name) + @TestCaseMetadata( + description=""" + This test case checks kconfig only for the mana ethernet driver. + """, + priority=3, + requirement=simple_requirement( + supported_platform_type=[AZURE], supported_os=[Posix] + ), + ) + def verify_mana_en_driver_kconfig(self, node: Node) -> None: + distro = node.os + if isinstance(distro, Linux): + if distro.get_kernel_information().version < "5.15.0": + raise SkippedException("MANA is not available for kernels < 5.15") - # if it isn't loaded, will not load, and isn't builtin, fail fast. - if not any([module_loaded, module_exists, mana_is_builtin]): - raise LisaException(f"{mana_driver_name} is not present on this system") + mana_driver_name = "mana" + self._check_for_driver( + node, + driver_name=mana_driver_name, + kconfig_variable=self.MANA_EN_KCONFIG, + dmesg_pattern=self.MANA_DRIVER_MESSAGE_PATTERN, + verify_module_loads=False, + ) - # If module is not loaded, but is loadable, attempt to load the module - # This will throw if the module isn't found. - if module_exists and not (mana_is_builtin or module_loaded): - node.log.info( - f"Attempting to load {mana_driver_name} driver with modprobe..." - ) - modprobe.load(mana_driver_name) + @TestCaseMetadata( + description=""" + This test case checks kconfig only for the mana infiniband driver. + """, + priority=3, + requirement=simple_requirement( + supported_platform_type=[AZURE], supported_os=[Posix] + ), + ) + def verify_mana_en_driver_kconfig(self, node: Node) -> None: + distro = node.os + if isinstance(distro, Linux): + if distro.get_kernel_information().version < "5.15.0": + raise SkippedException("MANA is not available for kernels < 5.15") - # finally, verify that mana driver logs are present after loading. - kernel_driver_output = dmesg.get_output(force_run=True) - matches = self.MANA_DRIVER_MESSAGE_PATTERN.search(kernel_driver_output) - if not matches: - raise LisaException( - ( - f"{mana_driver_name} driver reported as present but " - f"no {mana_driver_name} logs in driver messages." - ) - ) + mana_driver_name = "mana_ib" + self._check_for_driver( + node, + driver_name=mana_driver_name, + kconfig_variable=self.MANA_IB_KCONFIG, + dmesg_pattern=self.MANA_IB_DRIVER_MESSAGE_PATTERN, + verify_module_loads=False, + )