1 //===-- RemoteAwarePlatformTest.cpp ---------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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"
19 using namespace lldb_private
;
21 using namespace testing
;
23 class RemoteAwarePlatformTester
: public RemoteAwarePlatform
{
25 using RemoteAwarePlatform::RemoteAwarePlatform
;
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
));
32 ProcessSP(ProcessAttachInfo
&, Debugger
&, Target
*, Status
&));
33 MOCK_METHOD0(CalculateTrapHandlerSymbolNames
, void());
35 MOCK_METHOD2(ResolveExecutable
,
36 std::pair
<bool, ModuleSP
>(const ModuleSpec
&,
37 const FileSpecList
*));
39 ResolveExecutable(const ModuleSpec
&module_spec
,
40 lldb::ModuleSP
&exe_module_sp
,
41 const FileSpecList
*module_search_paths_ptr
) /*override*/
42 { // NOLINT(modernize-use-override)
43 auto pair
= ResolveExecutable(module_spec
, module_search_paths_ptr
);
44 exe_module_sp
= pair
.second
;
45 return pair
.first
? Status() : Status::FromErrorString("error");
48 void SetRemotePlatform(lldb::PlatformSP platform
) {
49 m_remote_platform_sp
= platform
;
53 class TargetPlatformTester
: public Platform
{
55 using Platform::Platform
;
57 MOCK_METHOD0(GetDescription
, llvm::StringRef());
58 MOCK_METHOD0(GetPluginName
, llvm::StringRef());
59 MOCK_METHOD1(GetSupportedArchitectures
,
60 std::vector
<ArchSpec
>(const ArchSpec
&process_host_arch
));
62 ProcessSP(ProcessAttachInfo
&, Debugger
&, Target
*, Status
&));
63 MOCK_METHOD0(CalculateTrapHandlerSymbolNames
, void());
64 MOCK_METHOD0(GetUserIDResolver
, UserIDResolver
&());
68 class RemoteAwarePlatformTest
: public testing::Test
{
70 static void SetUpTestCase() { FileSystem::Initialize(); }
71 static void TearDownTestCase() { FileSystem::Terminate(); }
75 TEST_F(RemoteAwarePlatformTest
, TestResolveExecutabelOnClientByPlatform
) {
76 ModuleSpec executable_spec
;
77 ModuleSP
expected_executable(new Module(executable_spec
));
79 RemoteAwarePlatformTester
platform(false);
80 static const ArchSpec process_host_arch
;
81 EXPECT_CALL(platform
, GetSupportedArchitectures(process_host_arch
))
82 .WillRepeatedly(Return(std::vector
<ArchSpec
>()));
83 EXPECT_CALL(platform
, ResolveExecutable(_
, _
))
84 .WillRepeatedly(Return(std::make_pair(true, expected_executable
)));
86 platform
.SetRemotePlatform(std::make_shared
<TargetPlatformTester
>(false));
89 lldb_private::Status status
=
90 platform
.ResolveExecutable(executable_spec
, resolved_sp
, nullptr);
92 ASSERT_TRUE(status
.Success());
93 EXPECT_EQ(expected_executable
.get(), resolved_sp
.get());