Skip to content

Commit

Permalink
pyverbs: Fix randrange deprecation warning
Browse files Browse the repository at this point in the history
[ Upstream commit ff5b2ac ]

Second argument to randrange() call is not integer as such every time
rdma-core tests were run, the following deprecation warnings were
printed.

./tests/test_device.py:284: DeprecationWarning: non-integer arguments to randrange()
have been deprecated since Python 3.10 and will be removed in a subsequent version
  dm_len = random.randrange(u.MIN_DM_SIZE, self.attr_ex.max_dm_size/2,

Let's cast that argument to integer.

Fixes: 259fab3 ("tests: Avoid large allocation attempts of device memory")
Signed-off-by: Leon Romanovsky <[email protected]>
Signed-off-by: Nicolas Morey <[email protected]>
  • Loading branch information
rleon authored and nmorey committed Jul 25, 2023
1 parent f0812cb commit 5fc45a1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def test_create_dm(self):
"""
test ibv_alloc_dm()
"""
dm_len = random.randrange(u.MIN_DM_SIZE, self.attr_ex.max_dm_size/2,
dm_len = random.randrange(u.MIN_DM_SIZE, int(self.attr_ex.max_dm_size/2),
u.DM_ALIGNMENT)
dm_attrs = u.get_dm_attrs(dm_len)
with d.DM(self.ctx, dm_attrs):
Expand All @@ -291,7 +291,7 @@ def test_destroy_dm(self):
"""
test ibv_free_dm()
"""
dm_len = random.randrange(u.MIN_DM_SIZE, self.attr_ex.max_dm_size/2,
dm_len = random.randrange(u.MIN_DM_SIZE, int(self.attr_ex.max_dm_size/2),
u.DM_ALIGNMENT)
dm_attrs = u.get_dm_attrs(dm_len)
dm = d.DM(self.ctx, dm_attrs)
Expand Down Expand Up @@ -327,7 +327,7 @@ def test_destroy_dm_bad_flow(self):
"""
Test calling ibv_free_dm() twice
"""
dm_len = random.randrange(u.MIN_DM_SIZE, self.attr_ex.max_dm_size/2,
dm_len = random.randrange(u.MIN_DM_SIZE, int(self.attr_ex.max_dm_size/2),
u.DM_ALIGNMENT)
dm_attrs = u.get_dm_attrs(dm_len)
dm = d.DM(self.ctx, dm_attrs)
Expand All @@ -338,7 +338,7 @@ def test_dm_write(self):
"""
Test writing to the device memory
"""
dm_len = random.randrange(u.MIN_DM_SIZE, self.attr_ex.max_dm_size/2,
dm_len = random.randrange(u.MIN_DM_SIZE, int(self.attr_ex.max_dm_size/2),
u.DM_ALIGNMENT)
dm_attrs = u.get_dm_attrs(dm_len)
with d.DM(self.ctx, dm_attrs) as dm:
Expand All @@ -352,7 +352,7 @@ def test_dm_write_bad_flow(self):
"""
Test writing to the device memory with bad offset and length
"""
dm_len = random.randrange(u.MIN_DM_SIZE, self.attr_ex.max_dm_size/2,
dm_len = random.randrange(u.MIN_DM_SIZE, int(self.attr_ex.max_dm_size/2),
u.DM_ALIGNMENT)
dm_attrs = u.get_dm_attrs(dm_len)
with d.DM(self.ctx, dm_attrs) as dm:
Expand All @@ -373,7 +373,7 @@ def test_dm_read(self):
"""
Test reading from the device memory
"""
dm_len = random.randrange(u.MIN_DM_SIZE, self.attr_ex.max_dm_size/2,
dm_len = random.randrange(u.MIN_DM_SIZE, int(self.attr_ex.max_dm_size/2),
u.DM_ALIGNMENT)
dm_attrs = u.get_dm_attrs(dm_len)
with d.DM(self.ctx, dm_attrs) as dm:
Expand Down

0 comments on commit 5fc45a1

Please sign in to comment.