Re: [PATCH rdma-core v3 5/6] tests: Add tests for dma-buf based memory regions
On Mon, Nov 30, 2020 at 05:35:06PM +, Xiong, Jianxin wrote: > > -Original Message- > > From: Daniel Vetter > > Sent: Monday, November 30, 2020 7:00 AM > > To: Xiong, Jianxin > > Cc: linux-r...@vger.kernel.org; dri-devel@lists.freedesktop.org; Leon > > Romanovsky ; Jason Gunthorpe ; > > Doug Ledford ; Vetter, Daniel > > ; Christian Koenig > > Subject: Re: [PATCH rdma-core v3 5/6] tests: Add tests for dma-buf based > > memory regions > > > > On Fri, Nov 27, 2020 at 12:55:42PM -0800, Jianxin Xiong wrote: > > > Define a set of unit tests similar to regular MR tests and a set of > > > tests for send/recv and rdma traffic using dma-buf MRs. Add a utility > > > function to generate access flags for dma-buf based MRs because the > > > set of supported flags is smaller. > > > > > > Signed-off-by: Jianxin Xiong > > > --- > > > tests/test_mr.py | 239 > > > ++- > > > tests/utils.py | 26 ++ > > > 2 files changed, 264 insertions(+), 1 deletion(-) > > > > > > diff --git a/tests/test_mr.py b/tests/test_mr.py index > > > adc649c..52cf20a 100644 > > > --- a/tests/test_mr.py > > > +++ b/tests/test_mr.py > > > @@ -1,5 +1,6 @@ > > > # SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) # Copyright (c) > > > 2019 Mellanox Technologies, Inc. All rights reserved. See COPYING file > > > +# Copyright (c) 2020 Intel Corporation. All rights reserved. See > > > +COPYING file > > > """ > > > Test module for pyverbs' mr module. > > > """ > > > @@ -9,9 +10,10 @@ import errno > > > > > > from tests.base import PyverbsAPITestCase, RCResources, RDMATestCase > > > from pyverbs.pyverbs_error import PyverbsRDMAError, PyverbsError -from > > > pyverbs.mr import MR, MW, DMMR, MWBindInfo, MWBind > > > +from pyverbs.mr import MR, MW, DMMR, DmaBufMR, MWBindInfo, MWBind > > > from pyverbs.qp import QPCap, QPInitAttr, QPAttr, QP from pyverbs.wr > > > import SendWR > > > +from pyverbs.dmabuf import DmaBuf > > > import pyverbs.device as d > > > from pyverbs.pd import PD > > > import pyverbs.enums as e > > > @@ -366,3 +368,238 @@ class DMMRTest(PyverbsAPITestCase): > > > dm_mr = DMMR(pd, dm_mr_len, > > > e.IBV_ACCESS_ZERO_BASED, > > > dm=dm, offset=dm_mr_offset) > > > dm_mr.close() > > > + > > > + > > > +def check_dmabuf_support(): > > > +""" > > > +Check if dma-buf allocation is supported by the system. > > > +Skip the test on failure. > > > +""" > > > +try: > > > +DmaBuf(1) > > > > Hardcoding gpu unit 1 here (and in other places) is probably not quite what > > we want. Not sure what you want to do in the test framework > > here instead. > > '1' here is the buffer size. Unit is the default value 0. We could > probably add a command line argument to the test to set the preferred > gpu unit. Oh I mixed up my python, not really fluent in that :-) Some means to set the preferred unit would still be good I think. -Daniel > > > > > > +except PyverbsRDMAError as ex: > > > +if ex.error_code == errno.ENOENT: > > > +raise unittest.SkipTest('Device /dev/dri/renderD* is not > > > present') > > > +if ex.error_code == errno.EACCES: > > > +raise unittest.SkipTest('Lack of permission to access > > > + /dev/dri/renderD*') > > > + > > > + > > > +def check_dmabuf_mr_support(pd): > > > +""" > > > +Check if dma-buf MR registration is supported by the driver. > > > +Skip the test on failure > > > +""" > > > +try: > > > +DmaBufMR(pd, 1, 0) > > > +except PyverbsRDMAError as ex: > > > +if ex.error_code == errno.EOPNOTSUPP: > > > +raise unittest.SkipTest('Reg dma-buf MR is not > > > +supported') > > > + > > > + > > > +class DmaBufMRTest(PyverbsAPITestCase): > > > +""" > > > +Test various functionalities of the DmaBufMR class. > > > +""" > > > +def test_dmabuf_reg_mr(self): > > > +""" > > > +
RE: [PATCH rdma-core v3 5/6] tests: Add tests for dma-buf based memory regions
> -Original Message- > From: Daniel Vetter > Sent: Monday, November 30, 2020 7:00 AM > To: Xiong, Jianxin > Cc: linux-r...@vger.kernel.org; dri-devel@lists.freedesktop.org; Leon > Romanovsky ; Jason Gunthorpe ; > Doug Ledford ; Vetter, Daniel ; > Christian Koenig > Subject: Re: [PATCH rdma-core v3 5/6] tests: Add tests for dma-buf based > memory regions > > On Fri, Nov 27, 2020 at 12:55:42PM -0800, Jianxin Xiong wrote: > > Define a set of unit tests similar to regular MR tests and a set of > > tests for send/recv and rdma traffic using dma-buf MRs. Add a utility > > function to generate access flags for dma-buf based MRs because the > > set of supported flags is smaller. > > > > Signed-off-by: Jianxin Xiong > > --- > > tests/test_mr.py | 239 > > ++- > > tests/utils.py | 26 ++ > > 2 files changed, 264 insertions(+), 1 deletion(-) > > > > diff --git a/tests/test_mr.py b/tests/test_mr.py index > > adc649c..52cf20a 100644 > > --- a/tests/test_mr.py > > +++ b/tests/test_mr.py > > @@ -1,5 +1,6 @@ > > # SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) # Copyright (c) > > 2019 Mellanox Technologies, Inc. All rights reserved. See COPYING file > > +# Copyright (c) 2020 Intel Corporation. All rights reserved. See > > +COPYING file > > """ > > Test module for pyverbs' mr module. > > """ > > @@ -9,9 +10,10 @@ import errno > > > > from tests.base import PyverbsAPITestCase, RCResources, RDMATestCase > > from pyverbs.pyverbs_error import PyverbsRDMAError, PyverbsError -from > > pyverbs.mr import MR, MW, DMMR, MWBindInfo, MWBind > > +from pyverbs.mr import MR, MW, DMMR, DmaBufMR, MWBindInfo, MWBind > > from pyverbs.qp import QPCap, QPInitAttr, QPAttr, QP from pyverbs.wr > > import SendWR > > +from pyverbs.dmabuf import DmaBuf > > import pyverbs.device as d > > from pyverbs.pd import PD > > import pyverbs.enums as e > > @@ -366,3 +368,238 @@ class DMMRTest(PyverbsAPITestCase): > > dm_mr = DMMR(pd, dm_mr_len, > > e.IBV_ACCESS_ZERO_BASED, > > dm=dm, offset=dm_mr_offset) > > dm_mr.close() > > + > > + > > +def check_dmabuf_support(): > > +""" > > +Check if dma-buf allocation is supported by the system. > > +Skip the test on failure. > > +""" > > +try: > > +DmaBuf(1) > > Hardcoding gpu unit 1 here (and in other places) is probably not quite what > we want. Not sure what you want to do in the test framework > here instead. '1' here is the buffer size. Unit is the default value 0. We could probably add a command line argument to the test to set the preferred gpu unit. > > > +except PyverbsRDMAError as ex: > > +if ex.error_code == errno.ENOENT: > > +raise unittest.SkipTest('Device /dev/dri/renderD* is not > > present') > > +if ex.error_code == errno.EACCES: > > +raise unittest.SkipTest('Lack of permission to access > > + /dev/dri/renderD*') > > + > > + > > +def check_dmabuf_mr_support(pd): > > +""" > > +Check if dma-buf MR registration is supported by the driver. > > +Skip the test on failure > > +""" > > +try: > > +DmaBufMR(pd, 1, 0) > > +except PyverbsRDMAError as ex: > > +if ex.error_code == errno.EOPNOTSUPP: > > +raise unittest.SkipTest('Reg dma-buf MR is not > > +supported') > > + > > + > > +class DmaBufMRTest(PyverbsAPITestCase): > > +""" > > +Test various functionalities of the DmaBufMR class. > > +""" > > +def test_dmabuf_reg_mr(self): > > +""" > > +Test ibv_reg_dmabuf_mr() > > +""" > > +check_dmabuf_support() > > +for ctx, attr, attr_ex in self.devices: > > +with PD(ctx) as pd: > > +check_dmabuf_mr_support(pd) > > +flags = u.get_dmabuf_access_flags(ctx) > > +for f in flags: > > +len = u.get_mr_length() > > +for off in [0, len//2]: > > +with DmaBufMR(pd, len, f, offset=off) as mr: > > +pass > > + > > +def test_dmabuf_dereg_mr(self): > > +""&q
Re: [PATCH rdma-core v3 5/6] tests: Add tests for dma-buf based memory regions
On Fri, Nov 27, 2020 at 12:55:42PM -0800, Jianxin Xiong wrote: > Define a set of unit tests similar to regular MR tests and a set of > tests for send/recv and rdma traffic using dma-buf MRs. Add a utility > function to generate access flags for dma-buf based MRs because the > set of supported flags is smaller. > > Signed-off-by: Jianxin Xiong > --- > tests/test_mr.py | 239 > ++- > tests/utils.py | 26 ++ > 2 files changed, 264 insertions(+), 1 deletion(-) > > diff --git a/tests/test_mr.py b/tests/test_mr.py > index adc649c..52cf20a 100644 > --- a/tests/test_mr.py > +++ b/tests/test_mr.py > @@ -1,5 +1,6 @@ > # SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) > # Copyright (c) 2019 Mellanox Technologies, Inc. All rights reserved. See > COPYING file > +# Copyright (c) 2020 Intel Corporation. All rights reserved. See COPYING file > """ > Test module for pyverbs' mr module. > """ > @@ -9,9 +10,10 @@ import errno > > from tests.base import PyverbsAPITestCase, RCResources, RDMATestCase > from pyverbs.pyverbs_error import PyverbsRDMAError, PyverbsError > -from pyverbs.mr import MR, MW, DMMR, MWBindInfo, MWBind > +from pyverbs.mr import MR, MW, DMMR, DmaBufMR, MWBindInfo, MWBind > from pyverbs.qp import QPCap, QPInitAttr, QPAttr, QP > from pyverbs.wr import SendWR > +from pyverbs.dmabuf import DmaBuf > import pyverbs.device as d > from pyverbs.pd import PD > import pyverbs.enums as e > @@ -366,3 +368,238 @@ class DMMRTest(PyverbsAPITestCase): > dm_mr = DMMR(pd, dm_mr_len, e.IBV_ACCESS_ZERO_BASED, > dm=dm, offset=dm_mr_offset) > dm_mr.close() > + > + > +def check_dmabuf_support(): > +""" > +Check if dma-buf allocation is supported by the system. > +Skip the test on failure. > +""" > +try: > +DmaBuf(1) Hardcoding gpu unit 1 here (and in other places) is probably not quite what we want. Not sure what you want to do in the test framework here instead. -Daniel > +except PyverbsRDMAError as ex: > +if ex.error_code == errno.ENOENT: > +raise unittest.SkipTest('Device /dev/dri/renderD* is not > present') > +if ex.error_code == errno.EACCES: > +raise unittest.SkipTest('Lack of permission to access > /dev/dri/renderD*') > + > + > +def check_dmabuf_mr_support(pd): > +""" > +Check if dma-buf MR registration is supported by the driver. > +Skip the test on failure > +""" > +try: > +DmaBufMR(pd, 1, 0) > +except PyverbsRDMAError as ex: > +if ex.error_code == errno.EOPNOTSUPP: > +raise unittest.SkipTest('Reg dma-buf MR is not supported') > + > + > +class DmaBufMRTest(PyverbsAPITestCase): > +""" > +Test various functionalities of the DmaBufMR class. > +""" > +def test_dmabuf_reg_mr(self): > +""" > +Test ibv_reg_dmabuf_mr() > +""" > +check_dmabuf_support() > +for ctx, attr, attr_ex in self.devices: > +with PD(ctx) as pd: > +check_dmabuf_mr_support(pd) > +flags = u.get_dmabuf_access_flags(ctx) > +for f in flags: > +len = u.get_mr_length() > +for off in [0, len//2]: > +with DmaBufMR(pd, len, f, offset=off) as mr: > +pass > + > +def test_dmabuf_dereg_mr(self): > +""" > +Test ibv_dereg_mr() with DmaBufMR > +""" > +check_dmabuf_support() > +for ctx, attr, attr_ex in self.devices: > +with PD(ctx) as pd: > +check_dmabuf_mr_support(pd) > +flags = u.get_dmabuf_access_flags(ctx) > +for f in flags: > +len = u.get_mr_length() > +for off in [0, len//2]: > +with DmaBufMR(pd, len, f, offset=off) as mr: > +mr.close() > + > +def test_dmabuf_dereg_mr_twice(self): > +""" > +Verify that explicit call to DmaBufMR's close() doesn't fail > +""" > +check_dmabuf_support() > +for ctx, attr, attr_ex in self.devices: > +with PD(ctx) as pd: > +check_dmabuf_mr_support(pd) > +flags = u.get_dmabuf_access_flags(ctx) > +for f in flags: > +len = u.get_mr_length() > +for off in [0, len//2]: > +with DmaBufMR(pd, len, f, offset=off) as mr: > +# Pyverbs supports multiple destruction of > objects, > +# we are not expecting an exception here. > +mr.close() > +mr.close() > + > +def test_dmabuf_reg_mr_bad_flags(self): > +""" > +Verify that illegal flags combination fails as expected > +
[PATCH rdma-core v3 5/6] tests: Add tests for dma-buf based memory regions
Define a set of unit tests similar to regular MR tests and a set of tests for send/recv and rdma traffic using dma-buf MRs. Add a utility function to generate access flags for dma-buf based MRs because the set of supported flags is smaller. Signed-off-by: Jianxin Xiong --- tests/test_mr.py | 239 ++- tests/utils.py | 26 ++ 2 files changed, 264 insertions(+), 1 deletion(-) diff --git a/tests/test_mr.py b/tests/test_mr.py index adc649c..52cf20a 100644 --- a/tests/test_mr.py +++ b/tests/test_mr.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) # Copyright (c) 2019 Mellanox Technologies, Inc. All rights reserved. See COPYING file +# Copyright (c) 2020 Intel Corporation. All rights reserved. See COPYING file """ Test module for pyverbs' mr module. """ @@ -9,9 +10,10 @@ import errno from tests.base import PyverbsAPITestCase, RCResources, RDMATestCase from pyverbs.pyverbs_error import PyverbsRDMAError, PyverbsError -from pyverbs.mr import MR, MW, DMMR, MWBindInfo, MWBind +from pyverbs.mr import MR, MW, DMMR, DmaBufMR, MWBindInfo, MWBind from pyverbs.qp import QPCap, QPInitAttr, QPAttr, QP from pyverbs.wr import SendWR +from pyverbs.dmabuf import DmaBuf import pyverbs.device as d from pyverbs.pd import PD import pyverbs.enums as e @@ -366,3 +368,238 @@ class DMMRTest(PyverbsAPITestCase): dm_mr = DMMR(pd, dm_mr_len, e.IBV_ACCESS_ZERO_BASED, dm=dm, offset=dm_mr_offset) dm_mr.close() + + +def check_dmabuf_support(): +""" +Check if dma-buf allocation is supported by the system. +Skip the test on failure. +""" +try: +DmaBuf(1) +except PyverbsRDMAError as ex: +if ex.error_code == errno.ENOENT: +raise unittest.SkipTest('Device /dev/dri/renderD* is not present') +if ex.error_code == errno.EACCES: +raise unittest.SkipTest('Lack of permission to access /dev/dri/renderD*') + + +def check_dmabuf_mr_support(pd): +""" +Check if dma-buf MR registration is supported by the driver. +Skip the test on failure +""" +try: +DmaBufMR(pd, 1, 0) +except PyverbsRDMAError as ex: +if ex.error_code == errno.EOPNOTSUPP: +raise unittest.SkipTest('Reg dma-buf MR is not supported') + + +class DmaBufMRTest(PyverbsAPITestCase): +""" +Test various functionalities of the DmaBufMR class. +""" +def test_dmabuf_reg_mr(self): +""" +Test ibv_reg_dmabuf_mr() +""" +check_dmabuf_support() +for ctx, attr, attr_ex in self.devices: +with PD(ctx) as pd: +check_dmabuf_mr_support(pd) +flags = u.get_dmabuf_access_flags(ctx) +for f in flags: +len = u.get_mr_length() +for off in [0, len//2]: +with DmaBufMR(pd, len, f, offset=off) as mr: +pass + +def test_dmabuf_dereg_mr(self): +""" +Test ibv_dereg_mr() with DmaBufMR +""" +check_dmabuf_support() +for ctx, attr, attr_ex in self.devices: +with PD(ctx) as pd: +check_dmabuf_mr_support(pd) +flags = u.get_dmabuf_access_flags(ctx) +for f in flags: +len = u.get_mr_length() +for off in [0, len//2]: +with DmaBufMR(pd, len, f, offset=off) as mr: +mr.close() + +def test_dmabuf_dereg_mr_twice(self): +""" +Verify that explicit call to DmaBufMR's close() doesn't fail +""" +check_dmabuf_support() +for ctx, attr, attr_ex in self.devices: +with PD(ctx) as pd: +check_dmabuf_mr_support(pd) +flags = u.get_dmabuf_access_flags(ctx) +for f in flags: +len = u.get_mr_length() +for off in [0, len//2]: +with DmaBufMR(pd, len, f, offset=off) as mr: +# Pyverbs supports multiple destruction of objects, +# we are not expecting an exception here. +mr.close() +mr.close() + +def test_dmabuf_reg_mr_bad_flags(self): +""" +Verify that illegal flags combination fails as expected +""" +check_dmabuf_support() +for ctx, attr, attr_ex in self.devices: +with PD(ctx) as pd: +check_dmabuf_mr_support(pd) +for i in range(5): +flags = random.sample([e.IBV_ACCESS_REMOTE_WRITE, + e.IBV_ACCESS_REMOTE_ATOMIC], + random.randint(1, 2)) +mr_flags = 0 +for i in flags: