diff --git a/test/functional/tests/security/fuzzy/config/prefetch_policy.yml b/test/functional/tests/security/fuzzy/config/prefetch_policy.yml new file mode 100644 index 000000000..73c41ef80 --- /dev/null +++ b/test/functional/tests/security/fuzzy/config/prefetch_policy.yml @@ -0,0 +1,10 @@ +- name: String + attributes: + name: PrefetchPolicy + value: 'readahead' + mutable: 'true' + children: + - name: Hint + attributes: + name: ValidValues + value: 'readahead;none' diff --git a/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_get_param/test_fuzzy_get_param_prefetch_cache_id.py b/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_get_param/test_fuzzy_get_param_prefetch_cache_id.py new file mode 100644 index 000000000..e3cda22ac --- /dev/null +++ b/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_get_param/test_fuzzy_get_param_prefetch_cache_id.py @@ -0,0 +1,86 @@ +# +# Copyright(c) 2026 Unvertical +# SPDX-License-Identifier: BSD-3-Clause +# + +import pytest + +from api.cas.cache_config import ( + CacheLineSize, + CacheMode, + CacheModeTrait, + KernelParameters, + UnalignedIo, + UseIoScheduler, +) +from api.cas.cli import get_param_prefetch_cmd +from core.test_run import TestRun +from storage_devices.disk import DiskType, DiskTypeLowerThan, DiskTypeSet +from test_tools.peach_fuzzer.peach_fuzzer import PeachFuzzer +from tests.security.fuzzy.kernel.common.common import ( + get_fuzz_config, + prepare_cas_instance, + run_cmd_and_validate, +) +from tests.security.fuzzy.kernel.fuzzy_with_io.common.common import ( + get_basic_workload, + mount_point, +) + + +@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand])) +@pytest.mark.require_disk("core", DiskTypeLowerThan("cache")) +@pytest.mark.parametrizex("cache_mode", CacheMode.with_traits(CacheModeTrait.LazyWrites)) +@pytest.mark.parametrizex("cache_line_size", CacheLineSize) +@pytest.mark.parametrizex("unaligned_io", UnalignedIo) +@pytest.mark.parametrizex("use_io_scheduler", UseIoScheduler) +def test_fuzzy_get_param_prefetch_cache_id( + cache_mode, cache_line_size, unaligned_io, use_io_scheduler +): + """ + title: Fuzzy test for casadm 'get parameter' command for prefetch policy – cache id. + description: | + Using Peach Fuzzer check Open CAS ability of handling wrong cache id in 'get parameter' + command for prefetch policy parameters. + pass_criteria: + - System did not crash + - Open CAS still works. + """ + with TestRun.step("Start cache and add core device"): + cache_disk = TestRun.disks["cache"] + core_disk = TestRun.disks["core"] + cache, core = prepare_cas_instance( + kernel_params=KernelParameters(unaligned_io, use_io_scheduler), + cache_device=cache_disk, + core_device=core_disk, + cache_mode=cache_mode, + cache_line_size=cache_line_size, + mount_point=mount_point, + ) + + with TestRun.step("Run FIO in background"): + fio = get_basic_workload(mount_point) + fio_pid = fio.run_in_background() + if not TestRun.executor.check_if_process_exists(fio_pid): + raise Exception("Fio is not running.") + + with TestRun.step("Using Peach Fuzzer create 'get parameter' command and run it."): + valid_values = [str(core.cache_id).encode("ascii")] + PeachFuzzer.generate_config(get_fuzz_config("cache_id.yml")) + base_cmd = get_param_prefetch_cmd(cache_id="{param}") + commands = PeachFuzzer.get_fuzzed_command( + command_template=base_cmd, count=TestRun.usr.fuzzy_iter_count + ) + + for index, cmd in TestRun.iteration( + enumerate(commands), f"Run command {TestRun.usr.fuzzy_iter_count} times" + ): + with TestRun.step(f"Iteration {index + 1}"): + if not TestRun.executor.check_if_process_exists(fio_pid): + raise Exception("Fio is not running.") + + run_cmd_and_validate( + cmd=cmd, + value_name="Cache id", + is_valid=cmd.param in valid_values, + ) diff --git a/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_get_param/test_fuzzy_get_param_prefetch_output_format.py b/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_get_param/test_fuzzy_get_param_prefetch_output_format.py new file mode 100644 index 000000000..d7fcb1647 --- /dev/null +++ b/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_get_param/test_fuzzy_get_param_prefetch_output_format.py @@ -0,0 +1,87 @@ +# +# Copyright(c) 2026 Unvertical +# SPDX-License-Identifier: BSD-3-Clause +# + +import pytest + +from api.cas.cache_config import ( + CacheLineSize, + CacheMode, + CacheModeTrait, + KernelParameters, + UnalignedIo, + UseIoScheduler, +) +from api.cas.casadm_params import OutputFormat +from api.cas.cli import get_param_prefetch_cmd +from core.test_run import TestRun +from storage_devices.disk import DiskType, DiskTypeLowerThan, DiskTypeSet +from test_tools.peach_fuzzer.peach_fuzzer import PeachFuzzer +from tests.security.fuzzy.kernel.common.common import ( + get_fuzz_config, + prepare_cas_instance, + run_cmd_and_validate, +) +from tests.security.fuzzy.kernel.fuzzy_with_io.common.common import ( + get_basic_workload, + mount_point, +) + + +@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand])) +@pytest.mark.require_disk("core", DiskTypeLowerThan("cache")) +@pytest.mark.parametrizex("cache_mode", CacheMode.with_traits(CacheModeTrait.LazyWrites)) +@pytest.mark.parametrizex("cache_line_size", CacheLineSize) +@pytest.mark.parametrizex("unaligned_io", UnalignedIo) +@pytest.mark.parametrizex("use_io_scheduler", UseIoScheduler) +def test_fuzzy_get_param_prefetch_output_format( + cache_mode, cache_line_size, unaligned_io, use_io_scheduler +): + """ + title: Fuzzy test for casadm 'get parameter' command for prefetch policy – output format. + description: | + Using Peach Fuzzer check Open CAS ability of handling wrong output format + in 'get parameter' command for prefetch policy parameters. + pass_criteria: + - System did not crash + - Open CAS still works. + """ + with TestRun.step("Start cache and add core device"): + cache_disk = TestRun.disks["cache"] + core_disk = TestRun.disks["core"] + cache, core = prepare_cas_instance( + kernel_params=KernelParameters(unaligned_io, use_io_scheduler), + cache_device=cache_disk, + core_device=core_disk, + cache_mode=cache_mode, + cache_line_size=cache_line_size, + mount_point=mount_point, + ) + + with TestRun.step("Run FIO in background"): + fio = get_basic_workload(mount_point) + fio_pid = fio.run_in_background() + if not TestRun.executor.check_if_process_exists(fio_pid): + raise Exception("Fio is not running.") + + with TestRun.step("Using Peach Fuzzer create 'get parameter' command and run it."): + valid_values = [e.name.encode("ascii") for e in list(OutputFormat)] + PeachFuzzer.generate_config(get_fuzz_config("output_format.yml")) + base_cmd = get_param_prefetch_cmd(cache_id=str(core.cache_id), output_format="{param}") + commands = PeachFuzzer.get_fuzzed_command( + command_template=base_cmd, count=TestRun.usr.fuzzy_iter_count + ) + + for index, cmd in TestRun.iteration( + enumerate(commands), f"Run command {TestRun.usr.fuzzy_iter_count} times" + ): + with TestRun.step(f"Iteration {index + 1}"): + if not TestRun.executor.check_if_process_exists(fio_pid): + raise Exception("Fio is not running.") + + run_cmd_and_validate( + cmd=cmd, + value_name="Output format", + is_valid=cmd.param in valid_values, + ) diff --git a/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_get_param/test_fuzzy_get_param_prefetch_readahead_cache_id.py b/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_get_param/test_fuzzy_get_param_prefetch_readahead_cache_id.py new file mode 100644 index 000000000..e2e7c77c4 --- /dev/null +++ b/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_get_param/test_fuzzy_get_param_prefetch_readahead_cache_id.py @@ -0,0 +1,86 @@ +# +# Copyright(c) 2026 Unvertical +# SPDX-License-Identifier: BSD-3-Clause +# + +import pytest + +from api.cas.cache_config import ( + CacheLineSize, + CacheMode, + CacheModeTrait, + KernelParameters, + UnalignedIo, + UseIoScheduler, +) +from api.cas.cli import get_param_prefetch_readahead_cmd +from core.test_run import TestRun +from storage_devices.disk import DiskType, DiskTypeLowerThan, DiskTypeSet +from test_tools.peach_fuzzer.peach_fuzzer import PeachFuzzer +from tests.security.fuzzy.kernel.common.common import ( + get_fuzz_config, + prepare_cas_instance, + run_cmd_and_validate, +) +from tests.security.fuzzy.kernel.fuzzy_with_io.common.common import ( + get_basic_workload, + mount_point, +) + + +@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand])) +@pytest.mark.require_disk("core", DiskTypeLowerThan("cache")) +@pytest.mark.parametrizex("cache_mode", CacheMode.with_traits(CacheModeTrait.LazyWrites)) +@pytest.mark.parametrizex("cache_line_size", CacheLineSize) +@pytest.mark.parametrizex("unaligned_io", UnalignedIo) +@pytest.mark.parametrizex("use_io_scheduler", UseIoScheduler) +def test_fuzzy_get_param_prefetch_readahead_cache_id( + cache_mode, cache_line_size, unaligned_io, use_io_scheduler +): + """ + title: Fuzzy test for casadm 'get parameter' command for prefetch readahead – cache id. + description: | + Using Peach Fuzzer check Open CAS ability of handling wrong cache id in 'get parameter' + command for prefetch readahead parameters. + pass_criteria: + - System did not crash + - Open CAS still works. + """ + with TestRun.step("Start cache and add core device"): + cache_disk = TestRun.disks["cache"] + core_disk = TestRun.disks["core"] + cache, core = prepare_cas_instance( + kernel_params=KernelParameters(unaligned_io, use_io_scheduler), + cache_device=cache_disk, + core_device=core_disk, + cache_mode=cache_mode, + cache_line_size=cache_line_size, + mount_point=mount_point, + ) + + with TestRun.step("Run FIO in background"): + fio = get_basic_workload(mount_point) + fio_pid = fio.run_in_background() + if not TestRun.executor.check_if_process_exists(fio_pid): + raise Exception("Fio is not running.") + + with TestRun.step("Using Peach Fuzzer create 'get parameter' command and run it."): + valid_values = [str(core.cache_id).encode("ascii")] + PeachFuzzer.generate_config(get_fuzz_config("cache_id.yml")) + base_cmd = get_param_prefetch_readahead_cmd(cache_id="{param}") + commands = PeachFuzzer.get_fuzzed_command( + command_template=base_cmd, count=TestRun.usr.fuzzy_iter_count + ) + + for index, cmd in TestRun.iteration( + enumerate(commands), f"Run command {TestRun.usr.fuzzy_iter_count} times" + ): + with TestRun.step(f"Iteration {index + 1}"): + if not TestRun.executor.check_if_process_exists(fio_pid): + raise Exception("Fio is not running.") + + run_cmd_and_validate( + cmd=cmd, + value_name="Cache id", + is_valid=cmd.param in valid_values, + ) diff --git a/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_get_param/test_fuzzy_get_param_prefetch_readahead_output_format.py b/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_get_param/test_fuzzy_get_param_prefetch_readahead_output_format.py new file mode 100644 index 000000000..3f9841014 --- /dev/null +++ b/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_get_param/test_fuzzy_get_param_prefetch_readahead_output_format.py @@ -0,0 +1,89 @@ +# +# Copyright(c) 2026 Unvertical +# SPDX-License-Identifier: BSD-3-Clause +# + +import pytest + +from api.cas.cache_config import ( + CacheLineSize, + CacheMode, + CacheModeTrait, + KernelParameters, + UnalignedIo, + UseIoScheduler, +) +from api.cas.casadm_params import OutputFormat +from api.cas.cli import get_param_prefetch_readahead_cmd +from core.test_run import TestRun +from storage_devices.disk import DiskType, DiskTypeLowerThan, DiskTypeSet +from test_tools.peach_fuzzer.peach_fuzzer import PeachFuzzer +from tests.security.fuzzy.kernel.common.common import ( + get_fuzz_config, + prepare_cas_instance, + run_cmd_and_validate, +) +from tests.security.fuzzy.kernel.fuzzy_with_io.common.common import ( + get_basic_workload, + mount_point, +) + + +@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand])) +@pytest.mark.require_disk("core", DiskTypeLowerThan("cache")) +@pytest.mark.parametrizex("cache_mode", CacheMode.with_traits(CacheModeTrait.LazyWrites)) +@pytest.mark.parametrizex("cache_line_size", CacheLineSize) +@pytest.mark.parametrizex("unaligned_io", UnalignedIo) +@pytest.mark.parametrizex("use_io_scheduler", UseIoScheduler) +def test_fuzzy_get_param_prefetch_readahead_output_format( + cache_mode, cache_line_size, unaligned_io, use_io_scheduler +): + """ + title: Fuzzy test for casadm 'get parameter' command for prefetch readahead – output format. + description: | + Using Peach Fuzzer check Open CAS ability of handling wrong output format + in 'get parameter' command for prefetch readahead parameters. + pass_criteria: + - System did not crash + - Open CAS still works. + """ + with TestRun.step("Start cache and add core device"): + cache_disk = TestRun.disks["cache"] + core_disk = TestRun.disks["core"] + cache, core = prepare_cas_instance( + kernel_params=KernelParameters(unaligned_io, use_io_scheduler), + cache_device=cache_disk, + core_device=core_disk, + cache_mode=cache_mode, + cache_line_size=cache_line_size, + mount_point=mount_point, + ) + + with TestRun.step("Run FIO in background"): + fio = get_basic_workload(mount_point) + fio_pid = fio.run_in_background() + if not TestRun.executor.check_if_process_exists(fio_pid): + raise Exception("Fio is not running.") + + with TestRun.step("Using Peach Fuzzer create 'get parameter' command and run it."): + valid_values = [e.name.encode("ascii") for e in list(OutputFormat)] + PeachFuzzer.generate_config(get_fuzz_config("output_format.yml")) + base_cmd = get_param_prefetch_readahead_cmd( + cache_id=str(core.cache_id), output_format="{param}" + ) + commands = PeachFuzzer.get_fuzzed_command( + command_template=base_cmd, count=TestRun.usr.fuzzy_iter_count + ) + + for index, cmd in TestRun.iteration( + enumerate(commands), f"Run command {TestRun.usr.fuzzy_iter_count} times" + ): + with TestRun.step(f"Iteration {index + 1}"): + if not TestRun.executor.check_if_process_exists(fio_pid): + raise Exception("Fio is not running.") + + run_cmd_and_validate( + cmd=cmd, + value_name="Output format", + is_valid=cmd.param in valid_values, + ) diff --git a/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_set_param/test_fuzzy_set_param_prefetch_cache_id.py b/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_set_param/test_fuzzy_set_param_prefetch_cache_id.py new file mode 100644 index 000000000..c5a103f2b --- /dev/null +++ b/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_set_param/test_fuzzy_set_param_prefetch_cache_id.py @@ -0,0 +1,90 @@ +# +# Copyright(c) 2026 Unvertical +# SPDX-License-Identifier: BSD-3-Clause +# + +import pytest + +from api.cas.cache_config import ( + CacheLineSize, + CacheMode, + CacheModeTrait, + KernelParameters, + PrefetchPolicy, + UnalignedIo, + UseIoScheduler, +) +from api.cas.cli import set_param_prefetch_cmd +from core.test_run import TestRun +from storage_devices.disk import DiskType, DiskTypeLowerThan, DiskTypeSet +from test_tools.peach_fuzzer.peach_fuzzer import PeachFuzzer +from tests.security.fuzzy.kernel.common.common import ( + get_fuzz_config, + prepare_cas_instance, + run_cmd_and_validate, +) +from tests.security.fuzzy.kernel.fuzzy_with_io.common.common import ( + get_basic_workload, + mount_point, +) + + +@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand])) +@pytest.mark.require_disk("core", DiskTypeLowerThan("cache")) +@pytest.mark.parametrizex("cache_mode", CacheMode.with_traits(CacheModeTrait.LazyWrites)) +@pytest.mark.parametrizex("cache_line_size", CacheLineSize) +@pytest.mark.parametrizex("unaligned_io", UnalignedIo) +@pytest.mark.parametrizex("use_io_scheduler", UseIoScheduler) +def test_fuzzy_set_param_prefetch_cache_id( + cache_mode, cache_line_size, unaligned_io, use_io_scheduler +): + """ + title: Fuzzy test for casadm 'set parameter' command for prefetch – cache id. + description: | + Using Peach Fuzzer check Open CAS ability of handling wrong cache id in 'set parameter' + command for prefetch parameters. + pass_criteria: + - System did not crash + - Open CAS still works. + """ + with TestRun.step("Start cache and add core device"): + cache_disk = TestRun.disks["cache"] + core_disk = TestRun.disks["core"] + cache, core = prepare_cas_instance( + kernel_params=KernelParameters(unaligned_io, use_io_scheduler), + cache_device=cache_disk, + core_device=core_disk, + cache_mode=cache_mode, + cache_line_size=cache_line_size, + mount_point=mount_point, + ) + + with TestRun.step("Run FIO in background"): + fio = get_basic_workload(mount_point) + fio_pid = fio.run_in_background() + if not TestRun.executor.check_if_process_exists(fio_pid): + raise Exception("Fio is not running.") + + with TestRun.step("Using Peach Fuzzer create 'set parameter' command and run it."): + valid_values = [str(core.cache_id).encode("ascii")] + PeachFuzzer.generate_config(get_fuzz_config("cache_id.yml")) + base_cmd = set_param_prefetch_cmd( + cache_id="{param}", + policy=str(PrefetchPolicy.DEFAULT), + ) + commands = PeachFuzzer.get_fuzzed_command( + command_template=base_cmd, count=TestRun.usr.fuzzy_iter_count + ) + + for index, cmd in TestRun.iteration( + enumerate(commands), f"Run command {TestRun.usr.fuzzy_iter_count} times" + ): + with TestRun.step(f"Iteration {index + 1}"): + if not TestRun.executor.check_if_process_exists(fio_pid): + raise Exception("Fio is not running.") + + run_cmd_and_validate( + cmd=cmd, + value_name="Cache id", + is_valid=cmd.param in valid_values, + ) diff --git a/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_set_param/test_fuzzy_set_param_prefetch_policy.py b/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_set_param/test_fuzzy_set_param_prefetch_policy.py new file mode 100644 index 000000000..bd43b8d08 --- /dev/null +++ b/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_set_param/test_fuzzy_set_param_prefetch_policy.py @@ -0,0 +1,90 @@ +# +# Copyright(c) 2026 Unvertical +# SPDX-License-Identifier: BSD-3-Clause +# + +import pytest + +from api.cas.cache_config import ( + CacheLineSize, + CacheMode, + CacheModeTrait, + KernelParameters, + PrefetchPolicy, + UnalignedIo, + UseIoScheduler, +) +from api.cas.cli import set_param_prefetch_cmd +from core.test_run import TestRun +from storage_devices.disk import DiskType, DiskTypeLowerThan, DiskTypeSet +from test_tools.peach_fuzzer.peach_fuzzer import PeachFuzzer +from tests.security.fuzzy.kernel.common.common import ( + get_fuzz_config, + prepare_cas_instance, + run_cmd_and_validate, +) +from tests.security.fuzzy.kernel.fuzzy_with_io.common.common import ( + get_basic_workload, + mount_point, +) + + +@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand])) +@pytest.mark.require_disk("core", DiskTypeLowerThan("cache")) +@pytest.mark.parametrizex("cache_mode", CacheMode.with_traits(CacheModeTrait.LazyWrites)) +@pytest.mark.parametrizex("cache_line_size", CacheLineSize) +@pytest.mark.parametrizex("unaligned_io", UnalignedIo) +@pytest.mark.parametrizex("use_io_scheduler", UseIoScheduler) +def test_fuzzy_set_param_prefetch_policy( + cache_mode, cache_line_size, unaligned_io, use_io_scheduler +): + """ + title: Fuzzy test for casadm 'set parameter' command for prefetch – policy. + description: | + Using Peach Fuzzer check Open CAS ability of handling wrong prefetch policy in + 'set parameter' command for prefetch parameters. + pass_criteria: + - System did not crash + - Open CAS still works. + """ + with TestRun.step("Start cache and add core device"): + cache_disk = TestRun.disks["cache"] + core_disk = TestRun.disks["core"] + cache, core = prepare_cas_instance( + kernel_params=KernelParameters(unaligned_io, use_io_scheduler), + cache_device=cache_disk, + core_device=core_disk, + cache_mode=cache_mode, + cache_line_size=cache_line_size, + mount_point=mount_point, + ) + + with TestRun.step("Run FIO in background"): + fio = get_basic_workload(mount_point) + fio_pid = fio.run_in_background() + if not TestRun.executor.check_if_process_exists(fio_pid): + raise Exception("Fio is not running.") + + with TestRun.step("Using Peach Fuzzer create 'set parameter' command and run it."): + valid_values = [str(PrefetchPolicy.none).encode("ascii")] + valid_values += [ + str(policy).encode("ascii") for policy in PrefetchPolicy if policy.value + ] + PeachFuzzer.generate_config(get_fuzz_config("prefetch_policy.yml")) + base_cmd = set_param_prefetch_cmd(cache_id=str(core.cache_id), policy="{param}") + commands = PeachFuzzer.get_fuzzed_command( + command_template=base_cmd, count=TestRun.usr.fuzzy_iter_count + ) + + for index, cmd in TestRun.iteration( + enumerate(commands), f"Run command {TestRun.usr.fuzzy_iter_count} times" + ): + with TestRun.step(f"Iteration {index + 1}"): + if not TestRun.executor.check_if_process_exists(fio_pid): + raise Exception("Fio is not running.") + + run_cmd_and_validate( + cmd=cmd, + value_name="Policy", + is_valid=cmd.param in valid_values, + ) diff --git a/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_set_param/test_fuzzy_set_param_prefetch_readahead_cache_id.py b/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_set_param/test_fuzzy_set_param_prefetch_readahead_cache_id.py new file mode 100644 index 000000000..62b2ae4db --- /dev/null +++ b/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_set_param/test_fuzzy_set_param_prefetch_readahead_cache_id.py @@ -0,0 +1,92 @@ +# +# Copyright(c) 2026 Unvertical +# SPDX-License-Identifier: BSD-3-Clause +# + +import pytest + +from api.cas.cache_config import ( + CacheLineSize, + CacheMode, + CacheModeTrait, + KernelParameters, + PrefetchParametersReadahead, + UnalignedIo, + UseIoScheduler, +) +from api.cas.cli import set_param_prefetch_readahead_cmd +from core.test_run import TestRun +from storage_devices.disk import DiskType, DiskTypeLowerThan, DiskTypeSet +from test_tools.peach_fuzzer.peach_fuzzer import PeachFuzzer +from tests.security.fuzzy.kernel.common.common import ( + get_fuzz_config, + prepare_cas_instance, + run_cmd_and_validate, +) +from tests.security.fuzzy.kernel.fuzzy_with_io.common.common import ( + get_basic_workload, + mount_point, +) +from type_def.size import Unit + + +@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand])) +@pytest.mark.require_disk("core", DiskTypeLowerThan("cache")) +@pytest.mark.parametrizex("cache_mode", CacheMode.with_traits(CacheModeTrait.LazyWrites)) +@pytest.mark.parametrizex("cache_line_size", CacheLineSize) +@pytest.mark.parametrizex("unaligned_io", UnalignedIo) +@pytest.mark.parametrizex("use_io_scheduler", UseIoScheduler) +def test_fuzzy_set_param_prefetch_readahead_cache_id( + cache_mode, cache_line_size, unaligned_io, use_io_scheduler +): + """ + title: Fuzzy test for casadm 'set parameter' command for prefetch readahead – cache id. + description: | + Using Peach Fuzzer check Open CAS ability of handling wrong cache id in 'set parameter' + command for prefetch readahead parameters. + pass_criteria: + - System did not crash + - Open CAS still works. + """ + with TestRun.step("Start cache and add core device"): + cache_disk = TestRun.disks["cache"] + core_disk = TestRun.disks["core"] + cache, core = prepare_cas_instance( + kernel_params=KernelParameters(unaligned_io, use_io_scheduler), + cache_device=cache_disk, + core_device=core_disk, + cache_mode=cache_mode, + cache_line_size=cache_line_size, + mount_point=mount_point, + ) + + with TestRun.step("Run FIO in background"): + fio = get_basic_workload(mount_point) + fio_pid = fio.run_in_background() + if not TestRun.executor.check_if_process_exists(fio_pid): + raise Exception("Fio is not running.") + + with TestRun.step("Using Peach Fuzzer create 'set parameter' command and run it."): + valid_values = [str(core.cache_id).encode("ascii")] + default_threshold = PrefetchParametersReadahead.default_readahead_params().threshold + PeachFuzzer.generate_config(get_fuzz_config("cache_id.yml")) + base_cmd = set_param_prefetch_readahead_cmd( + cache_id="{param}", + threshold=str(int(default_threshold.get_value(Unit.KibiByte))), + ) + commands = PeachFuzzer.get_fuzzed_command( + command_template=base_cmd, count=TestRun.usr.fuzzy_iter_count + ) + + for index, cmd in TestRun.iteration( + enumerate(commands), f"Run command {TestRun.usr.fuzzy_iter_count} times" + ): + with TestRun.step(f"Iteration {index + 1}"): + if not TestRun.executor.check_if_process_exists(fio_pid): + raise Exception("Fio is not running.") + + run_cmd_and_validate( + cmd=cmd, + value_name="Cache id", + is_valid=cmd.param in valid_values, + ) diff --git a/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_set_param/test_fuzzy_set_param_prefetch_readahead_threshold.py b/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_set_param/test_fuzzy_set_param_prefetch_readahead_threshold.py new file mode 100644 index 000000000..c1e151c6b --- /dev/null +++ b/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/fuzzy_set_param/test_fuzzy_set_param_prefetch_readahead_threshold.py @@ -0,0 +1,99 @@ +# +# Copyright(c) 2026 Unvertical +# SPDX-License-Identifier: BSD-3-Clause +# + +import pytest + +from api.cas.cache_config import ( + CacheLineSize, + CacheMode, + CacheModeTrait, + KernelParameters, + PrefetchParametersReadahead, + UnalignedIo, + UseIoScheduler, +) +from api.cas.cli import set_param_prefetch_readahead_cmd +from core.test_run import TestRun +from storage_devices.disk import DiskType, DiskTypeLowerThan, DiskTypeSet +from test_tools.peach_fuzzer.peach_fuzzer import PeachFuzzer +from tests.security.fuzzy.kernel.common.common import ( + get_fuzz_config, + prepare_cas_instance, + run_cmd_and_validate, +) +from tests.security.fuzzy.kernel.fuzzy_with_io.common.common import ( + get_basic_workload, + mount_point, +) + +threshold_min, threshold_max = PrefetchParametersReadahead.readahead_params_range().threshold + + +@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand])) +@pytest.mark.require_disk("core", DiskTypeLowerThan("cache")) +@pytest.mark.parametrizex("cache_mode", CacheMode.with_traits(CacheModeTrait.LazyWrites)) +@pytest.mark.parametrizex("cache_line_size", CacheLineSize) +@pytest.mark.parametrizex("unaligned_io", UnalignedIo) +@pytest.mark.parametrizex("use_io_scheduler", UseIoScheduler) +def test_fuzzy_set_param_prefetch_readahead_threshold( + cache_mode, cache_line_size, unaligned_io, use_io_scheduler +): + """ + title: Fuzzy test for casadm 'set parameter' command for prefetch readahead – threshold. + description: | + Using Peach Fuzzer check Open CAS ability of handling wrong threshold value in + 'set parameter' command for prefetch readahead parameters. + pass_criteria: + - System did not crash + - Open CAS still works. + """ + with TestRun.step("Start cache and add core device"): + cache_disk = TestRun.disks["cache"] + core_disk = TestRun.disks["core"] + cache, core = prepare_cas_instance( + kernel_params=KernelParameters(unaligned_io, use_io_scheduler), + cache_device=cache_disk, + core_device=core_disk, + cache_mode=cache_mode, + cache_line_size=cache_line_size, + mount_point=mount_point, + ) + + with TestRun.step("Run FIO in background"): + fio = get_basic_workload(mount_point) + fio_pid = fio.run_in_background() + if not TestRun.executor.check_if_process_exists(fio_pid): + raise Exception("Fio is not running.") + + with TestRun.step("Using Peach Fuzzer create 'set parameter' command and run it."): + PeachFuzzer.generate_config(get_fuzz_config("uint.yml")) + base_cmd = set_param_prefetch_readahead_cmd( + cache_id=str(core.cache_id), + threshold="{param}", + ) + commands = PeachFuzzer.get_fuzzed_command( + command_template=base_cmd, count=TestRun.usr.fuzzy_iter_count + ) + + for index, cmd in TestRun.iteration( + enumerate(commands), f"Run command {TestRun.usr.fuzzy_iter_count} times" + ): + with TestRun.step(f"Iteration {index + 1}"): + if not TestRun.executor.check_if_process_exists(fio_pid): + raise Exception("Fio is not running.") + + run_cmd_and_validate( + cmd=cmd, + value_name="Threshold", + is_valid=__is_valid(cmd.param), + ) + + +def __is_valid(parameter): + try: + value = int(parameter) + except ValueError: + return False + return threshold_min <= value <= threshold_max