xref: /llvm-project/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp (revision e3959de26867d65410d4d5e1fc8c9c8f5bb2951a)
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 class TestScriptInterpreterPython : public ScriptInterpreterPython {
20 public:
21   using ScriptInterpreterPython::Initialize;
22   using ScriptInterpreterPython::InitializePrivate;
23 };
24 
25 void PythonTestSuite::SetUp() {
26   FileSystem::Initialize();
27   HostInfoBase::Initialize();
28   // ScriptInterpreterPython::Initialize() depends on HostInfo being
29   // initializedso it can compute the python directory etc.
30   TestScriptInterpreterPython::Initialize();
31   TestScriptInterpreterPython::InitializePrivate();
32 
33   // Although we don't care about concurrency for the purposes of running
34   // this test suite, Python requires the GIL to be locked even for
35   // deallocating memory, which can happen when you call Py_DECREF or
36   // Py_INCREF.  So acquire the GIL for the entire duration of this
37   // test suite.
38   m_gil_state = PyGILState_Ensure();
39 }
40 
41 void PythonTestSuite::TearDown() {
42   PyGILState_Release(m_gil_state);
43 
44   TestScriptInterpreterPython::Terminate();
45   HostInfoBase::Terminate();
46   FileSystem::Terminate();
47 }
48