[llvm] 4ef2e59 - [flang] Run non-gtest unit tests with lit.
David Truby via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 24 07:13:19 PDT 2020
Author: David Truby
Date: 2020-07-24T14:49:39+01:00
New Revision: 4ef2e594d5be2e0e6d4446c8082b15466bc7ffcb
URL: https://github.com/llvm/llvm-project/commit/4ef2e594d5be2e0e6d4446c8082b15466bc7ffcb
DIFF: https://github.com/llvm/llvm-project/commit/4ef2e594d5be2e0e6d4446c8082b15466bc7ffcb.diff
LOG: [flang] Run non-gtest unit tests with lit.
Summary:
As a corrollary, these tests are now run as part of the check-flang
target.
Reviewers: sscalpone
Subscribers: mgorny, delcypher, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83946
Added:
flang/test/NonGtestUnit/lit.cfg.py
flang/test/NonGtestUnit/lit.site.cfg.py.in
Modified:
flang/CMakeLists.txt
flang/test/CMakeLists.txt
flang/unittests/CMakeLists.txt
flang/unittests/Decimal/CMakeLists.txt
flang/unittests/Evaluate/CMakeLists.txt
flang/unittests/Runtime/CMakeLists.txt
llvm/utils/lit/lit/formats/__init__.py
llvm/utils/lit/lit/formats/base.py
Removed:
################################################################################
diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 9dd6281d410b..f1aaa5c6473f 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -380,7 +380,6 @@ endif()
add_subdirectory(runtime)
if (FLANG_INCLUDE_TESTS)
- enable_testing()
add_subdirectory(test)
if (FLANG_GTEST_AVAIL)
add_subdirectory(unittests)
diff --git a/flang/test/CMakeLists.txt b/flang/test/CMakeLists.txt
index ad47fff8c425..7da1d94d84c4 100644
--- a/flang/test/CMakeLists.txt
+++ b/flang/test/CMakeLists.txt
@@ -19,6 +19,13 @@ configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.cfg.py
)
+configure_lit_site_cfg(
+ ${CMAKE_CURRENT_SOURCE_DIR}/NonGtestUnit/lit.site.cfg.py.in
+ ${CMAKE_CURRENT_BINARY_DIR}/NonGtestUnit/lit.site.cfg.py
+ MAIN_CONFIG
+ ${CMAKE_CURRENT_SOURCE_DIR}/NonGtestUnit/lit.cfg.py
+)
+
set(FLANG_TEST_PARAMS
flang_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py)
diff --git a/flang/test/NonGtestUnit/lit.cfg.py b/flang/test/NonGtestUnit/lit.cfg.py
new file mode 100644
index 000000000000..7f53f861bc65
--- /dev/null
+++ b/flang/test/NonGtestUnit/lit.cfg.py
@@ -0,0 +1,16 @@
+import os
+
+import lit.Test
+
+config.name = 'flang-OldUnit'
+
+config.suffixes = [".test"]
+
+config.test_source_root = os.path.join(config.flang_obj_root, 'unittests')
+config.test_exec_root = config.test_source_root
+
+config.test_format = lit.formats.ExecutableTest()
+
+path = os.path.pathsep.join((config.flang_libs_dir, config.llvm_libs_dir,
+ config.environment.get('LD_LIBRARY_PATH','')))
+config.environment['LD_LIBRARY_PATH'] = path
diff --git a/flang/test/NonGtestUnit/lit.site.cfg.py.in b/flang/test/NonGtestUnit/lit.site.cfg.py.in
new file mode 100644
index 000000000000..3218fe0b5ce3
--- /dev/null
+++ b/flang/test/NonGtestUnit/lit.site.cfg.py.in
@@ -0,0 +1,27 @@
+ at LIT_SITE_CFG_IN_HEADER@
+
+config.llvm_src_root = "@LLVM_SOURCE_DIR@"
+config.llvm_obj_root = "@LLVM_BINARY_DIR@"
+config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
+config.llvm_libs_dir = "@LLVM_LIBS_DIR@"
+config.llvm_build_mode = "@LLVM_BUILD_MODE@"
+config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
+config.flang_obj_root = "@FLANG_BINARY_DIR@"
+config.flang_src_root = "@FLANG_SOURCE_DIR@"
+config.flang_libs_dir = "@LLVM_LIBRARY_OUTPUT_INTDIR@"
+config.flang_tools_dir = "@LLVM_RUNTIME_OUTPUT_INTDIR@"
+config.target_triple = "@TARGET_TRIPLE@"
+config.python_executable = "@Python3_EXECUTABLE@"
+
+# Support substitution of the tools and libs dirs with user parameters. This is
+# used when we can't determine the tool dir at configuration time.
+try:
+ config.llvm_tools_dir = config.llvm_tools_dir % lit_config.params
+ config.llvm_libs_dir = config.llvm_libs_dir % lit_config.params
+ config.llvm_build_mode = config.llvm_build_mode % lit_config.params
+except KeyError as e:
+ key, = e.args
+ lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key))
+
+# Let the main config do the real work.
+lit_config.load_config(config, "@FLANG_SOURCE_DIR@/test/NonGtestUnit/lit.cfg.py")
diff --git a/flang/unittests/CMakeLists.txt b/flang/unittests/CMakeLists.txt
index 21da59f3afcb..a30f0edaec61 100644
--- a/flang/unittests/CMakeLists.txt
+++ b/flang/unittests/CMakeLists.txt
@@ -9,6 +9,14 @@ if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
add_compile_options("-Wno-suggest-override")
endif()
+function(add_flang_nongtest_unittest test_name)
+ add_executable(${test_name}.test ${test_name}.cpp)
+
+ target_link_libraries(${test_name}.test ${ARGN})
+
+ add_dependencies(FlangUnitTests ${test_name}.test)
+endfunction()
+
add_subdirectory(Optimizer)
add_subdirectory(Decimal)
add_subdirectory(Evaluate)
diff --git a/flang/unittests/Decimal/CMakeLists.txt b/flang/unittests/Decimal/CMakeLists.txt
index f26aca5d0e9b..112b02f9029f 100644
--- a/flang/unittests/Decimal/CMakeLists.txt
+++ b/flang/unittests/Decimal/CMakeLists.txt
@@ -1,13 +1,10 @@
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
-add_executable(quick-sanity-test
- quick-sanity-test.cpp
-)
-
-target_link_libraries(quick-sanity-test
+add_flang_nongtest_unittest(quick-sanity-test
FortranDecimal
LLVMSupport
)
+# This test is not run by default as it takes a long time to execute
add_executable(thorough-test
thorough-test.cpp
)
@@ -16,5 +13,3 @@ target_link_libraries(thorough-test
FortranDecimal
LLVMSupport
)
-
-add_test(NAME Sanity COMMAND quick-sanity-test)
diff --git a/flang/unittests/Evaluate/CMakeLists.txt b/flang/unittests/Evaluate/CMakeLists.txt
index 54676b0b5a0a..c56789b598ce 100644
--- a/flang/unittests/Evaluate/CMakeLists.txt
+++ b/flang/unittests/Evaluate/CMakeLists.txt
@@ -8,43 +8,22 @@ target_link_libraries(FortranEvaluateTesting
LLVMSupport
)
-add_executable(leading-zero-bit-count-test
- leading-zero-bit-count.cpp
-)
-
-target_link_libraries(leading-zero-bit-count-test
+add_flang_nongtest_unittest(leading-zero-bit-count
FortranEvaluateTesting
LLVMSupport
)
-add_executable(bit-population-count-test
- bit-population-count.cpp
-)
-
-target_link_libraries(bit-population-count-test
+add_flang_nongtest_unittest(bit-population-count
FortranEvaluateTesting
LLVMSupport
)
-add_executable(uint128-test
- uint128.cpp
-)
-
-target_link_libraries(uint128-test
+add_flang_nongtest_unittest(uint128
FortranEvaluateTesting
LLVMSupport
)
-# These routines live in lib/Common but we test them here.
-add_test(UINT128 uint128-test)
-add_test(Leadz leading-zero-bit-count-test)
-add_test(PopPar bit-population-count-test)
-
-add_executable(expression-test
- expression.cpp
-)
-
-target_link_libraries(expression-test
+add_flang_nongtest_unittest(expression
FortranCommon
FortranEvaluateTesting
FortranEvaluate
@@ -53,22 +32,14 @@ target_link_libraries(expression-test
LLVMSupport
)
-add_executable(integer-test
- integer.cpp
-)
-
-target_link_libraries(integer-test
+add_flang_nongtest_unittest(integer
FortranEvaluateTesting
FortranEvaluate
FortranSemantics
LLVMSupport
)
-add_executable(intrinsics-test
- intrinsics.cpp
-)
-
-target_link_libraries(intrinsics-test
+add_flang_nongtest_unittest(intrinsics
FortranCommon
FortranEvaluateTesting
FortranEvaluate
@@ -79,11 +50,7 @@ target_link_libraries(intrinsics-test
LLVMSupport
)
-add_executable(logical-test
- logical.cpp
-)
-
-target_link_libraries(logical-test
+add_flang_nongtest_unittest(logical
FortranEvaluateTesting
FortranEvaluate
FortranSemantics
@@ -96,24 +63,16 @@ target_link_libraries(logical-test
# C++ exceptions are enabled for this test.
set(LLVM_REQUIRES_EH ON)
set(LLVM_REQUIRES_RTTI ON)
-add_executable(real-test
- real.cpp
-)
-llvm_update_compile_flags(real-test)
-
-target_link_libraries(real-test
+add_flang_nongtest_unittest(real
FortranEvaluateTesting
FortranEvaluate
FortranDecimal
FortranSemantics
LLVMSupport
)
+llvm_update_compile_flags(real.test)
-add_executable(reshape-test
- reshape.cpp
-)
-
-target_link_libraries(reshape-test
+add_flang_nongtest_unittest(reshape
FortranEvaluateTesting
FortranSemantics
FortranEvaluate
@@ -121,11 +80,7 @@ target_link_libraries(reshape-test
LLVMSupport
)
-add_executable(ISO-Fortran-binding-test
- ISO-Fortran-binding.cpp
-)
-
-target_link_libraries(ISO-Fortran-binding-test
+add_flang_nongtest_unittest(ISO-Fortran-binding
FortranEvaluateTesting
FortranEvaluate
FortranSemantics
@@ -133,23 +88,10 @@ target_link_libraries(ISO-Fortran-binding-test
LLVMSupport
)
-add_executable(folding-test
- folding.cpp
-)
-
-target_link_libraries(folding-test
+add_flang_nongtest_unittest(folding
FortranCommon
FortranEvaluateTesting
FortranEvaluate
FortranSemantics
LLVMSupport
)
-
-add_test(Expression expression-test)
-add_test(Integer integer-test)
-add_test(Intrinsics intrinsics-test)
-add_test(Logical logical-test)
-add_test(Real real-test)
-add_test(RESHAPE reshape-test)
-add_test(ISO-binding ISO-Fortran-binding-test)
-add_test(folding folding-test)
diff --git a/flang/unittests/Runtime/CMakeLists.txt b/flang/unittests/Runtime/CMakeLists.txt
index b13c84e88a02..041b631f59d6 100644
--- a/flang/unittests/Runtime/CMakeLists.txt
+++ b/flang/unittests/Runtime/CMakeLists.txt
@@ -13,30 +13,19 @@ target_link_libraries(RuntimeTesting
LLVMSupport
)
-add_executable(format-test
- format.cpp
-)
-
-target_link_libraries(format-test
+add_flang_nongtest_unittest(format
RuntimeTesting
FortranRuntime
LLVMSupport
)
-add_test(NAME Format COMMAND format-test)
-
-add_executable(hello-world
- hello.cpp
-)
-
-target_link_libraries(hello-world
+add_flang_nongtest_unittest(hello
RuntimeTesting
FortranRuntime
LLVMSupport
)
-add_test(NAME HelloWorld COMMAND hello-world)
-
+# This test is not run by default as it requires input.
add_executable(external-hello-world
external-hello.cpp
)
@@ -46,38 +35,20 @@ target_link_libraries(external-hello-world
LLVMSupport
)
-add_executable(external-io
- external-io.cpp
-)
-
-target_link_libraries(external-io
+add_flang_nongtest_unittest(external-io
RuntimeTesting
FortranRuntime
LLVMSupport
)
-add_test(NAME ExternalIO COMMAND external-io)
-
-add_executable(list-input-test
- list-input.cpp
-)
-
-target_link_libraries(list-input-test
+add_flang_nongtest_unittest(list-input
RuntimeTesting
FortranRuntime
LLVMSupport
)
-add_test(NAME ListInput COMMAND list-input-test)
-
-add_executable(character-test
- character.cpp
-)
-
-target_link_libraries(character-test
+add_flang_nongtest_unittest(character
RuntimeTesting
FortranRuntime
LLVMSupport
)
-
-add_test(NAME CharacterTest COMMAND character-test)
diff --git a/llvm/utils/lit/lit/formats/__init__.py b/llvm/utils/lit/lit/formats/__init__.py
index 3ff46e93ead2..7a357657670f 100644
--- a/llvm/utils/lit/lit/formats/__init__.py
+++ b/llvm/utils/lit/lit/formats/__init__.py
@@ -1,7 +1,8 @@
from lit.formats.base import ( # noqa: F401
TestFormat,
FileBasedTest,
- OneCommandPerFileTest
+ OneCommandPerFileTest,
+ ExecutableTest
)
from lit.formats.googletest import GoogleTest # noqa: F401
diff --git a/llvm/utils/lit/lit/formats/base.py b/llvm/utils/lit/lit/formats/base.py
index 6721d17e334e..b44a606e76a8 100644
--- a/llvm/utils/lit/lit/formats/base.py
+++ b/llvm/utils/lit/lit/formats/base.py
@@ -115,3 +115,20 @@ def execute(self, test, litConfig):
report += """Output:\n--\n%s--""" % diags
return lit.Test.FAIL, report
+
+
+###
+
+# Check exit code of a simple executable with no input
+class ExecutableTest(FileBasedTest):
+ def execute(self, test, litConfig):
+ if test.config.unsupported:
+ return lit.Test.UNSUPPORTED
+
+ out, err, exitCode = lit.util.executeCommand(test.getSourcePath())
+
+ if not exitCode:
+ return lit.Test.PASS, ''
+
+ return lit.Test.FAIL, out+err
+
More information about the llvm-commits
mailing list