2025 年 3 月 27 日より、AOSP のビルドとコントリビューションには aosp-main
ではなく android-latest-release
を使用することをおすすめします。詳細については、AOSP の変更をご覧ください。
サービス名認識型 HAL テスト
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Android 9 には、ベンダー テストスイート(VTS)テストが実行されているデバイスに基づいて、HAL インスタンスのサービス名を取得する機能があります。サービス名を認識する VTS HAL テストを実行すると、ベンダー拡張、複数の HAL、複数の HAL インスタンスのテストを、ターゲット側とホスト側の両方の VTS テスト実行で自動化できます。
サービス名について
実行中の HAL サービスの各インスタンスは、サービス名で登録されます。
以前のバージョンの Android では、VTS HAL テストを実行する際に、getService()
でテスト クライアントの正しいサービス名を設定するか、名前を空にしてデフォルトのサービス名のままにする必要がありました。この方法には以下の欠点があります。
- 正しいサービス名の設定がテスト デベロッパーの知識に依存する。
- デフォルトで、1 つのサービス インスタンスのテストに限定される。
- サービス名を手動でメンテナンスする必要がある(名前はハードコードされるため、サービス名の変更時に手動で更新する必要がある)。
Android 9 では、テスト対象デバイスに基づいて、HAL インスタンスのサービス名を自動的に取得できます。
この方法のメリットは、以下のテストに対応している点です。
- ベンダーの HAL 拡張。たとえば、ベンダーがベンダー デバイス上でサービス名をカスタマイズして動作する camera.provider HAL を実装している場合に、VTS でベンダー インスタンスを識別し、それに対してテストを実行できます。
- 複数の HAL インスタンス。たとえば、
graphics.composer
HAL に 2 つのインスタンス(1 つはサービス名「default」、もう 1 つはサービス名「vr」)がある場合、両方のインスタンスを識別し、各インスタンスに対してテストを実行できます。
- 複数 HAL のテスト。複数 HAL を複数インスタンスでテストする場合に使用します。たとえば、keymaster HAL と gatekeeper HAL の連携を検証する VTS テストを実行する場合に、HAL とそのサービス インスタンスの組み合わせをすべてテストできます。
ターゲット側のテスト
Android 9 には、ターゲット側のテストでサービス名の認識を有効にするために、以下を行うためのインターフェースを提供するカスタマイズ可能なテスト環境(VtsHalHidlTargetTestEnvBase
)が含まれています。
- テスト対象とする HAL を登録する。
- 登録されている HAL をすべて列挙する。
- VTS フレームワークが提供している登録済みの HAL のサービス名を取得する。
また、VTS フレームワークには、以下を行うためのランタイム サポートがあります。
- テストバイナリを前処理して、登録済みのテスト HAL をすべて取得する。
- 実行中のサービス インスタンスをすべて検出し、各インスタンスのサービス名を取得する(
vendor/manifest.xml
に基づいて取得)。
- インスタンスの組み合わせをすべて求める(複数 HAL のテストをサポートするため)。
- サービス インスタンス(組み合わせ)ごとに新しいテストを生成する。
例:
図 1. ターゲット側のテストに対する VTS フレームワークのランタイム サポート
ターゲット側のサービス名認識型テストのセットアップ
以下のようにして、ターゲット側のサービス名認識型テストのテスト環境をセットアップします。
VtsHalHidlTargetTestEnvBase
をベースにして testEnvironment
を定義し、テスト HAL を登録します。
#include <VtsHalHidlTargetTestEnvBase.h>
class testEnvironment : public::testing::VtsHalHidlTargetTestEnvBase {
virtual void registerTestServices() override {
registerTestService<IFoo>();
}
};
- テスト環境から提供されている
getServiceName()
を使用して、サービス名を渡します。
::testing::VtsHalHidlTargetTestBase::getService<IFoo>(testEnv->getServiceName<IFoo>("default"));
// "default" is the default service name you want to use.
main()
と initTest
の中で、テスト環境を登録します。
int main(int argc, char** argv) {
testEnv = new testEnvironment();
::testing::AddGlobalTestEnvironment(testEnv);
::testing::InitGoogleTest(&argc, argv);
testEnv->init(argc, argv);
return RUN_ALL_TESTS();
}
その他の例については、VtsHalCameraProviderV2_4TargetTest.cpp
をご覧ください。
VTS のホスト側のテスト
VTS のホスト側のテストでは、対象デバイスでテストバイナリを実行するのではなく、ホスト側でテスト スクリプトを実行します。このテストでサービス名の認識を有効にするには、ホスト側のテンプレートを使用して、同じテスト スクリプトを異なるパラメータに対して複数回実行します(gtest パラメータ化テストと同様)。
図 2. ホスト側のテストに対する VTS フレームワークのランタイム サポート
- hal test スクリプトで、テスト対象とする HAL サービスが指定されます。
hal_hidl_host_test
(param_test
のサブクラス)は、登録済みのテスト HAL をテスト スクリプトから受け取り、テスト HAL の対応するサービス名を特定してから、テスト パラメータとしてサービス名の組み合わせを(複数 HAL のテスト用に)生成します。また、現在のテストケースに渡されたパラメータに従って対応するサービス名を返すメソッド getHalServiceName()
を提供します。
- param_test テンプレートは、パラメータのリストを受け取って、各パラメータに対してすべてのテストケースを実行するロジックをサポートしています。つまり、各テストケースに対して、各パラメータでパラメータ化されたテストケースを N 個生成します(N はパラメータの個数)。
ホスト側のサービス名認識型テストのセットアップ
次のようにして、ホスト側のサービス名認識型テスト用にテスト環境をセットアップします。
- 次のようにして、テスト スクリプトで対象の HAL サービスを指定します。
TEST_HAL_SERVICES = { "android.hardware.foo@1.0::IFoo" }
- 次のように、
getHalServiceName()
を呼び出して、名前を init hal に渡します。
self.dut.hal.InitHidlHal(
target_type='foo',
target_basepaths=self.dut.libPaths,
target_version=1.0,
target_package='android.hardware.foo',
target_component_name='IFoo',
hw_binder_service_name
=self.getHalServiceName("android.hardware.foo@1.0::IFoo"),
bits=int(self.abi_bitness))
その他の例については、VtsHalMediaOmxStoreV1_0HostTest.py
をご覧ください。
テスト HAL の登録
以前のバージョンの Android では、VTS は AndroidTest.xml
で設定された <precondition-lshal>
オプションを使用してテスト HAL を特定しました。この方法では、デベロッパーがテストを適切に設定し、それに応じて設定を更新することが前提となるため、維持管理が難しく、またパッケージ情報とバージョン情報だけでインターフェース情報が含まれないため不正確になります。
Android 9 では、VTS はサービス名認識を使用してテスト HAL を特定します。登録済みのテスト HAL は、次の場合にも役立ちます。
- 前提条件のチェック。VTS は、HAL テストを実行する前に、対象デバイスでテスト HAL が使用可能かを確認し、使用可能でない場合にテストをスキップできます(VTS でのテスト可否のチェックをご覧ください)。
- カバレッジの測定。VTS は、測定するテスト HAL サービスに関する知識によるプロセス横断コード カバレッジ測定をサポートしています(HAL サービス プロセスのカバレッジをフラッシュするため)。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-03-05 UTC。
[null,null,["最終更新日 2025-03-05 UTC。"],[],[],null,["# Service name aware HAL testing\n\nAndroid 9 includes support for obtaining the service\nname of a given HAL instance based on the device on which Vendor Test Suite\n(VTS) tests are running. Running VTS HAL tests that are service name aware\nenables developers to automate testing vendor extensions, multiple HALs, and\nmultiple HAL instances on both target- and host-side VTS test runs.\n\n### About service names\n\n\nEach instance of the running HAL service registers itself with a service name.\n\n\nIn previous versions of Android, developers running VTS HAL tests were\nrequired to set the correct service name for the test client in\n`getService()` or leave the name empty and fallback to the default\nservice name. Disadvantages to this approach included:\n\n- Reliance on the test developer's knowledge to set the correct service name.\n- Limited to testing against a single service instance by default.\n- Manual maintenance of service names (i.e. because names are hard-coded, they must be manually updated if the service name changes.\n\n\nIn Android 9, developers can automatically get the\nservice name for a given HAL instance based on the device under test.\nAdvantages to this approach include support for testing:\n\n- **Vendor HAL extensions**. For example, when a vendor has an implementation of camera.provider HAL that runs on vendor devices with a customized service name, VTS can identify the vendor instance and run the test against it.\n- **Multiple HAL instances** . For example, when the `graphics.composer` HAL has two instances (one with service name \"default\" and one with service name \"vr\"), VTS can identify both instances and run the test against each of them.\n- **Multi-HAL testing**. Used when testing multiple HALs with multiple instances For example, when running the VTS test that verifies how the KeyMint (previously Keymaster) and Gatekeeper HALs work together, VTS can test all combinations of service instances for those HALs.\n\nTarget-side tests\n-----------------\n\n\nTo enable service name awareness for target-side testing, Android\n9 includes a customizable test environment\n([VtsHalHidlTargetTestEnvBase](https://android.googlesource.com/platform/test/vts/+/android16-release/runners/target/vts_hal_hidl_target/VtsHalHidlTargetTestEnvBase.h))\nthat provides interfaces to:\n\n- Register targeting HAL(s) in the test.\n- List all the registered HAL(s).\n- Get service name(s) for registered HAL(s) provided by VTS framework.\n\n\nIn addition, the VTS framework provides runtime support for:\n\n- Pre-processing the test binary to get all registered test HAL(s).\n- Identifying all running service instances and getting the service name for each instance (retrieved based on `vendor/manifest.xml`).\n- Calculating all instance combinations (to support multiple HAL testing).\n- Generating a new test for each service instance (combination).\n\n\nExample:\n\n\n**Figure 1.** VTS framework runtime support for target-side testing\n\n### Set up service name aware target-side tests\n\n\nTo setup your test environment for target-side service name aware testing:\n\n1. Define a `testEnvironment` based on `VtsHalHidlTargetTestEnvBase` and register test HALs: \n\n ```verilog\n #include \u003cVtsHalHidlTargetTestEnvBase.h\u003e\n class testEnvironment : public::testing::VtsHalHidlTargetTestEnvBase {\n virtual void registerTestServices() override {\n registerTestService\u003cIFoo\u003e();\n }\n };\n ```\n2. Use `getServiceName()` provided by the test environment to pass service name: \n\n ```css+lasso\n ::testing::VtsHalHidlTargetTestBase::getService\u003cIFoo\u003e(testEnv-\u003egetServiceName\u003cIFoo\u003e(\"default\"));\n // \"default\" is the default service name you want to use.\n ```\n3. Register the test environment in `main()` and `initTest`: \n\n ```css+lasso\n int main(int argc, char** argv) {\n testEnv = new testEnvironment();\n ::testing::AddGlobalTestEnvironment(testEnv);\n ::testing::InitGoogleTest(&argc, argv);\n testEnv-\u003einit(argc, argv);\n return RUN_ALL_TESTS();\n }\n ```\n\n\nFor additional examples, refer to\n[VtsHalCameraProviderV2_4TargetTest.cpp](https://android.googlesource.com/platform/hardware/interfaces/+/android16-release/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp).\n\nVTS host-side tests\n-------------------\n\n\nVTS host-side tests run test scripts on host side instead of test binaries on\nthe target device. To enable service name awareness for these tests, you can\nuse host side templates to run the same test script multiple times against\ndifferent parameters (similar to the gtest parameterized test).\n\n\n**Figure 2.** VTS framework runtime support for host-side testing\n\n- The **hal test** script specifies the targeting HAL service(s) in the test.\n- The [hal_hidl_host_test](https://android.googlesource.com/platform/test/vts/+/android16-release/testcases/template/hal_hidl_host_test/hal_hidl_host_test.py) (subclass of `param_test`) takes the registered testing HAL(s) from test script, identifies the corresponding service name(s) for the testing HAL, then generates service name combinations (for multi-HAL testing) as test parameters. It also provides a method `getHalServiceName()` which returns the corresponding service name according to the parameter passed to the current test case.\n- The [param_test](https://android.googlesource.com/platform/test/vts/+/android16-release/testcases/template/param_test/param_test.py) template supports logic to accept a list of parameters and run all the given test cases against each parameter. I.e. for each test case it generates N new parameterized test case (N = size of parameters), each with a given parameter.\n\n### Set up service name aware host-side tests\n\n\nTo setup your test environment for host-side service name aware testing:\n\n1. Specify the target HAL service in the test script: \n\n ```objective-c\n TEST_HAL_SERVICES = { \"android.hardware.foo@1.0::IFoo\" }\n ```\n2. Call `getHalServiceName()` and pass the name to init hal: \n\n ```objective-c\n self.dut.hal.InitHidlHal(\n target_type='foo',\n target_basepaths=self.dut.libPaths,\n target_version=1.0,\n target_package='android.hardware.foo',\n target_component_name='IFoo',\n hw_binder_service_name\n =self.getHalServiceName(\"android.hardware.foo@1.0::IFoo\"),\n bits=int(self.abi_bitness))\n ```\n\n\nFor additional examples, refer to\n[VtsHalMediaOmxStoreV1_0HostTest.py](https://android.googlesource.com/platform/test/vts-testcase/hal/+/android16-release/media/omx/V1_0/host_omxstore/VtsHalMediaOmxStoreV1_0HostTest.py).\n\nRegister test HALs\n------------------\n\n\nIn previous versions of Android, VTS identified the testing HAL using the\n`\u003cprecondition-lshal\u003e` option configured in\n`AndroidTest.xml`. This approach was difficult to maintain (as it\nrelied on developers to configure the test properly and update the\nconfiguration accordingly) and inaccurate (as it contained only the package\nand version info and not the interface info).\n\n\nIn Android 9, VTS identifies the testing HAL using\nservice name awareness. The registered testing HALs are also useful for:\n\n- **Precondition checks** . Before running a HAL test, VTS can confirm the testing HAL is available on the target device and skip the tests if it is not (refer to [VTS\n testability check](/docs/core/tests/vts/hal-testability)).\n- **Coverage measurement**. VTS supports cross-process code coverage measurement via the knowledge about the testing HAL services it wants to measure (i.e. to flush the coverage for the hal service process)."]]