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
19using namespace lldb_private;
20using namespace lldb;
21using namespace testing;
22
23class RemoteAwarePlatformTester : public RemoteAwarePlatform {
24public:
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(ResolveExecutable,
36 std::pair<bool, ModuleSP>(const ModuleSpec &,
37 const FileSpecList *));
38 Status
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(gmock_a0: module_spec, gmock_a1: module_search_paths_ptr);
44 exe_module_sp = pair.second;
45 return pair.first ? Status() : Status::FromErrorString(str: "error");
46 }
47
48 void SetRemotePlatform(lldb::PlatformSP platform) {
49 m_remote_platform_sp = platform;
50 }
51};
52
53class TargetPlatformTester : public Platform {
54public:
55 using Platform::Platform;
56
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));
61 MOCK_METHOD4(Attach,
62 ProcessSP(ProcessAttachInfo &, Debugger &, Target *, Status &));
63 MOCK_METHOD0(CalculateTrapHandlerSymbolNames, void());
64 MOCK_METHOD0(GetUserIDResolver, UserIDResolver &());
65};
66
67namespace {
68class RemoteAwarePlatformTest : public testing::Test {
69public:
70 static void SetUpTestCase() { FileSystem::Initialize(); }
71 static void TearDownTestCase() { FileSystem::Terminate(); }
72};
73} // namespace
74
75TEST_F(RemoteAwarePlatformTest, TestResolveExecutabelOnClientByPlatform) {
76 ModuleSpec executable_spec;
77 ModuleSP expected_executable(new Module(executable_spec));
78
79 RemoteAwarePlatformTester platform(false);
80 static const ArchSpec process_host_arch;
81 EXPECT_CALL(platform, GetSupportedArchitectures(process_host_arch))
82 .WillRepeatedly(action: Return(value: std::vector<ArchSpec>()));
83 EXPECT_CALL(platform, ResolveExecutable(_, _))
84 .WillRepeatedly(action: Return(value: std::make_pair(x: true, y&: expected_executable)));
85
86 platform.SetRemotePlatform(std::make_shared<TargetPlatformTester>(args: false));
87
88 ModuleSP resolved_sp;
89 lldb_private::Status status =
90 platform.ResolveExecutable(module_spec: executable_spec, exe_module_sp&: resolved_sp, module_search_paths_ptr: nullptr);
91
92 ASSERT_TRUE(status.Success());
93 EXPECT_EQ(expected_executable.get(), resolved_sp.get());
94}
95

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

source code of lldb/unittests/Target/RemoteAwarePlatformTest.cpp