[lit] Fix test that relied on "single process" mode
authorJulian Lettner <julian.lettner@apple.com>
Tue, 31 Mar 2020 04:35:42 +0000 (21:35 -0700)
committerJulian Lettner <julian.lettner@apple.com>
Tue, 31 Mar 2020 04:58:48 +0000 (21:58 -0700)
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.

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

index fdc9bd0..e1be48c 100644 (file)
@@ -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)
index 65a02e0..dfec55a 100644 (file)
@@ -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
index f51f083..9f9ff60 100644 (file)
@@ -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
 #