/* * Copyright (C) 2017 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 "VtsTestabilityChecker.h" #include #include #include #include #include using namespace testing; using android::hidl::base::V1_0::IBase; using android::hidl::manager::V1_0::IServiceManager; using android::hidl::manager::V1_0::IServiceNotification; using android::hardware::hidl_array; using android::hardware::hidl_death_recipient; using android::hardware::hidl_handle; using android::hardware::hidl_string; using android::hardware::hidl_vec; using android::vintf::Arch; using android::vintf::CompatibilityMatrix; using android::vintf::HalManifest; using android::vintf::ManifestHal; using android::vintf::MatrixHal; using android::vintf::Version; using android::vintf::XmlConverter; using android::vintf::gCompatibilityMatrixConverter; using android::vintf::gHalManifestConverter; using std::set; using std::string; namespace android { namespace vts { class MockServiceManager : public IServiceManager { public: template using R = ::android::hardware::Return; using String = const hidl_string &; ~MockServiceManager() = default; #define MOCK_METHOD_CB(name) \ MOCK_METHOD1(name, R(IServiceManager::name##_cb)) MOCK_METHOD2(get, R>(String, String)); MOCK_METHOD2(add, R(String, const sp &)); MOCK_METHOD2(getTransport, R(String, String)); MOCK_METHOD_CB(list); MOCK_METHOD2(listByInterface, R(String, listByInterface_cb)); MOCK_METHOD3(registerForNotifications, R(String, String, const sp &)); MOCK_METHOD_CB(debugDump); MOCK_METHOD2(registerPassthroughClient, R(String, String)); MOCK_METHOD_CB(interfaceChain); MOCK_METHOD2(debug, R(const hidl_handle &, const hidl_vec &)); MOCK_METHOD_CB(interfaceDescriptor); MOCK_METHOD_CB(getHashChain); MOCK_METHOD0(setHalInstrumentation, R()); MOCK_METHOD2(linkToDeath, R(const sp &, uint64_t)); MOCK_METHOD0(ping, R()); MOCK_METHOD_CB(getDebugInfo); MOCK_METHOD0(notifySyspropsChanged, R()); MOCK_METHOD1(unlinkToDeath, R(const sp &)); }; class VtsTestabilityCheckerTest : public ::testing::Test { public: virtual void SetUp() override { test_cm_ = testFrameworkCompMatrix(); test_fm_ = testFrameworkManfiest(); test_vm_ = testDeviceManifest(); sm_ = new NiceMock(); checker_.reset( new VtsTestabilityChecker(&test_cm_, &test_fm_, &test_vm_, sm_)); } virtual void TearDown() override {} HalManifest testDeviceManifest() { HalManifest vm; string xml = "\n" " \n" " android.hardware.audio\n" " passthrough\n" " 2.0\n" " \n" " IAudio\n" " default\n" " \n" " \n" " \n" " android.hardware.camera\n" " hwbinder\n" " 1.2\n" " 2.5\n" " \n" " ICamera\n" " legacy/0\n" " \n" " \n" " IBetterCamera\n" " camera\n" " default\n" " \n" " \n" " \n" " android.hardware.drm\n" " hwbinder\n" " 2.0\n" " \n" " IDrm\n" " default\n" " \n" " \n" " \n" " android.hardware.nfc\n" " hwbinder\n" " 1.0\n" " \n" " INfc\n" " default\n" " \n" " \n" " \n" " android.hardware.renderscript\n" " passthrough\n" " 1.0\n" " \n" " IRenderscript\n" " default\n" " \n" " \n" " \n" " android.hardware.vibrator\n" " hwbinder\n" " 1.0\n" " \n" " IVibrator\n" " default\n" " \n" " \n" "\n"; gHalManifestConverter(&vm, xml); return vm; } HalManifest testFrameworkManfiest() { HalManifest fm; string xml = "\n" " \n" " android.hardware.nfc\n" " hwbinder\n" " 1.0\n" " \n" " INfc\n" " default\n" " fnfc\n" " \n" " \n" "\n"; gHalManifestConverter(&fm, xml); return fm; } CompatibilityMatrix testFrameworkCompMatrix() { CompatibilityMatrix cm; string xml = "\n" " \n" " android.hardware.audio\n" " 2.0-1\n" " \n" " IAudio\n" " default\n" " \n" " \n" " \n" " android.hardware.camera\n" " 2.2-3\n" " 4.5-6\n" " \n" " ICamera\n" " default\n" " \n" " \n" " IBetterCamera\n" " camera\n" " \n" " \n" " \n" " android.hardware.drm\n" " 1.0-1\n" " \n" " IDrm\n" " default\n" " drm\n" " \n" " \n" " IDrmTest\n" " default\n" " \n" " \n" " \n" " android.hardware.light\n" " 2.0-1\n" " \n" " ILight\n" " default\n" " \n" " \n" " \n" " android.hardware.nfc\n" " 1.0-2\n" " \n" " INfc\n" " default\n" " nfc\n" " \n" " \n" " INfcTest\n" " default\n" " \n" " \n" " \n" " android.hardware.radio\n" " 1.0-1\n" " \n" " IRadio\n" " default\n" " \n" " \n" " \n" " android.hardware.vibrator\n" " 2.0\n" " \n" " IVibrator\n" " default\n" " \n" " \n" "\n"; gCompatibilityMatrixConverter(&cm, xml); return cm; } protected: CompatibilityMatrix test_cm_; HalManifest test_fm_; HalManifest test_vm_; sp sm_; std::unique_ptr checker_; }; TEST_F(VtsTestabilityCheckerTest, CheckComplianceTest) { set instances; // Check non-existent hal. EXPECT_FALSE(checker_->CheckHalForComplianceTest( "nonexistent", {1, 0}, "None", Arch::ARCH_32, &instances)); EXPECT_TRUE(instances.empty()); // Check hal with unsupported version by vendor. EXPECT_FALSE(checker_->CheckHalForComplianceTest( "android.hardware.nfc", {2, 0}, "INfc", Arch::ARCH_32, &instances)); EXPECT_TRUE(instances.empty()); // Check hal with unsupported interface by vendor. EXPECT_FALSE(checker_->CheckHalForComplianceTest( "android.hardware.nfc", {1, 0}, "INfcTest", Arch::ARCH_32, &instances)); EXPECT_TRUE(instances.empty()); // Check hal with unsupported arch by vendor. EXPECT_FALSE(checker_->CheckHalForComplianceTest( "android.hardware.audio", {1, 0}, "IAudio", Arch::ARCH_64, &instances)); EXPECT_TRUE(instances.empty()); // Check hal claimed by framework but not supported by vendor (error case). EXPECT_FALSE(checker_->CheckHalForComplianceTest( "android.hardware.light", {2, 0}, "ILight", Arch::ARCH_32, &instances)); EXPECT_TRUE(instances.empty()); // Check hal interface claimed by framework but not supported by vendor (error // case). EXPECT_FALSE(checker_->CheckHalForComplianceTest( "android.hardware.drm", {1, 0}, "IDrmTest", Arch::ARCH_32, &instances)); EXPECT_TRUE(instances.empty()); // Check hal claimed by framework and supported by vendor. instances.clear(); EXPECT_TRUE(checker_->CheckHalForComplianceTest("android.hardware.vibrator", {1, 0}, "IVibrator", Arch::ARCH_32, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default"}))); // Check hal not claimed by framework but supported by vendor. instances.clear(); EXPECT_TRUE(checker_->CheckHalForComplianceTest( "android.hardware.renderscript", {1, 0}, "IRenderscript", Arch::ARCH_32, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default"}))); // Check hal with version not claimed by framework by supported by vendor. instances.clear(); EXPECT_TRUE(checker_->CheckHalForComplianceTest("android.hardware.vibrator", {1, 0}, "IVibrator", Arch::ARCH_32, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default"}))); // Check hal with instance not claimed by framework but supported by vendor. instances.clear(); EXPECT_TRUE(checker_->CheckHalForComplianceTest( "android.hardware.camera", {2, 2}, "ICamera", Arch::ARCH_32, &instances)); EXPECT_THAT(instances, ContainerEq(set({"legacy/0"}))); // Check hal with additional vendor instance not claimed by framework. instances.clear(); EXPECT_TRUE(checker_->CheckHalForComplianceTest("android.hardware.camera", {1, 2}, "IBetterCamera", Arch::ARCH_32, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default", "camera"}))); // Check hal supported by both framework and vendor. instances.clear(); EXPECT_TRUE(checker_->CheckHalForComplianceTest( "android.hardware.nfc", {1, 0}, "INfc", Arch::ARCH_32, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default", "fnfc"}))); // Check hal instance claimed by framework but not supported by vendor. instances.clear(); EXPECT_TRUE(checker_->CheckHalForComplianceTest( "android.hardware.drm", {2, 0}, "IDrm", Arch::ARCH_32, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default"}))); // Check an optional hal with empty interface (legacy input). instances.clear(); EXPECT_TRUE(checker_->CheckHalForComplianceTest( "android.hardware.vibrator", {1, 0}, "" /*interface*/, Arch::ARCH_EMPTY, &instances)); EXPECT_TRUE(instances.empty()); } TEST_F(VtsTestabilityCheckerTest, CheckNonComplianceTest) { set instances; ON_CALL(*sm_, listByInterface(_, _)) .WillByDefault( Invoke([](hidl_string str, IServiceManager::listByInterface_cb cb) { if (str == "android.hardware.foo@1.0::IFoo") { cb({"default", "footest"}); } else if (str == "android.hardware.nfc@3.0::INfc") { cb({"default"}); } else if (str == "android.hardware.drm@2.0::IDrm") { cb({"drmtest"}); } return hardware::Void(); })); ON_CALL(*sm_, list(_)).WillByDefault(Invoke([](IServiceManager::list_cb cb) { cb({"android.hardware.foo@1.0::IFoo/default", "android.hardware.foo@1.0::IFoo/footest", "android.hardware.nfc@3.0::INfc/default", "android.hardware.drm@2.0::IDrm/drmtest"}); return hardware::Void(); })); // Check non-existent hal. EXPECT_FALSE(checker_->CheckHalForNonComplianceTest( "non-existent", {1, 0}, "None", Arch::ARCH_32, &instances)); EXPECT_TRUE(instances.empty()); // Check hal with unsupported version by vendor. EXPECT_FALSE(checker_->CheckHalForNonComplianceTest( "android.hardware.nfc", {2, 0}, "INfc", Arch::ARCH_32, &instances)); EXPECT_TRUE(instances.empty()); // Check hal with unsupported interface by vendor. EXPECT_FALSE(checker_->CheckHalForNonComplianceTest( "android.hardware.nfc", {1, 0}, "INfcTest", Arch::ARCH_32, &instances)); EXPECT_TRUE(instances.empty()); // Check hal with unsupported arch by vendor. EXPECT_FALSE(checker_->CheckHalForNonComplianceTest( "android.hardware.audio", {1, 0}, "IAudio", Arch::ARCH_64, &instances)); EXPECT_TRUE(instances.empty()); // Check hal claimed by framework but not supported by vendor (error case). EXPECT_FALSE(checker_->CheckHalForNonComplianceTest( "android.hardware.light", {2, 0}, "ILight", Arch::ARCH_32, &instances)); EXPECT_TRUE(instances.empty()); // Check hal interface claimed by framework but not supported by vendor (error // case). EXPECT_FALSE(checker_->CheckHalForNonComplianceTest( "android.hardware.drm", {1, 0}, "IDrmTest", Arch::ARCH_32, &instances)); EXPECT_TRUE(instances.empty()); // Check hal claimed by framework and supported by vendor. instances.clear(); EXPECT_TRUE(checker_->CheckHalForNonComplianceTest( "android.hardware.vibrator", {1, 0}, "IVibrator", Arch::ARCH_32, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default"}))); // Check hal not claimed by framework but supported by vendor. instances.clear(); EXPECT_TRUE(checker_->CheckHalForNonComplianceTest( "android.hardware.renderscript", {1, 0}, "IRenderscript", Arch::ARCH_32, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default"}))); // Check hal with version not claimed by framework by supported by vendor. instances.clear(); EXPECT_TRUE(checker_->CheckHalForNonComplianceTest( "android.hardware.vibrator", {1, 0}, "IVibrator", Arch::ARCH_32, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default"}))); // Check hal with instance not claimed by framework but supported by vendor. instances.clear(); EXPECT_TRUE(checker_->CheckHalForNonComplianceTest( "android.hardware.camera", {2, 2}, "ICamera", Arch::ARCH_32, &instances)); EXPECT_THAT(instances, ContainerEq(set({"legacy/0"}))); // Check hal with additional vendor instance not claimed by framework. instances.clear(); EXPECT_TRUE(checker_->CheckHalForNonComplianceTest( "android.hardware.camera", {1, 2}, "IBetterCamera", Arch::ARCH_32, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default", "camera"}))); // Check hal supported by both framework and vendor. instances.clear(); EXPECT_TRUE(checker_->CheckHalForNonComplianceTest( "android.hardware.nfc", {1, 0}, "INfc", Arch::ARCH_32, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default"}))); // Check an optional hal with empty interface (legacy input). instances.clear(); EXPECT_TRUE(checker_->CheckHalForNonComplianceTest( "android.hardware.vibrator", {1, 0}, "" /*interface*/, Arch::ARCH_EMPTY, &instances)); EXPECT_TRUE(instances.empty()); // Check hal only registered with hwmanger. instances.clear(); EXPECT_TRUE(checker_->CheckHalForNonComplianceTest( "android.hardware.foo", {1, 0}, "IFoo", Arch::ARCH_EMPTY, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default", "footest"}))); // Check hal with version only registered with hwmanger. instances.clear(); EXPECT_TRUE(checker_->CheckHalForNonComplianceTest( "android.hardware.nfc", {3, 0}, "INfc", Arch::ARCH_EMPTY, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default"}))); // Check hal with additional instance registered with hwmanger. instances.clear(); EXPECT_TRUE(checker_->CheckHalForNonComplianceTest( "android.hardware.drm", {2, 0}, "IDrm", Arch::ARCH_EMPTY, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default", "drmtest"}))); instances.clear(); EXPECT_TRUE(checker_->CheckHalForNonComplianceTest( "android.hardware.foo", {1, 0}, "", Arch::ARCH_EMPTY, &instances)); EXPECT_TRUE(instances.empty()); } TEST_F(VtsTestabilityCheckerTest, CheckFrameworkCompatibleHalOptional) { set instances; // Check non-existent hal. EXPECT_FALSE(checker_->CheckFrameworkCompatibleHal( "nonexistent", {1, 0}, "None", Arch::ARCH_EMPTY, &instances)); EXPECT_TRUE(instances.empty()); // Check hal not required by framework EXPECT_FALSE(checker_->CheckFrameworkCompatibleHal( "android.hardware.renderscript", {1, 0}, "IRenderscript", Arch::ARCH_EMPTY, &instances)); EXPECT_TRUE(instances.empty()); // Check hal with unsupported version. EXPECT_FALSE(checker_->CheckFrameworkCompatibleHal( "android.hardware.camera", {1, 0}, "ICamera", Arch::ARCH_EMPTY, &instances)); EXPECT_TRUE(instances.empty()); // Check hal with non-existent interface. EXPECT_FALSE(checker_->CheckFrameworkCompatibleHal( "android.hardware.camera", {1, 2}, "None", Arch::ARCH_EMPTY, &instances)); EXPECT_TRUE(instances.empty()); // Check an optional hal not supported by vendor. EXPECT_FALSE(checker_->CheckFrameworkCompatibleHal( "android.hardware.radio", {1, 0}, "IRadio", Arch::ARCH_EMPTY, &instances)); EXPECT_TRUE(instances.empty()); // Check an optional hal with version not supported by vendor. EXPECT_FALSE(checker_->CheckFrameworkCompatibleHal( "android.hardware.camera", {4, 5}, "ICamera", Arch::ARCH_EMPTY, &instances)); EXPECT_TRUE(instances.empty()); // Check an optional hal with interface not supported by vendor. EXPECT_FALSE(checker_->CheckFrameworkCompatibleHal( "android.hardware.nfc", {4, 5}, "INfcTest", Arch::ARCH_EMPTY, &instances)); EXPECT_TRUE(instances.empty()); // Check an option passthrough hal with unsupported arch. EXPECT_FALSE(checker_->CheckFrameworkCompatibleHal( "android.hardware.audio", {2, 0}, "IAudio", Arch::ARCH_64, &instances)); EXPECT_TRUE(instances.empty()); // Check an optional hal supported by vendor but with no compatible // instance. EXPECT_TRUE(checker_->CheckFrameworkCompatibleHal( "android.hardware.camera", {2, 2}, "ICamera", Arch::ARCH_EMPTY, &instances)); EXPECT_TRUE(instances.empty()); // Check an optional hal supported by vendor. instances.clear(); EXPECT_TRUE(checker_->CheckFrameworkCompatibleHal( "android.hardware.camera", {2, 2}, "IBetterCamera", Arch::ARCH_EMPTY, &instances)); EXPECT_THAT(instances, ContainerEq(set({"camera"}))); // Check an optional passthrough hal supported by vendor. instances.clear(); EXPECT_TRUE(checker_->CheckFrameworkCompatibleHal( "android.hardware.audio", {2, 0}, "IAudio", Arch::ARCH_32, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default"}))); // Check an optional hal with empty interface (legacy input). instances.clear(); EXPECT_TRUE(checker_->CheckFrameworkCompatibleHal( "android.hardware.camera", {2, 2}, "" /*interface*/, Arch::ARCH_EMPTY, &instances)); EXPECT_TRUE(instances.empty()); } TEST_F(VtsTestabilityCheckerTest, CheckFrameworkCompatibleHalRequired) { set instances; // Check a required hal not supported by vendor. EXPECT_TRUE(checker_->CheckFrameworkCompatibleHal( "android.hardware.light", {2, 0}, "ILight", Arch::ARCH_32, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default"}))); // Check a required hal with version not supported by vendor. instances.clear(); EXPECT_TRUE(checker_->CheckFrameworkCompatibleHal("android.hardware.vibrator", {2, 0}, "IVibrator", Arch::ARCH_32, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default"}))); // Check a required hal with interface not supported by vendor. instances.clear(); EXPECT_TRUE(checker_->CheckFrameworkCompatibleHal( "android.hardware.drm", {1, 0}, "IDrmTest", Arch::ARCH_32, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default"}))); // Check a required hal supported by vendor. instances.clear(); EXPECT_TRUE(checker_->CheckFrameworkCompatibleHal( "android.hardware.drm", {1, 0}, "IDrm", Arch::ARCH_32, &instances)); EXPECT_THAT(instances, ContainerEq(set({"default", "drm"}))); // Check an optional hal with empty interface (legacy input). instances.clear(); EXPECT_TRUE(checker_->CheckFrameworkCompatibleHal( "android.hardware.vibrator", {2, 0}, "" /*interface*/, Arch::ARCH_EMPTY, &instances)); EXPECT_TRUE(instances.empty()); } } // namespace vts } // namespace android int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }