Merge pull request #311 from katlapinka/unaligned-tests

Add new negative io tests and raising error when failed to create io
This commit is contained in:
Michal Rakowski 2019-10-02 20:50:40 +02:00 committed by GitHub
commit a61664ddd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -100,6 +100,10 @@ class Core:
io = OcfLib.getInstance().ocf_core_new_io_wrapper(
self.handle, queue.handle, addr, length, direction, io_class, flags)
if io is None:
raise Exception("Failed to create io!")
return Io.from_pointer(io)
def new_core_io(

View File

@ -118,6 +118,36 @@ def test_neg_read_offset_outside_of_device(pyocf_ctx, c_int_sector_randomize):
assert completion.results["err"] != 0
@pytest.mark.security
def test_neg_offset_unaligned(pyocf_ctx, c_int_randomize):
"""
Check that write operations are blocked when
IO offset is not aligned
"""
core = prepare_cache_and_core(Size.from_MiB(2))
data = Data(int(Size.from_KiB(1)))
if c_int_randomize % 512 != 0:
with pytest.raises(Exception, match="Failed to create io!"):
core.new_io(core.cache.get_default_queue(), c_int_randomize, data.size,
IoDir.WRITE, 0, 0)
@pytest.mark.security
def test_neg_size_unaligned(pyocf_ctx, c_uint16_randomize):
"""
Check that write operations are blocked when
IO size is not aligned
"""
core = prepare_cache_and_core(Size.from_MiB(2))
data = Data(int(Size.from_B(c_uint16_randomize)))
if c_uint16_randomize % 512 != 0:
with pytest.raises(Exception, match="Failed to create io!"):
core.new_io(core.cache.get_default_queue(), 0, data.size,
IoDir.WRITE, 0, 0)
@pytest.mark.security
def test_neg_io_class(pyocf_ctx, c_int_randomize):
"""