From 5b9a483e0594af8d931ff216907b206396dd58d8 Mon Sep 17 00:00:00 2001 From: Igor Krivenko Date: Wed, 24 Jan 2024 13:04:46 +0100 Subject: [PATCH] Debugging SEGFAULT in `expression` unit test --- .github/workflows/build-test-deploy.yml | 82 ++++++------ include/libcommute/expression/expression.hpp | 5 +- test/CMakeLists.txt | 128 +++++++++---------- test/catch2/catch.hpp | 28 ++-- test/catch2/catch2-main.cpp | 27 +++- 5 files changed, 148 insertions(+), 122 deletions(-) diff --git a/.github/workflows/build-test-deploy.yml b/.github/workflows/build-test-deploy.yml index ec2724b9..0cd7d292 100644 --- a/.github/workflows/build-test-deploy.yml +++ b/.github/workflows/build-test-deploy.yml @@ -5,6 +5,7 @@ on: branches: - master - ci + - debug pull_request: branches: - master @@ -13,73 +14,66 @@ jobs: build-test-deploy: strategy: matrix: - os: [ubuntu-20.04, macos-11] + os: [macos-13] cxx_compiler: - - { name: "gcc", cxx: "g++-10" } - { name: "clang", cxx: "clang++" } runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - - name: Install Eigen 3 - run: | - if [[ "${{ matrix.os }}" == ubuntu-* ]]; then - sudo apt-get update -q - sudo apt-get install libeigen3-dev - else - brew update - brew install eigen - fi + #- name: Install Eigen 3 + # run: | + # if [[ "${{ matrix.os }}" == ubuntu-* ]]; then + # sudo apt-get update -q + # sudo apt-get install libeigen3-dev + # else + # brew update + # brew install eigen + # fi - - name: Set up Python 3.8 - if: startsWith(matrix.cxx_compiler.name, 'clang') - uses: actions/setup-python@v4 - with: - python-version: 3.8 + #- name: Set up Python 3.8 + # if: startsWith(matrix.cxx_compiler.name, 'clang') + # uses: actions/setup-python@v4 + # with: + # python-version: 3.8 - - name: Install cppcheck - if: startsWith(matrix.os, 'ubuntu') - run: sudo apt-get install cppcheck + #- name: Install cppcheck + # if: startsWith(matrix.os, 'ubuntu') + # run: sudo apt-get install cppcheck - - name: Install Sphinx and Read the Docs Sphinx Theme - if: startsWith(matrix.cxx_compiler.name, 'clang') - run: | - python -m pip install --upgrade pip - pip install sphinx sphinx-rtd-theme myst-parser + #- name: Install Sphinx and Read the Docs Sphinx Theme + # if: startsWith(matrix.cxx_compiler.name, 'clang') + # run: | + # python -m pip install --upgrade pip + # pip install sphinx sphinx-rtd-theme myst-parser + + #- name: Install Clang + # run: | + # brew update + # brew install llvm@16 - name: Build libcommute run: | mkdir installed mkdir build && cd build - if [[ "${{ matrix.os }}" == ubuntu* ]]; then - STATIC_ANALYSIS=ON - else - STATIC_ANALYSIS=OFF - fi - - if [[ "${{ matrix.cxx_compiler.name }}" == clang* ]]; then - DOCS=ON - else - DOCS=OFF - fi CXX="${{ matrix.cxx_compiler.cxx }}" cmake .. \ - -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/installed \ -DSTATIC_ANALYSIS=${STATIC_ANALYSIS} \ -DTESTS=ON \ - -DEXAMPLES=ON \ - -DDOCUMENTATION=${DOCS} - make -j3 + -DEXAMPLES=OFF \ + -DDOCUMENTATION=OFF + make VERBOSE=1 -j3 - name: Test libcommute run: | cd ${GITHUB_WORKSPACE}/build - CTEST_OUTPUT_ON_FAILURE=1 make test - - name: Install libcommute - run: | - cd ${GITHUB_WORKSPACE}/build - make install + ctest --output-on-failure + #- name: Install libcommute + # run: | + # cd ${GITHUB_WORKSPACE}/build + # make install - name: Deploy documentation if: | diff --git a/include/libcommute/expression/expression.hpp b/include/libcommute/expression/expression.hpp index ba33faf7..14366321 100644 --- a/include/libcommute/expression/expression.hpp +++ b/include/libcommute/expression/expression.hpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -947,7 +948,7 @@ class expression::const_iterator { // Increments const_iterator& operator++() { - ++m_it_; + std::advance(m_it_, 1); return *this; } const_iterator operator++(int) { @@ -958,7 +959,7 @@ class expression::const_iterator { // Decrements const_iterator& operator--() { - --m_it_; + std::advance(m_it_, -1); return *this; } const_iterator operator--(int) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 17df427e..cfd096a2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -20,38 +20,38 @@ endif(STATIC_ANALYSIS) include_directories(BEFORE SYSTEM catch2) set(TESTS - utility - metafunctions - generator - monomial - scalar_traits - factories + #utility + #metafunctions + #generator + #monomial + #scalar_traits + #factories expression - expression.addition - expression.subtraction - expression.multiplication - expression.const.addition - expression.const.subtraction - expression.const.multiplication - expression.mixed_arithmetics - hc - commutators - new_algebra - state_vector - elementary_space - hilbert_space - monomial_action - monomial_action_fermion - monomial_action_boson - monomial_action_spin - loperator - new_algebra.loperator - disjoint_sets - sparse_state_vector - space_partition - mapped_basis_view - n_fermion_sector_view - n_fermion_multisector_view + #expression.addition + #expression.subtraction + #expression.multiplication + #expression.const.addition + #expression.const.subtraction + #expression.const.multiplication + #expression.mixed_arithmetics + #hc + #commutators + #new_algebra + #state_vector + #elementary_space + #hilbert_space + #monomial_action + #monomial_action_fermion + #monomial_action_boson + #monomial_action_spin + #loperator + #new_algebra.loperator + #disjoint_sets + #sparse_state_vector + #space_partition + #mapped_basis_view + #n_fermion_sector_view + #n_fermion_multisector_view ) # Build C++ unit tests @@ -62,36 +62,36 @@ foreach(t ${TESTS}) add_test(NAME ${t} COMMAND ${t}) endforeach() -set(CXX17_TESTS - dyn_indices - generator_dyn - factories_dyn - elementary_space_dyn -) - -# C++17 tests -if("cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES) - message(STATUS "Enabling C++17 tests") - foreach(t ${CXX17_TESTS}) - set(s ${CMAKE_CURRENT_SOURCE_DIR}/${t}.cpp) - add_executable(${t} ${s}) - target_compile_features(${t} PRIVATE cxx_std_17) - target_link_libraries(${t} PRIVATE libcommute catch2) - add_test(NAME ${t} COMMAND ${t}) - endforeach() -else() - message(STATUS "Disabling C++17 tests") -endif() - -# Tests using Eigen 3 -if(Eigen3_FOUND) - message(STATUS "Enabling Eigen 3 tests") - set(EIGEN3_TESTS state_vector_eigen3) - foreach(t ${EIGEN3_TESTS}) - set(s ${CMAKE_CURRENT_SOURCE_DIR}/${t}.cpp) - add_executable(${t} ${s}) - target_link_libraries(${t} PRIVATE libcommute catch2) - link_to_eigen3(${t}) - add_test(NAME ${t} COMMAND ${t}) - endforeach() -endif(Eigen3_FOUND) +#set(CXX17_TESTS +# dyn_indices +# generator_dyn +# factories_dyn +# elementary_space_dyn +#) +# +## C++17 tests +#if("cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES) +# message(STATUS "Enabling C++17 tests") +# foreach(t ${CXX17_TESTS}) +# set(s ${CMAKE_CURRENT_SOURCE_DIR}/${t}.cpp) +# add_executable(${t} ${s}) +# target_compile_features(${t} PRIVATE cxx_std_17) +# target_link_libraries(${t} PRIVATE libcommute catch2) +# add_test(NAME ${t} COMMAND ${t}) +# endforeach() +#else() +# message(STATUS "Disabling C++17 tests") +#endif() +# +## Tests using Eigen 3 +#if(Eigen3_FOUND) +# message(STATUS "Enabling Eigen 3 tests") +# set(EIGEN3_TESTS state_vector_eigen3) +# foreach(t ${EIGEN3_TESTS}) +# set(s ${CMAKE_CURRENT_SOURCE_DIR}/${t}.cpp) +# add_executable(${t} ${s}) +# target_link_libraries(${t} PRIVATE libcommute catch2) +# link_to_eigen3(${t}) +# add_test(NAME ${t} COMMAND ${t}) +# endforeach() +#endif(Eigen3_FOUND) diff --git a/test/catch2/catch.hpp b/test/catch2/catch.hpp index d2a12427..9b309bdd 100644 --- a/test/catch2/catch.hpp +++ b/test/catch2/catch.hpp @@ -1,6 +1,6 @@ /* - * Catch v2.13.9 - * Generated: 2022-04-12 22:37:23.260201 + * Catch v2.13.10 + * Generated: 2022-10-16 11:01:23.452308 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly * Copyright (c) 2022 Two Blue Cubes Ltd. All rights reserved. @@ -15,7 +15,7 @@ #define CATCH_VERSION_MAJOR 2 #define CATCH_VERSION_MINOR 13 -#define CATCH_VERSION_PATCH 9 +#define CATCH_VERSION_PATCH 10 #ifdef __clang__ # pragma clang system_header @@ -7395,8 +7395,6 @@ namespace Catch { template struct ObjectStorage { - using TStorage = typename std::aligned_storage::value>::type; - ObjectStorage() : data() {} ObjectStorage(const ObjectStorage& other) @@ -7439,7 +7437,7 @@ namespace Catch { return *static_cast(static_cast(&data)); } - TStorage data; + struct { alignas(T) unsigned char data[sizeof(T)]; } data; }; } @@ -7949,7 +7947,7 @@ namespace Catch { #if defined(__i386__) || defined(__x86_64__) #define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */ #elif defined(__aarch64__) - #define CATCH_TRAP() __asm__(".inst 0xd4200000") + #define CATCH_TRAP() __asm__(".inst 0xd43e0000") #endif #elif defined(CATCH_PLATFORM_IPHONE) @@ -13558,7 +13556,7 @@ namespace Catch { // Handle list request if( Option listed = list( m_config ) ) - return static_cast( *listed ); + return (std::min) (MaxExitCode, static_cast(*listed)); TestGroup tests { m_config }; auto const totals = tests.execute(); @@ -15391,7 +15389,7 @@ namespace Catch { } Version const& libraryVersion() { - static Version version( 2, 13, 9, "", 0 ); + static Version version( 2, 13, 10, "", 0 ); return version; } @@ -17526,12 +17524,20 @@ namespace Catch { #ifndef __OBJC__ +#ifndef CATCH_INTERNAL_CDECL +#ifdef _MSC_VER +#define CATCH_INTERNAL_CDECL __cdecl +#else +#define CATCH_INTERNAL_CDECL +#endif +#endif + #if defined(CATCH_CONFIG_WCHAR) && defined(CATCH_PLATFORM_WINDOWS) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN) // Standard C/C++ Win32 Unicode wmain entry point -extern "C" int wmain (int argc, wchar_t * argv[], wchar_t * []) { +extern "C" int CATCH_INTERNAL_CDECL wmain (int argc, wchar_t * argv[], wchar_t * []) { #else // Standard C/C++ main entry point -int main (int argc, char * argv[]) { +int CATCH_INTERNAL_CDECL main (int argc, char * argv[]) { #endif return Catch::Session().run( argc, argv ); diff --git a/test/catch2/catch2-main.cpp b/test/catch2/catch2-main.cpp index dac62817..01ea365d 100644 --- a/test/catch2/catch2-main.cpp +++ b/test/catch2/catch2-main.cpp @@ -11,5 +11,30 @@ * ******************************************************************************/ -#define CATCH_CONFIG_MAIN +#include +#include +#include +#include +#include + +#define CATCH_CONFIG_RUNNER #include + +void handler(int sig) { + void *array[10]; + size_t size; + + // get void*'s for all entries on the stack + size = backtrace(array, 10); + + // print out all the frames to stderr + fprintf(stderr, "Error: signal %d:\n", sig); + backtrace_symbols_fd(array, size, STDERR_FILENO); + exit(1); +} + +int main( int argc, char* argv[] ) { + signal(SIGSEGV, handler); // install our handler + int result = Catch::Session().run( argc, argv ); + return result; +}