Kể từ ngày 27 tháng 3 năm 2025, bạn nên sử dụng android-latest-release
thay vì aosp-main
để xây dựng và đóng góp cho AOSP. Để biết thêm thông tin, hãy xem phần Thay đổi đối với AOSP.
Viết mã kiểm thử shell trong Trade Federation
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Trang này mô tả cách viết kiểm thử shell. Nếu có thể kiểm thử bằng tập lệnh shell, bạn có thể chạy kiểm thử bằng ExecutableHostTest
. ExecutableHostTest
hỗ trợ lọc kiểm thử và phân đoạn kiểm thử.
Viết mã kiểm thử shell
Tập lệnh shell chính của bạn chạy trên máy chủ. Trước tiên, bạn phải đẩy các tập lệnh hoặc tệp nhị phân khác để chạy trên thiết bị và các tệp dữ liệu cần thiết vào thiết bị.
Bạn có thể thực hiện việc này trong tập lệnh chính hoặc sử dụng PushFilePreparer
.
Nếu kiểm thử có các mô-đun nhị phân thiết bị cần được cài đặt cùng với kiểm thử, hãy chỉ định các mô-đun đó bằng thuộc tính data_device_bins
.
sh_test {
name: "module-name",
...
data_device_bins: ["target-name"],
}
Kiểm thử shell ziptool-tests
là một ví dụ như vậy.
Kết quả kiểm thử cho mỗi lần kiểm thử dựa trên trạng thái thoát của tập lệnh chính.
Một kiểm thử có thể hết thời gian chờ nếu bạn đã chỉ định per-binary-timeout
.
Định cấu hình kiểm thử shell
Trong cấu hình XML Tradefed, các kiểm thử shell được chạy thông qua trình chạy 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>
Đặt tập lệnh chính cho kiểm thử làm giá trị của tuỳ chọn binary
. Hãy xem các tuỳ chọn ExecutableHostTest
khác.
Nếu tập lệnh yêu cầu quyền truy cập thư mục gốc, hãy thêm RootTargetPreparer
vào cấu hình.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],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."]]