1 //===-- PythonTestSuite.cpp -------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "gtest/gtest.h" 10 11 #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h" 12 #include "Plugins/ScriptInterpreter/Python/lldb-python.h" 13 #include "lldb/Host/FileSystem.h" 14 #include "lldb/Host/HostInfo.h" 15 16 #include "PythonTestSuite.h" 17 18 using namespace lldb_private; 19 20 void PythonTestSuite::SetUp() { 21 FileSystem::Initialize(); 22 HostInfoBase::Initialize(); 23 // ScriptInterpreterPython::Initialize() depends on HostInfo being 24 // initializedso it can compute the python directory etc. 25 ScriptInterpreterPython::Initialize(); 26 ScriptInterpreterPython::InitializePrivate(); 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 PythonTestSuite::TearDown() { 37 PyGILState_Release(m_gil_state); 38 39 ScriptInterpreterPython::Terminate(); 40 HostInfoBase::Terminate(); 41 FileSystem::Terminate(); 42 } 43