示例#1
0
def test_stop(pyocf_ctx, mode: CacheMode, cls: CacheLineSize, with_flush: bool):
    """Stopping cache.
    Check if cache is stopped properly in different modes with or without preceding flush operation.
    """

    cache_device = Volume(Size.from_MiB(20))
    core_device = Volume(Size.from_MiB(5))
    cache = Cache.start_on_device(cache_device, cache_mode=mode, cache_line_size=cls)
    core_exported = Core.using_device(core_device)
    cache.add_core(core_exported)
    cls_no = 10

    run_io_and_cache_data_if_possible(core_exported, mode, cls, cls_no)

    stats = cache.get_stats()
    assert int(stats["conf"]["dirty"]) == (cls_no if mode.lazy_write() else 0),\
        "Dirty data before MD5"

    md5_exported_core = core_exported.exp_obj_md5()

    if with_flush:
        cache.flush()
    cache.stop()

    if mode.lazy_write() and not with_flush:
        assert core_device.md5() != md5_exported_core, \
            "MD5 check: core device vs exported object with dirty data"
    else:
        assert core_device.md5() == md5_exported_core, \
            "MD5 check: core device vs exported object with clean data"
示例#2
0
def check_stats_write_empty(exported_obj: Core, mode: CacheMode, cls: CacheLineSize):
    stats = exported_obj.cache.get_stats()
    assert stats["conf"]["cache_mode"] == mode, "Cache mode"
    # TODO(ajrutkow): why 1 for WT ??
    assert exported_obj.cache.device.get_stats()[IoDir.WRITE] == \
        (2 if mode.lazy_write() else (1 if mode == CacheMode.WT else 0)), \
        "Writes to cache device"
    assert exported_obj.device.get_stats()[IoDir.WRITE] == (0 if mode.lazy_write() else 1), \
        "Writes to core device"
    assert stats["req"]["wr_full_misses"]["value"] == (1 if mode.write_insert() else 0), \
        "Write full misses"
    assert stats["usage"]["occupancy"]["value"] == \
        ((cls / CacheLineSize.LINE_4KiB) if mode.write_insert() else 0), \
        "Occupancy"
示例#3
0
def check_stats_write_after_read(exported_obj: Core,
                                 mode: CacheMode,
                                 cls: CacheLineSize,
                                 read_from_empty=False):
    stats = exported_obj.cache.get_stats()
    assert exported_obj.cache.device.get_stats()[IoDir.WRITE] == \
        (0 if mode in {CacheMode.WI, CacheMode.PT} else
            (2 if read_from_empty and mode.lazy_write() else 1)), \
        "Writes to cache device"
    assert exported_obj.device.get_stats()[IoDir.WRITE] == (0 if mode.lazy_write() else 1), \
        "Writes to core device"
    assert stats["req"]["wr_hits"]["value"] == \
        (1 if (mode.read_insert() and mode != CacheMode.WI)
            or (mode.write_insert() and not read_from_empty) else 0), \
        "Write hits"
    assert stats["usage"]["occupancy"]["value"] == \
        (0 if mode in {CacheMode.WI, CacheMode.PT} else (cls / CacheLineSize.LINE_4KiB)), \
        "Occupancy"
示例#4
0
def check_md5_sums(exported_obj: Core, mode: CacheMode):
    if mode.lazy_write():
        assert exported_obj.device.md5() != exported_obj.exp_obj_md5(), \
            "MD5 check: core device vs exported object without flush"
        exported_obj.cache.flush()
        assert exported_obj.device.md5() == exported_obj.exp_obj_md5(), \
            "MD5 check: core device vs exported object after flush"
    else:
        assert exported_obj.device.md5() == exported_obj.exp_obj_md5(), \
            "MD5 check: core device vs exported object"
示例#5
0
def check_md5_sums(core: Core, mode: CacheMode):
    if mode.lazy_write():
        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.get_front_volume().md5(), \
            "MD5 check: core device vs exported object after flush"
    else:
        assert core.device.md5() == core.get_front_volume().md5(), \
            "MD5 check: core device vs exported object"