xref: /llvm-project/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp (revision c946d46283b2578055c47de9b7ef7d182cd9a2ac)
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 
12 #include "lldb/Host/HostInfo.h"
13 #include "Plugins/ScriptInterpreter/Python/lldb-python.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 
28     // Although we don't care about concurrency for the purposes of running
29     // this test suite, Python requires the GIL to be locked even for
30     // deallocating memory, which can happen when you call Py_DECREF or
31     // Py_INCREF.  So acquire the GIL for the entire duration of this
32     // test suite.
33     m_gil_state = PyGILState_Ensure();
34 }
35 
36 void
37 PythonTestSuite::TearDown()
38 {
39     PyGILState_Release(m_gil_state);
40 
41     ScriptInterpreterPython::Terminate();
42 }
43