-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up: Add simple testing environment
- Loading branch information
Showing
17 changed files
with
466 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
cmake_minimum_required(VERSION 3.3) | ||
|
||
project(ione | ||
LANGUAGES CXX | ||
) | ||
|
||
set(IONE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
set(IONE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
# Include guards | ||
if (IONE_SOURCE_DIR STREQUAL IONE_BINARY_DIR) | ||
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.") | ||
endif () | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
set(CMAKE_CXX_VISIBILITY_PRESET hidden) | ||
|
||
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
|
||
list(APPEND CMAKE_MODULE_PATH "${IONE_SOURCE_DIR}/cmake") | ||
include(ione_flags) | ||
|
||
if (IONE_INSTALL) | ||
include(GNUInstallDirs) | ||
install(DIRECTORY ${IONE_SOURCE_DIR}/include/ione TYPE INCLUDE) | ||
install(DIRECTORY ${IONE_BINARY_DIR}/include/ione TYPE INCLUDE) | ||
endif() | ||
|
||
add_subdirectory(src) # Create static library | ||
|
||
if (IONE_TEST) | ||
enable_testing() | ||
add_subdirectory(test) | ||
message("CMAKE_CXX_COMPILER_ID : ${CMAKE_CXX_COMPILER_ID}") | ||
message("CMAKE_CXX_SIMULATE_ID : ${CMAKE_CXX_SIMULATE_ID}") | ||
message("IONE_LINK_OPTIONS : ${IONE_LINK_OPTIONS}") | ||
message("IONE_COMPILE_OPTIONS: ${IONE_COMPILE_OPTIONS}") | ||
message("IONE_DEFINITIONS : ${IONE_DEFINITIONS}") | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") | ||
list(APPEND IONE_COMPILE_OPTIONS | ||
/fsanitize=address | ||
/fsanitize-address-use-after-return | ||
) | ||
else () | ||
if (NOT CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC") | ||
list(APPEND IONE_LINK_OPTIONS -fsanitize=address) | ||
list(APPEND IONE_COMPILE_OPTIONS -fno-common) | ||
endif () | ||
list(APPEND IONE_COMPILE_OPTIONS -fsanitize=address) | ||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
# -fsanitize=pointer-subtract removed because detect_invalid_pointer_pairs fails with fiber fault injection | ||
# on test initialization, probably caused by GTest | ||
# TODO(kononovk) add -fsanitize=pointer-compare when will be fixed: | ||
# https://github.com/google/sanitizers/issues/1324 also see mentioned issue | ||
list(APPEND IONE_COMPILE_OPTIONS | ||
# -fsanitize=pointer-subtract | ||
-fsanitize-address-use-after-scope | ||
) | ||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | ||
list(APPEND IONE_COMPILE_OPTIONS | ||
# -fsanitize=pointer-compare,pointer-subtract | ||
-fsanitize-address-use-after-scope | ||
-mllvm -asan-use-private-alias=1 | ||
) | ||
endif () | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
set(IONE_ASAN 0) | ||
set(IONE_UBSAN 0) | ||
set(IONE_LSAN 0) | ||
set(IONE_TSAN 0) | ||
set(IONE_MEMSAN 0) | ||
|
||
if (ASAN IN_LIST IONE_FLAGS) | ||
set(IONE_SAN 1) | ||
set(IONE_ASAN 1) | ||
include(ione_asan) | ||
endif () | ||
if (UBSAN IN_LIST IONE_FLAGS) | ||
set(IONE_SAN 1) | ||
set(IONE_UBSAN 1) | ||
include(ione_ubsan) | ||
endif () | ||
if (LSAN IN_LIST IONE_FLAGS) | ||
set(IONE_SAN 1) | ||
set(IONE_LSAN 1) | ||
include(ione_lsan) | ||
endif () | ||
if (TSAN IN_LIST IONE_FLAGS) | ||
set(IONE_SAN 1) | ||
set(IONE_TSAN 1) | ||
include(ione_tsan) | ||
endif () | ||
if (MEMSAN IN_LIST IONE_FLAGS) | ||
set(IONE_SAN 1) | ||
set(IONE_MEMSAN 1) | ||
include(ione_memsan) | ||
endif () | ||
if (IONE_SAN AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND NOT CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC") | ||
# Nicer stack trace and recover | ||
list(APPEND IONE_COMPILE_OPTIONS -fno-omit-frame-pointer) | ||
endif () | ||
|
||
set(IONE_COVERAGE 0) | ||
if (COVERAGE IN_LIST IONE_FLAGS) | ||
set(IONE_COVERAGE 1) | ||
list(APPEND IONE_LINK_OPTIONS --coverage) | ||
list(APPEND IONE_COMPILE_OPTIONS --coverage) | ||
list(APPEND IONE_DEFINITIONS NDEBUG) | ||
endif () | ||
|
||
|
||
set(IONE_FUTEX 0) # TODO(kononovk) Fucking atomic::wait bugged | ||
|
||
if (DISABLE_SYMMETRIC_TRANSFER IN_LIST IONE_FLAGS) | ||
set(IONE_SYMMETRIC_TRANSFER 0) | ||
set(IONE_FINAL_SUSPEND_TRANSFER 0) | ||
elseif (DISABLE_FINAL_SUSPEND_TRANSFER IN_LIST IONE_FLAGS) | ||
set(IONE_SYMMETRIC_TRANSFER 1) | ||
set(IONE_FINAL_SUSPEND_TRANSFER 0) | ||
else () | ||
set(IONE_SYMMETRIC_TRANSFER 1) | ||
set(IONE_FINAL_SUSPEND_TRANSFER 1) | ||
endif () | ||
|
||
if (ERROR IN_LIST IONE_LOG) | ||
list(APPEND IONE_DEFINITIONS IONE_LOG_ERROR) | ||
endif () | ||
if (WARN IN_LIST IONE_LOG) | ||
list(APPEND IONE_DEFINITIONS IONE_LOG_WARN) | ||
endif () | ||
if (DEBUG IN_LIST IONE_LOG) | ||
list(APPEND IONE_DEFINITIONS IONE_LOG_DEBUG) | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
list(APPEND IONE_LINK_OPTIONS -fsanitize=leak) | ||
list(APPEND IONE_COMPILE_OPTIONS -fsanitize=leak) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Memory Sanitizer doesn't work without compile stdlib with it | ||
list(APPEND IONE_LINK_OPTIONS -fsanitize=memory) | ||
list(APPEND IONE_COMPILE_OPTIONS -fsanitize=memory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
list(APPEND IONE_LINK_OPTIONS -fsanitize=thread) | ||
list(APPEND IONE_COMPILE_OPTIONS -fsanitize=thread) | ||
|
||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") | ||
list(APPEND IONE_COMPILE_OPTIONS -gcolumn-info) | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
set(IONE_UBSAN 1) | ||
if (NOT CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC") | ||
list(APPEND IONE_LINK_OPTIONS -fsanitize=undefined) | ||
endif () | ||
list(APPEND IONE_COMPILE_OPTIONS -fsanitize=undefined,float-divide-by-zero) | ||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
list(APPEND IONE_COMPILE_OPTIONS -fsanitize=float-cast-overflow) | ||
else () | ||
list(APPEND IONE_COMPILE_OPTIONS -fsanitize=implicit-conversion,local-bounds) | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") | ||
# TODO(kononovk) We have to use /Wall. But MSVC is dumb and uses this flag for external projects, like gtest. | ||
list(APPEND IONE_WARN | ||
/Wall | ||
/wd4625 # copy constructor was implicitly defined as deleted | ||
/wd4626 # assignment operator was implicitly defined as deleted | ||
/wd5026 # move constructor was implicitly defined as deleted | ||
/wd5027 # move assignment operator was implicitly defined as deleted | ||
/wd4514 # TODO(kononovk) Fix it (unreferenced inline function has been removed) | ||
/wd4820 # TODO(kononovk) Maybe ix it (bytes padding added after data member) | ||
) | ||
elseif (CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?Clang") | ||
list(APPEND IONE_WARN | ||
-Weverything | ||
-Wno-c++98-compat | ||
-Wno-c++98-compat-pedantic | ||
-Wno-ctad-maybe-unsupported | ||
-Wno-padded | ||
-Wno-exit-time-destructors | ||
-Wno-undefined-func-template # Needed for some hacks that speed up compilation | ||
-Wno-weak-template-vtables # TODO(kononovk) Maybe fix it | ||
-Wno-switch-enum # TODO(kononovk) Maybe fix it | ||
-Wno-weak-vtables # TODO(kononovk) Fix it | ||
) | ||
else () | ||
list(APPEND IONE_WARN | ||
-Wall | ||
-Wextra | ||
-pedantic | ||
) | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") | ||
# TODO(kononovk) We have to use /Wall. We need to disable some paranoid warnings, but I don't have windows. | ||
list(APPEND IONE_WARN | ||
/W3 | ||
) | ||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | ||
list(APPEND IONE_WARN | ||
-Weverything | ||
-Wno-c++98-compat | ||
-Wno-c++98-compat-pedantic | ||
-Wno-ctad-maybe-unsupported | ||
-Wno-padded | ||
-Wno-exit-time-destructors | ||
-Wno-undefined-func-template # Needed for some hacks that speed up compilation | ||
-Wno-weak-template-vtables # TODO(kononovk) Maybe fix it | ||
-Wno-switch-enum # TODO(kononovk) Maybe fix it | ||
-Wno-weak-vtables # TODO(kononovk) Fix it | ||
-Wno-global-constructors # TODO(kononovk) Maybe fix it: Needed only for tests | ||
-Wno-sign-conversion # TODO(kononovk) Maybe fix it: Needed only for tests | ||
-Wno-gnu-zero-variadic-macro-arguments # TODO(kononovk) Fix it: Needed only for tests | ||
-Wno-covered-switch-default # TODO(kononovk) Fix it: test/unit/algo/when_any.cpp | ||
-Wno-shadow-uncaptured-local # TODO(kononovk) Fix it: test/unit/algo/when_any.cpp | ||
) | ||
if (CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC") | ||
list(APPEND IONE_WARN | ||
-Wno-undef # For gtest | ||
) | ||
endif () | ||
else () | ||
list(APPEND IONE_WARN | ||
-Wall | ||
-Wextra | ||
-pedantic | ||
) | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
namespace ione { | ||
|
||
int Sum(int, int); | ||
|
||
} // namespace ione |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
macro(add_files) | ||
set(IONE_INCLUDES ${IONE_INCLUDES} PARENT_SCOPE) | ||
set(IONE_HEADERS ${IONE_HEADERS} PARENT_SCOPE) | ||
set(IONE_SOURCES ${IONE_SOURCES} PARENT_SCOPE) | ||
endmacro() | ||
|
||
set(IONE_INCLUDE_DIR ${IONE_SOURCE_DIR}/include/ione) | ||
set(IONE_STD_INCLUDE_DIR ${IONE_SOURCE_DIR}/include/ione_std) | ||
|
||
set(IONE_INCLUDES | ||
${IONE_BINARY_DIR}/include/ione/config.hpp | ||
) | ||
set(IONE_HEADERS | ||
) | ||
set(IONE_SOURCES | ||
) | ||
|
||
add_subdirectory(sum) | ||
|
||
configure_file(config.hpp.in ${IONE_BINARY_DIR}/include/ione/config.hpp) | ||
|
||
add_library(ione STATIC) | ||
|
||
include(FetchContent) | ||
FetchContent_Declare(yaclib | ||
GIT_REPOSITORY https://github.com/YACLib/YACLib.git | ||
GIT_TAG main | ||
) | ||
set(YACLIB_FLAGS "CORO") | ||
FetchContent_MakeAvailable(yaclib) | ||
target_link_libraries(ione PUBLIC yaclib) | ||
|
||
target_sources(ione | ||
PUBLIC ${IONE_INCLUDES} | ||
PRIVATE ${IONE_HEADERS} | ||
PRIVATE ${IONE_SOURCES} | ||
) | ||
|
||
if (WARN IN_LIST IONE_FLAGS) | ||
include(ione_warn_lib) | ||
message("IOneRing/library warnings: ${IONE_WARN}") | ||
endif () | ||
target_compile_options(ione PRIVATE ${IONE_COMPILE_OPTIONS} ${IONE_WARN}) | ||
target_compile_definitions(ione PRIVATE ${IONE_DEFINITIONS}) | ||
|
||
find_package(Threads REQUIRED) | ||
target_link_libraries(ione PUBLIC Threads::Threads) | ||
|
||
target_include_directories(ione | ||
PUBLIC ${IONE_SOURCE_DIR}/include | ||
PUBLIC ${IONE_BINARY_DIR}/include # for config.hpp | ||
PRIVATE ${IONE_SOURCE_DIR}/src | ||
) | ||
|
||
if (IONE_INSTALL) | ||
install(TARGETS ione) | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#pragma once |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
list(APPEND IONE_INCLUDES | ||
${IONE_INCLUDE_DIR}/sum/sum.hpp | ||
) | ||
list(APPEND IONE_HEADERS | ||
) | ||
list(APPEND IONE_HEADERS | ||
${CMAKE_CURRENT_SOURCE_DIR}/sum.cpp | ||
) | ||
|
||
add_files() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <ione/sum/sum.hpp> | ||
|
||
namespace ione { | ||
|
||
int Sum(int a, int b) { | ||
return a + b; | ||
} | ||
|
||
} // namespace ione |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
cmake_minimum_required(VERSION 3.13) | ||
|
||
if (IONE_LINK_OPTIONS OR IONE_COMPILE_OPTIONS) | ||
add_link_options(${IONE_LINK_OPTIONS}) | ||
add_compile_options(${IONE_COMPILE_OPTIONS}) | ||
else () | ||
find_package(GTest QUIET) | ||
endif () | ||
|
||
if (NOT GTEST_FOUND) | ||
include(FetchContent) | ||
FetchContent_Declare(googletest | ||
GIT_REPOSITORY https://github.com/google/googletest.git | ||
GIT_TAG main | ||
) | ||
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) | ||
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE) # May be enabled later | ||
# For Windows: Prevent overriding the parent project's compiler/linker settings | ||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
FetchContent_MakeAvailable(googletest) | ||
endif () | ||
|
||
set(TEST_UTIL_INCLUDES | ||
) | ||
set(TEST_UTIL_SOURCES | ||
) | ||
|
||
set(IONE_EXAMPLE_SOURCES | ||
) | ||
set(IONE_UNIT_SOURCES | ||
unit/sum/sum | ||
) | ||
|
||
set(IONE_TEST_SOURCES ${IONE_UNIT_SOURCES} ${IONE_EXAMPLE_SOURCES}) | ||
|
||
set(OLD_IONE_DEFINITIONS IONE_DEFINITIONS) | ||
|
||
if (NOT IONE_DEFINITIONS MATCHES "IONE_CI_SLOWDOWN") | ||
list(APPEND IONE_DEFINITIONS "IONE_CI_SLOWDOWN=1") | ||
endif () | ||
|
||
function(ione_add_test TEST_NAME) | ||
target_compile_options(${TEST_NAME} PRIVATE ${IONE_WARN}) | ||
target_compile_definitions(${TEST_NAME} PRIVATE ${IONE_DEFINITIONS}) | ||
target_sources(${TEST_NAME} | ||
PRIVATE ${TEST_UTIL_INCLUDES} | ||
) | ||
target_link_libraries(${TEST_NAME} | ||
PRIVATE GTest::gtest | ||
PRIVATE ione | ||
) | ||
target_include_directories(${TEST_NAME} | ||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} | ||
PRIVATE ${IONE_SOURCE_DIR}/src | ||
) | ||
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME}) | ||
endfunction() | ||
|
||
if (WARN IN_LIST IONE_FLAGS) | ||
include(ione_warn_test) | ||
message("IOneRing/test warnings: ${IONE_WARN}") | ||
endif () | ||
|
||
if (IONE_TEST STREQUAL "SINGLE") | ||
list(TRANSFORM IONE_TEST_SOURCES APPEND .cpp) | ||
add_executable(ione_test test.cpp ${IONE_TEST_SOURCES}) | ||
ione_add_test(ione_test) | ||
else () | ||
foreach (TEST_SOURCE ${IONE_TEST_SOURCES}) | ||
string(REPLACE "/" "_" TEST_NAME ${TEST_SOURCE}) | ||
add_executable(${TEST_NAME} test.cpp ${TEST_SOURCE}.cpp) | ||
ione_add_test(${TEST_NAME}) | ||
endforeach () | ||
endif () | ||
|
||
unset(IONE_TEST_SOURCES) |
Oops, something went wrong.