自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
在 Trade Federation 中編寫殼層測試
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本頁說明如何編寫殼層測試。如果可以使用殼層指令碼執行測試,您可以使用 ExecutableHostTest
執行測試。ExecutableHostTest
支援測試篩選和測試分割。
編寫殼層測試
主要的殼層指令碼會在主機上執行。其他要在裝置上執行的指令碼或二進位檔,以及所需的資料檔案,必須先推送至裝置。您可以透過主要指令碼或 PushFilePreparer
執行這項操作。
如果測試包含應與測試一併安裝的裝置二進位模組,請使用 data_device_bins
屬性指定這些模組。
sh_test {
name: "module-name",
...
data_device_bins: ["target-name"],
}
殼層測試 ziptool-tests
就是這類測試的例子。
每項測試的結果會根據主指令碼的結束狀態而定。如果已指定 per-binary-timeout
,測試可能會逾時。
設定殼層測試
在 Tradefed XML 設定中,殼層測試會透過 ExecutableHostTest
執行器執行。
<test class="com.android.tradefed.testtype.binary.ExecutableHostTest" >
<option name="binary" value="your-test-script.sh" />
<option name="relative-path-execution" value="true" />
<option name="per-binary-timeout" value="15m" />
</test>
將測試的主要指令碼設為 binary
選項的值。查看其他 ExecutableHostTest
選項。
如果指令碼需要使用 root 權限,請在設定中新增 RootTargetPreparer
。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Write a shell test in Trade Federation\n\nThis page describes how to write a shell test. If a test can be done with a\nshell script, you can run it with [`ExecutableHostTest`](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/test_framework/com/android/tradefed/testtype/binary/ExecutableHostTest.java). `ExecutableHostTest` supports test filtering and\ntest sharding.\n\nWrite a shell test\n------------------\n\nYour main shell script runs on the host. Other scripts or binaries to run on\nthe device and the data files required must be pushed to the device first.\nThis can be done as part of the main script or using [`PushFilePreparer`](https://cs.android.com/android/platform/superproject/+/android-latest-release:tools/tradefederation/core/test_framework/com/android/tradefed/targetprep/PushFilePreparer.java?q=PushFilePreparer).\n\nIf the test has device binary modules that should be installed alongside the\ntest, specify them with [`data_device_bins`](https://ci.android.com/builds/submitted/6873301/linux/latest/view/sh.html#sh_test.data_device_bins)\nproperty. \n\n sh_test {\n name: \"module-name\",\n ...\n data_device_bins: [\"target-name\"],\n }\n\nShell test [`ziptool-tests`](https://cs.android.com/android/platform/superproject/+/android-latest-release:system/libziparchive/Android.bp?q=ziptool-tests)\nis such an example.\n\nThe test result for each test is based on the exit status of your main script.\nA test can timeout if `per-binary-timeout` has been specified.\n\nConfigure a shell test\n----------------------\n\nIn Tradefed XML configuration, shell tests are run through the\n`ExecutableHostTest` runner. \n\n \u003ctest class=\"com.android.tradefed.testtype.binary.ExecutableHostTest\" \u003e\n \u003coption name=\"binary\" value=\"your-test-script.sh\" /\u003e\n \u003coption name=\"relative-path-execution\" value=\"true\" /\u003e\n \u003coption name=\"per-binary-timeout\" value=\"15m\" /\u003e\n \u003c/test\u003e\n\nSet the main script for the test as the value of the `binary` option. Check out\nother `ExecutableHostTest` options.\n\nIf the script requires root privilege, add [`RootTargetPreparer`](https://cs.android.com/android/platform/superproject/+/android-latest-release:tools/tradefederation/core/test_framework/com/android/tradefed/targetprep/RootTargetPreparer.java) to the configuration."]]