1631048e8SLevon Ter-Grigoryan //===-- RemoteAwarePlatformTest.cpp ---------------------------------------===//
2631048e8SLevon Ter-Grigoryan //
3631048e8SLevon Ter-Grigoryan // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4631048e8SLevon Ter-Grigoryan // See https://llvm.org/LICENSE.txt for license information.
5631048e8SLevon Ter-Grigoryan // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6631048e8SLevon Ter-Grigoryan //
7631048e8SLevon Ter-Grigoryan //===----------------------------------------------------------------------===//
8631048e8SLevon Ter-Grigoryan
9631048e8SLevon Ter-Grigoryan #include "lldb/Target/RemoteAwarePlatform.h"
10631048e8SLevon Ter-Grigoryan #include "lldb/Core/Debugger.h"
11631048e8SLevon Ter-Grigoryan #include "lldb/Core/Module.h"
12631048e8SLevon Ter-Grigoryan #include "lldb/Core/ModuleSpec.h"
13631048e8SLevon Ter-Grigoryan #include "lldb/Host/FileSystem.h"
14631048e8SLevon Ter-Grigoryan #include "lldb/Target/Platform.h"
15631048e8SLevon Ter-Grigoryan #include "lldb/Target/Process.h"
16631048e8SLevon Ter-Grigoryan #include "gmock/gmock.h"
17631048e8SLevon Ter-Grigoryan #include "gtest/gtest.h"
18631048e8SLevon Ter-Grigoryan
19631048e8SLevon Ter-Grigoryan using namespace lldb_private;
20631048e8SLevon Ter-Grigoryan using namespace lldb;
21631048e8SLevon Ter-Grigoryan using namespace testing;
22631048e8SLevon Ter-Grigoryan
23631048e8SLevon Ter-Grigoryan class RemoteAwarePlatformTester : public RemoteAwarePlatform {
24631048e8SLevon Ter-Grigoryan public:
25631048e8SLevon Ter-Grigoryan using RemoteAwarePlatform::RemoteAwarePlatform;
26631048e8SLevon Ter-Grigoryan
27a458ef4fSPavel Labath MOCK_METHOD0(GetDescription, llvm::StringRef());
28a3939e15SPavel Labath MOCK_METHOD0(GetPluginName, llvm::StringRef());
29dde487e5SJonas Devlieghere MOCK_METHOD1(GetSupportedArchitectures,
30dde487e5SJonas Devlieghere std::vector<ArchSpec>(const ArchSpec &process_host_arch));
31631048e8SLevon Ter-Grigoryan MOCK_METHOD4(Attach,
32631048e8SLevon Ter-Grigoryan ProcessSP(ProcessAttachInfo &, Debugger &, Target *, Status &));
33631048e8SLevon Ter-Grigoryan MOCK_METHOD0(CalculateTrapHandlerSymbolNames, void());
34631048e8SLevon Ter-Grigoryan
35098c01c1SPavel Labath MOCK_METHOD2(ResolveRemoteExecutable,
36098c01c1SPavel Labath std::pair<Status, ModuleSP>(const ModuleSpec &,
37098c01c1SPavel Labath const FileSpecList *));
ResolveRemoteExecutable(const ModuleSpec & module_spec,lldb::ModuleSP & exe_module_sp,const FileSpecList * module_search_paths_ptr)38098c01c1SPavel Labath Status ResolveRemoteExecutable(
39098c01c1SPavel Labath const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp,
40*fd146460SShafik Yaghmour const FileSpecList *module_search_paths_ptr) /*override*/
41*fd146460SShafik Yaghmour { // NOLINT(modernize-use-override)
42098c01c1SPavel Labath auto pair = ResolveRemoteExecutable(module_spec, module_search_paths_ptr);
43098c01c1SPavel Labath exe_module_sp = pair.second;
44098c01c1SPavel Labath return pair.first;
45098c01c1SPavel Labath }
46098c01c1SPavel Labath
SetRemotePlatform(lldb::PlatformSP platform)47631048e8SLevon Ter-Grigoryan void SetRemotePlatform(lldb::PlatformSP platform) {
48631048e8SLevon Ter-Grigoryan m_remote_platform_sp = platform;
49631048e8SLevon Ter-Grigoryan }
50631048e8SLevon Ter-Grigoryan };
51631048e8SLevon Ter-Grigoryan
52631048e8SLevon Ter-Grigoryan class TargetPlatformTester : public Platform {
53631048e8SLevon Ter-Grigoryan public:
54631048e8SLevon Ter-Grigoryan using Platform::Platform;
55631048e8SLevon Ter-Grigoryan
56a458ef4fSPavel Labath MOCK_METHOD0(GetDescription, llvm::StringRef());
57a3939e15SPavel Labath MOCK_METHOD0(GetPluginName, llvm::StringRef());
58dde487e5SJonas Devlieghere MOCK_METHOD1(GetSupportedArchitectures,
59dde487e5SJonas Devlieghere std::vector<ArchSpec>(const ArchSpec &process_host_arch));
60631048e8SLevon Ter-Grigoryan MOCK_METHOD4(Attach,
61631048e8SLevon Ter-Grigoryan ProcessSP(ProcessAttachInfo &, Debugger &, Target *, Status &));
62631048e8SLevon Ter-Grigoryan MOCK_METHOD0(CalculateTrapHandlerSymbolNames, void());
63631048e8SLevon Ter-Grigoryan MOCK_METHOD0(GetUserIDResolver, UserIDResolver &());
64631048e8SLevon Ter-Grigoryan };
65631048e8SLevon Ter-Grigoryan
66631048e8SLevon Ter-Grigoryan namespace {
67631048e8SLevon Ter-Grigoryan class RemoteAwarePlatformTest : public testing::Test {
68631048e8SLevon Ter-Grigoryan public:
SetUpTestCase()69631048e8SLevon Ter-Grigoryan static void SetUpTestCase() { FileSystem::Initialize(); }
TearDownTestCase()70631048e8SLevon Ter-Grigoryan static void TearDownTestCase() { FileSystem::Terminate(); }
71631048e8SLevon Ter-Grigoryan };
72631048e8SLevon Ter-Grigoryan } // namespace
73631048e8SLevon Ter-Grigoryan
TEST_F(RemoteAwarePlatformTest,TestResolveExecutabelOnClientByPlatform)74631048e8SLevon Ter-Grigoryan TEST_F(RemoteAwarePlatformTest, TestResolveExecutabelOnClientByPlatform) {
75631048e8SLevon Ter-Grigoryan ModuleSpec executable_spec;
76631048e8SLevon Ter-Grigoryan ModuleSP expected_executable(new Module(executable_spec));
77631048e8SLevon Ter-Grigoryan
78631048e8SLevon Ter-Grigoryan RemoteAwarePlatformTester platform(false);
79dde487e5SJonas Devlieghere static const ArchSpec process_host_arch;
80dde487e5SJonas Devlieghere EXPECT_CALL(platform, GetSupportedArchitectures(process_host_arch))
8196beb30fSPavel Labath .WillRepeatedly(Return(std::vector<ArchSpec>()));
82098c01c1SPavel Labath EXPECT_CALL(platform, ResolveRemoteExecutable(_, _))
83098c01c1SPavel Labath .WillRepeatedly(Return(std::make_pair(Status(), expected_executable)));
84631048e8SLevon Ter-Grigoryan
85098c01c1SPavel Labath platform.SetRemotePlatform(std::make_shared<TargetPlatformTester>(false));
86631048e8SLevon Ter-Grigoryan
87631048e8SLevon Ter-Grigoryan ModuleSP resolved_sp;
88631048e8SLevon Ter-Grigoryan lldb_private::Status status =
89631048e8SLevon Ter-Grigoryan platform.ResolveExecutable(executable_spec, resolved_sp, nullptr);
90631048e8SLevon Ter-Grigoryan
91631048e8SLevon Ter-Grigoryan ASSERT_TRUE(status.Success());
92631048e8SLevon Ter-Grigoryan EXPECT_EQ(expected_executable.get(), resolved_sp.get());
93631048e8SLevon Ter-Grigoryan }
94