diff options
-rw-r--r-- | llvm/utils/lit/lit/TestRunner.py | 36 | ||||
-rw-r--r-- | llvm/utils/lit/tests/Inputs/shtest-output-printing/basic.txt | 2 | ||||
-rw-r--r-- | llvm/utils/lit/tests/shtest-output-printing.py | 8 | ||||
-rw-r--r-- | llvm/utils/lit/tests/shtest-shell.py | 2 |
4 files changed, 39 insertions, 9 deletions
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py index 5ef1b2b304b..f6dfd46604f 100644 --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -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(): diff --git a/llvm/utils/lit/tests/Inputs/shtest-output-printing/basic.txt b/llvm/utils/lit/tests/Inputs/shtest-output-printing/basic.txt index 1720c6097bd..4899c7e63db 100644 --- a/llvm/utils/lit/tests/Inputs/shtest-output-printing/basic.txt +++ b/llvm/utils/lit/tests/Inputs/shtest-output-printing/basic.txt @@ -1,3 +1,3 @@ # RUN: true # RUN: echo hi -# RUN: false +# RUN: wc missing-file &> %t.out diff --git a/llvm/utils/lit/tests/shtest-output-printing.py b/llvm/utils/lit/tests/shtest-output-printing.py index 1d5fc04ab81..24580b37f1f 100644 --- a/llvm/utils/lit/tests/shtest-output-printing.py +++ b/llvm/utils/lit/tests/shtest-output-printing.py @@ -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 diff --git a/llvm/utils/lit/tests/shtest-shell.py b/llvm/utils/lit/tests/shtest-shell.py index 379b040fc45..18b80cd7d08 100644 --- a/llvm/utils/lit/tests/shtest-shell.py +++ b/llvm/utils/lit/tests/shtest-shell.py @@ -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. |