blob: 9b056fca3a88f2bfd451b7d8b40a04af4947cf0b [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",
Changyeon Joed143a22020-01-12 20:10:01 -080031 "android.frameworks.automotive.display@1.0",
Steven Morelandd6df9182019-10-08 18:21:35 -070032 "android.hardware.audio@2.0",
33 "android.hardware.audio@4.0",
Mikhail Naganov6dc07d22020-01-24 11:58:37 -080034 "android.hardware.audio@5.0",
Steven Morelandd6df9182019-10-08 18:21:35 -070035 "android.hardware.audio.effect@2.0",
36 "android.hardware.audio.effect@4.0",
Mikhail Naganov6dc07d22020-01-24 11:58:37 -080037 "android.hardware.audio.effect@5.0",
Steven Morelandd6df9182019-10-08 18:21:35 -070038 "android.hardware.automotive.audiocontrol@1.0",
Hayden Gomes1defdc12020-01-22 14:10:10 -080039 "android.hardware.automotive.audiocontrol@2.0",
Steven Morelandd6df9182019-10-08 18:21:35 -070040 "android.hardware.automotive.can@1.0",
41 "android.hardware.automotive.evs@1.0",
42 "android.hardware.automotive.evs@1.1",
43 "android.hardware.automotive.vehicle@2.0",
Steven Morelandd6df9182019-10-08 18:21:35 -070044 "android.hardware.biometrics.fingerprint@2.1",
Ilya Matyukhin451defa2020-01-22 21:49:53 -080045 "android.hardware.biometrics.fingerprint@2.2",
Steven Morelandd6df9182019-10-08 18:21:35 -070046 "android.hardware.bluetooth.a2dp@1.0",
47 "android.hardware.broadcastradio@1.1",
48 "android.hardware.broadcastradio@2.0",
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 Morelandc70c8942020-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",
Steven Morelande9228952020-02-06 15:38:09 -080054 "android.hardware.gnss.measurement_corrections@1.1", // is sub-interface of gnss
Steven Morelandd6df9182019-10-08 18:21:35 -070055 "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",
Wei Wang6580ed32020-01-17 18:28:15 -080073 "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",
Steven Morelandd6df9182019-10-08 18:21:35 -070078 "android.hardware.tetheroffload.config@1.0",
79 "android.hardware.tetheroffload.control@1.0",
80 "android.hardware.thermal@1.1",
81 "android.hardware.tv.cec@1.0",
82 "android.hardware.tv.cec@2.0",
83 "android.hardware.tv.input@1.0",
84 "android.hardware.tv.tuner@1.0",
85 "android.hardware.usb@1.2",
Howard Yen91d505d2020-01-17 16:31:55 +080086 "android.hardware.usb.gadget@1.1",
Steven Moreland8a9f5c52019-11-10 17:53:41 -080087 "android.hardware.vibrator@1.3",
Steven Morelandd6df9182019-10-08 18:21:35 -070088 "android.hardware.vr@1.0",
89 "android.hardware.weaver@1.0",
90 "android.hardware.wifi@1.3",
91 "android.hardware.wifi@1.4",
leslfcdc95d2019-12-06 14:29:04 +080092 "android.hardware.wifi.hostapd@1.2",
Steven Morelandd6df9182019-10-08 18:21:35 -070093 "android.hardware.wifi.offload@1.0",
94 "android.hidl.base@1.0",
95 "android.hidl.memory.token@1.0",
96};
97
Steven Morelandaa6f7082020-02-07 16:08:17 -080098static const std::set<std::string> kKnownMissingAidl = {
Steven Morelandaa6f7082020-02-07 16:08:17 -080099 // types-only packages, which never expect a default implementation
100 "android.hardware.common.NativeHandle",
101 "android.hardware.graphics.common.ExtendableType",
David Zeuthen39748432020-02-12 11:02:56 -0500102
103 // These KeyMaster types are in an AIDL types-only HAL because they're used
104 // by the Identity Credential AIDL HAL. Remove this when fully porting
105 // KeyMaster to AIDL.
106 "android.hardware.keymaster.HardwareAuthToken",
107 "android.hardware.keymaster.HardwareAuthenticatorType",
108 "android.hardware.keymaster.Timestamp",
Steven Morelandaa6f7082020-02-07 16:08:17 -0800109};
110
Steven Morelandd6df9182019-10-08 18:21:35 -0700111// AOSP packages which are never considered
Steven Morelandaa6f7082020-02-07 16:08:17 -0800112static bool isHidlPackageWhitelist(const FQName& name) {
Steven Morelandd6df9182019-10-08 18:21:35 -0700113 static std::vector<std::string> gAospExclude = {
114 // packages not implemented now that we never expect to be implemented
115 "android.hardware.tests",
Emilian Peev206aaf82019-11-19 08:15:31 -0800116 // packages not registered with hwservicemanager, usually sub-interfaces
117 "android.hardware.camera.device",
Steven Morelandd6df9182019-10-08 18:21:35 -0700118 };
119 for (const std::string& package : gAospExclude) {
120 if (name.inPackage(package)) {
121 return true;
122 }
123 }
124 return false;
125}
126
Steven Morelandaa6f7082020-02-07 16:08:17 -0800127static bool isAospHidlInterface(const FQName& name) {
128 static const std::vector<std::string> kAospPackages = {
Steven Morelandd6df9182019-10-08 18:21:35 -0700129 "android.hidl",
130 "android.hardware",
131 "android.frameworks",
132 "android.system",
133 };
Steven Morelandaa6f7082020-02-07 16:08:17 -0800134 for (const std::string& package : kAospPackages) {
135 if (name.inPackage(package) && !isHidlPackageWhitelist(name)) {
Steven Morelandd6df9182019-10-08 18:21:35 -0700136 return true;
137 }
138 }
139 return false;
140}
141
Steven Morelandaa6f7082020-02-07 16:08:17 -0800142static std::set<FQName> allTreeHidlInterfaces() {
Steven Morelandd6df9182019-10-08 18:21:35 -0700143 std::set<FQName> ret;
144 for (const auto& iface : HidlInterfaceMetadata::all()) {
145 FQName f;
146 CHECK(f.setTo(iface.name)) << iface.name;
147 ret.insert(f);
148 }
149 return ret;
150}
151
Steven Morelandaa6f7082020-02-07 16:08:17 -0800152static std::set<FQName> allHidlManifestInterfaces() {
Steven Morelandd6df9182019-10-08 18:21:35 -0700153 std::set<FQName> ret;
154 auto setInserter = [&] (const vintf::ManifestInstance& i) -> bool {
155 if (i.format() != vintf::HalFormat::HIDL) {
Steven Morelandd6df9182019-10-08 18:21:35 -0700156 return true; // continue
157 }
158 ret.insert(i.getFqInstance().getFqName());
159 return true; // continue
160 };
161 vintf::VintfObject::GetDeviceHalManifest()->forEachInstance(setInserter);
162 vintf::VintfObject::GetFrameworkHalManifest()->forEachInstance(setInserter);
163 return ret;
164}
165
Steven Morelandaa6f7082020-02-07 16:08:17 -0800166static bool isAospAidlInterface(const std::string& name) {
167 return base::StartsWith(name, "android.") &&
Steven Moreland9177c632020-02-12 11:16:09 -0800168 !base::StartsWith(name, "android.automotive.") &&
169 !base::StartsWith(name, "android.hardware.automotive.");
Steven Morelandaa6f7082020-02-07 16:08:17 -0800170}
171
172static std::set<std::string> allAidlManifestInterfaces() {
173 std::set<std::string> ret;
174 auto setInserter = [&] (const vintf::ManifestInstance& i) -> bool {
175 if (i.format() != vintf::HalFormat::AIDL) {
176 return true; // continue
177 }
178 ret.insert(i.package() + "." + i.interface());
179 return true; // continue
180 };
181 vintf::VintfObject::GetDeviceHalManifest()->forEachInstance(setInserter);
182 vintf::VintfObject::GetFrameworkHalManifest()->forEachInstance(setInserter);
183 return ret;
184}
185
186TEST(Hal, AllHidlInterfacesAreInAosp) {
187 for (const FQName& name : allHidlManifestInterfaces()) {
188 EXPECT_TRUE(isAospHidlInterface(name)) << name.string();
Steven Morelandd6df9182019-10-08 18:21:35 -0700189 }
190}
191
Steven Morelandaa6f7082020-02-07 16:08:17 -0800192TEST(Hal, HidlInterfacesImplemented) {
Steven Moreland089942a2019-11-19 11:24:05 -0800193 // instances -> major version -> minor versions
Steven Morelandd6df9182019-10-08 18:21:35 -0700194 std::map<std::string, std::map<size_t, std::set<size_t>>> unimplemented;
195
Steven Morelandaa6f7082020-02-07 16:08:17 -0800196 for (const FQName& f : allTreeHidlInterfaces()) {
197 if (!isAospHidlInterface(f)) continue;
Steven Morelandd6df9182019-10-08 18:21:35 -0700198
199 unimplemented[f.package()][f.getPackageMajorVersion()].insert(f.getPackageMinorVersion());
200 }
201
Steven Moreland089942a2019-11-19 11:24:05 -0800202 // we'll be removing items from this which we know are missing
203 // in order to be left with those elements which we thought we
204 // knew were missing but are actually present
Steven Morelandaa6f7082020-02-07 16:08:17 -0800205 std::set<std::string> thoughtMissing = kKnownMissingHidl;
Steven Moreland089942a2019-11-19 11:24:05 -0800206
Steven Morelandaa6f7082020-02-07 16:08:17 -0800207 for (const FQName& f : allHidlManifestInterfaces()) {
Steven Moreland089942a2019-11-19 11:24:05 -0800208 if (thoughtMissing.erase(f.getPackageAndVersion().string()) > 0) {
Steven Morelandaa6f7082020-02-07 16:08:17 -0800209 std::cout << "[ WARNING ] Instance in missing list, but available: "
210 << f.string() << std::endl;
Steven Moreland089942a2019-11-19 11:24:05 -0800211 }
212
Steven Morelandd6df9182019-10-08 18:21:35 -0700213 std::set<size_t>& minors = unimplemented[f.package()][f.getPackageMajorVersion()];
214 size_t minor = f.getPackageMinorVersion();
215
216 auto it = minors.find(minor);
217 if (it == minors.end()) continue;
218
219 // if 1.2 is implemented, also considere 1.0, 1.1 implemented
220 minors.erase(minors.begin(), std::next(it));
221 }
222
223 for (const auto& [package, minorsPerMajor] : unimplemented) {
224 for (const auto& [major, minors] : minorsPerMajor) {
225 if (minors.empty()) continue;
226
227 size_t maxMinor = *minors.rbegin();
228
229 FQName missing;
230 ASSERT_TRUE(missing.setTo(package, major, maxMinor));
231
Steven Moreland089942a2019-11-19 11:24:05 -0800232 if (thoughtMissing.erase(missing.string()) > 0) continue;
Steven Morelandd6df9182019-10-08 18:21:35 -0700233
234 ADD_FAILURE() << "Missing implementation from " << missing.string();
235 }
236 }
Steven Moreland089942a2019-11-19 11:24:05 -0800237
238 for (const std::string& missing : thoughtMissing) {
Steven Morelandaa6f7082020-02-07 16:08:17 -0800239 std::cout << "[ WARNING ] Instance in missing list and cannot find it anywhere: "
240 << missing << std::endl;
241 }
242}
243
244TEST(Hal, AllAidlInterfacesAreInAosp) {
245 for (const std::string& name : allAidlManifestInterfaces()) {
246 EXPECT_TRUE(isAospAidlInterface(name)) << name;
247 }
248}
249
250TEST(Hal, AidlInterfacesImplemented) {
251 std::set<std::string> manifest = allAidlManifestInterfaces();
252 std::set<std::string> thoughtMissing = kKnownMissingAidl;
253
254 for (const auto& iface : AidlInterfaceMetadata::all()) {
255 ASSERT_FALSE(iface.types.empty()) << iface.name; // sanity
256 if (!isAospAidlInterface(iface.name)) continue;
257 if (iface.stability != "vintf") continue;
258
259 bool hasRegistration = false;
260 bool knownMissing = false;
261 for (const std::string& type : iface.types) {
262 if (manifest.erase(type) > 0) hasRegistration = true;
263 if (thoughtMissing.erase(type) > 0) knownMissing = true;
264 }
265
266 if (knownMissing) {
267 if (hasRegistration) {
268 std::cout << "[ WARNING ] Interface in missing list, but available: " << iface.name
269 << " which declares the following types:\n "
270 << base::Join(iface.types, "\n ") << std::endl;
271 }
272
273 continue;
274 }
275
276 EXPECT_TRUE(hasRegistration) << iface.name << " which declares the following types:\n "
277 << base::Join(iface.types, "\n ") << std::endl;
278 }
279
280 for (const std::string& iface : thoughtMissing) {
281 std::cout << "[ WARNING ] Interface in manifest list and cannot find it anywhere: "
282 << iface << std::endl;
283 }
284
285 for (const std::string& iface : manifest) {
286 std::cout << "[ WARNING ] Can't find manifest entry in tree: " << iface << std::endl;
Steven Moreland089942a2019-11-19 11:24:05 -0800287 }
Steven Morelandd6df9182019-10-08 18:21:35 -0700288}