2.1.2.1.2. tests.utils.cpu_utils
2.1.2.1.2.1. Classes
Utility class for CPU-related operations. |
2.1.2.1.2.2. Module Contents
- class tests.utils.cpu_utils.CpuUtils[source]
Utility class for CPU-related operations.
- static get_clusters_and_cores(cpu_count, cores_per_cluster)[source]
Return a mapping of cluster IDs to lists of core IDs.
- Parameters:
cpu_count (int) – Total number of CPUs.
cores_per_cluster (int) – Number of cores per cluster.
- Returns:
Mapping
cluster_id -> [core_id, ...].- Return type:
Dict[int, List[int]]
- static get_cpu_index(cluster_id, core_id, cores_per_cluster)[source]
Compute a global CPU index from cluster and core IDs.
- Parameters:
cluster_id (int) – Cluster identifier.
core_id (int) – Core identifier within the cluster.
cores_per_cluster (int) – Number of cores per cluster.
- Returns:
Global CPU index.
- Return type:
int
- _list_state_dirs(mgr, port, cpu, cpu_sysfs)[source]
List cpuidle state directories for a given CPU.
- Parameters:
cpu (int) – CPU index to list states for.
cpu_sysfs (str) – Base sysfs path for CPU information.
- Returns:
Mapping of state names to their sysfs paths.
- Return type:
Dict[str, str]
- _load_states_per_cpu(platform_base_obj, names, cpu_sysfs)[source]
Load cpuidle states for each CPU.
- Parameters:
platform_base_obj – Object containing configuration and manager.
names – List of state names to load.
cpu_sysfs – Base sysfs path for CPU information.
- Returns:
Mapping of CPU indices to their cpuidle states.
- Return type:
Dict[int, Dict[str, str]]
- _check_default_status_for_state(mgr, port, cpu, state_id, states)[source]
Check the default status for a given cpuidle state on a specific CPU.
- Parameters:
mgr – Manager object for executing commands.
port – Port identifier for command execution.
cpu (int) – CPU index to check.
state_id (str) – Identifier of the cpuidle state to check.
states (Dict[str, str]) – Mapping of state names to their sysfs paths for the CPU.
- _validate_required_files(mgr, port, *paths)[source]
Validate that required cpuidle files exist.
- Parameters:
mgr – Manager object for executing commands.
port – Port identifier for command execution.
paths (str) – List of file paths to validate.
- Returns:
None
- Return type:
None
- _verify_usage_increases(mgr, port, usage_path, cpu, state_id, time_short=60)[source]
Verify that the usage count increases over a short period.
- Parameters:
mgr – Manager object for executing commands.
port – Port identifier for command execution.
usage_path (str) – Path to the usage file for the state.
cpu (int) – CPU index to check.
state_id (str) – Identifier of the cpuidle state to check.
time_short (int) – Time to wait between checks in seconds.
- Returns:
None
- _disable_state(mgr, port, disable_path, cpu, state_id, original_disable_values)[source]
Disable a specific cpuidle state for a given CPU.
- Parameters:
mgr – Manager object for executing commands.
port – Port identifier for command execution.
disable_path (str) – Path to the disable file for the state.
cpu (int) – CPU index to disable the state on.
state_id (str) – Identifier of the cpuidle state to disable.
original_disable_values (Dict[int, Dict[str, str]]) – Dictionary to store original disable values for restoration.
- _verify_usage_stays_same_when_disabled(mgr, port, usage_path, cpu, state_id, time_short=60)[source]
Verify that the usage count does not change when the state is disabled.
- Parameters:
mgr – Manager object for executing commands.
port – Port identifier for command execution.
usage_path (str) – Path to the usage file for the state.
cpu (int) – CPU index to check.
state_id (str) – Identifier of the cpuidle state to check.
time_short (int) – Time to wait between checks in seconds.
- _verify_latency_residency_values(mgr, port, base, props, cpu, state_id)[source]
Verify latency and residency values for a specific C-state on a CPU.
- Parameters:
mgr – Manager object for executing commands.
port – Port identifier for command execution.
base (str) – Base sysfs path for the C-state.
props (Dict[str, int]) – Expected properties containing ‘latency’ and ‘residency’.
cpu (int) – CPU index to check.
state_id (str) – Identifier of the cpuidle state to check.
- _verify_usage_time_advancement(mgr, port, base, cpu, state_id, time_long=120)[source]
Verify that usage and time values advance over a longer period.
- Parameters:
mgr – Manager object for executing commands.
port – Port identifier for command execution.
base (str) – Base sysfs path for the C-state.
cpu (int) – CPU index to check.
state_id (str) – Identifier of the cpuidle state to check.
time_long (int) – Time to wait between checks in seconds.
- available_governors(mgr, port, cpuidle_dir)[source]
List available cpuidle governors.
- Parameters:
mgr – Manager object for executing commands.
port – Port identifier for command execution.
cpuidle_dir – Base directory for cpuidle sysfs entries.
- Returns:
List of available cpuidle governors.
- Return type:
List[str]
- current_governor(mgr, port, cpuidle_dir, ro=True)[source]
Get the current cpuidle governor.
- Parameters:
mgr – Manager object for executing commands.
port – Port identifier for command execution.
cpuidle_dir – Base directory for cpuidle sysfs entries.
ro (bool) – Whether to read from the read-only current_governor_ro file.
- Returns:
Name of the current cpuidle governor.
- Return type:
str
- set_cpu(platform_base_obj, cpu_num, flag)[source]
Set a CPU core online/offline and verify the new state.
- Parameters:
platform_base_obj (test_automation.utils.auto_platform_base.AutoTestPlatformBase) – Platform fixture with console access.
cpu_num (int) – CPU index to modify.
flag (str) – Desired CPU online state as string.
- Returns:
True when the value matches flag otherwise False
- Return type:
bool
- enable_cpu(platform_base_obj, cpu_num)[source]
Enable a specific CPU core.
- Parameters:
platform_base_obj (test_automation.utils.auto_platform_base.AutoTestPlatformBase)
cpu_num (int)
- Return type:
bool
- disable_cpu(platform_base_obj, cpu_num)[source]
Disable a specific CPU core.
- Parameters:
platform_base_obj (test_automation.utils.auto_platform_base.AutoTestPlatformBase)
cpu_num (int)
- Return type:
bool
- validate_cpu_count_from_devicetree(platform_base_obj, expected_num_cpus)[source]
Validate CPU count in device tree against expected value.
- Parameters:
platform_base_obj (test_automation.utils.auto_platform_base.AutoTestPlatformBase) – Platform fixture with console access.
expected_num_cpus (int) – Expected number of CPU nodes in device tree.
- Raises:
AssertionError – If CPU count does not match expected value.
- Return type:
None
- assert_all_cores_online(platform_base_obj, expected_num_cpus)[source]
Check that all expected CPU cores are currently online.
- Parameters:
platform_base_obj (test_automation.utils.auto_platform_base.AutoTestPlatformBase) – Platform fixture with console access.
expected_num_cpus (int) – Expected number of online processors.
- Raises:
AssertionError – If online CPU count differs from expected
- Return type:
None
- stop_individual_core(platform_base_obj, expected_num_cpus)[source]
Verify per-core CPU hotplug by toggling each core off then on.
- Parameters:
platform_base_obj (test_automation.utils.auto_platform_base.AutoTestPlatformBase) – Platform fixture with console access.
expected_num_cpus (int) – Expected number of online processors.
- Raises:
AssertionError – If online CPU count differs from expected
- Return type:
None
- reenable_all_cpus(platform_base_obj, expected_num_cpus)[source]
Attempt to re-enable all CPU cores and assert recovery
- Parameters:
platform_base_obj (test_automation.utils.auto_platform_base.AutoTestPlatformBase) – Platform fixture with console access.
expected_num_cpus (int) – number of CPU cores expected to be online.
- Raises:
AssertionError – If one or more CPU cores cannot be re-enabled.
- Return type:
None
- check_cannot_disable_all_cores(platform_base_obj, expected_num_cpus)[source]
Verify the system refuses disabling the final online CPU core.
- Parameters:
platform_base_obj (test_automation.utils.auto_platform_base.AutoTestPlatformBase) – Platform fixture with console access.
expected_num_cpus (int) – Total number of CPU cores in the system.
- Raises:
AssertionError – last core disable unexpectedly succeeds.
- Return type:
None