Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile only tests #1710

Merged
merged 17 commits into from Sep 14, 2015
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -183,6 +183,7 @@ hpx_option(HPX_WITH_TESTS BOOL "Build the HPX tests (default ON)" ON CATEGORY "B
hpx_option(HPX_WITH_TESTS_BENCHMARKS BOOL "Build HPX benchmark tests (default: ON)" ON ADVANCED CATEGORY "Build Targets")
hpx_option(HPX_WITH_TESTS_REGRESSIONS BOOL "Build HPX regression tests (default: ON)" ON ADVANCED CATEGORY "Build Targets")
hpx_option(HPX_WITH_TESTS_UNIT BOOL "Build HPX unit tests (default: ON)" ON ADVANCED CATEGORY "Build Targets")
hpx_option(HPX_WITH_TESTS_HEADERS BOOL "Build HPX header tests (default: OFF)" OFF ADVANCED CATEGORY "Build Targets")
hpx_option(HPX_WITH_TESTS_EXTERNAL_BUILD BOOL "Build external cmake build tests (default: ON)" ON ADVANCED CATEGORY "Build Targets")
hpx_option(HPX_WITH_TOOLS BOOL "Build HPX tools (default: OFF)" OFF ADVANCED CATEGORY "Build Targets")
hpx_option(HPX_WITH_RUNTIME BOOL "Build HPX runtime (default: ON)" ON ADVANCED CATEGORY "Build Targets")
Expand Down
51 changes: 14 additions & 37 deletions cmake/HPX_AddCompileTest.cmake
Expand Up @@ -16,44 +16,21 @@ macro(add_hpx_compile_test category name)
set(expected TRUE)
endif()

get_directory_property(_INCLUDE_DIRS INCLUDE_DIRECTORIES)
foreach(dir ${_INCLUDE_DIRS})
if(NOT MSVC)
set(include_flags ${include_flags} "-I${dir}")
else()
set(include_flags ${include_flags} "/I ${dir}")
endif()
endforeach()
add_hpx_executable(
${name}
SOURCE_ROOT ${${name}_SOURCE_ROOT}
SOURCES ${${name}_SOURCES}
EXCLUDE_FROM_ALL
EXCLUDE_FROM_DEFAULT_BUILD
FOLDER ${${name}_FOLDER})

add_test(NAME "${category}.${name}"
COMMAND ${CMAKE_COMMAND}
--build .
--target ${name}_exe
--config $<CONFIGURATION>
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

if(NOT ${name}_SOURCE_ROOT)
set(${name}_SOURCE_ROOT ".")
endif()
add_hpx_source_group(
NAME ${name}
CLASS "Source Files"
ROOT ${${name}_SOURCE_ROOT}
TARGETS ${${name}_SOURCES})

set(sources)
foreach(source ${${name}_SOURCES})
set(sources ${sources} "${CMAKE_CURRENT_SOURCE_DIR}/${source}")
endforeach()

string(REPLACE " " ";" CMAKE_CXX_FLAGS_LIST ${CMAKE_CXX_FLAGS})
set(cmd
${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS_LIST} ${include_flags} ${sources}
)

if(MSVC)
set(cmd ${cmd} -c /Fo"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}")
else()
set(cmd ${cmd} -c -o "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${name}.o")
endif()

add_test(
NAME "${category}.${name}"
COMMAND ${cmd}
)
if(expected)
set_tests_properties("${category}.${name}" PROPERTIES WILL_FAIL TRUE)
endif()
Expand Down
17 changes: 11 additions & 6 deletions cmake/HPX_AddExecutable.cmake
Expand Up @@ -6,7 +6,7 @@

macro(add_hpx_executable name)
# retrieve arguments
set(options EXCLUDE_FROM_ALL AUTOGLOB NOLIBS NOHPX_INIT)
set(options EXCLUDE_FROM_ALL EXCLUDE_FROM_DEFAULT_BUILD AUTOGLOB NOLIBS NOHPX_INIT)
set(one_value_args INI FOLDER SOURCE_ROOT HEADER_ROOT SOURCE_GLOB HEADER_GLOB OUTPUT_SUFFIX INSTALL_SUFFIX LANGUAGE HPX_PREFIX)
set(multi_value_args SOURCES HEADERS DEPENDENCIES COMPONENT_DEPENDENCIES COMPILE_FLAGS LINK_FLAGS)
cmake_parse_arguments(${name} "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
Expand Down Expand Up @@ -98,10 +98,8 @@ macro(add_hpx_executable name)
set(_target_flags)

# add the executable build target
set(exclude_from_all)
set(install_options)
if(${name}_EXCLUDE_FROM_ALL)
set(exclude_from_all EXCLUDE_FROM_ALL)
set(exclude_from_all EXCLUDE_FROM_ALL TRUE)
else()
set(install_destination bin)
if(${name}_INSTALL_SUFFIX)
Expand All @@ -114,7 +112,11 @@ macro(add_hpx_executable name)
)
endif()

add_executable(${name}_exe ${exclude_from_all}
if(${name}_EXCLUDE_FROM_DEFAULT_BUILD)
set(exclude_from_all ${exclude_from_all} EXCLUDE_FROM_DEFAULT_BUILD TRUE)
endif()

add_executable(${name}_exe
${${name}_SOURCES} ${${name}_HEADERS})

if(${name}_OUTPUT_SUFFIX)
Expand All @@ -132,6 +134,10 @@ macro(add_hpx_executable name)

set_target_properties(${name}_exe PROPERTIES OUTPUT_NAME ${name})

if(exclude_from_all)
set_target_properties(${name}_exe PROPERTIES ${exclude_from_all})
endif()

if(${${name}_NOLIBS})
set(_target_flags ${_target_flags} NOLIBS)
endif()
Expand All @@ -150,7 +156,6 @@ macro(add_hpx_executable name)
COMPONENT_DEPENDENCIES ${${name}_COMPONENT_DEPENDENCIES}
HPX_PREFIX ${${name}_HPX_PREFIX}
${_target_flags}
${install_optional}
)
endmacro()

5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Expand Up @@ -20,6 +20,11 @@ if(HPX_WITH_TESTS_UNIT)
${subdirs} unit)
endif()

if(HPX_WITH_TESTS_HEADERS)
set(subdirs
${subdirs} headers)
endif()

foreach(subdir ${subdirs})
add_hpx_pseudo_target(tests.${subdir})
add_subdirectory(${subdir})
Expand Down
75 changes: 75 additions & 0 deletions tests/headers/CMakeLists.txt
@@ -0,0 +1,75 @@
# Copyright (c) 2015 Hartmut Kaiser
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

# collect a list of all header files in the source tree
file(GLOB_RECURSE headers "${PROJECT_SOURCE_DIR}/hpx/*hpp")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably exclude everything in directories in "detail" directories, those are not meant to be included by anyone knowing exactly what they do anyways.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will do.


set(all_headers)

# for each of the found headers, generate a test executable
foreach(header ${headers})

# extract relative path of header
string(REGEX REPLACE "${PROJECT_SOURCE_DIR}/hpx/" "" relpath "${header}")

# .hpp --> .cpp
string(REGEX REPLACE ".hpp" ".cpp" full_test_file "${relpath}")

# remove extension, '/' --> '_'
string(REGEX REPLACE ".hpp" "_hpp" test_file "${relpath}")
string(REGEX REPLACE "/" "_" test_name "${test_file}")

# generate the test
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${full_test_file}
"#include <hpx/${relpath}>\n"
"int main() { return 0; }\n")

set(all_headers ${all_headers} "#include <hpx/${relpath}>\n")

get_filename_component(header_dir "${relpath}" DIRECTORY)

# add compile only test
add_hpx_unit_compile_test(
"headers"
${test_name}
SOURCES "${CMAKE_CURRENT_BINARY_DIR}/${full_test_file}"
SOURCE_ROOT "${CMAKE_CURRENT_BINARY_DIR}/${header_dir}"
FOLDER "Tests/Headers/${header_dir}")

# add a custom target for this example
add_hpx_pseudo_target(tests.headers.${test_name})

# make pseudo-targets depend on master pseudo-target
add_hpx_pseudo_dependencies(tests.headers tests.headers.${test_name})

# add dependencies to pseudo-target
add_hpx_pseudo_dependencies(tests.headers.${test_name}
"tests.unit.headers.${test_name}")

endforeach()

# generate a test executable project including all found header files
set(test_name "all_headers")
set(all_headers_test_name "${CMAKE_CURRENT_BINARY_DIR}/${test_name}.cpp")
file(WRITE ${all_headers_test_name}
${all_headers}
"int main() { return 0; }\n")

add_hpx_unit_compile_test(
"all_headers"
${test_name}
SOURCES "${all_headers_test_name}"
SOURCE_ROOT "${CMAKE_CURRENT_BINARY_DIR}"
FOLDER "Tests/Headers")

# add a custom target for this example
add_hpx_pseudo_target(tests.headers.${test_name})

# make pseudo-targets depend on master pseudo-target
add_hpx_pseudo_dependencies(tests.headers tests.headers.${test_name})

# add dependencies to pseudo-target
add_hpx_pseudo_dependencies(tests.headers.${test_name}
"tests.unit.headers.${test_name}")
45 changes: 18 additions & 27 deletions tests/unit/actions/CMakeLists.txt
Expand Up @@ -59,33 +59,24 @@ if(HPX_WITH_COMPILE_ONLY_TESTS)

source_group("Source Files" FILES ${sources})

if(MSVC)
# add dummy library for MSVC to generate a project in VS
add_hpx_library(${compile_test}_compile_test
SOURCES ${sources}
EXCLUDE_FROM_ALL
FOLDER "Tests/Unit/Actions/CompileOnly")

# add a custom target for this example
add_hpx_pseudo_target(tests.unit.actions.${compile_test})

# make pseudo-targets depend on master pseudo-target
add_hpx_pseudo_dependencies(tests.unit.actions
tests.unit.actions.${compile_test})

# add dependencies to pseudo-target
add_hpx_pseudo_dependencies(tests.unit.actions.${compile_test}
${compile_test}_compile_test_lib)

else()
add_hpx_unit_compile_test(
"actions"
${compile_test}
SOURCES ${sources}
${${compile_test}_FLAGS}
FOLDER "Tests/Unit/Actions/CompileOnly")
# there is no way to make this test depend on one of our pseudo targets
endif()
add_hpx_unit_compile_test(
"actions"
${compile_test}
SOURCES ${sources}
${${compile_test}_FLAGS}
FOLDER "Tests/Unit/Actions/CompileOnly")

# add a custom target for this example
add_hpx_pseudo_target(tests.unit.actions.${compile_test})

# make pseudo-targets depend on master pseudo-target
add_hpx_pseudo_dependencies(tests.unit.actions
tests.unit.actions.${compile_test})

# add dependencies to pseudo-target
add_hpx_pseudo_dependencies(tests.unit.actions.${compile_test}
"tests.unit.actions.${compile_test}")

endforeach()
endif()

46 changes: 18 additions & 28 deletions tests/unit/lcos/CMakeLists.txt
Expand Up @@ -133,34 +133,24 @@ if(HPX_WITH_COMPILE_ONLY_TESTS)
set(sources
${compile_test}.cpp)

source_group("Source Files" FILES ${sources})

if(MSVC)
# add dummy library for MSVC to generate a project in VS
add_hpx_library(${compile_test}_compile_test
SOURCES ${sources}
EXCLUDE_FROM_ALL
FOLDER "Tests/Unit/LCOs/CompileOnly")

# add a custom target for this example
add_hpx_pseudo_target(tests.unit.lcos.${compile_test})

# make pseudo-targets depend on master pseudo-target
add_hpx_pseudo_dependencies(tests.unit.lcos
tests.unit.lcos.${compile_test})

# add dependencies to pseudo-target
add_hpx_pseudo_dependencies(tests.unit.lcos.${compile_test}
${compile_test}_compile_test_lib)
else()
add_hpx_unit_compile_test(
"lcos"
${compile_test}
SOURCES ${sources}
${${compile_test}_FLAGS}
FOLDER "Tests/Unit/LCOs/CompileOnly")
# there is no way to make this test depend on one of our pseudo targets
endif()
add_hpx_unit_compile_test(
"lcos"
${compile_test}
SOURCES ${sources}
${${compile_test}_FLAGS}
FOLDER "Tests/Unit/LCOs/CompileOnly")

# add a custom target for this example
add_hpx_pseudo_target(tests.unit.lcos.${compile_test})

# make pseudo-targets depend on master pseudo-target
add_hpx_pseudo_dependencies(tests.unit.lcos
tests.unit.lcos.${compile_test})

# add dependencies to pseudo-target
add_hpx_pseudo_dependencies(tests.unit.lcos.${compile_test}
"tests.unit.lcos.${compile_test}")

endforeach()
endif()

2 changes: 1 addition & 1 deletion tests/unit/serialization/polymorphic/CMakeLists.txt
Expand Up @@ -26,7 +26,7 @@ foreach(test ${tests})
${${test}_FLAGS}
EXCLUDE_FROM_ALL
HPX_PREFIX ${HPX_BUILD_PREFIX}
FOLDER "Tests/Unit/Serialization/")
FOLDER "Tests/Unit/Serialization/Polymorphic")

add_hpx_unit_test("serialization" ${test} ${${test}_PARAMETERS})

Expand Down
Expand Up @@ -4,9 +4,6 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <iostream>
#include <vector>

#include <hpx/runtime/serialization/serialize.hpp>
#include <hpx/runtime/serialization/base_object.hpp>
#include <hpx/runtime/serialization/shared_ptr.hpp>
Expand All @@ -15,6 +12,9 @@
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>

#include <iostream>
#include <vector>

template <class T>
struct A
{
Expand Down
11 changes: 6 additions & 5 deletions tests/unit/serialization/polymorphic/polymorphic_template.cpp
Expand Up @@ -3,16 +3,17 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <iostream>
#include <vector>

#include <hpx/runtime/serialization/serialize.hpp>
#include <hpx/runtime/serialization/base_object.hpp>
#include <hpx/runtime/serialization/shared_ptr.hpp>
#include <hpx/util/lightweight_test.hpp>

#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <boost/current_function.hpp>

#include <iostream>
#include <vector>

template <class T>
struct A
Expand All @@ -31,7 +32,7 @@ struct A
void serialize(Ar& ar, unsigned)
{
ar & a;
std::cout << __PRETTY_FUNCTION__ << std::endl;
std::cout << BOOST_CURRENT_FUNCTION << std::endl;
}
HPX_SERIALIZATION_POLYMORPHIC_ABSTRACT(A);
};
Expand All @@ -53,7 +54,7 @@ struct B: A<T>
template <class Ar>
void serialize(Ar& ar, unsigned)
{
std::cout << __PRETTY_FUNCTION__ << std::endl;
std::cout << BOOST_CURRENT_FUNCTION << std::endl;
ar & hpx::serialization::base_object<A<T> >(*this);
ar & b;
}
Expand Down
Expand Up @@ -3,8 +3,6 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <iostream>

#include <hpx/runtime/serialization/serialize.hpp>
#include <hpx/runtime/serialization/base_object.hpp>
#include <hpx/runtime/serialization/shared_ptr.hpp>
Expand All @@ -15,6 +13,8 @@

#include <hpx/util/lightweight_test.hpp>

#include <iostream>

// =========================shared_ptr test==============================
struct A
{
Expand Down