xref: /dpdk/dts/tests/TestSuite_smoke_tests.py (revision b6eb5004460e1e96269a29a54ae70c24611ad4b0)
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.testpmd_shell import TestPmdShell
19from framework.settings import SETTINGS
20from framework.test_suite import TestSuite, func_test
21from framework.utils import REGEX_FOR_PCI_ADDRESS
22
23
24class TestSmokeTests(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    @func_test
51    def test_unit_tests(self) -> None:
52        """DPDK meson ``fast-tests`` unit tests.
53
54        Test that all unit test from the ``fast-tests`` suite pass.
55        The suite is a subset with only the most basic tests.
56
57        Test:
58            Run the ``fast-tests`` unit test suite through meson.
59        """
60        self.sut_node.main_session.send_command(
61            f"meson test -C {self.dpdk_build_dir_path} --suite fast-tests -t 60",
62            480,
63            verify=True,
64            privileged=True,
65        )
66
67    @func_test
68    def test_driver_tests(self) -> None:
69        """DPDK meson ``driver-tests`` unit tests.
70
71        Test that all unit test from the ``driver-tests`` suite pass.
72        The suite is a subset with driver tests. This suite may be run with virtual devices
73        configured in the test run configuration.
74
75        Test:
76            Run the ``driver-tests`` unit test suite through meson.
77        """
78        vdev_args = ""
79        for dev in self.sut_node.virtual_devices:
80            vdev_args += f"--vdev {dev} "
81        vdev_args = vdev_args[:-1]
82        driver_tests_command = f"meson test -C {self.dpdk_build_dir_path} --suite driver-tests"
83        if vdev_args:
84            self._logger.info(
85                f"Running driver tests with the following virtual devices: {vdev_args}"
86            )
87            driver_tests_command += f' --test-args "{vdev_args}"'
88
89        self.sut_node.main_session.send_command(
90            driver_tests_command,
91            300,
92            verify=True,
93            privileged=True,
94        )
95
96    @func_test
97    def test_devices_listed_in_testpmd(self) -> None:
98        """Testpmd device discovery.
99
100        Test that the devices configured in the test run configuration are found in testpmd.
101
102        Test:
103            List all devices found in testpmd and verify the configured devices are among them.
104        """
105        with TestPmdShell(self.sut_node) as testpmd:
106            dev_list = [str(x) for x in testpmd.get_devices()]
107        for nic in self.nics_in_node:
108            self.verify(
109                nic.pci in dev_list,
110                f"Device {nic.pci} was not listed in testpmd's available devices, "
111                "please check your configuration",
112            )
113
114    @func_test
115    def test_device_bound_to_driver(self) -> None:
116        """Device driver in OS.
117
118        Test that the devices configured in the test run configuration are bound to
119        the proper driver.
120
121        Test:
122            List all devices with the ``dpdk-devbind.py`` script and verify that
123            the configured devices are bound to the proper driver.
124        """
125        path_to_devbind = self.sut_node.path_to_devbind_script
126
127        all_nics_in_dpdk_devbind = self.sut_node.main_session.send_command(
128            f"{path_to_devbind} --status | awk '{REGEX_FOR_PCI_ADDRESS}'",
129            SETTINGS.timeout,
130        ).stdout
131
132        for nic in self.nics_in_node:
133            # This regular expression finds the line in the above string that starts
134            # with the address for the nic we are on in the loop and then captures the
135            # name of the driver in a group
136            devbind_info_for_nic = re.search(
137                f"{nic.pci}[^\\n]*drv=([\\d\\w-]*) [^\\n]*",
138                all_nics_in_dpdk_devbind,
139            )
140            self.verify(
141                devbind_info_for_nic is not None,
142                f"Failed to find configured device ({nic.pci}) using dpdk-devbind.py",
143            )
144            # We know this isn't None, but mypy doesn't
145            assert devbind_info_for_nic is not None
146            self.verify(
147                devbind_info_for_nic.group(1) == nic.os_driver_for_dpdk,
148                f"Driver for device {nic.pci} does not match driver listed in "
149                f"configuration (bound to {devbind_info_for_nic.group(1)})",
150            )
151