diff options
author | 2017-09-14 18:23:38 -0700 | |
---|---|---|
committer | 2017-09-15 12:36:50 -0700 | |
commit | fee209dda24dc94277df020fee3d91f1194e5ea1 (patch) | |
tree | cdcf51a4fe30f62b4c2f4340d1352870c2ad3459 /cmds/lshal/test.cpp | |
parent | 22ea7b851dbe753eda2a703952bbc803c1dcfc1f (diff) |
lshal: add Released column.
Example output:
$ lshal --neat -lis
...
Y android.hardware.configstore@1.0::ISurfaceFlingerConfigs/default 7f5fe8f4f8a24037153c504d8b4d3313c2ce33d81c8c69fe5194ddd2d4080e72
android.hardware.configstore@1.1::ISurfaceFlingerConfigs/default 0000000000000000000000000000000000000000000000000000000000000000
...
Bug: 65123158
Test: lshal_test
Test: lshal
Test: lshal -ils
Test: lshal --help
Change-Id: I18e52eb977461d68909057583be8223d53f6748b
Diffstat (limited to 'cmds/lshal/test.cpp')
-rw-r--r-- | cmds/lshal/test.cpp | 77 |
1 files changed, 73 insertions, 4 deletions
diff --git a/cmds/lshal/test.cpp b/cmds/lshal/test.cpp index 7d87d6d4cc..9220fc09fb 100644 --- a/cmds/lshal/test.cpp +++ b/cmds/lshal/test.cpp @@ -39,6 +39,7 @@ using ::android::hidl::base::V1_0::DebugInfo; 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; @@ -46,6 +47,8 @@ using ::android::hardware::hidl_vec; using InstanceDebugInfo = IServiceManager::InstanceDebugInfo; +using hidl_hash = hidl_array<uint8_t, 32>; + namespace android { namespace hardware { namespace tests { @@ -277,17 +280,34 @@ static std::string getCmdlineFromId(pid_t serverId) { if (serverId == NO_PID) return ""; return "command_line_" + std::to_string(serverId); } +static bool getIsReleasedFromId(pid_t p) { return p % 2 == 0; } +static hidl_hash getHashFromId(pid_t serverId) { + hidl_hash hash; + bool isReleased = getIsReleasedFromId(serverId); + for (size_t i = 0; i < hash.size(); ++i) { + hash[i] = isReleased ? static_cast<uint8_t>(serverId) : 0u; + } + return hash; +} // Fake service returned by mocked IServiceManager::get. class TestService : public IBase { public: - TestService(DebugInfo&& info) : mInfo(std::move(info)) {} + TestService(pid_t id) : mId(id) {} hardware::Return<void> getDebugInfo(getDebugInfo_cb cb) override { - cb(mInfo); + cb({ mId /* pid */, getPtr(mId), DebugInfo::Architecture::IS_64BIT }); + return hardware::Void(); + } + hardware::Return<void> interfaceChain(interfaceChain_cb cb) override { + cb({getInterfaceName(mId), IBase::descriptor}); + return hardware::Void(); + } + hardware::Return<void> getHashChain(getHashChain_cb cb) override { + cb({getHashFromId(mId), getHashFromId(0xff)}); return hardware::Void(); } private: - DebugInfo mInfo; + pid_t mId; }; class ListTest : public ::testing::Test { @@ -328,7 +348,7 @@ public: ON_CALL(*serviceManager, get(_, _)).WillByDefault(Invoke( [&](const hidl_string&, const hidl_string& instance) { int id = getIdFromInstanceName(instance); - return sp<IBase>(new TestService({ id /* pid */, getPtr(id), A::IS_64BIT })); + return sp<IBase>(new TestService(id)); })); ON_CALL(*serviceManager, debugDump(_)).WillByDefault(Invoke( @@ -473,6 +493,55 @@ TEST_F(ListTest, DumpVintf) { << vintf::gHalManifestConverter.lastError(); } +// test default columns +TEST_F(ListTest, DumpDefault) { + const std::string expected = + "[fake description 0]\n" + "R Interface Thread Use Server Clients\n" + " a.h.foo1@1.0::IFoo/1 11/21 1 2 4\n" + "Y a.h.foo2@2.0::IFoo/2 12/22 2 3 5\n" + "\n" + "[fake description 1]\n" + "R Interface Thread Use Server Clients\n" + " a.h.foo3@3.0::IFoo/3 N/A N/A 4 6\n" + " a.h.foo4@4.0::IFoo/4 N/A N/A 5 7\n" + "\n" + "[fake description 2]\n" + "R Interface Thread Use Server Clients\n" + " a.h.foo5@5.0::IFoo/5 N/A N/A 6 8\n" + " a.h.foo6@6.0::IFoo/6 N/A N/A 7 9\n" + "\n"; + + optind = 1; // mimic Lshal::parseArg() + EXPECT_EQ(0u, mockList->main(createArg({"lshal"}))); + EXPECT_EQ(expected, out.str()); + EXPECT_EQ("", err.str()); +} + +TEST_F(ListTest, DumpHash) { + const std::string expected = + "[fake description 0]\n" + "Interface R Hash\n" + "a.h.foo1@1.0::IFoo/1 0000000000000000000000000000000000000000000000000000000000000000\n" + "a.h.foo2@2.0::IFoo/2 Y 0202020202020202020202020202020202020202020202020202020202020202\n" + "\n" + "[fake description 1]\n" + "Interface R Hash\n" + "a.h.foo3@3.0::IFoo/3 \n" + "a.h.foo4@4.0::IFoo/4 \n" + "\n" + "[fake description 2]\n" + "Interface R Hash\n" + "a.h.foo5@5.0::IFoo/5 \n" + "a.h.foo6@6.0::IFoo/6 \n" + "\n"; + + optind = 1; // mimic Lshal::parseArg() + EXPECT_EQ(0u, mockList->main(createArg({"lshal", "-ils"}))); + EXPECT_EQ(expected, out.str()); + EXPECT_EQ("", err.str()); +} + TEST_F(ListTest, Dump) { const std::string expected = "[fake description 0]\n" |