|
1 | 1 | # |
2 | 2 | # Copyright(c) 2019-2022 Intel Corporation |
3 | 3 | # Copyright(c) 2024-2025 Huawei Technologies Co., Ltd. |
| 4 | +# Copyright(c) 2026 Unvertical |
4 | 5 | # SPDX-License-Identifier: BSD-3-Clause |
5 | 6 | # |
6 | 7 |
|
|
9 | 10 | from api.cas import casadm, casadm_parser |
10 | 11 | from api.cas.cache_config import (CleaningPolicy, |
11 | 12 | CacheMode, |
| 13 | + CacheModeTrait, |
12 | 14 | CacheLineSize, |
13 | 15 | FlushParametersAlru, |
14 | 16 | Time, |
15 | 17 | FlushParametersAcp) |
| 18 | +from api.cas.casadm_params import StatsFilter |
16 | 19 | from core.test_run import TestRun |
17 | 20 | from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan |
18 | 21 | from test_tools.fio.fio import Fio |
@@ -142,3 +145,72 @@ def test_load_x_cores_to_one_cache(cache_mode, cleaning_policy, cache_line_size, |
142 | 145 | with TestRun.step("Check if there are no error statistics."): |
143 | 146 | if cache.get_statistics().error_stats.total_errors != 0: |
144 | 147 | TestRun.fail("There are errors in the cache.") |
| 148 | + |
| 149 | +@pytest.mark.parametrize("cache_mode", CacheMode.with_traits(CacheModeTrait.LazyWrites)) |
| 150 | +@pytest.mark.parametrizex("cache_line_size", CacheLineSize) |
| 151 | +@pytest.mark.parametrizex("cleaning_policy", CleaningPolicy) |
| 152 | +@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand])) |
| 153 | +@pytest.mark.require_disk("core", DiskTypeLowerThan("cache")) |
| 154 | +def test_load_cache_dirty(cache_mode, cache_line_size, cleaning_policy): |
| 155 | + """ |
| 156 | + title: Load cache with dirty data after stopping it without flush |
| 157 | + description: | |
| 158 | + Verify that cache loads properly after being stopped with dirty data and no flush. |
| 159 | + pass_criteria: |
| 160 | + - Cache loads successfully. |
| 161 | + - There is dirty data on the cache after load. |
| 162 | + """ |
| 163 | + with TestRun.step("Prepare cache and core devices"): |
| 164 | + cache_dev = TestRun.disks['cache'] |
| 165 | + cache_dev.create_partitions([Size(512, Unit.MebiByte)]) |
| 166 | + cache_dev = cache_dev.partitions[0] |
| 167 | + core_dev = TestRun.disks['core'] |
| 168 | + core_dev.create_partitions([Size(1, Unit.GibiByte)]) |
| 169 | + core_dev = core_dev.partitions[0] |
| 170 | + |
| 171 | + with TestRun.step("Start cache and add core"): |
| 172 | + cache = casadm.start_cache(cache_dev, cache_mode, cache_line_size, force=True) |
| 173 | + core = cache.add_core(core_dev) |
| 174 | + |
| 175 | + with TestRun.step("Configure cleaning policy"): |
| 176 | + cache.set_cleaning_policy(cleaning_policy) |
| 177 | + if cleaning_policy == CleaningPolicy.alru: |
| 178 | + alru = FlushParametersAlru() |
| 179 | + alru.wake_up_time = Time(seconds=5) |
| 180 | + cache.set_params_alru(alru) |
| 181 | + if cleaning_policy == CleaningPolicy.acp: |
| 182 | + acp = FlushParametersAcp() |
| 183 | + acp.wake_up_time = Time(seconds=5) |
| 184 | + cache.set_params_acp(acp) |
| 185 | + |
| 186 | + with TestRun.step("Run FIO on exported object"): |
| 187 | + fio = (Fio().create_command() |
| 188 | + .io_engine(IoEngine.libaio) |
| 189 | + .read_write(ReadWrite.write) |
| 190 | + .block_size(cache_line_size) |
| 191 | + .io_depth(64) |
| 192 | + .direct() |
| 193 | + .sync() |
| 194 | + .size(Size(1, Unit.GibiByte)) |
| 195 | + .target(core.path) |
| 196 | + ) |
| 197 | + fio.run() |
| 198 | + |
| 199 | + with TestRun.step("Verify that cache has dirty data"): |
| 200 | + cache_stats = cache.get_statistics([StatsFilter.usage], percentage_val=True) |
| 201 | + if cache_stats.usage_stats.dirty < 0.5: |
| 202 | + TestRun.block("Ditry lower than 50%") |
| 203 | + |
| 204 | + with TestRun.step("Stop cache without flush"): |
| 205 | + cache.stop(no_data_flush=True) |
| 206 | + |
| 207 | + with TestRun.step("Load cache"): |
| 208 | + cache = casadm.load_cache(cache_dev) |
| 209 | + |
| 210 | + with TestRun.step("Verify that cache still has dirty data"): |
| 211 | + cache_stats = cache.get_statistics([StatsFilter.usage], percentage_val=True) |
| 212 | + if cache_stats.usage_stats.dirty < 0.5: |
| 213 | + TestRun.fail("Ditry lower than 50%") |
| 214 | + |
| 215 | + with TestRun.step("Stop cache"): |
| 216 | + cache.stop() |
0 commit comments