xref: /dpdk/dts/tests/TestSuite_smoke_tests.py (revision 3c4898ef762eeb2578b9ae3d7f6e3a0e5cbca8c8)
1# SPDX-License-Identifier: BSD-3-Clause
2# Copyright(c) 2023 University of New Hampshire
3
4import re
5
6from framework.config import PortConfig
7from framework.remote_session import TestPmdShell
8from framework.settings import SETTINGS
9from framework.test_suite import TestSuite
10from framework.utils import REGEX_FOR_PCI_ADDRESS
11
12
13class SmokeTests(TestSuite):
14    is_blocking = True
15    # dicts in this list are expected to have two keys:
16    # "pci_address" and "current_driver"
17    nics_in_node: list[PortConfig] = []
18
19    def set_up_suite(self) -> None:
20        """
21        Setup:
22            Set the build directory path and generate a list of NICs in the SUT node.
23        """
24        self.dpdk_build_dir_path = self.sut_node.remote_dpdk_build_dir
25        self.nics_in_node = self.sut_node.config.ports
26
27    def test_unit_tests(self) -> None:
28        """
29        Test:
30            Run the fast-test unit-test suite through meson.
31        """
32        self.sut_node.main_session.send_command(
33            f"meson test -C {self.dpdk_build_dir_path} --suite fast-tests -t 60",
34            480,
35            verify=True,
36            privileged=True,
37        )
38
39    def test_driver_tests(self) -> None:
40        """
41        Test:
42            Run the driver-test unit-test suite through meson.
43        """
44        vdev_args = ""
45        for dev in self.sut_node.virtual_devices:
46            vdev_args += f"--vdev {dev} "
47        vdev_args = vdev_args[:-1]
48        driver_tests_command = (
49            f"meson test -C {self.dpdk_build_dir_path} --suite driver-tests"
50        )
51        if vdev_args:
52            self._logger.info(
53                "Running driver tests with the following virtual "
54                f"devices: {vdev_args}"
55            )
56            driver_tests_command += f' --test-args "{vdev_args}"'
57
58        self.sut_node.main_session.send_command(
59            driver_tests_command,
60            300,
61            verify=True,
62            privileged=True,
63        )
64
65    def test_devices_listed_in_testpmd(self) -> None:
66        """
67        Test:
68            Uses testpmd driver to verify that devices have been found by testpmd.
69        """
70        testpmd_driver = self.sut_node.create_interactive_shell(
71            TestPmdShell, privileged=True
72        )
73        dev_list = [str(x) for x in testpmd_driver.get_devices()]
74        for nic in self.nics_in_node:
75            self.verify(
76                nic.pci in dev_list,
77                f"Device {nic.pci} was not listed in testpmd's available devices, "
78                "please check your configuration",
79            )
80
81    def test_device_bound_to_driver(self) -> None:
82        """
83        Test:
84            Ensure that all drivers listed in the config are bound to the correct
85            driver.
86        """
87        path_to_devbind = self.sut_node.path_to_devbind_script
88
89        all_nics_in_dpdk_devbind = self.sut_node.main_session.send_command(
90            f"{path_to_devbind} --status | awk '{REGEX_FOR_PCI_ADDRESS}'",
91            SETTINGS.timeout,
92        ).stdout
93
94        for nic in self.nics_in_node:
95            # This regular expression finds the line in the above string that starts
96            # with the address for the nic we are on in the loop and then captures the
97            # name of the driver in a group
98            devbind_info_for_nic = re.search(
99                f"{nic.pci}[^\\n]*drv=([\\d\\w]*) [^\\n]*",
100                all_nics_in_dpdk_devbind,
101            )
102            self.verify(
103                devbind_info_for_nic is not None,
104                f"Failed to find configured device ({nic.pci}) using dpdk-devbind.py",
105            )
106            # We know this isn't None, but mypy doesn't
107            assert devbind_info_for_nic is not None
108            self.verify(
109                devbind_info_for_nic.group(1) == nic.os_driver_for_dpdk,
110                f"Driver for device {nic.pci} does not match driver listed in "
111                f"configuration (bound to {devbind_info_for_nic.group(1)})",
112            )
113