[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
This commit is contained in:
David Truby 2020-07-16 14:15:07 +01:00
parent 6b8948922c
commit 4ef2e594d5
10 changed files with 97 additions and 114 deletions

View File

@ -380,7 +380,6 @@ endif()
add_subdirectory(runtime)
if (FLANG_INCLUDE_TESTS)
enable_testing()
add_subdirectory(test)
if (FLANG_GTEST_AVAIL)
add_subdirectory(unittests)

View File

@ -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)

View File

@ -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

View File

@ -0,0 +1,27 @@
@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")

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -1,7 +1,8 @@
from lit.formats.base import ( # noqa: F401
TestFormat,
FileBasedTest,
OneCommandPerFileTest
OneCommandPerFileTest,
ExecutableTest
)
from lit.formats.googletest import GoogleTest # noqa: F401

View File

@ -115,3 +115,20 @@ class OneCommandPerFileTest(TestFormat):
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