llvm/lldb/unittests/Process/ProcessEventDataTest.cpp

//===-- ProcessEventDataTest.cpp ------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
#include "TestingSupport/TestUtilities.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/StopInfo.h"
#include "lldb/Target/Thread.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/Event.h"
#include "gtest/gtest.h"

usingnamespacelldb_private;
usingnamespacelldb_private::repro;
usingnamespacelldb;

namespace {
class ProcessEventDataTest : public ::testing::Test {};

class DummyProcess : public Process {};

class DummyThread : public Thread {};

class DummyStopInfo : public StopInfo {};

class DummyProcessEventData : public Process::ProcessEventData {};
} // namespace

ProcessEventDataSP;
EventSP;

TargetSP CreateTarget(DebuggerSP &debugger_sp, ArchSpec &arch) {}

ThreadSP CreateThread(ProcessSP &process_sp, bool should_stop,
                      bool has_valid_stopinfo) {}

// Disable this test till I figure out why changing how events are sent
// to Secondary Listeners (44d9692e6a657ec46e98e4912ac56417da67cfee)
// caused this test to fail.  It is testing responses to events that are
// not delivered in the way Process events are meant to be delivered, it
// bypasses the private event queue, and I'm not sure is testing real
// behaviors.
#if 0
TEST_F(ProcessEventDataTest, DoOnRemoval) {
  ArchSpec arch("x86_64-apple-macosx-");

  Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, &arch));

  DebuggerSP debugger_sp = Debugger::CreateInstance();
  ASSERT_TRUE(debugger_sp);

  TargetSP target_sp = CreateTarget(debugger_sp, arch);
  ASSERT_TRUE(target_sp);

  ListenerSP listener_sp(Listener::MakeListener("dummy"));
  ProcessSP process_sp = std::make_shared<DummyProcess>(target_sp, listener_sp);
  ASSERT_TRUE(process_sp);

  /*
   Should hit ShouldStop if state is eStateStopped
   */
  ProcessEventDataSP event_data_sp =
      std::make_shared<DummyProcessEventData>(process_sp, eStateStopped);
  EventSP event_sp = std::make_shared<Event>(0, event_data_sp);
  event_data_sp->SetUpdateStateOnRemoval(event_sp.get());
  event_data_sp->DoOnRemoval(event_sp.get());
  bool result = static_cast<DummyProcessEventData *>(event_data_sp.get())
                    ->m_should_stop_hit_count == 1;
  ASSERT_TRUE(result);

  /*
   Should not hit ShouldStop if state is not eStateStopped
   */
  event_data_sp =
      std::make_shared<DummyProcessEventData>(process_sp, eStateStepping);
  event_sp = std::make_shared<Event>(0, event_data_sp);
  event_data_sp->SetUpdateStateOnRemoval(event_sp.get());
  event_data_sp->DoOnRemoval(event_sp.get());
  result = static_cast<DummyProcessEventData *>(event_data_sp.get())
               ->m_should_stop_hit_count == 0;
  ASSERT_TRUE(result);
}
#endif 

TEST_F(ProcessEventDataTest, ShouldStop) {}