| 1 |
# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) |
| 2 |
# Copyright (c) 2019 Mellanox Technologies, Inc. All rights reserved. See COPYING file |
| 3 |
|
| 4 |
""" |
| 5 |
Test module for Mlx5 UAR allocation. |
| 6 |
""" |
| 7 |
import unittest |
| 8 |
import errno |
| 9 |
|
| 10 |
from pyverbs.pyverbs_error import PyverbsRDMAError |
| 11 |
from pyverbs.providers.mlx5.mlx5dv import Mlx5UAR |
| 12 |
from pyverbs.providers.mlx5.mlx5_enums import _MLX5DV_UAR_ALLOC_TYPE_BF, _MLX5DV_UAR_ALLOC_TYPE_NC |
| 13 |
from tests.mlx5_base import Mlx5RDMATestCase |
| 14 |
from tests.base import BaseResources |
| 15 |
|
| 16 |
|
| 17 |
class Mlx5UarRes(BaseResources): |
| 18 |
def __init__(self, dev_name, ib_port=None, gid_index=None): |
| 19 |
super().__init__(dev_name, ib_port, gid_index) |
| 20 |
self.uars = [] |
| 21 |
|
| 22 |
|
| 23 |
class Mlx5UarTestCase(Mlx5RDMATestCase): |
| 24 |
def setUp(self): |
| 25 |
super().setUp() |
| 26 |
self.uar_res = Mlx5UarRes(self.dev_name) |
| 27 |
|
| 28 |
def test_alloc_uar(self): |
| 29 |
try: |
| 30 |
for f in [_MLX5DV_UAR_ALLOC_TYPE_BF, _MLX5DV_UAR_ALLOC_TYPE_NC]: |
| 31 |
self.uar_res.uars.append(Mlx5UAR(self.uar_res.ctx, f)) |
| 32 |
except PyverbsRDMAError as ex: |
| 33 |
if ex.error_code == errno.EOPNOTSUPP or ex.error_code == errno.EPROTONOSUPPORT: |
| 34 |
raise unittest.SkipTest(f'UAR allocation (with flag={f}) is not supported') |
| 35 |
raise ex |
| 36 |
finally: |
| 37 |
for uar in self.uar_res.uars: |
| 38 |
uar.close() |
| 39 |
|
| 40 |
def test_uar_export_dmabuf_fd(self): |
| 41 |
"""Test exporting a UAR as a dmabuf FD""" |
| 42 |
try: |
| 43 |
self.uar_res.uars.append(Mlx5UAR(self.uar_res.ctx, _MLX5DV_UAR_ALLOC_TYPE_NC)) |
| 44 |
dmabuf_fd = self.uar_res.uars[-1].export_dmabuf_fd() |
| 45 |
self.assertGreater(dmabuf_fd, 0, 'Expected a valid dmabuf FD greater than 0') |
| 46 |
except PyverbsRDMAError as ex: |
| 47 |
if ex.error_code in [errno.EPROTONOSUPPORT, errno.EOPNOTSUPP]: |
| 48 |
raise unittest.SkipTest('UAR dmabuf export is not supported') |
| 49 |
raise ex |
| 50 |
finally: |
| 51 |
for uar in self.uar_res.uars: |
| 52 |
uar.close() |