Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 1 | /* |
| 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 Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 16 | #include <aidl/metadata.h> |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 17 | #include <android-base/logging.h> |
Steven Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 18 | #include <android-base/strings.h> |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 19 | #include <gtest/gtest.h> |
| 20 | #include <hidl/metadata.h> |
| 21 | #include <hidl-util/FQName.h> |
| 22 | #include <vintf/VintfObject.h> |
| 23 | |
| 24 | using namespace android; |
| 25 | |
Steven Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 26 | static const std::set<std::string> kKnownMissingHidl = { |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 27 | "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 Naganov | 6dc07d2 | 2020-01-24 11:58:37 -0800 | [diff] [blame] | 33 | "android.hardware.audio@5.0", |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 34 | "android.hardware.audio.effect@2.0", |
| 35 | "android.hardware.audio.effect@4.0", |
Mikhail Naganov | 6dc07d2 | 2020-01-24 11:58:37 -0800 | [diff] [blame] | 36 | "android.hardware.audio.effect@5.0", |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 37 | "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 Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 47 | "android.hardware.camera.provider@2.5", |
Henry Fang | ee99f19 | 2019-10-25 12:54:01 -0700 | [diff] [blame] | 48 | "android.hardware.cas@1.2", |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 49 | "android.hardware.cas.native@1.0", |
| 50 | "android.hardware.confirmationui@1.0", |
| 51 | "android.hardware.contexthub@1.0", |
Steven Moreland | 043028c | 2020-02-06 15:37:03 -0800 | [diff] [blame] | 52 | "android.hardware.configstore@1.1", // deprecated, see b/149050985, b/149050733 |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 53 | "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 Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 65 | "android.hardware.ir@1.0", |
| 66 | "android.hardware.keymaster@3.0", |
Ivailo Karamanolev | 01e6821 | 2020-02-12 19:27:54 +0100 | [diff] [blame] | 67 | "android.hardware.light@2.0", |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 68 | "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 Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 74 | "android.hardware.radio.deprecated@1.0", |
| 75 | "android.hardware.renderscript@1.0", |
Jack Yu | fadc551 | 2019-12-20 11:30:11 +0800 | [diff] [blame] | 76 | "android.hardware.secure_element@1.2", |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 77 | "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 Moreland | 8a9f5c5 | 2019-11-10 17:53:41 -0800 | [diff] [blame] | 88 | "android.hardware.vibrator@1.3", |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 89 | "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 Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 99 | static const std::set<std::string> kKnownMissingAidl = { |
Steven Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 100 | // types-only packages, which never expect a default implementation |
| 101 | "android.hardware.common.NativeHandle", |
| 102 | "android.hardware.graphics.common.ExtendableType", |
David Zeuthen | 3974843 | 2020-02-12 11:02:56 -0500 | [diff] [blame] | 103 | |
| 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 Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 110 | }; |
| 111 | |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 112 | // AOSP packages which are never considered |
Steven Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 113 | static bool isHidlPackageWhitelist(const FQName& name) { |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 114 | static std::vector<std::string> gAospExclude = { |
| 115 | // packages not implemented now that we never expect to be implemented |
| 116 | "android.hardware.tests", |
Emilian Peev | 206aaf8 | 2019-11-19 08:15:31 -0800 | [diff] [blame] | 117 | // packages not registered with hwservicemanager, usually sub-interfaces |
| 118 | "android.hardware.camera.device", |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 119 | }; |
| 120 | for (const std::string& package : gAospExclude) { |
| 121 | if (name.inPackage(package)) { |
| 122 | return true; |
| 123 | } |
| 124 | } |
| 125 | return false; |
| 126 | } |
| 127 | |
Steven Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 128 | static bool isAospHidlInterface(const FQName& name) { |
| 129 | static const std::vector<std::string> kAospPackages = { |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 130 | "android.hidl", |
| 131 | "android.hardware", |
| 132 | "android.frameworks", |
| 133 | "android.system", |
| 134 | }; |
Steven Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 135 | for (const std::string& package : kAospPackages) { |
| 136 | if (name.inPackage(package) && !isHidlPackageWhitelist(name)) { |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 137 | return true; |
| 138 | } |
| 139 | } |
| 140 | return false; |
| 141 | } |
| 142 | |
Steven Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 143 | static std::set<FQName> allTreeHidlInterfaces() { |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 144 | 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 Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 153 | static std::set<FQName> allHidlManifestInterfaces() { |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 154 | std::set<FQName> ret; |
| 155 | auto setInserter = [&] (const vintf::ManifestInstance& i) -> bool { |
| 156 | if (i.format() != vintf::HalFormat::HIDL) { |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 157 | 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 Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 167 | static bool isAospAidlInterface(const std::string& name) { |
| 168 | return base::StartsWith(name, "android.") && |
Steven Moreland | 9177c63 | 2020-02-12 11:16:09 -0800 | [diff] [blame] | 169 | !base::StartsWith(name, "android.automotive.") && |
| 170 | !base::StartsWith(name, "android.hardware.automotive."); |
Steven Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | static 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 | |
| 187 | TEST(Hal, AllHidlInterfacesAreInAosp) { |
| 188 | for (const FQName& name : allHidlManifestInterfaces()) { |
| 189 | EXPECT_TRUE(isAospHidlInterface(name)) << name.string(); |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
Steven Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 193 | TEST(Hal, HidlInterfacesImplemented) { |
Steven Moreland | 089942a | 2019-11-19 11:24:05 -0800 | [diff] [blame] | 194 | // instances -> major version -> minor versions |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 195 | std::map<std::string, std::map<size_t, std::set<size_t>>> unimplemented; |
| 196 | |
Steven Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 197 | for (const FQName& f : allTreeHidlInterfaces()) { |
| 198 | if (!isAospHidlInterface(f)) continue; |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 199 | |
| 200 | unimplemented[f.package()][f.getPackageMajorVersion()].insert(f.getPackageMinorVersion()); |
| 201 | } |
| 202 | |
Steven Moreland | 089942a | 2019-11-19 11:24:05 -0800 | [diff] [blame] | 203 | // 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 Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 206 | std::set<std::string> thoughtMissing = kKnownMissingHidl; |
Steven Moreland | 089942a | 2019-11-19 11:24:05 -0800 | [diff] [blame] | 207 | |
Steven Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 208 | for (const FQName& f : allHidlManifestInterfaces()) { |
Steven Moreland | 089942a | 2019-11-19 11:24:05 -0800 | [diff] [blame] | 209 | if (thoughtMissing.erase(f.getPackageAndVersion().string()) > 0) { |
Steven Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 210 | std::cout << "[ WARNING ] Instance in missing list, but available: " |
| 211 | << f.string() << std::endl; |
Steven Moreland | 089942a | 2019-11-19 11:24:05 -0800 | [diff] [blame] | 212 | } |
| 213 | |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 214 | 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 Moreland | 089942a | 2019-11-19 11:24:05 -0800 | [diff] [blame] | 233 | if (thoughtMissing.erase(missing.string()) > 0) continue; |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 234 | |
| 235 | ADD_FAILURE() << "Missing implementation from " << missing.string(); |
| 236 | } |
| 237 | } |
Steven Moreland | 089942a | 2019-11-19 11:24:05 -0800 | [diff] [blame] | 238 | |
| 239 | for (const std::string& missing : thoughtMissing) { |
Steven Moreland | aa6f708 | 2020-02-07 16:08:17 -0800 | [diff] [blame] | 240 | std::cout << "[ WARNING ] Instance in missing list and cannot find it anywhere: " |
| 241 | << missing << std::endl; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | TEST(Hal, AllAidlInterfacesAreInAosp) { |
| 246 | for (const std::string& name : allAidlManifestInterfaces()) { |
| 247 | EXPECT_TRUE(isAospAidlInterface(name)) << name; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | TEST(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 Moreland | 089942a | 2019-11-19 11:24:05 -0800 | [diff] [blame] | 288 | } |
Steven Moreland | d6df918 | 2019-10-08 18:21:35 -0700 | [diff] [blame] | 289 | } |