def test_dmabuf_dereg_mr(self): """ Test ibv_dereg_mr() with DmaBufMR """ check_dmabuf_support(self.gpu) with PD(self.ctx) as pd: check_dmabuf_mr_support(pd, self.gpu) flags = u.get_dmabuf_access_flags(self.ctx) for f in flags: len = u.get_mr_length() for off in [0, len//2]: with DmaBufMR(pd, len, f, offset=off, unit=self.gpu, gtt=self.gtt) as mr: mr.close()
def test_dmabuf_rkey(self): """ Test reading rkey property """ check_dmabuf_support(self.unit) for ctx, attr, attr_ex in self.devices: with PD(ctx) as pd: check_dmabuf_mr_support(pd, self.unit) length = u.get_mr_length() flags = u.get_dmabuf_access_flags(ctx) for f in flags: with DmaBufMR(pd, length, f, unit=self.unit, gtt=self.gtt) as mr: mr.rkey
def test_dmabuf_reg_mr(self): """ Test ibv_reg_dmabuf_mr() """ check_dmabuf_support(self.gpu) for ctx, attr, attr_ex in self.devices: with PD(ctx) as pd: check_dmabuf_mr_support(pd, self.gpu) 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, gpu=self.gpu, gtt=self.gtt) as mr: pass
def test_dmabuf_write(self): """ Test writing to DmaBufMR's buffer """ check_dmabuf_support(self.gpu) with PD(self.ctx) as pd: check_dmabuf_mr_support(pd, self.gpu) for i in range(10): mr_len = u.get_mr_length() flags = u.get_dmabuf_access_flags(self.ctx) for f in flags: for mr_off in [0, mr_len//2]: with DmaBufMR(pd, mr_len, f, offset=mr_off, unit=self.gpu, gtt=self.gtt) as mr: write_len = min(random.randint(1, MAX_IO_LEN), mr_len) mr.write('a' * write_len, write_len)
def test_dmabuf_dereg_mr_twice(self): """ Verify that explicit call to DmaBufMR's close() doesn't fail """ check_dmabuf_support(self.gpu) with PD(self.ctx) as pd: check_dmabuf_mr_support(pd, self.gpu) flags = u.get_dmabuf_access_flags(self.ctx) for f in flags: len = u.get_mr_length() for off in [0, len//2]: with DmaBufMR(pd, len, f, offset=off, unit=self.gpu, gtt=self.gtt) 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(self.gpu) with PD(self.ctx) as pd: check_dmabuf_mr_support(pd, self.gpu) 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: mr_flags += i.value try: DmaBufMR(pd, u.get_mr_length(), mr_flags, unit=self.gpu, gtt=self.gtt) except PyverbsRDMAError as err: assert 'Failed to register a dma-buf MR' in err.args[0] else: raise PyverbsRDMAError('Registered a dma-buf MR with illegal falgs')
def test_dmabuf_read(self): """ Test reading from DmaBufMR's buffer """ check_dmabuf_support(self.gpu) with PD(self.ctx) as pd: check_dmabuf_mr_support(pd, self.gpu) for i in range(10): mr_len = u.get_mr_length() flags = u.get_dmabuf_access_flags(self.ctx) for f in flags: for mr_off in [0, mr_len//2]: with DmaBufMR(pd, mr_len, f, offset=mr_off, unit=self.gpu, gtt=self.gtt) as mr: write_len = min(random.randint(1, MAX_IO_LEN), mr_len) write_str = 'a' * write_len mr.write(write_str, write_len) read_len = random.randint(1, write_len) offset = random.randint(0, write_len-read_len) read_str = mr.read(read_len, offset).decode() assert read_str in write_str