Run NPU Manager Mobly tests

The CtsNpuManagerMoblyTestCases suite verifies device compatibility with the NpuManager service, added in Android 17 (API level 37). These Mobly-based tests evaluate NPU workload prioritization, ensure foreground app NPU workloads receive higher priority than background ones, and validate NPU access control.

Test configuration

The global default parameters for this test suite are optimized for reference devices. Because NPU hardware capabilities can vary across different devices, adjust the test configuration parameters to ensure the tests run properly on your hardware.

Why tuning is necessary

The core of the prioritization test test_foreground_app_finishes_first relies on a race condition by evaluating whether the foreground app finishes its inferences before the background app. To ensure the test reliably meets its stability requirement for passing two out of three runs, configure these parameters to match your device's specific NPU speeds.

The configuration file is located in the Android source tree at packages/modules/NpuManager/tests/cts/mobly_config.yaml.

Configurable parameters

When tuning the tests for your device, adjust the following parameters within the YAML file. All numerical values must be greater than zero, and foreground delay specifically must be at least 0.5 seconds, the default value.

  • foreground_delay_seconds

    • Description: The head start in seconds given to the background app before the foreground app triggers its inference. The sequence is: Background app starts inferences -> [test waits for foreground_delay_seconds] -> foreground app starts inferences.
    • Default: 0.5
    • Tuning guidance: A larger delay gives the background app more time to process inferences before the foreground app starts. The foreground app should begin its inferences roughly halfway through the background app's workload.
  • foreground_test_num_iterations_per_thread

    • Description: The number of consecutive inference loops each individual thread executes for the test_foreground_app_finishes_first test for both the foreground and background app.
    • Default: 30
  • foreground_test_num_threads

    • Description: The number of concurrent threads spawned to run inferences simultaneously for the test_foreground_app_finishes_first test for both the foreground and background app.
    • Default: 4

Run the tests

After your device is configured and connected, run the suite using standard CTS Tradefed commands.

To run the module using CTS Tradefed:

cts-tradefed run cts -m CtsNpuManagerMoblyTestCases