From 23f823b40c173aa78ea202977cb111c313b646bd Mon Sep 17 00:00:00 2001 From: Johan Mabille Date: Tue, 3 Sep 2024 15:23:31 +0200 Subject: [PATCH] Additional folders for refactoring --- .github/workflows/linux.yml | 29 ++++-- .github/workflows/osx.yml | 17 +++- .github/workflows/windows.yml | 27 ++++- CMakeLists.txt | 15 +++ include/sparrow_v01/utils/memory.hpp | 23 +++++ test_v01/CMakeLists.txt | 143 +++++++++++++++++++++++++++ test_v01/test_memory.cpp | 25 +++++ 7 files changed, 267 insertions(+), 12 deletions(-) create mode 100644 include/sparrow_v01/utils/memory.hpp create mode 100644 test_v01/CMakeLists.txt create mode 100644 test_v01/test_memory.cpp diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 318a0229..ecded9dd 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -18,14 +18,14 @@ jobs: fail-fast: false matrix: sys: - - {compiler: clang, version: '16', config-flags: '', stdlib: 'libstdc++-12', date-polyfill: 'ON' } + - {compiler: clang, version: '16', config-flags: '', stdlib: 'libstdc++-12', date-polyfill: 'ON', build_refactoring: 'ON' } # - {compiler: clang, version: '16', config-flags: '-DCMAKE_CXX_FLAGS=-stdlib=libc++', stdlib: 'libc++-17', date-polyfill: 'ON' } - - {compiler: clang, version: '17', config-flags: '', stdlib: 'libstdc++-12', date-polyfill: 'ON' } + - {compiler: clang, version: '17', config-flags: '', stdlib: 'libstdc++-12', date-polyfill: 'ON', build_refactoring: 'OFF' } # - {compiler: clang, version: '17', config-flags: '-DCMAKE_CXX_FLAGS=-stdlib=libc++', stdlib: 'libc++-17', date-polyfill: 'ON' } - - {compiler: gcc, version: '12', config-flags: '', date-polyfill: 'ON' } - - {compiler: gcc, version: '13', config-flags: '', date-polyfill: 'ON' } - - {compiler: gcc, version: '13', config-flags: '', date-polyfill: 'OFF' } + - {compiler: gcc, version: '12', config-flags: '', date-polyfill: 'ON', build_refactoring: 'OFF' } + - {compiler: gcc, version: '13', config-flags: '', date-polyfill: 'ON', build_refactoring: 'OFF' } + - {compiler: gcc, version: '13', config-flags: '', date-polyfill: 'OFF', build_refactoring: 'ON' } config: - { name: Debug } @@ -63,7 +63,7 @@ jobs: cache-downloads: true - name: Configure using CMake - run: cmake -G Ninja -Bbuild ${{matrix.sys.config-flags}} -DCMAKE_BUILD_TYPE:STRING=${{matrix.config.name}} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DUSE_DATE_POLYFILL=${{matrix.sys.date-polyfill}} -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON + run: cmake -G Ninja -Bbuild ${{matrix.sys.config-flags}} -DCMAKE_BUILD_TYPE:STRING=${{matrix.config.name}} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DUSE_DATE_POLYFILL=${{matrix.sys.date-polyfill}} -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON -DBUILD_REFACTORING=${{matrix.sys.build_refactoring}} - name: Install working-directory: build @@ -84,6 +84,23 @@ jobs: name: test_sparrow_lib_report_Linux_${{ matrix.sys.compiler }}_${{ matrix.sys.version }}_${{ matrix.sys.stdlib }}_${{ matrix.config.name }}_date-polyfill_${{ matrix.sys.date-polyfill}} path: '**/test_sparrow_lib_report.xml' + - name: Build refactoring + if: matrix.sys.build_refactoring == 'ON' + working-directory: build + run: cmake --build . --config ${{matrix.config.name}} --target test_sparrow_lib_v01 --parallel 8 + + - name: Run refactoring tests + if: matrix.sys.build_refactoring == 'ON' + working_directory: build + run: cmake --build . --config ${{matrix.config.name}} --target run_tests_with_junit_report_v01 + + - name: Upload refactoring test results + uses: actions/upload-artifact@v4 + if: matrix.sys.build_refactoring == 'ON' && (success() || failure()) + with: + name: test_sparrow_lib_report_Linux_v01_${{ matrix.sys.compiler }}_${{ matrix.sys.version }}_${{ matrix.sys.stdlib }}_${{ matrix.config.name }}_date-polyfill_${{ matrix.sys.date-polyfill}} + path: '**/test_sparrow_lib_report_v01.xml' + - name: Run all examples working-directory: build run: cmake --build . --config ${{matrix.config.name}} --target run_examples diff --git a/.github/workflows/osx.yml b/.github/workflows/osx.yml index ed84fb74..54d92f5d 100644 --- a/.github/workflows/osx.yml +++ b/.github/workflows/osx.yml @@ -58,7 +58,7 @@ jobs: echo "CMAKE_CXX_COMPILER=/usr/bin/clang++" >> $GITHUB_ENV - name: Configure using CMake - run: cmake -Bbuild -DCMAKE_BUILD_TYPE:STRING=${{matrix.config.name}} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON + run: cmake -Bbuild -DCMAKE_BUILD_TYPE:STRING=${{matrix.config.name}} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON -DBUILD_REFACTORING=ON - name: Install working-directory: build @@ -78,6 +78,21 @@ jobs: with: name: test_sparrow_lib_report_OSX_${{ matrix.os }}_${{ matrix.config.name }}_${{ matrix.compiler }} path: '**/test_sparrow_lib_report.xml' + + - name: Build refactoring + working-directory: build + run: cmake --build . --config ${{matrix.config.name}} --target test_sparrow_lib_v01 --parallel 8 + + - name: Run refactoring tests + working-directory: build + run: cmake --build . --config ${{matrix.config.name}} --target run_tests_with_junit_report_v01 + + - name: Upload refactoring test results + uses: actions/upload-artifact@v4 + if: success() || failure() + with: + name: test_sparrow_lib_report_OSX_v01_${{ matrix.os }}_${{ matrix.config.name }}_${{ matrix.compiler }} + path: '**/test_sparrow_lib_report_v01.xml' - name: Run all examples working-directory: build diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index e1962f3e..f54d7090 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -19,10 +19,10 @@ jobs: matrix: runs-on: [windows-latest] sys: - - { compiler: msvc, date-polyfill: 'ON' } - - { compiler: msvc, date-polyfill: 'OFF' } - - { compiler: clang, date-polyfill: 'ON', version: 17 } - - { compiler: clang, date-polyfill: 'OFF', version: 17 } + - { compiler: msvc, date-polyfill: 'ON', build_refactoring: 'OFF' } + - { compiler: msvc, date-polyfill: 'OFF', build_refactoring: 'ON' } + - { compiler: clang, date-polyfill: 'ON', version: 17, build_refactoring: 'OFF'} + - { compiler: clang, date-polyfill: 'OFF', version: 17, build_refactoring: 'ON' } config: - { name: Debug } - { name: Release } @@ -63,7 +63,7 @@ jobs: ninja - name: Configure using CMake - run: cmake -Bbuild -DCMAKE_BUILD_TYPE:STRING=${{matrix.config.name}} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON -DUSE_DATE_POLYFILL=${{matrix.sys.date-polyfill}} -G "${{matrix.build-system}}" + run: cmake -Bbuild -DCMAKE_BUILD_TYPE:STRING=${{matrix.config.name}} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON -DUSE_DATE_POLYFILL=${{matrix.sys.date-polyfill}} -DBUILD_REFACTORING=${{matrix.sys.build_refactoring}} -G "${{matrix.build-system}}" - name: Install working-directory: build @@ -84,6 +84,23 @@ jobs: name: test_sparrow_lib_report_Windows_${{ matrix.sys.compiler }}_${{ matrix.build-system }}_${{ matrix.config.name }}_date-polyfill_${{ matrix.sys.date-polyfill}} path: '**/test_sparrow_lib_report.xml' + - name: Build refactoring + if: matrix.sys.build_refactoring == 'ON' + working-directory: build + run: cmake --build . --config ${{matrix.config.name}} --target test_sparrow_lib_v01 --parallel 8 + + - name: Run refactoring tests + if: matrix.sys.build_refactoring == 'ON' + working-directory: build + run: cmake --build . --config ${{matrix.config.name}} --target run_tests_with_junit_report_v01 + + - name: Upload refactoring test results + uses: actions/upload-artifact@v4 + if: matrix.sys.build_refactoring == 'ON' && (success() || failure()) + with: + name: test_sparrow_lib_report_Windows_v01_${{ matrix.sys.compiler }}_${{ matrix.build-system }}_${{ matrix.config.name }}_date-polyfill_${{ matrix.sys.date-polyfill}} + path: '**/test_sparrow_lib_report_v01.xml' + - name: Run all examples working-directory: build run: cmake --build . --config ${{matrix.config.name}} --target run_examples diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a26d2e6..a2f8f669 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ OPTION(BUILD_TESTS "Build sparrow test suite" OFF) OPTION(BUILD_DOCS "Build sparrow documentation" OFF) OPTION(BUILD_EXAMPLES "Build sparrow examples" OFF) OPTION(USE_DATE_POLYFILL "Use date polyfill implementation" ON) +OPTION(BUILD_REFACTORING "Build the refactoring target" OFF) include(CheckCXXSymbolExists) @@ -138,6 +139,13 @@ set(SPARROW_HEADERS ${SPARROW_INCLUDE_DIR}/sparrow/details/3rdparty/float16_t.hpp ) +if (BUILD_REFACTORING) + set(SPARROW_V01_HEADERS + ${SPARROW_INCLUDE_DIR}/sparrow_v01/utils/memory.hpp + ) + list(APPEND SPARROW_HEADERS ${SPARROW_V01_HEADERS}) +endif () + add_library(sparrow INTERFACE ${SPARROW_HEADERS}) target_include_directories(sparrow INTERFACE @@ -153,6 +161,9 @@ target_compile_features(sparrow INTERFACE cxx_std_20) if (BUILD_TESTS) enable_testing() add_subdirectory(test) + if (BUILD_REFACTORING) + add_subdirectory(test_v01) + endif () endif () # Docs @@ -186,6 +197,10 @@ install(DIRECTORY ${SPARROW_INCLUDE_DIR}/sparrow DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PATTERN ".clang-*" EXCLUDE PATTERN "README.md" EXCLUDE) +if (BUILD_REFACTORING) + install(DIRECTORY ${SPARROW_INCLUDE_DIR}/sparrow_v01 + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +endif () set(SPARROW_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for sparrowConfig.cmake") diff --git a/include/sparrow_v01/utils/memory.hpp b/include/sparrow_v01/utils/memory.hpp new file mode 100644 index 00000000..7f8ccb3a --- /dev/null +++ b/include/sparrow_v01/utils/memory.hpp @@ -0,0 +1,23 @@ +// Copyright 2024 Man Group Operations Limited +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or mplied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +namespace sparrow +{ + inline int dummy() + { + return 0; + } +} diff --git a/test_v01/CMakeLists.txt b/test_v01/CMakeLists.txt new file mode 100644 index 00000000..689b6fb5 --- /dev/null +++ b/test_v01/CMakeLists.txt @@ -0,0 +1,143 @@ +# Copyright 2024 Man Group Operations Limited +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.8) + +enable_testing() + +if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + project(sparrow-test CXX) + find_package(sparrow REQUIRED CONFIG) + set(SPARROW_INCLUDE_DIR ${sparrow_INCLUDE_DIRS}) +endif() + +find_package(doctest REQUIRED) + +# find_package(Threads) +if(NOT CMAKE_BUILD_TYPE) + message(STATUS "Setting tests build type to Release") + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) +else() + message(STATUS "Tests build type is ${CMAKE_BUILD_TYPE}") +endif() + +set(SPARROW_V1_TESTS_SOURCES + ../test/main.cpp + ../test/better_junit_reporter.hpp + ../test/junit.hpp + ../test/junit.cpp + ../test/junit_xml_writer.hpp + test_memory.cpp +) +set(test_target_v01 "test_sparrow_lib_v01") +add_executable(${test_target_v01} ${SPARROW_V1_TESTS_SOURCES}) +target_link_libraries(${test_target_v01} + PRIVATE + sparrow doctest::doctest $<$:${SANITIZER_LINK_LIBRARIES}>) + +include(doctest) +doctest_discover_tests(${test_target_v01}) + +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set(compiles_options + /permissive- + /WX # treat warnings as errors + /W4 # Baseline reasonable warnings + /we4242 # 'identifier': conversion from 'type1' to 'type1', possible loss of data + /we4244 # conversion from 'type1' to 'type_2', possible loss of data + /we4254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data + /we4263 # 'function': member function does not override any base class virtual member function + /we4265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may not be destructed correctly + /we4287 # 'operator': unsigned/negative constant mismatch + /we4289 # nonstandard extension used: 'variable': loop control variable declared in the for-loop is used outside the for-loop scope + /we4296 # 'operator': expression is always 'boolean_value' + /we4311 # 'variable': pointer truncation from 'type1' to 'type2' + /we4545 # expression before comma evaluates to a function which is missing an argument list + /we4546 # function call before comma missing argument list + /we4547 # 'operator': operator before comma has no effect; expected operator with side-effect + /we4549 # 'operator': operator before comma has no effect; did you intend 'operator'? + /we4555 # expression has no effect; expected expression with side- effect + /we4619 # pragma warning: there is no warning number 'number' + /we4640 # Enable warning on thread un-safe static member initialization + /we4826 # Conversion from 'type1' to 'type_2' is sign-extended. This may cause unexpected runtime behavior. + /we4905 # wide string literal cast to 'LPSTR' + /we4906 # string literal cast to 'LPWSTR' + /we4928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied + /we5038 # data member 'member1' will be initialized after data member 'member2' + /Zc:__cplusplus) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(compiles_options + -pedantic # Warn on language extensions + -Wall # reasonable and standard + -Wcast-align # warn for potential performance problem casts + -Wconversion # warn on type conversions that may lose data + -Wdouble-promotion # warn if float is implicitly promoted to double + -Werror # treat warnings as errors + -Wextra + -Wformat=2 # warn on security issues around functions that format output (i.e., printf) + -Wimplicit-fallthrough # Warns when case statements fall-through. (Included with -Wextra in GCC, not in clang) + -Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist + -Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor. This helps catch hard to track down memory errors + -Wnull-dereference # warn if a null dereference is detected + -Wold-style-cast # warn for c-style casts + -Woverloaded-virtual # warn if you overload (not override) a virtual function + -Wpedantic # warn if non-standard C++ is used + -Wshadow # warn the user if a variable declaration shadows one from a parent context + -Wsign-conversion # warn on sign conversions + -Wunused # warn on anything being unused + $<$:-Wno-maybe-uninitialized> + $<$:-Wno-array-bounds> + $<$:-Wno-stringop-overread> + $<$:-Wduplicated-branches> # warn if if / else branches have duplicated code + $<$:-Wduplicated-cond> # warn if if / else chain has duplicated conditions + $<$:-Wlogical-op> # warn about logical operations being used where bitwise were probably wanted + $<$:-Wno-subobject-linkage> # suppress warnings about subobject linkage + $<$:-Wuseless-cast> # warn if you perform a cast to the same type + ) + target_compile_options(${test_target_v01} PRIVATE "-ftemplate-backtrace-limit=0") +endif() + +target_compile_options(${test_target_v01} + PRIVATE + ${compiles_options} + $<$:${SANITIZER_COMPILE_OPTIONS}> + ) +target_link_options(${test_target_v01} + PRIVATE + $<$:${SANITIZER_LINK_OPTIONS}>) +# We do not use non-standard C++ +set_target_properties(${test_target_v01} PROPERTIES CMAKE_CXX_EXTENSIONS OFF) +target_compile_features(${test_target_v01} PRIVATE cxx_std_20) + +add_custom_target(run_tests_v01 + COMMAND ${test_target_v01} + DEPENDS ${test_target_v01} + COMMENT "Running tests" + USES_TERMINAL +) + +set_target_properties(run_tests_v01 PROPERTIES FOLDER "Tests utilities") + +set(JUNIT_REPORT_FILE_V1 + ${CMAKE_CURRENT_BINARY_DIR}/test_sparrow_lib_report_v01.xml) + +add_custom_target(run_tests_with_junit_report_v01 + COMMAND ${test_target_v01} --reporters=better_junit + --out=${JUNIT_REPORT_FILE_V1} --no-path-filenames=true + DEPENDS ${test_target_v01} + COMMENT "Running tests with JUnit report saved to: ${JUNIT_REPORT_FILE_V1}" + USES_TERMINAL +) + +set_target_properties(run_tests_with_junit_report_v01 PROPERTIES FOLDER "Tests utilities") diff --git a/test_v01/test_memory.cpp b/test_v01/test_memory.cpp new file mode 100644 index 00000000..4c075eed --- /dev/null +++ b/test_v01/test_memory.cpp @@ -0,0 +1,25 @@ +// Copyright 2024 Man Group Operations Limited +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "sparrow_v01/utils/memory.hpp" + +#include "doctest/doctest.h" + +TEST_SUITE("memory_v01") +{ + TEST_CASE("dummy") + { + CHECK_EQ(sparrow::dummy(), 0); + } +}