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 // SystemVendorTest test cases that runs on P+ vendor. 18 19 #include "SystemVendorTest.h" 20 21 #include <android-base/logging.h> 22 #include <android-base/strings.h> 23 #include <vintf/VintfObject.h> 24 #include <iostream> 25 26 #include "SingleManifestTest.h" 27 28 namespace android { 29 namespace vintf { 30 namespace testing { 31 32 using std::endl; 33 34 // Tests that vendor and framework are compatible. 35 TEST_F(SystemVendorTest, VendorFrameworkCompatibility) { 36 string error; 37 38 EXPECT_TRUE(vendor_manifest_->checkCompatibility( 39 *VintfObject::GetFrameworkCompatibilityMatrix(), &error)) 40 << error; 41 42 EXPECT_TRUE(fwk_manifest_->checkCompatibility( 43 *VintfObject::GetDeviceCompatibilityMatrix(), &error)) 44 << error; 45 46 // AVB version is not a compliance requirement. 47 EXPECT_TRUE(VintfObject::GetRuntimeInfo()->checkCompatibility( 48 *VintfObject::GetFrameworkCompatibilityMatrix(), &error, 49 ::android::vintf::DISABLE_AVB_CHECK)) 50 << error; 51 52 EXPECT_EQ(android::vintf::COMPATIBLE, 53 VintfObject::CheckCompatibility( 54 {}, &error, ::android::vintf::DISABLE_AVB_CHECK)) 55 << error; 56 } 57 58 template <typename D, typename S> 59 static void insert(D *d, const S &s) { 60 d->insert(s.begin(), s.end()); 61 } 62 63 // This needs to be tested besides 64 // SingleManifestTest.ServedHwbinderHalsAreInManifest because some HALs may 65 // refuse to provide its PID, and the partition cannot be inferred. 66 TEST_F(SystemVendorTest, ServedHwbinderHalsAreInManifest) { 67 std::set<std::string> manifest_hwbinder_hals_; 68 69 insert(&manifest_hwbinder_hals_, GetHwbinderHals(fwk_manifest_)); 70 insert(&manifest_hwbinder_hals_, GetHwbinderHals(vendor_manifest_)); 71 72 Return<void> ret = default_manager_->list([&](const auto &list) { 73 for (const auto &name : list) { 74 // TODO(b/73774955): use standardized parsing code for fqinstancename 75 if (std::string(name).find(IBase::descriptor) == 0) continue; 76 77 EXPECT_NE(manifest_hwbinder_hals_.find(name), 78 manifest_hwbinder_hals_.end()) 79 << name << " is being served, but it is not in a manifest."; 80 } 81 }); 82 EXPECT_TRUE(ret.isOk()); 83 } 84 85 // Tests that deprecated HALs are not served, unless a higher, non-deprecated 86 // minor version is served. 87 TEST_F(SystemVendorTest, NoDeprecatedHalsOnManager) { 88 if (vendor_manifest_->level() == Level::UNSPECIFIED) { 89 // On a legacy device, no HALs are deprecated. 90 return; 91 } 92 93 // Predicate for whether an instance is served through service manager. 94 // Return {instance name, highest minor version} 95 // where "highest minor version" is the first element in getInterfaceChain() 96 // that has the same "package", major version as "version" and "interface" 97 // but a higher minor version than "version". 98 VintfObject::ListInstances list_instances = [this](const string &package, 99 Version version, 100 const string &interface, 101 const vector<string> 102 &instance_hints) { 103 vector<std::pair<string, Version>> ret; 104 105 FQName fq_name(package, to_string(version), interface); 106 for (auto transport : {Transport::HWBINDER, Transport::PASSTHROUGH}) { 107 const vector<string> &instance_names = 108 transport == Transport::HWBINDER 109 ? GetInstanceNames(default_manager_, fq_name) 110 : instance_hints; 111 112 for (auto instance : instance_names) { 113 auto service = 114 GetHalService(fq_name, instance, transport, false /* log */); 115 if (service == nullptr) { 116 if (transport == Transport::PASSTHROUGH) { 117 CHECK(std::find(instance_hints.begin(), instance_hints.end(), 118 instance) != instance_hints.end()) 119 << "existing <instance>'s: [" 120 << android::base::Join(instance_hints, ",") 121 << "] but instance=" << instance; 122 continue; // name is from instance_hints, so ignore 123 } 124 ADD_FAILURE() 125 << fq_name.string() << "/" << instance 126 << " is registered to hwservicemanager but cannot be retrieved."; 127 continue; 128 } 129 130 vector<string> iface_chain = GetInterfaceChain(service); 131 bool done = false; 132 for (const auto &fq_interface_str : iface_chain) { 133 FQName fq_interface; 134 if (!FQName::parse(fq_interface_str, &fq_interface)) { 135 // Allow CheckDeprecation to proceed with some sensible default 136 ADD_FAILURE() << "'" << fq_interface_str 137 << "' (returned by getInterfaceChain())" 138 << "is not a valid fully-qualified name."; 139 ret.push_back(std::make_pair(instance, version)); 140 done = true; 141 continue; 142 } 143 if (fq_interface.package() == package) { 144 Version fq_version{fq_interface.getPackageMajorVersion(), 145 fq_interface.getPackageMinorVersion()}; 146 if (fq_version.minorAtLeast(version)) { 147 ret.push_back(std::make_pair(instance, fq_version)); 148 done = true; 149 break; 150 } 151 } 152 } 153 if (!done) { 154 // Allow CheckDeprecation to proceed with some sensible default 155 ADD_FAILURE() << "getInterfaceChain() does not return interface name " 156 << "with at least minor version'" << package << "@" 157 << version << "'; returned values are [" 158 << android::base::Join(iface_chain, ", ") << "]"; 159 ret.push_back(std::make_pair(instance, version)); 160 } 161 } 162 } 163 164 return ret; 165 }; 166 string error; 167 EXPECT_EQ(android::vintf::NO_DEPRECATED_HALS, 168 VintfObject::CheckDeprecation(list_instances, &error)) 169 << error; 170 } 171 172 static std::vector<HalManifestPtr> GetTestManifests() { 173 return { 174 VintfObject::GetFrameworkHalManifest(), 175 }; 176 } 177 178 INSTANTIATE_TEST_CASE_P(FrameworkManifest, SingleManifestTest, 179 ::testing::ValuesIn(GetTestManifests())); 180 181 } // namespace testing 182 } // namespace vintf 183 } // namespace android 184