From 0e8d02235a8ba3ddf289a9f9e202f4c89cd4d213 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Wed, 23 Mar 2022 10:45:01 +0100 Subject: [PATCH] pyocf: Move core/cache md5() logic to volume Signed-off-by: Adam Rutkowski --- tests/functional/pyocf/types/core.py | 30 ------------------- tests/functional/pyocf/types/volume_cache.py | 8 ++--- tests/functional/pyocf/types/volume_core.py | 6 ++-- .../functional/pyocf/types/volume_exp_obj.py | 29 ++++++++++++++++++ tests/functional/tests/basic/test_pyocf.py | 6 ++-- .../tests/management/test_start_stop.py | 8 ++--- 6 files changed, 44 insertions(+), 43 deletions(-) diff --git a/tests/functional/pyocf/types/core.py b/tests/functional/pyocf/types/core.py index c22a79f..9ee0bdf 100644 --- a/tests/functional/pyocf/types/core.py +++ b/tests/functional/pyocf/types/core.py @@ -175,36 +175,6 @@ class Core: def reset_stats(self): self.cache.owner.lib.ocf_core_stats_initialize(self.handle) - def exp_obj_md5(self): - logging.getLogger("pyocf").warning( - "Reading whole exported object! This disturbs statistics values" - ) - - cache_line_size = int(self.cache.get_stats()['conf']['cache_line_size']) - read_buffer_all = Data(self.device.size) - - read_buffer = Data(cache_line_size) - - position = 0 - while position < read_buffer_all.size: - io = self.new_io(self.cache.get_default_queue(), position, - cache_line_size, IoDir.READ, 0, 0) - io.set_data(read_buffer) - - cmpl = OcfCompletion([("err", c_int)]) - io.callback = cmpl.callback - io.submit() - cmpl.wait() - - if cmpl.results["err"]: - raise Exception("Error reading whole exported object") - - read_buffer_all.copy(read_buffer, position, 0, cache_line_size) - position += cache_line_size - - return read_buffer_all.md5() - - lib = OcfLib.getInstance() lib.ocf_core_get_uuid_wrapper.restype = POINTER(Uuid) lib.ocf_core_get_uuid_wrapper.argtypes = [c_void_p] diff --git a/tests/functional/pyocf/types/volume_cache.py b/tests/functional/pyocf/types/volume_cache.py index 3751e43..d44e683 100644 --- a/tests/functional/pyocf/types/volume_cache.py +++ b/tests/functional/pyocf/types/volume_cache.py @@ -20,12 +20,12 @@ class CacheVolume(ExpObjVolume): if open: self.open() - def md5(self): - data = self._read() - return data.md5() - def open(self): return Volume.open( self.lib.ocf_cache_get_front_volume(self.cache.handle), self ) + + def md5(self): + cache_line_size = int(self.cache.get_stats()['conf']['cache_line_size']) + return self._exp_obj_md5(cache_line_size) diff --git a/tests/functional/pyocf/types/volume_core.py b/tests/functional/pyocf/types/volume_core.py index 841bdaf..af0badd 100644 --- a/tests/functional/pyocf/types/volume_core.py +++ b/tests/functional/pyocf/types/volume_core.py @@ -17,11 +17,11 @@ class CoreVolume(ExpObjVolume): if open: self.open() - def md5(self): - return self.core.exp_obj_md5() - def open(self): return Volume.open( self.lib.ocf_core_get_front_volume(self.core.handle), self ) + + def md5(self): + return self._exp_obj_md5(4096) diff --git a/tests/functional/pyocf/types/volume_exp_obj.py b/tests/functional/pyocf/types/volume_exp_obj.py index 5cacc15..20771c5 100644 --- a/tests/functional/pyocf/types/volume_exp_obj.py +++ b/tests/functional/pyocf/types/volume_exp_obj.py @@ -3,6 +3,7 @@ # SPDX-License-Identifier: BSD-3-Clause # +import logging from ctypes import c_int, c_void_p, CFUNCTYPE, byref, c_uint32, c_uint64, cast, POINTER from ..ocf import OcfLib @@ -87,6 +88,34 @@ class ExpObjVolume(Volume): def md5(self): raise NotImplementedError + def _exp_obj_md5(self, read_size): + logging.getLogger("pyocf").warning( + "Reading whole exported object! This disturbs statistics values" + ) + + read_buffer_all = Data(self.parent.device.size) + + read_buffer = Data(read_size) + + position = 0 + while position < read_buffer_all.size: + io = self.new_io(self.parent.get_default_queue(), position, + read_size, IoDir.READ, 0, 0) + io.set_data(read_buffer) + + cmpl = OcfCompletion([("err", c_int)]) + io.callback = cmpl.callback + io.submit() + cmpl.wait() + + if cmpl.results["err"]: + raise Exception("Error reading whole exported object") + + read_buffer_all.copy(read_buffer, position, 0, read_size) + position += read_size + + return read_buffer_all.md5() + lib = OcfLib.getInstance() lib.ocf_volume_get_max_io_size.argtypes = [c_void_p] diff --git a/tests/functional/tests/basic/test_pyocf.py b/tests/functional/tests/basic/test_pyocf.py index 1b4dcf1..4468078 100644 --- a/tests/functional/tests/basic/test_pyocf.py +++ b/tests/functional/tests/basic/test_pyocf.py @@ -42,7 +42,7 @@ def test_simple_wt_write(pyocf_ctx): assert stats["req"]["wr_full_misses"]["value"] == 1 assert stats["usage"]["occupancy"]["value"] == 1 - assert core.exp_obj_md5() == core_device.md5() + assert vol.md5() == core_device.md5() cache.stop() @@ -110,6 +110,8 @@ def test_load_cache_with_cores(pyocf_ctx, open_cores): else: core = cache.get_core_by_name("test_core") + vol = CoreVolume(core, open=True) + read_data = Data(write_data.size) io = vol.new_io(cache.get_default_queue(), S.from_sector(3).B, read_data.size, IoDir.READ, 0, 0) @@ -121,4 +123,4 @@ def test_load_cache_with_cores(pyocf_ctx, open_cores): cmpl.wait() assert read_data.md5() == write_data.md5() - assert core.exp_obj_md5() == core_device.md5() + assert vol.md5() == core_device.md5() diff --git a/tests/functional/tests/management/test_start_stop.py b/tests/functional/tests/management/test_start_stop.py index 9b3c829..626fa32 100644 --- a/tests/functional/tests/management/test_start_stop.py +++ b/tests/functional/tests/management/test_start_stop.py @@ -201,7 +201,7 @@ def test_stop(pyocf_ctx, mode: CacheMode, cls: CacheLineSize, with_flush: bool): assert int(stats["conf"]["dirty"]) == (cls_no if mode.lazy_write() else 0),\ "Dirty data before MD5" - md5_exported_core = core.exp_obj_md5() + md5_exported_core = front_vol.md5() if with_flush: cache.flush() @@ -554,13 +554,13 @@ def check_stats_read_after_write(core, mode, cls, write_to_empty=False): def check_md5_sums(core: Core, mode: CacheMode): if mode.lazy_write(): - assert core.device.md5() != core.exp_obj_md5(), \ + assert core.device.md5() != core.get_front_volume().md5(), \ "MD5 check: core device vs exported object without flush" core.cache.flush() - assert core.device.md5() == core.exp_obj_md5(), \ + assert core.device.md5() == core.get_front_volume().md5(), \ "MD5 check: core device vs exported object after flush" else: - assert core.device.md5() == core.exp_obj_md5(), \ + assert core.device.md5() == core.get_front_volume().md5(), \ "MD5 check: core device vs exported object"