Levon Ter-Grigoryan | 631048e | 2020-05-14 16:05:40 +0200 | [diff] [blame] | 1 | //===-- RemoteAwarePlatformTest.cpp ---------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "lldb/Target/RemoteAwarePlatform.h" |
| 10 | #include "lldb/Core/Debugger.h" |
| 11 | #include "lldb/Core/Module.h" |
| 12 | #include "lldb/Core/ModuleSpec.h" |
| 13 | #include "lldb/Host/FileSystem.h" |
| 14 | #include "lldb/Target/Platform.h" |
| 15 | #include "lldb/Target/Process.h" |
| 16 | #include "gmock/gmock.h" |
| 17 | #include "gtest/gtest.h" |
| 18 | |
| 19 | using namespace lldb_private; |
| 20 | using namespace lldb; |
| 21 | using namespace testing; |
| 22 | |
| 23 | class RemoteAwarePlatformTester : public RemoteAwarePlatform { |
| 24 | public: |
| 25 | using RemoteAwarePlatform::RemoteAwarePlatform; |
| 26 | |
| 27 | MOCK_METHOD0(GetDescription, const char *()); |
| 28 | MOCK_METHOD0(GetPluginVersion, uint32_t()); |
| 29 | MOCK_METHOD0(GetPluginName, ConstString()); |
| 30 | MOCK_METHOD2(GetSupportedArchitectureAtIndex, bool(uint32_t, ArchSpec &)); |
| 31 | MOCK_METHOD4(Attach, |
| 32 | ProcessSP(ProcessAttachInfo &, Debugger &, Target *, Status &)); |
| 33 | MOCK_METHOD0(CalculateTrapHandlerSymbolNames, void()); |
| 34 | |
| 35 | void SetRemotePlatform(lldb::PlatformSP platform) { |
| 36 | m_remote_platform_sp = platform; |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | class TargetPlatformTester : public Platform { |
| 41 | public: |
| 42 | using Platform::Platform; |
| 43 | |
| 44 | MOCK_METHOD0(GetDescription, const char *()); |
| 45 | MOCK_METHOD0(GetPluginVersion, uint32_t()); |
| 46 | MOCK_METHOD0(GetPluginName, ConstString()); |
| 47 | MOCK_METHOD2(GetSupportedArchitectureAtIndex, bool(uint32_t, ArchSpec &)); |
| 48 | MOCK_METHOD4(Attach, |
| 49 | ProcessSP(ProcessAttachInfo &, Debugger &, Target *, Status &)); |
| 50 | MOCK_METHOD0(CalculateTrapHandlerSymbolNames, void()); |
| 51 | MOCK_METHOD0(GetUserIDResolver, UserIDResolver &()); |
| 52 | |
| 53 | MOCK_METHOD2(ResolveExecutable, |
| 54 | std::pair<Status, ModuleSP>(const ModuleSpec &, |
| 55 | const FileSpecList *)); |
| 56 | Status |
| 57 | ResolveExecutable(const ModuleSpec &module_spec, |
| 58 | lldb::ModuleSP &exe_module_sp, |
| 59 | const FileSpecList *module_search_paths_ptr) /*override*/ { |
| 60 | auto pair = ResolveExecutable(module_spec, module_search_paths_ptr); |
| 61 | exe_module_sp = pair.second; |
| 62 | return pair.first; |
| 63 | } |
| 64 | }; |
| 65 | |
| 66 | namespace { |
| 67 | class RemoteAwarePlatformTest : public testing::Test { |
| 68 | public: |
| 69 | static void SetUpTestCase() { FileSystem::Initialize(); } |
| 70 | static void TearDownTestCase() { FileSystem::Terminate(); } |
| 71 | }; |
| 72 | } // namespace |
| 73 | |
| 74 | TEST_F(RemoteAwarePlatformTest, TestResolveExecutabelOnClientByPlatform) { |
| 75 | ModuleSpec executable_spec; |
| 76 | ModuleSP expected_executable(new Module(executable_spec)); |
| 77 | |
| 78 | auto platform_sp = std::make_shared<TargetPlatformTester>(false); |
| 79 | EXPECT_CALL(*platform_sp, ResolveExecutable(_, _)) |
| 80 | .WillRepeatedly(Return(std::make_pair(Status(), expected_executable))); |
| 81 | |
| 82 | RemoteAwarePlatformTester platform(false); |
| 83 | EXPECT_CALL(platform, GetSupportedArchitectureAtIndex(_, _)) |
| 84 | .WillRepeatedly(Return(false)); |
| 85 | |
| 86 | platform.SetRemotePlatform(platform_sp); |
| 87 | |
| 88 | ModuleSP resolved_sp; |
| 89 | lldb_private::Status status = |
| 90 | platform.ResolveExecutable(executable_spec, resolved_sp, nullptr); |
| 91 | |
| 92 | ASSERT_TRUE(status.Success()); |
| 93 | EXPECT_EQ(expected_executable.get(), resolved_sp.get()); |
| 94 | } |