brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.7 KiB · 7918b25 Raw
117 lines · cpp
1//===-- ExecutionContextTest.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/ExecutionContext.h"10#include "Plugins/Platform/Linux/PlatformLinux.h"11#include "lldb/Core/Debugger.h"12#include "lldb/Host/FileSystem.h"13#include "lldb/Host/HostInfo.h"14#include "lldb/Target/Platform.h"15#include "lldb/Target/Process.h"16#include "lldb/Target/Target.h"17#include "lldb/Utility/ArchSpec.h"18#include "lldb/Utility/Endian.h"19#include "lldb/lldb-enumerations.h"20#include "lldb/lldb-forward.h"21#include "lldb/lldb-private-enumerations.h"22#include "lldb/lldb-private.h"23#include "llvm/Support/FormatVariadic.h"24#include "gtest/gtest.h"25 26using namespace lldb_private;27using namespace lldb;28 29namespace {30class ExecutionContextTest : public ::testing::Test {31public:32  void SetUp() override {33    FileSystem::Initialize();34    HostInfo::Initialize();35    platform_linux::PlatformLinux::Initialize();36  }37  void TearDown() override {38    platform_linux::PlatformLinux::Terminate();39    HostInfo::Terminate();40    FileSystem::Terminate();41  }42};43 44class DummyProcess : public Process {45public:46  DummyProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp)47      : Process(target_sp, listener_sp) {}48 49  bool CanDebug(lldb::TargetSP target, bool plugin_specified_by_name) override {50    return true;51  }52  Status DoDestroy() override { return {}; }53  void RefreshStateAfterStop() override {}54  size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,55                      Status &error) override {56    return 0;57  }58  bool DoUpdateThreadList(ThreadList &old_thread_list,59                          ThreadList &new_thread_list) override {60    return false;61  }62  llvm::StringRef GetPluginName() override { return "Dummy"; }63};64} // namespace65 66TEST_F(ExecutionContextTest, GetByteOrder) {67  ExecutionContext exe_ctx(nullptr, nullptr, nullptr);68  EXPECT_EQ(endian::InlHostByteOrder(), exe_ctx.GetByteOrder());69}70 71TEST_F(ExecutionContextTest, GetByteOrderTarget) {72  ArchSpec arch("powerpc64-pc-linux");73 74  Platform::SetHostPlatform(75      platform_linux::PlatformLinux::CreateInstance(true, &arch));76 77  DebuggerSP debugger_sp = Debugger::CreateInstance();78  ASSERT_TRUE(debugger_sp);79 80  TargetSP target_sp;81  PlatformSP platform_sp;82  Status error = debugger_sp->GetTargetList().CreateTarget(83      *debugger_sp, "", arch, eLoadDependentsNo, platform_sp, target_sp);84  ASSERT_TRUE(target_sp);85  ASSERT_TRUE(target_sp->GetArchitecture().IsValid());86  ASSERT_TRUE(platform_sp);87 88  ExecutionContext target_ctx(target_sp, false);89  EXPECT_EQ(target_sp->GetArchitecture().GetByteOrder(),90            target_ctx.GetByteOrder());91}92 93TEST_F(ExecutionContextTest, GetByteOrderProcess) {94  ArchSpec arch("powerpc64-pc-linux");95 96  Platform::SetHostPlatform(97      platform_linux::PlatformLinux::CreateInstance(true, &arch));98 99  DebuggerSP debugger_sp = Debugger::CreateInstance();100  ASSERT_TRUE(debugger_sp);101 102  TargetSP target_sp;103  PlatformSP platform_sp;104  Status error = debugger_sp->GetTargetList().CreateTarget(105      *debugger_sp, "", arch, eLoadDependentsNo, platform_sp, target_sp);106  ASSERT_TRUE(target_sp);107  ASSERT_TRUE(target_sp->GetArchitecture().IsValid());108  ASSERT_TRUE(platform_sp);109 110  ListenerSP listener_sp(Listener::MakeListener("dummy"));111  ProcessSP process_sp = std::make_shared<DummyProcess>(target_sp, listener_sp);112  ASSERT_TRUE(process_sp);113 114  ExecutionContext process_ctx(process_sp);115  EXPECT_EQ(process_sp->GetByteOrder(), process_ctx.GetByteOrder());116}117