You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

CTS工具如何确定Android设备需运行的测试模块及用例数量?

Great question! I’ve spent a fair amount of time working with CTS-TradeFed, so let me walk you through exactly how it determines which modules and test cases to execute when you run run cts.

Core Logic Behind CTS Module & Test Case Selection

1. Device Profile Identification & Feature Matching

First off, CTS-TradeFed starts by identifying the device’s type (phone, TV, wear, etc.) using system properties like ro.build.product and ro.product.device. Each device type has a predefined baseline of required modules tailored to its use case.

Next, it cross-references the device’s supported features—pulled from pm list features and the device’s system manifest—against each module’s dependencies. For example:

  • Android TV devices don’t declare telephony-related features, so all CtsTelephony* modules get automatically skipped.
  • TV-specific features like android.software.leanback trigger inclusion of modules like CtsLeanbackTestCases, which aren’t part of the phone’s default CTS run.

2. Module Configuration Rules

Every CTS module has its own set of configuration rules (usually in the module’s AndroidManifest.xml or global CTS config files) that dictate eligibility:

  • Minimum SDK version: Modules targeting API 30+ won’t run on devices with older Android versions.
  • Hardware/software requirements: Annotations or manifest entries like <uses-feature android:name="android.hardware.camera"/> block the module if the device lacks that feature.
  • Device type exclusions: Explicit tags like <exclude-if-device-type tv="true"/> in module configs prevent it from running on specific device categories.

When you run run cts, CTS-TradeFed parses all these configs and filters out any modules that don’t align with the target device’s specs.

3. Fine-Grained Test Case Filtering

Even within an included module, not all test cases execute:

  • Runtime feature checks: Test cases with annotations like @RequiresFeature("android.hardware.nfc") will skip themselves if the device doesn’t support that feature.
  • Device-specific skips: Cases designed for touch-based interactions (common in phone tests) are often marked to skip on TV devices, which use remote controls instead.
  • Disabled cases: Any test marked with @Disabled (either in code or via runtime config overrides) gets excluded from the run.

4. Optional Manual Overrides

While the default run cts uses the device’s profile and feature set, you can tweak the module list with command-line flags:

  • Use --include-module <module-name> to force-include a module that would otherwise be skipped.
  • Use --exclude-module <module-name> to remove a module from the default run.
  • Custom config files (in cts/config/) can also define global inclusion/exclusion rules that override the default behavior.

As a concrete example: When running CTS on an Android TV, you’ll notice far fewer telephony, camera, and touch-interaction modules compared to a phone. Instead, you’ll see extra modules focused on leanback UI, HDMI connectivity, and TV-specific media handling—all tied directly to the device’s declared features and profile.

内容的提问来源于stack exchange,提问作者Sanyal

火山引擎 最新活动