|
| 1 | +# |
| 2 | +# Copyright(c) 2023 Intel Corporation |
| 3 | +# SPDX-License-Identifier: BSD-3-Clause |
| 4 | +# |
| 5 | + |
| 6 | +import pytest |
| 7 | +from api.cas.cache_config import ( |
| 8 | + CacheLineSize, |
| 9 | + KernelParameters, |
| 10 | + UnalignedIo, |
| 11 | + UseIoScheduler, |
| 12 | +) |
| 13 | +from api.cas import casadm |
| 14 | +from api.cas.cli import standby_detach_cmd |
| 15 | +from core.test_run import TestRun |
| 16 | +from storage_devices.disk import DiskType, DiskTypeSet |
| 17 | +from test_tools.peach_fuzzer.peach_fuzzer import PeachFuzzer |
| 18 | +from tests.security.fuzzy.kernel.common.common import get_fuzz_config, run_cmd_and_validate |
| 19 | +from test_utils.size import Size, Unit |
| 20 | +from time import sleep |
| 21 | + |
| 22 | +config_file = "cache_id.yml" |
| 23 | +iterations_count = 1000 |
| 24 | + |
| 25 | + |
| 26 | +@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand])) |
| 27 | +@pytest.mark.parametrizex("cache_line_size", CacheLineSize) |
| 28 | +@pytest.mark.parametrizex("unaligned_io", UnalignedIo) |
| 29 | +@pytest.mark.parametrizex("use_io_scheduler", UseIoScheduler) |
| 30 | +def test_fuzzy_standby_detach_cache_id(cache_line_size, unaligned_io, use_io_scheduler): |
| 31 | + """ |
| 32 | + title: Fuzzy test for casadm 'standby detach' command. |
| 33 | + description: Using Peach Fuzzer check CAS ability of handling wrong cache id in |
| 34 | + 'standby detach' command. |
| 35 | + pass criteria: |
| 36 | + - System did not crash |
| 37 | + - Open CAS still works. |
| 38 | + """ |
| 39 | + |
| 40 | + with TestRun.step("Prepare CAS instance"): |
| 41 | + kernel_params = KernelParameters(unaligned_io, use_io_scheduler) |
| 42 | + cache_dev = TestRun.disks["cache"] |
| 43 | + cache_dev.create_partitions([Size(100, Unit.MebiByte)]) |
| 44 | + cache_part = cache_dev.partitions[0] |
| 45 | + cache = casadm.standby_init( |
| 46 | + cache_dev=cache_part, |
| 47 | + cache_id=1, |
| 48 | + cache_line_size=cache_line_size, |
| 49 | + kernel_params=kernel_params, |
| 50 | + force=True, |
| 51 | + ) |
| 52 | + TestRun.executor.run_expect_success("udevadm settle") |
| 53 | + |
| 54 | + with TestRun.step("Prepare Peach fuzzer to create 'standby detach' command and then run it"): |
| 55 | + valid_values = [str(cache.cache_id).encode("ascii")] |
| 56 | + PeachFuzzer.generate_config(get_fuzz_config("cache_id.yml")) |
| 57 | + base_cmd = standby_detach_cmd(cache_id="{param}").encode("ascii") |
| 58 | + commands = PeachFuzzer.get_fuzzed_command(base_cmd, iterations_count) |
| 59 | + |
| 60 | + for index, cmd in TestRun.iteration( |
| 61 | + enumerate(commands), f"Run command {iterations_count} times" |
| 62 | + ): |
| 63 | + with TestRun.step(f"Iteration {index+1}"): |
| 64 | + is_valid = cmd.param in valid_values |
| 65 | + run_cmd_and_validate(cmd, "cache_id:", is_valid) |
| 66 | + if is_valid: |
| 67 | + cache.stop() |
| 68 | + cache = casadm.standby_init( |
| 69 | + cache_dev=cache_part, |
| 70 | + cache_id=1, |
| 71 | + cache_line_size=cache_line_size, |
| 72 | + kernel_params=kernel_params, |
| 73 | + force=True, |
| 74 | + ) |
| 75 | + sleep(0.1) |
0 commit comments