[llvm] r313887 - [lit] Add a test for the builtin config map.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 09:18:29 PDT 2017


Author: zturner
Date: Thu Sep 21 09:18:28 2017
New Revision: 313887

URL: http://llvm.org/viewvc/llvm-project?rev=313887&view=rev
Log:
[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

Added:
    llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/
    llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/driver.py
    llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/invalid-test.txt
    llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/lit.alt.cfg
    llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/main-config/
    llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/main-config/lit.cfg
    llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/tests/
    llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/tests/test1.txt
    llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/tests/test2.txt
Modified:
    llvm/trunk/cmake/modules/AddLLVM.cmake
    llvm/trunk/utils/lit/CMakeLists.txt
    llvm/trunk/utils/lit/lit/util.py
    llvm/trunk/utils/lit/tests/discovery.py

Modified: llvm/trunk/cmake/modules/AddLLVM.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/AddLLVM.cmake?rev=313887&r1=313886&r2=313887&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/AddLLVM.cmake (original)
+++ llvm/trunk/cmake/modules/AddLLVM.cmake Thu Sep 21 09:18:28 2017
@@ -1113,10 +1113,14 @@ endfunction(llvm_canonicalize_cmake_bool
 # common variables that any Lit instance is likely to need, and custom
 # variables can be passed in.
 function(configure_lit_site_cfg site_in site_out)
-  cmake_parse_arguments(ARG "" "" "MAIN_CONFIG" ${ARGN})
+  cmake_parse_arguments(ARG "" "" "MAIN_CONFIG;OUTPUT_MAPPING" ${ARGN})
 
   if ("${ARG_MAIN_CONFIG}" STREQUAL "")
-    set(ARG_MAIN_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg")
+    get_filename_component(INPUT_DIR ${site_in} DIRECTORY)
+    set(ARG_MAIN_CONFIG "${INPUT_DIR}/lit.cfg")
+  endif()
+  if ("${ARG_OUTPUT_MAPPING}" STREQUAL "")
+    set(ARG_OUTPUT_MAPPING "${site_out}")
   endif()
 
   foreach(c ${LLVM_TARGETS_TO_BUILD})
@@ -1184,7 +1188,6 @@ function(configure_lit_site_cfg site_in
      "lit.llvm.initialize(lit_config, config)\n")
 
   configure_file(${site_in} ${site_out} @ONLY)
-  get_filename_component(INPUT_DIR ${site_in} DIRECTORY)
   if (EXISTS "${ARG_MAIN_CONFIG}")
     set(PYTHON_STATEMENT "map_config('${ARG_MAIN_CONFIG}', '${site_out}')")
     get_property(LLVM_LIT_CONFIG_MAP GLOBAL PROPERTY LLVM_LIT_CONFIG_MAP)

Modified: llvm/trunk/utils/lit/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/CMakeLists.txt?rev=313887&r1=313886&r2=313887&view=diff
==============================================================================
--- llvm/trunk/utils/lit/CMakeLists.txt (original)
+++ llvm/trunk/utils/lit/CMakeLists.txt Thu Sep 21 09:18:28 2017
@@ -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.

Modified: llvm/trunk/utils/lit/lit/util.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/util.py?rev=313887&r1=313886&r2=313887&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/util.py (original)
+++ llvm/trunk/utils/lit/lit/util.py Thu Sep 21 09:18:28 2017
@@ -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.

Added: llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/driver.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/driver.py?rev=313887&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/driver.py (added)
+++ llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/driver.py Thu Sep 21 09:18:28 2017
@@ -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)

Added: llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/invalid-test.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/invalid-test.txt?rev=313887&view=auto
==============================================================================
    (empty)

Added: llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/lit.alt.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/lit.alt.cfg?rev=313887&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/lit.alt.cfg (added)
+++ llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/lit.alt.cfg Thu Sep 21 09:18:28 2017
@@ -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")

Added: llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/main-config/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/main-config/lit.cfg?rev=313887&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/main-config/lit.cfg (added)
+++ llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/main-config/lit.cfg Thu Sep 21 09:18:28 2017
@@ -0,0 +1 @@
+print("ERROR: lit.cfg invoked!")
\ No newline at end of file

Added: llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/tests/test1.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/tests/test1.txt?rev=313887&view=auto
==============================================================================
    (empty)

Added: llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/tests/test2.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/config-map-discovery/tests/test2.txt?rev=313887&view=auto
==============================================================================
    (empty)

Modified: llvm/trunk/utils/lit/tests/discovery.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/discovery.py?rev=313887&r1=313886&r2=313887&view=diff
==============================================================================
--- llvm/trunk/utils/lit/tests/discovery.py (original)
+++ llvm/trunk/utils/lit/tests/discovery.py Thu Sep 21 09:18:28 2017
@@ -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.
 #




More information about the llvm-commits mailing list