diff options
Diffstat (limited to 'cmds/lshal/test.cpp')
| -rw-r--r-- | cmds/lshal/test.cpp | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/cmds/lshal/test.cpp b/cmds/lshal/test.cpp index 2af01996d4..501c04de84 100644 --- a/cmds/lshal/test.cpp +++ b/cmds/lshal/test.cpp @@ -45,7 +45,12 @@ 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::gCompatibilityMatrixConverter; +using android::vintf::gHalManifestConverter; +using android::vintf::HalManifest; using android::vintf::Transport; +using android::vintf::VintfObject; using InstanceDebugInfo = IServiceManager::InstanceDebugInfo; @@ -209,6 +214,11 @@ public: MOCK_CONST_METHOD2(getPidInfo, bool(pid_t, PidInfo*)); MOCK_CONST_METHOD1(parseCmdline, std::string(pid_t)); MOCK_METHOD1(getPartition, Partition(pid_t)); + + MOCK_CONST_METHOD0(getDeviceManifest, std::shared_ptr<const vintf::HalManifest>()); + MOCK_CONST_METHOD0(getDeviceMatrix, std::shared_ptr<const vintf::CompatibilityMatrix>()); + MOCK_CONST_METHOD0(getFrameworkManifest, std::shared_ptr<const vintf::HalManifest>()); + MOCK_CONST_METHOD0(getFrameworkMatrix, std::shared_ptr<const vintf::CompatibilityMatrix>()); }; class ListParseArgsTest : public ::testing::Test { @@ -337,6 +347,15 @@ public: }); })); ON_CALL(*mockList, getPartition(_)).WillByDefault(Return(Partition::VENDOR)); + + ON_CALL(*mockList, getDeviceManifest()) + .WillByDefault(Return(VintfObject::GetDeviceHalManifest())); + ON_CALL(*mockList, getDeviceMatrix()) + .WillByDefault(Return(VintfObject::GetDeviceCompatibilityMatrix())); + ON_CALL(*mockList, getFrameworkManifest()) + .WillByDefault(Return(VintfObject::GetFrameworkHalManifest())); + ON_CALL(*mockList, getFrameworkMatrix()) + .WillByDefault(Return(VintfObject::GetFrameworkCompatibilityMatrix())); } void initMockServiceManager() { @@ -656,6 +675,87 @@ TEST_F(ListTest, UnknownHalType) { EXPECT_THAT(err.str(), HasSubstr("Unrecognized HAL type: a")); } +TEST_F(ListTest, Vintf) { + std::string deviceManifestXml = + "<manifest version=\"1.0\" type=\"device\">\n" + " <hal>\n" + " <name>a.h.foo1</name>\n" + " <transport>hwbinder</transport>\n" + " <fqname>@1.0::IFoo/1</fqname>\n" + " </hal>\n" + " <hal>\n" + " <name>a.h.foo3</name>\n" + " <transport arch=\"32+64\">passthrough</transport>\n" + " <fqname>@3.0::IFoo/3</fqname>\n" + " </hal>\n" + "</manifest>\n"; + std::string frameworkManifestXml = + "<manifest version=\"1.0\" type=\"framework\">\n" + " <hal>\n" + " <name>a.h.foo5</name>\n" + " <transport arch=\"32\">passthrough</transport>\n" + " <fqname>@5.0::IFoo/5</fqname>\n" + " </hal>\n" + "</manifest>\n"; + std::string deviceMatrixXml = + "<compatibility-matrix version=\"1.0\" type=\"device\">\n" + " <hal>\n" + " <name>a.h.foo5</name>\n" + " <version>5.0</version>\n" + " <interface>\n" + " <name>IFoo</name>\n" + " <instance>5</instance>\n" + " </interface>\n" + " </hal>\n" + "</compatibility-matrix>\n"; + std::string frameworkMatrixXml = + "<compatibility-matrix version=\"1.0\" type=\"framework\">\n" + " <hal>\n" + " <name>a.h.foo1</name>\n" + " <version>1.0</version>\n" + " <interface>\n" + " <name>IFoo</name>\n" + " <instance>1</instance>\n" + " </interface>\n" + " </hal>\n" + " <hal>\n" + " <name>a.h.foo3</name>\n" + " <version>3.0</version>\n" + " <interface>\n" + " <name>IFoo</name>\n" + " <instance>3</instance>\n" + " </interface>\n" + " </hal>\n" + "</compatibility-matrix>\n"; + + std::string expected = "DM,FC a.h.foo1@1.0::IFoo/1\n" + "X a.h.foo2@2.0::IFoo/2\n" + "DM,FC a.h.foo3@3.0::IFoo/3\n" + "X a.h.foo4@4.0::IFoo/4\n" + "DC,FM a.h.foo5@5.0::IFoo/5\n" + "X a.h.foo6@6.0::IFoo/6\n"; + + auto deviceManifest = std::make_shared<HalManifest>(); + auto frameworkManifest = std::make_shared<HalManifest>(); + auto deviceMatrix = std::make_shared<CompatibilityMatrix>(); + auto frameworkMatrix = std::make_shared<CompatibilityMatrix>(); + + ASSERT_TRUE(gHalManifestConverter(deviceManifest.get(), deviceManifestXml)); + ASSERT_TRUE(gHalManifestConverter(frameworkManifest.get(), frameworkManifestXml)); + ASSERT_TRUE(gCompatibilityMatrixConverter(deviceMatrix.get(), deviceMatrixXml)); + ASSERT_TRUE(gCompatibilityMatrixConverter(frameworkMatrix.get(), frameworkMatrixXml)); + + ON_CALL(*mockList, getDeviceManifest()).WillByDefault(Return(deviceManifest)); + ON_CALL(*mockList, getDeviceMatrix()).WillByDefault(Return(deviceMatrix)); + ON_CALL(*mockList, getFrameworkManifest()).WillByDefault(Return(frameworkManifest)); + ON_CALL(*mockList, getFrameworkMatrix()).WillByDefault(Return(frameworkMatrix)); + + optind = 1; // mimic Lshal::parseArg() + EXPECT_EQ(0u, mockList->main(createArg({"lshal", "-Vi", "--neat"}))); + EXPECT_THAT(out.str(), HasSubstr(expected)); + EXPECT_EQ("", err.str()); +} + class HelpTest : public ::testing::Test { public: void SetUp() override { |