Skip to content

Commit 3cdbacc

Browse files
committed
[lldb/test] Avoid globbing in log file handling code
The glob expression for a test called "test" could match a log file for a the test "test_foo". Instead of globbing, maintain an explicit list of log files relevant to the current test.
1 parent b539f01 commit 3cdbacc

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ def enableLogChannelsForCurrentTest(self):
576576
# confirm that the file is writeable
577577
host_log_path = "{}-host.log".format(log_basename)
578578
open(host_log_path, 'w').close()
579+
self.log_files.append(host_log_path)
579580

580581
log_enable = "log enable -Tpn -f {} ".format(host_log_path)
581582
for channel_with_categories in lldbtest_config.channels:
@@ -602,6 +603,7 @@ def enableLogChannelsForCurrentTest(self):
602603
if lldb.remote_platform is None:
603604
server_log_path = "{}-server.log".format(log_basename)
604605
open(server_log_path, 'w').close()
606+
self.log_files.append(server_log_path)
605607
os.environ["LLDB_DEBUGSERVER_LOG_FILE"] = server_log_path
606608

607609
# Communicate channels to lldb-server
@@ -623,12 +625,13 @@ def disableLogChannelsForCurrentTest(self):
623625
# Retrieve the server log (if any) from the remote system. It is assumed the server log
624626
# is writing to the "server.log" file in the current test directory. This can be
625627
# achieved by setting LLDB_DEBUGSERVER_LOG_FILE="server.log" when starting remote
626-
# platform. If the remote logging is not enabled, then just let the Get() command silently
627-
# fail.
628+
# platform.
628629
if lldb.remote_platform:
629-
lldb.remote_platform.Get(
630-
lldb.SBFileSpec("server.log"), lldb.SBFileSpec(
631-
self.getLogBasenameForCurrentTest() + "-server.log"))
630+
server_log_path = self.getLogBasenameForCurrentTest() + "-server.log"
631+
if lldb.remote_platform.Get(
632+
lldb.SBFileSpec("server.log"),
633+
lldb.SBFileSpec(server_log_path)).Success():
634+
self.log_files.append(server_log_path)
632635

633636
def setPlatformWorkingDir(self):
634637
if not lldb.remote_platform or not configuration.lldb_platform_working_dir:
@@ -800,11 +803,12 @@ def setUp(self):
800803
# List of forked process PIDs
801804
self.forkedProcessPids = []
802805

803-
# Create a string buffer to record the session info, to be dumped into a
804-
# test case specific file if test failure is encountered.
805-
self.log_basename = self.getLogBasenameForCurrentTest()
806+
# List of log files produced by the current test.
807+
self.log_files = []
808+
809+
session_file = self.getLogBasenameForCurrentTest()+".log"
810+
self.log_files.append(session_file)
806811

807-
session_file = "{}.log".format(self.log_basename)
808812
# Python 3 doesn't support unbuffered I/O in text mode. Open buffered.
809813
self.session = encoded_file.open(session_file, "utf-8", mode="w")
810814

@@ -1218,14 +1222,13 @@ def dumpSessionInfo(self):
12181222
del self.session
12191223

12201224
# process the log files
1221-
log_files_for_this_test = glob.glob(self.log_basename + "*")
1222-
12231225
if prefix != 'Success' or lldbtest_config.log_success:
12241226
# keep all log files, rename them to include prefix
1227+
src_log_basename = self.getLogBasenameForCurrentTest(None)
12251228
dst_log_basename = self.getLogBasenameForCurrentTest(prefix)
1226-
for src in log_files_for_this_test:
1229+
for src in self.log_files:
12271230
if os.path.isfile(src):
1228-
dst = src.replace(self.log_basename, dst_log_basename)
1231+
dst = src.replace(src_log_basename, dst_log_basename)
12291232
if os.name == "nt" and os.path.isfile(dst):
12301233
# On Windows, renaming a -> b will throw an exception if
12311234
# b exists. On non-Windows platforms it silently
@@ -1239,8 +1242,9 @@ def dumpSessionInfo(self):
12391242
os.rename(src, dst)
12401243
else:
12411244
# success! (and we don't want log files) delete log files
1242-
for log_file in log_files_for_this_test:
1243-
remove_file(log_file)
1245+
for log_file in self.log_files:
1246+
if os.path.isfile(log_file):
1247+
remove_file(log_file)
12441248

12451249
# ====================================================
12461250
# Config. methods supported through a plugin interface

0 commit comments

Comments
 (0)