Debian Codegraph @

tests/test_mlx5_var.py

raw
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 VAR allocation.
6 """
7
8 from pyverbs.pyverbs_error import PyverbsRDMAError
9 from pyverbs.providers.mlx5.mlx5dv import Mlx5VAR
10 from tests.mlx5_base import Mlx5RDMATestCase
11 from tests.base import BaseResources
12 import unittest
13 import errno
14 import mmap
15
16
17 class Mlx5VarRes(BaseResources):
18 def __init__(self, dev_name, ib_port=None, gid_index=None):
19 super().__init__(dev_name, ib_port, gid_index)
20 try:
21 self.var = Mlx5VAR(self.ctx)
22 except PyverbsRDMAError as ex:
23 if ex.error_code == errno.EOPNOTSUPP or ex.error_code == errno.EPROTONOSUPPORT:
24 raise unittest.SkipTest('VAR allocation is not supported')
25
26
27 class Mlx5VarTestCase(Mlx5RDMATestCase):
28 def setUp(self):
29 super().setUp()
30 self.var_res = Mlx5VarRes(self.dev_name)
31
32 def test_var_map_unmap(self):
33 var_map = mmap.mmap(fileno=self.var_res.ctx.cmd_fd,
34 length=self.var_res.var.length,
35 offset=self.var_res.var.mmap_off)
36 # There is no munmap method in mmap Python module, but by closing the
37 # mmap instance the memory is unmapped.
38 var_map.close()
39 self.var_res.var.close()