summaryrefslogtreecommitdiff
path: root/utils/lit
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2017-09-21 16:18:28 +0000
committerZachary Turner <zturner@google.com>2017-09-21 16:18:28 +0000
commit2462b0299b02493822434ba165930c8feeb59dd1 (patch)
tree481f91e649ca31808dfcb515f4dfd46f032758dd /utils/lit
parent5185caa70db4611c18ee6e6c2529dd5e345f0a15 (diff)
[lit] Add a test for the builtin config map.
Config map is not exposed through the command line, so testing this is somewhat tricky. But basically we need a test that if a custom driver builds a config map and passes it to main, it gets respected. A config map allows config files in the source tree to be mapped to alternate config files in the build tree. This particular test works by having two config files in separate directories, and setting up a config map to have that redirects A/lit.site.cfg to B/altconfig. Then, we print a message in A/lit.site.cfg and B/altconfig and check that we do see the output from B but don't see the output from A. Additionally we test that the test suite specified by A's config map is properly discovered. Differential Revision: https://reviews.llvm.org/D38105 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313887 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/lit')
-rw-r--r--utils/lit/CMakeLists.txt7
-rw-r--r--utils/lit/lit/util.py6
-rw-r--r--utils/lit/tests/Inputs/config-map-discovery/driver.py14
-rw-r--r--utils/lit/tests/Inputs/config-map-discovery/invalid-test.txt0
-rw-r--r--utils/lit/tests/Inputs/config-map-discovery/lit.alt.cfg9
-rw-r--r--utils/lit/tests/Inputs/config-map-discovery/main-config/lit.cfg1
-rw-r--r--utils/lit/tests/Inputs/config-map-discovery/tests/test1.txt0
-rw-r--r--utils/lit/tests/Inputs/config-map-discovery/tests/test2.txt0
-rw-r--r--utils/lit/tests/discovery.py22
9 files changed, 58 insertions, 1 deletions
diff --git a/utils/lit/CMakeLists.txt b/utils/lit/CMakeLists.txt
index d10decedaa8..43caf09f140 100644
--- a/utils/lit/CMakeLists.txt
+++ b/utils/lit/CMakeLists.txt
@@ -1,7 +1,12 @@
# The configured file is not placed in the correct location
# until the tests are run as we need to copy it into
# a copy of the tests folder
-configure_lit_site_cfg("tests/lit.site.cfg.in" "lit.site.cfg")
+configure_lit_site_cfg(
+ "${CMAKE_CURRENT_SOURCE_DIR}/tests/lit.site.cfg.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg"
+ OUTPUT_MAPPING
+ "${CMAKE_CURRENT_BINARY_DIR}/tests/lit.site.cfg"
+ )
# Lit's test suite creates output files next to the sources which makes the
# source tree dirty. This is undesirable because we do out of source builds.
diff --git a/utils/lit/lit/util.py b/utils/lit/lit/util.py
index bdd407b57d5..174194f81be 100644
--- a/utils/lit/lit/util.py
+++ b/utils/lit/lit/util.py
@@ -9,6 +9,12 @@ import subprocess
import sys
import threading
+def norm_path(path):
+ path = os.path.realpath(path)
+ path = os.path.normpath(path)
+ path = os.path.normcase(path)
+ return path
+
def is_string(value):
try:
# Python 2 and Python 3 are different here.
diff --git a/utils/lit/tests/Inputs/config-map-discovery/driver.py b/utils/lit/tests/Inputs/config-map-discovery/driver.py
new file mode 100644
index 00000000000..c1acdfc972f
--- /dev/null
+++ b/utils/lit/tests/Inputs/config-map-discovery/driver.py
@@ -0,0 +1,14 @@
+import lit.util
+import os
+import sys
+
+main_config = sys.argv[1]
+
+config_map = {lit.util.norm_path(main_config) : sys.argv[2]}
+builtin_parameters = {'config_map' : config_map}
+
+if __name__=='__main__':
+ from lit.main import main
+ main_config_dir = os.path.dirname(main_config)
+ sys.argv = [sys.argv[0]] + sys.argv[3:] + [main_config_dir]
+ main(builtin_parameters)
diff --git a/utils/lit/tests/Inputs/config-map-discovery/invalid-test.txt b/utils/lit/tests/Inputs/config-map-discovery/invalid-test.txt
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/utils/lit/tests/Inputs/config-map-discovery/invalid-test.txt
diff --git a/utils/lit/tests/Inputs/config-map-discovery/lit.alt.cfg b/utils/lit/tests/Inputs/config-map-discovery/lit.alt.cfg
new file mode 100644
index 00000000000..8462c81bdca
--- /dev/null
+++ b/utils/lit/tests/Inputs/config-map-discovery/lit.alt.cfg
@@ -0,0 +1,9 @@
+import lit.formats
+import lit.util
+config.name = 'config-map'
+config.suffixes = ['.txt']
+config.test_format = lit.formats.ShTest()
+
+import os
+config.test_exec_root = lit.util.norm_path(os.path.dirname(__file__))
+config.test_source_root = os.path.join(config.test_exec_root, "tests")
diff --git a/utils/lit/tests/Inputs/config-map-discovery/main-config/lit.cfg b/utils/lit/tests/Inputs/config-map-discovery/main-config/lit.cfg
new file mode 100644
index 00000000000..380a05beb4a
--- /dev/null
+++ b/utils/lit/tests/Inputs/config-map-discovery/main-config/lit.cfg
@@ -0,0 +1 @@
+print("ERROR: lit.cfg invoked!") \ No newline at end of file
diff --git a/utils/lit/tests/Inputs/config-map-discovery/tests/test1.txt b/utils/lit/tests/Inputs/config-map-discovery/tests/test1.txt
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/utils/lit/tests/Inputs/config-map-discovery/tests/test1.txt
diff --git a/utils/lit/tests/Inputs/config-map-discovery/tests/test2.txt b/utils/lit/tests/Inputs/config-map-discovery/tests/test2.txt
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/utils/lit/tests/Inputs/config-map-discovery/tests/test2.txt
diff --git a/utils/lit/tests/discovery.py b/utils/lit/tests/discovery.py
index ba5247337a8..41a2d6cad3d 100644
--- a/utils/lit/tests/discovery.py
+++ b/utils/lit/tests/discovery.py
@@ -25,6 +25,28 @@
# CHECK-BASIC-OUT: top-level-suite :: test-one
# CHECK-BASIC-OUT: top-level-suite :: test-two
+# Check discovery when providing the special builtin 'config_map'
+# RUN: %{python} %{inputs}/config-map-discovery/driver.py \
+# RUN: %{inputs}/config-map-discovery/main-config/lit.cfg \
+# RUN: %{inputs}/config-map-discovery/lit.alt.cfg \
+# RUN: --single-process --debug --show-tests --show-suites > %t.out 2> %t.err
+# RUN: FileCheck --check-prefix=CHECK-CONFIG-MAP-OUT < %t.out %s
+# RUN: FileCheck --check-prefix=CHECK-CONFIG-MAP-ERR < %t.err %s
+
+# CHECK-CONFIG-MAP-OUT-NOT: ERROR: lit.cfg invoked
+# CHECK-CONFIG-MAP-OUT: -- Test Suites --
+# CHECK-CONFIG-MAP-OUT: config-map - 2 tests
+# CHECK-CONFIG-MAP-OUT: Source Root: {{.*[/\\]config-map-discovery[/\\]tests}}
+# CHECK-CONFIG-MAP-OUT: Exec Root : {{.*[/\\]tests[/\\]inputs[/\\]config-map-discovery}}
+# CHECK-CONFIG-MAP-OUT: -- Available Tests --
+# CHECK-CONFIG-MAP-OUT-NOT: invalid-test.txt
+# CHECK-CONFIG-MAP-OUT: config-map :: test1.txt
+# CHECK-CONFIG-MAP-OUT: config-map :: test2.txt
+
+# CHECK-CONFIG-MAP-ERR: loading suite config '{{.*}}lit.alt.cfg'
+# CHECK-CONFIG-MAP-ERR: loaded config '{{.*}}lit.alt.cfg'
+# CHECK-CONFIG-MAP-ERR: resolved input '{{.*config-map-discovery[/\\]main-config}}' to 'config-map'::()
+
# Check discovery when exact test names are given.
#