החל מ-27 במרץ 2025, מומלץ להשתמש ב-android-latest-release
במקום ב-aosp-main
כדי ליצור תרומות ל-AOSP. מידע נוסף זמין במאמר שינויים ב-AOSP.
בדיקת HAL עם התאמה לשם השירות
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
Android 9 כולל תמיכה בהשגת שם השירות של מופע HAL נתון על סמך המכשיר שבו מופעלות בדיקות Vendor Test Suite (VTS). הפעלת בדיקות VTS HAL שמודעות לשם השירות מאפשרת למפתחים לבצע אוטומציה של בדיקות הרחבות של ספקים, של כמה HAL ושל כמה מופעים של HAL בהרצות בדיקות VTS בצד היעד ובצד המארח.
מידע על שמות שירותים
כל מופע של שירות HAL שפועל נרשם עם שם שירות.
בגרסאות קודמות של Android, מפתחים שהריצו בדיקות VTS HAL נדרשו להגדיר את שם השירות הנכון עבור לקוח הבדיקה ב-getService()
או להשאיר את השם ריק ולחזור לשם השירות שמוגדר כברירת מחדל. החסרונות של הגישה הזו כוללים:
- הסתמכות על הידע של מפתח הבדיקה כדי להגדיר את שם השירות הנכון.
- כברירת מחדל, אפשר לבצע בדיקות רק מול מופע שירות יחיד.
- תחזוקה ידנית של שמות שירותים (כלומר, השמות מוצפנים, ולכן צריך לעדכן אותם ידנית אם שם השירות משתנה).
ב-Android 9, מפתחים יכולים לקבל באופן אוטומטי את שם השירות של מופע HAL נתון על סמך המכשיר שנבדק.
היתרונות של הגישה הזו כוללים תמיכה בבדיקות:
- Vendor HAL extensions. לדוגמה, אם לספק יש הטמעה של camera.provider HAL שפועלת במכשירי הספק עם שם שירות מותאם אישית, VTS יכול לזהות את מופע הספק ולהריץ את הבדיקה מולו.
- Multiple HAL instances (כמה מופעים של HAL). לדוגמה, אם ל-
graphics.composer
HAL יש שני מופעים (אחד עם שם השירות default ואחד עם שם השירות vr), VTS יכול לזהות את שני המופעים ולהריץ את הבדיקה על כל אחד מהם.
- בדיקות של Multi-HAL. השימוש באפשרות הזו מתאים לבדיקה של כמה HAL עם כמה מופעים. לדוגמה, כשמריצים את בדיקת VTS שמאמתת את אופן הפעולה של KeyMint (לשעבר Keymaster) ו-Gatekeeper HAL ביחד, VTS יכול לבדוק את כל השילובים של מופעי שירות עבור ה-HAL האלה.
בדיקות בצד היעד
כדי להפעיל את ההגדרה 'מודעות לשם השירות' לבדיקות בצד היעד, Android 9 כולל סביבת בדיקה שניתנת להתאמה אישית (VtsHalHidlTargetTestEnvBase
) שמספקת ממשקי API ל:
- רושמים את ה-HAL(ים) לטירגוט בבדיקה.
- מציינים את כל רכיבי ה-HAL הרשומים.
- קבלת שמות של שירותים עבור HAL רשומים שסופקו על ידי מסגרת VTS.
בנוסף, ה-framework של VTS מספק תמיכה בזמן ריצה עבור:
- ביצוע עיבוד מקדים לקובץ הבינארי של הבדיקה כדי לקבל את כל ה-HAL של הבדיקה הרשומים.
- זיהוי כל המכונות של השירות שפועלות וקבלת שם השירות של כל מכונה (השם מאוחזר על סמך
vendor/manifest.xml
).
- חישוב כל השילובים של המכונות (כדי לתמוך בבדיקות של כמה HAL).
- יצירת בדיקה חדשה לכל מופע (שילוב) של שירות.
דוגמה:
איור 1. תמיכה בזמן ריצה של מסגרת VTS לבדיקה בצד היעד
הגדרה של בדיקות בצד היעד שמודעות לשם השירות
כדי להגדיר את סביבת הבדיקה לבדיקה עם מודעות לשם השירות בצד היעד:
- מגדירים
testEnvironment
על סמך VtsHalHidlTargetTestEnvBase
ורושמים בדיקות 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. תמיכה בזמן ריצה של framework של VTS לבדיקות בצד המארח
- סקריפט בדיקת ה-HAL מציין את שירותי ה-HAL לטירגוט בבדיקה.
- הפונקציה
hal_hidl_host_test
(מחלקת משנה של param_test
) מקבלת את ה-HAL(s) הרשומים לבדיקה מסקריפט הבדיקה, מזהה את שמות השירותים התואמים ל-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 זיהתה את HAL לבדיקה באמצעות האפשרות <precondition-lshal>
שהוגדרה ב-AndroidTest.xml
. היה קשה לתחזק את הגישה הזו (כי היא הסתמכה על המפתחים כדי להגדיר את הבדיקה בצורה נכונה ולעדכן את ההגדרה בהתאם) והיא הייתה לא מדויקת (כי היא הכילה רק את חבילת המידע ופרטי הגרסה ולא את פרטי הממשק).
ב-Android 9, VTS מזהה את HAL של הבדיקה באמצעות מודעות לשם השירות. ממשקי HAL רשומים לבדיקה שימושיים גם למטרות הבאות:
- בדיקות של תנאים מוקדמים. לפני שמריצים בדיקת HAL, VTS יכול לאשר ש-HAL לבדיקה זמין במכשיר היעד ולדלג על הבדיקות אם הוא לא זמין (מידע נוסף זמין במאמר בנושא בדיקת היכולת של VTS).
- מדידת כיסוי. VTS תומך במדידת כיסוי קוד בין תהליכים באמצעות הידע על שירותי ה-HAL לבדיקה שהוא רוצה למדוד (כלומר, כדי לנקות את הכיסוי של תהליך שירות ה-HAL).
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-27 (שעון UTC).
[[["התוכן קל להבנה","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 (שעון 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)."]]