def test_create_dm_bad_flow(self): """ test ibv_alloc_dm() with an illegal size and comp mask """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: attr = ctx.query_device_ex() if attr.max_dm_size == 0: return dm_len = attr.max_dm_size + 1 dm_attrs = u.get_dm_attrs(dm_len) try: dm = d.DM(ctx, dm_attrs) except PyverbsRDMAError as e: assert 'Failed to allocate device memory of size' in e.args[ 0] assert 'Max available size' in e.args[0] else: raise PyverbsError( 'Created a DM with size larger than max reported') dm_attrs.comp_mask = random.randint(1, 100) try: dm = d.DM(ctx, dm_attrs) except PyverbsRDMAError as e: assert 'Failed to allocate device memory of size' in e.args[ 0] else: raise PyverbsError('Created a DM with illegal comp mask {c}'.\ format(c=dm_attrs.comp_mask))
def test_dm_write_bad_flow(self): """ Test writing to the device memory with bad offset and length """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: attr = ctx.query_device_ex() if attr.max_dm_size == 0: return dm_len = random.randrange(u.MIN_DM_SIZE, attr.max_dm_size, u.DM_ALIGNMENT) dm_attrs = u.get_dm_attrs(dm_len) with d.DM(ctx, dm_attrs) as dm: data_length = random.randrange(4, dm_len, u.DM_ALIGNMENT) data_offset = random.randrange(0, dm_len - data_length, u.DM_ALIGNMENT) data_offset += 1 # offset needs to be a multiple of 4 data = u.get_data(data_length) try: dm.copy_to_dm(data_offset, data.encode(), data_length) except PyverbsRDMAError as e: assert 'Failed to copy to dm' in e.args[0] else: raise PyverbsError( 'Wrote to device memory with a bad offset')
def test_create_cq_ex_bad_flow(): """ Test ibv_create_cq_ex() with wrong comp_vector / number of cqes """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: attrs_ex = get_attrs_ex(ctx) max_cqe = ctx.query_device().max_cqe attrs_ex.cqe = max_cqe + random.randint(1, 100) try: CQEX(ctx, attrs_ex) except PyverbsError as e: assert 'Failed to create extended CQ' in e.args[0] assert ' Errno: 22' in e.args[0] else: raise PyverbsError( 'Created a CQEX with {c} CQEs while device\'s max CQE={dc}' .format(c=attrs_ex.cqe, dc=max_cqe)) comp_channel = random.randint(ctx.num_comp_vectors, 100) attrs_ex.comp_vector = comp_channel attrs_ex.cqe = get_num_cqes(ctx) try: CQEX(ctx, attrs_ex) except PyverbsError as e: assert 'Failed to create extended CQ' in e.args[0] assert ' Errno: 22' in e.args[0] else: raise PyverbsError( 'Created a CQEX with comp_vector={c} while device\'s num_comp_vectors={dc}' .format(c=comp_channel, dc=ctx.num_comp_vectors))
def test_open_dev(): """ Test ibv_open_device() """ lst = d.get_device_list() for dev in lst: d.Context(name=dev.name.decode())
def test_query_gid(): """ Test ibv_query_gid() """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: ctx.query_gid(port_num=1, index=0)
def test_query_device(self): """ Test ibv_query_device() """ lst = d.get_device_list() for dev in lst: ctx = d.Context(name=dev.name.decode()) ctx.query_device()
def test_dereg_mr(self): """ Test ibv_dereg_mr() """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: with PD(ctx) as pd: with MR(pd, u.get_mr_length(), u.get_access_flags()) as mr: mr.close()
def test_open_dev(): """ Test ibv_open_device() """ lst = d.get_device_list() if len(lst) == 0: raise unittest.SkipTest('No IB devices found') for dev in lst: d.Context(name=dev.name.decode())
def test_dealloc_pd(): """ Test ibv_dealloc_pd() """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: with PD(ctx) as pd: pd.close()
def test_create_comp_channel(): """ Test ibv_create_comp_channel() """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: with CompChannel(ctx): pass
def test_alloc_pd(self): """ Test ibv_alloc_pd() """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: with PD(ctx): pass
def test_destroy_cq_ex(): """ Test ibv_destroy_cq() for extended CQs """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: with CQEX(ctx, get_attrs_ex(ctx)) as cq: cq.close()
def test_create_cq_ex(): """ Test ibv_create_cq_ex() """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: with CQEX(ctx, get_attrs_ex(ctx)): pass
def test_query_device_ex(self): """ Test ibv_query_device_ex() """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: attr_ex = ctx.query_device_ex() self.verify_device_attr(attr_ex.orig_attr)
def test_destroy_comp_channel(): """ Test ibv_destroy_comp_channel() """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: cc = CompChannel(ctx) cc.close()
def test_multiple_pd_creation(): """ Test multiple creations and destructions of a PD object """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: for i in range(random.randint(1, 200)): with PD(ctx) as pd: pd.close()
def test_query_gid(): """ Test ibv_query_gid() """ lst = d.get_device_list() if len(lst) == 0: raise unittest.SkipTest('No IB devices found') for dev in lst: with d.Context(name=dev.name.decode()) as ctx: ctx.query_gid(port_num=1, index=0)
def test_dereg_mw(self): """ Test ibv_dealloc_mw() """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: with PD(ctx) as pd: with MW(pd, random.choice([e.IBV_MW_TYPE_1, e.IBV_MW_TYPE_2])) as mw: mw.close()
def test_dereg_mr_twice(self): """ Verify that explicit call to MR's close() doesn't fails """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: with PD(ctx) as pd: with MR(pd, u.get_mr_length(), u.get_access_flags()) as mr: # Pyverbs supports multiple destruction of objects, we are # not expecting an exception here. mr.close() mr.close()
def test_query_device_ex(self): """ Test ibv_query_device_ex() """ lst = d.get_device_list() if len(lst) == 0: raise unittest.SkipTest('No IB devices found') for dev in lst: with d.Context(name=dev.name.decode()) as ctx: attr_ex = ctx.query_device_ex() self.verify_device_attr(attr_ex.orig_attr)
def setUp(self): """ Opens the devices and queries them """ lst = d.get_device_list() self.devices = [] for dev in lst: c = d.Context(name=dev.name.decode()) attr = c.query_device() attr_ex = c.query_device_ex() self.devices.append((c, attr, attr_ex))
def test_query_port(self): """ Test ibv_query_port """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: num_ports = ctx.query_device().phys_port_cnt for p in range(num_ports): port_attr = ctx.query_port(p + 1) self.verify_port_attr(port_attr)
def test_buffer(self): """ Test reading buf property """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: with PD(ctx) as pd: length = u.get_mr_length() with MR(pd, length, u.get_access_flags()) as mr: buf = mr.buf
def test_write(self): """ Test writing to MR's buffer """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: with PD(ctx) as pd: mr_len = u.get_mr_length() with MR(pd, mr_len, u.get_access_flags()) as mr: write_len = min(random.randint(1, MAX_IO_LEN), mr_len) mr.write(u.get_data(write_len), write_len)
def test_destroy_pd_twice(): """ Test bad flow cases in destruction of a PD object """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: with PD(ctx) as pd: # Pyverbs supports multiple destruction of objects, we are # not expecting an exception here. pd.close() pd.close()
def test_query_port(self): """ Test ibv_query_port """ lst = d.get_device_list() if len(lst) == 0: raise unittest.SkipTest('No IB devices found') for dev in lst: with d.Context(name=dev.name.decode()) as ctx: num_ports = ctx.query_device().phys_port_cnt for p in range(num_ports): port_attr = ctx.query_port(p + 1) self.verify_port_attr(port_attr)
def get_device_list(self): lst = d.get_device_list() if len(lst) == 0: raise unittest.SkipTest('No IB device found') dev_name = self.config['dev'] if dev_name: for dev in lst: if dev.name.decode() == dev_name: lst = [dev] break if len(lst) == 0: raise PyverbsRDMAError(f'No IB device with name {dev_name} found') return lst
def setUp(self): """ Opens the devices and queries them """ lst = d.get_device_list() self.devices = [] if len(lst) == 0: raise unittest.SkipTest('No IB devices found') for dev in lst: c = d.Context(name=dev.name.decode()) attr = c.query_device() attr_ex = c.query_device_ex() self.devices.append((c, attr, attr_ex))
def test_reg_mw_wrong_type(self): """ Test ibv_alloc_mw() """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: with PD(ctx) as pd: try: mw_type = random.randint(3, 100) mw = MW(pd, mw_type) except PyverbsRDMAError as e: pass else: raise PyverbsError('Created a MW with type {t}'.\ format(t=mw_type))
def test_destroy_cq(): """ Test ibv_destroy_cq() """ lst = d.get_device_list() for dev in lst: with d.Context(name=dev.name.decode()) as ctx: cqes = get_num_cqes(ctx) comp_vector = random.randint(0, ctx.num_comp_vectors - 1) if random.choice([True, False]): with CompChannel(ctx) as cc: cq = CQ(ctx, cqes, None, cc, comp_vector) else: cq = CQ(ctx, cqes, None, None, comp_vector) cq.close()