From bdf44f81d0b7ffb2bf1d9a6c5fbbfb25b55ba565 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Fri, 25 May 2018 14:20:00 -0700 Subject: lshal: Add VINTF column Fixes: 71555570 Test: lshal_test Change-Id: I7ac5ef5a920d41c0f534195c764b1a300429a367 --- cmds/lshal/test.cpp | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) (limited to 'cmds/lshal/test.cpp') 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()); + MOCK_CONST_METHOD0(getDeviceMatrix, std::shared_ptr()); + MOCK_CONST_METHOD0(getFrameworkManifest, std::shared_ptr()); + MOCK_CONST_METHOD0(getFrameworkMatrix, std::shared_ptr()); }; 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 = + "\n" + " \n" + " a.h.foo1\n" + " hwbinder\n" + " @1.0::IFoo/1\n" + " \n" + " \n" + " a.h.foo3\n" + " passthrough\n" + " @3.0::IFoo/3\n" + " \n" + "\n"; + std::string frameworkManifestXml = + "\n" + " \n" + " a.h.foo5\n" + " passthrough\n" + " @5.0::IFoo/5\n" + " \n" + "\n"; + std::string deviceMatrixXml = + "\n" + " \n" + " a.h.foo5\n" + " 5.0\n" + " \n" + " IFoo\n" + " 5\n" + " \n" + " \n" + "\n"; + std::string frameworkMatrixXml = + "\n" + " \n" + " a.h.foo1\n" + " 1.0\n" + " \n" + " IFoo\n" + " 1\n" + " \n" + " \n" + " \n" + " a.h.foo3\n" + " 3.0\n" + " \n" + " IFoo\n" + " 3\n" + " \n" + " \n" + "\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(); + auto frameworkManifest = std::make_shared(); + auto deviceMatrix = std::make_shared(); + auto frameworkMatrix = std::make_shared(); + + 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 { -- cgit v1.2.3-59-g8ed1b