[Lldb-commits] [lldb] r370259 - [dotest] Centralize and simplify session dir logic (NFC)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 28 13:54:17 PDT 2019


Author: jdevlieghere
Date: Wed Aug 28 13:54:17 2019
New Revision: 370259

URL: http://llvm.org/viewvc/llvm-project?rev=370259&view=rev
Log:
[dotest] Centralize and simplify session dir logic (NFC)

I was looking at the session directory logic for unrelated reasons and
noticed that the logic spread out across dotest. This simplifies things
a bit by moving the logic together.

Modified:
    lldb/trunk/packages/Python/lldbsuite/test/dotest.py

Modified: lldb/trunk/packages/Python/lldbsuite/test/dotest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/dotest.py?rev=370259&r1=370258&r2=370259&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/dotest.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/dotest.py Wed Aug 28 13:54:17 2019
@@ -23,9 +23,10 @@ from __future__ import print_function
 
 # System modules
 import atexit
-import os
+import datetime
 import errno
 import logging
+import os
 import platform
 import re
 import signal
@@ -387,9 +388,11 @@ def parseOptionsAndInitTestdirs():
         configuration.regexp = args.p
 
     if args.s:
-        if args.s.startswith('-'):
-            usage(parser)
         configuration.sdir_name = args.s
+    else:
+        timestamp_started = datetime.datetime.now().strftime("%Y-%m-%d-%H_%M_%S")
+        configuration.sdir_name = os.path.join(os.getcwd(), timestamp_started)
+
     configuration.session_file_format = args.session_file_format
 
     if args.t:
@@ -1019,6 +1022,9 @@ def run_suite():
     # lldb.SBDebugger.Initialize()/Terminate() pair.
     import lldb
 
+    # Now we can also import lldbutil
+    from lldbsuite.test import lldbutil
+
     # Create a singleton SBDebugger in the lldb namespace.
     lldb.DBG = lldb.SBDebugger.Create()
 
@@ -1078,7 +1084,6 @@ def run_suite():
 
     # Set up the working directory.
     # Note that it's not dotest's job to clean this directory.
-    import lldbsuite.test.lldbutil as lldbutil
     build_dir = configuration.test_build_dir
     lldbutil.mkdir_p(build_dir)
 
@@ -1120,19 +1125,8 @@ def run_suite():
     # Install the control-c handler.
     unittest2.signals.installHandler()
 
-    # If sdir_name is not specified through the '-s sdir_name' option, get a
-    # timestamp string and export it as LLDB_SESSION_DIR environment var.  This will
-    # be used when/if we want to dump the session info of individual test cases
-    # later on.
-    #
-    # See also TestBase.dumpSessionInfo() in lldbtest.py.
-    import datetime
-    # The windows platforms don't like ':' in the pathname.
-    timestamp_started = datetime.datetime.now().strftime("%Y-%m-%d-%H_%M_%S")
-    if not configuration.sdir_name:
-        configuration.sdir_name = timestamp_started
-    os.environ["LLDB_SESSION_DIRNAME"] = os.path.join(
-        os.getcwd(), configuration.sdir_name)
+    lldbutil.mkdir_p(configuration.sdir_name)
+    os.environ["LLDB_SESSION_DIRNAME"] = configuration.sdir_name
 
     sys.stderr.write(
         "\nSession logs for test failures/errors/unexpected successes"
@@ -1140,13 +1134,6 @@ def run_suite():
         configuration.sdir_name)
     sys.stderr.write("Command invoked: %s\n" % getMyCommandLine())
 
-    if not os.path.isdir(configuration.sdir_name):
-        try:
-            os.mkdir(configuration.sdir_name)
-        except OSError as exception:
-            if exception.errno != errno.EEXIST:
-                raise
-
     #
     # Invoke the default TextTestRunner to run the test suite
     #




More information about the lldb-commits mailing list