diff --git a/test/functional/tests/security/fuzzy/kernel/common/common.py b/test/functional/tests/security/fuzzy/kernel/common/common.py index f485f1a..408682a 100644 --- a/test/functional/tests/security/fuzzy/kernel/common/common.py +++ b/test/functional/tests/security/fuzzy/kernel/common/common.py @@ -1,8 +1,9 @@ # # Copyright(c) 2022 Intel Corporation +# Copyright(c) 2024 Huawei Technologies # SPDX-License-Identifier: BSD-3-Clause # - +import base64 import os import posixpath from collections import namedtuple @@ -29,36 +30,38 @@ def get_device_fuzz_config(device_paths: List[str]): raise Exception("device_paths parameter cannot be empty list") device_base_config = get_fuzz_config("device.yml") - device_base_config[0]['attributes']['value'] = device_paths[0] + device_base_config[0]["attributes"]["value"] = device_paths[0] if len(device_paths) > 1: other_valid_devices = { - 'name': 'Hint', - 'attributes': { - 'name': 'ValidValues', - 'value': ';'.join(device_paths[1:]) - } + "name": "Hint", + "attributes": {"name": "ValidValues", "value": ";".join(device_paths[1:])}, } - device_base_config[0]['children'].append(other_valid_devices) + device_base_config[0]["children"].append(other_valid_devices) return device_base_config -def prepare_cas_instance(cache_device, core_device, cache_mode: CacheMode = None, - cache_line_size: CacheLineSize = None, - kernel_params: KernelParameters = KernelParameters(), - cleaning_policy: CleaningPolicy = None, mount_point: str = None, - create_partition=True): +def prepare_cas_instance( + cache_device, + core_device, + cache_mode: CacheMode = None, + cache_line_size: CacheLineSize = None, + kernel_params: KernelParameters = KernelParameters(), + cleaning_policy: CleaningPolicy = None, + mount_point: str = None, + create_partition=True, +): # Change cleaning policy to default for Write Policy different than WB if cleaning_policy: - cleaning_policy = CleaningPolicy.DEFAULT if cache_mode != CacheMode.WB \ - else cleaning_policy + cleaning_policy = CleaningPolicy.DEFAULT if cache_mode != CacheMode.WB else cleaning_policy if create_partition is True: cache_device.create_partitions([Size(400, Unit.MebiByte)]) cache_device = cache_device.partitions[0] - cache = casadm.start_cache(cache_device, cache_mode, cache_line_size, 1, True, - kernel_params=kernel_params) + cache = casadm.start_cache( + cache_device, cache_mode, cache_line_size, 1, True, kernel_params=kernel_params + ) if cleaning_policy: cache.set_cleaning_policy(cleaning_policy) @@ -73,24 +76,33 @@ def prepare_cas_instance(cache_device, core_device, cache_mode: CacheMode = None def run_cmd_and_validate(cmd, value_name: str, is_valid: bool): + cmd_prefix = b"echo " + cmd_suffix = b" | base64 --decode | sh" TestRun.LOGGER.info(f"{value_name}: {cmd.param}") TestRun.LOGGER.info(f"Command: {cmd.command}") - output = TestRun.executor.run(cmd.command) + + encoded_command = cmd_prefix + base64.b64encode(cmd.command) + cmd_suffix + + TestRun.LOGGER.info(f"Executed (encoded) command: {encoded_command}") + output = TestRun.executor.run(encoded_command) if output.exit_code == 0 and not is_valid: - TestRun.LOGGER.error(f"{cmd.param} value is not valid\n" - f"stdout: {output.stdout}\n" - f"stderr: {output.stderr}") + TestRun.LOGGER.error( + f"{cmd.param} value is not valid\n" + f"stdout: {output.stdout}\n" + f"stderr: {output.stderr}" + ) elif output.exit_code != 0 and is_valid: - TestRun.LOGGER.error(f"{cmd.param} value is valid but command returned with " - f"{output.exit_code} exit code\n" - f"stdout: {output.stdout}\n" - f"stderr: {output.stderr}") + TestRun.LOGGER.error( + f"{cmd.param} value is valid but command returned with " + f"{output.exit_code} exit code\n" + f"stdout: {output.stdout}\n" + f"stderr: {output.stderr}" + ) return output def get_cmd(command, param): - FuzzedCommand = namedtuple('Command', ['param', 'command']) - - return FuzzedCommand(param, command) + FuzzedCommand = namedtuple("Command", ["param", "command"]) + return FuzzedCommand(param, command.encode("ascii")) diff --git a/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/common/common.py b/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/common/common.py index 9432a67..91cb165 100644 --- a/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/common/common.py +++ b/test/functional/tests/security/fuzzy/kernel/fuzzy_with_io/common/common.py @@ -1,5 +1,6 @@ # # Copyright(c) 2022 Intel Corporation +# Copyright(c) 2024 Huawei Technologies # SPDX-License-Identifier: BSD-3-Clause # from datetime import timedelta @@ -8,19 +9,23 @@ from test_tools.fio.fio import Fio from test_tools.fio.fio_param import IoEngine, ReadWrite from test_utils.size import Size, Unit +mount_point = "/mnt/test" + def get_basic_workload(mount_point: str): file_min_size = Size(10, Unit.Byte).get_value() file_max_size = Size(512, Unit.KiB).get_value() - fio = (Fio() - .create_command() - .io_engine(IoEngine.libaio) - .direct() - .run_time(timedelta(days=1)) - .time_based() - .directory(mount_point) - .read_write(ReadWrite.randrw) - .nr_files(1000) - .file_size_range([(file_min_size, file_max_size)]) - .num_jobs(32)) + fio = ( + Fio() + .create_command() + .io_engine(IoEngine.libaio) + .direct() + .run_time(timedelta(days=1)) + .time_based() + .directory(mount_point) + .read_write(ReadWrite.randrw) + .nr_files(1000) + .file_size_range([(file_min_size, file_max_size)]) + .num_jobs(32) + ) return fio