1c946d462SZachary Turner //===-- PythonTestSuite.cpp -------------------------------------*- C++ -*-===//
2c946d462SZachary Turner //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6c946d462SZachary Turner //
7c946d462SZachary Turner //===----------------------------------------------------------------------===//
8c946d462SZachary Turner 
9b9c1b51eSKate Stone #include "gtest/gtest.h"
10c946d462SZachary Turner 
11c946d462SZachary Turner #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
1246376966SJonas Devlieghere #include "Plugins/ScriptInterpreter/Python/lldb-python.h"
1346376966SJonas Devlieghere #include "lldb/Host/FileSystem.h"
14b9c1b51eSKate Stone #include "lldb/Host/HostInfo.h"
15c946d462SZachary Turner 
16c946d462SZachary Turner #include "PythonTestSuite.h"
17c946d462SZachary Turner 
18c946d462SZachary Turner using namespace lldb_private;
19*e3959de2SJonas Devlieghere class TestScriptInterpreterPython : public ScriptInterpreterPython {
20*e3959de2SJonas Devlieghere public:
21*e3959de2SJonas Devlieghere   using ScriptInterpreterPython::Initialize;
22*e3959de2SJonas Devlieghere   using ScriptInterpreterPython::InitializePrivate;
23*e3959de2SJonas Devlieghere };
24c946d462SZachary Turner 
25b9c1b51eSKate Stone void PythonTestSuite::SetUp() {
2646376966SJonas Devlieghere   FileSystem::Initialize();
27c946d462SZachary Turner   HostInfoBase::Initialize();
28c946d462SZachary Turner   // ScriptInterpreterPython::Initialize() depends on HostInfo being
29c946d462SZachary Turner   // initializedso it can compute the python directory etc.
30*e3959de2SJonas Devlieghere   TestScriptInterpreterPython::Initialize();
31*e3959de2SJonas Devlieghere   TestScriptInterpreterPython::InitializePrivate();
32c946d462SZachary Turner 
33c946d462SZachary Turner   // Although we don't care about concurrency for the purposes of running
34c946d462SZachary Turner   // this test suite, Python requires the GIL to be locked even for
35c946d462SZachary Turner   // deallocating memory, which can happen when you call Py_DECREF or
36c946d462SZachary Turner   // Py_INCREF.  So acquire the GIL for the entire duration of this
37c946d462SZachary Turner   // test suite.
38c946d462SZachary Turner   m_gil_state = PyGILState_Ensure();
39c946d462SZachary Turner }
40c946d462SZachary Turner 
41b9c1b51eSKate Stone void PythonTestSuite::TearDown() {
42c946d462SZachary Turner   PyGILState_Release(m_gil_state);
43c946d462SZachary Turner 
44*e3959de2SJonas Devlieghere   TestScriptInterpreterPython::Terminate();
450bca15a3SJonas Devlieghere   HostInfoBase::Terminate();
460bca15a3SJonas Devlieghere   FileSystem::Terminate();
47c946d462SZachary Turner }
48