From: Maxim Chicherin <maximc@xxxxxxxxxxxx> Add a 'requires_odp' decorator, to be used when registering an MR with ON_DEMAND access flag. Signed-off-by: Maxim Chicherin <maximc@xxxxxxxxxxxx> --- tests/utils.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/utils.py b/tests/utils.py index 30166f41d555..20a7e8d38e54 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -5,6 +5,7 @@ Provide some useful helper function for pyverbs' tests. """ from itertools import combinations as com from string import ascii_lowercase as al +import unittest import random from pyverbs.qp import QPCap, QPInitAttrEx @@ -241,3 +242,32 @@ def wc_status_to_str(status): except KeyError: return 'Unknown WC status ({s})'.format(s=status) + +# Decorators + +def requires_odp(qp_type): + def outer(func): + def inner(instance): + odp_supported(instance.ctx, qp_type) + return func(instance) + return inner + return outer + + +def odp_supported(ctx, qp_type): + """ + Check device ODP capabilities, support only send/recv so far. + :param ctx: Device Context + :param qp_type: QP type ('rc', 'ud' or 'uc') + :return: None + """ + odp_caps = ctx.query_device_ex().odp_caps + if odp_caps.general_caps == 0: + raise unittest.SkipTest('ODP is not supported - No ODP caps') + qp_odp_caps = getattr(odp_caps, '{}_odp_caps'.format(qp_type)) + has_odp_send = qp_odp_caps & e.IBV_ODP_SUPPORT_SEND + has_odp_recv = qp_odp_caps & e.IBV_ODP_SUPPORT_RECV + if has_odp_send == 0: + raise unittest.SkipTest('ODP is not supported - ODP send not supported') + if has_odp_recv == 0: + raise unittest.SkipTest('ODP is not supported - ODP recv not supported') -- 2.21.0