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