Author: Jonas Devlieghere Date: 2020-05-22T13:07:10-07:00 New Revision: 5a85582eb26f0c8f6b8ef5a14385d608ef10385c
URL: https://github.com/llvm/llvm-project/commit/5a85582eb26f0c8f6b8ef5a14385d608ef10385c DIFF: https://github.com/llvm/llvm-project/commit/5a85582eb26f0c8f6b8ef5a14385d608ef10385c.diff LOG: [lldb/Reproducers] Make the type tests work with reproducers Added: Modified: lldb/packages/Python/lldbsuite/test/lldbtest.py lldb/test/API/types/AbstractBase.py Removed: ################################################################################ diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py index 9d119e08b6c3..b02181ae1ffc 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbtest.py +++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -667,6 +667,13 @@ def getBuildDir(self): return os.path.join(os.environ["LLDB_BUILD"], self.mydir, self.getBuildDirBasename()) + def getReproducerDir(self): + """Return the full path to the reproducer if enabled.""" + if configuration.capture_path: + return configuration.capture_path + if configuration.replay_path: + return configuration.replay_path + return None def makeBuildDir(self): """Create the test-specific working directory, deleting any previous @@ -685,6 +692,9 @@ def getSourcePath(self, name): """Return absolute path to a file in the test's source directory.""" return os.path.join(self.getSourceDir(), name) + def getReproducerArtifact(self, name): + return os.path.join(self.getReproducerDir(), name) + @classmethod def setUpCommands(cls): commands = [ diff --git a/lldb/test/API/types/AbstractBase.py b/lldb/test/API/types/AbstractBase.py index f2abfa092a7e..df8416b9c41f 100644 --- a/lldb/test/API/types/AbstractBase.py +++ b/lldb/test/API/types/AbstractBase.py @@ -33,12 +33,15 @@ def setUp(self): # module cacheing subsystem to be confused with executable name "a.out" # used for all the test cases. self.exe_name = self.testMethodName - self.golden_filename = self.getBuildArtifact("golden-output.txt") + golden = "{}-golden-output.txt".format(self.testMethodName) + if configuration.is_reproducer(): + self.golden_filename = self.getReproducerArtifact(golden) + else: + self.golden_filename = self.getBuildArtifact(golden) def tearDown(self): """Cleanup the test byproducts.""" - #print("Removing golden-output.txt...") - if os.path.exists(self.golden_filename): + if os.path.exists(self.golden_filename) and not configuration.is_reproducer(): os.remove(self.golden_filename) TestBase.tearDown(self) @@ -88,7 +91,7 @@ def build_and_run_with_source_atoms_expr( blockCaptured=bc, quotedDisplay=qd) - def process_launch_o(self, localPath): + def process_launch_o(self): # process launch command output redirect always goes to host the # process is running on if lldb.remote_platform: @@ -101,10 +104,32 @@ def process_launch_o(self, localPath): # copy remote_path to local host self.runCmd('platform get-file {remote} "{local}"'.format( remote=remote_path, local=self.golden_filename)) + elif configuration.is_reproducer_replay(): + # Don't overwrite the golden file generated at capture time. + self.runCmd('process launch') else: self.runCmd( 'process launch -o "{local}"'.format(local=self.golden_filename)) + def get_golden_list(self, blockCaptured=False): + with open(self.golden_filename, 'r') as f: + go = f.read() + + golden_list = [] + # Scan the golden output line by line, looking for the pattern: + # + # variable = 'value' + # + for line in go.split(os.linesep): + # We'll ignore variables of array types from inside a block. + if blockCaptured and '[' in line: + continue + match = self.pattern.search(line) + if match: + var, val = match.group(1), match.group(2) + golden_list.append((var, val)) + return golden_list + def generic_type_tester( self, exe_name, @@ -117,29 +142,11 @@ def generic_type_tester( # First, capture the golden output emitted by the oracle, i.e., the # series of printf statements. - - self.process_launch_o(self.golden_filename) - - with open(self.golden_filename) as f: - go = f.read() + self.process_launch_o() # This golden list contains a list of (variable, value) pairs extracted # from the golden output. - gl = [] - - # Scan the golden output line by line, looking for the pattern: - # - # variable = 'value' - # - for line in go.split(os.linesep): - # We'll ignore variables of array types from inside a block. - if blockCaptured and '[' in line: - continue - match = self.pattern.search(line) - if match: - var, val = match.group(1), match.group(2) - gl.append((var, val)) - #print("golden list:", gl) + gl = self.get_golden_list(blockCaptured) # This test uses a #include of "basic_type.cpp" so we need to enable # always setting inlined breakpoints. @@ -213,29 +220,11 @@ def generic_type_expr_tester( # First, capture the golden output emitted by the oracle, i.e., the # series of printf statements. - - self.process_launch_o(self.golden_filename) - - with open(self.golden_filename) as f: - go = f.read() + self.process_launch_o() # This golden list contains a list of (variable, value) pairs extracted # from the golden output. - gl = [] - - # Scan the golden output line by line, looking for the pattern: - # - # variable = 'value' - # - for line in go.split(os.linesep): - # We'll ignore variables of array types from inside a block. - if blockCaptured and '[' in line: - continue - match = self.pattern.search(line) - if match: - var, val = match.group(1), match.group(2) - gl.append((var, val)) - #print("golden list:", gl) + gl = self.get_golden_list(blockCaptured) # This test uses a #include of "basic_type.cpp" so we need to enable # always setting inlined breakpoints. _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits