当 atest 运行设备测试时,atest 会将测试二进制文件及其资源推送到 /data 分区,并使用 adb shell 执行该文件。测试可执行文件
使用 shell SELinux 域;因此,请接收与 shell 域关联的 SELinux 政策。当设备在强制执行 SELinux 模式下运行时,违反这些政策的设备测试会因 SELinux 错误而失败。
值得注意的是,shell 域没有 allow 规则来:
访问
/vendor分区上的文件,包括与安装到/vendor分区的库进行链接。调用任意 Binder 接口。
如果设备测试需要其中一项或两项权限,那么您必须 使用 root 权限运行测试。当 adbd 具有 root 权限时,adbd 会在设备上使用
su SELinux 域,而不是具有
更多特权的 shell。
如需使用 root 权限运行设备测试,请将 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,
}