Skip to content

Commit 6a81bde

Browse files
committed
pyocf: Add test for re-attaching device w/o force
Signed-off-by: Daniel Madej <daniel.madej@huawei.com>
1 parent bb8116e commit 6a81bde

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

tests/functional/tests/management/test_attach_cache.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
#
22
# Copyright(c) 2019-2022 Intel Corporation
3-
# Copyright(c) 2024 Huawei Technologies
3+
# Copyright(c) 2024-2025 Huawei Technologies
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
66

77
import logging
8-
from ctypes import c_int, c_void_p, byref, c_uint32, memmove, cast
9-
from random import randrange
10-
from itertools import count
8+
from ctypes import c_void_p, memmove, cast
119

1210
import pytest
13-
1411
from pyocf.types.cache import (
1512
Cache,
1613
CacheMode,
@@ -70,12 +67,32 @@ def test_detach_cache_twice(pyocf_ctx):
7067
cache.stop()
7168

7269

70+
def test_detach_cache_zero_superblock(pyocf_ctx):
71+
"""Check if superblock is zeroed after detach and the cache device can be reattached without
72+
--force option.
73+
"""
74+
cache_device = RamVolume(Size.from_MiB(50))
75+
cache = Cache.start_on_device(cache_device)
76+
77+
cache.detach_device()
78+
79+
data = cache_device.get_bytes()
80+
81+
page_size = 4096
82+
assert data[:page_size] == b'\x00'*page_size
83+
84+
cache.attach_device(cache_device, force=False)
85+
cache.detach_device()
86+
87+
cache.stop()
88+
89+
7390
@pytest.mark.parametrize("cls", CacheLineSize)
7491
@pytest.mark.parametrize("mode", [CacheMode.WB, CacheMode.WT, CacheMode.WO])
7592
@pytest.mark.parametrize("new_cache_size", [80, 120])
7693
def test_attach_different_size(pyocf_ctx, new_cache_size, mode: CacheMode, cls: CacheLineSize):
7794
"""Start cache and add partition with limited occupancy. Fill partition with data,
78-
attach cache with different size and trigger IO. Verify if occupancy thresold is
95+
attach cache with different size and trigger IO. Verify if occupancy threshold is
7996
respected with both original and new cache device.
8097
"""
8198
cache_device = RamVolume(Size.from_MiB(100))

0 commit comments

Comments
 (0)