From e26cfd6bda3e08619c50c654a39744011550a114 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sat, 19 Oct 2024 15:30:32 +0300 Subject: [PATCH] Added support for running tests in CMake. --- .github/workflows/ci.yml | 37 ++++++++++------- CMakeLists.txt | 7 +++- test/CMakeLists.txt | 76 ++++++++++++++++++++++++++++++++++ test/test_cmake/CMakeLists.txt | 21 ---------- test/test_cmake/main.cpp | 22 ---------- 5 files changed, 103 insertions(+), 60 deletions(-) create mode 100644 test/CMakeLists.txt delete mode 100644 test/test_cmake/CMakeLists.txt delete mode 100644 test/test_cmake/main.cpp diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ea608a1..84c35564 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -468,7 +468,7 @@ jobs: - name: CMake tests cmake_tests: 1 - os: ubuntu-20.04 + os: ubuntu-22.04 timeout-minutes: 30 runs-on: ${{matrix.os}} @@ -710,7 +710,7 @@ jobs: ./b2 "${B2_ARGS[@]}" "address-model=32" "cxxstd=${{matrix.cxxstd32}}" "libs/$LIBRARY/test" fi - - name: Run CMake tests + - name: Build CMake tests if: matrix.cmake_tests run: | if [ -n "${{matrix.macosx_version_min}}" ] @@ -719,12 +719,15 @@ jobs: fi cd boost-root mkdir __build_static__ && cd __build_static__ - cmake ../libs/$LIBRARY/test/test_cmake - cmake --build . --target boost_${LIBRARY}_cmake_self_test -j $BUILD_JOBS - cd .. - mkdir __build_shared__ && cd __build_shared__ - cmake -DBUILD_SHARED_LIBS=On ../libs/$LIBRARY/test/test_cmake - cmake --build . --target boost_${LIBRARY}_cmake_self_test -j $BUILD_JOBS + cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DBUILD_TESTING=ON .. + cmake --build . --target tests -j $BUILD_JOBS + + - name: Run CMake tests + if: matrix.cmake_tests + run: | + cd boost-root + cd __build_static__ + ctest --output-on-failure --no-tests=error -j $BUILD_JOBS windows: defaults: @@ -828,16 +831,18 @@ jobs: b2 %B2_ARGS% cxxstd=${{matrix.cxxstd32}} address-model=32 libs/%LIBRARY%/test ) - - name: Run CMake tests + - name: Build CMake tests if: matrix.cmake_tests run: | cd boost-root mkdir __build_static__ cd __build_static__ - cmake ../libs/%LIBRARY%/test/test_cmake - cmake --build . --target boost_%LIBRARY%_cmake_self_test -j %NUMBER_OF_PROCESSORS% - cd .. - mkdir __build_shared__ - cd __build_shared__ - cmake -DBUILD_SHARED_LIBS=On ../libs/%LIBRARY%/test/test_cmake - cmake --build . --target boost_%LIBRARY%_cmake_self_test -j %NUMBER_OF_PROCESSORS% + cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DBUILD_TESTING=ON .. + cmake --build . --config Release --target tests -j %NUMBER_OF_PROCESSORS% + + - name: Run CMake tests + if: matrix.cmake_tests + run: | + cd boost-root + cd __build_static__ + ctest --config Release --output-on-failure --no-tests=error -j %NUMBER_OF_PROCESSORS% diff --git a/CMakeLists.txt b/CMakeLists.txt index ddad2e0a..d9a945a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ # Copyright 2018 Mike Dev # Copyright 2019 Peter Dimov -# Copyright 2020-2023 Andrey Semashev +# Copyright 2020-2024 Andrey Semashev +# # Distributed under the Boost Software License, Version 1.0. # See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt @@ -138,3 +139,7 @@ endif() if (BOOST_ATOMIC_COMPILER_HAS_SSE41) target_compile_definitions(boost_atomic PRIVATE BOOST_ATOMIC_USE_SSE41) endif() + +if (BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") + add_subdirectory(test) +endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..d1ac8c91 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,76 @@ +# Copyright 2024 Andrey Semashev +# +# 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(BoostTest OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST) + +if (NOT HAVE_BOOST_TEST) + return() +endif() + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +set(BOOST_TEST_COMPILE_FEATURES + cxx_lambdas + cxx_static_assert + cxx_deleted_functions + cxx_defaulted_functions +) + +set(BOOST_TEST_LINK_LIBRARIES + Boost::atomic + Boost::config + Boost::core + Boost::type_traits +) + +if (WIN32) + set(BOOST_TEST_COMPILE_DEFINITIONS + "_CRT_SECURE_NO_WARNINGS" + "_CRT_SECURE_NO_DEPRECATE" + "BOOST_USE_WINDOWS_H" + ) + list(APPEND BOOST_TEST_LINK_LIBRARIES + Boost::winapi + ) + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + list(APPEND BOOST_TEST_LINK_LIBRARIES + kernel32 + ) + endif() +endif() + +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(BOOST_TEST_COMPILE_OPTIONS "-Wall" "-Wextra" "-Werror") +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set(BOOST_TEST_COMPILE_OPTIONS "/W4" "/WX") +endif() + +boost_test(TYPE run SOURCES atomic_api.cpp) +boost_test(TYPE run SOURCES atomic_ref_api.cpp) +boost_test(TYPE run SOURCES atomic_api.cpp COMPILE_DEFINITIONS BOOST_ATOMIC_FORCE_FALLBACK NAME fallback_atomic_api) +boost_test(TYPE run SOURCES atomic_ref_api.cpp COMPILE_DEFINITIONS BOOST_ATOMIC_FORCE_FALLBACK NAME fallback_atomic_ref_api) +boost_test(TYPE run SOURCES wait_api.cpp) +boost_test(TYPE run SOURCES wait_ref_api.cpp) +boost_test(TYPE run SOURCES wait_api.cpp COMPILE_DEFINITIONS BOOST_ATOMIC_FORCE_FALLBACK NAME fallback_wait_api) +boost_test(TYPE run SOURCES wait_ref_api.cpp COMPILE_DEFINITIONS BOOST_ATOMIC_FORCE_FALLBACK NAME fallback_wait_ref_api) +boost_test(TYPE run SOURCES wait_fuzz.cpp) +boost_test(TYPE run SOURCES wait_fuzz.cpp COMPILE_DEFINITIONS BOOST_ATOMIC_FORCE_FALLBACK NAME fallback_wait_fuzz) +boost_test(TYPE run SOURCES ipc_atomic_api.cpp) +boost_test(TYPE run SOURCES ipc_atomic_ref_api.cpp) +boost_test(TYPE run SOURCES ipc_wait_api.cpp) +boost_test(TYPE run SOURCES ipc_wait_ref_api.cpp) +boost_test(TYPE run SOURCES atomicity.cpp) +boost_test(TYPE run SOURCES atomicity_ref.cpp) +boost_test(TYPE run SOURCES ordering.cpp) +boost_test(TYPE run SOURCES ordering_ref.cpp) +boost_test(TYPE run SOURCES lockfree.cpp) + +unset(BOOST_TEST_COMPILE_OPTIONS) + +boost_test(TYPE compile-fail SOURCES cf_arith_void_ptr.cpp) +boost_test(TYPE compile-fail SOURCES cf_arith_func_ptr.cpp) +boost_test(TYPE compile-fail SOURCES cf_arith_mem_ptr.cpp) + +boost_test(TYPE compile SOURCES c_implicit_ctor.cpp) diff --git a/test/test_cmake/CMakeLists.txt b/test/test_cmake/CMakeLists.txt deleted file mode 100644 index ec343325..00000000 --- a/test/test_cmake/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2018 Mike Dev -# Copyright 2020 Andrey Semashev -# -# Distributed under the Boost Software License, Version 1.0. -# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt -# -# NOTE: This does NOT run the unit tests for Boost.Atomic. -# It only tests if the CMakeLists.txt file in its root works as expected - -cmake_minimum_required(VERSION 3.5) - -project(BoostAtomicCMakeSelfTest) - -# Use experimental superproject to pull library dependencies recursively -set(BOOST_ENABLE_CMAKE 1) -add_subdirectory(../../../.. "${CMAKE_CURRENT_BINARY_DIR}/boost_superproject") - -add_definitions(-DBOOST_ALL_NO_LIB) - -add_executable(boost_atomic_cmake_self_test main.cpp) -target_link_libraries(boost_atomic_cmake_self_test Boost::atomic) diff --git a/test/test_cmake/main.cpp b/test/test_cmake/main.cpp deleted file mode 100644 index 98d8453a..00000000 --- a/test/test_cmake/main.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2018 Mike Dev -// -// Distributed under the Boost Software License, Version 1.0. -// See accompanying file LICENSE_1_0.txt or copy at -// https://www.boost.org/LICENSE_1_0.txt) - -#include - -struct Dummy -{ - int x[128]; -}; - -int main() -{ - Dummy d = {}; - boost::atomic ad; - - // this operation requires functions from - // the compiled part of Boost.Atomic - ad = d; -}