xref: /dpdk/dts/tests/TestSuite_blocklist.py (revision 125d85e72f9b85043fd75e4027cee76bf2c2c4ac)
1*125d85e7SLuca Vizzarro# SPDX-License-Identifier: BSD-3-Clause
2*125d85e7SLuca Vizzarro# Copyright(c) 2024 Arm Limited
3*125d85e7SLuca Vizzarro
4*125d85e7SLuca Vizzarro"""The DPDK device blocklisting test suite.
5*125d85e7SLuca Vizzarro
6*125d85e7SLuca VizzarroThis testing suite ensures tests the port blocklisting functionality of testpmd.
7*125d85e7SLuca Vizzarro"""
8*125d85e7SLuca Vizzarro
9*125d85e7SLuca Vizzarrofrom framework.remote_session.testpmd_shell import TestPmdShell
10*125d85e7SLuca Vizzarrofrom framework.test_suite import TestSuite, func_test
11*125d85e7SLuca Vizzarrofrom framework.testbed_model.capability import TopologyType, requires
12*125d85e7SLuca Vizzarrofrom framework.testbed_model.port import Port
13*125d85e7SLuca Vizzarro
14*125d85e7SLuca Vizzarro
15*125d85e7SLuca Vizzarro@requires(topology_type=TopologyType.two_links)
16*125d85e7SLuca Vizzarroclass TestBlocklist(TestSuite):
17*125d85e7SLuca Vizzarro    """DPDK device blocklisting test suite."""
18*125d85e7SLuca Vizzarro
19*125d85e7SLuca Vizzarro    def verify_blocklisted_ports(self, ports_to_block: list[Port]):
20*125d85e7SLuca Vizzarro        """Runs testpmd with the given ports blocklisted and verifies the ports."""
21*125d85e7SLuca Vizzarro        with TestPmdShell(self.sut_node, allowed_ports=[], blocked_ports=ports_to_block) as testpmd:
22*125d85e7SLuca Vizzarro            allowlisted_ports = {port.device_name for port in testpmd.show_port_info_all()}
23*125d85e7SLuca Vizzarro            blocklisted_ports = {port.pci for port in ports_to_block}
24*125d85e7SLuca Vizzarro
25*125d85e7SLuca Vizzarro            # sanity check
26*125d85e7SLuca Vizzarro            allowed_len = len(allowlisted_ports - blocklisted_ports)
27*125d85e7SLuca Vizzarro            self.verify(allowed_len > 0, "At least one port should have been allowed")
28*125d85e7SLuca Vizzarro
29*125d85e7SLuca Vizzarro            blocked = not allowlisted_ports & blocklisted_ports
30*125d85e7SLuca Vizzarro            self.verify(blocked, "At least one port was not blocklisted")
31*125d85e7SLuca Vizzarro
32*125d85e7SLuca Vizzarro    @func_test
33*125d85e7SLuca Vizzarro    def no_blocklisted(self):
34*125d85e7SLuca Vizzarro        """Run testpmd with no blocklisted device.
35*125d85e7SLuca Vizzarro
36*125d85e7SLuca Vizzarro        Steps:
37*125d85e7SLuca Vizzarro            Run testpmd without specifying allowed or blocked ports.
38*125d85e7SLuca Vizzarro        Verify:
39*125d85e7SLuca Vizzarro            That no ports were blocked.
40*125d85e7SLuca Vizzarro        """
41*125d85e7SLuca Vizzarro        self.verify_blocklisted_ports([])
42*125d85e7SLuca Vizzarro
43*125d85e7SLuca Vizzarro    @func_test
44*125d85e7SLuca Vizzarro    def one_port_blocklisted(self):
45*125d85e7SLuca Vizzarro        """Run testpmd with one blocklisted port.
46*125d85e7SLuca Vizzarro
47*125d85e7SLuca Vizzarro        Steps:
48*125d85e7SLuca Vizzarro            Run testpmd with one only one blocklisted port and allowing all the other ones.
49*125d85e7SLuca Vizzarro        Verify:
50*125d85e7SLuca Vizzarro            That the port was successfully blocklisted.
51*125d85e7SLuca Vizzarro        """
52*125d85e7SLuca Vizzarro        self.verify_blocklisted_ports(self.sut_node.ports[:1])
53*125d85e7SLuca Vizzarro
54*125d85e7SLuca Vizzarro    @func_test
55*125d85e7SLuca Vizzarro    def all_but_one_port_blocklisted(self):
56*125d85e7SLuca Vizzarro        """Run testpmd with all but one blocklisted port.
57*125d85e7SLuca Vizzarro
58*125d85e7SLuca Vizzarro        Steps:
59*125d85e7SLuca Vizzarro            Run testpmd with only one allowed port, blocking all the other ones.
60*125d85e7SLuca Vizzarro        Verify:
61*125d85e7SLuca Vizzarro            That all specified ports were successfully blocklisted.
62*125d85e7SLuca Vizzarro        """
63*125d85e7SLuca Vizzarro        self.verify_blocklisted_ports(self.sut_node.ports[:-1])
64