| /* |
| * Copyright (C) 2019 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| #include <android-base/logging.h> |
| #include <gtest/gtest.h> |
| #include <hidl/metadata.h> |
| #include <hidl-util/FQName.h> |
| #include <vintf/VintfObject.h> |
| |
| using namespace android; |
| |
| static const std::set<std::string> kKnownMissing = { |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| "[email protected]", |
| }; |
| |
| // AOSP packages which are never considered |
| static bool isPackageWhitelist(const FQName& name) { |
| static std::vector<std::string> gAospExclude = { |
| // packages not implemented now that we never expect to be implemented |
| "android.hardware.tests", |
| // packages not registered with hwservicemanager, usually sub-interfaces |
| "android.hardware.camera.device", |
| }; |
| for (const std::string& package : gAospExclude) { |
| if (name.inPackage(package)) { |
| return true; |
| } |
| } |
| return false; |
| } |
| |
| static bool isAospInterface(const FQName& name) { |
| static std::vector<std::string> gAospPackages = { |
| "android.hidl", |
| "android.hardware", |
| "android.frameworks", |
| "android.system", |
| }; |
| for (const std::string& package : gAospPackages) { |
| if (name.inPackage(package) && !isPackageWhitelist(name)) { |
| return true; |
| } |
| } |
| return false; |
| } |
| |
| static std::set<FQName> allTreeInterfaces() { |
| std::set<FQName> ret; |
| for (const auto& iface : HidlInterfaceMetadata::all()) { |
| FQName f; |
| CHECK(f.setTo(iface.name)) << iface.name; |
| ret.insert(f); |
| } |
| return ret; |
| } |
| |
| static std::set<FQName> allManifestInstances() { |
| std::set<FQName> ret; |
| auto setInserter = [&] (const vintf::ManifestInstance& i) -> bool { |
| if (i.format() != vintf::HalFormat::HIDL) { |
| std::cout << "[ WARNING ] Not checking non-HIDL instance: " << i.description() << std::endl; |
| return true; // continue |
| } |
| ret.insert(i.getFqInstance().getFqName()); |
| return true; // continue |
| }; |
| vintf::VintfObject::GetDeviceHalManifest()->forEachInstance(setInserter); |
| vintf::VintfObject::GetFrameworkHalManifest()->forEachInstance(setInserter); |
| return ret; |
| } |
| |
| TEST(Hidl, IsAospDevice) { |
| for (const FQName& name : allManifestInstances()) { |
| EXPECT_TRUE(isAospInterface(name)) << name.string(); |
| } |
| } |
| |
| TEST(Hidl, InterfacesImplemented) { |
| // instances -> major version -> minor versions |
| std::map<std::string, std::map<size_t, std::set<size_t>>> unimplemented; |
| |
| for (const FQName& f : allTreeInterfaces()) { |
| if (!isAospInterface(f)) continue; |
| |
| unimplemented[f.package()][f.getPackageMajorVersion()].insert(f.getPackageMinorVersion()); |
| } |
| |
| // we'll be removing items from this which we know are missing |
| // in order to be left with those elements which we thought we |
| // knew were missing but are actually present |
| std::set<std::string> thoughtMissing = kKnownMissing; |
| |
| for (const FQName& f : allManifestInstances()) { |
| if (thoughtMissing.erase(f.getPackageAndVersion().string()) > 0) { |
| std::cout << "[ WARNING ] Instance in missing list, but available: " << f.string() << std::endl; |
| } |
| |
| std::set<size_t>& minors = unimplemented[f.package()][f.getPackageMajorVersion()]; |
| size_t minor = f.getPackageMinorVersion(); |
| |
| auto it = minors.find(minor); |
| if (it == minors.end()) continue; |
| |
| // if 1.2 is implemented, also considere 1.0, 1.1 implemented |
| minors.erase(minors.begin(), std::next(it)); |
| } |
| |
| for (const auto& [package, minorsPerMajor] : unimplemented) { |
| for (const auto& [major, minors] : minorsPerMajor) { |
| if (minors.empty()) continue; |
| |
| size_t maxMinor = *minors.rbegin(); |
| |
| FQName missing; |
| ASSERT_TRUE(missing.setTo(package, major, maxMinor)); |
| |
| if (thoughtMissing.erase(missing.string()) > 0) continue; |
| |
| ADD_FAILURE() << "Missing implementation from " << missing.string(); |
| } |
| } |
| |
| for (const std::string& missing : thoughtMissing) { |
| std::cout << "[ WARNING ] Instance in missing list, and cannot find it anywhere: " << missing << std::endl; |
| } |
| } |