1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "DeviceManifestTest.h"
18
19 #include <android-base/properties.h>
20 #include <android-base/result.h>
21 #include <libvts_vintf_test_common/common.h>
22 #include <vintf/VintfObject.h>
23
24 #include "SingleManifestTest.h"
25
26 using testing::Combine;
27 using testing::Values;
28 using testing::ValuesIn;
29
30 namespace android {
31 namespace vintf {
32 namespace testing {
33
SetUp()34 void DeviceManifestTest::SetUp() {
35 VtsTrebleVintfTestBase::SetUp();
36
37 vendor_manifest_ = VintfObject::GetDeviceHalManifest();
38 ASSERT_NE(vendor_manifest_, nullptr)
39 << "Failed to get vendor HAL manifest." << endl;
40 }
41
42 // Tests that Shipping FCM Version in the device manifest is at least the
43 // minimum Shipping FCM Version as required by Board API level.
44 // @VsrTest = VSR-3.2-014
TEST_F(DeviceManifestTest,ShippingFcmVersion)45 TEST_F(DeviceManifestTest, ShippingFcmVersion) {
46 uint64_t board_api_level = GetBoardApiLevel();
47 Level shipping_fcm_version = VintfObject::GetDeviceHalManifest()->level();
48 auto res = TestTargetFcmVersion(shipping_fcm_version, board_api_level);
49 ASSERT_RESULT_OK(res);
50 }
51
52 // Tests that deprecated HALs are not in the manifest, unless a higher,
53 // non-deprecated minor version is in the manifest.
54 // @VsrTest = VSR-3.2-014
TEST_F(DeviceManifestTest,NoDeprecatedHalsOnManifest)55 TEST_F(DeviceManifestTest, NoDeprecatedHalsOnManifest) {
56 string error;
57 EXPECT_EQ(android::vintf::NO_DEPRECATED_HALS,
58 VintfObject::GetInstance()->checkDeprecation(
59 HidlInterfaceMetadata::all(), &error))
60 << error;
61 }
62
63 // Tests that devices launching R support mapper@4.0. Go devices are exempt
64 // from this requirement, so we use this test to enforce instead of the
65 // compatibility matrix.
66 // @VsrTest = VSR-3.2-014
TEST_F(DeviceManifestTest,GraphicsMapperHalVersionCompatibility)67 TEST_F(DeviceManifestTest, GraphicsMapperHalVersionCompatibility) {
68 Level shipping_fcm_version = VintfObject::GetDeviceHalManifest()->level();
69 bool is_go_device =
70 android::base::GetBoolProperty("ro.config.low_ram", false);
71 if (shipping_fcm_version == Level::UNSPECIFIED ||
72 shipping_fcm_version < Level::R ||
73 (is_go_device && shipping_fcm_version < Level::V)) {
74 GTEST_SKIP() << "Graphics mapper 4 is only required on launching R devices";
75 }
76
77 if (shipping_fcm_version >= Level::V) {
78 bool exists = false;
79 ASSERT_TRUE(vendor_manifest_->forEachInstance(
80 [&](const ManifestHal::InstanceType& instance) -> bool {
81 if (instance.package() == "mapper" &&
82 instance.format() == HalFormat::NATIVE &&
83 instance.version().majorVer == 5 &&
84 instance.version().minorVer == 0)
85 exists = true;
86 return true;
87 }));
88 ASSERT_TRUE(exists)
89 << "Graphics mapper 5 is required on launching V+ devices";
90 } else {
91 bool exists = false;
92 bool ret = vendor_manifest_->forEachInstance(
93 [&](const ManifestHal::InstanceType& instance) -> bool {
94 if (instance.package() == "mapper" &&
95 instance.format() == HalFormat::NATIVE &&
96 instance.version().majorVer == 5 &&
97 instance.version().minorVer == 0)
98 exists = true;
99 return true;
100 });
101 // If native implementation doesn't exist, then the HIDL implementation must
102 // exist on this device.
103 if (!ret || !exists) {
104 ASSERT_TRUE(vendor_manifest_->hasHidlInstance(
105 "android.hardware.graphics.mapper", {4, 0}, "IMapper", "default"));
106 ASSERT_FALSE(vendor_manifest_->hasHidlInstance(
107 "android.hardware.graphics.mapper", {2, 0}, "IMapper", "default"));
108 ASSERT_FALSE(vendor_manifest_->hasHidlInstance(
109 "android.hardware.graphics.mapper", {2, 1}, "IMapper", "default"));
110 }
111 }
112 }
113
114 // Devices with Shipping FCM version 3~6 must have either the HIDL or the
115 // AIDL health HAL. Because compatibility matrices cannot express OR condition
116 // between <hal>'s, add a test here.
117 //
118 // There's no need to enforce minimum HAL versions because
119 // NoDeprecatedHalsOnManifest already checks it.
120 // @VsrTest = VSR-3.2-014
TEST_F(DeviceManifestTest,HealthHal)121 TEST_F(DeviceManifestTest, HealthHal) {
122 bool has_hidl = vendor_manifest_->hasHidlInstance(
123 "android.hardware.health", {2, 0}, "IHealth", "default");
124 bool has_aidl = vendor_manifest_->hasAidlInstance("android.hardware.health",
125 1, "IHealth", "default");
126 ASSERT_TRUE(has_hidl || has_aidl)
127 << "Device must have either health HIDL HAL or AIDL HAL";
128 }
129
130 // Devices with Shipping FCM version 5+ must have the
131 // AIDL power HAL.
132 //
133 // The specific versions are handled by the framework compatibility matrix.
134 // @VsrTest = VSR-3.2-014
TEST_F(DeviceManifestTest,PowerHal)135 TEST_F(DeviceManifestTest, PowerHal) {
136 Level fcm_version = VintfObject::GetDeviceHalManifest()->level();
137 if (fcm_version == Level::UNSPECIFIED || fcm_version < Level::R) {
138 GTEST_SKIP() << "Power HAL is only required on launching R+ devices";
139 }
140 ASSERT_TRUE(vendor_manifest_->hasAidlInstance("android.hardware.power",
141 "IPower", "default"))
142 << "Device must have the android.hardware.power.IPower/default HAL";
143 }
144
145 // Devices must have either the HIDL or the AIDL gatekeeper HAL.
146 // Because compatibility matrices cannot express OR condition
147 // between <hal>'s, add a test here.
148 //
149 // There's no need to enforce minimum HAL versions because
150 // NoDeprecatedHalsOnManifest already checks it.
151 // @VsrTest = VSR-3.2-014
TEST_F(DeviceManifestTest,GatekeeperHal)152 TEST_F(DeviceManifestTest, GatekeeperHal) {
153 bool has_hidl = vendor_manifest_->hasHidlInstance(
154 "android.hardware.gatekeeper", {1, 0}, "IGatekeeper", "default");
155 bool has_aidl = vendor_manifest_->hasAidlInstance(
156 "android.hardware.gatekeeper", "IGatekeeper", "default");
157 ASSERT_TRUE(has_hidl || has_aidl)
158 << "Device must have either gatekeeper HIDL HAL or AIDL HAL";
159 }
160
161 // Devices with Shipping FCM version 7 must have either the HIDL or the
162 // AIDL composer HAL. Because compatibility matrices cannot express OR condition
163 // between <hal>'s, add a test here.
164 //
165 // There's no need to enforce minimum HAL versions because
166 // NoDeprecatedHalsOnManifest already checks it.
167 // @VsrTest = VSR-3.2-014
TEST_F(DeviceManifestTest,ComposerHal)168 TEST_F(DeviceManifestTest, ComposerHal) {
169 bool has_hidl = vendor_manifest_->hasHidlInstance(
170 "android.hardware.graphics.composer", {2, 1}, "IComposer", "default");
171 bool has_aidl = vendor_manifest_->hasAidlInstance(
172 "android.hardware.graphics.composer3", 1, "IComposer", "default");
173 ASSERT_TRUE(has_hidl || has_aidl)
174 << "Device must have either composer HIDL HAL or AIDL HAL";
175 }
176
177 // Devices with Shipping FCM version 7 must have either the HIDL or the
178 // AIDL gralloc HAL. Because compatibility matrices cannot express OR condition
179 // between <hal>'s, add a test here.
180 //
181 // There's no need to enforce minimum HAL versions because
182 // NoDeprecatedHalsOnManifest already checks it.
183 // @VsrTest = VSR-3.2-014
TEST_F(DeviceManifestTest,GrallocHal)184 TEST_F(DeviceManifestTest, GrallocHal) {
185 bool has_hidl = false;
186 for (size_t hidl_major = 2; hidl_major <= 4; hidl_major++)
187 has_hidl = has_hidl || vendor_manifest_->hasHidlInstance(
188 "android.hardware.graphics.allocator",
189 {hidl_major, 0}, "IAllocator", "default");
190
191 bool has_aidl = vendor_manifest_->hasAidlInstance(
192 "android.hardware.graphics.allocator", "IAllocator", "default");
193
194 ASSERT_TRUE(has_hidl || has_aidl)
195 << "Device must have either graphics allocator HIDL HAL or AIDL HAL";
196 }
197
198 // Devices after Android T must have either the HIDL or the
199 // AIDL thermal HAL. Because compatibility matrices cannot express OR condition
200 // between <hal>'s, add a test here.
201 // @VsrTest = VSR-3.2-014
TEST_F(DeviceManifestTest,ThermalHal)202 TEST_F(DeviceManifestTest, ThermalHal) {
203 Level shipping_fcm_version = VintfObject::GetDeviceHalManifest()->level();
204 if (shipping_fcm_version == Level::UNSPECIFIED ||
205 shipping_fcm_version < Level::T) {
206 GTEST_SKIP()
207 << "Thermal HAL is only required on devices launching in T or later";
208 }
209 bool has_hidl = vendor_manifest_->hasHidlInstance(
210 "android.hardware.thermal", {2, 0}, "IThermal", "default");
211 bool has_aidl = vendor_manifest_->hasAidlInstance("android.hardware.thermal",
212 "IThermal", "default");
213 ASSERT_TRUE(has_hidl || has_aidl)
214 << "Device must have either thermal HIDL HAL or AIDL HAL";
215 }
216
217 // Tests that devices launching T support allocator@4.0 or AIDL.
218 // Go devices are exempt
219 // from this requirement, so we use this test to enforce instead of the
220 // compatibility matrix.
221 // @VsrTest = VSR-3.2-014
TEST_F(DeviceManifestTest,GrallocHalVersionCompatibility)222 TEST_F(DeviceManifestTest, GrallocHalVersionCompatibility) {
223 Level shipping_fcm_version = VintfObject::GetDeviceHalManifest()->level();
224 bool is_go_device =
225 android::base::GetBoolProperty("ro.config.low_ram", false);
226 if (shipping_fcm_version == Level::UNSPECIFIED ||
227 shipping_fcm_version < Level::T ||
228 (is_go_device && shipping_fcm_version < Level::V)) {
229 GTEST_SKIP() << "Gralloc 4.0/AIDL is only required on launching T devices";
230 }
231
232 bool has_aidl = vendor_manifest_->hasAidlInstance(
233 "android.hardware.graphics.allocator", 1, "IAllocator", "default");
234 bool has_hidl_4_0 = vendor_manifest_->hasHidlInstance(
235 "android.hardware.graphics.allocator", {4, 0}, "IAllocator", "default");
236 ASSERT_TRUE(has_aidl || has_hidl_4_0);
237
238 ASSERT_FALSE(vendor_manifest_->hasHidlInstance(
239 "android.hardware.graphics.allocator", {2, 0}, "IAllocator", "default"));
240 ASSERT_FALSE(vendor_manifest_->hasHidlInstance(
241 "android.hardware.graphics.allocator", {3, 0}, "IAllocator", "default"));
242 }
243
244 // Devices must have either the HIDL or the AIDL audio HAL, both "core" and
245 // "effect" parts must be of the same type. Checked by a test because
246 // compatibility matrices cannot express these conditions.
247 // @VsrTest = VSR-3.2-014
TEST_F(DeviceManifestTest,AudioHal)248 TEST_F(DeviceManifestTest, AudioHal) {
249 Level shipping_fcm_version = VintfObject::GetDeviceHalManifest()->level();
250 if (shipping_fcm_version == Level::UNSPECIFIED ||
251 shipping_fcm_version < Level::U) {
252 GTEST_SKIP() << "AIDL Audio HAL can only appear on launching U devices";
253 }
254 bool has_hidl_core = false;
255 for (const auto v :
256 {Version(5, 0), Version(6, 0), Version(7, 0), Version(7, 1)}) {
257 has_hidl_core |= vendor_manifest_->hasHidlInstance(
258 "android.hardware.audio", v, "IDevicesFactory", "default");
259 }
260 bool has_hidl_effect = false;
261 for (const auto v : {Version(5, 0), Version(6, 0), Version(7, 0)}) {
262 has_hidl_effect |= vendor_manifest_->hasHidlInstance(
263 "android.hardware.audio.effect", v, "IEffectsFactory", "default");
264 }
265 bool has_aidl_core = vendor_manifest_->hasAidlInstance(
266 "android.hardware.audio.core", "IConfig", "default");
267 bool has_aidl_effect = vendor_manifest_->hasAidlInstance(
268 "android.hardware.audio.effect", "IFactory", "default");
269 EXPECT_EQ(has_hidl_core, has_hidl_effect)
270 << "Device must have both Audio Core and Effect HALs of the same type";
271 EXPECT_EQ(has_aidl_core, has_aidl_effect)
272 << "Device must have both Audio Core and Effect HALs of the same type";
273 EXPECT_TRUE(has_hidl_core || has_aidl_core)
274 << "Device must have either Audio HIDL HAL or AIDL HAL";
275 }
276
277 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SingleHidlTest);
278 INSTANTIATE_TEST_CASE_P(
279 DeviceManifest, SingleHidlTest,
280 Combine(ValuesIn(VtsTrebleVintfTestBase::GetHidlInstances(
281 VintfObject::GetDeviceHalManifest())),
282 Values(VintfObject::GetDeviceHalManifest())),
283 &GetTestCaseSuffix<SingleHidlTest>);
284
285 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SingleHwbinderHalTest);
286 INSTANTIATE_TEST_CASE_P(
287 DeviceManifest, SingleHwbinderHalTest,
288 Combine(ValuesIn(SingleHwbinderHalTest::ListRegisteredHwbinderHals()),
289 Values(VintfObject::GetDeviceHalManifest())),
290 &SingleHwbinderHalTest::GetTestCaseSuffix);
291
292 INSTANTIATE_TEST_CASE_P(
293 DeviceManifest, SingleAidlTest,
294 Combine(ValuesIn(VtsTrebleVintfTestBase::GetAidlInstances(
295 VintfObject::GetDeviceHalManifest())),
296 Values(VintfObject::GetDeviceHalManifest())),
297 &GetTestCaseSuffix<SingleAidlTest>);
298
299 INSTANTIATE_TEST_CASE_P(
300 DeviceManifest, SingleNativeTest,
301 Combine(ValuesIn(VtsTrebleVintfTestBase::GetNativeInstances(
302 VintfObject::GetDeviceHalManifest())),
303 Values(VintfObject::GetDeviceHalManifest())),
304 &GetTestCaseSuffix<SingleNativeTest>);
305
306 } // namespace testing
307 } // namespace vintf
308 } // namespace android
309