diff --git a/CMake/RunTests/CMakeLists.txt b/CMake/RunTests/CMakeLists.txt new file mode 100644 index 0000000000..726603fe46 --- /dev/null +++ b/CMake/RunTests/CMakeLists.txt @@ -0,0 +1,44 @@ +# Project that runs the Clang regression tests for a given glob pattern. +# +# There are several CMake cache variabes that must be set for this +# project to work: +# +# CLANG_TEST_RUNNER: The TestRunner.sh shell script, which is used to test +# Clang. +# +# CLANG_TEST_GLOB_PATTERN: Set to a GLOB pattern to identify the kind of +# tests, e.g., *.cpp for C++ tests. +# +# LLVM_TOOLS_PATH: The directory where the Clang and LLVM tool +# executables (such as opt) are generated. +# +# LLVM_SCRIPTS_PATH: The directory where the LLVM test scripts are +# located. +cmake_minimum_required(VERSION 2.6) +project(ClangTest) + +enable_testing() + +# Computes the normalized name of a test from its path name. +macro(compute_test_name var filename) + get_filename_component(test_name ${filename} NAME_WE) + get_filename_component(test_path ${filename} PATH) + get_filename_component(test_lastpath ${test_path} NAME_WE) + set(${var} "${test_lastpath}-${test_name}") +endmacro() + +# FIXME: Total hack! +file(WRITE dummy.c "int dummy() { return 0; }") +add_library(dummy dummy.c) + +set(PATH $ENV{PATH}) +set(PATH "${LLVM_TOOLS_PATH}:${LLVM_SCRIPTS_PATH}:${PATH}") +message(STATUS "Globbing for tests with ${CLANG_TEST_GLOB_PATTERN}") +file(GLOB_RECURSE tests ${CLANG_TEST_GLOB_PATTERN}) +foreach(test ${tests}) + compute_test_name(testname ${test}) + message(STATUS "Adding test ${testname} with file ${test}") + add_test(${testname} ${CLANG_TEST_RUNNER} ${test}) + set_tests_properties(${testname} PROPERTIES + ENVIRONMENT "PATH=${PATH}") +endforeach(test ${tests}) \ No newline at end of file diff --git a/CMake/RunTests/dummy.c b/CMake/RunTests/dummy.c new file mode 100644 index 0000000000..ddba74f1c8 --- /dev/null +++ b/CMake/RunTests/dummy.c @@ -0,0 +1 @@ +int dummy() { return 0; } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ca44b8445..45f3d0c56b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,3 +54,4 @@ add_subdirectory(lib) add_subdirectory(tools) # TODO: docs. +add_subdirectory(test) \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000000..c64ca896a1 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,33 @@ +find_file(CLANG_TEST_RUNNER TestRunner.sh PATHS ${CMAKE_CURRENT_SOURCE_DIR} + DOC "Clang's regression testing script") +mark_as_advanced(CLANG_TEST_RUNNER) + +get_target_property(LLVM_TOOLS_PATH clang RUNTIME_OUTPUT_DIRECTORY) + +add_custom_target(clang-test COMMENT "Running Clang regression tests") + +macro(add_clang_test_suite language target extension) +add_custom_target(${target} + ${CMAKE_CTEST_COMMAND} + --build-and-test + ${LLVM_SOURCE_DIR}/tools/clang/CMake/RunTests + ${CMAKE_CURRENT_BINARY_DIR}/${target} + --build-generator ${CMAKE_GENERATOR} + --build-makeprogram ${CMAKE_MAKE_PROGRAM} + --build-project ClangTest + --build-target test + --build-options + "-DCLANG_TEST_RUNNER=${CLANG_TEST_RUNNER}" + "-DCLANG_TEST_GLOB_PATTERN=${CMAKE_CURRENT_SOURCE_DIR}/*.${extension}" + "-DLLVM_TOOLS_PATH=${LLVM_TOOLS_PATH}" + "-DLLVM_SCRIPTS_PATH=${LLVM_SOURCE_DIR}/test/Scripts" + COMMENT "Running Clang ${language} regression tests") + + add_dependencies(clang-test ${target}) +endmacro(add_clang_test_suite) + +add_clang_test_suite(C clang-test-c c) +add_clang_test_suite(Objective-C clang-test-objc m) +add_clang_test_suite(C++ clang-test-cxx cpp) +add_clang_test_suite(Objective-C++ clang-test-objcxx mm) +add_clang_test_suite(Assembler clang-test-asm S)