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