|
1 | 1 | # |
2 | 2 | # Copyright(c) 2019-2022 Intel Corporation |
3 | | -# Copyright(c) 2024 Huawei Technologies |
| 3 | +# Copyright(c) 2024-2025 Huawei Technologies |
4 | 4 | # SPDX-License-Identifier: BSD-3-Clause |
5 | 5 | # |
6 | 6 |
|
7 | 7 | 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 |
11 | 9 |
|
12 | 10 | import pytest |
13 | | - |
14 | 11 | from pyocf.types.cache import ( |
15 | 12 | Cache, |
16 | 13 | CacheMode, |
@@ -70,12 +67,32 @@ def test_detach_cache_twice(pyocf_ctx): |
70 | 67 | cache.stop() |
71 | 68 |
|
72 | 69 |
|
| 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 | + |
73 | 90 | @pytest.mark.parametrize("cls", CacheLineSize) |
74 | 91 | @pytest.mark.parametrize("mode", [CacheMode.WB, CacheMode.WT, CacheMode.WO]) |
75 | 92 | @pytest.mark.parametrize("new_cache_size", [80, 120]) |
76 | 93 | def test_attach_different_size(pyocf_ctx, new_cache_size, mode: CacheMode, cls: CacheLineSize): |
77 | 94 | """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 |
79 | 96 | respected with both original and new cache device. |
80 | 97 | """ |
81 | 98 | cache_device = RamVolume(Size.from_MiB(100)) |
|
0 commit comments