pyocf: format all .py files with black -l 100
Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
@@ -5,12 +5,7 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
from ctypes import (
|
||||
c_uint64,
|
||||
c_uint32,
|
||||
c_uint16,
|
||||
c_int
|
||||
)
|
||||
from ctypes import c_uint64, c_uint32, c_uint16, c_int
|
||||
from tests.utils.random import RandomStringGenerator, RandomGenerator, DefaultRanges, Range
|
||||
|
||||
from pyocf.types.cache import CacheMode, MetadataLayout, PromotionPolicy
|
||||
@@ -63,9 +58,7 @@ def string_randomize(request):
|
||||
return request.param
|
||||
|
||||
|
||||
@pytest.fixture(
|
||||
params=RandomGenerator(DefaultRanges.UINT32).exclude_range(enum_range(CacheMode))
|
||||
)
|
||||
@pytest.fixture(params=RandomGenerator(DefaultRanges.UINT32).exclude_range(enum_range(CacheMode)))
|
||||
def not_cache_mode_randomize(request):
|
||||
return request.param
|
||||
|
||||
|
@@ -199,9 +199,7 @@ def test_neg_core_set_seq_cut_off_promotion(pyocf_ctx, cm, cls):
|
||||
for i in RandomGenerator(DefaultRanges.UINT32):
|
||||
if i in ConfValidValues.seq_cutoff_promotion_range:
|
||||
continue
|
||||
with pytest.raises(
|
||||
OcfError, match="Error setting core seq cut off policy promotion count"
|
||||
):
|
||||
with pytest.raises(OcfError, match="Error setting core seq cut off policy promotion count"):
|
||||
core1.set_seq_cut_off_promotion(i)
|
||||
print(f"\n{i}")
|
||||
|
||||
@@ -235,9 +233,7 @@ def test_neg_cache_set_seq_cut_off_threshold(pyocf_ctx, cm, cls):
|
||||
for i in RandomGenerator(DefaultRanges.UINT32):
|
||||
if i in ConfValidValues.seq_cutoff_threshold_rage:
|
||||
continue
|
||||
with pytest.raises(
|
||||
OcfError, match="Error setting cache seq cut off policy threshold"
|
||||
):
|
||||
with pytest.raises(OcfError, match="Error setting cache seq cut off policy threshold"):
|
||||
cache.set_seq_cut_off_threshold(i)
|
||||
print(f"\n{i}")
|
||||
|
||||
@@ -268,9 +264,7 @@ def test_neg_core_set_seq_cut_off_threshold(pyocf_ctx, cm, cls):
|
||||
for i in RandomGenerator(DefaultRanges.UINT32):
|
||||
if i in ConfValidValues.seq_cutoff_threshold_rage:
|
||||
continue
|
||||
with pytest.raises(
|
||||
OcfError, match="Error setting core seq cut off policy threshold"
|
||||
):
|
||||
with pytest.raises(OcfError, match="Error setting core seq cut off policy threshold"):
|
||||
core.set_seq_cut_off_threshold(i)
|
||||
print(f"\n{i}")
|
||||
|
||||
@@ -468,10 +462,7 @@ def test_neg_set_nhit_promotion_policy_param(pyocf_ctx, cm, cls):
|
||||
# Start cache device
|
||||
cache_device = RamVolume(S.from_MiB(50))
|
||||
cache = Cache.start_on_device(
|
||||
cache_device,
|
||||
cache_mode=cm,
|
||||
cache_line_size=cls,
|
||||
promotion_policy=PromotionPolicy.NHIT,
|
||||
cache_device, cache_mode=cm, cache_line_size=cls, promotion_policy=PromotionPolicy.NHIT,
|
||||
)
|
||||
|
||||
# Set invalid promotion policy param id and check if failed
|
||||
@@ -498,10 +489,7 @@ def test_neg_set_nhit_promotion_policy_param_trigger(pyocf_ctx, cm, cls):
|
||||
# Start cache device
|
||||
cache_device = RamVolume(S.from_MiB(50))
|
||||
cache = Cache.start_on_device(
|
||||
cache_device,
|
||||
cache_mode=cm,
|
||||
cache_line_size=cls,
|
||||
promotion_policy=PromotionPolicy.NHIT,
|
||||
cache_device, cache_mode=cm, cache_line_size=cls, promotion_policy=PromotionPolicy.NHIT,
|
||||
)
|
||||
|
||||
# Set to invalid promotion policy trigger threshold and check if failed
|
||||
@@ -509,9 +497,7 @@ def test_neg_set_nhit_promotion_policy_param_trigger(pyocf_ctx, cm, cls):
|
||||
if i in ConfValidValues.promotion_nhit_trigger_threshold_range:
|
||||
continue
|
||||
with pytest.raises(OcfError, match="Error setting promotion policy parameter"):
|
||||
cache.set_promotion_policy_param(
|
||||
PromotionPolicy.NHIT, NhitParams.TRIGGER_THRESHOLD, i
|
||||
)
|
||||
cache.set_promotion_policy_param(PromotionPolicy.NHIT, NhitParams.TRIGGER_THRESHOLD, i)
|
||||
print(f"\n{i}")
|
||||
|
||||
|
||||
@@ -530,10 +516,7 @@ def test_neg_set_nhit_promotion_policy_param_threshold(pyocf_ctx, cm, cls):
|
||||
# Start cache device
|
||||
cache_device = RamVolume(S.from_MiB(50))
|
||||
cache = Cache.start_on_device(
|
||||
cache_device,
|
||||
cache_mode=cm,
|
||||
cache_line_size=cls,
|
||||
promotion_policy=PromotionPolicy.NHIT,
|
||||
cache_device, cache_mode=cm, cache_line_size=cls, promotion_policy=PromotionPolicy.NHIT,
|
||||
)
|
||||
|
||||
# Set to invalid promotion policy insertion threshold and check if failed
|
||||
@@ -568,11 +551,7 @@ def test_neg_set_ioclass_max_size(pyocf_ctx, cm, cls):
|
||||
continue
|
||||
with pytest.raises(OcfError, match="Error adding partition to cache"):
|
||||
cache.configure_partition(
|
||||
part_id=1,
|
||||
name="unclassified",
|
||||
max_size=i,
|
||||
priority=0,
|
||||
cache_mode=CACHE_MODE_NONE,
|
||||
part_id=1, name="unclassified", max_size=i, priority=0, cache_mode=CACHE_MODE_NONE,
|
||||
)
|
||||
print(f"\n{i}")
|
||||
|
||||
|
@@ -21,6 +21,7 @@ def try_start_cache(**config):
|
||||
cache = Cache.start_on_device(cache_device, **config)
|
||||
cache.stop()
|
||||
|
||||
|
||||
@pytest.mark.security
|
||||
@pytest.mark.parametrize("cls", CacheLineSize)
|
||||
def test_fuzzy_start_cache_mode(pyocf_ctx, cls, not_cache_mode_randomize):
|
||||
@@ -59,14 +60,16 @@ def test_fuzzy_start_name(pyocf_ctx, string_randomize, cm, cls):
|
||||
:param cls: cache line size value to start cache with
|
||||
"""
|
||||
cache_device = RamVolume(Size.from_MiB(50))
|
||||
incorrect_values = ['']
|
||||
incorrect_values = [""]
|
||||
try:
|
||||
cache = Cache.start_on_device(cache_device, name=string_randomize, cache_mode=cm,
|
||||
cache_line_size=cls)
|
||||
cache = Cache.start_on_device(
|
||||
cache_device, name=string_randomize, cache_mode=cm, cache_line_size=cls
|
||||
)
|
||||
except OcfError:
|
||||
if string_randomize not in incorrect_values:
|
||||
logger.error(
|
||||
f"Cache did not start properly with correct name value: '{string_randomize}'")
|
||||
f"Cache did not start properly with correct name value: '{string_randomize}'"
|
||||
)
|
||||
return
|
||||
if string_randomize in incorrect_values:
|
||||
logger.error(f"Cache started with incorrect name value: '{string_randomize}'")
|
||||
@@ -75,7 +78,7 @@ def test_fuzzy_start_name(pyocf_ctx, string_randomize, cm, cls):
|
||||
|
||||
@pytest.mark.security
|
||||
@pytest.mark.parametrize("cls", CacheLineSize)
|
||||
@pytest.mark.parametrize('max_wb_queue_size', RandomGenerator(DefaultRanges.UINT32, 10))
|
||||
@pytest.mark.parametrize("max_wb_queue_size", RandomGenerator(DefaultRanges.UINT32, 10))
|
||||
def test_fuzzy_start_max_queue_size(pyocf_ctx, max_wb_queue_size, c_uint32_randomize, cls):
|
||||
"""
|
||||
Test whether it is impossible to start cache with invalid dependence between max queue size
|
||||
@@ -91,11 +94,14 @@ def test_fuzzy_start_max_queue_size(pyocf_ctx, max_wb_queue_size, c_uint32_rando
|
||||
max_queue_size=max_wb_queue_size,
|
||||
queue_unblock_size=c_uint32_randomize,
|
||||
cache_mode=CacheMode.WB,
|
||||
cache_line_size=cls)
|
||||
cache_line_size=cls,
|
||||
)
|
||||
else:
|
||||
logger.warning(f"Test skipped for valid values: "
|
||||
f"'max_queue_size={max_wb_queue_size}, "
|
||||
f"queue_unblock_size={c_uint32_randomize}'.")
|
||||
logger.warning(
|
||||
f"Test skipped for valid values: "
|
||||
f"'max_queue_size={max_wb_queue_size}, "
|
||||
f"queue_unblock_size={c_uint32_randomize}'."
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.security
|
||||
@@ -111,7 +117,5 @@ def test_fuzzy_start_promotion_policy(pyocf_ctx, not_promotion_policy_randomize,
|
||||
"""
|
||||
with pytest.raises(OcfError, match="OCF_ERR_INVAL"):
|
||||
try_start_cache(
|
||||
cache_mode=cm,
|
||||
cache_line_size=cls,
|
||||
promotion_policy=not_promotion_policy_randomize
|
||||
cache_mode=cm, cache_line_size=cls, promotion_policy=not_promotion_policy_randomize
|
||||
)
|
||||
|
@@ -132,8 +132,7 @@ def test_neg_offset_unaligned(pyocf_ctx, c_int_randomize):
|
||||
data = Data(int(Size.from_KiB(1)))
|
||||
if c_int_randomize % 512 != 0:
|
||||
with pytest.raises(Exception):
|
||||
vol.new_io(queue, c_int_randomize, data.size,
|
||||
IoDir.WRITE, 0, 0)
|
||||
vol.new_io(queue, c_int_randomize, data.size, IoDir.WRITE, 0, 0)
|
||||
|
||||
|
||||
@pytest.mark.security
|
||||
@@ -147,8 +146,7 @@ def test_neg_size_unaligned(pyocf_ctx, c_uint16_randomize):
|
||||
data = Data(int(Size.from_B(c_uint16_randomize)))
|
||||
if c_uint16_randomize % 512 != 0:
|
||||
with pytest.raises(Exception):
|
||||
vol.new_io(queue, 0, data.size,
|
||||
IoDir.WRITE, 0, 0)
|
||||
vol.new_io(queue, 0, data.size, IoDir.WRITE, 0, 0)
|
||||
|
||||
|
||||
@pytest.mark.security
|
||||
@@ -200,12 +198,7 @@ def prepare_cache_and_core(core_size: Size, cache_size: Size = Size.from_MiB(50)
|
||||
|
||||
|
||||
def io_operation(
|
||||
vol: Volume,
|
||||
queue: Queue,
|
||||
data: Data,
|
||||
io_direction: int,
|
||||
offset: int = 0,
|
||||
io_class: int = 0,
|
||||
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)
|
||||
|
@@ -59,9 +59,7 @@ class DataCopyTracer(Data):
|
||||
|
||||
|
||||
@pytest.mark.security
|
||||
@pytest.mark.parametrize(
|
||||
"cache_mode", [CacheMode.WT, CacheMode.WB, CacheMode.WA, CacheMode.WI]
|
||||
)
|
||||
@pytest.mark.parametrize("cache_mode", [CacheMode.WT, CacheMode.WB, CacheMode.WA, CacheMode.WI])
|
||||
def test_secure_erase_simple_io_read_misses(cache_mode):
|
||||
"""
|
||||
Perform simple IO which will trigger read misses, which in turn should
|
||||
@@ -88,14 +86,7 @@ def test_secure_erase_simple_io_read_misses(cache_mode):
|
||||
queue = cache.get_default_queue()
|
||||
|
||||
write_data = DataCopyTracer(S.from_sector(1))
|
||||
io = vol.new_io(
|
||||
queue,
|
||||
S.from_sector(1).B,
|
||||
write_data.size,
|
||||
IoDir.WRITE,
|
||||
0,
|
||||
0,
|
||||
)
|
||||
io = vol.new_io(queue, S.from_sector(1).B, write_data.size, IoDir.WRITE, 0, 0,)
|
||||
io.set_data(write_data)
|
||||
|
||||
cmpl = OcfCompletion([("err", c_int)])
|
||||
@@ -106,14 +97,7 @@ def test_secure_erase_simple_io_read_misses(cache_mode):
|
||||
cmpls = []
|
||||
for i in range(100):
|
||||
read_data = DataCopyTracer(S.from_sector(1))
|
||||
io = vol.new_io(
|
||||
queue,
|
||||
i * S.from_sector(1).B,
|
||||
read_data.size,
|
||||
IoDir.READ,
|
||||
0,
|
||||
0,
|
||||
)
|
||||
io = vol.new_io(queue, i * S.from_sector(1).B, read_data.size, IoDir.READ, 0, 0,)
|
||||
io.set_data(read_data)
|
||||
|
||||
cmpl = OcfCompletion([("err", c_int)])
|
||||
@@ -137,17 +121,13 @@ def test_secure_erase_simple_io_read_misses(cache_mode):
|
||||
|
||||
ctx.exit()
|
||||
|
||||
assert len(DataCopyTracer.needs_erase) == 0, "Not all locked Data instances were secure erased!"
|
||||
assert len(DataCopyTracer.locked_instances) == 0, "Not all locked Data instances were unlocked!"
|
||||
assert (
|
||||
len(DataCopyTracer.needs_erase) == 0
|
||||
), "Not all locked Data instances were secure erased!"
|
||||
assert (
|
||||
len(DataCopyTracer.locked_instances) == 0
|
||||
), "Not all locked Data instances were unlocked!"
|
||||
assert (
|
||||
stats["req"]["rd_partial_misses"]["value"]
|
||||
+ stats["req"]["rd_full_misses"]["value"]
|
||||
stats["req"]["rd_partial_misses"]["value"] + stats["req"]["rd_full_misses"]["value"]
|
||||
) > 0
|
||||
|
||||
|
||||
@pytest.mark.security
|
||||
def test_secure_erase_simple_io_cleaning():
|
||||
"""
|
||||
@@ -201,10 +181,6 @@ def test_secure_erase_simple_io_cleaning():
|
||||
|
||||
ctx.exit()
|
||||
|
||||
assert (
|
||||
len(DataCopyTracer.needs_erase) == 0
|
||||
), "Not all locked Data instances were secure erased!"
|
||||
assert (
|
||||
len(DataCopyTracer.locked_instances) == 0
|
||||
), "Not all locked Data instances were unlocked!"
|
||||
assert len(DataCopyTracer.needs_erase) == 0, "Not all locked Data instances were secure erased!"
|
||||
assert len(DataCopyTracer.locked_instances) == 0, "Not all locked Data instances were unlocked!"
|
||||
assert (stats["usage"]["clean"]["value"]) > 0, "Cleaner didn't run!"
|
||||
|
Reference in New Issue
Block a user