[PATCH] D45332: [LIT] Add new LLDB test format

Jonas Devlieghere via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 5 13:38:24 PDT 2018


JDevlieghere created this revision.
JDevlieghere added reviewers: zturner, labath, davide, aprantl.
Herald added a subscriber: delcypher.
JDevlieghere added a comment.

As discussed in https://reviews.llvm.org/D45215


This adds a new test format to lit which will be used for LLDB.

(If it's possible to define a new format outside the LLVM repo, I'm more than happy to move it into the LLDB repo)


Repository:
  rL LLVM

https://reviews.llvm.org/D45332

Files:
  utils/lit/lit/formats/__init__.py
  utils/lit/lit/formats/lldbtest.py


Index: utils/lit/lit/formats/lldbtest.py
===================================================================
--- /dev/null
+++ utils/lit/lit/formats/lldbtest.py
@@ -0,0 +1,66 @@
+from __future__ import absolute_import
+import os
+
+import subprocess
+import sys
+
+import lit.Test
+import lit.TestRunner
+import lit.util
+from .base import TestFormat
+
+
+class LLDBTest(TestFormat):
+    def __init__(self, dotest_cmd):
+        self.dotest_cmd = dotest_cmd
+
+    def getTestsInDirectory(self, testSuite, path_in_suite, litConfig,
+                            localConfig):
+        source_path = testSuite.getSourcePath(path_in_suite)
+        for filename in os.listdir(source_path):
+            # Ignore dot files and excluded tests.
+            if (filename.startswith('.') or filename in localConfig.excludes):
+                continue
+
+            # Ignore files that don't start with 'Test'.
+            if not filename.startswith('Test'):
+                continue
+
+            filepath = os.path.join(source_path, filename)
+            if not os.path.isdir(filepath):
+                base, ext = os.path.splitext(filename)
+                if ext in localConfig.suffixes:
+                    yield lit.Test.Test(testSuite, path_in_suite +
+                                        (filename, ), localConfig)
+
+    def execute(self, test, litConfig):
+        if litConfig.noExecute:
+            return lit.Test.PASS, ''
+
+        if test.config.unsupported:
+            return (lit.Test.UNSUPPORTED, 'Test is unsupported')
+
+        testPath, testFile = os.path.split(test.getSourcePath())
+        testName, testExt = os.path.splitext(testFile)
+        cmd = self.dotest_cmd + [testPath, '-p', testName]
+        print ' '.join(cmd)
+
+        try:
+            out, err, exitCode = lit.util.executeCommand(
+                cmd,
+                env=test.config.environment,
+                timeout=litConfig.maxIndividualTestTime)
+        except lit.util.ExecuteCommandTimeoutException:
+            return (lit.Test.TIMEOUT, 'Reached timeout of {} seconds'.format(
+                litConfig.maxIndividualTestTime))
+
+        if exitCode:
+            return lit.Test.FAIL, out + err
+
+        passing_test_line = 'RESULT: PASSED'
+        if passing_test_line not in out:
+            msg = ('Unable to find %r in dotest output:\n\n%s%s' %
+                   (passing_test_line, out, err))
+            return lit.Test.UNRESOLVED, msg
+
+        return lit.Test.PASS, ''
Index: utils/lit/lit/formats/__init__.py
===================================================================
--- utils/lit/lit/formats/__init__.py
+++ utils/lit/lit/formats/__init__.py
@@ -5,4 +5,5 @@
 )
 
 from lit.formats.googletest import GoogleTest  # noqa: F401
+from lit.formats.lldbtest import LLDBTest  # noqa: F401
 from lit.formats.shtest import ShTest  # noqa: F401


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45332.141213.patch
Type: text/x-patch
Size: 2885 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180405/fc8a5bca/attachment.bin>


More information about the llvm-commits mailing list