From 219ccf360c95b1ea3438140ca4412ead95e8e6a9 Mon Sep 17 00:00:00 2001 From: Katarzyna Lapinska Date: Wed, 2 Oct 2019 20:35:25 +0200 Subject: [PATCH] Add new negative io tests and raising error when failed to create io Signed-off-by: Katarzyna Lapinska --- tests/functional/pyocf/types/core.py | 4 +++ .../tests/security/test_negative_io.py | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/tests/functional/pyocf/types/core.py b/tests/functional/pyocf/types/core.py index 532a520..0003c0d 100644 --- a/tests/functional/pyocf/types/core.py +++ b/tests/functional/pyocf/types/core.py @@ -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( diff --git a/tests/functional/tests/security/test_negative_io.py b/tests/functional/tests/security/test_negative_io.py index f915f71..c580df1 100644 --- a/tests/functional/tests/security/test_negative_io.py +++ b/tests/functional/tests/security/test_negative_io.py @@ -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): """