Author: Jonas Devlieghere
Date: 2020-06-17T10:09:06-07:00
New Revision: 64c87a94caadc4a6351ab138dd2ca99975441b60

URL: 
https://github.com/llvm/llvm-project/commit/64c87a94caadc4a6351ab138dd2ca99975441b60
DIFF: 
https://github.com/llvm/llvm-project/commit/64c87a94caadc4a6351ab138dd2ca99975441b60.diff

LOG: [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.

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py 
b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index c5373479e48f..481c23671228 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -699,6 +699,12 @@ def getReproducerArtifact(self, name):
         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 c0ffa2c6f509..72df276b06c3 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 @@ def cleanup():
         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 16321dca86fd..4ba67f8794b6 100644
--- a/lldb/test/API/commands/log/basic/TestLogging.py
+++ b/lldb/test/API/commands/log/basic/TestLogging.py
@@ -20,6 +20,9 @@ def setUp(self):
         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 @@ def test_file_writing(self):
 
         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 @@ def test_log_append(self):
         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 948e8bed7862..7dd073e600f7 100644
--- a/lldb/test/API/lang/c/modules/TestCModules.py
+++ b/lldb/test/API/lang/c/modules/TestCModules.py
@@ -44,7 +44,9 @@ def test_expr(self):
                     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 3705e95c6003..54c5cccb9738 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 a0dcbf002664..63d19ea3eb28 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 @@ def _test_globals(self):
         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 606bd300c244..d7cb91530c07 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 @@ def test_expr(self):
         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:


        
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to