test-api: Change Cache init to force use of the cache_id instead of cache_device

Signed-off-by: Kamil Gierszewski <kamil.gierszewski@huawei.com>
This commit is contained in:
Kamil Gierszewski 2025-01-02 02:14:04 +01:00
parent 9fb333a73f
commit 0f645ac10b
No known key found for this signature in database

View File

@ -13,24 +13,26 @@ from test_tools.os_tools import sync
class Cache: class Cache:
def __init__(self, device: Device, cache_id: int = None) -> None: def __init__(
self.cache_device = device self, cache_id: int, device: Device = None, cache_line_size: CacheLineSize = None
self.cache_id = cache_id if cache_id else self.__get_cache_id() ) -> None:
self.__cache_line_size = None self.cache_id = cache_id
self.cache_device = device if device else self.__get_cache_device()
def __get_cache_id(self) -> int: self.__cache_line_size = cache_line_size
device_path = self.__get_cache_device_path()
def __get_cache_device(self) -> Device | None:
caches_dict = get_cas_devices_dict()["caches"] caches_dict = get_cas_devices_dict()["caches"]
cache = next(
iter([cache for cache in caches_dict.values() if cache["id"] == self.cache_id])
)
for cache in caches_dict.values(): if not cache:
if cache["device_path"] == device_path: return None
return int(cache["id"])
raise Exception(f"There is no cache started on {device_path}") if cache["device_path"] is "-":
return None
def __get_cache_device_path(self) -> str: return Device(path=cache["device_path"])
return self.cache_device.path if self.cache_device is not None else "-"
def get_core_devices(self) -> list: def get_core_devices(self) -> list:
return get_cores(self.cache_id) return get_cores(self.cache_id)