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, llvm::StringRef()); 28 MOCK_METHOD0(GetPluginName, llvm::StringRef()); 29 MOCK_METHOD1(GetSupportedArchitectures, 30 std::vector<ArchSpec>(const ArchSpec &process_host_arch)); 31 MOCK_METHOD4(Attach, 32 ProcessSP(ProcessAttachInfo &, Debugger &, Target *, Status &)); 33 MOCK_METHOD0(CalculateTrapHandlerSymbolNames, void()); 34 35 MOCK_METHOD2(ResolveRemoteExecutable, 36 std::pair<Status, ModuleSP>(const ModuleSpec &, 37 const FileSpecList *)); 38 Status ResolveRemoteExecutable( 39 const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp, 40 const FileSpecList *module_search_paths_ptr) /*override*/ { 41 auto pair = ResolveRemoteExecutable(module_spec, module_search_paths_ptr); 42 exe_module_sp = pair.second; 43 return pair.first; 44 } 45 46 void SetRemotePlatform(lldb::PlatformSP platform) { 47 m_remote_platform_sp = platform; 48 } 49 }; 50 51 class TargetPlatformTester : public Platform { 52 public: 53 using Platform::Platform; 54 55 MOCK_METHOD0(GetDescription, llvm::StringRef()); 56 MOCK_METHOD0(GetPluginName, llvm::StringRef()); 57 MOCK_METHOD1(GetSupportedArchitectures, 58 std::vector<ArchSpec>(const ArchSpec &process_host_arch)); 59 MOCK_METHOD4(Attach, 60 ProcessSP(ProcessAttachInfo &, Debugger &, Target *, Status &)); 61 MOCK_METHOD0(CalculateTrapHandlerSymbolNames, void()); 62 MOCK_METHOD0(GetUserIDResolver, UserIDResolver &()); 63 }; 64 65 namespace { 66 class RemoteAwarePlatformTest : public testing::Test { 67 public: 68 static void SetUpTestCase() { FileSystem::Initialize(); } 69 static void TearDownTestCase() { FileSystem::Terminate(); } 70 }; 71 } // namespace 72 73 TEST_F(RemoteAwarePlatformTest, TestResolveExecutabelOnClientByPlatform) { 74 ModuleSpec executable_spec; 75 ModuleSP expected_executable(new Module(executable_spec)); 76 77 RemoteAwarePlatformTester platform(false); 78 static const ArchSpec process_host_arch; 79 EXPECT_CALL(platform, GetSupportedArchitectures(process_host_arch)) 80 .WillRepeatedly(Return(std::vector<ArchSpec>())); 81 EXPECT_CALL(platform, ResolveRemoteExecutable(_, _)) 82 .WillRepeatedly(Return(std::make_pair(Status(), expected_executable))); 83 84 platform.SetRemotePlatform(std::make_shared<TargetPlatformTester>(false)); 85 86 ModuleSP resolved_sp; 87 lldb_private::Status status = 88 platform.ResolveExecutable(executable_spec, resolved_sp, nullptr); 89 90 ASSERT_TRUE(status.Success()); 91 EXPECT_EQ(expected_executable.get(), resolved_sp.get()); 92 } 93