[llvm] 08d5426 - [lit] NFC: Move the flaky test logic to _runShTest

Louis Dionne via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 27 06:33:23 PDT 2020


Author: Louis Dionne
Date: 2020-03-27T09:32:58-04:00
New Revision: 08d5426981595485c47682ecc57091541e41c674

URL: https://github.com/llvm/llvm-project/commit/08d5426981595485c47682ecc57091541e41c674
DIFF: https://github.com/llvm/llvm-project/commit/08d5426981595485c47682ecc57091541e41c674.diff

LOG: [lit] NFC: Move the flaky test logic to _runShTest

This minor refactoring allows reducing the amount of processing that
is duplicated when we re-run a flaky test. It also has the nice
side effect that libc++'s current test format supports flaky .sh.cpp
tests, because those are built on top of _runShTest, not executeShTest.

Added: 
    

Modified: 
    llvm/utils/lit/lit/TestRunner.py

Removed: 
    


################################################################################
diff  --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 1632827a300d..e227dc8fd4de 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -1477,25 +1477,43 @@ def parseIntegratedTestScript(test, additional_parsers=[],
 
 
 def _runShTest(test, litConfig, useExternalSh, script, tmpBase):
+    def runOnce(execdir):
+        if useExternalSh:
+            res = executeScript(test, litConfig, tmpBase, script, execdir)
+        else:
+            res = executeScriptInternal(test, litConfig, tmpBase, script, execdir)
+        if isinstance(res, lit.Test.Result):
+            return res
+
+        out,err,exitCode,timeoutInfo = res
+        if exitCode == 0:
+            status = Test.PASS
+        else:
+            if timeoutInfo is None:
+                status = Test.FAIL
+            else:
+                status = Test.TIMEOUT
+        return out,err,exitCode,timeoutInfo,status
+
     # Create the output directory if it does not already exist.
     lit.util.mkdir_p(os.path.dirname(tmpBase))
 
+    # Re-run failed tests up to test.allowed_retries times.
     execdir = os.path.dirname(test.getExecPath())
-    if useExternalSh:
-        res = executeScript(test, litConfig, tmpBase, script, execdir)
-    else:
-        res = executeScriptInternal(test, litConfig, tmpBase, script, execdir)
-    if isinstance(res, lit.Test.Result):
-        return res
+    attempts = test.allowed_retries + 1
+    for i in range(attempts):
+        res = runOnce(execdir)
+        if isinstance(res, lit.Test.Result):
+            return res
 
-    out,err,exitCode,timeoutInfo = res
-    if exitCode == 0:
-        status = Test.PASS
-    else:
-        if timeoutInfo is None:
-            status = Test.FAIL
-        else:
-            status = Test.TIMEOUT
+        out,err,exitCode,timeoutInfo,status = res
+        if status != Test.FAIL:
+            break
+
+    # If we had to run the test more than once, count it as a flaky pass. These
+    # will be printed separately in the test summary.
+    if i > 0 and status == Test.PASS:
+        status = Test.FLAKYPASS
 
     # Form the output log.
     output = """Script:\n--\n%s\n--\nExit Code: %d\n""" % (
@@ -1536,14 +1554,4 @@ def executeShTest(test, litConfig, useExternalSh,
     script = applySubstitutions(script, substitutions,
                                 recursion_limit=litConfig.recursiveExpansionLimit)
 
-    # Re-run failed tests up to test.allowed_retries times.
-    attempts = test.allowed_retries + 1
-    for i in range(attempts):
-        res = _runShTest(test, litConfig, useExternalSh, script, tmpBase)
-        if res.code != Test.FAIL:
-            break
-    # If we had to run the test more than once, count it as a flaky pass. These
-    # will be printed separately in the test summary.
-    if i > 0 and res.code == Test.PASS:
-        res.code = Test.FLAKYPASS
-    return res
+    return _runShTest(test, litConfig, useExternalSh, script, tmpBase)


        


More information about the llvm-commits mailing list