[llvm] r187261 - Use pipefail when available.

Rafael Espindola rafael.espindola at gmail.com
Fri Jul 26 15:32:59 PDT 2013


Author: rafael
Date: Fri Jul 26 17:32:58 2013
New Revision: 187261

URL: http://llvm.org/viewvc/llvm-project?rev=187261&view=rev
Log:
Use pipefail when available.

This change makes test with RUN lines like
RUN: opt ... | FileCheck

fail if opt fails, even if it prints what FileCheck wants. Enabling this
found some interesting cases of broken tests that were not being noticed
because opt (or some other tool) was crashing late.

Pipefail is used when the shell supports it or when using the internal
python based tester.

Added:
    llvm/trunk/test/Other/pipefail.txt
Modified:
    llvm/trunk/docs/CommandGuide/lit.rst
    llvm/trunk/docs/ReleaseNotes.rst
    llvm/trunk/utils/lit/lit/ShUtil.py
    llvm/trunk/utils/lit/lit/TestRunner.py
    llvm/trunk/utils/lit/lit/TestingConfig.py

Modified: llvm/trunk/docs/CommandGuide/lit.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/lit.rst?rev=187261&r1=187260&r2=187261&view=diff
==============================================================================
--- llvm/trunk/docs/CommandGuide/lit.rst (original)
+++ llvm/trunk/docs/CommandGuide/lit.rst Fri Jul 26 17:32:58 2013
@@ -316,6 +316,10 @@ executed, two important global variables
  *on_clone* function will generally modify), and (3) the test path to the new
  directory being scanned.
 
+ **pipefail** Normally a test using a shell pipe fails if any of the commands
+ on the pipe fail. If this is not desired, setting this variable to false
+ makes the test fail only if the last command in the pipe fails.
+
 TEST DISCOVERY
 ~~~~~~~~~~~~~~
 

Modified: llvm/trunk/docs/ReleaseNotes.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/ReleaseNotes.rst?rev=187261&r1=187260&r2=187261&view=diff
==============================================================================
--- llvm/trunk/docs/ReleaseNotes.rst (original)
+++ llvm/trunk/docs/ReleaseNotes.rst Fri Jul 26 17:32:58 2013
@@ -41,6 +41,10 @@ Non-comprehensive list of changes in thi
    functionality, or simply have a lot to talk about), see the `NOTE` below
    for adding a new subsection.
 
+* The regression tests now fail if any command in a pipe fails. To disable it in
+  a directory, just add ``config.pipefail = False`` to its ``lit.local.cfg``.
+  See :doc:`Lit <CommandGuide/lit>` for the details.
+
 * Support for exception handling has been removed from the old JIT. Use MCJIT
   if you need EH support.
 

Added: llvm/trunk/test/Other/pipefail.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/pipefail.txt?rev=187261&view=auto
==============================================================================
--- llvm/trunk/test/Other/pipefail.txt (added)
+++ llvm/trunk/test/Other/pipefail.txt Fri Jul 26 17:32:58 2013
@@ -0,0 +1,2 @@
+REQUIRES: shell
+RUN: ((false | true) && echo true || echo false) | grep false

Modified: llvm/trunk/utils/lit/lit/ShUtil.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/ShUtil.py?rev=187261&r1=187260&r2=187261&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/ShUtil.py (original)
+++ llvm/trunk/utils/lit/lit/ShUtil.py Fri Jul 26 17:32:58 2013
@@ -166,8 +166,9 @@ class ShLexer:
 ###
  
 class ShParser:
-    def __init__(self, data, win32Escapes = False):
+    def __init__(self, data, win32Escapes = False, pipefail = False):
         self.data = data
+        self.pipefail = pipefail
         self.tokens = ShLexer(data, win32Escapes = win32Escapes).lex()
     
     def lex(self):
@@ -224,7 +225,7 @@ class ShParser:
         while self.look() == ('|',):
             self.lex()
             commands.append(self.parse_command())
-        return Pipeline(commands, negate)
+        return Pipeline(commands, negate, self.pipefail)
             
     def parse(self):
         lhs = self.parse_pipeline()

Modified: llvm/trunk/utils/lit/lit/TestRunner.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/TestRunner.py?rev=187261&r1=187260&r2=187261&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/TestRunner.py (original)
+++ llvm/trunk/utils/lit/lit/TestRunner.py Fri Jul 26 17:32:58 2013
@@ -245,7 +245,8 @@ def executeScriptInternal(test, litConfi
     cmds = []
     for ln in commands:
         try:
-            cmds.append(ShUtil.ShParser(ln, litConfig.isWindows).parse())
+            cmds.append(ShUtil.ShParser(ln, litConfig.isWindows,
+                                        test.config.pipefail).parse())
         except:
             return (Test.FAIL, "shell parser error on: %r" % ln)
 
@@ -284,6 +285,8 @@ def executeScript(test, litConfig, tmpBa
     if isWin32CMDEXE:
         f.write('\nif %ERRORLEVEL% NEQ 0 EXIT\n'.join(commands))
     else:
+        if test.config.pipefail:
+            f.write('set -o pipefail;')
         f.write('{ ' + '; } &&\n{ '.join(commands) + '; }')
     f.write('\n')
     f.close()

Modified: llvm/trunk/utils/lit/lit/TestingConfig.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/TestingConfig.py?rev=187261&r1=187260&r2=187261&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/TestingConfig.py (original)
+++ llvm/trunk/utils/lit/lit/TestingConfig.py Fri Jul 26 17:32:58 2013
@@ -92,6 +92,7 @@ class TestingConfig:
         self.test_source_root = test_source_root
         self.excludes = set(excludes)
         self.available_features = set(available_features)
+        self.pipefail = True
 
     def clone(self, path):
         # FIXME: Chain implementations?





More information about the llvm-commits mailing list