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