[test-suite] r254128 - lit: Refactoring: Introduce toplevel prepareRunSafely function

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 25 19:35:26 PST 2015


Author: matze
Date: Wed Nov 25 21:35:26 2015
New Revision: 254128

URL: http://llvm.org/viewvc/llvm-project?rev=254128&view=rev
Log:
lit: Refactoring: Introduce toplevel prepareRunSafely function

Modified:
    test-suite/trunk/lit.cfg

Modified: test-suite/trunk/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/lit.cfg?rev=254128&r1=254127&r2=254128&view=diff
==============================================================================
--- test-suite/trunk/lit.cfg (original)
+++ test-suite/trunk/lit.cfg Wed Nov 25 21:35:26 2015
@@ -80,6 +80,24 @@ def runScript(test, litConfig, script, t
         res = executeScriptInternal(test, litConfig, tmpBase, script, execdir)
     return res
 
+def prepareRunSafely(config, commandline, outfile):
+    stdin = "/dev/null"
+    tokens = shlex.split(commandline)
+    for i in range(len(tokens)):
+        # Detect "< INPUTFILE" pattern
+        if tokens[i] == "<" and i+1 < len(tokens):
+            stdin = tokens[i+1]
+            del tokens[i+1]
+            del tokens[i]
+            break
+    timeit = "%s/tools/timeit" % config.test_source_root
+    runsafely = "%s/RunSafely.sh" % config.test_suite_root
+    timeout = "7200"
+    runsafely_prefix = [runsafely, "-t", timeit, timeout, stdin, outfile]
+
+    new_commandline = " ".join(map(quote, runsafely_prefix + tokens))
+    return new_commandline
+
 class TestSuiteTest(FileBasedTest):
     def __init__(self):
         super(TestSuiteTest, self).__init__()
@@ -104,26 +122,11 @@ class TestSuiteTest(FileBasedTest):
         runscript = applySubstitutions(runscript, substitutions)
         verifyscript = applySubstitutions(verifyscript, substitutions)
 
-        # Prepend runscript with RunSafely and timeit stuff
-        def prependRunSafely(line):
-            # Search for "< INPUTFILE" in the line and use that for stdin
-            stdin = "/dev/null"
-            commandline = shlex.split(line)
-            for i in range(len(commandline)):
-                if commandline[i] == "<" and i+1 < len(commandline):
-                    stdin = commandline[i+1]
-                    del commandline[i+1]
-                    del commandline[i]
-                    break
-            timeit = "%s/tools/timeit" % config.test_source_root
-            runsafely = "%s/RunSafely.sh" % config.test_suite_root
-            timeout = "7200"
-            runsafely_prefix = [runsafely, "-t", timeit, timeout, stdin,
-                                outfile]
-
-            line = " ".join(map(quote, runsafely_prefix + commandline))
-            return line
-        runscript = map(prependRunSafely, runscript)
+        adjusted_runscript = []
+        for line in runscript:
+            line = prepareRunSafely(config, line, outfile)
+            adjusted_runscript.append(line)
+        runscript = adjusted_runscript
 
         # Create the output directory if it does not already exist.
         lit.util.mkdir_p(os.path.dirname(tmpBase))




More information about the llvm-commits mailing list