[lldb/Test] Fix tests that rely on logfiles with reproducers.
authorJonas Devlieghere <jonas@devlieghere.com>
Wed, 17 Jun 2020 16:32:17 +0000 (09:32 -0700)
committerJonas Devlieghere <jonas@devlieghere.com>
Wed, 17 Jun 2020 17:09:06 +0000 (10:09 -0700)
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
lldb/test/API/api/log/TestAPILog.py
lldb/test/API/commands/log/basic/TestLogging.py
lldb/test/API/lang/c/modules/TestCModules.py
lldb/test/API/lang/cpp/accelerator-table/TestCPPAccelerator.py
lldb/test/API/lang/cpp/member-and-local-vars-with-same-name/TestMembersAndLocalsWithSameName.py
lldb/test/API/lang/objc/modules-hash-mismatch/TestClangModulesHashMismatch.py

index c537347..481c236 100644 (file)
@@ -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 = [
index c0ffa2c..72df276 100644 (file)
@@ -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()
 
index 16321dc..4ba67f8 100644 (file)
@@ -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
index 948e8be..7dd073e 100644 (file)
@@ -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(
index 3705e95..54c5ccc 100644 (file)
@@ -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'))
index a0dcbf0..63d19ea 100644 (file)
@@ -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 = []
index 606bd30..d7cb915 100644 (file)
@@ -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: