Skip to content

Commit

Permalink
DAOS-15747 test: Quote filenames when creating stack traces (#14246)
Browse files Browse the repository at this point in the history
Support filenames with spaces when generating stack traces from core
files detected after running tests.

Signed-off-by: Phil Henderson <[email protected]>
  • Loading branch information
phender authored Apr 25, 2024
1 parent 9149d77 commit d8e09d2
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions src/tests/ftest/process_core_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ def process_core_files(self, directory, delete, test=None):
continue
if os.path.splitext(core_name)[-1] == ".bz2":
# Decompress the file
command = ["lbzip2", "-d", "-v", os.path.join(core_dir, core_name)]
run_local(self.log, " ".join(command))
command = f"lbzip2 -d -v '{os.path.join(core_dir, core_name)}'"
run_local(self.log, command)
core_name = os.path.splitext(core_name)[0]
exe_name = self._get_exe_name(os.path.join(core_dir, core_name))
self._create_stacktrace(core_dir, core_name, exe_name)
Expand Down Expand Up @@ -184,26 +184,16 @@ def _create_stacktrace(self, core_dir, core_name, exe_name):
"""
host = os.path.split(core_dir)[-1].split(".")[-1]
core_full = os.path.join(core_dir, core_name)
stack_trace_file = os.path.join(core_dir, f"{core_name}.stacktrace")
stack_trace_file = os.path.join(core_dir, f"'{core_name}.stacktrace'")

self.log.debug("Generating a stacktrace from the %s core file from %s", core_full, host)
run_local(self.log, " ".join(['ls', '-l', core_full]))
run_local(self.log, f"ls -l '{core_full}'")

command = (
f"gdb -cd='{core_dir}' -ex 'set pagination off' -ex 'thread apply all bt full' -ex "
f"detach -ex quit '{exe_name}' '{core_name}'")
try:
command = [
"gdb", f"-cd={core_dir}",
"-ex", "'set pagination off'",
"-ex", "'thread apply all bt full'",
"-ex", "detach",
"-ex", "quit",
exe_name, core_name
]

except RunException as error:
raise RunException(f"Error obtaining the exe name from {core_name}") from error

try:
output = run_local(self.log, " ".join(command), check=False, verbose=False)
output = run_local(self.log, command, check=False, verbose=False)
with open(stack_trace_file, "w", encoding="utf-8") as stack_trace:
stack_trace.writelines(output.stdout)

Expand All @@ -226,9 +216,9 @@ def _get_exe_name(self, core_file):
str: the executable name
"""
self.log.debug("Extracting the executable name from %s", core_file)
command = ["gdb", "-c", core_file, "-ex", "'info proc exe'", "-ex", "quit"]
result = run_local(self.log, " ".join(command), verbose=False)
self.log.debug("Extracting the executable name from '%s'", core_file)
command = f"gdb -c '{core_file}' -ex 'info proc exe' -ex quit"
result = run_local(self.log, command, verbose=False)
last_line = result.stdout.splitlines()[-1]
self.log.debug(" last line: %s", last_line)
cmd = last_line[7:]
Expand Down

0 comments on commit d8e09d2

Please sign in to comment.