blob: 3d4fd4725b8c877e15a11e89117323ac0e6add35 [file] [log] [blame]
Steven Morelandd6df9182019-10-08 18:21:35 -07001/*
2 * Copyright (C) 2019 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 */
Steven Morelandaa6f7082020-02-07 16:08:17 -080016#include <aidl/metadata.h>
Steven Morelandd6df9182019-10-08 18:21:35 -070017#include <android-base/logging.h>
Steven Morelandaa6f7082020-02-07 16:08:17 -080018#include <android-base/strings.h>
Steven Morelandd6df9182019-10-08 18:21:35 -070019#include <gtest/gtest.h>
20#include <hidl/metadata.h>
21#include <hidl-util/FQName.h>
22#include <vintf/VintfObject.h>
23
24using namespace android;
25
Steven Morelandaa6f7082020-02-07 16:08:17 -080026static const std::set<std::string> kKnownMissingHidl = {
Steven Morelandd6df9182019-10-08 18:21:35 -070027 "android.frameworks.bufferhub@1.0",
28 "android.frameworks.cameraservice.device@2.0",
29 "android.frameworks.vr.composer@1.0",
30 "android.frameworks.vr.composer@2.0",
31 "android.hardware.audio@2.0",
32 "android.hardware.audio@4.0",
Mikhail Naganov6dc07d22020-01-24 11:58:37 -080033 "android.hardware.audio@5.0",
Steven Morelandd6df9182019-10-08 18:21:35 -070034 "android.hardware.audio.effect@2.0",
35 "android.hardware.audio.effect@4.0",
Mikhail Naganov6dc07d22020-01-24 11:58:37 -080036 "android.hardware.audio.effect@5.0",
Steven Morelandd6df9182019-10-08 18:21:35 -070037 "android.hardware.automotive.audiocontrol@1.0",
38 "android.hardware.automotive.can@1.0",
39 "android.hardware.automotive.evs@1.0",
40 "android.hardware.automotive.evs@1.1",
41 "android.hardware.automotive.vehicle@2.0",
42 "android.hardware.biometrics.face@1.0",
43 "android.hardware.biometrics.fingerprint@2.1",
44 "android.hardware.bluetooth.a2dp@1.0",
45 "android.hardware.broadcastradio@1.1",
46 "android.hardware.broadcastradio@2.0",
Steven Morelandd6df9182019-10-08 18:21:35 -070047 "android.hardware.camera.provider@2.5",
Henry Fangee99f192019-10-25 12:54:01 -070048 "android.hardware.cas@1.2",
Steven Morelandd6df9182019-10-08 18:21:35 -070049 "android.hardware.cas.native@1.0",
50 "android.hardware.confirmationui@1.0",
51 "android.hardware.contexthub@1.0",
Steven Moreland043028c2020-02-06 15:37:03 -080052 "android.hardware.configstore@1.1", // deprecated, see b/149050985, b/149050733
Steven Morelandd6df9182019-10-08 18:21:35 -070053 "android.hardware.fastboot@1.0",
54 "android.hardware.gnss.measurement_corrections@1.0",
55 "android.hardware.gnss.visibility_control@1.0",
56 "android.hardware.graphics.allocator@3.0",
57 "android.hardware.graphics.allocator@4.0",
58 "android.hardware.graphics.bufferqueue@1.0",
59 "android.hardware.graphics.bufferqueue@2.0",
60 "android.hardware.graphics.composer@2.3",
61 "android.hardware.graphics.composer@2.4",
62 "android.hardware.graphics.mapper@3.0",
63 "android.hardware.graphics.mapper@4.0",
64 "android.hardware.health@1.0",
Steven Morelandd6df9182019-10-08 18:21:35 -070065 "android.hardware.ir@1.0",
66 "android.hardware.keymaster@3.0",
Ivailo Karamanolev01e68212020-02-12 19:27:54 +010067 "android.hardware.light@2.0",
Steven Morelandd6df9182019-10-08 18:21:35 -070068 "android.hardware.media.bufferpool@1.0",
69 "android.hardware.media.bufferpool@2.0",
70 "android.hardware.memtrack@1.0",
71 "android.hardware.nfc@1.2",
72 "android.hardware.oemlock@1.0",
73 "android.hardware.power@1.3",
Steven Morelandd6df9182019-10-08 18:21:35 -070074 "android.hardware.radio.deprecated@1.0",
75 "android.hardware.renderscript@1.0",
Jack Yufadc5512019-12-20 11:30:11 +080076 "android.hardware.secure_element@1.2",
Steven Morelandd6df9182019-10-08 18:21:35 -070077 "android.hardware.sensors@1.0",
78 "android.hardware.soundtrigger@2.2",
79 "android.hardware.tetheroffload.config@1.0",
80 "android.hardware.tetheroffload.control@1.0",
81 "android.hardware.thermal@1.1",
82 "android.hardware.tv.cec@1.0",
83 "android.hardware.tv.cec@2.0",
84 "android.hardware.tv.input@1.0",
85 "android.hardware.tv.tuner@1.0",
86 "android.hardware.usb@1.2",
87 "android.hardware.usb.gadget@1.0",
Steven Moreland8a9f5c52019-11-10 17:53:41 -080088 "android.hardware.vibrator@1.3",
Steven Morelandd6df9182019-10-08 18:21:35 -070089 "android.hardware.vr@1.0",
90 "android.hardware.weaver@1.0",
91 "android.hardware.wifi@1.3",
92 "android.hardware.wifi@1.4",
93 "android.hardware.wifi.hostapd@1.1",
94 "android.hardware.wifi.offload@1.0",
95 "android.hidl.base@1.0",
96 "android.hidl.memory.token@1.0",
97};
98
Steven Morelandaa6f7082020-02-07 16:08:17 -080099static const std::set<std::string> kKnownMissingAidl = {
Steven Morelandaa6f7082020-02-07 16:08:17 -0800100 // types-only packages, which never expect a default implementation
101 "android.hardware.common.NativeHandle",
102 "android.hardware.graphics.common.ExtendableType",
David Zeuthen39748432020-02-12 11:02:56 -0500103
104 // These KeyMaster types are in an AIDL types-only HAL because they're used
105 // by the Identity Credential AIDL HAL. Remove this when fully porting
106 // KeyMaster to AIDL.
107 "android.hardware.keymaster.HardwareAuthToken",
108 "android.hardware.keymaster.HardwareAuthenticatorType",
109 "android.hardware.keymaster.Timestamp",
Steven Morelandaa6f7082020-02-07 16:08:17 -0800110};
111
Steven Morelandd6df9182019-10-08 18:21:35 -0700112// AOSP packages which are never considered
Steven Morelandaa6f7082020-02-07 16:08:17 -0800113static bool isHidlPackageWhitelist(const FQName& name) {
Steven Morelandd6df9182019-10-08 18:21:35 -0700114 static std::vector<std::string> gAospExclude = {
115 // packages not implemented now that we never expect to be implemented
116 "android.hardware.tests",
Emilian Peev206aaf82019-11-19 08:15:31 -0800117 // packages not registered with hwservicemanager, usually sub-interfaces
118 "android.hardware.camera.device",
Steven Morelandd6df9182019-10-08 18:21:35 -0700119 };
120 for (const std::string& package : gAospExclude) {
121 if (name.inPackage(package)) {
122 return true;
123 }
124 }
125 return false;
126}
127
Steven Morelandaa6f7082020-02-07 16:08:17 -0800128static bool isAospHidlInterface(const FQName& name) {
129 static const std::vector<std::string> kAospPackages = {
Steven Morelandd6df9182019-10-08 18:21:35 -0700130 "android.hidl",
131 "android.hardware",
132 "android.frameworks",
133 "android.system",
134 };
Steven Morelandaa6f7082020-02-07 16:08:17 -0800135 for (const std::string& package : kAospPackages) {
136 if (name.inPackage(package) && !isHidlPackageWhitelist(name)) {
Steven Morelandd6df9182019-10-08 18:21:35 -0700137 return true;
138 }
139 }
140 return false;
141}
142
Steven Morelandaa6f7082020-02-07 16:08:17 -0800143static std::set<FQName> allTreeHidlInterfaces() {
Steven Morelandd6df9182019-10-08 18:21:35 -0700144 std::set<FQName> ret;
145 for (const auto& iface : HidlInterfaceMetadata::all()) {
146 FQName f;
147 CHECK(f.setTo(iface.name)) << iface.name;
148 ret.insert(f);
149 }
150 return ret;
151}
152
Steven Morelandaa6f7082020-02-07 16:08:17 -0800153static std::set<FQName> allHidlManifestInterfaces() {
Steven Morelandd6df9182019-10-08 18:21:35 -0700154 std::set<FQName> ret;
155 auto setInserter = [&] (const vintf::ManifestInstance& i) -> bool {
156 if (i.format() != vintf::HalFormat::HIDL) {
Steven Morelandd6df9182019-10-08 18:21:35 -0700157 return true; // continue
158 }
159 ret.insert(i.getFqInstance().getFqName());
160 return true; // continue
161 };
162 vintf::VintfObject::GetDeviceHalManifest()->forEachInstance(setInserter);
163 vintf::VintfObject::GetFrameworkHalManifest()->forEachInstance(setInserter);
164 return ret;
165}
166
Steven Morelandaa6f7082020-02-07 16:08:17 -0800167static bool isAospAidlInterface(const std::string& name) {
168 return base::StartsWith(name, "android.") &&
Steven Moreland9177c632020-02-12 11:16:09 -0800169 !base::StartsWith(name, "android.automotive.") &&
170 !base::StartsWith(name, "android.hardware.automotive.");
Steven Morelandaa6f7082020-02-07 16:08:17 -0800171}
172
173static std::set<std::string> allAidlManifestInterfaces() {
174 std::set<std::string> ret;
175 auto setInserter = [&] (const vintf::ManifestInstance& i) -> bool {
176 if (i.format() != vintf::HalFormat::AIDL) {
177 return true; // continue
178 }
179 ret.insert(i.package() + "." + i.interface());
180 return true; // continue
181 };
182 vintf::VintfObject::GetDeviceHalManifest()->forEachInstance(setInserter);
183 vintf::VintfObject::GetFrameworkHalManifest()->forEachInstance(setInserter);
184 return ret;
185}
186
187TEST(Hal, AllHidlInterfacesAreInAosp) {
188 for (const FQName& name : allHidlManifestInterfaces()) {
189 EXPECT_TRUE(isAospHidlInterface(name)) << name.string();
Steven Morelandd6df9182019-10-08 18:21:35 -0700190 }
191}
192
Steven Morelandaa6f7082020-02-07 16:08:17 -0800193TEST(Hal, HidlInterfacesImplemented) {
Steven Moreland089942a2019-11-19 11:24:05 -0800194 // instances -> major version -> minor versions
Steven Morelandd6df9182019-10-08 18:21:35 -0700195 std::map<std::string, std::map<size_t, std::set<size_t>>> unimplemented;
196
Steven Morelandaa6f7082020-02-07 16:08:17 -0800197 for (const FQName& f : allTreeHidlInterfaces()) {
198 if (!isAospHidlInterface(f)) continue;
Steven Morelandd6df9182019-10-08 18:21:35 -0700199
200 unimplemented[f.package()][f.getPackageMajorVersion()].insert(f.getPackageMinorVersion());
201 }
202
Steven Moreland089942a2019-11-19 11:24:05 -0800203 // we'll be removing items from this which we know are missing
204 // in order to be left with those elements which we thought we
205 // knew were missing but are actually present
Steven Morelandaa6f7082020-02-07 16:08:17 -0800206 std::set<std::string> thoughtMissing = kKnownMissingHidl;
Steven Moreland089942a2019-11-19 11:24:05 -0800207
Steven Morelandaa6f7082020-02-07 16:08:17 -0800208 for (const FQName& f : allHidlManifestInterfaces()) {
Steven Moreland089942a2019-11-19 11:24:05 -0800209 if (thoughtMissing.erase(f.getPackageAndVersion().string()) > 0) {
Steven Morelandaa6f7082020-02-07 16:08:17 -0800210 std::cout << "[ WARNING ] Instance in missing list, but available: "
211 << f.string() << std::endl;
Steven Moreland089942a2019-11-19 11:24:05 -0800212 }
213
Steven Morelandd6df9182019-10-08 18:21:35 -0700214 std::set<size_t>& minors = unimplemented[f.package()][f.getPackageMajorVersion()];
215 size_t minor = f.getPackageMinorVersion();
216
217 auto it = minors.find(minor);
218 if (it == minors.end()) continue;
219
220 // if 1.2 is implemented, also considere 1.0, 1.1 implemented
221 minors.erase(minors.begin(), std::next(it));
222 }
223
224 for (const auto& [package, minorsPerMajor] : unimplemented) {
225 for (const auto& [major, minors] : minorsPerMajor) {
226 if (minors.empty()) continue;
227
228 size_t maxMinor = *minors.rbegin();
229
230 FQName missing;
231 ASSERT_TRUE(missing.setTo(package, major, maxMinor));
232
Steven Moreland089942a2019-11-19 11:24:05 -0800233 if (thoughtMissing.erase(missing.string()) > 0) continue;
Steven Morelandd6df9182019-10-08 18:21:35 -0700234
235 ADD_FAILURE() << "Missing implementation from " << missing.string();
236 }
237 }
Steven Moreland089942a2019-11-19 11:24:05 -0800238
239 for (const std::string& missing : thoughtMissing) {
Steven Morelandaa6f7082020-02-07 16:08:17 -0800240 std::cout << "[ WARNING ] Instance in missing list and cannot find it anywhere: "
241 << missing << std::endl;
242 }
243}
244
245TEST(Hal, AllAidlInterfacesAreInAosp) {
246 for (const std::string& name : allAidlManifestInterfaces()) {
247 EXPECT_TRUE(isAospAidlInterface(name)) << name;
248 }
249}
250
251TEST(Hal, AidlInterfacesImplemented) {
252 std::set<std::string> manifest = allAidlManifestInterfaces();
253 std::set<std::string> thoughtMissing = kKnownMissingAidl;
254
255 for (const auto& iface : AidlInterfaceMetadata::all()) {
256 ASSERT_FALSE(iface.types.empty()) << iface.name; // sanity
257 if (!isAospAidlInterface(iface.name)) continue;
258 if (iface.stability != "vintf") continue;
259
260 bool hasRegistration = false;
261 bool knownMissing = false;
262 for (const std::string& type : iface.types) {
263 if (manifest.erase(type) > 0) hasRegistration = true;
264 if (thoughtMissing.erase(type) > 0) knownMissing = true;
265 }
266
267 if (knownMissing) {
268 if (hasRegistration) {
269 std::cout << "[ WARNING ] Interface in missing list, but available: " << iface.name
270 << " which declares the following types:\n "
271 << base::Join(iface.types, "\n ") << std::endl;
272 }
273
274 continue;
275 }
276
277 EXPECT_TRUE(hasRegistration) << iface.name << " which declares the following types:\n "
278 << base::Join(iface.types, "\n ") << std::endl;
279 }
280
281 for (const std::string& iface : thoughtMissing) {
282 std::cout << "[ WARNING ] Interface in manifest list and cannot find it anywhere: "
283 << iface << std::endl;
284 }
285
286 for (const std::string& iface : manifest) {
287 std::cout << "[ WARNING ] Can't find manifest entry in tree: " << iface << std::endl;
Steven Moreland089942a2019-11-19 11:24:05 -0800288 }
Steven Morelandd6df9182019-10-08 18:21:35 -0700289}