From: Maxim Chicherin <maximc@xxxxxxxxxxxx> This test creates active and passive sides for RDMACM communication and validates received messages. Signed-off-by: Maxim Chicherin <maximc@xxxxxxxxxxxx> --- tests/CMakeLists.txt | 2 ++ tests/rdmacm_utils.py | 43 ++++++++++++++++++++++++++++++++ tests/test_rdmacm.py | 57 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) mode change 100644 => 100755 tests/CMakeLists.txt create mode 100755 tests/rdmacm_utils.py create mode 100755 tests/test_rdmacm.py diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt old mode 100644 new mode 100755 index 960276230860..0d81d1a98fb7 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,6 +3,7 @@ rdma_python_test(tests __init__.py + rdmacm_utils.py test_addr.py base.py test_cq.py @@ -11,6 +12,7 @@ rdma_python_test(tests test_pd.py test_qp.py test_odp.py + test_rdmacm.py utils.py ) diff --git a/tests/rdmacm_utils.py b/tests/rdmacm_utils.py new file mode 100755 index 000000000000..59b627393e4f --- /dev/null +++ b/tests/rdmacm_utils.py @@ -0,0 +1,43 @@ +# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) +# Copyright (c) 2019 Mellanox Technologies, Inc. All rights reserved. See COPYING file +""" +Provide some useful helper function for pyverbs rdmacm' tests. +""" +from tests.base import CMResources +from tests.utils import validate + + +def active_side(node): + client = CMResources(dst=node) + client.pre_run() + connected_id = client.cmid + send_msg = 'c' * client.msg_size + for _ in range(client.num_msgs): + client.mr.write(send_msg, client.msg_size) + connected_id.post_send(client.mr) + while connected_id.get_send_comp() is None: + pass + connected_id.post_recv(client.mr) + while connected_id.get_recv_comp() is None: + pass + msg_received = client.mr.read(client.msg_size, 0) + validate(msg_received, False, client.msg_size) + connected_id.disconnect() + + +def passive_side(node): + server = CMResources(src=node) + server.pre_run() + connected_id = server.new_id + send_msg = 's' * server.msg_size + for _ in range(server.num_msgs): + connected_id.post_recv(server.mr) + while connected_id.get_recv_comp() is None: + pass + msg_received = server.mr.read(server.msg_size, 0) + validate(msg_received, True, server.msg_size) + server.mr.write(send_msg, server.msg_size) + connected_id.post_send(server.mr) + while connected_id.get_send_comp() is None: + pass + connected_id.disconnect() diff --git a/tests/test_rdmacm.py b/tests/test_rdmacm.py new file mode 100755 index 000000000000..e435c635d7b2 --- /dev/null +++ b/tests/test_rdmacm.py @@ -0,0 +1,57 @@ +from tests.rdmacm_utils import active_side, passive_side +from tests.base import RDMATestCase +from multiprocessing import Process +import pyverbs.device as d +import subprocess +import unittest +import json + + +class CMTestCase(RDMATestCase): + def setUp(self): + if self.dev_name is not None: + net_name = self.get_net_name(self.dev_name) + try: + self.ip_addr = self.get_ip_address(net_name) + except KeyError: + raise unittest.SkipTest('Device {} has no net interface' + .format(self.dev_name)) + else: + dev_list = d.get_device_list() + for dev in dev_list: + net_name = self.get_net_name(dev.name.decode()) + try: + self.ip_addr = self.get_ip_address(net_name) + except IndexError: + continue + else: + self.dev_name = dev.name.decode() + break + if self.dev_name is None: + raise unittest.SkipTest('No devices with net interface') + super().setUp() + + @staticmethod + def get_net_name(dev): + process = subprocess.Popen(['ls', '/sys/class/infiniband/{}/device/net/' + .format(dev)], stdout=subprocess.PIPE) + out, err = process.communicate() + return out.decode().split('\n')[0] + + @staticmethod + def get_ip_address(ifname): + process = subprocess.Popen(['ip', '-j', 'addr', 'show', ifname], + stdout=subprocess.PIPE) + out, err = process.communicate() + loaded_json = json.loads(out.decode()) + interface = loaded_json[0]['addr_info'][0]['local'] + if 'fe80::' in interface: + interface = interface + '%' + ifname + return interface + + def test_rdmacm_sync_traffic(self): + ps = Process(target=passive_side, args=[self.ip_addr]) + ps.start() + ps.join(1) + active_side(self.ip_addr) + ps.join() -- 2.21.0