1# SPDX-License-Identifier: BSD-3-Clause 2# Copyright(c) 2023 University of New Hampshire 3 4"""Smoke test suite. 5 6Smoke tests are a class of tests which are used for validating a minimal set of important features. 7These are the most important features without which (or when they're faulty) the software wouldn't 8work properly. Thus, if any failure occurs while testing these features, 9there isn't that much of a reason to continue testing, as the software is fundamentally broken. 10 11These tests don't have to include only DPDK tests, as the reason for failures could be 12in the infrastructure (a faulty link between NICs or a misconfiguration). 13""" 14 15import re 16 17from framework.config import PortConfig 18from framework.remote_session import TestPmdShell 19from framework.settings import SETTINGS 20from framework.test_suite import TestSuite 21from framework.utils import REGEX_FOR_PCI_ADDRESS 22 23 24class SmokeTests(TestSuite): 25 """DPDK and infrastructure smoke test suite. 26 27 The test cases validate the most basic DPDK functionality needed for all other test suites. 28 The infrastructure also needs to be tested, as that is also used by all other test suites. 29 30 Attributes: 31 is_blocking: This test suite will block the execution of all other test suites 32 in the build target after it. 33 nics_in_node: The NICs present on the SUT node. 34 """ 35 36 is_blocking = True 37 # dicts in this list are expected to have two keys: 38 # "pci_address" and "current_driver" 39 nics_in_node: list[PortConfig] = [] 40 41 def set_up_suite(self) -> None: 42 """Set up the test suite. 43 44 Setup: 45 Set the build directory path and a list of NICs in the SUT node. 46 """ 47 self.dpdk_build_dir_path = self.sut_node.remote_dpdk_build_dir 48 self.nics_in_node = self.sut_node.config.ports 49 50 def test_unit_tests(self) -> None: 51 """DPDK meson ``fast-tests`` unit tests. 52 53 Test that all unit test from the ``fast-tests`` suite pass. 54 The suite is a subset with only the most basic tests. 55 56 Test: 57 Run the ``fast-tests`` unit test suite through meson. 58 """ 59 self.sut_node.main_session.send_command( 60 f"meson test -C {self.dpdk_build_dir_path} --suite fast-tests -t 60", 61 480, 62 verify=True, 63 privileged=True, 64 ) 65 66 def test_driver_tests(self) -> None: 67 """DPDK meson ``driver-tests`` unit tests. 68 69 Test that all unit test from the ``driver-tests`` suite pass. 70 The suite is a subset with driver tests. This suite may be run with virtual devices 71 configured in the test run configuration. 72 73 Test: 74 Run the ``driver-tests`` unit test suite through meson. 75 """ 76 vdev_args = "" 77 for dev in self.sut_node.virtual_devices: 78 vdev_args += f"--vdev {dev} " 79 vdev_args = vdev_args[:-1] 80 driver_tests_command = f"meson test -C {self.dpdk_build_dir_path} --suite driver-tests" 81 if vdev_args: 82 self._logger.info( 83 f"Running driver tests with the following virtual devices: {vdev_args}" 84 ) 85 driver_tests_command += f' --test-args "{vdev_args}"' 86 87 self.sut_node.main_session.send_command( 88 driver_tests_command, 89 300, 90 verify=True, 91 privileged=True, 92 ) 93 94 def test_devices_listed_in_testpmd(self) -> None: 95 """Testpmd device discovery. 96 97 Test that the devices configured in the test run configuration are found in testpmd. 98 99 Test: 100 List all devices found in testpmd and verify the configured devices are among them. 101 """ 102 testpmd_driver = self.sut_node.create_interactive_shell(TestPmdShell, privileged=True) 103 dev_list = [str(x) for x in testpmd_driver.get_devices()] 104 for nic in self.nics_in_node: 105 self.verify( 106 nic.pci in dev_list, 107 f"Device {nic.pci} was not listed in testpmd's available devices, " 108 "please check your configuration", 109 ) 110 111 def test_device_bound_to_driver(self) -> None: 112 """Device driver in OS. 113 114 Test that the devices configured in the test run configuration are bound to 115 the proper driver. 116 117 Test: 118 List all devices with the ``dpdk-devbind.py`` script and verify that 119 the configured devices are bound to the proper driver. 120 """ 121 path_to_devbind = self.sut_node.path_to_devbind_script 122 123 all_nics_in_dpdk_devbind = self.sut_node.main_session.send_command( 124 f"{path_to_devbind} --status | awk '{REGEX_FOR_PCI_ADDRESS}'", 125 SETTINGS.timeout, 126 ).stdout 127 128 for nic in self.nics_in_node: 129 # This regular expression finds the line in the above string that starts 130 # with the address for the nic we are on in the loop and then captures the 131 # name of the driver in a group 132 devbind_info_for_nic = re.search( 133 f"{nic.pci}[^\\n]*drv=([\\d\\w]*) [^\\n]*", 134 all_nics_in_dpdk_devbind, 135 ) 136 self.verify( 137 devbind_info_for_nic is not None, 138 f"Failed to find configured device ({nic.pci}) using dpdk-devbind.py", 139 ) 140 # We know this isn't None, but mypy doesn't 141 assert devbind_info_for_nic is not None 142 self.verify( 143 devbind_info_for_nic.group(1) == nic.os_driver_for_dpdk, 144 f"Driver for device {nic.pci} does not match driver listed in " 145 f"configuration (bound to {devbind_info_for_nic.group(1)})", 146 ) 147