brintos

brintos / llvm-project-archived public Read only

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