xref: /llvm-project/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp (revision 8c68837df383bc7749d34317fd5df56dfc24f388)
1 //===-- PythonTestSuite.cpp -------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "gtest/gtest.h"
11 #include "Plugins/ScriptInterpreter/Python/lldb-python.h"
12 
13 #include "lldb/Host/HostInfo.h"
14 #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
15 
16 #include "PythonTestSuite.h"
17 
18 using namespace lldb_private;
19 
20 void
21 PythonTestSuite::SetUp()
22 {
23     HostInfoBase::Initialize();
24     // ScriptInterpreterPython::Initialize() depends on HostInfo being
25     // initializedso it can compute the python directory etc.
26     ScriptInterpreterPython::Initialize();
27     ScriptInterpreterPython::InitializePrivate();
28 
29     // Although we don't care about concurrency for the purposes of running
30     // this test suite, Python requires the GIL to be locked even for
31     // deallocating memory, which can happen when you call Py_DECREF or
32     // Py_INCREF.  So acquire the GIL for the entire duration of this
33     // test suite.
34     m_gil_state = PyGILState_Ensure();
35 }
36 
37 void
38 PythonTestSuite::TearDown()
39 {
40     PyGILState_Release(m_gil_state);
41 
42     ScriptInterpreterPython::Terminate();
43 }
44