Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@ -0,0 +1,13 @@
add_lldb_unittest(ScriptInterpreterPythonTests
PythonDataObjectsTests.cpp
PythonExceptionStateTests.cpp
PythonTestSuite.cpp
LINK_LIBS
lldbHost
lldbPluginScriptInterpreterPython
${PYTHON_LIBRARY}
LINK_COMPONENTS
Support
)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,165 @@
//===-- PythonExceptionStateTest.cpp ------------------------------*- C++
//-*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "gtest/gtest.h"
#include "Plugins/ScriptInterpreter/Python/PythonDataObjects.h"
#include "Plugins/ScriptInterpreter/Python/PythonExceptionState.h"
#include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
#include "Plugins/ScriptInterpreter/Python/lldb-python.h"
#include "PythonTestSuite.h"
using namespace lldb_private;
class PythonExceptionStateTest : public PythonTestSuite {
public:
protected:
void RaiseException() {
PyErr_SetString(PyExc_RuntimeError, "PythonExceptionStateTest test error");
}
};
TEST_F(PythonExceptionStateTest, TestExceptionStateChecking) {
PyErr_Clear();
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
RaiseException();
EXPECT_TRUE(PythonExceptionState::HasErrorOccurred());
PyErr_Clear();
}
TEST_F(PythonExceptionStateTest, TestAcquisitionSemantics) {
PyErr_Clear();
PythonExceptionState no_error(false);
EXPECT_FALSE(no_error.IsError());
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
PyErr_Clear();
RaiseException();
PythonExceptionState error(false);
EXPECT_TRUE(error.IsError());
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
error.Discard();
PyErr_Clear();
RaiseException();
error.Acquire(false);
EXPECT_TRUE(error.IsError());
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
PyErr_Clear();
}
TEST_F(PythonExceptionStateTest, TestDiscardSemantics) {
PyErr_Clear();
// Test that discarding an exception does not restore the exception
// state even when auto-restore==true is set
RaiseException();
PythonExceptionState error(true);
EXPECT_TRUE(error.IsError());
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
error.Discard();
EXPECT_FALSE(error.IsError());
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
}
TEST_F(PythonExceptionStateTest, TestResetSemantics) {
PyErr_Clear();
// Resetting when auto-restore is true should restore.
RaiseException();
PythonExceptionState error(true);
EXPECT_TRUE(error.IsError());
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
error.Reset();
EXPECT_FALSE(error.IsError());
EXPECT_TRUE(PythonExceptionState::HasErrorOccurred());
PyErr_Clear();
// Resetting when auto-restore is false should discard.
RaiseException();
PythonExceptionState error2(false);
EXPECT_TRUE(error2.IsError());
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
error2.Reset();
EXPECT_FALSE(error2.IsError());
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
PyErr_Clear();
}
TEST_F(PythonExceptionStateTest, TestManualRestoreSemantics) {
PyErr_Clear();
RaiseException();
PythonExceptionState error(false);
EXPECT_TRUE(error.IsError());
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
error.Restore();
EXPECT_FALSE(error.IsError());
EXPECT_TRUE(PythonExceptionState::HasErrorOccurred());
PyErr_Clear();
}
TEST_F(PythonExceptionStateTest, TestAutoRestoreSemantics) {
PyErr_Clear();
// Test that using the auto-restore flag correctly restores the exception
// state on destruction, and not using the auto-restore flag correctly
// does NOT restore the state on destruction.
{
RaiseException();
PythonExceptionState error(false);
EXPECT_TRUE(error.IsError());
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
}
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
PyErr_Clear();
{
RaiseException();
PythonExceptionState error(true);
EXPECT_TRUE(error.IsError());
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
}
EXPECT_TRUE(PythonExceptionState::HasErrorOccurred());
PyErr_Clear();
}
TEST_F(PythonExceptionStateTest, TestAutoRestoreChanged) {
// Test that if we re-acquire with different auto-restore semantics,
// that the new semantics are respected.
PyErr_Clear();
RaiseException();
PythonExceptionState error(false);
EXPECT_TRUE(error.IsError());
error.Reset();
EXPECT_FALSE(error.IsError());
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
RaiseException();
error.Acquire(true);
EXPECT_TRUE(error.IsError());
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
error.Reset();
EXPECT_FALSE(error.IsError());
EXPECT_TRUE(PythonExceptionState::HasErrorOccurred());
PyErr_Clear();
}

View File

@ -0,0 +1,39 @@
//===-- PythonTestSuite.cpp -------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "Plugins/ScriptInterpreter/Python/lldb-python.h"
#include "gtest/gtest.h"
#include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
#include "lldb/Host/HostInfo.h"
#include "PythonTestSuite.h"
using namespace lldb_private;
void PythonTestSuite::SetUp() {
HostInfoBase::Initialize();
// ScriptInterpreterPython::Initialize() depends on HostInfo being
// initializedso it can compute the python directory etc.
ScriptInterpreterPython::Initialize();
ScriptInterpreterPython::InitializePrivate();
// Although we don't care about concurrency for the purposes of running
// this test suite, Python requires the GIL to be locked even for
// deallocating memory, which can happen when you call Py_DECREF or
// Py_INCREF. So acquire the GIL for the entire duration of this
// test suite.
m_gil_state = PyGILState_Ensure();
}
void PythonTestSuite::TearDown() {
PyGILState_Release(m_gil_state);
ScriptInterpreterPython::Terminate();
}

View File

@ -0,0 +1,22 @@
//===-- PythonTestSuite.cpp -------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "gtest/gtest.h"
using namespace lldb_private;
class PythonTestSuite : public testing::Test {
public:
void SetUp() override;
void TearDown() override;
private:
PyGILState_STATE m_gil_state;
};