pyocf: Add test for re-attaching device w/o force

Signed-off-by: Daniel Madej <daniel.madej@huawei.com>
This commit is contained in:
Daniel Madej 2025-01-30 12:42:43 +01:00
parent 95c9c8987e
commit 3263503de1

View File

@ -1,16 +1,13 @@
# #
# Copyright(c) 2019-2022 Intel Corporation # Copyright(c) 2019-2022 Intel Corporation
# Copyright(c) 2024 Huawei Technologies # Copyright(c) 2024-2025 Huawei Technologies
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
# #
import logging import logging
from ctypes import c_int, c_void_p, byref, c_uint32, memmove, cast from ctypes import c_void_p, memmove, cast
from random import randrange
from itertools import count
import pytest import pytest
from pyocf.types.cache import ( from pyocf.types.cache import (
Cache, Cache,
CacheMode, CacheMode,
@ -70,12 +67,32 @@ def test_detach_cache_twice(pyocf_ctx):
cache.stop() cache.stop()
def test_detach_cache_zero_superblock(pyocf_ctx):
"""Check if superblock is zeroed after detach and the cache device can be reattached without
--force option.
"""
cache_device = RamVolume(Size.from_MiB(50))
cache = Cache.start_on_device(cache_device)
cache.detach_device()
data = cache_device.get_bytes()
page_size = 4096
assert data[:page_size] == b'\x00'*page_size
cache.attach_device(cache_device, force=False)
cache.detach_device()
cache.stop()
@pytest.mark.parametrize("cls", CacheLineSize) @pytest.mark.parametrize("cls", CacheLineSize)
@pytest.mark.parametrize("mode", [CacheMode.WB, CacheMode.WT, CacheMode.WO]) @pytest.mark.parametrize("mode", [CacheMode.WB, CacheMode.WT, CacheMode.WO])
@pytest.mark.parametrize("new_cache_size", [80, 120]) @pytest.mark.parametrize("new_cache_size", [80, 120])
def test_attach_different_size(pyocf_ctx, new_cache_size, mode: CacheMode, cls: CacheLineSize): def test_attach_different_size(pyocf_ctx, new_cache_size, mode: CacheMode, cls: CacheLineSize):
"""Start cache and add partition with limited occupancy. Fill partition with data, """Start cache and add partition with limited occupancy. Fill partition with data,
attach cache with different size and trigger IO. Verify if occupancy thresold is attach cache with different size and trigger IO. Verify if occupancy threshold is
respected with both original and new cache device. respected with both original and new cache device.
""" """
cache_device = RamVolume(Size.from_MiB(100)) cache_device = RamVolume(Size.from_MiB(100))