[llvm] r271610 - [lit] Improve readability of failing scripts.

Daniel Dunbar via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 2 16:49:45 PDT 2016


Author: ddunbar
Date: Thu Jun  2 18:49:42 2016
New Revision: 271610

URL: http://llvm.org/viewvc/llvm-project?rev=271610&view=rev
Log:
[lit] Improve readability of failing scripts.

 - This only applies to scripts executed by the _internal_ shell script
   interpreter.

 - This patch reworks the log to look more like a shell transcript, and be less
   verbose (but in the interest of calling attention to the important parts).

Here is an example of the new format, for commands with/without failures and
with/without output:
```
$ true
$ echo hi
hi

$ false
note: command had no output on stdout or stderr
error: command failed with exit status 1

```

Added:
    llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/
    llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/basic.txt
    llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/lit.cfg
    llvm/trunk/utils/lit/tests/shtest-output-printing.py
Modified:
    llvm/trunk/utils/lit/lit/TestRunner.py
    llvm/trunk/utils/lit/tests/shtest-format.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=271610&r1=271609&r2=271610&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/TestRunner.py (original)
+++ llvm/trunk/utils/lit/lit/TestRunner.py Thu Jun  2 18:49:42 2016
@@ -379,11 +379,17 @@ def _executeShCmd(cmd, shenv, results, t
 
         # Ensure the resulting output is always of string type.
         try:
-            out = to_string(out.decode('utf-8'))
+            if out is None:
+                out = ''
+            else:
+                out = to_string(out.decode('utf-8', errors='replace'))
         except:
             out = str(out)
         try:
-            err = to_string(err.decode('utf-8'))
+            if err is None:
+                err = ''
+            else:
+                err = to_string(err.decode('utf-8', errors='replace'))
         except:
             err = str(err)
 
@@ -438,14 +444,31 @@ def executeScriptInternal(test, litConfi
 
     out = err = ''
     for i,result in enumerate(results):
-        out += 'Command %d: %s\n' % (i, ' '.join('"%s"' % s
-                                                 for s in result.command.args))
-        out += 'Command %d Result: %r\n' % (i, result.exitCode)
+        # Write the command line run.
+        out += '$ %s\n' % (' '.join('"%s"' % s
+                                    for s in result.command.args),)
+
+        # If nothing interesting happened, move on.
+        if litConfig.maxIndividualTestTime == 0 and \
+               result.exitCode == 0 and \
+               not result.stdout.strip() and not result.stderr.strip():
+            continue
+
+        # Otherwise, something failed or was printed, show it.
+        if result.stdout.strip():
+            out += '# command output:\n%s\n' % (result.stdout,)
+        if result.stderr.strip():
+            out += '# command stderr:\n%s\n' % (result.stderr,)
+        if not result.stdout.strip() and not result.stderr.strip():
+            out += "note: command had no output on stdout or stderr\n"
+
+        # Show the error conditions:
+        if result.exitCode != 0:
+            out += "error: command failed with exit status: %d\n" % (
+                result.exitCode,)
         if litConfig.maxIndividualTestTime > 0:
-            out += 'Command %d Reached Timeout: %s\n\n' % (
+            out += 'error: command reached timeout: %s\n' % (
                 i, str(result.timeoutReached))
-        out += 'Command %d Output:\n%s\n\n' % (i, result.stdout)
-        out += 'Command %d Stderr:\n%s\n\n' % (i, result.stderr)
 
     return out, err, exitCode, timeoutInfo
 

Added: 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=271610&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/basic.txt (added)
+++ llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/basic.txt Thu Jun  2 18:49:42 2016
@@ -0,0 +1,3 @@
+# RUN: true
+# RUN: echo hi
+# RUN: false

Added: llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/lit.cfg?rev=271610&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/lit.cfg (added)
+++ llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/lit.cfg Thu Jun  2 18:49:42 2016
@@ -0,0 +1,4 @@
+import lit.formats
+config.name = 'shtest-output-printing'
+config.suffixes = ['.txt']
+config.test_format = lit.formats.ShTest(execute_external=False)

Modified: llvm/trunk/utils/lit/tests/shtest-format.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/shtest-format.py?rev=271610&r1=271609&r2=271610&view=diff
==============================================================================
--- llvm/trunk/utils/lit/tests/shtest-format.py (original)
+++ llvm/trunk/utils/lit/tests/shtest-format.py Thu Jun  2 18:49:42 2016
@@ -39,9 +39,8 @@
 #
 # CHECK: Command Output (stdout):
 # CHECK-NEXT: --
-# CHECK-NEXT: Command 0: "printf"
-# CHECK-NEXT: Command 0 Result: 0
-# CHECK-NEXT: Command 0 Output:
+# CHECK-NEXT: $ "printf"
+# CHECK-NEXT: # command output:
 # CHECK-NEXT: line 1: failed test output on stdout
 # CHECK-NEXT: line 2: failed test output on stdout
 

Added: 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=271610&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/shtest-output-printing.py (added)
+++ llvm/trunk/utils/lit/tests/shtest-output-printing.py Thu Jun  2 18:49:42 2016
@@ -0,0 +1,26 @@
+# 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
+#
+# END.
+
+# CHECK: -- Testing:
+
+# CHECK: FAIL: shtest-output-printing :: basic.txt
+# CHECK-NEXT: *** TEST 'shtest-output-printing :: basic.txt' FAILED ***
+# CHECK-NEXT: Script:
+# CHECK-NEXT: --
+# CHECK:      --
+# CHECK-NEXT: Exit Code: 1
+#
+# CHECK:      Command Output
+# CHECK-NEXT: --
+# CHECK-NEXT: $ "true"
+# CHECK-NEXT: $ "echo" "hi"
+# CHECK-NEXT: # command output:
+# CHECK-NEXT: hi
+#
+# CHECK:      $ "false"
+# CHECK-NEXT: 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=271610&r1=271609&r2=271610&view=diff
==============================================================================
--- llvm/trunk/utils/lit/tests/shtest-shell.py (original)
+++ llvm/trunk/utils/lit/tests/shtest-shell.py Thu Jun  2 18:49:42 2016
@@ -9,10 +9,10 @@
 
 # CHECK: FAIL: shtest-shell :: error-0.txt
 # CHECK: *** TEST 'shtest-shell :: error-0.txt' FAILED ***
-# CHECK: Command 0: "not-a-real-command"
-# CHECK: Command 0 Result: 127
-# CHECK: Command 0 Stderr:
+# CHECK: $ "not-a-real-command"
+# CHECK: # command stderr:
 # CHECK: 'not-a-real-command': command not found
+# CHECK: error: command failed with exit status: 127
 # CHECK: ***
 
 # FIXME: The output here sucks.




More information about the llvm-commits mailing list