Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Enable standard library assertions in debug builds #3759

Merged
merged 12 commits into from
Dec 11, 2024
13 changes: 9 additions & 4 deletions Core/include/Acts/EventData/detail/GenerateParameters.hpp
benjaminhuth marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,24 @@ template <typename generator_t>
inline std::pair<double, double> generateBoundDirection(
generator_t& rng, const GenerateBoundDirectionOptions& options) {
using UniformReal = std::uniform_real_distribution<double>;
assert(options.thetaMin >= 0.f);
assert(options.thetaMax <= std::numbers::pi);
assert(options.thetaMin <= options.thetaMax);

// since we want to draw the direction uniform on the unit sphere, we must
// draw from cos(theta) instead of theta. see e.g.
// https://mathworld.wolfram.com/SpherePointPicking.html
double cosThetaMin = std::cos(options.thetaMin);
// Get cosThetaMin from thetaMax and vice versa, because cos is
// monothonical decreasing between [0, pi]
double cosThetaMin = std::cos(options.thetaMax);
// ensure upper bound is included. see e.g.
// https://en.cppreference.com/w/cpp/numeric/random/uniform_real_distribution
double cosThetaMax = std::nextafter(std::cos(options.thetaMax),
double cosThetaMax = std::nextafter(std::cos(options.thetaMin),
std::numeric_limits<double>::max());

// in case we force uniform eta generation
double etaMin = Acts::AngleHelpers::etaFromTheta(options.thetaMin);
double etaMax = Acts::AngleHelpers::etaFromTheta(options.thetaMax);
double etaMin = Acts::AngleHelpers::etaFromTheta(options.thetaMax);
double etaMax = Acts::AngleHelpers::etaFromTheta(options.thetaMin);

UniformReal phiDist(options.phiMin, options.phiMax);
UniformReal cosThetaDist(cosThetaMin, cosThetaMax);
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Visualization/ObjVisualization3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void ObjVisualization3D::faces(const std::vector<Vector3>& vtxs,
o.vertices.insert(o.vertices.end(), vtxs.begin(), vtxs.end());
for (const auto& face : faces) {
if (face.size() == 2) {
o.lines.push_back({face[0] + vtxoffs, face[2] + vtxoffs});
o.lines.push_back({face[0] + vtxoffs, face[1] + vtxoffs});
} else {
FaceType rawFace;
std::ranges::transform(
Expand Down
7 changes: 7 additions & 0 deletions Plugins/Json/src/DetrayJsonHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

// For whatever reason, this compilation unit does not compile
// with those assertions and GCC 13. For now just disable the
// flags in this case.
#if defined(_GLIBCXX_ASSERTIONS) && __GNUC__ == 13
#undef _GLIBCXX_ASSERTIONS
#endif

#include "Acts/Plugins/Json/DetrayJsonHelper.hpp"

namespace Acts::DetrayJsonHelper {
Expand Down
6 changes: 3 additions & 3 deletions Tests/UnitTests/Core/Geometry/CylinderVolumeBuilderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ BOOST_DATA_TEST_CASE(
CylinderVolumeBuilder_wraps,
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution =
std::uniform_real_distribution<double>(-11., -15.))) ^
std::uniform_real_distribution<double>(-15., -11.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution =
std::uniform_real_distribution<double>(11., 15.))) ^
Expand Down Expand Up @@ -114,7 +114,7 @@ BOOST_DATA_TEST_CASE(
CylinderVolumeBuilder_containes,
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution =
std::uniform_real_distribution<double>(-11., -15.))) ^
std::uniform_real_distribution<double>(-15., -11.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution =
std::uniform_real_distribution<double>(11., 15.))) ^
Expand Down Expand Up @@ -285,7 +285,7 @@ BOOST_DATA_TEST_CASE(
CylinderVolumeBuilder_overlapsInZ,
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 1,
bdata::distribution =
std::uniform_real_distribution<double>(-11., -15.))) ^
std::uniform_real_distribution<double>(-15., -11.))) ^
bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
bdata::distribution =
std::uniform_real_distribution<double>(11., 15.))) ^
Expand Down
11 changes: 3 additions & 8 deletions Tests/UnitTests/Core/Utilities/AlgebraHelpersTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,15 @@ BOOST_AUTO_TEST_CASE(SafeInverseFPESmallMatrix) {
m(1, 1) = 1;

auto mInv = Acts::safeInverse(m);
BOOST_REQUIRE(mInv.has_value());
auto mInvInv = Acts::safeInverse(*mInv);

BOOST_CHECK(mInv);
BOOST_CHECK(!mInvInv);

ACTS_VERBOSE("Test: SafeInverseFPESmallMatrix" << "\n"
<< "m:\n"
<< m << "\n"
<< "mInv:\n"
<< *mInv << "\n"
<< "mInvInv [garbage]:\n"
<< *mInvInv);
<< *mInv);
}

BOOST_AUTO_TEST_CASE(SafeInverseFPELargeMatrix) {
Expand All @@ -107,9 +104,7 @@ BOOST_AUTO_TEST_CASE(SafeInverseFPELargeMatrix) {

ACTS_VERBOSE("Test: SafeInverseFPELargeMatrix" << "\n"
<< "m:\n"
<< m << "\n"
<< "mInv [garbage]:\n"
<< *mInv);
<< m);
}

/// This test should not compile
Expand Down
5 changes: 5 additions & 0 deletions cmake/ActsCompilerOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ set(cxx_flags
"-Wall -Wextra -Wpedantic -Wshadow -Wzero-as-null-pointer-constant -Wold-style-cast"
)

# Add assertions to standard libraries
if(ACTS_FORCE_ASSERTIONS)
set(cxx_flags "${cxx_flags} -D_GLIBCXX_ASSERTIONS -D_LIBCPP_DEBUG")
benjaminhuth marked this conversation as resolved.
Show resolved Hide resolved
endif()

# This adds some useful conversion checks like float-to-bool, float-to-int, etc.
# However, at the moment this is only added to clang builds, since GCC's -Wfloat-conversion
# is much more aggressive and also triggers on e.g., double-to-float
Expand Down
Loading