From 64c87a94caadc4a6351ab138dd2ca99975441b60 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 17 Jun 2020 09:32:17 -0700 Subject: [PATCH] [lldb/Test] Fix tests that rely on logfiles with reproducers. Now that the log file is included in the reproducers, the path needs to be remapped for the test to find the new file in the reproducer. --- lldb/packages/Python/lldbsuite/test/lldbtest.py | 6 ++++++ lldb/test/API/api/log/TestAPILog.py | 7 +++++-- lldb/test/API/commands/log/basic/TestLogging.py | 10 ++++++---- lldb/test/API/lang/c/modules/TestCModules.py | 4 +++- lldb/test/API/lang/cpp/accelerator-table/TestCPPAccelerator.py | 4 ++++ .../TestMembersAndLocalsWithSameName.py | 8 ++++++-- .../objc/modules-hash-mismatch/TestClangModulesHashMismatch.py | 4 +++- 7 files changed, 33 insertions(+), 10 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py index c537347..481c236 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbtest.py +++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -699,6 +699,12 @@ class Base(unittest2.TestCase): lldbutil.mkdir_p(self.getReproducerDir()) return os.path.join(self.getReproducerDir(), name) + def getReproducerRemappedPath(self, path): + assert configuration.replay_path + assert os.path.isabs(path) + path = os.path.relpath(path, '/') + return os.path.join(configuration.replay_path, 'root', path) + @classmethod def setUpCommands(cls): commands = [ diff --git a/lldb/test/API/api/log/TestAPILog.py b/lldb/test/API/api/log/TestAPILog.py index c0ffa2c..72df276 100644 --- a/lldb/test/API/api/log/TestAPILog.py +++ b/lldb/test/API/api/log/TestAPILog.py @@ -17,12 +17,15 @@ class APILogTestCase(TestBase): def test_api_log(self): """Test API logging""" - logfile = os.path.join(self.getBuildDir(), "api-log.txt") + logfile = self.getBuildArtifact("api-log.txt") def cleanup(): if os.path.exists(logfile): os.unlink(logfile) + if configuration.is_reproducer_replay(): + logfile = self.getReproducerRemappedPath(logfile) + self.addTearDownHook(cleanup) self.expect("log enable lldb api -f {}".format(logfile)) @@ -30,7 +33,7 @@ class APILogTestCase(TestBase): self.dbg.GetScriptingLanguage(None) target = self.dbg.CreateTarget(None) - print(logfile) + self.assertTrue(os.path.isfile(logfile)) with open(logfile, 'r') as f: log = f.read() diff --git a/lldb/test/API/commands/log/basic/TestLogging.py b/lldb/test/API/commands/log/basic/TestLogging.py index 16321dc..4ba67f8 100644 --- a/lldb/test/API/commands/log/basic/TestLogging.py +++ b/lldb/test/API/commands/log/basic/TestLogging.py @@ -20,6 +20,9 @@ class LogTestCase(TestBase): super(LogTestCase, self).setUp() self.log_file = self.getBuildArtifact("log-file.txt") + if configuration.is_reproducer_replay(): + self.log_file = self.getReproducerRemappedPath(self.log_file) + def test_file_writing(self): self.build() exe = self.getBuildArtifact("a.out") @@ -44,9 +47,8 @@ class LogTestCase(TestBase): self.assertTrue(os.path.isfile(self.log_file)) - f = open(self.log_file) - log_lines = f.readlines() - f.close() + with open(self.log_file, 'r') as f: + log_lines = f.read() os.remove(self.log_file) self.assertGreater( @@ -83,7 +85,7 @@ class LogTestCase(TestBase): self.runCmd("log disable lldb") self.assertTrue(os.path.isfile(self.log_file)) - with open(self.log_file, "r") as f: + with open(self.log_file, 'r') as f: contents = f.read() # check that it is still there diff --git a/lldb/test/API/lang/c/modules/TestCModules.py b/lldb/test/API/lang/c/modules/TestCModules.py index 948e8be..7dd073e 100644 --- a/lldb/test/API/lang/c/modules/TestCModules.py +++ b/lldb/test/API/lang/c/modules/TestCModules.py @@ -44,7 +44,9 @@ class CModulesTestCase(TestBase): substrs=[' resolved, hit count = 1']) # Enable logging of the imported AST. - log_file = os.path.join(self.getBuildDir(), "lldb-ast-log.txt") + log_file = self.getBuildArtifact("lldb-ast-log.txt") + if configuration.is_reproducer_replay(): + log_file = self.getReproducerRemappedPath(log_file) self.runCmd("log enable lldb ast -f '%s'" % log_file) self.expect( diff --git a/lldb/test/API/lang/cpp/accelerator-table/TestCPPAccelerator.py b/lldb/test/API/lang/cpp/accelerator-table/TestCPPAccelerator.py index 3705e95..54c5ccc 100644 --- a/lldb/test/API/lang/cpp/accelerator-table/TestCPPAccelerator.py +++ b/lldb/test/API/lang/cpp/accelerator-table/TestCPPAccelerator.py @@ -13,7 +13,11 @@ class CPPAcceleratorTableTestCase(TestBase): def test(self): """Test that type lookups fail early (performance)""" self.build() + logfile = self.getBuildArtifact('dwarf.log') + if configuration.is_reproducer_replay(): + logfile = self.getReproducerRemappedPath(logfile) + self.expect('log enable dwarf lookups -f' + logfile) target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( self, 'break here', lldb.SBFileSpec('main.cpp')) diff --git a/lldb/test/API/lang/cpp/member-and-local-vars-with-same-name/TestMembersAndLocalsWithSameName.py b/lldb/test/API/lang/cpp/member-and-local-vars-with-same-name/TestMembersAndLocalsWithSameName.py index a0dcbf0..63d19ea 100644 --- a/lldb/test/API/lang/cpp/member-and-local-vars-with-same-name/TestMembersAndLocalsWithSameName.py +++ b/lldb/test/API/lang/cpp/member-and-local-vars-with-same-name/TestMembersAndLocalsWithSameName.py @@ -265,11 +265,15 @@ class TestMembersAndLocalsWithSameName(TestBase): self.assertEqual(val.GetValueAsUnsigned(), 778899) def enable_expression_log(self): - log_file = os.path.join(self.getBuildDir(), "expr.log") + log_file = self.getBuildArtifact("expr.log") + if configuration.is_reproducer_replay(): + log_file = self.getReproducerRemappedPath(log_file) self.runCmd("log enable -f '%s' lldb expr" % (log_file)) def disable_expression_log_and_check_for_locals(self, variables): - log_file = os.path.join(self.getBuildDir(), "expr.log") + log_file = self.getBuildArtifact("expr.log") + if configuration.is_reproducer_replay(): + log_file = self.getReproducerRemappedPath(log_file) self.runCmd("log disable lldb expr") local_var_regex = re.compile(r".*__lldb_local_vars::(.*);") matched = [] diff --git a/lldb/test/API/lang/objc/modules-hash-mismatch/TestClangModulesHashMismatch.py b/lldb/test/API/lang/objc/modules-hash-mismatch/TestClangModulesHashMismatch.py index 606bd30..d7cb915 100644 --- a/lldb/test/API/lang/objc/modules-hash-mismatch/TestClangModulesHashMismatch.py +++ b/lldb/test/API/lang/objc/modules-hash-mismatch/TestClangModulesHashMismatch.py @@ -32,10 +32,12 @@ class TestClangModuleHashMismatch(TestBase): self.assertTrue(os.path.isdir(mod_cache), "module cache exists") logfile = self.getBuildArtifact("host.log") + if configuration.is_reproducer_replay(): + logfile = self.getReproducerRemappedPath(logfile) self.runCmd("log enable -v -f %s lldb host" % logfile) target, _, _, _ = lldbutil.run_to_source_breakpoint( self, "break here", lldb.SBFileSpec("main.m")) - target.GetModuleAtIndex(0).FindTypes('my_int') + target.GetModuleAtIndex(0).FindTypes('my_int') found = False with open(logfile, 'r') as f: -- 2.7.4