diff --git a/tests/functional/pyocf/types/data.py b/tests/functional/pyocf/types/data.py index 6243e12..c4054c6 100644 --- a/tests/functional/pyocf/types/data.py +++ b/tests/functional/pyocf/types/data.py @@ -21,7 +21,7 @@ from enum import IntEnum from hashlib import md5 import weakref -from ..utils import print_buffer +from ..utils import print_buffer, Size as S class DataSeek(IntEnum): diff --git a/tests/functional/pyocf/utils.py b/tests/functional/pyocf/utils.py index 643f675..a0710af 100644 --- a/tests/functional/pyocf/utils.py +++ b/tests/functional/pyocf/utils.py @@ -56,9 +56,13 @@ class Size: _MiB = _KiB * 1024 _GiB = _MiB * 1024 _TiB = _GiB * 1024 + _SECTOR_SIZE = 512 - def __init__(self, b: int): - self.bytes = b + def __init__(self, b: int, sector_aligned: bool = False): + if sector_aligned: + self.bytes = ((b + self._SECTOR_SIZE - 1) // self._SECTOR_SIZE) * self._SECTOR_SIZE + else: + self.bytes = b def __int__(self): return self.bytes @@ -67,24 +71,28 @@ class Size: return self.bytes @classmethod - def from_B(cls, value): - return cls(value) + def from_B(cls, value, sector_aligned = False): + return cls(value, sector_aligned) @classmethod - def from_KiB(cls, value): - return cls(value * cls._KiB) + def from_KiB(cls, value, sector_aligned = False): + return cls(value * cls._KiB, sector_aligned) @classmethod - def from_MiB(cls, value): - return cls(value * cls._MiB) + def from_MiB(cls, value, sector_aligned = False): + return cls(value * cls._MiB, sector_aligned) @classmethod - def from_GiB(cls, value): - return cls(value * cls._GiB) + def from_GiB(cls, value, sector_aligned = False): + return cls(value * cls._GiB, sector_aligned) @classmethod - def from_TiB(cls, value): - return cls(value * cls._TiB) + def from_TiB(cls, value, sector_aligned = False): + return cls(value * cls._TiB, sector_aligned) + + @classmethod + def from_sector(cls, value): + return cls(value * cls._SECTOR_SIZE) @property def B(self): @@ -106,6 +114,10 @@ class Size: def TiB(self): return self.bytes / self._TiB + @property + def sectors(self): + return self.bytes // _SECTOR_SIZE + def __str__(self): if self.bytes < self._KiB: return "{} B".format(self.B) diff --git a/tests/functional/tests/engine/test_wo.py b/tests/functional/tests/engine/test_wo.py index 012d74c..2ea0b60 100644 --- a/tests/functional/tests/engine/test_wo.py +++ b/tests/functional/tests/engine/test_wo.py @@ -93,7 +93,7 @@ def test_wo_read_data_consistency(pyocf_ctx): # possible end sectors for test iteration end_sec = [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 23] - SECTOR_SIZE = 512 + SECTOR_SIZE = Size.from_sector(1).B CACHELINE_SIZE = 4096 WORKSET_SIZE = 3 * CACHELINE_SIZE WORKSET_OFFSET = 1024 * CACHELINE_SIZE