From: Chris Bieneman Date: Thu, 27 Oct 2016 22:52:32 +0000 (+0000) Subject: [Test Suite] Pull generateSource into lldbtest X-Git-Tag: llvmorg-4.0.0-rc1~6079 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f817bae1616852aeae880aa8e6a22407276aa223;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/lldb/packages/Python/lldbsuite/test/api/check_public_api_headers/TestPublicAPIHeaders.py b/lldb/packages/Python/lldbsuite/test/api/check_public_api_headers/TestPublicAPIHeaders.py index 0b202a0..dd6dbe0 100644 --- a/lldb/packages/Python/lldbsuite/test/api/check_public_api_headers/TestPublicAPIHeaders.py +++ b/lldb/packages/Python/lldbsuite/test/api/check_public_api_headers/TestPublicAPIHeaders.py @@ -19,9 +19,9 @@ class SBDirCheckerCase(TestBase): def setUp(self): TestBase.setUp(self) - self.template = 'main.cpp.template' self.source = 'main.cpp' self.exe_name = 'a.out' + self.generateSource(self.source) @skipIfNoSBHeaders def test_sb_api_directory(self): @@ -34,40 +34,9 @@ class SBDirCheckerCase(TestBase): self.skipTest( "LLDB is 64-bit and cannot be linked to 32-bit test program.") - # Generate main.cpp, build it, and execute. - self.generate_main_cpp() self.buildDriver(self.source, self.exe_name) self.sanity_check_executable(self.exe_name) - def generate_main_cpp(self): - """Generate main.cpp from main.cpp.template.""" - temp = os.path.join(os.getcwd(), self.template) - with open(temp, 'r') as f: - content = f.read() - - public_api_dir = os.path.join( - os.environ["LLDB_SRC"], "include", "lldb", "API") - - # Look under the include/lldb/API directory and add #include statements - # for all the SB API headers. - public_headers = os.listdir(public_api_dir) - # For different platforms, the include statement can vary. - if self.platformIsDarwin(): - include_stmt = "'#include <%s>' % os.path.join('LLDB', header)" - if self.getPlatform() == "freebsd" or self.getPlatform( - ) == "linux" or os.environ.get('LLDB_BUILD_TYPE') == 'Makefile': - include_stmt = "'#include <%s>' % os.path.join(public_api_dir, header)" - list = [eval(include_stmt) for header in public_headers if ( - header.startswith("SB") and header.endswith(".h"))] - includes = '\n'.join(list) - new_content = content.replace('%include_SB_APIs%', includes) - src = os.path.join(os.getcwd(), self.source) - with open(src, 'w') as f: - f.write(new_content) - - # The main.cpp has been generated, add a teardown hook to remove it. - self.addTearDownHook(lambda: os.remove(src)) - def sanity_check_executable(self, exe_name): """Sanity check executable compiled from the auto-generated program.""" exe = os.path.join(os.getcwd(), exe_name) diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/TestMultithreaded.py b/lldb/packages/Python/lldbsuite/test/api/multithreaded/TestMultithreaded.py index 970c251..abd252b 100644 --- a/lldb/packages/Python/lldbsuite/test/api/multithreaded/TestMultithreaded.py +++ b/lldb/packages/Python/lldbsuite/test/api/multithreaded/TestMultithreaded.py @@ -15,6 +15,15 @@ import subprocess class SBBreakpointCallbackCase(TestBase): + def setUp(self): + TestBase.setUp(self) + self.generateSource('driver.cpp') + self.generateSource('listener_test.cpp') + self.generateSource('test_breakpoint_callback.cpp') + self.generateSource('test_listener_event_description.cpp') + self.generateSource('test_listener_event_process_state.cpp') + self.generateSource('test_listener_resume.cpp') + mydir = TestBase.compute_mydir(__file__) @skipIfRemote diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp b/lldb/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp.template similarity index 96% rename from lldb/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp rename to lldb/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp.template index fa0c48e..adb1d20 100644 --- a/lldb/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp +++ b/lldb/packages/Python/lldbsuite/test/api/multithreaded/driver.cpp.template @@ -7,7 +7,7 @@ #include #include -#include "lldb-headers.h" +%include_SB_APIs% #include "common.h" diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp b/lldb/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp.template similarity index 98% rename from lldb/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp rename to lldb/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp.template index b20868f..e305d1a 100644 --- a/lldb/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp +++ b/lldb/packages/Python/lldbsuite/test/api/multithreaded/listener_test.cpp.template @@ -7,7 +7,7 @@ #include #include -#include "lldb-headers.h" +%include_SB_APIs% #include "common.h" using namespace lldb; diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/lldb-headers.h b/lldb/packages/Python/lldbsuite/test/api/multithreaded/lldb-headers.h deleted file mode 100644 index da0914b..0000000 --- a/lldb/packages/Python/lldbsuite/test/api/multithreaded/lldb-headers.h +++ /dev/null @@ -1,11 +0,0 @@ - -#ifndef LLDB_HEADERS_H -#define LLDB_HEADERS_H - -#ifdef __APPLE__ -#include -#else -#include "lldb/API/LLDB.h" -#endif - -#endif // LLDB_HEADERS_H diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp.template similarity index 98% rename from lldb/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp rename to lldb/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp.template index def31f8..4133025 100644 --- a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp +++ b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_breakpoint_callback.cpp.template @@ -7,7 +7,7 @@ #include #include -#include "lldb-headers.h" +%include_SB_APIs% #include "common.h" diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp.template similarity index 98% rename from lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp rename to lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp.template index 0d7844d..63e3f36 100644 --- a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp +++ b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_description.cpp.template @@ -8,7 +8,7 @@ #include #include -#include "lldb-headers.h" +%include_SB_APIs% #include "common.h" diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp.template similarity index 98% rename from lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp rename to lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp.template index 574257e..2926ece 100644 --- a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp +++ b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_event_process_state.cpp.template @@ -8,7 +8,7 @@ #include #include -#include "lldb-headers.h" +%include_SB_APIs% #include "common.h" diff --git a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp.template similarity index 98% rename from lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp rename to lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp.template index 8cf786b..4adc9b3 100644 --- a/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp +++ b/lldb/packages/Python/lldbsuite/test/api/multithreaded/test_listener_resume.cpp.template @@ -8,7 +8,7 @@ #include #include -#include "lldb-headers.h" +%include_SB_APIs% #include "common.h" diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/plugins/commands/TestPluginCommands.py b/lldb/packages/Python/lldbsuite/test/functionalities/plugins/commands/TestPluginCommands.py index 9341ff9..18fcc41 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/plugins/commands/TestPluginCommands.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/plugins/commands/TestPluginCommands.py @@ -18,6 +18,10 @@ class PluginCommandTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) + def setUp(self): + TestBase.setUp(self) + self.generateSource('plugin.cpp') + @skipIfNoSBHeaders # Requires a compatible arch and platform to link against the host's built # lldb lib. diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/plugins/commands/plugin.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/plugins/commands/plugin.cpp.template similarity index 85% rename from lldb/packages/Python/lldbsuite/test/functionalities/plugins/commands/plugin.cpp rename to lldb/packages/Python/lldbsuite/test/functionalities/plugins/commands/plugin.cpp.template index be3d293..393e9fe 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/plugins/commands/plugin.cpp +++ b/lldb/packages/Python/lldbsuite/test/functionalities/plugins/commands/plugin.cpp.template @@ -13,15 +13,7 @@ Compile this into a dylib foo.dylib and load by placing in appropriate locations by typing plugin load foo.dylib at the LLDB command line */ -#if defined (__APPLE__) -#include -#include -#include -#else -#include -#include -#include -#endif +%include_SB_APIs% namespace lldb { bool diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py index a79e06f..2c5cd2e 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbtest.py +++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -1824,6 +1824,33 @@ class TestBase(Base): folder = os.path.dirname(folder) continue + def generateSource(self, source): + template = source + '.template' + temp = os.path.join(os.getcwd(), template) + with open(temp, 'r') as f: + content = f.read() + + public_api_dir = os.path.join( + os.environ["LLDB_SRC"], "include", "lldb", "API") + + # Look under the include/lldb/API directory and add #include statements + # for all the SB API headers. + public_headers = os.listdir(public_api_dir) + # For different platforms, the include statement can vary. + if self.hasDarwinFramework(): + include_stmt = "'#include <%s>' % os.path.join('LLDB', header)" + else: + include_stmt = "'#include <%s>' % os.path.join(public_api_dir, header)" + list = [eval(include_stmt) for header in public_headers if ( + header.startswith("SB") and header.endswith(".h"))] + includes = '\n'.join(list) + new_content = content.replace('%include_SB_APIs%', includes) + src = os.path.join(os.getcwd(), source) + with open(src, 'w') as f: + f.write(new_content) + + self.addTearDownHook(lambda: os.remove(src)) + def setUp(self): #import traceback # traceback.print_stack()