[Lldb-commits] [lldb] r274491 - Enable test log collection from remote debug servers (take 2)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon Jul 4 02:59:45 PDT 2016


Author: labath
Date: Mon Jul  4 04:59:45 2016
New Revision: 274491

URL: http://llvm.org/viewvc/llvm-project?rev=274491&view=rev
Log:
Enable test log collection from remote debug servers (take 2)

Summary:
This is a slightly reworked version of D16322, which I had reverted because it did not do what it
advertised. Differences from the previous version are:
- moved the code for cleaning up the remote working dir to a later point as it was removing the
  log file before we could get to it.
- specialised log downloading code for gdb-remote tests is not needed, as this will cover that
  use case as well.

Reviewers: tfiala

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D21898

Modified:
    lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py
    lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py

Modified: lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py?rev=274491&r1=274490&r2=274491&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py Mon Jul  4 04:59:45 2016
@@ -583,7 +583,7 @@ class Base(unittest2.TestCase):
             else:
                 categories = "default"
 
-            if channel == "gdb-remote":
+            if channel == "gdb-remote" and lldb.remote_platform is None:
                 # communicate gdb-remote categories to debugserver
                 os.environ["LLDB_DEBUGSERVER_LOG_FLAGS"] = categories
 
@@ -592,15 +592,17 @@ class Base(unittest2.TestCase):
                 raise Exception('log enable failed (check LLDB_LOG_OPTION env variable)')
 
         # Communicate log path name to debugserver & lldb-server
-        server_log_path = "{}-server.log".format(log_basename)
-        open(server_log_path, 'w').close()
-        os.environ["LLDB_DEBUGSERVER_LOG_FILE"] = server_log_path
+        # For remote debugging, these variables need to be set when starting the platform
+        # instance.
+        if lldb.remote_platform is None:
+            server_log_path = "{}-server.log".format(log_basename)
+            open(server_log_path, 'w').close()
+            os.environ["LLDB_DEBUGSERVER_LOG_FILE"] = server_log_path
 
-        # Communicate channels to lldb-server
-        os.environ["LLDB_SERVER_LOG_CHANNELS"] = ":".join(lldbtest_config.channels)
+            # Communicate channels to lldb-server
+            os.environ["LLDB_SERVER_LOG_CHANNELS"] = ":".join(lldbtest_config.channels)
 
-        if len(lldbtest_config.channels) == 0:
-            return
+        self.addTearDownHook(self.disableLogChannelsForCurrentTest)
 
     def disableLogChannelsForCurrentTest(self):
         # close all log files that we opened
@@ -611,6 +613,42 @@ class Base(unittest2.TestCase):
             if not self.res.Succeeded():
                 raise Exception('log disable failed (check LLDB_LOG_OPTION env variable)')
 
+        # Retrieve the server log (if any) from the remote system. It is assumed the server log
+        # is writing to the "server.log" file in the current test directory. This can be
+        # achieved by setting LLDB_DEBUGSERVER_LOG_FILE="server.log" when starting remote
+        # platform. If the remote logging is not enabled, then just let the Get() command silently
+        # fail.
+        if lldb.remote_platform:
+            lldb.remote_platform.Get(lldb.SBFileSpec("server.log"),
+                    lldb.SBFileSpec(self.getLogBasenameForCurrentTest()+"-server.log"))
+
+    def setPlatformWorkingDir(self):
+        if not lldb.remote_platform or not configuration.lldb_platform_working_dir:
+            return
+
+        remote_test_dir = lldbutil.join_remote_paths(
+                configuration.lldb_platform_working_dir,
+                self.getArchitecture(),
+                str(self.test_number),
+                self.mydir)
+        error = lldb.remote_platform.MakeDirectory(remote_test_dir, 448) # 448 = 0o700
+        if error.Success():
+            lldb.remote_platform.SetWorkingDirectory(remote_test_dir)
+
+            # This function removes all files from the current working directory while leaving
+            # the directories in place. The cleaup is required to reduce the disk space required
+            # by the test suit while leaving the directories untached is neccessary because
+            # sub-directories might belong to an other test
+            def clean_working_directory():
+                # TODO: Make it working on Windows when we need it for remote debugging support
+                # TODO: Replace the heuristic to remove the files with a logic what collects the
+                # list of files we have to remove during test runs.
+                shell_cmd = lldb.SBPlatformShellCommand("rm %s/*" % remote_test_dir)
+                lldb.remote_platform.Run(shell_cmd)
+            self.addTearDownHook(clean_working_directory)
+        else:
+            print("error: making remote directory '%s': %s" % (remote_test_dir, error))
+
     def setUp(self):
         """Fixture for unittest test case setup.
 
@@ -716,6 +754,7 @@ class Base(unittest2.TestCase):
         # And the result object.
         self.res = lldb.SBCommandReturnObject()
 
+        self.setPlatformWorkingDir()
         self.enableLogChannelsForCurrentTest()
 
         #Initialize debug_info
@@ -884,8 +923,6 @@ class Base(unittest2.TestCase):
                 for dict in reversed(self.dicts):
                     self.cleanup(dictionary=dict)
 
-        self.disableLogChannelsForCurrentTest()
-
     # =========================================================
     # Various callbacks to allow introspection of test progress
     # =========================================================
@@ -1614,30 +1651,6 @@ class TestBase(Base):
         # And the result object.
         self.res = lldb.SBCommandReturnObject()
 
-        if lldb.remote_platform and configuration.lldb_platform_working_dir:
-            remote_test_dir = lldbutil.join_remote_paths(
-                    configuration.lldb_platform_working_dir,
-                    self.getArchitecture(),
-                    str(self.test_number),
-                    self.mydir)
-            error = lldb.remote_platform.MakeDirectory(remote_test_dir, 448) # 448 = 0o700
-            if error.Success():
-                lldb.remote_platform.SetWorkingDirectory(remote_test_dir)
-
-                # This function removes all files from the current working directory while leaving
-                # the directories in place. The cleaup is required to reduce the disk space required
-                # by the test suit while leaving the directories untached is neccessary because
-                # sub-directories might belong to an other test
-                def clean_working_directory():
-                    # TODO: Make it working on Windows when we need it for remote debugging support
-                    # TODO: Replace the heuristic to remove the files with a logic what collects the
-                    # list of files we have to remove during test runs.
-                    shell_cmd = lldb.SBPlatformShellCommand("rm %s/*" % remote_test_dir)
-                    lldb.remote_platform.Run(shell_cmd)
-                self.addTearDownHook(clean_working_directory)
-            else:
-                print("error: making remote directory '%s': %s" % (remote_test_dir, error))
-    
     def registerSharedLibrariesWithTarget(self, target, shlibs):
         '''If we are remotely running the test suite, register the shared libraries with the target so they get uploaded, otherwise do nothing
         

Modified: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py?rev=274491&r1=274490&r2=274491&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py Mon Jul  4 04:59:45 2016
@@ -78,7 +78,6 @@ class GdbRemoteTestCaseBase(TestBase):
         TestBase.setUp(self)
 
         self.setUpBaseLogging()
-        self._remote_server_log_file = None
         self.debug_monitor_extra_args = []
         self._pump_queues = socket_packet_pump.PumpQueues()
 
@@ -114,12 +113,6 @@ class GdbRemoteTestCaseBase(TestBase):
     def tearDown(self):
         self._pump_queues.verify_queues_empty()
 
-        if self._remote_server_log_file is not None:
-            lldb.remote_platform.Get(lldb.SBFileSpec(self._remote_server_log_file),
-                    lldb.SBFileSpec(self.getLocalServerLogFile()))
-            lldb.remote_platform.Run(lldb.SBPlatformShellCommand("rm " + self._remote_server_log_file))
-            self._remote_server_log_file = None
-
         self.logger.removeHandler(self._verbose_log_handler)
         self._verbose_log_handler = None
         TestBase.tearDown(self)
@@ -133,7 +126,6 @@ class GdbRemoteTestCaseBase(TestBase):
 
         if lldb.remote_platform:
             log_file = lldbutil.join_remote_paths(lldb.remote_platform.GetWorkingDirectory(), "server.log")
-            self._remote_server_log_file = log_file
         else:
             log_file = self.getLocalServerLogFile()
 




More information about the lldb-commits mailing list