Source code for tests.utils.fvp_utils

# SPDX-FileCopyrightText: <text>Copyright 2026 Arm Limited
# and/or its affiliates <open-source-office@arm.com></text>
#
# SPDX-License-Identifier: MIT


from tests.utils.common_utils import CommonUtils
from tests.utils.cpu_utils import CpuUtils
from test_automation.utils.auto_platform_base import AutoTestPlatformBase

[docs] logger = CommonUtils.get_logger(__name__)
[docs] class FvpUtils:
[docs] cpu_utils = CpuUtils()
[docs] def check_rng( self, platform_base_obj: AutoTestPlatformBase, hw_random: str, dev: str ) -> None: """ Validate RNG sysfs entry contains the expected device identifier. :param platform_base_obj: Platform fixture with console access. :param hw_random: Path to RNG sysfs node to inspect. :param dev: Expected RNG device name. :raises RuntimeError: when command execution fails on the target. """ mgr = platform_base_obj.mgr cmd = f"grep {dev} {hw_random}" mgr.run_cmd(platform_base_obj.default_console, cmd)
[docs] def check_devices( self, platform_base_obj: AutoTestPlatformBase, cls: str, min_count: int, search_drivers: list[str], ) -> None: """ Validate device class population and expected driver bindings. :param platform_base_obj: Platform fixture with console access. :param cls: Sysfs device class name. :param min_count: Minimum number of class devices expected. :param search_drivers: acceptable driver names for the class devices. :raises AssertionError: If device count is below minimum or no expected driver is found. """ # Step 1: List all devices in the given class mgr = platform_base_obj.mgr cmd = f"find /sys/class/{cls} -type l -maxdepth 1" output = mgr.run_cmd(platform_base_obj.default_console, cmd) devices = output.split() devices = [d for d in devices if d.startswith(f"/sys/class/{cls}/")] assert ( len(devices) >= min_count ), f"Expected at least {min_count} device(s) in class '{cls}', \ found {len(devices)}" logger.info(f"Available devices: {devices}") # Step 2: Extract driver names drivers = set() for device in devices: cmd = f'basename "$(readlink "{device}/device/driver")"' output = mgr.run_cmd(platform_base_obj.default_console, cmd) driver_path = output.strip() if driver_path: driver_name = driver_path.rstrip("/").split("/")[-1] logger.info(f"Device: {device}, Driver: {driver_name}") drivers.add(driver_name) logger.info(f"Detected drivers for '{cls}': {sorted(drivers)}") # Ensure that at least one device is using a supported driver. # This logic ensures test can run across different environments # such as baremetal (virtio-net) and Xen (vif) assert drivers & set(search_drivers), ( f"No '{cls}' device is using any of the expected drivers: \ {search_drivers}\n" f"Detected drivers: {sorted(drivers)}" )