1 /* 2 * Copyright (C) 2017 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 // This needs to be on top of the file to work. 18 #include "gmock-logging-compat.h" 19 20 #include <stdio.h> 21 #include <unistd.h> 22 23 #include <android-base/file.h> 24 #include <android-base/logging.h> 25 #include <android-base/stringprintf.h> 26 #include <android-base/strings.h> 27 #include <gtest/gtest.h> 28 #include <hidl-util/FQName.h> 29 30 #include <vintf/VintfObject.h> 31 #include <vintf/parse_string.h> 32 #include <vintf/parse_xml.h> 33 #include "constants-private.h" 34 #include "parse_xml_internal.h" 35 #include "test_constants.h" 36 #include "utils-fake.h" 37 38 using namespace ::testing; 39 using namespace std::literals; 40 41 using android::FqInstance; 42 43 static AssertionResult In(const std::string& sub, const std::string& str) { 44 return (str.find(sub) != std::string::npos ? AssertionSuccess() : AssertionFailure()) 45 << "Value is " << str; 46 } 47 #define EXPECT_IN(sub, str) EXPECT_TRUE(In((sub), (str))) 48 #define EXPECT_NOT_IN(sub, str) EXPECT_FALSE(In((sub), (str))) 49 50 namespace android { 51 namespace vintf { 52 namespace testing { 53 54 using namespace ::android::vintf::details; 55 56 // clang-format off 57 58 // 59 // Set of Xml1 metadata compatible with each other. 60 // 61 62 const std::string systemMatrixXml1 = 63 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n" 64 " <hal format=\"hidl\" optional=\"false\">\n" 65 " <name>android.hardware.camera</name>\n" 66 " <version>2.0-5</version>\n" 67 " <version>3.4-16</version>\n" 68 " </hal>\n" 69 " <hal format=\"hidl\" optional=\"false\">\n" 70 " <name>android.hardware.nfc</name>\n" 71 " <version>1.0</version>\n" 72 " <version>2.0</version>\n" 73 " </hal>\n" 74 " <hal format=\"hidl\" optional=\"true\">\n" 75 " <name>android.hardware.foo</name>\n" 76 " <version>1.0</version>\n" 77 " </hal>\n" 78 " <kernel version=\"3.18.31\"></kernel>\n" 79 " <sepolicy>\n" 80 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n" 81 " <sepolicy-version>25.5</sepolicy-version>\n" 82 " <sepolicy-version>26.0-3</sepolicy-version>\n" 83 " </sepolicy>\n" 84 " <avb>\n" 85 " <vbmeta-version>0.0</vbmeta-version>\n" 86 " </avb>\n" 87 "</compatibility-matrix>\n"; 88 89 const std::string vendorManifestXml1 = 90 "<manifest " + kMetaVersionStr + " type=\"device\">\n" 91 " <hal format=\"hidl\">\n" 92 " <name>android.hardware.camera</name>\n" 93 " <transport>hwbinder</transport>\n" 94 " <version>3.5</version>\n" 95 " <interface>\n" 96 " <name>IBetterCamera</name>\n" 97 " <instance>camera</instance>\n" 98 " </interface>\n" 99 " <interface>\n" 100 " <name>ICamera</name>\n" 101 " <instance>default</instance>\n" 102 " <instance>legacy/0</instance>\n" 103 " </interface>\n" 104 " </hal>\n" 105 " <hal format=\"hidl\">\n" 106 " <name>android.hardware.nfc</name>\n" 107 " <transport>hwbinder</transport>\n" 108 " <version>1.0</version>\n" 109 " <interface>\n" 110 " <name>INfc</name>\n" 111 " <instance>nfc_nci</instance>\n" 112 " </interface>\n" 113 " </hal>\n" 114 " <hal format=\"hidl\">\n" 115 " <name>android.hardware.nfc</name>\n" 116 " <transport>hwbinder</transport>\n" 117 " <version>2.0</version>\n" 118 " <interface>\n" 119 " <name>INfc</name>\n" 120 " <instance>default</instance>\n" 121 " <instance>nfc_nci</instance>\n" 122 " </interface>\n" 123 " </hal>\n" 124 " <sepolicy>\n" 125 " <version>25.5</version>\n" 126 " </sepolicy>\n" 127 "</manifest>\n"; 128 129 const std::string systemManifestXml1 = 130 "<manifest " + kMetaVersionStr + " type=\"framework\">\n" 131 " <hal format=\"hidl\">\n" 132 " <name>android.hidl.manager</name>\n" 133 " <transport>hwbinder</transport>\n" 134 " <version>1.0</version>\n" 135 " <interface>\n" 136 " <name>IServiceManager</name>\n" 137 " <instance>default</instance>\n" 138 " </interface>\n" 139 " </hal>\n" 140 " <vndk>\n" 141 " <version>25.0.5</version>\n" 142 " <library>libbase.so</library>\n" 143 " <library>libjpeg.so</library>\n" 144 " </vndk>\n" 145 "</manifest>\n"; 146 147 const std::string vendorMatrixXml1 = 148 "<compatibility-matrix " + kMetaVersionStr + " type=\"device\">\n" 149 " <hal format=\"hidl\" optional=\"false\">\n" 150 " <name>android.hidl.manager</name>\n" 151 " <version>1.0</version>\n" 152 " </hal>\n" 153 " <vndk>\n" 154 " <version>25.0.1-5</version>\n" 155 " <library>libbase.so</library>\n" 156 " <library>libjpeg.so</library>\n" 157 " </vndk>\n" 158 "</compatibility-matrix>\n"; 159 160 // 161 // Set of Xml2 metadata compatible with each other. 162 // 163 164 const std::string systemMatrixXml2 = 165 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n" 166 " <hal format=\"hidl\">\n" 167 " <name>android.hardware.foo</name>\n" 168 " <version>1.0</version>\n" 169 " </hal>\n" 170 " <kernel version=\"3.18.31\"></kernel>\n" 171 " <sepolicy>\n" 172 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n" 173 " <sepolicy-version>25.5</sepolicy-version>\n" 174 " <sepolicy-version>26.0-3</sepolicy-version>\n" 175 " </sepolicy>\n" 176 " <avb>\n" 177 " <vbmeta-version>0.0</vbmeta-version>\n" 178 " </avb>\n" 179 "</compatibility-matrix>\n"; 180 181 const std::string vendorManifestXml2 = 182 "<manifest " + kMetaVersionStr + " type=\"device\">" 183 " <hal>" 184 " <name>android.hardware.foo</name>" 185 " <transport>hwbinder</transport>" 186 " <version>1.0</version>" 187 " </hal>" 188 " <sepolicy>\n" 189 " <version>25.5</version>\n" 190 " </sepolicy>\n" 191 "</manifest>"; 192 193 // 194 // Set of framework matrices of different FCM version. 195 // 196 197 const std::string systemMatrixLevel1 = 198 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n" 199 " <hal format=\"hidl\" optional=\"true\">\n" 200 " <name>android.hardware.major</name>\n" 201 " <version>1.0</version>\n" 202 " <interface>\n" 203 " <name>IMajor</name>\n" 204 " <instance>default</instance>\n" 205 " </interface>\n" 206 " </hal>\n" 207 " <hal format=\"hidl\" optional=\"true\">\n" 208 " <name>android.hardware.removed</name>\n" 209 " <version>1.0</version>\n" 210 " <interface>\n" 211 " <name>IRemoved</name>\n" 212 " <instance>default</instance>\n" 213 " </interface>\n" 214 " </hal>\n" 215 " <hal format=\"hidl\" optional=\"true\">\n" 216 " <name>android.hardware.minor</name>\n" 217 " <version>1.0</version>\n" 218 " <interface>\n" 219 " <name>IMinor</name>\n" 220 " <instance>default</instance>\n" 221 " <instance>legacy</instance>\n" 222 " </interface>\n" 223 " </hal>\n" 224 "</compatibility-matrix>\n"; 225 226 const std::string systemMatrixLevel2 = 227 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"2\">\n" 228 " <hal format=\"hidl\" optional=\"true\">\n" 229 " <name>android.hardware.major</name>\n" 230 " <version>2.0</version>\n" 231 " <interface>\n" 232 " <name>IMajor</name>\n" 233 " <instance>default</instance>\n" 234 " </interface>\n" 235 " </hal>\n" 236 " <hal format=\"hidl\" optional=\"true\">\n" 237 " <name>android.hardware.minor</name>\n" 238 " <version>1.1</version>\n" 239 " <interface>\n" 240 " <name>IMinor</name>\n" 241 " <instance>default</instance>\n" 242 " </interface>\n" 243 " </hal>\n" 244 "</compatibility-matrix>\n"; 245 246 // 247 // Smaller product FCMs at different levels to test that framework and product 248 // FCMs are combined when checking deprecation. 249 // 250 251 const std::string productMatrixLevel1 = 252 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n" 253 " <hal format=\"hidl\" optional=\"true\">\n" 254 " <name>product.removed</name>\n" 255 " <version>1.0</version>\n" 256 " <interface>\n" 257 " <name>IRemoved</name>\n" 258 " <instance>default</instance>\n" 259 " </interface>\n" 260 " </hal>\n" 261 " <hal format=\"hidl\" optional=\"true\">\n" 262 " <name>product.minor</name>\n" 263 " <version>1.0</version>\n" 264 " <interface>\n" 265 " <name>IMinor</name>\n" 266 " <instance>default</instance>\n" 267 " </interface>\n" 268 " </hal>\n" 269 "</compatibility-matrix>\n"; 270 271 const std::string productMatrixLevel2 = 272 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"2\">\n" 273 " <hal format=\"hidl\" optional=\"true\">\n" 274 " <name>product.minor</name>\n" 275 " <version>1.1</version>\n" 276 " <interface>\n" 277 " <name>IMinor</name>\n" 278 " <instance>default</instance>\n" 279 " </interface>\n" 280 " </hal>\n" 281 "</compatibility-matrix>\n"; 282 283 // 284 // Set of framework matrices of different FCM version with regex. 285 // 286 287 const static std::vector<std::string> systemMatrixRegexXmls = { 288 // 1.xml 289 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n" 290 " <hal format=\"hidl\" optional=\"false\">\n" 291 " <name>android.hardware.regex</name>\n" 292 " <version>1.0-1</version>\n" 293 " <interface>\n" 294 " <name>IRegex</name>\n" 295 " <instance>default</instance>\n" 296 " <instance>special/1.0</instance>\n" 297 " <regex-instance>regex/1.0/[0-9]+</regex-instance>\n" 298 " <regex-instance>regex_common/[0-9]+</regex-instance>\n" 299 " </interface>\n" 300 " </hal>\n" 301 "</compatibility-matrix>\n", 302 // 2.xml 303 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"2\">\n" 304 " <hal format=\"hidl\" optional=\"false\">\n" 305 " <name>android.hardware.regex</name>\n" 306 " <version>1.1-2</version>\n" 307 " <interface>\n" 308 " <name>IRegex</name>\n" 309 " <instance>default</instance>\n" 310 " <instance>special/1.1</instance>\n" 311 " <regex-instance>regex/1.1/[0-9]+</regex-instance>\n" 312 " <regex-instance>[a-z]+_[a-z]+/[0-9]+</regex-instance>\n" 313 " </interface>\n" 314 " </hal>\n" 315 "</compatibility-matrix>\n", 316 // 3.xml 317 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"3\">\n" 318 " <hal format=\"hidl\" optional=\"false\">\n" 319 " <name>android.hardware.regex</name>\n" 320 " <version>2.0</version>\n" 321 " <interface>\n" 322 " <name>IRegex</name>\n" 323 " <instance>default</instance>\n" 324 " <instance>special/2.0</instance>\n" 325 " <regex-instance>regex/2.0/[0-9]+</regex-instance>\n" 326 " <regex-instance>regex_[a-z]+/[0-9]+</regex-instance>\n" 327 " </interface>\n" 328 " </hal>\n" 329 "</compatibility-matrix>\n"}; 330 331 // 332 // Set of metadata at different FCM version that has requirements 333 // 334 335 const std::vector<std::string> systemMatrixRequire = { 336 // 1.xml 337 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n" 338 " <hal format=\"hidl\" optional=\"false\">\n" 339 " <name>android.hardware.foo</name>\n" 340 " <version>1.0</version>\n" 341 " <interface>\n" 342 " <name>IFoo</name>\n" 343 " <instance>default</instance>\n" 344 " </interface>\n" 345 " </hal>\n" 346 "</compatibility-matrix>\n", 347 // 2.xml 348 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"2\">\n" 349 " <hal format=\"hidl\" optional=\"false\">\n" 350 " <name>android.hardware.bar</name>\n" 351 " <version>1.0</version>\n" 352 " <interface>\n" 353 " <name>IBar</name>\n" 354 " <instance>default</instance>\n" 355 " </interface>\n" 356 " </hal>\n" 357 "</compatibility-matrix>\n"}; 358 359 const std::string vendorManifestRequire1 = 360 "<manifest " + kMetaVersionStr + " type=\"device\" target-level=\"1\">\n" 361 " <hal format=\"hidl\">\n" 362 " <name>android.hardware.foo</name>\n" 363 " <transport>hwbinder</transport>\n" 364 " <fqname>@1.0::IFoo/default</fqname>\n" 365 " </hal>\n" 366 "</manifest>\n"; 367 368 const std::string vendorManifestRequire2 = 369 "<manifest " + kMetaVersionStr + " type=\"device\" target-level=\"2\">\n" 370 " <hal format=\"hidl\">\n" 371 " <name>android.hardware.bar</name>\n" 372 " <transport>hwbinder</transport>\n" 373 " <fqname>@1.0::IBar/default</fqname>\n" 374 " </hal>\n" 375 "</manifest>\n"; 376 377 // 378 // Set of metadata for kernel requirements 379 // 380 381 const std::string vendorManifestKernel318 = 382 "<manifest " + kMetaVersionStr + " type=\"device\">\n" 383 " <kernel version=\"3.18.999\" />\n" 384 " <sepolicy>\n" 385 " <version>25.5</version>\n" 386 " </sepolicy>\n" 387 "</manifest>\n"; 388 389 const std::string systemMatrixKernel318 = 390 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n" 391 " <kernel version=\"3.18.999\"></kernel>\n" 392 " <sepolicy>\n" 393 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n" 394 " <sepolicy-version>25.5</sepolicy-version>\n" 395 " </sepolicy>\n" 396 "</compatibility-matrix>\n"; 397 398 class VintfObjectTestBase : public ::testing::Test { 399 protected: 400 MockFileSystem& fetcher() { 401 return static_cast<MockFileSystem&>(*vintfObject->getFileSystem()); 402 } 403 MockPropertyFetcher& propertyFetcher() { 404 return static_cast<MockPropertyFetcher&>(*vintfObject->getPropertyFetcher()); 405 } 406 407 void useEmptyFileSystem() { 408 // By default, no files exist in the file system. 409 // Use EXPECT_CALL because more specific expectation of fetch and listFiles will come along. 410 EXPECT_CALL(fetcher(), listFiles(_, _, _)).Times(AnyNumber()) 411 .WillRepeatedly(Return(::android::NAME_NOT_FOUND)); 412 EXPECT_CALL(fetcher(), fetch(_, _)).Times(AnyNumber()) 413 .WillRepeatedly(Return(::android::NAME_NOT_FOUND)); 414 } 415 416 // Setup the MockFileSystem used by the fetchAllInformation template 417 // so it returns the given metadata info instead of fetching from device. 418 void setupMockFetcher(const std::string& vendorManifestXml, const std::string& systemMatrixXml, 419 const std::string& systemManifestXml, const std::string& vendorMatrixXml) { 420 421 useEmptyFileSystem(); 422 423 ON_CALL(fetcher(), fetch(StrEq(kVendorLegacyManifest), _)) 424 .WillByDefault( 425 Invoke([vendorManifestXml](const std::string& path, std::string& fetched) { 426 (void)path; 427 fetched = vendorManifestXml; 428 return 0; 429 })); 430 ON_CALL(fetcher(), fetch(StrEq(kSystemManifest), _)) 431 .WillByDefault( 432 Invoke([systemManifestXml](const std::string& path, std::string& fetched) { 433 (void)path; 434 fetched = systemManifestXml; 435 return 0; 436 })); 437 ON_CALL(fetcher(), fetch(StrEq(kVendorLegacyMatrix), _)) 438 .WillByDefault(Invoke([vendorMatrixXml](const std::string& path, std::string& fetched) { 439 (void)path; 440 fetched = vendorMatrixXml; 441 return 0; 442 })); 443 ON_CALL(fetcher(), fetch(StrEq(kSystemLegacyMatrix), _)) 444 .WillByDefault(Invoke([systemMatrixXml](const std::string& path, std::string& fetched) { 445 (void)path; 446 fetched = systemMatrixXml; 447 return 0; 448 })); 449 } 450 451 virtual void SetUp() { 452 vintfObject = VintfObject::Builder() 453 .setFileSystem(std::make_unique<NiceMock<MockFileSystem>>()) 454 .setRuntimeInfoFactory(std::make_unique<NiceMock<MockRuntimeInfoFactory>>( 455 std::make_shared<NiceMock<MockRuntimeInfo>>())) 456 .setPropertyFetcher(std::make_unique<NiceMock<MockPropertyFetcher>>()) 457 .build(); 458 } 459 virtual void TearDown() { 460 Mock::VerifyAndClear(&fetcher()); 461 } 462 463 void expectVendorManifest(size_t times = 1) { 464 EXPECT_CALL(fetcher(), fetch(StrEq(kVendorLegacyManifest), _)).Times(times); 465 } 466 467 void expectSystemManifest(size_t times = 1) { 468 EXPECT_CALL(fetcher(), fetch(StrEq(kSystemManifest), _)).Times(times); 469 } 470 471 void expectVendorMatrix(size_t times = 1) { 472 EXPECT_CALL(fetcher(), fetch(StrEq(kVendorLegacyMatrix), _)).Times(times); 473 } 474 475 void expectSystemMatrix(size_t times = 1) { 476 EXPECT_CALL(fetcher(), fetch(StrEq(kSystemLegacyMatrix), _)).Times(times); 477 } 478 479 // Expect that a file exist and should be fetched once. 480 void expectFetch(const std::string& path, const std::string& content) { 481 EXPECT_CALL(fetcher(), fetch(StrEq(path), _)) 482 .WillOnce(Invoke([content](const auto&, auto& out) { 483 out = content; 484 return ::android::OK; 485 })); 486 } 487 488 // Expect that a file exist and can be fetched 0 or more times. 489 void expectFetchRepeatedly(const std::string& path, const std::string& content) { 490 EXPECT_CALL(fetcher(), fetch(StrEq(path), _)) 491 .Times(AnyNumber()) 492 .WillRepeatedly(Invoke([content](const auto&, auto& out) { 493 out = content; 494 return ::android::OK; 495 })); 496 } 497 498 // Expect that the file should never be fetched (whether it exists or not). 499 void expectNeverFetch(const std::string& path) { 500 EXPECT_CALL(fetcher(), fetch(StrEq(path), _)).Times(0); 501 } 502 503 // Expect that the file does not exist, and can be fetched 0 or more times. 504 template <typename Matcher> 505 void expectFileNotExist(const Matcher& matcher) { 506 EXPECT_CALL(fetcher(), fetch(matcher, _)) 507 .Times(AnyNumber()) 508 .WillRepeatedly(Return(::android::NAME_NOT_FOUND)); 509 } 510 511 MockRuntimeInfoFactory& runtimeInfoFactory() { 512 return static_cast<MockRuntimeInfoFactory&>(*vintfObject->getRuntimeInfoFactory()); 513 } 514 515 std::unique_ptr<VintfObject> vintfObject; 516 }; 517 518 // Test fixture that provides compatible metadata from the mock device. 519 class VintfObjectCompatibleTest : public VintfObjectTestBase { 520 protected: 521 virtual void SetUp() { 522 VintfObjectTestBase::SetUp(); 523 setupMockFetcher(vendorManifestXml1, systemMatrixXml1, systemManifestXml1, vendorMatrixXml1); 524 } 525 }; 526 527 // Tests that local info is checked. 528 TEST_F(VintfObjectCompatibleTest, TestDeviceCompatibility) { 529 std::string error; 530 531 expectVendorManifest(); 532 expectSystemManifest(); 533 expectVendorMatrix(); 534 expectSystemMatrix(); 535 536 int result = vintfObject->checkCompatibility(&error); 537 538 ASSERT_EQ(result, 0) << "Fail message:" << error.c_str(); 539 // Check that nothing was ignored. 540 ASSERT_STREQ(error.c_str(), ""); 541 } 542 543 // Test fixture that provides incompatible metadata from the mock device. 544 class VintfObjectIncompatibleTest : public VintfObjectTestBase { 545 protected: 546 virtual void SetUp() { 547 VintfObjectTestBase::SetUp(); 548 setupMockFetcher(vendorManifestXml1, systemMatrixXml2, systemManifestXml1, vendorMatrixXml1); 549 } 550 }; 551 552 // Fetch all metadata from device and ensure that it fails. 553 TEST_F(VintfObjectIncompatibleTest, TestDeviceCompatibility) { 554 std::string error; 555 556 expectVendorManifest(); 557 expectSystemManifest(); 558 expectVendorMatrix(); 559 expectSystemMatrix(); 560 561 int result = vintfObject->checkCompatibility(&error); 562 563 ASSERT_EQ(result, 1) << "Should have failed:" << error.c_str(); 564 } 565 566 const std::string vendorManifestKernelFcm = 567 "<manifest " + kMetaVersionStr + " type=\"device\">\n" 568 " <kernel version=\"3.18.999\" target-level=\"92\"/>\n" 569 "</manifest>\n"; 570 571 // Test fixture that provides compatible metadata from the mock device. 572 class VintfObjectRuntimeInfoTest : public VintfObjectTestBase { 573 protected: 574 virtual void SetUp() { 575 VintfObjectTestBase::SetUp(); 576 } 577 virtual void TearDown() { 578 Mock::VerifyAndClear(&runtimeInfoFactory()); 579 Mock::VerifyAndClear(runtimeInfoFactory().getInfo().get()); 580 } 581 }; 582 583 TEST_F(VintfObjectRuntimeInfoTest, GetRuntimeInfo) { 584 setupMockFetcher(vendorManifestKernelFcm, "", "", ""); 585 expectVendorManifest(); 586 InSequence s; 587 588 EXPECT_CALL(*runtimeInfoFactory().getInfo(), 589 fetchAllInformation(RuntimeInfo::FetchFlag::CPU_VERSION)); 590 EXPECT_CALL(*runtimeInfoFactory().getInfo(), fetchAllInformation(RuntimeInfo::FetchFlag::NONE)); 591 EXPECT_CALL( 592 *runtimeInfoFactory().getInfo(), 593 fetchAllInformation(RuntimeInfo::FetchFlag::ALL & ~RuntimeInfo::FetchFlag::CPU_VERSION)); 594 EXPECT_CALL(*runtimeInfoFactory().getInfo(), fetchAllInformation(RuntimeInfo::FetchFlag::NONE)); 595 596 EXPECT_NE(nullptr, vintfObject->getRuntimeInfo( 597 RuntimeInfo::FetchFlag::CPU_VERSION)); 598 EXPECT_NE(nullptr, vintfObject->getRuntimeInfo( 599 RuntimeInfo::FetchFlag::CPU_VERSION)); 600 EXPECT_NE(nullptr, vintfObject->getRuntimeInfo( 601 RuntimeInfo::FetchFlag::ALL)); 602 EXPECT_NE(nullptr, vintfObject->getRuntimeInfo( 603 RuntimeInfo::FetchFlag::ALL)); 604 } 605 606 TEST_F(VintfObjectRuntimeInfoTest, GetRuntimeInfoHost) { 607 runtimeInfoFactory().getInfo()->failNextFetch(); 608 EXPECT_EQ(nullptr, vintfObject->getRuntimeInfo(RuntimeInfo::FetchFlag::ALL)); 609 } 610 611 class VintfObjectKernelFcmTest : public VintfObjectTestBase, 612 public WithParamInterface<std::tuple<bool, bool>> { 613 protected: 614 virtual void SetUp() { 615 VintfObjectTestBase::SetUp(); 616 auto [isHost, hasDeviceManifest] = GetParam(); 617 if (hasDeviceManifest) { 618 setupMockFetcher(vendorManifestKernelFcm, "", "", ""); 619 expectVendorManifest(); 620 } 621 622 if (isHost) { 623 runtimeInfoFactory().getInfo()->failNextFetch(); 624 } else { 625 runtimeInfoFactory().getInfo()->setNextFetchKernelLevel(Level{92}); 626 } 627 } 628 629 Level expectedKernelFcm() { 630 auto [isHost, hasDeviceManifest] = GetParam(); 631 return !isHost || hasDeviceManifest ? Level{92} : Level::UNSPECIFIED; 632 } 633 }; 634 635 TEST_P(VintfObjectKernelFcmTest, GetKernelLevel) { 636 ASSERT_EQ(expectedKernelFcm(), vintfObject->getKernelLevel()); 637 } 638 639 INSTANTIATE_TEST_SUITE_P(KernelFcm, VintfObjectKernelFcmTest, 640 ::testing::Combine(::testing::Bool(), ::testing::Bool())); 641 642 // Test fixture that provides incompatible metadata from the mock device. 643 class VintfObjectTest : public VintfObjectTestBase { 644 protected: 645 virtual void SetUp() { 646 VintfObjectTestBase::SetUp(); 647 useEmptyFileSystem(); 648 } 649 }; 650 651 // Test framework compatibility matrix is combined at runtime 652 TEST_F(VintfObjectTest, FrameworkCompatibilityMatrixCombine) { 653 EXPECT_CALL(fetcher(), listFiles(StrEq(kSystemVintfDir), _, _)) 654 .WillOnce(Invoke([](const auto&, auto* out, auto*) { 655 *out = { 656 "compatibility_matrix.1.xml", 657 "compatibility_matrix.empty.xml", 658 }; 659 return ::android::OK; 660 })); 661 expectFetch(kSystemVintfDir + "compatibility_matrix.1.xml"s, 662 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\"/>"); 663 expectFetch(kSystemVintfDir + "compatibility_matrix.empty.xml"s, 664 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\"/>"); 665 expectFileNotExist(StrEq(kProductMatrix)); 666 expectFetch(kVendorManifest, "<manifest " + kMetaVersionStr + " type=\"device\" />\n"); 667 expectNeverFetch(kSystemLegacyMatrix); 668 669 EXPECT_NE(nullptr, vintfObject->getFrameworkCompatibilityMatrix()); 670 } 671 672 // Test product compatibility matrix is fetched 673 TEST_F(VintfObjectTest, ProductCompatibilityMatrix) { 674 EXPECT_CALL(fetcher(), listFiles(StrEq(kSystemVintfDir), _, _)) 675 .WillOnce(Invoke([](const auto&, auto* out, auto*) { 676 *out = { 677 "compatibility_matrix.1.xml", 678 "compatibility_matrix.empty.xml", 679 }; 680 return ::android::OK; 681 })); 682 EXPECT_CALL(fetcher(), listFiles(StrEq(kProductVintfDir), _, _)) 683 .WillRepeatedly(Invoke([](const auto&, auto* out, auto*) { 684 *out = {android::base::Basename(kProductMatrix)}; 685 return ::android::OK; 686 })); 687 expectFetch(kSystemVintfDir + "compatibility_matrix.1.xml"s, 688 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\"/>"); 689 expectFetch(kSystemVintfDir + "compatibility_matrix.empty.xml"s, 690 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\"/>"); 691 expectFetch(kProductMatrix, 692 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n" 693 " <hal format=\"hidl\" optional=\"true\">\n" 694 " <name>android.hardware.foo</name>\n" 695 " <version>1.0</version>\n" 696 " <interface>\n" 697 " <name>IFoo</name>\n" 698 " <instance>default</instance>\n" 699 " </interface>\n" 700 " </hal>\n" 701 "</compatibility-matrix>\n"); 702 expectFetch(kVendorManifest, "<manifest " + kMetaVersionStr + " type=\"device\" />\n"); 703 expectNeverFetch(kSystemLegacyMatrix); 704 705 auto fcm = vintfObject->getFrameworkCompatibilityMatrix(); 706 ASSERT_NE(nullptr, fcm); 707 708 FqInstance expectInstance; 709 EXPECT_TRUE(expectInstance.setTo("android.hardware.foo@1.0::IFoo/default")); 710 bool found = false; 711 fcm->forEachHidlInstance([&found, &expectInstance](const auto& matrixInstance) { 712 found |= matrixInstance.isSatisfiedBy(expectInstance); 713 return !found; // continue if not found 714 }); 715 EXPECT_TRUE(found) << "android.hardware.foo@1.0::IFoo/default should be found in matrix:\n" 716 << toXml(*fcm); 717 } 718 719 const std::string vendorEtcManifest = 720 "<manifest " + kMetaVersionStr + " type=\"device\">\n" 721 " <hal format=\"hidl\">\n" 722 " <name>android.hardware.foo</name>\n" 723 " <transport>hwbinder</transport>\n" 724 " <version>1.0</version>\n" 725 " <version>2.0</version>\n" 726 " <interface>\n" 727 " <name>IVendorEtc</name>\n" 728 " <instance>default</instance>\n" 729 " </interface>\n" 730 " </hal>\n" 731 "</manifest>\n"; 732 733 const std::string vendorManifest = 734 "<manifest " + kMetaVersionStr + " type=\"device\">\n" 735 " <hal format=\"hidl\">\n" 736 " <name>android.hardware.foo</name>\n" 737 " <transport>hwbinder</transport>\n" 738 " <version>1.0</version>\n" 739 " <interface>\n" 740 " <name>IVendor</name>\n" 741 " <instance>default</instance>\n" 742 " </interface>\n" 743 " </hal>\n" 744 "</manifest>\n"; 745 746 const std::string odmProductManifest = 747 "<manifest " + kMetaVersionStr + " type=\"device\">\n" 748 " <hal format=\"hidl\" override=\"true\">\n" 749 " <name>android.hardware.foo</name>\n" 750 " <transport>hwbinder</transport>\n" 751 " <version>1.1</version>\n" 752 " <interface>\n" 753 " <name>IOdmProduct</name>\n" 754 " <instance>default</instance>\n" 755 " </interface>\n" 756 " </hal>\n" 757 "</manifest>\n"; 758 759 const std::string odmManifest = 760 "<manifest " + kMetaVersionStr + " type=\"device\">\n" 761 " <hal format=\"hidl\" override=\"true\">\n" 762 " <name>android.hardware.foo</name>\n" 763 " <transport>hwbinder</transport>\n" 764 " <version>1.1</version>\n" 765 " <interface>\n" 766 " <name>IOdm</name>\n" 767 " <instance>default</instance>\n" 768 " </interface>\n" 769 " </hal>\n" 770 "</manifest>\n"; 771 772 bool containsVendorManifest(const std::shared_ptr<const HalManifest>& p) { 773 return !p->getHidlInstances("android.hardware.foo", {1, 0}, "IVendor").empty(); 774 } 775 776 bool containsVendorEtcManifest(const std::shared_ptr<const HalManifest>& p) { 777 return !p->getHidlInstances("android.hardware.foo", {2, 0}, "IVendorEtc").empty(); 778 } 779 780 bool vendorEtcManifestOverridden(const std::shared_ptr<const HalManifest>& p) { 781 return p->getHidlInstances("android.hardware.foo", {1, 0}, "IVendorEtc").empty(); 782 } 783 784 bool containsOdmManifest(const std::shared_ptr<const HalManifest>& p) { 785 return !p->getHidlInstances("android.hardware.foo", {1, 1}, "IOdm").empty(); 786 } 787 788 bool containsOdmProductManifest(const std::shared_ptr<const HalManifest>& p) { 789 return !p->getHidlInstances("android.hardware.foo", {1, 1}, "IOdmProduct").empty(); 790 } 791 792 class DeviceManifestTest : public VintfObjectTestBase { 793 protected: 794 // Expect that /vendor/etc/vintf/manifest.xml is fetched. 795 void expectVendorManifest() { expectFetch(kVendorManifest, vendorEtcManifest); } 796 // /vendor/etc/vintf/manifest.xml does not exist. 797 void noVendorManifest() { expectFileNotExist(StrEq(kVendorManifest)); } 798 // Expect some ODM manifest is fetched. 799 void expectOdmManifest() { 800 expectFetch(kOdmManifest, odmManifest); 801 } 802 void noOdmManifest() { expectFileNotExist(StartsWith("/odm/")); } 803 std::shared_ptr<const HalManifest> get() { 804 return vintfObject->getDeviceHalManifest(); 805 } 806 }; 807 808 // Test /vendor/etc/vintf/manifest.xml + ODM manifest 809 TEST_F(DeviceManifestTest, Combine1) { 810 expectVendorManifest(); 811 expectOdmManifest(); 812 auto p = get(); 813 ASSERT_NE(nullptr, p); 814 EXPECT_TRUE(containsVendorEtcManifest(p)); 815 EXPECT_TRUE(vendorEtcManifestOverridden(p)); 816 EXPECT_TRUE(containsOdmManifest(p)); 817 EXPECT_FALSE(containsVendorManifest(p)); 818 } 819 820 // Test /vendor/etc/vintf/manifest.xml 821 TEST_F(DeviceManifestTest, Combine2) { 822 expectVendorManifest(); 823 noOdmManifest(); 824 auto p = get(); 825 ASSERT_NE(nullptr, p); 826 EXPECT_TRUE(containsVendorEtcManifest(p)); 827 EXPECT_FALSE(vendorEtcManifestOverridden(p)); 828 EXPECT_FALSE(containsOdmManifest(p)); 829 EXPECT_FALSE(containsVendorManifest(p)); 830 } 831 832 // Test ODM manifest 833 TEST_F(DeviceManifestTest, Combine3) { 834 noVendorManifest(); 835 expectOdmManifest(); 836 auto p = get(); 837 ASSERT_NE(nullptr, p); 838 EXPECT_FALSE(containsVendorEtcManifest(p)); 839 EXPECT_TRUE(vendorEtcManifestOverridden(p)); 840 EXPECT_TRUE(containsOdmManifest(p)); 841 EXPECT_FALSE(containsVendorManifest(p)); 842 } 843 844 // Test /vendor/manifest.xml 845 TEST_F(DeviceManifestTest, Combine4) { 846 noVendorManifest(); 847 noOdmManifest(); 848 expectFetch(kVendorLegacyManifest, vendorManifest); 849 auto p = get(); 850 ASSERT_NE(nullptr, p); 851 EXPECT_FALSE(containsVendorEtcManifest(p)); 852 EXPECT_TRUE(vendorEtcManifestOverridden(p)); 853 EXPECT_FALSE(containsOdmManifest(p)); 854 EXPECT_TRUE(containsVendorManifest(p)); 855 } 856 857 class OdmManifestTest : public VintfObjectTestBase, 858 public ::testing::WithParamInterface<const char*> { 859 protected: 860 virtual void SetUp() override { 861 VintfObjectTestBase::SetUp(); 862 // Assume /vendor/etc/vintf/manifest.xml does not exist to simplify 863 // testing logic. 864 expectFileNotExist(StrEq(kVendorManifest)); 865 // Expect that the legacy /vendor/manifest.xml is never fetched. 866 expectNeverFetch(kVendorLegacyManifest); 867 // Assume no files exist under /odm/ unless otherwise specified. 868 expectFileNotExist(StartsWith("/odm/")); 869 870 // set SKU 871 productModel = GetParam(); 872 ON_CALL(propertyFetcher(), getProperty("ro.boot.product.hardware.sku", _)) 873 .WillByDefault(Return(productModel)); 874 } 875 std::shared_ptr<const HalManifest> get() { 876 return vintfObject->getDeviceHalManifest(); 877 } 878 std::string productModel; 879 }; 880 881 TEST_P(OdmManifestTest, OdmProductManifest) { 882 if (productModel.empty()) return; 883 expectFetch(kOdmVintfDir + "manifest_"s + productModel + ".xml", odmProductManifest); 884 // /odm/etc/vintf/manifest.xml should not be fetched when the product variant exists. 885 expectNeverFetch(kOdmManifest); 886 auto p = get(); 887 ASSERT_NE(nullptr, p); 888 EXPECT_TRUE(containsOdmProductManifest(p)); 889 } 890 891 TEST_P(OdmManifestTest, OdmManifest) { 892 expectFetch(kOdmManifest, odmManifest); 893 auto p = get(); 894 ASSERT_NE(nullptr, p); 895 EXPECT_TRUE(containsOdmManifest(p)); 896 } 897 898 TEST_P(OdmManifestTest, OdmLegacyProductManifest) { 899 if (productModel.empty()) return; 900 expectFetch(kOdmLegacyVintfDir + "manifest_"s + productModel + ".xml", odmProductManifest); 901 // /odm/manifest.xml should not be fetched when the product variant exists. 902 expectNeverFetch(kOdmLegacyManifest); 903 auto p = get(); 904 ASSERT_NE(nullptr, p); 905 EXPECT_TRUE(containsOdmProductManifest(p)); 906 } 907 908 TEST_P(OdmManifestTest, OdmLegacyManifest) { 909 expectFetch(kOdmLegacyManifest, odmManifest); 910 auto p = get(); 911 ASSERT_NE(nullptr, p); 912 EXPECT_TRUE(containsOdmManifest(p)); 913 } 914 915 INSTANTIATE_TEST_SUITE_P(OdmManifest, OdmManifestTest, ::testing::Values("", "fake_sku")); 916 917 struct CheckedFqInstance : FqInstance { 918 CheckedFqInstance(const char* s) : CheckedFqInstance(std::string(s)) {} 919 CheckedFqInstance(const std::string& s) { CHECK(setTo(s)) << s; } 920 921 Version getVersion() const { return FqInstance::getVersion(); } 922 }; 923 924 static VintfObject::ListInstances getInstanceListFunc( 925 const std::vector<CheckedFqInstance>& instances) { 926 return [instances](const std::string& package, Version version, const std::string& interface, 927 const auto& /* instanceHint */) { 928 std::vector<std::pair<std::string, Version>> ret; 929 for (auto&& existing : instances) { 930 if (existing.getPackage() == package && existing.getVersion().minorAtLeast(version) && 931 existing.getInterface() == interface) { 932 ret.push_back(std::make_pair(existing.getInstance(), existing.getVersion())); 933 } 934 } 935 936 return ret; 937 }; 938 } 939 940 class DeprecateTest : public VintfObjectTestBase { 941 protected: 942 virtual void SetUp() override { 943 VintfObjectTestBase::SetUp(); 944 useEmptyFileSystem(); 945 EXPECT_CALL(fetcher(), listFiles(StrEq(kSystemVintfDir), _, _)) 946 .WillRepeatedly(Invoke([](const auto&, auto* out, auto*) { 947 *out = { 948 "compatibility_matrix.1.xml", 949 "compatibility_matrix.2.xml", 950 }; 951 return ::android::OK; 952 })); 953 expectFetchRepeatedly(kSystemVintfDir + "compatibility_matrix.1.xml"s, systemMatrixLevel1); 954 expectFetchRepeatedly(kSystemVintfDir + "compatibility_matrix.2.xml"s, systemMatrixLevel2); 955 EXPECT_CALL(fetcher(), listFiles(StrEq(kProductVintfDir), _, _)) 956 .WillRepeatedly(Invoke([](const auto&, auto* out, auto*) { 957 *out = { 958 "compatibility_matrix.1.xml", 959 "compatibility_matrix.2.xml", 960 }; 961 return ::android::OK; 962 })); 963 expectFetchRepeatedly(kProductVintfDir + "compatibility_matrix.1.xml"s, 964 productMatrixLevel1); 965 expectFetchRepeatedly(kProductVintfDir + "compatibility_matrix.2.xml"s, 966 productMatrixLevel2); 967 expectFileNotExist(StrEq(kProductMatrix)); 968 expectNeverFetch(kSystemLegacyMatrix); 969 970 expectFetchRepeatedly(kVendorManifest, 971 "<manifest " + kMetaVersionStr + " type=\"device\" target-level=\"2\"/>"); 972 expectFileNotExist(StartsWith("/odm/")); 973 974 // Update the device manifest cache because CheckDeprecate does not fetch 975 // device manifest again if cache exist. 976 vintfObject->getDeviceHalManifest(); 977 } 978 979 }; 980 981 TEST_F(DeprecateTest, CheckNoDeprecate) { 982 auto pred = getInstanceListFunc({ 983 "android.hardware.minor@1.1::IMinor/default", 984 "android.hardware.major@2.0::IMajor/default", 985 "product.minor@1.1::IMinor/default", 986 }); 987 std::string error; 988 EXPECT_EQ(NO_DEPRECATED_HALS, vintfObject->checkDeprecation(pred, {}, &error)) << error; 989 } 990 991 TEST_F(DeprecateTest, CheckRemovedSystem) { 992 auto pred = getInstanceListFunc({ 993 "android.hardware.removed@1.0::IRemoved/default", 994 "android.hardware.minor@1.1::IMinor/default", 995 "android.hardware.major@2.0::IMajor/default", 996 }); 997 std::string error; 998 EXPECT_EQ(DEPRECATED, vintfObject->checkDeprecation(pred, {}, &error)) 999 << "removed@1.0 should be deprecated. " << error; 1000 } 1001 1002 TEST_F(DeprecateTest, CheckRemovedProduct) { 1003 auto pred = getInstanceListFunc({ 1004 "product.removed@1.0::IRemoved/default", 1005 "product.minor@1.1::IMinor/default", 1006 }); 1007 std::string error; 1008 EXPECT_EQ(DEPRECATED, vintfObject->checkDeprecation(pred, {}, &error)) 1009 << "removed@1.0 should be deprecated. " << error; 1010 } 1011 1012 TEST_F(DeprecateTest, CheckMinorSystem) { 1013 auto pred = getInstanceListFunc({ 1014 "android.hardware.minor@1.0::IMinor/default", 1015 "android.hardware.major@2.0::IMajor/default", 1016 }); 1017 std::string error; 1018 EXPECT_EQ(DEPRECATED, vintfObject->checkDeprecation(pred, {}, &error)) 1019 << "minor@1.0 should be deprecated. " << error; 1020 } 1021 1022 TEST_F(DeprecateTest, CheckMinorProduct) { 1023 auto pred = getInstanceListFunc({ 1024 "product.minor@1.0::IMinor/default", 1025 }); 1026 std::string error; 1027 EXPECT_EQ(DEPRECATED, vintfObject->checkDeprecation(pred, {}, &error)) 1028 << "minor@1.0 should be deprecated. " << error; 1029 } 1030 1031 TEST_F(DeprecateTest, CheckMinorDeprecatedInstance1) { 1032 auto pred = getInstanceListFunc({ 1033 "android.hardware.minor@1.0::IMinor/legacy", 1034 "android.hardware.minor@1.1::IMinor/default", 1035 "android.hardware.major@2.0::IMajor/default", 1036 }); 1037 std::string error; 1038 EXPECT_EQ(DEPRECATED, vintfObject->checkDeprecation(pred, {}, &error)) 1039 << "minor@1.0::IMinor/legacy should be deprecated. " << error; 1040 } 1041 1042 TEST_F(DeprecateTest, CheckMinorDeprecatedInstance2) { 1043 auto pred = getInstanceListFunc({ 1044 "android.hardware.minor@1.1::IMinor/default", 1045 "android.hardware.minor@1.1::IMinor/legacy", 1046 "android.hardware.major@2.0::IMajor/default", 1047 }); 1048 std::string error; 1049 EXPECT_EQ(DEPRECATED, vintfObject->checkDeprecation(pred, {}, &error)) 1050 << "minor@1.1::IMinor/legacy should be deprecated. " << error; 1051 } 1052 1053 TEST_F(DeprecateTest, CheckMajor1) { 1054 auto pred = getInstanceListFunc({ 1055 "android.hardware.minor@1.1::IMinor/default", 1056 "android.hardware.major@1.0::IMajor/default", 1057 "android.hardware.major@2.0::IMajor/default", 1058 }); 1059 std::string error; 1060 EXPECT_EQ(DEPRECATED, vintfObject->checkDeprecation(pred, {}, &error)) 1061 << "major@1.0 should be deprecated. " << error; 1062 } 1063 1064 TEST_F(DeprecateTest, CheckMajor2) { 1065 auto pred = getInstanceListFunc({ 1066 "android.hardware.minor@1.1::IMinor/default", 1067 "android.hardware.major@1.0::IMajor/default", 1068 }); 1069 std::string error; 1070 EXPECT_EQ(DEPRECATED, vintfObject->checkDeprecation(pred, {}, &error)) 1071 << "major@1.0 should be deprecated. " << error; 1072 } 1073 1074 TEST_F(DeprecateTest, HidlMetadataNotDeprecate) { 1075 auto pred = getInstanceListFunc({ 1076 "android.hardware.major@1.0::IMajor/default", 1077 "android.hardware.major@2.0::IMajor/default", 1078 }); 1079 std::string error; 1080 EXPECT_EQ(DEPRECATED, vintfObject->checkDeprecation(pred, {}, &error)) 1081 << "major@1.0 should be deprecated. " << error; 1082 std::vector<HidlInterfaceMetadata> hidlMetadata{ 1083 {"android.hardware.major@2.0::IMajor", {"android.hardware.major@1.0::IMajor"}}, 1084 }; 1085 EXPECT_EQ(NO_DEPRECATED_HALS, vintfObject->checkDeprecation(pred, hidlMetadata, &error)) 1086 << "major@1.0 should not be deprecated because it extends from 2.0: " << error; 1087 } 1088 1089 TEST_F(DeprecateTest, HidlMetadataDeprecate) { 1090 auto pred = getInstanceListFunc({ 1091 "android.hardware.major@1.0::IMajor/default", 1092 }); 1093 std::string error; 1094 EXPECT_EQ(DEPRECATED, vintfObject->checkDeprecation(pred, {}, &error)) 1095 << "major@1.0 should be deprecated. " << error; 1096 std::vector<HidlInterfaceMetadata> hidlMetadata{ 1097 {"android.hardware.major@2.0::IMajor", {"android.hardware.major@1.0::IMajor"}}, 1098 }; 1099 EXPECT_EQ(DEPRECATED, vintfObject->checkDeprecation(pred, hidlMetadata, &error)) 1100 << "major@1.0 should be deprecated. " << error; 1101 } 1102 1103 class MultiMatrixTest : public VintfObjectTestBase { 1104 protected: 1105 void SetUp() override { 1106 VintfObjectTestBase::SetUp(); 1107 useEmptyFileSystem(); 1108 } 1109 static std::string getFileName(size_t i) { 1110 return "compatibility_matrix." + std::to_string(static_cast<Level>(i)) + ".xml"; 1111 } 1112 void SetUpMockSystemMatrices(const std::vector<std::string>& xmls) { 1113 SetUpMockMatrices(kSystemVintfDir, xmls); 1114 } 1115 void SetUpMockMatrices(const std::string& dir, const std::vector<std::string>& xmls) { 1116 EXPECT_CALL(fetcher(), listFiles(StrEq(dir), _, _)) 1117 .WillRepeatedly(Invoke([=](const auto&, auto* out, auto*) { 1118 size_t i = 1; 1119 for (const auto& content : xmls) { 1120 (void)content; 1121 out->push_back(getFileName(i)); 1122 ++i; 1123 } 1124 return ::android::OK; 1125 })); 1126 size_t i = 1; 1127 for (const auto& content : xmls) { 1128 expectFetchRepeatedly(dir + getFileName(i), content); 1129 ++i; 1130 } 1131 } 1132 void expectTargetFcmVersion(size_t level) { 1133 expectFetch(kVendorManifest, "<manifest " + kMetaVersionStr + " type=\"device\" target-level=\"" + 1134 to_string(static_cast<Level>(level)) + "\"/>"); 1135 vintfObject->getDeviceHalManifest(); 1136 } 1137 }; 1138 1139 class RegexTest : public MultiMatrixTest { 1140 protected: 1141 virtual void SetUp() { 1142 MultiMatrixTest::SetUp(); 1143 SetUpMockSystemMatrices(systemMatrixRegexXmls); 1144 } 1145 }; 1146 1147 TEST_F(RegexTest, CombineLevel1) { 1148 expectTargetFcmVersion(1); 1149 auto matrix = vintfObject->getFrameworkCompatibilityMatrix(); 1150 ASSERT_NE(nullptr, matrix); 1151 std::string xml = toXml(*matrix); 1152 1153 EXPECT_IN( 1154 " <hal format=\"hidl\" optional=\"false\">\n" 1155 " <name>android.hardware.regex</name>\n" 1156 " <version>1.0-2</version>\n" 1157 " <version>2.0</version>\n" 1158 " <interface>\n" 1159 " <name>IRegex</name>\n" 1160 " <instance>default</instance>\n" 1161 " </interface>\n" 1162 " </hal>\n", 1163 xml); 1164 EXPECT_IN( 1165 " <hal format=\"hidl\" optional=\"false\">\n" 1166 " <name>android.hardware.regex</name>\n" 1167 " <version>1.0-1</version>\n" 1168 " <interface>\n" 1169 " <name>IRegex</name>\n" 1170 " <instance>special/1.0</instance>\n" 1171 " <regex-instance>regex/1.0/[0-9]+</regex-instance>\n" 1172 " <regex-instance>regex_common/[0-9]+</regex-instance>\n" 1173 " </interface>\n" 1174 " </hal>\n", 1175 xml); 1176 EXPECT_IN( 1177 " <hal format=\"hidl\" optional=\"true\">\n" 1178 " <name>android.hardware.regex</name>\n" 1179 " <version>1.1-2</version>\n" 1180 " <interface>\n" 1181 " <name>IRegex</name>\n" 1182 " <instance>special/1.1</instance>\n" 1183 " <regex-instance>[a-z]+_[a-z]+/[0-9]+</regex-instance>\n" 1184 " <regex-instance>regex/1.1/[0-9]+</regex-instance>\n" 1185 " </interface>\n" 1186 " </hal>\n", 1187 xml); 1188 EXPECT_IN( 1189 " <hal format=\"hidl\" optional=\"true\">\n" 1190 " <name>android.hardware.regex</name>\n" 1191 " <version>2.0</version>\n" 1192 " <interface>\n" 1193 " <name>IRegex</name>\n" 1194 " <instance>special/2.0</instance>\n" 1195 " <regex-instance>regex/2.0/[0-9]+</regex-instance>\n" 1196 " <regex-instance>regex_[a-z]+/[0-9]+</regex-instance>\n" 1197 " </interface>\n" 1198 " </hal>\n", 1199 xml); 1200 } 1201 1202 TEST_F(RegexTest, CombineLevel2) { 1203 expectTargetFcmVersion(2); 1204 auto matrix = vintfObject->getFrameworkCompatibilityMatrix(); 1205 ASSERT_NE(nullptr, matrix); 1206 std::string xml = toXml(*matrix); 1207 1208 EXPECT_IN( 1209 " <hal format=\"hidl\" optional=\"false\">\n" 1210 " <name>android.hardware.regex</name>\n" 1211 " <version>1.1-2</version>\n" 1212 " <version>2.0</version>\n" 1213 " <interface>\n" 1214 " <name>IRegex</name>\n" 1215 " <instance>default</instance>\n" 1216 " </interface>\n" 1217 " </hal>\n", 1218 xml); 1219 EXPECT_IN( 1220 " <hal format=\"hidl\" optional=\"false\">\n" 1221 " <name>android.hardware.regex</name>\n" 1222 " <version>1.1-2</version>\n" 1223 " <interface>\n" 1224 " <name>IRegex</name>\n" 1225 " <instance>special/1.1</instance>\n" 1226 " <regex-instance>[a-z]+_[a-z]+/[0-9]+</regex-instance>\n" 1227 " <regex-instance>regex/1.1/[0-9]+</regex-instance>\n" 1228 " </interface>\n" 1229 " </hal>\n", 1230 xml); 1231 EXPECT_IN( 1232 " <hal format=\"hidl\" optional=\"true\">\n" 1233 " <name>android.hardware.regex</name>\n" 1234 " <version>2.0</version>\n" 1235 " <interface>\n" 1236 " <name>IRegex</name>\n" 1237 " <instance>special/2.0</instance>\n" 1238 " <regex-instance>regex/2.0/[0-9]+</regex-instance>\n" 1239 " <regex-instance>regex_[a-z]+/[0-9]+</regex-instance>\n" 1240 " </interface>\n" 1241 " </hal>\n", 1242 xml); 1243 } 1244 1245 TEST_F(RegexTest, DeprecateLevel2) { 1246 std::string error; 1247 expectTargetFcmVersion(2); 1248 1249 auto pred = getInstanceListFunc({ 1250 "android.hardware.regex@1.1::IRegex/default", 1251 "android.hardware.regex@1.1::IRegex/special/1.1", 1252 "android.hardware.regex@1.1::IRegex/regex/1.1/1", 1253 "android.hardware.regex@1.1::IRegex/regex_common/0", 1254 "android.hardware.regex@2.0::IRegex/default", 1255 }); 1256 EXPECT_EQ(NO_DEPRECATED_HALS, vintfObject->checkDeprecation(pred, {}, &error)) << error; 1257 1258 for (const auto& deprecated : { 1259 "android.hardware.regex@1.0::IRegex/default", 1260 "android.hardware.regex@1.0::IRegex/special/1.0", 1261 "android.hardware.regex@1.0::IRegex/regex/1.0/1", 1262 "android.hardware.regex@1.0::IRegex/regex_common/0", 1263 "android.hardware.regex@1.1::IRegex/special/1.0", 1264 "android.hardware.regex@1.1::IRegex/regex/1.0/1", 1265 }) { 1266 // 2.0/default ensures compatibility. 1267 pred = getInstanceListFunc({ 1268 deprecated, 1269 "android.hardware.regex@2.0::IRegex/default", 1270 }); 1271 error.clear(); 1272 EXPECT_EQ(DEPRECATED, vintfObject->checkDeprecation(pred, {}, &error)) 1273 << deprecated << " should be deprecated. " << error; 1274 } 1275 } 1276 1277 TEST_F(RegexTest, DeprecateLevel3) { 1278 std::string error; 1279 expectTargetFcmVersion(3); 1280 1281 auto pred = getInstanceListFunc({ 1282 "android.hardware.regex@2.0::IRegex/special/2.0", 1283 "android.hardware.regex@2.0::IRegex/regex/2.0/1", 1284 "android.hardware.regex@2.0::IRegex/default", 1285 }); 1286 EXPECT_EQ(NO_DEPRECATED_HALS, vintfObject->checkDeprecation(pred, {}, &error)) << error; 1287 1288 for (const auto& deprecated : { 1289 "android.hardware.regex@1.0::IRegex/default", 1290 "android.hardware.regex@1.0::IRegex/special/1.0", 1291 "android.hardware.regex@1.0::IRegex/regex/1.0/1", 1292 "android.hardware.regex@1.0::IRegex/regex_common/0", 1293 "android.hardware.regex@1.1::IRegex/special/1.0", 1294 "android.hardware.regex@1.1::IRegex/regex/1.0/1", 1295 "android.hardware.regex@1.1::IRegex/special/1.1", 1296 "android.hardware.regex@1.1::IRegex/regex/1.1/1", 1297 "android.hardware.regex@1.1::IRegex/regex_common/0", 1298 }) { 1299 // 2.0/default ensures compatibility. 1300 pred = getInstanceListFunc({ 1301 deprecated, 1302 "android.hardware.regex@2.0::IRegex/default", 1303 }); 1304 1305 error.clear(); 1306 EXPECT_EQ(DEPRECATED, vintfObject->checkDeprecation(pred, {}, &error)) 1307 << deprecated << " should be deprecated."; 1308 } 1309 } 1310 1311 // 1312 // Set of framework matrices of different FCM version with <kernel>. 1313 // 1314 1315 #define FAKE_KERNEL(__version__, __key__, __level__) \ 1316 " <kernel version=\"" __version__ "\" level=\"" #__level__ "\">\n" \ 1317 " <config>\n" \ 1318 " <key>CONFIG_" __key__ "</key>\n" \ 1319 " <value type=\"tristate\">y</value>\n" \ 1320 " </config>\n" \ 1321 " </kernel>\n" 1322 1323 const static std::vector<std::string> systemMatrixKernelXmls = { 1324 // 1.xml 1325 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n" 1326 FAKE_KERNEL("1.0.0", "A1", 1) 1327 FAKE_KERNEL("2.0.0", "B1", 1) 1328 "</compatibility-matrix>\n", 1329 // 2.xml 1330 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"2\">\n" 1331 FAKE_KERNEL("2.0.0", "B2", 2) 1332 FAKE_KERNEL("3.0.0", "C2", 2) 1333 FAKE_KERNEL("4.0.0", "D2", 2) 1334 "</compatibility-matrix>\n", 1335 // 3.xml 1336 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"3\">\n" 1337 FAKE_KERNEL("4.0.0", "D3", 3) 1338 FAKE_KERNEL("5.0.0", "E3", 3) 1339 "</compatibility-matrix>\n", 1340 // 4.xml 1341 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"4\">\n" 1342 FAKE_KERNEL("5.0.0", "E4", 4) 1343 FAKE_KERNEL("6.0.0", "F4", 4) 1344 "</compatibility-matrix>\n", 1345 // 5.xml 1346 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"5\">\n" 1347 FAKE_KERNEL("6.0.0", "F5", 5) 1348 FAKE_KERNEL("7.0.0", "G5", 5) 1349 "</compatibility-matrix>\n", 1350 }; 1351 1352 class KernelTest : public MultiMatrixTest { 1353 public: 1354 void expectKernelFcmVersion(size_t targetFcm, Level kernelFcm) { 1355 std::string xml = "<manifest " + kMetaVersionStr + " type=\"device\" target-level=\"" + 1356 to_string(static_cast<Level>(targetFcm)) + "\">\n"; 1357 if (kernelFcm != Level::UNSPECIFIED) { 1358 xml += " <kernel target-level=\"" + to_string(kernelFcm) + "\"/>\n"; 1359 } 1360 xml += "</manifest>"; 1361 expectFetch(kVendorManifest, xml); 1362 } 1363 }; 1364 1365 // Assume that we are developing level 2. Test that old <kernel> requirements should 1366 // not change and new <kernel> versions are added. 1367 TEST_F(KernelTest, Level1AndLevel2) { 1368 SetUpMockSystemMatrices({systemMatrixKernelXmls[0], systemMatrixKernelXmls[1]}); 1369 1370 expectTargetFcmVersion(1); 1371 auto matrix = vintfObject->getFrameworkCompatibilityMatrix(); 1372 ASSERT_NE(nullptr, matrix); 1373 std::string xml = toXml(*matrix); 1374 1375 EXPECT_IN(FAKE_KERNEL("1.0.0", "A1", 1), xml) << "\nOld requirements must not change."; 1376 EXPECT_IN(FAKE_KERNEL("2.0.0", "B1", 1), xml) << "\nOld requirements must not change."; 1377 EXPECT_IN(FAKE_KERNEL("3.0.0", "C2", 2), xml) << "\nShould see <kernel> from new matrices"; 1378 EXPECT_IN(FAKE_KERNEL("4.0.0", "D2", 2), xml) << "\nShould see <kernel> from new matrices"; 1379 1380 EXPECT_IN(FAKE_KERNEL("2.0.0", "B2", 2), xml) << "\nShould see <kernel> from new matrices"; 1381 } 1382 1383 // Assume that we are developing level 3. Test that old <kernel> requirements should 1384 // not change and new <kernel> versions are added. 1385 TEST_F(KernelTest, Level1AndMore) { 1386 SetUpMockSystemMatrices({systemMatrixKernelXmls}); 1387 1388 expectTargetFcmVersion(1); 1389 auto matrix = vintfObject->getFrameworkCompatibilityMatrix(); 1390 ASSERT_NE(nullptr, matrix); 1391 std::string xml = toXml(*matrix); 1392 1393 EXPECT_IN(FAKE_KERNEL("1.0.0", "A1", 1), xml) << "\nOld requirements must not change."; 1394 EXPECT_IN(FAKE_KERNEL("2.0.0", "B1", 1), xml) << "\nOld requirements must not change."; 1395 EXPECT_IN(FAKE_KERNEL("3.0.0", "C2", 2), xml) << "\nOld requirements must not change."; 1396 EXPECT_IN(FAKE_KERNEL("4.0.0", "D2", 2), xml) << "\nOld requirements must not change."; 1397 EXPECT_IN(FAKE_KERNEL("5.0.0", "E3", 3), xml) << "\nShould see <kernel> from new matrices"; 1398 1399 EXPECT_IN(FAKE_KERNEL("2.0.0", "B2", 2), xml) << "\nShould see <kernel> from new matrices"; 1400 EXPECT_IN(FAKE_KERNEL("4.0.0", "D3", 3), xml) << "\nShould see <kernel> from new matrices"; 1401 } 1402 1403 KernelInfo MakeKernelInfo(const std::string& version, const std::string& key) { 1404 KernelInfo info; 1405 CHECK(fromXml(&info, 1406 " <kernel version=\"" + version + "\">\n" 1407 " <config>\n" 1408 " <key>CONFIG_" + key + "</key>\n" 1409 " <value type=\"tristate\">y</value>\n" 1410 " </config>\n" 1411 " </kernel>\n")); 1412 return info; 1413 } 1414 1415 TEST_F(KernelTest, Compatible) { 1416 setupMockFetcher(vendorManifestXml1, systemMatrixXml1, systemManifestXml1, vendorMatrixXml1); 1417 1418 SetUpMockSystemMatrices({ 1419 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n" 1420 FAKE_KERNEL("1.0.0", "A1", 1) 1421 FAKE_KERNEL("2.0.0", "B1", 1) 1422 " <sepolicy>\n" 1423 " <kernel-sepolicy-version>0</kernel-sepolicy-version>\n" 1424 " <sepolicy-version>0.0</sepolicy-version>\n" 1425 " </sepolicy>\n" 1426 "</compatibility-matrix>\n"}); 1427 expectKernelFcmVersion(Level{1}, Level{1}); 1428 expectSystemManifest(); 1429 expectVendorMatrix(); 1430 1431 auto info = MakeKernelInfo("1.0.0", "A1"); 1432 runtimeInfoFactory().getInfo()->setNextFetchKernelInfo(info.version(), info.configs()); 1433 std::string error; 1434 ASSERT_EQ(COMPATIBLE, vintfObject->checkCompatibility(&error)) << error; 1435 } 1436 1437 TEST_F(KernelTest, Level) { 1438 expectKernelFcmVersion(1, Level{10}); 1439 EXPECT_EQ(Level{10}, vintfObject->getKernelLevel()); 1440 } 1441 1442 TEST_F(KernelTest, LevelUnspecified) { 1443 expectKernelFcmVersion(1, Level::UNSPECIFIED); 1444 EXPECT_EQ(Level::UNSPECIFIED, vintfObject->getKernelLevel()); 1445 } 1446 1447 class KernelTestP : public KernelTest, public WithParamInterface< 1448 std::tuple<std::vector<std::string>, KernelInfo, Level, Level, bool>> {}; 1449 // Assume that we are developing level 2. Test that old <kernel> requirements should 1450 // not change and new <kernel> versions are added. 1451 TEST_P(KernelTestP, Test) { 1452 auto&& [matrices, info, targetFcm, kernelFcm, pass] = GetParam(); 1453 1454 SetUpMockSystemMatrices(matrices); 1455 expectKernelFcmVersion(targetFcm, kernelFcm); 1456 runtimeInfoFactory().getInfo()->setNextFetchKernelInfo(info.version(), info.configs()); 1457 auto matrix = vintfObject->getFrameworkCompatibilityMatrix(); 1458 auto runtime = vintfObject->getRuntimeInfo(); 1459 ASSERT_NE(nullptr, matrix); 1460 ASSERT_NE(nullptr, runtime); 1461 std::string fallbackError = kernelFcm == Level::UNSPECIFIED 1462 ? "\nOld requirements must not change" 1463 : "\nMust not pull unnecessary requirements from new matrices"; 1464 std::string error; 1465 ASSERT_EQ(pass, runtime->checkCompatibility(*matrix, &error)) 1466 << (pass ? error : fallbackError); 1467 } 1468 1469 1470 std::vector<KernelTestP::ParamType> KernelTestParamValues() { 1471 std::vector<KernelTestP::ParamType> ret; 1472 std::vector<std::string> matrices = {systemMatrixKernelXmls[0], systemMatrixKernelXmls[1]}; 1473 ret.emplace_back(matrices, MakeKernelInfo("1.0.0", "A1"), Level{1}, Level::UNSPECIFIED, true); 1474 ret.emplace_back(matrices, MakeKernelInfo("2.0.0", "B1"), Level{1}, Level::UNSPECIFIED, true); 1475 ret.emplace_back(matrices, MakeKernelInfo("3.0.0", "C2"), Level{1}, Level::UNSPECIFIED, true); 1476 ret.emplace_back(matrices, MakeKernelInfo("4.0.0", "D2"), Level{1}, Level::UNSPECIFIED, true); 1477 ret.emplace_back(matrices, MakeKernelInfo("2.0.0", "B2"), Level{1}, Level::UNSPECIFIED, false); 1478 1479 ret.emplace_back(matrices, MakeKernelInfo("1.0.0", "A1"), Level{1}, Level{1}, true); 1480 ret.emplace_back(matrices, MakeKernelInfo("2.0.0", "B1"), Level{1}, Level{1}, true); 1481 ret.emplace_back(matrices, MakeKernelInfo("3.0.0", "C2"), Level{1}, Level{1}, false); 1482 ret.emplace_back(matrices, MakeKernelInfo("4.0.0", "D2"), Level{1}, Level{1}, false); 1483 ret.emplace_back(matrices, MakeKernelInfo("2.0.0", "B2"), Level{1}, Level{1}, true); 1484 1485 matrices = systemMatrixKernelXmls; 1486 ret.emplace_back(matrices, MakeKernelInfo("1.0.0", "A1"), Level{1}, Level::UNSPECIFIED, true); 1487 ret.emplace_back(matrices, MakeKernelInfo("2.0.0", "B1"), Level{1}, Level::UNSPECIFIED, true); 1488 ret.emplace_back(matrices, MakeKernelInfo("3.0.0", "C2"), Level{1}, Level::UNSPECIFIED, true); 1489 ret.emplace_back(matrices, MakeKernelInfo("4.0.0", "D2"), Level{1}, Level::UNSPECIFIED, true); 1490 ret.emplace_back(matrices, MakeKernelInfo("5.0.0", "E3"), Level{1}, Level::UNSPECIFIED, true); 1491 ret.emplace_back(matrices, MakeKernelInfo("6.0.0", "F4"), Level{1}, Level::UNSPECIFIED, true); 1492 ret.emplace_back(matrices, MakeKernelInfo("2.0.0", "B2"), Level{1}, Level::UNSPECIFIED, false); 1493 ret.emplace_back(matrices, MakeKernelInfo("4.0.0", "D3"), Level{1}, Level::UNSPECIFIED, false); 1494 ret.emplace_back(matrices, MakeKernelInfo("5.0.0", "E4"), Level{1}, Level::UNSPECIFIED, false); 1495 ret.emplace_back(matrices, MakeKernelInfo("6.0.0", "F5"), Level{1}, Level::UNSPECIFIED, false); 1496 1497 ret.emplace_back(matrices, MakeKernelInfo("6.0.0", "F4"), Level{2}, Level::UNSPECIFIED, true); 1498 ret.emplace_back(matrices, MakeKernelInfo("6.0.0", "F4"), Level{3}, Level::UNSPECIFIED, true); 1499 ret.emplace_back(matrices, MakeKernelInfo("6.0.0", "F4"), Level{4}, Level::UNSPECIFIED, true); 1500 ret.emplace_back(matrices, MakeKernelInfo("6.0.0", "F4"), Level{5}, Level::UNSPECIFIED, false); 1501 1502 ret.emplace_back(matrices, MakeKernelInfo("1.0.0", "A1"), Level{1}, Level{1}, true); 1503 ret.emplace_back(matrices, MakeKernelInfo("2.0.0", "B1"), Level{1}, Level{1}, true); 1504 ret.emplace_back(matrices, MakeKernelInfo("2.0.0", "B2"), Level{1}, Level{1}, true); 1505 ret.emplace_back(matrices, MakeKernelInfo("3.0.0", "C2"), Level{1}, Level{1}, false); 1506 ret.emplace_back(matrices, MakeKernelInfo("3.0.0", "C3"), Level{1}, Level{1}, false); 1507 ret.emplace_back(matrices, MakeKernelInfo("4.0.0", "D2"), Level{1}, Level{1}, false); 1508 ret.emplace_back(matrices, MakeKernelInfo("4.0.0", "D3"), Level{1}, Level{1}, false); 1509 ret.emplace_back(matrices, MakeKernelInfo("5.0.0", "E3"), Level{1}, Level{1}, false); 1510 ret.emplace_back(matrices, MakeKernelInfo("5.0.0", "E4"), Level{1}, Level{1}, false); 1511 ret.emplace_back(matrices, MakeKernelInfo("6.0.0", "F4"), Level{1}, Level{1}, false); 1512 ret.emplace_back(matrices, MakeKernelInfo("6.0.0", "F5"), Level{1}, Level{1}, false); 1513 ret.emplace_back(matrices, MakeKernelInfo("7.0.0", "G5"), Level{1}, Level{1}, false); 1514 1515 ret.emplace_back(matrices, MakeKernelInfo("6.0.0", "F4"), Level{2}, Level{2}, false); 1516 ret.emplace_back(matrices, MakeKernelInfo("6.0.0", "F4"), Level{3}, Level{3}, false); 1517 ret.emplace_back(matrices, MakeKernelInfo("6.0.0", "F4"), Level{4}, Level{4}, true); 1518 ret.emplace_back(matrices, MakeKernelInfo("6.0.0", "F4"), Level{5}, Level{5}, false); 1519 1520 return ret; 1521 } 1522 1523 std::vector<KernelTestP::ParamType> RKernelTestParamValues() { 1524 std::vector<KernelTestP::ParamType> ret; 1525 std::vector<std::string> matrices = systemMatrixKernelXmls; 1526 1527 // Devices launching O~Q: Must not use *-r+ kernels without specifying kernel FCM version 1528 ret.emplace_back(matrices, MakeKernelInfo("7.0.0", "G5"), Level{1}, Level::UNSPECIFIED, false); 1529 ret.emplace_back(matrices, MakeKernelInfo("7.0.0", "G5"), Level{2}, Level::UNSPECIFIED, false); 1530 ret.emplace_back(matrices, MakeKernelInfo("7.0.0", "G5"), Level{3}, Level::UNSPECIFIED, false); 1531 ret.emplace_back(matrices, MakeKernelInfo("7.0.0", "G5"), Level{4}, Level::UNSPECIFIED, false); 1532 1533 // Devices launching R: may use r kernel without specifying kernel FCM version because 1534 // assemble_vintf does not insert <kernel> tags to device manifest any more. 1535 ret.emplace_back(matrices, MakeKernelInfo("7.0.0", "G5"), Level{5}, Level::UNSPECIFIED, true); 1536 1537 // May use *-r+ kernels with kernel FCM version 1538 ret.emplace_back(matrices, MakeKernelInfo("7.0.0", "G5"), Level{1}, Level{5}, true); 1539 ret.emplace_back(matrices, MakeKernelInfo("7.0.0", "G5"), Level{2}, Level{5}, true); 1540 ret.emplace_back(matrices, MakeKernelInfo("7.0.0", "G5"), Level{3}, Level{5}, true); 1541 ret.emplace_back(matrices, MakeKernelInfo("7.0.0", "G5"), Level{4}, Level{5}, true); 1542 ret.emplace_back(matrices, MakeKernelInfo("7.0.0", "G5"), Level{5}, Level{5}, true); 1543 1544 return ret; 1545 } 1546 1547 std::string PrintKernelTestParam(const TestParamInfo<KernelTestP::ParamType>& info) { 1548 const auto& [matrices, kernelInfo, targetFcm, kernelFcm, pass] = info.param; 1549 return (matrices.size() == 2 ? "Level1AndLevel2_" : "Level1AndMore_") + 1550 android::base::StringReplace(to_string(kernelInfo.version()), ".", "_", true) + "_" + 1551 android::base::StringReplace(kernelInfo.configs().begin()->first, "CONFIG_", "", false) + 1552 "_TargetFcm" + 1553 (targetFcm == Level::UNSPECIFIED ? "Unspecified" : to_string(targetFcm)) + 1554 "_KernelFcm" + 1555 (kernelFcm == Level::UNSPECIFIED ? "Unspecified" : to_string(kernelFcm)) + 1556 "_Should" + (pass ? "Pass" : "Fail"); 1557 } 1558 1559 INSTANTIATE_TEST_SUITE_P(KernelTest, KernelTestP, ValuesIn(KernelTestParamValues()), 1560 &PrintKernelTestParam); 1561 INSTANTIATE_TEST_SUITE_P(NoRKernelWithoutFcm, KernelTestP, ValuesIn(RKernelTestParamValues()), 1562 &PrintKernelTestParam); 1563 1564 class VintfObjectPartialUpdateTest : public MultiMatrixTest { 1565 protected: 1566 void SetUp() override { 1567 MultiMatrixTest::SetUp(); 1568 } 1569 }; 1570 1571 TEST_F(VintfObjectPartialUpdateTest, DeviceCompatibility) { 1572 setupMockFetcher(vendorManifestRequire1, "", systemManifestXml1, vendorMatrixXml1); 1573 SetUpMockSystemMatrices(systemMatrixRequire); 1574 1575 expectSystemManifest(); 1576 expectVendorMatrix(); 1577 expectVendorManifest(); 1578 1579 std::string error; 1580 EXPECT_TRUE(vintfObject->checkCompatibility(&error)) << error; 1581 } 1582 1583 std::string CreateFrameworkManifestFrag(const std::string& interface) { 1584 return "<manifest " + kMetaVersionStr + " type=\"framework\">\n" 1585 " <hal format=\"hidl\">\n" 1586 " <name>android.hardware.foo</name>\n" 1587 " <transport>hwbinder</transport>\n" 1588 " <fqname>@1.0::" + interface + "/default</fqname>\n" 1589 " </hal>\n" 1590 "</manifest>\n"; 1591 } 1592 1593 using FrameworkManifestTestParam = 1594 std::tuple<bool /* Existence of /system/etc/vintf/manifest.xml */, 1595 bool /* Existence of /system/etc/vintf/manifest/fragment.xml */, 1596 bool /* Existence of /product/etc/vintf/manifest.xml */, 1597 bool /* Existence of /product/etc/vintf/manifest/fragment.xml */, 1598 bool /* Existence of /system_ext/etc/vintf/manifest.xml */, 1599 bool /* Existence of /system_ext/etc/vintf/manifest/fragment.xml */>; 1600 class FrameworkManifestTest : public VintfObjectTestBase, 1601 public ::testing::WithParamInterface<FrameworkManifestTestParam> { 1602 protected: 1603 // Set the existence of |path|. 1604 void expectManifest(const std::string& path, const std::string& interface, bool exists) { 1605 if (exists) { 1606 expectFetchRepeatedly(path, CreateFrameworkManifestFrag(interface)); 1607 } else { 1608 expectFileNotExist(StrEq(path)); 1609 } 1610 } 1611 1612 // Set the existence of |path| as a fragment dir 1613 void expectFragment(const std::string& path, const std::string& interface, bool exists) { 1614 if (exists) { 1615 EXPECT_CALL(fetcher(), listFiles(StrEq(path), _, _)) 1616 .Times(AnyNumber()) 1617 .WillRepeatedly(Invoke([](const auto&, auto* out, auto*) { 1618 *out = {"fragment.xml"}; 1619 return ::android::OK; 1620 })); 1621 expectFetchRepeatedly(path + "fragment.xml", 1622 CreateFrameworkManifestFrag(interface)); 1623 } else { 1624 EXPECT_CALL(fetcher(), listFiles(StrEq(path), _, _)) 1625 .Times(AnyNumber()) 1626 .WillRepeatedly(Return(::android::OK)); 1627 expectFileNotExist(path + "fragment.xml"); 1628 } 1629 } 1630 1631 void expectContainsInterface(const std::string& interface, bool contains = true) { 1632 auto manifest = vintfObject->getFrameworkHalManifest(); 1633 ASSERT_NE(nullptr, manifest); 1634 EXPECT_NE(manifest->getHidlInstances("android.hardware.foo", {1, 0}, interface).empty(), 1635 contains) 1636 << interface << " should " << (contains ? "" : "not ") << "exist."; 1637 } 1638 }; 1639 1640 TEST_P(FrameworkManifestTest, Existence) { 1641 useEmptyFileSystem(); 1642 1643 expectFileNotExist(StrEq(kSystemLegacyManifest)); 1644 1645 expectManifest(kSystemManifest, "ISystemEtc", std::get<0>(GetParam())); 1646 expectFragment(kSystemManifestFragmentDir, "ISystemEtcFragment", std::get<1>(GetParam())); 1647 expectManifest(kProductManifest, "IProductEtc", std::get<2>(GetParam())); 1648 expectFragment(kProductManifestFragmentDir, "IProductEtcFragment", std::get<3>(GetParam())); 1649 expectManifest(kSystemExtManifest, "ISystemExtEtc", std::get<4>(GetParam())); 1650 expectFragment(kSystemExtManifestFragmentDir, "ISystemExtEtcFragment", std::get<5>(GetParam())); 1651 1652 if (!std::get<0>(GetParam())) { 1653 EXPECT_EQ(nullptr, vintfObject->getFrameworkHalManifest()) 1654 << "getFrameworkHalManifest must return nullptr if " << kSystemManifest 1655 << " does not exist"; 1656 } else { 1657 expectContainsInterface("ISystemEtc", std::get<0>(GetParam())); 1658 expectContainsInterface("ISystemEtcFragment", std::get<1>(GetParam())); 1659 expectContainsInterface("IProductEtc", std::get<2>(GetParam())); 1660 expectContainsInterface("IProductEtcFragment", std::get<3>(GetParam())); 1661 expectContainsInterface("ISystemExtEtc", std::get<4>(GetParam())); 1662 expectContainsInterface("ISystemExtEtcFragment", std::get<5>(GetParam())); 1663 } 1664 } 1665 INSTANTIATE_TEST_SUITE_P(Vintf, FrameworkManifestTest, 1666 ::testing::Combine(Bool(), Bool(), Bool(), Bool(), Bool(), Bool())); 1667 1668 // clang-format on 1669 1670 class FrameworkManifestLevelTest : public VintfObjectTestBase { 1671 protected: 1672 void SetUp() override { 1673 VintfObjectTestBase::SetUp(); 1674 useEmptyFileSystem(); 1675 1676 auto head = "<manifest " + kMetaVersionStr + R"( type="framework">)"; 1677 auto tail = "</manifest>"; 1678 1679 auto systemManifest = head + getFragment(HalFormat::HIDL, 13, "@3.0::ISystemEtc") + 1680 getFragment(HalFormat::AIDL, 14, "ISystemEtc4") + tail; 1681 expectFetch(kSystemManifest, systemManifest); 1682 1683 auto hidlFragment = 1684 head + getFragment(HalFormat::HIDL, 14, "@4.0::ISystemEtcFragment") + tail; 1685 expectFetch(kSystemManifestFragmentDir + "hidl.xml"s, hidlFragment); 1686 1687 auto aidlFragment = head + getFragment(HalFormat::AIDL, 13, "ISystemEtcFragment3") + tail; 1688 expectFetch(kSystemManifestFragmentDir + "aidl.xml"s, aidlFragment); 1689 1690 EXPECT_CALL(fetcher(), listFiles(StrEq(kSystemManifestFragmentDir), _, _)) 1691 .Times(AnyNumber()) 1692 .WillRepeatedly(Invoke([](const auto&, auto* out, auto*) { 1693 *out = {"hidl.xml", "aidl.xml"}; 1694 return ::android::OK; 1695 })); 1696 } 1697 1698 void expectTargetFcmVersion(size_t level) { 1699 std::string xml = android::base::StringPrintf( 1700 R"(<manifest %s type="device" target-level="%s"/>)", kMetaVersionStr.c_str(), 1701 to_string(static_cast<Level>(level)).c_str()); 1702 expectFetch(kVendorManifest, xml); 1703 (void)vintfObject->getDeviceHalManifest(); 1704 } 1705 1706 void expectContainsHidl(const Version& version, const std::string& interfaceName, 1707 bool exists = true) { 1708 auto manifest = vintfObject->getFrameworkHalManifest(); 1709 ASSERT_NE(nullptr, manifest); 1710 EXPECT_NE( 1711 manifest->getHidlInstances("android.frameworks.foo", version, interfaceName).empty(), 1712 exists) 1713 << "@" << version << "::" << interfaceName << " should " << (exists ? "" : "not ") 1714 << "exist."; 1715 } 1716 1717 void expectContainsAidl(const std::string& interfaceName, bool exists = true) { 1718 auto manifest = vintfObject->getFrameworkHalManifest(); 1719 ASSERT_NE(nullptr, manifest); 1720 EXPECT_NE(manifest->getAidlInstances("android.frameworks.foo", interfaceName).empty(), 1721 exists) 1722 << interfaceName << " should " << (exists ? "" : "not ") << "exist."; 1723 } 1724 1725 private: 1726 std::string getFragment(HalFormat halFormat, size_t maxLevel, const char* versionedInterface) { 1727 auto format = R"(<hal format="%s" max-level="%s"> 1728 <name>android.frameworks.foo</name> 1729 %s 1730 <fqname>%s/default</fqname> 1731 </hal>)"; 1732 std::string level = to_string(static_cast<Level>(maxLevel)); 1733 const char* transport = ""; 1734 if (halFormat == HalFormat::HIDL) { 1735 transport = "<transport>hwbinder</transport>"; 1736 } 1737 return android::base::StringPrintf(format, to_string(halFormat).c_str(), level.c_str(), 1738 transport, versionedInterface); 1739 } 1740 }; 1741 1742 TEST_F(FrameworkManifestLevelTest, NoTargetFcmVersion) { 1743 auto xml = 1744 android::base::StringPrintf(R"(<manifest %s type="device"/> )", kMetaVersionStr.c_str()); 1745 expectFetch(kVendorManifest, xml); 1746 1747 expectContainsHidl({3, 0}, "ISystemEtc"); 1748 expectContainsHidl({4, 0}, "ISystemEtcFragment"); 1749 expectContainsAidl("ISystemEtcFragment3"); 1750 expectContainsAidl("ISystemEtc4"); 1751 } 1752 1753 TEST_F(FrameworkManifestLevelTest, TargetFcmVersion13) { 1754 expectTargetFcmVersion(13); 1755 expectContainsHidl({3, 0}, "ISystemEtc"); 1756 expectContainsHidl({4, 0}, "ISystemEtcFragment"); 1757 expectContainsAidl("ISystemEtcFragment3"); 1758 expectContainsAidl("ISystemEtc4"); 1759 } 1760 1761 TEST_F(FrameworkManifestLevelTest, TargetFcmVersion14) { 1762 expectTargetFcmVersion(14); 1763 expectContainsHidl({3, 0}, "ISystemEtc", false); 1764 expectContainsHidl({4, 0}, "ISystemEtcFragment"); 1765 expectContainsAidl("ISystemEtcFragment3", false); 1766 expectContainsAidl("ISystemEtc4"); 1767 } 1768 1769 TEST_F(FrameworkManifestLevelTest, TargetFcmVersion15) { 1770 expectTargetFcmVersion(15); 1771 expectContainsHidl({3, 0}, "ISystemEtc", false); 1772 expectContainsHidl({4, 0}, "ISystemEtcFragment", false); 1773 expectContainsAidl("ISystemEtcFragment3", false); 1774 expectContainsAidl("ISystemEtc4", false); 1775 } 1776 1777 // clang-format off 1778 1779 // 1780 // Set of OEM FCM matrices at different FCM version. 1781 // 1782 1783 std::vector<std::string> GetOemFcmMatrixLevels(const std::string& name) { 1784 return { 1785 // 1.xml 1786 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n" 1787 " <hal format=\"hidl\" optional=\"true\">\n" 1788 " <name>vendor.foo." + name + "</name>\n" 1789 " <version>1.0</version>\n" 1790 " <interface>\n" 1791 " <name>IExtra</name>\n" 1792 " <instance>default</instance>\n" 1793 " </interface>\n" 1794 " </hal>\n" 1795 "</compatibility-matrix>\n", 1796 // 2.xml 1797 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"2\">\n" 1798 " <hal format=\"hidl\" optional=\"true\">\n" 1799 " <name>vendor.foo." + name + "</name>\n" 1800 " <version>2.0</version>\n" 1801 " <interface>\n" 1802 " <name>IExtra</name>\n" 1803 " <instance>default</instance>\n" 1804 " </interface>\n" 1805 " </hal>\n" 1806 "</compatibility-matrix>\n", 1807 }; 1808 } 1809 1810 class OemFcmLevelTest : public MultiMatrixTest, 1811 public WithParamInterface<std::tuple<size_t, bool, bool>> { 1812 protected: 1813 virtual void SetUp() override { 1814 MultiMatrixTest::SetUp(); 1815 SetUpMockSystemMatrices({systemMatrixLevel1, systemMatrixLevel2}); 1816 } 1817 using Instances = std::set<std::string>; 1818 Instances GetInstances(const CompatibilityMatrix* fcm) { 1819 Instances instances; 1820 fcm->forEachHidlInstance([&instances](const auto& matrixInstance) { 1821 instances.insert(matrixInstance.description(matrixInstance.versionRange().minVer())); 1822 return true; // continue 1823 }); 1824 return instances; 1825 } 1826 }; 1827 1828 TEST_P(OemFcmLevelTest, Test) { 1829 auto&& [level, hasProduct, hasSystemExt] = GetParam(); 1830 1831 expectTargetFcmVersion(level); 1832 if (hasProduct) { 1833 SetUpMockMatrices(kProductVintfDir, GetOemFcmMatrixLevels("product")); 1834 } 1835 if (hasSystemExt) { 1836 SetUpMockMatrices(kSystemExtVintfDir, GetOemFcmMatrixLevels("systemext")); 1837 } 1838 1839 auto fcm = vintfObject->getFrameworkCompatibilityMatrix(); 1840 ASSERT_NE(nullptr, fcm); 1841 auto instances = GetInstances(fcm.get()); 1842 1843 auto containsOrNot = [](bool contains, const std::string& e) { 1844 return contains ? SafeMatcherCast<Instances>(Contains(e)) 1845 : SafeMatcherCast<Instances>(Not(Contains(e))); 1846 }; 1847 1848 EXPECT_THAT(instances, containsOrNot(level == 1, 1849 "android.hardware.major@1.0::IMajor/default")); 1850 EXPECT_THAT(instances, containsOrNot(level == 1 && hasProduct, 1851 "vendor.foo.product@1.0::IExtra/default")); 1852 EXPECT_THAT(instances, containsOrNot(level == 1 && hasSystemExt, 1853 "vendor.foo.systemext@1.0::IExtra/default")); 1854 EXPECT_THAT(instances, Contains("android.hardware.major@2.0::IMajor/default")); 1855 EXPECT_THAT(instances, containsOrNot(hasProduct, 1856 "vendor.foo.product@2.0::IExtra/default")); 1857 EXPECT_THAT(instances, containsOrNot(hasSystemExt, 1858 "vendor.foo.systemext@2.0::IExtra/default")); 1859 } 1860 1861 static std::string OemFcmLevelTestParamToString( 1862 const TestParamInfo<OemFcmLevelTest::ParamType>& info) { 1863 auto&& [level, hasProduct, hasSystemExt] = info.param; 1864 auto name = "Level" + std::to_string(level); 1865 name += "With"s + (hasProduct ? "" : "out") + "Product"; 1866 name += "With"s + (hasSystemExt ? "" : "out") + "SystemExt"; 1867 return name; 1868 } 1869 INSTANTIATE_TEST_SUITE_P(OemFcmLevel, OemFcmLevelTest, Combine(Values(1, 2), Bool(), Bool()), 1870 OemFcmLevelTestParamToString); 1871 // clang-format on 1872 1873 // A matcher that checks if a Result object contains an error message, and the error message 1874 // contains the given substring. 1875 class ErrorMessageMatcher { 1876 public: 1877 ErrorMessageMatcher(const std::string& message) : mMessage(message) {} 1878 template <class T> 1879 bool MatchAndExplain(const android::base::Result<T>& result, 1880 MatchResultListener* listener) const { 1881 if (result.ok()) { 1882 *listener << "result is ok"; 1883 return false; 1884 } 1885 *listener << "result has error message \"" << result.error().message() << "\""; 1886 return result.error().message().find(mMessage) != std::string::npos; 1887 } 1888 void DescribeTo(std::ostream* os) const { 1889 *os << "error message contains \"" << mMessage << "\""; 1890 } 1891 void DescribeNegationTo(std::ostream* os) const { 1892 *os << "error message does not contain \"" << mMessage << "\""; 1893 } 1894 1895 private: 1896 std::string mMessage; 1897 }; 1898 PolymorphicMatcher<ErrorMessageMatcher> HasErrorMessage(const std::string& message) { 1899 return MakePolymorphicMatcher(ErrorMessageMatcher(message)); 1900 } 1901 1902 // Common test set up for checking matrices against lib*idlmetadata. 1903 class CheckMatricesWithHalDefTestBase : public MultiMatrixTest { 1904 void SetUp() override { 1905 MultiMatrixTest::SetUp(); 1906 1907 // clang-format off 1908 std::vector<std::string> matrices{ 1909 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n" 1910 " <hal format=\"hidl\">\n" 1911 " <name>android.hardware.hidl</name>\n" 1912 " <version>1.0</version>\n" 1913 " <interface>\n" 1914 " <name>IHidl</name>\n" 1915 " <instance>default</instance>\n" 1916 " </interface>\n" 1917 " </hal>\n" 1918 " <hal format=\"aidl\">\n" 1919 " <name>android.hardware.aidl</name>\n" 1920 " <interface>\n" 1921 " <name>IAidl</name>\n" 1922 " <instance>default</instance>\n" 1923 " </interface>\n" 1924 " </hal>\n" 1925 "</compatibility-matrix>\n", 1926 }; 1927 // clang-format on 1928 1929 SetUpMockSystemMatrices(matrices); 1930 } 1931 }; 1932 1933 // A set of tests on VintfObject::checkMissingHalsInMatrices 1934 class CheckMissingHalsTest : public CheckMatricesWithHalDefTestBase {}; 1935 1936 TEST_F(CheckMissingHalsTest, Empty) { 1937 EXPECT_RESULT_OK(vintfObject->checkMissingHalsInMatrices({}, {})); 1938 } 1939 1940 TEST_F(CheckMissingHalsTest, Pass) { 1941 std::vector<HidlInterfaceMetadata> hidl{{.name = "android.hardware.hidl@1.0::IHidl"}}; 1942 std::vector<AidlInterfaceMetadata> aidl{{.types = {"android.hardware.aidl.IAidl"}}}; 1943 EXPECT_RESULT_OK(vintfObject->checkMissingHalsInMatrices(hidl, {})); 1944 EXPECT_RESULT_OK(vintfObject->checkMissingHalsInMatrices({}, aidl)); 1945 EXPECT_RESULT_OK(vintfObject->checkMissingHalsInMatrices(hidl, aidl)); 1946 } 1947 1948 TEST_F(CheckMissingHalsTest, FailVendor) { 1949 std::vector<HidlInterfaceMetadata> hidl{{.name = "vendor.foo.hidl@1.0"}}; 1950 std::vector<AidlInterfaceMetadata> aidl{{.types = {"vendor.foo.aidl.IAidl"}}}; 1951 1952 auto res = vintfObject->checkMissingHalsInMatrices(hidl, {}); 1953 EXPECT_THAT(res, HasErrorMessage("vendor.foo.hidl@1.0")); 1954 1955 res = vintfObject->checkMissingHalsInMatrices({}, aidl); 1956 EXPECT_THAT(res, HasErrorMessage("vendor.foo.aidl")); 1957 1958 res = vintfObject->checkMissingHalsInMatrices(hidl, aidl); 1959 EXPECT_THAT(res, HasErrorMessage("vendor.foo.hidl@1.0")); 1960 EXPECT_THAT(res, HasErrorMessage("vendor.foo.aidl")); 1961 1962 auto predicate = [](const auto& interfaceName) { 1963 return android::base::StartsWith(interfaceName, "android.hardware"); 1964 }; 1965 EXPECT_RESULT_OK(vintfObject->checkMissingHalsInMatrices(hidl, {}, predicate)); 1966 EXPECT_RESULT_OK(vintfObject->checkMissingHalsInMatrices({}, aidl, predicate)); 1967 EXPECT_RESULT_OK(vintfObject->checkMissingHalsInMatrices(hidl, aidl, predicate)); 1968 } 1969 1970 TEST_F(CheckMissingHalsTest, FailVersion) { 1971 std::vector<HidlInterfaceMetadata> hidl{{.name = "android.hardware.hidl@2.0"}}; 1972 std::vector<AidlInterfaceMetadata> aidl{{.types = {"android.hardware.aidl2.IAidl"}}}; 1973 1974 auto res = vintfObject->checkMissingHalsInMatrices(hidl, {}); 1975 EXPECT_THAT(res, HasErrorMessage("android.hardware.hidl@2.0")); 1976 1977 res = vintfObject->checkMissingHalsInMatrices({}, aidl); 1978 EXPECT_THAT(res, HasErrorMessage("android.hardware.aidl2")); 1979 1980 res = vintfObject->checkMissingHalsInMatrices(hidl, aidl); 1981 EXPECT_THAT(res, HasErrorMessage("android.hardware.hidl@2.0")); 1982 EXPECT_THAT(res, HasErrorMessage("android.hardware.aidl2")); 1983 1984 auto predicate = [](const auto& interfaceName) { 1985 return android::base::StartsWith(interfaceName, "android.hardware"); 1986 }; 1987 1988 res = vintfObject->checkMissingHalsInMatrices(hidl, {}, predicate); 1989 EXPECT_THAT(res, HasErrorMessage("android.hardware.hidl@2.0")); 1990 1991 res = vintfObject->checkMissingHalsInMatrices({}, aidl, predicate); 1992 EXPECT_THAT(res, HasErrorMessage("android.hardware.aidl2")); 1993 1994 res = vintfObject->checkMissingHalsInMatrices(hidl, aidl, predicate); 1995 EXPECT_THAT(res, HasErrorMessage("android.hardware.hidl@2.0")); 1996 EXPECT_THAT(res, HasErrorMessage("android.hardware.aidl2")); 1997 } 1998 1999 // A set of tests on VintfObject::checkMatrixHalsHasDefinition 2000 class CheckMatrixHalsHasDefinitionTest : public CheckMatricesWithHalDefTestBase {}; 2001 2002 TEST_F(CheckMatrixHalsHasDefinitionTest, Pass) { 2003 std::vector<HidlInterfaceMetadata> hidl{{.name = "android.hardware.hidl@1.0::IHidl"}}; 2004 std::vector<AidlInterfaceMetadata> aidl{{.types = {"android.hardware.aidl.IAidl"}}}; 2005 EXPECT_RESULT_OK(vintfObject->checkMatrixHalsHasDefinition(hidl, aidl)); 2006 } 2007 2008 TEST_F(CheckMatrixHalsHasDefinitionTest, FailMissingHidl) { 2009 std::vector<AidlInterfaceMetadata> aidl{{.types = {"android.hardware.aidl.IAidl"}}}; 2010 auto res = vintfObject->checkMatrixHalsHasDefinition({}, aidl); 2011 EXPECT_THAT(res, HasErrorMessage("android.hardware.hidl@1.0::IHidl")); 2012 } 2013 2014 TEST_F(CheckMatrixHalsHasDefinitionTest, FailMissingAidl) { 2015 std::vector<HidlInterfaceMetadata> hidl{{.name = "android.hardware.hidl@1.0::IHidl"}}; 2016 auto res = vintfObject->checkMatrixHalsHasDefinition(hidl, {}); 2017 EXPECT_THAT(res, HasErrorMessage("android.hardware.aidl.IAidl")); 2018 } 2019 2020 TEST_F(CheckMatrixHalsHasDefinitionTest, FailMissingBoth) { 2021 auto res = vintfObject->checkMatrixHalsHasDefinition({}, {}); 2022 EXPECT_THAT(res, HasErrorMessage("android.hardware.hidl@1.0::IHidl")); 2023 EXPECT_THAT(res, HasErrorMessage("android.hardware.aidl.IAidl")); 2024 } 2025 2026 } // namespace testing 2027 } // namespace vintf 2028 } // namespace android 2029 2030 int main(int argc, char** argv) { 2031 #ifndef LIBVINTF_TARGET 2032 // Silence logs on host because they pollute the gtest output. Negative tests writes a lot 2033 // of warning and error logs. 2034 android::base::SetMinimumLogSeverity(android::base::LogSeverity::FATAL); 2035 #endif 2036 2037 ::testing::InitGoogleMock(&argc, argv); 2038 return RUN_ALL_TESTS(); 2039 } 2040