Skip to content

Commit 0502b9a

Browse files
committed
[tests] Fuzzy test for added flag
Signed-off-by: Daniel Madej <[email protected]>
1 parent 15119ed commit 0502b9a

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#
2+
# Copyright(c) 2025 Huawei Technologies Co., Ltd.
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
#
5+
6+
import pytest
7+
8+
from api.cas.cache_config import (
9+
CacheMode,
10+
CacheLineSize,
11+
CleaningPolicy,
12+
UnalignedIo,
13+
KernelParameters,
14+
UseIoScheduler,
15+
)
16+
from api.cas.cli import load_io_classes_cmd
17+
from core.test_run import TestRun
18+
from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan
19+
from test_tools.peach_fuzzer.peach_fuzzer import PeachFuzzer
20+
from tests.security.fuzzy.kernel.common.common import (
21+
prepare_cas_instance,
22+
get_fuzz_config,
23+
run_cmd_and_validate,
24+
)
25+
from tests.security.fuzzy.kernel.fuzzy_with_io.common.common import (
26+
get_basic_workload,
27+
mount_point,
28+
)
29+
30+
31+
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
32+
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
33+
@pytest.mark.parametrizex("cache_mode", CacheMode)
34+
@pytest.mark.parametrizex("cache_line_size", CacheLineSize)
35+
@pytest.mark.parametrizex("cleaning_policy", CleaningPolicy)
36+
@pytest.mark.parametrizex("unaligned_io", UnalignedIo)
37+
@pytest.mark.parametrizex("use_io_scheduler", UseIoScheduler)
38+
def test_fuzzy_io_class_load_config_flags(
39+
cache_mode, cache_line_size, cleaning_policy, unaligned_io, use_io_scheduler
40+
):
41+
"""
42+
title: Fuzzy test for casadm 'load IO class configuration' command – flags.
43+
description: |
44+
Using Peach Fuzzer check Open CAS ability of handling wrong flags in
45+
'load IO class configuration' command.
46+
pass_criteria:
47+
- System did not crash
48+
- Open CAS still works.
49+
"""
50+
with TestRun.step(
51+
"Start cache with configuration and add core device, make filesystem and mount it"
52+
):
53+
cache_disk = TestRun.disks["cache"]
54+
core_disk = TestRun.disks["core"]
55+
cache, core = prepare_cas_instance(
56+
cache_device=cache_disk,
57+
core_device=core_disk,
58+
cache_mode=cache_mode,
59+
cache_line_size=cache_line_size,
60+
kernel_params=KernelParameters(unaligned_io, use_io_scheduler),
61+
cleaning_policy=cleaning_policy,
62+
mount_point=mount_point,
63+
)
64+
65+
with TestRun.step("Run fio in background"):
66+
fio = get_basic_workload(mount_point)
67+
fio_pid = fio.run_in_background()
68+
if not TestRun.executor.check_if_process_exists(fio_pid):
69+
raise Exception("Fio is not running.")
70+
71+
with TestRun.step("Prepare PeachFuzzer"):
72+
valid_values = ["", "-k", "--keep-classification"]
73+
valid_values = [v.encode("ascii") for v in valid_values]
74+
PeachFuzzer.generate_config(get_fuzz_config("flags.yml"))
75+
base_cmd = load_io_classes_cmd(cache_id=str(cache.cache_id), file="/etc/opencas/ioclass-config.csv") + " {param}"
76+
commands = PeachFuzzer.get_fuzzed_command(
77+
command_template=base_cmd, count=TestRun.usr.fuzzy_iter_count
78+
)
79+
80+
for index, cmd in TestRun.iteration(
81+
enumerate(commands), f"Run command {TestRun.usr.fuzzy_iter_count} times"
82+
):
83+
with TestRun.step(f"Iteration {index + 1}"):
84+
if not TestRun.executor.check_if_process_exists(fio_pid):
85+
raise Exception("Fio is not running.")
86+
87+
run_cmd_and_validate(
88+
cmd=cmd,
89+
value_name="Flag",
90+
is_valid=cmd.param in valid_values,
91+
)

0 commit comments

Comments
 (0)