switch to volume I/O interface in functional tests
... instead of core::new_io() Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
@@ -11,8 +11,10 @@ import pytest
|
||||
from pyocf.types.cache import Cache, Core
|
||||
from pyocf.types.data import Data
|
||||
from pyocf.types.io import IoDir
|
||||
from pyocf.types.queue import Queue
|
||||
from pyocf.types.shared import OcfCompletion
|
||||
from pyocf.types.volume import RamVolume
|
||||
from pyocf.types.volume import Volume, RamVolume
|
||||
from pyocf.types.volume_core import CoreVolume
|
||||
from pyocf.utils import Size
|
||||
|
||||
|
||||
@@ -22,9 +24,9 @@ def test_neg_write_too_long_data(pyocf_ctx, c_uint16_randomize):
|
||||
Check if writing data larger than exported object size is properly blocked
|
||||
"""
|
||||
|
||||
core = prepare_cache_and_core(Size.from_MiB(1))
|
||||
vol, queue = prepare_cache_and_core(Size.from_MiB(1))
|
||||
data = Data(int(Size.from_KiB(c_uint16_randomize)))
|
||||
completion = io_operation(core, data, IoDir.WRITE)
|
||||
completion = io_operation(vol, queue, data, IoDir.WRITE)
|
||||
|
||||
if c_uint16_randomize > 1024:
|
||||
assert completion.results["err"] != 0
|
||||
@@ -38,9 +40,9 @@ def test_neg_read_too_long_data(pyocf_ctx, c_uint16_randomize):
|
||||
Check if reading data larger than exported object size is properly blocked
|
||||
"""
|
||||
|
||||
core = prepare_cache_and_core(Size.from_MiB(1))
|
||||
vol, queue = prepare_cache_and_core(Size.from_MiB(1))
|
||||
data = Data(int(Size.from_KiB(c_uint16_randomize)))
|
||||
completion = io_operation(core, data, IoDir.READ)
|
||||
completion = io_operation(vol, queue, data, IoDir.READ)
|
||||
|
||||
if c_uint16_randomize > 1024:
|
||||
assert completion.results["err"] != 0
|
||||
@@ -56,9 +58,9 @@ def test_neg_write_too_far(pyocf_ctx, c_uint16_randomize):
|
||||
"""
|
||||
|
||||
limited_size = c_uint16_randomize % (int(Size.from_KiB(4)) + 1)
|
||||
core = prepare_cache_and_core(Size.from_MiB(4))
|
||||
vol, queue = prepare_cache_and_core(Size.from_MiB(4))
|
||||
data = Data(int(Size.from_KiB(limited_size)))
|
||||
completion = io_operation(core, data, IoDir.WRITE, int(Size.from_MiB(3)))
|
||||
completion = io_operation(vol, queue, data, IoDir.WRITE, int(Size.from_MiB(3)))
|
||||
|
||||
if limited_size > 1024:
|
||||
assert completion.results["err"] != 0
|
||||
@@ -74,9 +76,9 @@ def test_neg_read_too_far(pyocf_ctx, c_uint16_randomize):
|
||||
"""
|
||||
|
||||
limited_size = c_uint16_randomize % (int(Size.from_KiB(4)) + 1)
|
||||
core = prepare_cache_and_core(Size.from_MiB(4))
|
||||
vol, queue = prepare_cache_and_core(Size.from_MiB(4))
|
||||
data = Data(int(Size.from_KiB(limited_size)))
|
||||
completion = io_operation(core, data, IoDir.READ, offset=(Size.from_MiB(3)))
|
||||
completion = io_operation(vol, queue, data, IoDir.READ, offset=(Size.from_MiB(3)))
|
||||
|
||||
if limited_size > 1024:
|
||||
assert completion.results["err"] != 0
|
||||
@@ -91,9 +93,9 @@ def test_neg_write_offset_outside_of_device(pyocf_ctx, c_int_sector_randomize):
|
||||
IO offset is located outside of device range
|
||||
"""
|
||||
|
||||
core = prepare_cache_and_core(Size.from_MiB(2))
|
||||
vol, queue = prepare_cache_and_core(Size.from_MiB(2))
|
||||
data = Data(int(Size.from_KiB(1)))
|
||||
completion = io_operation(core, data, IoDir.WRITE, offset=c_int_sector_randomize)
|
||||
completion = io_operation(vol, queue, data, IoDir.WRITE, offset=c_int_sector_randomize)
|
||||
|
||||
if 0 <= c_int_sector_randomize <= int(Size.from_MiB(2)) - int(Size.from_KiB(1)):
|
||||
assert completion.results["err"] == 0
|
||||
@@ -108,9 +110,9 @@ def test_neg_read_offset_outside_of_device(pyocf_ctx, c_int_sector_randomize):
|
||||
IO offset is located outside of device range
|
||||
"""
|
||||
|
||||
core = prepare_cache_and_core(Size.from_MiB(2))
|
||||
vol, queue = prepare_cache_and_core(Size.from_MiB(2))
|
||||
data = Data(int(Size.from_KiB(1)))
|
||||
completion = io_operation(core, data, IoDir.READ, offset=c_int_sector_randomize)
|
||||
completion = io_operation(vol, queue, data, IoDir.READ, offset=c_int_sector_randomize)
|
||||
|
||||
if 0 <= c_int_sector_randomize <= int(Size.from_MiB(2)) - int(Size.from_KiB(1)):
|
||||
assert completion.results["err"] == 0
|
||||
@@ -125,11 +127,11 @@ def test_neg_offset_unaligned(pyocf_ctx, c_int_randomize):
|
||||
IO offset is not aligned
|
||||
"""
|
||||
|
||||
core = prepare_cache_and_core(Size.from_MiB(2))
|
||||
vol, queue = 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,
|
||||
vol.new_io(queue, c_int_randomize, data.size,
|
||||
IoDir.WRITE, 0, 0)
|
||||
|
||||
|
||||
@@ -140,11 +142,11 @@ def test_neg_size_unaligned(pyocf_ctx, c_uint16_randomize):
|
||||
IO size is not aligned
|
||||
"""
|
||||
|
||||
core = prepare_cache_and_core(Size.from_MiB(2))
|
||||
vol, queue = 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,
|
||||
vol.new_io(queue, 0, data.size,
|
||||
IoDir.WRITE, 0, 0)
|
||||
|
||||
|
||||
@@ -155,9 +157,9 @@ def test_neg_io_class(pyocf_ctx, c_int_randomize):
|
||||
number is not in allowed values {0, ..., 32}
|
||||
"""
|
||||
|
||||
core = prepare_cache_and_core(Size.from_MiB(2))
|
||||
vol, queue = prepare_cache_and_core(Size.from_MiB(2))
|
||||
data = Data(int(Size.from_MiB(1)))
|
||||
completion = io_operation(core, data, randrange(0, 2), io_class=c_int_randomize)
|
||||
completion = io_operation(vol, queue, data, randrange(0, 2), io_class=c_int_randomize)
|
||||
|
||||
if 0 <= c_int_randomize <= 32:
|
||||
assert completion.results["err"] == 0
|
||||
@@ -172,9 +174,9 @@ def test_neg_io_direction(pyocf_ctx, c_int_randomize):
|
||||
that is when IO direction value is not in allowed values {0, 1}
|
||||
"""
|
||||
|
||||
core = prepare_cache_and_core(Size.from_MiB(2))
|
||||
vol, queue = prepare_cache_and_core(Size.from_MiB(2))
|
||||
data = Data(int(Size.from_MiB(1)))
|
||||
completion = io_operation(core, data, c_int_randomize)
|
||||
completion = io_operation(vol, queue, data, c_int_randomize)
|
||||
|
||||
if c_int_randomize in [0, 1]:
|
||||
assert completion.results["err"] == 0
|
||||
@@ -190,12 +192,21 @@ def prepare_cache_and_core(core_size: Size, cache_size: Size = Size.from_MiB(50)
|
||||
core = Core.using_device(core_device)
|
||||
|
||||
cache.add_core(core)
|
||||
return core
|
||||
vol = CoreVolume(core, open=True)
|
||||
queue = cache.get_default_queue()
|
||||
|
||||
return vol, queue
|
||||
|
||||
|
||||
def io_operation(core: Core, data: Data, io_direction: int, offset: int = 0, io_class: int = 0):
|
||||
io = core.new_io(core.cache.get_default_queue(), offset, data.size,
|
||||
io_direction, io_class, 0)
|
||||
def io_operation(
|
||||
vol: Volume,
|
||||
queue: Queue,
|
||||
data: Data,
|
||||
io_direction: int,
|
||||
offset: int = 0,
|
||||
io_class: int = 0,
|
||||
):
|
||||
io = vol.new_io(queue, offset, data.size, io_direction, io_class, 0)
|
||||
io.set_data(data)
|
||||
|
||||
completion = OcfCompletion([("err", c_int)])
|
||||
|
@@ -8,7 +8,8 @@ from ctypes import c_int
|
||||
|
||||
from pyocf.types.cache import Cache, CacheMode
|
||||
from pyocf.types.core import Core
|
||||
from pyocf.types.volume import RamVolume
|
||||
from pyocf.types.volume import Volume, RamVolume
|
||||
from pyocf.types.volume_core import CoreVolume
|
||||
from pyocf.utils import Size as S
|
||||
from pyocf.types.data import Data, DataOps
|
||||
from pyocf.types.ctx import OcfCtx
|
||||
@@ -83,10 +84,12 @@ def test_secure_erase_simple_io_read_misses(cache_mode):
|
||||
core_device = RamVolume(S.from_MiB(50))
|
||||
core = Core.using_device(core_device)
|
||||
cache.add_core(core)
|
||||
vol = CoreVolume(core, open=True)
|
||||
queue = cache.get_default_queue()
|
||||
|
||||
write_data = DataCopyTracer(S.from_sector(1))
|
||||
io = core.new_io(
|
||||
cache.get_default_queue(),
|
||||
io = vol.new_io(
|
||||
queue,
|
||||
S.from_sector(1).B,
|
||||
write_data.size,
|
||||
IoDir.WRITE,
|
||||
@@ -103,8 +106,8 @@ def test_secure_erase_simple_io_read_misses(cache_mode):
|
||||
cmpls = []
|
||||
for i in range(100):
|
||||
read_data = DataCopyTracer(S.from_sector(1))
|
||||
io = core.new_io(
|
||||
cache.get_default_queue(),
|
||||
io = vol.new_io(
|
||||
queue,
|
||||
i * S.from_sector(1).B,
|
||||
read_data.size,
|
||||
IoDir.READ,
|
||||
@@ -122,9 +125,7 @@ def test_secure_erase_simple_io_read_misses(cache_mode):
|
||||
c.wait()
|
||||
|
||||
write_data = DataCopyTracer.from_string("TEST DATA" * 100)
|
||||
io = core.new_io(
|
||||
cache.get_default_queue(), S.from_sector(1), write_data.size, IoDir.WRITE, 0, 0
|
||||
)
|
||||
io = vol.new_io(queue, S.from_sector(1), write_data.size, IoDir.WRITE, 0, 0)
|
||||
io.set_data(write_data)
|
||||
|
||||
cmpl = OcfCompletion([("err", c_int)])
|
||||
@@ -147,7 +148,6 @@ def test_secure_erase_simple_io_read_misses(cache_mode):
|
||||
+ stats["req"]["rd_full_misses"]["value"]
|
||||
) > 0
|
||||
|
||||
|
||||
@pytest.mark.security
|
||||
def test_secure_erase_simple_io_cleaning():
|
||||
"""
|
||||
@@ -176,11 +176,11 @@ def test_secure_erase_simple_io_cleaning():
|
||||
core_device = RamVolume(S.from_MiB(100))
|
||||
core = Core.using_device(core_device)
|
||||
cache.add_core(core)
|
||||
vol = CoreVolume(core, open=True)
|
||||
queue = cache.get_default_queue()
|
||||
|
||||
read_data = Data(S.from_sector(1).B)
|
||||
io = core.new_io(
|
||||
cache.get_default_queue(), S.from_sector(1).B, read_data.size, IoDir.WRITE, 0, 0
|
||||
)
|
||||
io = vol.new_io(queue, S.from_sector(1).B, read_data.size, IoDir.WRITE, 0, 0)
|
||||
io.set_data(read_data)
|
||||
|
||||
cmpl = OcfCompletion([("err", c_int)])
|
||||
@@ -189,9 +189,7 @@ def test_secure_erase_simple_io_cleaning():
|
||||
cmpl.wait()
|
||||
|
||||
read_data = Data(S.from_sector(8).B)
|
||||
io = core.new_io(
|
||||
cache.get_default_queue(), S.from_sector(1).B, read_data.size, IoDir.READ, 0, 0
|
||||
)
|
||||
io = vol.new_io(queue, S.from_sector(1).B, read_data.size, IoDir.READ, 0, 0)
|
||||
io.set_data(read_data)
|
||||
|
||||
cmpl = OcfCompletion([("err", c_int)])
|
||||
|
Reference in New Issue
Block a user