Skip to content

Commit f817bae

Browse files
author
Chris Bieneman
committedOct 27, 2016
[Test Suite] Pull generateSource into lldbtest
Summary: Convert tests using LLDB headers to use generateSource to put the right include paths in place regardless of whether or not you're building a framework. This also abstracted generateSource out of TestPublicAPIHeaders.py into lldbtest.py. Reviewers: tfiala, zturner Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D25887 llvm-svn: 285357
1 parent 91967bd commit f817bae

12 files changed

+48
-58
lines changed
 

‎lldb/packages/Python/lldbsuite/test/api/check_public_api_headers/TestPublicAPIHeaders.py

+1-32
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class SBDirCheckerCase(TestBase):
1919

2020
def setUp(self):
2121
TestBase.setUp(self)
22-
self.template = 'main.cpp.template'
2322
self.source = 'main.cpp'
2423
self.exe_name = 'a.out'
24+
self.generateSource(self.source)
2525

2626
@skipIfNoSBHeaders
2727
def test_sb_api_directory(self):
@@ -34,40 +34,9 @@ def test_sb_api_directory(self):
3434
self.skipTest(
3535
"LLDB is 64-bit and cannot be linked to 32-bit test program.")
3636

37-
# Generate main.cpp, build it, and execute.
38-
self.generate_main_cpp()
3937
self.buildDriver(self.source, self.exe_name)
4038
self.sanity_check_executable(self.exe_name)
4139

42-
def generate_main_cpp(self):
43-
"""Generate main.cpp from main.cpp.template."""
44-
temp = os.path.join(os.getcwd(), self.template)
45-
with open(temp, 'r') as f:
46-
content = f.read()
47-
48-
public_api_dir = os.path.join(
49-
os.environ["LLDB_SRC"], "include", "lldb", "API")
50-
51-
# Look under the include/lldb/API directory and add #include statements
52-
# for all the SB API headers.
53-
public_headers = os.listdir(public_api_dir)
54-
# For different platforms, the include statement can vary.
55-
if self.platformIsDarwin():
56-
include_stmt = "'#include <%s>' % os.path.join('LLDB', header)"
57-
if self.getPlatform() == "freebsd" or self.getPlatform(
58-
) == "linux" or os.environ.get('LLDB_BUILD_TYPE') == 'Makefile':
59-
include_stmt = "'#include <%s>' % os.path.join(public_api_dir, header)"
60-
list = [eval(include_stmt) for header in public_headers if (
61-
header.startswith("SB") and header.endswith(".h"))]
62-
includes = '\n'.join(list)
63-
new_content = content.replace('%include_SB_APIs%', includes)
64-
src = os.path.join(os.getcwd(), self.source)
65-
with open(src, 'w') as f:
66-
f.write(new_content)
67-
68-
# The main.cpp has been generated, add a teardown hook to remove it.
69-
self.addTearDownHook(lambda: os.remove(src))
70-
7140
def sanity_check_executable(self, exe_name):
7241
"""Sanity check executable compiled from the auto-generated program."""
7342
exe = os.path.join(os.getcwd(), exe_name)

‎lldb/packages/Python/lldbsuite/test/api/multithreaded/TestMultithreaded.py

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515

1616
class SBBreakpointCallbackCase(TestBase):
1717

18+
def setUp(self):
19+
TestBase.setUp(self)
20+
self.generateSource('driver.cpp')
21+
self.generateSource('listener_test.cpp')
22+
self.generateSource('test_breakpoint_callback.cpp')
23+
self.generateSource('test_listener_event_description.cpp')
24+
self.generateSource('test_listener_event_process_state.cpp')
25+
self.generateSource('test_listener_resume.cpp')
26+
1827
mydir = TestBase.compute_mydir(__file__)
1928

2029
@skipIfRemote

‎lldb/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp ‎lldb/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <string>
88
#include <vector>
99

10-
#include "lldb-headers.h"
10+
%include_SB_APIs%
1111

1212
#include "common.h"
1313

‎lldb/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp ‎lldb/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <thread>
88
#include <vector>
99

10-
#include "lldb-headers.h"
10+
%include_SB_APIs%
1111
#include "common.h"
1212

1313
using namespace lldb;

‎lldb/packages/Python/lldbsuite/test/api/multithreaded/lldb-headers.h

-11
This file was deleted.

‎lldb/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp ‎lldb/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <vector>
88
#include <string>
99

10-
#include "lldb-headers.h"
10+
%include_SB_APIs%
1111

1212
#include "common.h"
1313

‎lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp ‎lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <string>
99
#include <thread>
1010

11-
#include "lldb-headers.h"
11+
%include_SB_APIs%
1212

1313
#include "common.h"
1414

‎lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp ‎lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <string>
99
#include <thread>
1010

11-
#include "lldb-headers.h"
11+
%include_SB_APIs%
1212

1313
#include "common.h"
1414

‎lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp ‎lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <string>
99
#include <thread>
1010

11-
#include "lldb-headers.h"
11+
%include_SB_APIs%
1212

1313
#include "common.h"
1414

‎lldb/packages/Python/lldbsuite/test/functionalities/plugins/commands/TestPluginCommands.py

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class PluginCommandTestCase(TestBase):
1818

1919
mydir = TestBase.compute_mydir(__file__)
2020

21+
def setUp(self):
22+
TestBase.setUp(self)
23+
self.generateSource('plugin.cpp')
24+
2125
@skipIfNoSBHeaders
2226
# Requires a compatible arch and platform to link against the host's built
2327
# lldb lib.

‎lldb/packages/Python/lldbsuite/test/functionalities/plugins/commands/plugin.cpp ‎lldb/packages/Python/lldbsuite/test/functionalities/plugins/commands/plugin.cpp.template

+1-9
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,7 @@ Compile this into a dylib foo.dylib and load by placing in appropriate locations
1313
by typing plugin load foo.dylib at the LLDB command line
1414
*/
1515

16-
#if defined (__APPLE__)
17-
#include <LLDB/SBCommandInterpreter.h>
18-
#include <LLDB/SBCommandReturnObject.h>
19-
#include <LLDB/SBDebugger.h>
20-
#else
21-
#include <lldb/API/SBCommandInterpreter.h>
22-
#include <lldb/API/SBCommandReturnObject.h>
23-
#include <lldb/API/SBDebugger.h>
24-
#endif
16+
%include_SB_APIs%
2517

2618
namespace lldb {
2719
bool

‎lldb/packages/Python/lldbsuite/test/lldbtest.py

+27
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,33 @@ def getCategories(self):
18241824
folder = os.path.dirname(folder)
18251825
continue
18261826

1827+
def generateSource(self, source):
1828+
template = source + '.template'
1829+
temp = os.path.join(os.getcwd(), template)
1830+
with open(temp, 'r') as f:
1831+
content = f.read()
1832+
1833+
public_api_dir = os.path.join(
1834+
os.environ["LLDB_SRC"], "include", "lldb", "API")
1835+
1836+
# Look under the include/lldb/API directory and add #include statements
1837+
# for all the SB API headers.
1838+
public_headers = os.listdir(public_api_dir)
1839+
# For different platforms, the include statement can vary.
1840+
if self.hasDarwinFramework():
1841+
include_stmt = "'#include <%s>' % os.path.join('LLDB', header)"
1842+
else:
1843+
include_stmt = "'#include <%s>' % os.path.join(public_api_dir, header)"
1844+
list = [eval(include_stmt) for header in public_headers if (
1845+
header.startswith("SB") and header.endswith(".h"))]
1846+
includes = '\n'.join(list)
1847+
new_content = content.replace('%include_SB_APIs%', includes)
1848+
src = os.path.join(os.getcwd(), source)
1849+
with open(src, 'w') as f:
1850+
f.write(new_content)
1851+
1852+
self.addTearDownHook(lambda: os.remove(src))
1853+
18271854
def setUp(self):
18281855
#import traceback
18291856
# traceback.print_stack()

0 commit comments

Comments
 (0)
Please sign in to comment.