Refactor common fuzzy files
Signed-off-by: Katarzyna Treder <katarzyna.treder@h-partners.com>
This commit is contained in:
parent
d324f541a1
commit
619a6c8e2a
@ -1,8 +1,9 @@
|
|||||||
#
|
#
|
||||||
# Copyright(c) 2022 Intel Corporation
|
# Copyright(c) 2022 Intel Corporation
|
||||||
|
# Copyright(c) 2024 Huawei Technologies
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
import base64
|
||||||
import os
|
import os
|
||||||
import posixpath
|
import posixpath
|
||||||
from collections import namedtuple
|
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")
|
raise Exception("device_paths parameter cannot be empty list")
|
||||||
|
|
||||||
device_base_config = get_fuzz_config("device.yml")
|
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:
|
if len(device_paths) > 1:
|
||||||
other_valid_devices = {
|
other_valid_devices = {
|
||||||
'name': 'Hint',
|
"name": "Hint",
|
||||||
'attributes': {
|
"attributes": {"name": "ValidValues", "value": ";".join(device_paths[1:])},
|
||||||
'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
|
return device_base_config
|
||||||
|
|
||||||
|
|
||||||
def prepare_cas_instance(cache_device, core_device, cache_mode: CacheMode = None,
|
def prepare_cas_instance(
|
||||||
cache_line_size: CacheLineSize = None,
|
cache_device,
|
||||||
kernel_params: KernelParameters = KernelParameters(),
|
core_device,
|
||||||
cleaning_policy: CleaningPolicy = None, mount_point: str = None,
|
cache_mode: CacheMode = None,
|
||||||
create_partition=True):
|
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
|
# Change cleaning policy to default for Write Policy different than WB
|
||||||
if cleaning_policy:
|
if cleaning_policy:
|
||||||
cleaning_policy = CleaningPolicy.DEFAULT if cache_mode != CacheMode.WB \
|
cleaning_policy = CleaningPolicy.DEFAULT if cache_mode != CacheMode.WB else cleaning_policy
|
||||||
else cleaning_policy
|
|
||||||
|
|
||||||
if create_partition is True:
|
if create_partition is True:
|
||||||
cache_device.create_partitions([Size(400, Unit.MebiByte)])
|
cache_device.create_partitions([Size(400, Unit.MebiByte)])
|
||||||
cache_device = cache_device.partitions[0]
|
cache_device = cache_device.partitions[0]
|
||||||
|
|
||||||
cache = casadm.start_cache(cache_device, cache_mode, cache_line_size, 1, True,
|
cache = casadm.start_cache(
|
||||||
kernel_params=kernel_params)
|
cache_device, cache_mode, cache_line_size, 1, True, kernel_params=kernel_params
|
||||||
|
)
|
||||||
if cleaning_policy:
|
if cleaning_policy:
|
||||||
cache.set_cleaning_policy(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):
|
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"{value_name}: {cmd.param}")
|
||||||
TestRun.LOGGER.info(f"Command: {cmd.command}")
|
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:
|
if output.exit_code == 0 and not is_valid:
|
||||||
TestRun.LOGGER.error(f"{cmd.param} value is not valid\n"
|
TestRun.LOGGER.error(
|
||||||
f"stdout: {output.stdout}\n"
|
f"{cmd.param} value is not valid\n"
|
||||||
f"stderr: {output.stderr}")
|
f"stdout: {output.stdout}\n"
|
||||||
|
f"stderr: {output.stderr}"
|
||||||
|
)
|
||||||
elif output.exit_code != 0 and is_valid:
|
elif output.exit_code != 0 and is_valid:
|
||||||
TestRun.LOGGER.error(f"{cmd.param} value is valid but command returned with "
|
TestRun.LOGGER.error(
|
||||||
f"{output.exit_code} exit code\n"
|
f"{cmd.param} value is valid but command returned with "
|
||||||
f"stdout: {output.stdout}\n"
|
f"{output.exit_code} exit code\n"
|
||||||
f"stderr: {output.stderr}")
|
f"stdout: {output.stdout}\n"
|
||||||
|
f"stderr: {output.stderr}"
|
||||||
|
)
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
def get_cmd(command, param):
|
def get_cmd(command, param):
|
||||||
FuzzedCommand = namedtuple('Command', ['param', 'command'])
|
FuzzedCommand = namedtuple("Command", ["param", "command"])
|
||||||
|
return FuzzedCommand(param, command.encode("ascii"))
|
||||||
return FuzzedCommand(param, command)
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#
|
#
|
||||||
# Copyright(c) 2022 Intel Corporation
|
# Copyright(c) 2022 Intel Corporation
|
||||||
|
# Copyright(c) 2024 Huawei Technologies
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
from datetime import timedelta
|
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_tools.fio.fio_param import IoEngine, ReadWrite
|
||||||
from test_utils.size import Size, Unit
|
from test_utils.size import Size, Unit
|
||||||
|
|
||||||
|
mount_point = "/mnt/test"
|
||||||
|
|
||||||
|
|
||||||
def get_basic_workload(mount_point: str):
|
def get_basic_workload(mount_point: str):
|
||||||
file_min_size = Size(10, Unit.Byte).get_value()
|
file_min_size = Size(10, Unit.Byte).get_value()
|
||||||
file_max_size = Size(512, Unit.KiB).get_value()
|
file_max_size = Size(512, Unit.KiB).get_value()
|
||||||
fio = (Fio()
|
fio = (
|
||||||
.create_command()
|
Fio()
|
||||||
.io_engine(IoEngine.libaio)
|
.create_command()
|
||||||
.direct()
|
.io_engine(IoEngine.libaio)
|
||||||
.run_time(timedelta(days=1))
|
.direct()
|
||||||
.time_based()
|
.run_time(timedelta(days=1))
|
||||||
.directory(mount_point)
|
.time_based()
|
||||||
.read_write(ReadWrite.randrw)
|
.directory(mount_point)
|
||||||
.nr_files(1000)
|
.read_write(ReadWrite.randrw)
|
||||||
.file_size_range([(file_min_size, file_max_size)])
|
.nr_files(1000)
|
||||||
.num_jobs(32))
|
.file_size_range([(file_min_size, file_max_size)])
|
||||||
|
.num_jobs(32)
|
||||||
|
)
|
||||||
return fio
|
return fio
|
||||||
|
Loading…
Reference in New Issue
Block a user