mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
[lit] Improve logging with file redirection.
- This will cause lit to automatically include the first 1K of data in redirected output files when a command fails (previously if the command failed, but the main point of the test was, say, a `FileCheck` later on, then the log wasn't helpful in showing why the command failed). llvm-svn: 272021
This commit is contained in:
parent
09c70527ce
commit
45d8260ac8
@ -113,12 +113,14 @@ class TimeoutHelper(object):
|
||||
class ShellCommandResult(object):
|
||||
"""Captures the result of an individual command."""
|
||||
|
||||
def __init__(self, command, stdout, stderr, exitCode, timeoutReached):
|
||||
def __init__(self, command, stdout, stderr, exitCode, timeoutReached,
|
||||
outputFiles = []):
|
||||
self.command = command
|
||||
self.stdout = stdout
|
||||
self.stderr = stderr
|
||||
self.exitCode = exitCode
|
||||
self.timeoutReached = timeoutReached
|
||||
self.outputFiles = list(outputFiles)
|
||||
|
||||
def executeShCmd(cmd, shenv, results, timeout=0):
|
||||
"""
|
||||
@ -268,7 +270,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
|
||||
# FIXME: Actually, this is probably an instance of PR6753.
|
||||
if r[1] == 'a':
|
||||
r[2].seek(0, 2)
|
||||
opened_files.append(r[2])
|
||||
opened_files.append(tuple(r) + (redir_filename,))
|
||||
result = r[2]
|
||||
final_redirects.append(result)
|
||||
|
||||
@ -342,7 +344,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
|
||||
# need to release any handles we may have on the temporary files (important
|
||||
# on Win32, for example). Since we have already spawned the subprocess, our
|
||||
# handles have already been transferred so we do not need them anymore.
|
||||
for f in opened_files:
|
||||
for (name, mode, f, path) in opened_files:
|
||||
f.close()
|
||||
|
||||
# FIXME: There is probably still deadlock potential here. Yawn.
|
||||
@ -393,8 +395,21 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
|
||||
except:
|
||||
err = str(err)
|
||||
|
||||
# Gather the redirected output files.
|
||||
output_files = []
|
||||
for (name, mode, f, path) in sorted(opened_files):
|
||||
if mode in ('w', 'a'):
|
||||
try:
|
||||
with open(path) as f:
|
||||
data = f.read()
|
||||
except:
|
||||
data = None
|
||||
if data != None:
|
||||
output_files.append((name, path, data))
|
||||
|
||||
results.append(ShellCommandResult(
|
||||
cmd.commands[i], out, err, res, timeoutHelper.timeoutReached()))
|
||||
cmd.commands[i], out, err, res, timeoutHelper.timeoutReached(),
|
||||
output_files))
|
||||
if cmd.pipe_err:
|
||||
# Python treats the exit code as a signed char.
|
||||
if exitCode is None:
|
||||
@ -455,6 +470,19 @@ def executeScriptInternal(test, litConfig, tmpBase, commands, cwd):
|
||||
continue
|
||||
|
||||
# Otherwise, something failed or was printed, show it.
|
||||
|
||||
# Add the command output, if redirected.
|
||||
for (name, path, data) in result.outputFiles:
|
||||
if data.strip():
|
||||
out += "# redirected output from %r:\n" % (name,)
|
||||
data = to_string(data.decode('utf-8'))
|
||||
if len(data) > 1024:
|
||||
out += data[:1024] + "\n...\n"
|
||||
out += "note: data was truncated\n"
|
||||
else:
|
||||
out += data
|
||||
out += "\n"
|
||||
|
||||
if result.stdout.strip():
|
||||
out += '# command output:\n%s\n' % (result.stdout,)
|
||||
if result.stderr.strip():
|
||||
|
@ -1,3 +1,3 @@
|
||||
# RUN: true
|
||||
# RUN: echo hi
|
||||
# RUN: false
|
||||
# RUN: wc missing-file &> %t.out
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Check the various features of the ShTest format.
|
||||
#
|
||||
# RUN: not %{lit} -j 1 -v %{inputs}/shtest-output-printing > %t.out
|
||||
# RUN: FileCheck < %t.out %s
|
||||
# RUN: FileCheck --input-file %t.out %s
|
||||
#
|
||||
# END.
|
||||
|
||||
@ -21,6 +21,8 @@
|
||||
# CHECK-NEXT: # command output:
|
||||
# CHECK-NEXT: hi
|
||||
#
|
||||
# CHECK: $ "false"
|
||||
# CHECK-NEXT: note: command had no output on stdout or stderr
|
||||
# CHECK: $ "wc" "missing-file"
|
||||
# CHECK-NEXT: # redirected output from '{{.*}}/basic.txt.tmp.out':
|
||||
# CHECK-NEXT: missing-file{{.*}} No such file or directory
|
||||
# CHECK: note: command had no output on stdout or stderr
|
||||
# CHECK-NEXT: error: command failed with exit status: 1
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Check the internal shell handling component of the ShTest format.
|
||||
#
|
||||
# RUN: not %{lit} -j 1 -v %{inputs}/shtest-shell > %t.out
|
||||
# RUN: FileCheck < %t.out %s
|
||||
# RUN: FileCheck --input-file %t.out %s
|
||||
#
|
||||
# END.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user