[llvm] r272021 - [lit] Improve logging with file redirection.

Daniel Dunbar via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 7 09:13:40 PDT 2016


Author: ddunbar
Date: Tue Jun  7 11:13:40 2016
New Revision: 272021

URL: http://llvm.org/viewvc/llvm-project?rev=272021&view=rev
Log:
[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).

Modified:
    llvm/trunk/utils/lit/lit/TestRunner.py
    llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/basic.txt
    llvm/trunk/utils/lit/tests/shtest-output-printing.py
    llvm/trunk/utils/lit/tests/shtest-shell.py

Modified: llvm/trunk/utils/lit/lit/TestRunner.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/TestRunner.py?rev=272021&r1=272020&r2=272021&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/TestRunner.py (original)
+++ llvm/trunk/utils/lit/lit/TestRunner.py Tue Jun  7 11:13:40 2016
@@ -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, t
                     # 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, t
     # 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, t
         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, litConfi
             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():

Modified: llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/basic.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/basic.txt?rev=272021&r1=272020&r2=272021&view=diff
==============================================================================
--- llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/basic.txt (original)
+++ llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/basic.txt Tue Jun  7 11:13:40 2016
@@ -1,3 +1,3 @@
 # RUN: true
 # RUN: echo hi
-# RUN: false
+# RUN: wc missing-file &> %t.out

Modified: llvm/trunk/utils/lit/tests/shtest-output-printing.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/shtest-output-printing.py?rev=272021&r1=272020&r2=272021&view=diff
==============================================================================
--- llvm/trunk/utils/lit/tests/shtest-output-printing.py (original)
+++ llvm/trunk/utils/lit/tests/shtest-output-printing.py Tue Jun  7 11:13:40 2016
@@ -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

Modified: llvm/trunk/utils/lit/tests/shtest-shell.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/shtest-shell.py?rev=272021&r1=272020&r2=272021&view=diff
==============================================================================
--- llvm/trunk/utils/lit/tests/shtest-shell.py (original)
+++ llvm/trunk/utils/lit/tests/shtest-shell.py Tue Jun  7 11:13:40 2016
@@ -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.
 




More information about the llvm-commits mailing list