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.
TEST_F(DeviceManifestTest,ShippingFcmVersion)44 TEST_F(DeviceManifestTest, ShippingFcmVersion) {
45 uint64_t board_api_level = GetBoardApiLevel();
46 Level shipping_fcm_version = VintfObject::GetDeviceHalManifest()->level();
47 auto res = TestTargetFcmVersion(shipping_fcm_version, board_api_level);
48 ASSERT_RESULT_OK(res);
49 }
50
51 // Tests that deprecated HALs are not in the manifest, unless a higher,
52 // non-deprecated minor version is in the manifest.
TEST_F(DeviceManifestTest,NoDeprecatedHalsOnManifest)53 TEST_F(DeviceManifestTest, NoDeprecatedHalsOnManifest) {
54 string error;
55 EXPECT_EQ(android::vintf::NO_DEPRECATED_HALS,
56 VintfObject::GetInstance()->checkDeprecation(
57 HidlInterfaceMetadata::all(), &error))
58 << error;
59 }
60
61 // Tests that devices launching R support mapper@4.0. Go devices are exempt
62 // from this requirement, so we use this test to enforce instead of the
63 // compatibility matrix.
TEST_F(DeviceManifestTest,GraphicsMapperHalVersionCompatibility)64 TEST_F(DeviceManifestTest, GraphicsMapperHalVersionCompatibility) {
65 Level shipping_fcm_version = VintfObject::GetDeviceHalManifest()->level();
66 bool is_go_device =
67 android::base::GetBoolProperty("ro.config.low_ram", false);
68 if (shipping_fcm_version == Level::UNSPECIFIED ||
69 shipping_fcm_version < Level::R || is_go_device) {
70 GTEST_SKIP() << "Graphics mapper 4 is only required on launching R devices";
71 }
72
73 ASSERT_TRUE(vendor_manifest_->hasHidlInstance(
74 "android.hardware.graphics.mapper", {4, 0}, "IMapper", "default"));
75 ASSERT_FALSE(vendor_manifest_->hasHidlInstance(
76 "android.hardware.graphics.mapper", {2, 0}, "IMapper", "default"));
77 ASSERT_FALSE(vendor_manifest_->hasHidlInstance(
78 "android.hardware.graphics.mapper", {2, 1}, "IMapper", "default"));
79 }
80
81 // Devices with Shipping FCM version 3~6 must have either the HIDL or the
82 // AIDL health HAL. Because compatibility matrices cannot express OR condition
83 // between <hal>'s, add a test here.
84 //
85 // There's no need to enforce minimum HAL versions because
86 // NoDeprecatedHalsOnManifest already checks it.
TEST_F(DeviceManifestTest,HealthHal)87 TEST_F(DeviceManifestTest, HealthHal) {
88 bool has_hidl = vendor_manifest_->hasHidlInstance(
89 "android.hardware.health", {2, 0}, "IHealth", "default");
90 bool has_aidl = vendor_manifest_->hasAidlInstance("android.hardware.health",
91 1, "IHealth", "default");
92 ASSERT_TRUE(has_hidl || has_aidl)
93 << "Device must have either health HIDL HAL or AIDL HAL";
94 }
95
96 // Devices with Shipping FCM version 5+ must have the
97 // AIDL power HAL.
98 //
99 // The specific versions are handled by the framework compatibility matrix.
TEST_F(DeviceManifestTest,PowerHal)100 TEST_F(DeviceManifestTest, PowerHal) {
101 Level fcm_version = VintfObject::GetDeviceHalManifest()->level();
102 if (fcm_version == Level::UNSPECIFIED || fcm_version < Level::R) {
103 GTEST_SKIP() << "Power HAL is only required on launching R+ devices";
104 }
105 ASSERT_TRUE(vendor_manifest_->hasAidlInstance("android.hardware.power",
106 "IPower", "default"))
107 << "Device must have the android.hardware.power.IPower/default HAL";
108 }
109
110 // Devices must have either the HIDL or the AIDL gatekeeper HAL.
111 // Because compatibility matrices cannot express OR condition
112 // between <hal>'s, add a test here.
113 //
114 // There's no need to enforce minimum HAL versions because
115 // NoDeprecatedHalsOnManifest already checks it.
TEST_F(DeviceManifestTest,GatekeeperHal)116 TEST_F(DeviceManifestTest, GatekeeperHal) {
117 bool has_hidl = vendor_manifest_->hasHidlInstance(
118 "android.hardware.gatekeeper", {1, 0}, "IGatekeeper", "default");
119 bool has_aidl = vendor_manifest_->hasAidlInstance(
120 "android.hardware.gatekeeper", "IGatekeeper", "default");
121 ASSERT_TRUE(has_hidl || has_aidl)
122 << "Device must have either gatekeeper HIDL HAL or AIDL HAL";
123 }
124
125 // Devices with Shipping FCM version 7 must have either the HIDL or the
126 // AIDL composer HAL. Because compatibility matrices cannot express OR condition
127 // between <hal>'s, add a test here.
128 //
129 // There's no need to enforce minimum HAL versions because
130 // NoDeprecatedHalsOnManifest already checks it.
TEST_F(DeviceManifestTest,ComposerHal)131 TEST_F(DeviceManifestTest, ComposerHal) {
132 bool has_hidl = vendor_manifest_->hasHidlInstance(
133 "android.hardware.graphics.composer", {2, 1}, "IComposer", "default");
134 bool has_aidl = vendor_manifest_->hasAidlInstance(
135 "android.hardware.graphics.composer3", 1, "IComposer", "default");
136 ASSERT_TRUE(has_hidl || has_aidl)
137 << "Device must have either composer HIDL HAL or AIDL HAL";
138 }
139
140 // Devices with Shipping FCM version 7 must have either the HIDL or the
141 // AIDL gralloc HAL. Because compatibility matrices cannot express OR condition
142 // between <hal>'s, add a test here.
143 //
144 // There's no need to enforce minimum HAL versions because
145 // NoDeprecatedHalsOnManifest already checks it.
TEST_F(DeviceManifestTest,GrallocHal)146 TEST_F(DeviceManifestTest, GrallocHal) {
147 bool has_hidl = false;
148 for (size_t hidl_major = 2; hidl_major <= 4; hidl_major++)
149 has_hidl = has_hidl || vendor_manifest_->hasHidlInstance(
150 "android.hardware.graphics.allocator",
151 {hidl_major, 0}, "IAllocator", "default");
152
153 bool has_aidl = vendor_manifest_->hasAidlInstance(
154 "android.hardware.graphics.allocator", 1, "IAllocator", "default");
155
156 ASSERT_TRUE(has_hidl || has_aidl)
157 << "Device must have either graphics allocator HIDL HAL or AIDL HAL";
158 }
159
160 // Devices after Android T must have either the HIDL or the
161 // AIDL thermal HAL. Because compatibility matrices cannot express OR condition
162 // between <hal>'s, add a test here.
TEST_F(DeviceManifestTest,ThermalHal)163 TEST_F(DeviceManifestTest, ThermalHal) {
164 Level shipping_fcm_version = VintfObject::GetDeviceHalManifest()->level();
165 if (shipping_fcm_version == Level::UNSPECIFIED ||
166 shipping_fcm_version < Level::T) {
167 GTEST_SKIP()
168 << "Thermal HAL is only required on devices launching in T or later";
169 }
170 bool has_hidl = vendor_manifest_->hasHidlInstance(
171 "android.hardware.thermal", {2, 0}, "IThermal", "default");
172 bool has_aidl = vendor_manifest_->hasAidlInstance("android.hardware.thermal",
173 "IThermal", "default");
174 ASSERT_TRUE(has_hidl || has_aidl)
175 << "Device must have either thermal HIDL HAL or AIDL HAL";
176 }
177
178 // Tests that devices launching T support allocator@4.0 or AIDL.
179 // Go devices are exempt
180 // from this requirement, so we use this test to enforce instead of the
181 // compatibility matrix.
TEST_F(DeviceManifestTest,GrallocHalVersionCompatibility)182 TEST_F(DeviceManifestTest, GrallocHalVersionCompatibility) {
183 Level shipping_fcm_version = VintfObject::GetDeviceHalManifest()->level();
184 bool is_go_device =
185 android::base::GetBoolProperty("ro.config.low_ram", false);
186 if (shipping_fcm_version == Level::UNSPECIFIED ||
187 shipping_fcm_version < Level::T || is_go_device) {
188 GTEST_SKIP() << "Gralloc 4.0/AIDL is only required on launching T devices";
189 }
190
191 bool has_aidl = vendor_manifest_->hasAidlInstance(
192 "android.hardware.graphics.allocator", 1, "IAllocator", "default");
193 bool has_hidl_4_0 = vendor_manifest_->hasHidlInstance(
194 "android.hardware.graphics.allocator", {4, 0}, "IAllocator", "default");
195 ASSERT_TRUE(has_aidl || has_hidl_4_0);
196
197 ASSERT_FALSE(vendor_manifest_->hasHidlInstance(
198 "android.hardware.graphics.allocator", {2, 0}, "IAllocator", "default"));
199 ASSERT_FALSE(vendor_manifest_->hasHidlInstance(
200 "android.hardware.graphics.allocator", {3, 0}, "IAllocator", "default"));
201 }
202
203 // Devices must have either the HIDL or the AIDL audio HAL, both "core" and
204 // "effect" parts must be of the same type. Checked by a test because
205 // compatibility matrices cannot express these conditions.
TEST_F(DeviceManifestTest,AudioHal)206 TEST_F(DeviceManifestTest, AudioHal) {
207 Level shipping_fcm_version = VintfObject::GetDeviceHalManifest()->level();
208 if (shipping_fcm_version == Level::UNSPECIFIED ||
209 shipping_fcm_version < Level::U) {
210 GTEST_SKIP() << "AIDL Audio HAL can only appear on launching U devices";
211 }
212 bool has_hidl_core = false;
213 for (const auto v :
214 {Version(5, 0), Version(6, 0), Version(7, 0), Version(7, 1)}) {
215 has_hidl_core |= vendor_manifest_->hasHidlInstance(
216 "android.hardware.audio", v, "IDevicesFactory", "default");
217 }
218 bool has_hidl_effect = false;
219 for (const auto v : {Version(5, 0), Version(6, 0), Version(7, 0)}) {
220 has_hidl_effect |= vendor_manifest_->hasHidlInstance(
221 "android.hardware.audio.effect", v, "IEffectsFactory", "default");
222 }
223 bool has_aidl_core = vendor_manifest_->hasAidlInstance(
224 "android.hardware.audio.core", "IConfig", "default");
225 bool has_aidl_effect = vendor_manifest_->hasAidlInstance(
226 "android.hardware.audio.effect", "IFactory", "default");
227 EXPECT_EQ(has_hidl_core, has_hidl_effect)
228 << "Device must have both Audio Core and Effect HALs of the same type";
229 EXPECT_EQ(has_aidl_core, has_aidl_effect)
230 << "Device must have both Audio Core and Effect HALs of the same type";
231 EXPECT_TRUE(has_hidl_core || has_aidl_core)
232 << "Device must have either Audio HIDL HAL or AIDL HAL";
233 }
234
235 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SingleHidlTest);
236 INSTANTIATE_TEST_CASE_P(
237 DeviceManifest, SingleHidlTest,
238 Combine(ValuesIn(VtsTrebleVintfTestBase::GetHidlInstances(
239 VintfObject::GetDeviceHalManifest())),
240 Values(VintfObject::GetDeviceHalManifest())),
241 &GetTestCaseSuffix<SingleHidlTest>);
242
243 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SingleHwbinderHalTest);
244 INSTANTIATE_TEST_CASE_P(
245 DeviceManifest, SingleHwbinderHalTest,
246 Combine(ValuesIn(SingleHwbinderHalTest::ListRegisteredHwbinderHals()),
247 Values(VintfObject::GetDeviceHalManifest())),
248 &SingleHwbinderHalTest::GetTestCaseSuffix);
249
250 INSTANTIATE_TEST_CASE_P(
251 DeviceManifest, SingleAidlTest,
252 Combine(ValuesIn(VtsTrebleVintfTestBase::GetAidlInstances(
253 VintfObject::GetDeviceHalManifest())),
254 Values(VintfObject::GetDeviceHalManifest())),
255 &GetTestCaseSuffix<SingleAidlTest>);
256
257 INSTANTIATE_TEST_CASE_P(
258 DeviceManifest, SingleNativeTest,
259 Combine(ValuesIn(VtsTrebleVintfTestBase::GetNativeInstances(
260 VintfObject::GetDeviceHalManifest())),
261 Values(VintfObject::GetDeviceHalManifest())),
262 &GetTestCaseSuffix<SingleNativeTest>);
263
264 } // namespace testing
265 } // namespace vintf
266 } // namespace android
267