Skip to content

Commit 3331fd8

Browse files
committed
[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. llvm-svn: 370259
1 parent 3ae9b9d commit 3331fd8

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

lldb/packages/Python/lldbsuite/test/dotest.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323

2424
# System modules
2525
import atexit
26-
import os
26+
import datetime
2727
import errno
2828
import logging
29+
import os
2930
import platform
3031
import re
3132
import signal
@@ -387,9 +388,11 @@ def parseOptionsAndInitTestdirs():
387388
configuration.regexp = args.p
388389

389390
if args.s:
390-
if args.s.startswith('-'):
391-
usage(parser)
392391
configuration.sdir_name = args.s
392+
else:
393+
timestamp_started = datetime.datetime.now().strftime("%Y-%m-%d-%H_%M_%S")
394+
configuration.sdir_name = os.path.join(os.getcwd(), timestamp_started)
395+
393396
configuration.session_file_format = args.session_file_format
394397

395398
if args.t:
@@ -1019,6 +1022,9 @@ def run_suite():
10191022
# lldb.SBDebugger.Initialize()/Terminate() pair.
10201023
import lldb
10211024

1025+
# Now we can also import lldbutil
1026+
from lldbsuite.test import lldbutil
1027+
10221028
# Create a singleton SBDebugger in the lldb namespace.
10231029
lldb.DBG = lldb.SBDebugger.Create()
10241030

@@ -1078,7 +1084,6 @@ def run_suite():
10781084

10791085
# Set up the working directory.
10801086
# Note that it's not dotest's job to clean this directory.
1081-
import lldbsuite.test.lldbutil as lldbutil
10821087
build_dir = configuration.test_build_dir
10831088
lldbutil.mkdir_p(build_dir)
10841089

@@ -1120,33 +1125,15 @@ def run_suite():
11201125
# Install the control-c handler.
11211126
unittest2.signals.installHandler()
11221127

1123-
# If sdir_name is not specified through the '-s sdir_name' option, get a
1124-
# timestamp string and export it as LLDB_SESSION_DIR environment var. This will
1125-
# be used when/if we want to dump the session info of individual test cases
1126-
# later on.
1127-
#
1128-
# See also TestBase.dumpSessionInfo() in lldbtest.py.
1129-
import datetime
1130-
# The windows platforms don't like ':' in the pathname.
1131-
timestamp_started = datetime.datetime.now().strftime("%Y-%m-%d-%H_%M_%S")
1132-
if not configuration.sdir_name:
1133-
configuration.sdir_name = timestamp_started
1134-
os.environ["LLDB_SESSION_DIRNAME"] = os.path.join(
1135-
os.getcwd(), configuration.sdir_name)
1128+
lldbutil.mkdir_p(configuration.sdir_name)
1129+
os.environ["LLDB_SESSION_DIRNAME"] = configuration.sdir_name
11361130

11371131
sys.stderr.write(
11381132
"\nSession logs for test failures/errors/unexpected successes"
11391133
" will go into directory '%s'\n" %
11401134
configuration.sdir_name)
11411135
sys.stderr.write("Command invoked: %s\n" % getMyCommandLine())
11421136

1143-
if not os.path.isdir(configuration.sdir_name):
1144-
try:
1145-
os.mkdir(configuration.sdir_name)
1146-
except OSError as exception:
1147-
if exception.errno != errno.EEXIST:
1148-
raise
1149-
11501137
#
11511138
# Invoke the default TextTestRunner to run the test suite
11521139
#

0 commit comments

Comments
 (0)