[v2,2/2] dts: add pf smoke testing suite

Message ID 20240906165151.14668-3-jspewock@iol.unh.edu (mailing list archive)
State Superseded
Delegated to: Juraj Linkeš
Headers
Series dts: pf_smoke port |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation warning apply issues

Commit Message

Jeremy Spewock Sept. 6, 2024, 4:51 p.m. UTC
From: Jeremy Spewock <jspewock@iol.unh.edu>

This patch adds a smoke testing suite for Physical Function features.
The goal of this suite is to test some of the most basic features of
DPDK on a physical function and bail out early if any of these features
aren't supported as expected. Unlike DTS smoke tests, these ones are not
included as a switch in the config file and thus are an additional test
suite that developers can include alongside others at their own
discretion.

Depends-on: patch-143594 ("dts: add send_packets to test suites and
 rework packet addressing")

Signed-off-by: Jeremy Spewock <jspewock@iol.unh.edu>
---
 dts/framework/config/conf_yaml_schema.json |   3 +-
 dts/tests/TestSuite_pf_smoke_tests.py      | 121 +++++++++++++++++++++
 2 files changed, 123 insertions(+), 1 deletion(-)
 create mode 100644 dts/tests/TestSuite_pf_smoke_tests.py
  

Patch

diff --git a/dts/framework/config/conf_yaml_schema.json b/dts/framework/config/conf_yaml_schema.json
index f02a310bb5..910134f9e4 100644
--- a/dts/framework/config/conf_yaml_schema.json
+++ b/dts/framework/config/conf_yaml_schema.json
@@ -187,7 +187,8 @@ 
       "enum": [
         "hello_world",
         "os_udp",
-        "pmd_buffer_scatter"
+        "pmd_buffer_scatter",
+        "pf_smoke_tests"
       ]
     },
     "test_target": {
diff --git a/dts/tests/TestSuite_pf_smoke_tests.py b/dts/tests/TestSuite_pf_smoke_tests.py
new file mode 100644
index 0000000000..287132e9dd
--- /dev/null
+++ b/dts/tests/TestSuite_pf_smoke_tests.py
@@ -0,0 +1,121 @@ 
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2024 University of New Hampshire
+"""Physical Function (PF) smoke testing suite.
+
+This test suite tests some of the more common DPDK functionality on a PF. Things such as
+jumbroframes, Receive Side Scaling (RSS) functions, and being able to modify the number of queues
+at runtime should all be supported by PMDs that are capable of running DPDK. Since this is a smoke
+testing suite, it is considered a blocking suite that will stop following ones from running.
+"""
+
+from typing import ClassVar
+
+from scapy.layers.inet import IP  # type: ignore[import-untyped]
+from scapy.layers.l2 import Ether  # type: ignore[import-untyped]
+from scapy.packet import Raw  # type: ignore[import-untyped]
+
+from framework.exception import InteractiveCommandExecutionError, TestCaseVerifyError
+from framework.params.testpmd import SimpleForwardingModes
+from framework.remote_session.testpmd_shell import TestPmdShell
+from framework.test_suite import TestSuite
+
+
+class TestPfSmokeTests(TestSuite):
+    """DPDK Physical Function Testing Suite.
+
+    This test suite is designed to verify the basic functions of DPDK on a PF. The MTU of the ports
+    on the traffic generator are increased to 9000 to support jumboframes for one of the test
+    cases, and then reverted back to 1500 once the test suite is complete.
+
+    Attributes:
+        is_blocking: This test suite will block the execution of all other test suites
+            in the build target after it.
+    """
+
+    is_blocking: ClassVar[bool] = True
+    jumbo_frame_len: ClassVar[int] = 9000
+    num_queues: int = 4
+
+    def set_up_suite(self) -> None:
+        """Increase the MTU of the traffic generator to support jumboframes."""
+        for port_link in self._port_links:
+            self.tg_node.main_session.configure_port_mtu(self.jumbo_frame_len, port_link.tg_port)
+
+    def test_jumbo_frame_support(self) -> None:
+        """Verify that the PF is able to send and receive jumboframes."""
+        with TestPmdShell(
+            self.sut_node,
+            max_pkt_len=self.jumbo_frame_len,
+            mbuf_size=[self.jumbo_frame_len + 128],
+            forward_mode=SimpleForwardingModes.mac,
+        ) as testpmd:
+            testpmd.start()
+            # Take 26 bytes off the MTU size to account for Ethernet headers
+            payload_len = self.jumbo_frame_len - 26
+            packet = Ether() / Raw("X" * payload_len)
+            recv = self.send_packet_and_capture(packet)
+            self.verify(
+                any(hasattr(p, "load") and "X" * 20 in str(p.load) for p in recv),
+                f"Jumboframe was not received even when MTU was set to {self.jumbo_frame_len}.",
+            )
+
+    def test_rss_functionality(self) -> None:
+        """Test that Receive Side Scaling functions are working as intended.
+
+        The primary things to test in this case are that packets that are sent with different
+        destination IP addresses are handled by different queues and that the RSS hash of every
+        packet is unique. Verification of these functionalities is done by sending packets with
+        a unique source MAC addresses so that the packets sent by this test suite can be
+        differentiated from other packets sent to the same port.
+        """
+        with TestPmdShell(
+            self.sut_node,
+            forward_mode=SimpleForwardingModes.rxonly,
+            rx_queues=self.num_queues,
+            tx_queues=self.num_queues,
+        ) as testpmd:
+            testpmd.set_verbose(1)
+            src_max = "00:00:00:00:00:01"
+            send_pkts = [
+                Ether(src=src_max) / IP(dst=f"192.168.0.{i+1}") for i in range(self.num_queues * 4)
+            ]
+            testpmd.start()
+            self.send_packets(send_pkts)
+            verbose_stats = TestPmdShell.extract_verbose_output(testpmd.stop())
+            # Filter down the packets to only the ones with the correct source MAC
+            verbose_stats = list(filter(lambda x: x.src_mac == src_max, verbose_stats))
+            self.verify(
+                len(verbose_stats) > 0, "Testpmd did not receive any packets from the test case."
+            )
+            rss_hashes = [p.rss_hash for p in verbose_stats]
+            self.verify(
+                all(rss_h is not None for rss_h in rss_hashes),
+                "At least one packet did not have an RSS hash.",
+            )
+            self.verify(
+                len(set(rss_hashes)) == len(rss_hashes),
+                "RSS hashes were not unique.",
+            )
+            self.verify(
+                all(any(q == p.queue_id for p in verbose_stats) for q in range(self.num_queues)),
+                "Not all ports were used when packets were sent with different destination "
+                "addresses.",
+            )
+
+    def test_runtime_modify_num_queues(self) -> None:
+        """Ensure that the number of queues on a port can be changed at runtime."""
+        with TestPmdShell(
+            self.sut_node, rx_queues=self.num_queues, tx_queues=self.num_queues
+        ) as testpmd:
+            try:
+                testpmd.set_num_queues_all(2, True, verify=True)
+                testpmd.set_num_queues_all(2, False, verify=True)
+            except InteractiveCommandExecutionError as e:
+                raise TestCaseVerifyError(
+                    "Failed to change the number of queues on a port at runtime."
+                ) from e
+
+    def tear_down_suite(self) -> None:
+        """Revert MTU back to a standard value of 1500."""
+        for port_link in self._port_links:
+            self.tg_node.main_session.configure_port_mtu(1500, port_link.tg_port)