Index: lib/External/CMakeLists.txt =================================================================== --- lib/External/CMakeLists.txt +++ lib/External/CMakeLists.txt @@ -260,25 +260,39 @@ ${ISL_FILES} ) +add_executable(polly-isl-test + isl/isl_test.c +) + +target_link_libraries(polly-isl-test + PollyISL +) + if (MSVC) # Disable common warnings; ideally, they should be fixed upstream - target_compile_options(PollyISL PRIVATE + set(DISABLE_WARNING_FLAGS -wd4018 # 'expression' : signed/unsigned mismatch -wd4090 # 'operation' : different 'modifier' qualifiers -wd4200 # nonstandard extension used: zero-sized array in struct/union -wd4201 # nonstandard extension used: nameless struct/union -wd4334 # 'operator': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?) ) + target_compile_options(PollyISL PRIVATE ${DISABLE_WARNING_FLAGS}) + target_compile_options(polly-isl-test PRIVATE ${DISABLE_WARNING_FLAGS}) endif () # ISL requires at least C99 to compile. gcc < 5.0 use -std=gnu89 as default. target_enable_c99(PollyISL) +target_enable_c99(polly-isl-test) # Disable warnings which should be coped with upstream for isl and imath. if (NOT MSVC) set_target_properties(PollyISL PROPERTIES COMPILE_FLAGS "-w" ) + set_target_properties(polly-isl-test PROPERTIES + COMPILE_FLAGS "-w" + ) endif () set(PET_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/pet") Index: test/CMakeLists.txt =================================================================== --- test/CMakeLists.txt +++ test/CMakeLists.txt @@ -74,6 +74,7 @@ COMMAND ${LLVM_LIT} --param polly_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg --param polly_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg + --param polly_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg --param build_config=${CMAKE_CFG_INTDIR} -sv ${POLLY_TEST_EXTRA_ARGS} ${CMAKE_CURRENT_BINARY_DIR} @@ -97,6 +98,18 @@ COMMENT "Running Polly unit tests") set_target_properties(check-polly-unittests PROPERTIES FOLDER "Polly") endif () + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/UnitIsl/lit.site.cfg.in + ${CMAKE_CURRENT_BINARY_DIR}/UnitIsl/lit.site.cfg) + + add_custom_target(check-polly-isl + command ${LLVM_LIT} + --param polly_site_config=${CMAKE_CURRENT_BINARY_DIR}/UnitIsl/lit.site.cfg + --param build_config=${CMAKE_CFG_INTDIR} + -sv ${POLLY_TEST_EXTRA_ARGS} + ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS polly-isl-test + COMMENT "Running isl unit tests") endif() else (NOT DEFINED LLVM_MAIN_SRC_DIR) @@ -141,6 +154,17 @@ set_target_properties(check-polly-unittests PROPERTIES FOLDER "Polly") endif () + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/UnitIsl/lit.site.cfg.in + ${CMAKE_CURRENT_BINARY_DIR}/UnitIsl/lit.site.cfg) + + add_lit_testsuite(check-polly-isl "Running isl unit tests only" + ${CMAKE_CURRENT_BINARY_DIR}/UnitIsl + PARAMS polly_site_config=${CMAKE_CURRENT_BINARY_DIR}/UnitIsl/lit.site.cfg + DEPENDS polly-isl-test + ) + set_target_properties(check-polly-isl PROPERTIES FOLDER "Polly") + # Run polly-check-format as part of polly-check only if we are compiling with # clang, so clang-format is available. # if (TARGET clang-format) would be preferable, but this target is only added Index: test/UnitIsl/isl_test.sh =================================================================== --- /dev/null +++ test/UnitIsl/isl_test.sh @@ -0,0 +1 @@ +; RUN: isl_test Index: test/UnitIsl/lit.cfg =================================================================== --- /dev/null +++ test/UnitIsl/lit.cfg @@ -0,0 +1,132 @@ +# -*clang- Python -*- + +import os +import platform +import re + +import lit.formats +import lit.util + +# Configuration file for the 'lit' test runner. + +# name: The name of this test suite. +config.name = 'Polly - isl unit tests' + +# testFormat: The test format to use to interpret tests. +# +# For now we require '&&' between commands, until they get globally killed and +# the test runner updated. +execute_external = platform.system() != 'Windows' +config.test_format = lit.formats.ShTest(execute_external) + +# suffixes: A list of file extensions to treat as test files. +config.suffixes = ['.sh'] + +# test_source_root: The root path where tests are located. +config.test_source_root = os.path.dirname(__file__) + +# test_exec_root: The root path where tests should be run. +polly_obj_root = getattr(config, 'polly_obj_root', None) +if polly_obj_root is not None: + config.test_exec_root = os.path.join(polly_obj_root, 'test') + +# Set llvm_{src,obj}_root for use by others. +config.llvm_src_root = getattr(config, 'llvm_src_root', None) +config.llvm_obj_root = getattr(config, 'llvm_obj_root', None) + +# Tweak the PATH to include the tools dir and the scripts dir. +if polly_obj_root is not None: + llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) + if not llvm_tools_dir: + lit_config.fatal('No LLVM tools dir set!') + path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH'])) + config.environment['PATH'] = path + + llvm_libs_dir = getattr(config, 'llvm_libs_dir', None) + if not llvm_libs_dir: + lit_config.fatal('No LLVM libs dir set!') + path = os.path.pathsep.join((llvm_libs_dir, + config.environment.get('LD_LIBRARY_PATH',''))) + config.environment['LD_LIBRARY_PATH'] = path + +### + +print(config.test_exec_root) +# Check that the object root is known. +if config.test_exec_root is None: + # Otherwise, we haven't loaded the site specific configuration (the user is + # probably trying to run on a test file directly, and either the site + # configuration hasn't been created by the build system, or we are in an + # out-of-tree build situation). + + # Check for 'polly_site_config' user parameter, and use that if available. + site_cfg = lit_config.params.get('polly_site_config', None) + if site_cfg and os.path.exists(site_cfg): + lit_config.load_config(config, site_cfg) + raise SystemExit + + # Try to detect the situation where we are using an out-of-tree build by + # looking for 'llvm-config'. + # + # FIXME: I debated (i.e., wrote and threw away) adding logic to + # automagically generate the lit.site.cfg if we are in some kind of fresh + # build situation. This means knowing how to invoke the build system though, + # and I decided it was too much magic. We should solve this by just having + # the .cfg files generated during the configuration step. + + llvm_config = lit.util.which('llvm-config', config.environment['PATH']) + if not llvm_config: + lit_config.fatal('No site specific configuration available!') + + # Get the source and object roots. + llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() + llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() + polly_src_root = os.path.join(llvm_src_root, "tools", "polly") + polly_obj_root = os.path.join(llvm_obj_root, "tools", "polly") + + # Validate that we got a tree which points to here, using the standard + # tools/polly layout. + this_src_root = os.path.dirname(config.test_source_root) + if os.path.realpath(polly_src_root) != os.path.realpath(this_src_root): + lit_config.fatal('No site specific configuration available!') + + # Check that the site specific configuration exists. + site_cfg = os.path.join(polly_obj_root, 'test', 'lit.site.cfg') + if not os.path.exists(site_cfg): + lit_config.fatal('No site specific configuration available!') + + # Okay, that worked. Notify the user of the automagic, and reconfigure. + lit_config.note('using out-of-tree build at %r' % polly_obj_root) + lit_config.load_config(config, site_cfg) + raise SystemExit + +config.environment['srcdir'] = os.path.join(config.test_source_root, + '../../lib/External/isl') + +# opt knows whether it is compiled with -DNDEBUG. +import subprocess +try: + opt_cmd = subprocess.Popen([os.path.join(llvm_tools_dir, 'opt'), '-version'], + stdout = subprocess.PIPE, + env=config.environment) +except OSError: + print("Could not find opt in " + llvm_tools_dir) + exit(42) + +if re.search(r'with assertions', opt_cmd.stdout.read().decode('ascii')): + config.available_features.add('asserts') +opt_cmd.wait() + +try: + llvm_config_cmd = subprocess.Popen([os.path.join(llvm_tools_dir, + 'llvm-config'), + '--targets-built'], + stdout = subprocess.PIPE, + env=config.environment) +except OSError: + print("Could not find llvm-config in " + llvm_tools_dir) + exit(42) + +if re.search(r'NVPTX', llvm_config_cmd.stdout.read().decode('ascii')): + config.available_features.add('nvptx-registered-target') +llvm_config_cmd.wait() Index: test/UnitIsl/lit.site.cfg.in =================================================================== --- /dev/null +++ test/UnitIsl/lit.site.cfg.in @@ -0,0 +1,30 @@ +@LIT_SITE_CFG_IN_HEADER@ + +import sys + +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.polly_obj_root = "@POLLY_BINARY_DIR@" +config.polly_lib_dir = "@POLLY_LIB_DIR@" +config.shlibdir = "@SHLIBDIR@" +config.target_triple = "@TARGET_TRIPLE@" +config.enable_gpgpu_codegen = "@GPU_CODEGEN@" +config.link_polly_into_tools = "@LINK_POLLY_INTO_TOOLS@" + +# Support substitution of the tools_dir, libs_dirs, and build_mode 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: + e = sys.exc_info()[1] + 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, "@POLLY_SOURCE_DIR@/test/UnitIsl/lit.cfg")