Skip to content

Commit

Permalink
Debugging SEGFAULT in expression unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
krivenko committed Jan 24, 2024
1 parent 5622fbc commit 5b9a483
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 122 deletions.
82 changes: 38 additions & 44 deletions .github/workflows/build-test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- master
- ci
- debug
pull_request:
branches:
- master
Expand All @@ -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: |
Expand Down
5 changes: 3 additions & 2 deletions include/libcommute/expression/expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <complex>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <tuple>
Expand Down Expand Up @@ -947,7 +948,7 @@ class expression<ScalarType, IndexTypes...>::const_iterator {

// Increments
const_iterator& operator++() {
++m_it_;
std::advance(m_it_, 1);
return *this;
}
const_iterator operator++(int) {
Expand All @@ -958,7 +959,7 @@ class expression<ScalarType, IndexTypes...>::const_iterator {

// Decrements
const_iterator& operator--() {
--m_it_;
std::advance(m_it_, -1);
return *this;
}
const_iterator operator--(int) {
Expand Down
128 changes: 64 additions & 64 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
28 changes: 17 additions & 11 deletions test/catch2/catch.hpp
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -7395,8 +7395,6 @@ namespace Catch {
template <typename T, bool Destruct>
struct ObjectStorage
{
using TStorage = typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type;

ObjectStorage() : data() {}

ObjectStorage(const ObjectStorage& other)
Expand Down Expand Up @@ -7439,7 +7437,7 @@ namespace Catch {
return *static_cast<T*>(static_cast<void*>(&data));
}

TStorage data;
struct { alignas(T) unsigned char data[sizeof(T)]; } data;
};
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -13558,7 +13556,7 @@ namespace Catch {

// Handle list request
if( Option<std::size_t> listed = list( m_config ) )
return static_cast<int>( *listed );
return (std::min) (MaxExitCode, static_cast<int>(*listed));

TestGroup tests { m_config };
auto const totals = tests.execute();
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 );
Expand Down
Loading

0 comments on commit 5b9a483

Please sign in to comment.