atest 執行裝置測試時,atest 會將測試二進位檔及其資源推送至 /data 分區,並使用 adb shell 執行。測試可執行檔會使用 shell SELinux 網域,因此請接收與 shell 網域相關聯的 SELinux 政策 。如果裝置以強制執行的 SELinux 模式運作,違反這些政策的裝置測試會失敗,並顯示 SELinux 錯誤。
請注意,shell 網域「沒有」allow下列規則:
存取
/vendor分割區中的檔案,包括連結至安裝在/vendor分割區中的程式庫。呼叫任意 Binder 介面。
如果裝置測試需要其中一項或兩項權限,您必須使用 root 權限執行測試。如果 adbd 具有根層級權限,adbd 會使用裝置上的 su SELinux 網域,而非 shell,因為後者具有更多權限。
如要使用根層級權限執行裝置測試,請將 require_root: true 屬性新增至 Android.bp 檔案中對應的 Soong 模組定義。
// file: Android.bp
rust_test {
name: "example_rust_test_that requires root",
// ...
rustlibs: [
"some-vendor-lib",
],
// This example test requires root permissions, because it calls Binder
// interfaces unavailable for the shell, and also links with a vendor
// library.
require_root: true,
}