Skip to content

Commit

Permalink
tests: Add LAG TX affinity test
Browse files Browse the repository at this point in the history
This test creates RC and RAW QP and tries to query and modify the LAG TX
affinity.

Signed-off-by: Aharon Landau <aharonl@mellanox.com>
Reviewed-by: Edward Srouji <edwards@mellanox.com>
  • Loading branch information
Aharon Landau authored and yishaih committed Jun 2, 2020
1 parent 17a4af2 commit c79e6c4
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 20 deletions.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Expand Up @@ -13,6 +13,7 @@ rdma_python_test(tests
test_cqex.py
test_device.py
test_efadv.py
test_mlx5_lag_affinity.py
test_mlx5_pp.py
test_mlx5_uar.py
test_mlx5_var.py
Expand Down
48 changes: 48 additions & 0 deletions tests/test_mlx5_lag_affinity.py
@@ -0,0 +1,48 @@
import unittest
import errno


from pyverbs.qp import QP, QPAttr, QPInitAttr, QPCap
from pyverbs.pyverbs_error import PyverbsRDMAError
from tests.base import BaseResources, RDMATestCase
from pyverbs.providers.mlx5.mlx5dv import Mlx5QP
from tests.utils import requires_root_on_eth
import pyverbs.enums as e
from pyverbs.cq import CQ


class LagRawQP(BaseResources):
def __init__(self, dev_name):
super().__init__(dev_name, None, None)
self.cq = self.create_cq()
self.qp = self.create_qp()

def create_cq(self):
return CQ(self.ctx, 100)

@requires_root_on_eth()
def create_qp(self):
qia = QPInitAttr(e.IBV_QPT_RAW_PACKET, rcq=self.cq, scq=self.cq,
cap=QPCap())
qp = QP(self.pd, qia)
qp.to_init(QPAttr())
return qp


class LagPortTestCase(RDMATestCase):
def modify_lag(self, resources):
try:
port_num, active_port_num = Mlx5QP.query_lag_port(resources.qp)
# if port_num is 1 - modify to 2, else modify to 1
new_port_num = (2 - port_num) + 1
Mlx5QP.modify_lag_port(resources.qp, new_port_num)
port_num, active_port_num = Mlx5QP.query_lag_port(resources.qp)
self.assertEqual(port_num, new_port_num, 'Port num is not as expected')
except PyverbsRDMAError as ex:
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest('Set LAG affinity is not supported on this device')
raise ex

def test_raw_modify_lag_port(self):
qp = LagRawQP(self.dev_name)
self.modify_lag(qp)
26 changes: 6 additions & 20 deletions tests/test_qp.py
Expand Up @@ -53,7 +53,7 @@ def test_create_qp_no_attr(self):
qia.qp_type = e.IBV_QPT_UD
with QP(pd, qia) as qp:
assert qp.qp_state == e.IBV_QPS_RESET, 'UD QP should have been in RESET'
if is_eth(ctx, i) and is_root():
if u.is_eth(ctx, i) and u.is_root():
qia.qp_type = e.IBV_QPT_RAW_PACKET
with QP(pd, qia) as qp:
assert qp.qp_state == e.IBV_QPS_RESET, 'Raw Packet QP should have been in RESET'
Expand Down Expand Up @@ -85,12 +85,12 @@ def test_create_qp_with_attr(self):
with CQ(ctx, 100, None, None, 0) as cq:
for i in range(1, attr.phys_port_cnt + 1):
qpts = [e.IBV_QPT_UD, e.IBV_QPT_RAW_PACKET] \
if is_eth(ctx, i) else [e.IBV_QPT_UD]
if u.is_eth(ctx, i) else [e.IBV_QPT_UD]
qia = get_qp_init_attr(cq, attr)
qia.qp_type = e.IBV_QPT_UD
with QP(pd, qia, QPAttr()) as qp:
assert qp.qp_state == e.IBV_QPS_RTS, 'UD QP should have been in RTS'
if is_eth(ctx, i) and is_root():
if u.is_eth(ctx, i) and u.is_root():
qia.qp_type = e.IBV_QPT_RAW_PACKET
with QP(pd, qia, QPAttr()) as qp:
assert qp.qp_state == e.IBV_QPS_RTS, 'Raw Packet QP should have been in RTS'
Expand Down Expand Up @@ -139,7 +139,7 @@ def test_create_qp_ex_no_attr(self):
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest('Create QP with extended attrs is not supported')
raise ex
if is_eth(ctx, i) and is_root():
if u.is_eth(ctx, i) and u.is_root():
qia = get_qp_init_attr_ex(cq, pd, attr, attr_ex,
e.IBV_QPT_RAW_PACKET)
try:
Expand Down Expand Up @@ -196,7 +196,7 @@ def test_create_qp_ex_with_attr(self):
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest('Create QP with extended attrs is not supported')
raise ex
if is_eth(ctx, i) and is_root():
if u.is_eth(ctx, i) and u.is_root():
qia = get_qp_init_attr_ex(cq, pd, attr, attr_ex,
e.IBV_QPT_RAW_PACKET)
try:
Expand Down Expand Up @@ -298,7 +298,7 @@ def get_qp_types(ctx, port_num):
:return: An array of QP types that can be created on this port
"""
qpts = [e.IBV_QPT_RC, e.IBV_QPT_UC, e.IBV_QPT_UD]
if is_eth(ctx, port_num) and is_root():
if u.is_eth(ctx, port_num) and u.is_root():
qpts.append(e.IBV_QPT_RAW_PACKET)
return qpts

Expand Down Expand Up @@ -341,17 +341,3 @@ def get_qp_init_attr_ex(cq, pd, attr, attr_ex, qpt):
qia.recv_cq = cq
qia.pd = pd # Only XRCD can be created without a PD
return qia


def is_eth(ctx, port_num):
"""
Querires the device's context's <port_num> port for its link layer.
:param ctx: The Context to query
:param port_num: Which Context's port to query
:return: True if the port's link layer is Ethernet, else False
"""
return ctx.query_port(port_num).link_layer == e.IBV_LINK_LAYER_ETHERNET


def is_root():
return os.geteuid() == 0
24 changes: 24 additions & 0 deletions tests/utils.py
Expand Up @@ -633,6 +633,16 @@ def inner(instance):
return outer


def requires_root_on_eth(port_num=1):
def outer(func):
def inner(instance):
if not (is_eth(instance.ctx, port_num) and is_root()):
raise unittest.SkipTest('Must be run by root on Ethernet link layer')
return func(instance)
return inner
return outer


def odp_supported(ctx, qp_type):
"""
Check device ODP capabilities, support only send/recv so far.
Expand Down Expand Up @@ -686,3 +696,17 @@ def prefetch_mrs(agr_obj, sg_list, advise=e._IBV_ADVISE_MR_ADVICE_PREFETCH_WRITE
:return: None
"""
agr_obj.pd.advise_mr(advise, flags, sg_list)


def is_eth(ctx, port_num):
"""
Querires the device's context's <port_num> port for its link layer.
:param ctx: The Context to query
:param port_num: Which Context's port to query
:return: True if the port's link layer is Ethernet, else False
"""
return ctx.query_port(port_num).link_layer == e.IBV_LINK_LAYER_ETHERNET


def is_root():
return os.geteuid() == 0

0 comments on commit c79e6c4

Please sign in to comment.