tests: Add dmabuf FD export tests for UAR and DM Add tests that verify exporting UAR and DM as a dmabuf FD Signed-off-by: Daniel Hayon <dhayon@nvidia.com> Signed-off-by: Shachar Kagan <skagan@nvidia.com>
diff --git a/tests/test_mlx5_uar.py b/tests/test_mlx5_uar.py index 44a6267..d6f3ce8 100644 --- a/tests/test_mlx5_uar.py +++ b/tests/test_mlx5_uar.py
@@ -36,3 +36,17 @@ finally: for uar in self.uar_res.uars: uar.close() + + def test_uar_export_dmabuf_fd(self): + """Test exporting a UAR as a dmabuf FD""" + try: + self.uar_res.uars.append(Mlx5UAR(self.uar_res.ctx, _MLX5DV_UAR_ALLOC_TYPE_NC)) + dmabuf_fd = self.uar_res.uars[-1].export_dmabuf_fd() + self.assertGreater(dmabuf_fd, 0, 'Expected a valid dmabuf FD greater than 0') + except PyverbsRDMAError as ex: + if ex.error_code in [errno.EPROTONOSUPPORT, errno.EOPNOTSUPP]: + raise unittest.SkipTest('UAR dmabuf export is not supported') + raise ex + finally: + for uar in self.uar_res.uars: + uar.close()
diff --git a/tests/test_mr.py b/tests/test_mr.py index fdde078..ef75f4b 100644 --- a/tests/test_mr.py +++ b/tests/test_mr.py
@@ -484,6 +484,18 @@ with self.assertRaisesRegex(PyverbsRDMAError, 'Failed to register a device MR'): DMMR(PD(self.ctx), dm_size + 4, dm_access, dm, 0) + def test_dm_export_dmabuf_fd(self): + """Test exporting a DM as a dmabuf FD""" + dm_size = 100 + try: + with d.DM(self.ctx, d.AllocDmAttr(length=dm_size)) as dm: + dmabuf_fd = dm.export_dmabuf_fd() + self.assertGreater(dmabuf_fd, 0, 'Expected a valid dmabuf FD greater than 0') + except PyverbsRDMAError as ex: + if ex.error_code in [errno.EOPNOTSUPP, errno.EPROTONOSUPPORT]: + raise unittest.SkipTest('DM dmabuf export is not supported') + raise ex + def check_dmabuf_support(gpu=0): """