[llvm] 1e8900c - [lit] Fix test that relied on "single process" mode

Julian Lettner via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 30 22:00:10 PDT 2020


Author: Julian Lettner
Date: 2020-03-30T21:58:48-07:00
New Revision: 1e8900cc828bd62fdcc314283c991080bae4520c

URL: https://github.com/llvm/llvm-project/commit/1e8900cc828bd62fdcc314283c991080bae4520c
DIFF: https://github.com/llvm/llvm-project/commit/1e8900cc828bd62fdcc314283c991080bae4520c.diff

LOG: [lit] Fix test that relied on "single process" mode

The shtest-inject test relied on being executed in "single process" mode
and started to fail with a `PicklingError` after it was removed:
```
  Can't pickle <class 'lit.TestingConfig.CustomFormat'>: attribute
  lookup lit.TestingConfig.CustomFormat failed
```

This happened because the test config has to be serialized to the worker
process, but apparently the `CustomFormat` class defined inline is not
serializable.

This change allows passing the tested functionality (preamble_commands)
directly to `lit.formats.ShTest` so we can use it directly in the test.

Added: 
    

Modified: 
    llvm/utils/lit/lit/formats/shtest.py
    llvm/utils/lit/tests/Inputs/shtest-inject/lit.cfg
    llvm/utils/lit/tests/shtest-inject.py

Removed: 
    


################################################################################
diff  --git a/llvm/utils/lit/lit/formats/shtest.py b/llvm/utils/lit/lit/formats/shtest.py
index fdc9bd0241f3..e1be48cbd37f 100644
--- a/llvm/utils/lit/lit/formats/shtest.py
+++ b/llvm/utils/lit/lit/formats/shtest.py
@@ -17,9 +17,14 @@ class ShTest(FileBasedTest):
     The ShTest files contain some number of shell-like command pipelines, along
     with assertions about what should be in the output.
     """
-    def __init__(self, execute_external=False):
+    def __init__(self, execute_external=False, extra_substitutions=[],
+                 preamble_commands=[]):
         self.execute_external = execute_external
+        self.extra_substitutions = extra_substitutions
+        self.preamble_commands = preamble_commands
 
     def execute(self, test, litConfig):
         return lit.TestRunner.executeShTest(test, litConfig,
-                                            self.execute_external)
+                                            self.execute_external,
+                                            self.extra_substitutions,
+                                            self.preamble_commands)

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-inject/lit.cfg b/llvm/utils/lit/tests/Inputs/shtest-inject/lit.cfg
index 65a02e0081a2..dfec55a3d427 100644
--- a/llvm/utils/lit/tests/Inputs/shtest-inject/lit.cfg
+++ b/llvm/utils/lit/tests/Inputs/shtest-inject/lit.cfg
@@ -1,17 +1,12 @@
 import lit
 
-class CustomFormat(lit.formats.TestFormat):
-    def execute(self, test, litConfig):
-        commands = [
-            'echo "THIS WAS"',
-            'echo "INJECTED"'
-        ]
-        return lit.TestRunner.executeShTest(test, litConfig,
-                                            useExternalSh=False,
-                                            preamble_commands=commands)
+preamble_commands = [
+    'echo "THIS WAS"',
+    'echo "INJECTED"'
+];
 
 config.name = 'shtest-inject'
 config.suffixes = ['.txt']
-config.test_format = CustomFormat()
+config.test_format = lit.formats.ShTest(preamble_commands=preamble_commands)
 config.test_source_root = None
 config.test_exec_root = None

diff  --git a/llvm/utils/lit/tests/shtest-inject.py b/llvm/utils/lit/tests/shtest-inject.py
index f51f083f3990..9f9ff6097921 100644
--- a/llvm/utils/lit/tests/shtest-inject.py
+++ b/llvm/utils/lit/tests/shtest-inject.py
@@ -1,5 +1,4 @@
-# Check that we can inject commands at the beginning of a ShTest using a custom
-# test format.
+# Check that we can inject commands at the beginning of a ShTest.
 
 # RUN: %{lit} -j 1 %{inputs}/shtest-inject/test-empty.txt --show-all | FileCheck --check-prefix=CHECK-TEST1 %s
 #


        


More information about the llvm-commits mailing list