[test-suite] r262307 - lit: Option to skip test if hash did not change.

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 29 22:05:29 PST 2016


Author: matze
Date: Tue Mar  1 00:05:29 2016
New Revision: 262307

URL: http://llvm.org/viewvc/llvm-project?rev=262307&view=rev
Log:
lit: Option to skip test if hash did not change.

You can now use "llvm-lit -Dprevious=xxx.json" to make lit load the
results of a previous run and skip any tests whose executable hash is
the same as in the previous run.

Modified:
    test-suite/trunk/lit.cfg
    test-suite/trunk/litsupport/hash.py
    test-suite/trunk/litsupport/test.py

Modified: test-suite/trunk/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/lit.cfg?rev=262307&r1=262306&r2=262307&view=diff
==============================================================================
--- test-suite/trunk/lit.cfg (original)
+++ test-suite/trunk/lit.cfg Tue Mar  1 00:05:29 2016
@@ -1,5 +1,6 @@
 import site
 import os
+import json
 site.addsitedir(os.path.dirname(__file__))
 from litsupport import test
 
@@ -10,3 +11,9 @@ config.excludes = ['ABI-Testsuite']
 config.traditional_output = True
 if 'SSH_AUTH_SOCK' in os.environ:
     config.environment['SSH_AUTH_SOCK'] = os.environ['SSH_AUTH_SOCK']
+
+previous_results_file = lit_config.params.get('previous', None)
+if previous_results_file:
+    config.previous_results = json.load(open(previous_results_file))
+else:
+    config.previous_results = None

Modified: test-suite/trunk/litsupport/hash.py
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/litsupport/hash.py?rev=262307&r1=262306&r2=262307&view=diff
==============================================================================
--- test-suite/trunk/litsupport/hash.py (original)
+++ test-suite/trunk/litsupport/hash.py Tue Mar  1 00:05:29 2016
@@ -1,4 +1,4 @@
-import lit.Test
+from lit.Test import toMetricValue
 import hashlib
 import logging
 import subprocess
@@ -7,7 +7,7 @@ import platform
 import shellcommand
 
 
-def collect(context, result):
+def compute(context):
     executable = context.executable
     try:
         # Darwin's "strip" doesn't support these arguments.
@@ -22,9 +22,29 @@ def collect(context, result):
 
         h = hashlib.md5()
         h.update(open(executable, 'rb').read())
-        digest = h.hexdigest()
-
-        result.addMetric('hash', lit.Test.toMetricValue(digest))
-
+        context.executable_hash = h.hexdigest()
     except:
         logging.info('Could not calculate hash for %s' % executable)
+        context.executable_hash = None
+
+
+def same_as_previous(context):
+    """Check whether hash has changed compared to the results in
+    config.previous_results."""
+    previous_results = context.config.previous_results
+    testname = context.test.getFullName()
+    executable_hash = context.executable_hash
+    if previous_results and "tests" in previous_results:
+        for test in previous_results["tests"]:
+            if "name" not in test or test["name"] != testname:
+                continue
+            if "metrics" not in test:
+                continue
+            metrics = test["metrics"]
+            return "hash" in metrics and metrics["hash"] == executable_hash
+    return False
+
+
+def collect(context, result):
+    if context.executable_hash is not None:
+        result.addMetric('hash', toMetricValue(context.executable_hash))

Modified: test-suite/trunk/litsupport/test.py
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/litsupport/test.py?rev=262307&r1=262306&r2=262307&view=diff
==============================================================================
--- test-suite/trunk/litsupport/test.py (original)
+++ test-suite/trunk/litsupport/test.py Tue Mar  1 00:05:29 2016
@@ -19,6 +19,9 @@ import testscript
 import timeit
 
 
+SKIPPED = lit.Test.ResultCode('SKIPPED', False)
+
+
 class TestContext:
     """This class is used to hold data used while constructing a testrun.
     For example this can be used by modules modifying the commandline with
@@ -76,6 +79,10 @@ class TestSuiteTest(FileBasedTest):
         if context.executable is None:
             return lit.Test.Result(Test.UNSUPPORTED,
                                    'Could not determine executable name')
+        hash.compute(context)
+        if hash.same_as_previous(context):
+            return lit.Test.Result(SKIPPED,
+                                   'Executable identical to previous run')
 
         runscript = runsafely.wrapScript(context, runscript, suffix=".out")
 




More information about the llvm-commits mailing list