Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ The Axom project release numbers follow [Semantic Versioning](http://semver.org/

## [Unreleased] - Release date yyyy-mm-dd

### Added
- Slic: Adds the `AXOM_ENABLE_SLIC_DEBUG_MACROS` CMake option to enable the
`SLIC_ASSERT`, `SLIC_CHECK`, and `SLIC_DEBUG` macro families independently of
`AXOM_DEBUG`.

## [Version 0.15.0] - Release date 2026-08-28

### Added
Expand Down
6 changes: 6 additions & 0 deletions src/axom/slic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ axom_add_library(NAME slic
FOLDER axom/slic
)

if(AXOM_ENABLE_SLIC_DEBUG_MACROS)
blt_add_target_definitions(TO slic
SCOPE PUBLIC
TARGET_DEFINITIONS AXOM_ENABLE_SLIC_DEBUG_MACROS)
endif()

axom_write_unified_header( NAME slic
HEADERS ${slic_headers}
)
Expand Down
30 changes: 22 additions & 8 deletions src/axom/slic/docs/sphinx/sections/wrapping_slic_in_macros.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ operations when certain flags are toggled on or functions are called. Other macr
such as ``SLIC_ERROR`` and ``SLIC_ASSERT`` can be made not collective when certain
functions are called.

The ``SLIC_ASSERT``, ``SLIC_CHECK``, and ``SLIC_DEBUG`` families are active
when the ``AXOM_DEBUG_DEFINE`` CMake setting enables ``AXOM_DEBUG``. The
default value, ``AXOM_DEBUG_DEFINE=DEFAULT``, enables them in ``Debug`` and
``RelWithDebInfo`` configurations. Set ``AXOM_DEBUG_DEFINE=ON`` to enable
``AXOM_DEBUG`` in every configuration or ``AXOM_DEBUG_DEFINE=OFF`` to disable
it in every configuration. These Slic macro families can also be enabled
independently of ``AXOM_DEBUG`` by configuring Axom with
``-DAXOM_ENABLE_SLIC_DEBUG_MACROS=ON``.

The table below details the built-in SLIC macros as well as some notes about when they are collective calls:

.. list-table:: SLIC macro availability and collective behavior
Expand All @@ -121,15 +130,17 @@ The table below details the built-in SLIC macros as well as some notes about whe

* - ``SLIC_ASSERT``
``SLIC_ASSERT_MSG``
- - Only available in debug configurations (i.e. when ``AXOM_DEBUG`` is defined)
- - Available when enabled by ``AXOM_DEBUG_DEFINE`` or
``AXOM_ENABLE_SLIC_DEBUG_MACROS=ON``
- Not available in device code
- - Collective by default
- Collective after calling ``slic::enableAbortOnError()``
- No longer collective after calling ``slic::disableAbortOnError()``

* - ``SLIC_CHECK``
``SLIC_CHECK_MSG``
- - Only available in debug configurations (i.e. when ``AXOM_DEBUG`` is defined)
- - Available when enabled by ``AXOM_DEBUG_DEFINE`` or
``AXOM_ENABLE_SLIC_DEBUG_MACROS=ON``
- Not available in device code
- - Not collective by default
- Collective after ``slic::debug::checksAreErrors`` is set to ``true``, defaults to ``false``
Expand All @@ -144,7 +155,8 @@ The table below details the built-in SLIC macros as well as some notes about whe
``SLIC_DEBUG_ROOT_ONCE``
``SLIC_DEBUG_ROOT_IF_ONCE``
``SLIC_DEBUG_PRINT_CONTAINER_ONCE``
- - Only available in debug configurations (i.e. when ``AXOM_DEBUG`` is defined)
- - Available when enabled by ``AXOM_DEBUG_DEFINE`` or
``AXOM_ENABLE_SLIC_DEBUG_MACROS=ON``
- - Never

* - ``SLIC_INFO``
Expand Down Expand Up @@ -186,13 +198,15 @@ Doxygen generated API documentation on Macros can be found here: `SLIC Macros <.

Consider the following rules of thumb when choosing from the above logging macros:

* The `SLIC_ABORT` and `SLIC_CHECK` macros are typically used to check preconditions/postconditions of functions
and help catch developer errors. They are only available in debug configurations (i.e. when `AXOM_DEBUG` is available).
* The `SLIC_ASSERT` and `SLIC_CHECK` macros are typically used to check preconditions/postconditions of functions
and help catch developer errors. They are available when enabled by
``AXOM_DEBUG_DEFINE`` or ``AXOM_ENABLE_SLIC_DEBUG_MACROS=ON``.
* `SLIC_WARNING` and `SLIC_ERROR` are available in all configurations and can be used to check for conditions that might affect the results.
They are also useful for validating user inputs.
* `SLIC_INFO` and `SLIC_DEBUG` macros are typically used to provide information about the state of an application.
The `SLIC_*_IF` variants can be used to conditionally log messages. `SLIC_DEBUG` macros are compiled out in non-debug configurations
(i.e. their messages will not get logged), while `SLIC_INFO` macros are always available.
* `SLIC_INFO` and `SLIC_DEBUG` macros are typically used to provide information about the state of an application.
The `SLIC_*_IF` variants can be used to conditionally log messages. `SLIC_DEBUG` macros are compiled out unless
enabled by ``AXOM_DEBUG_DEFINE`` or ``AXOM_ENABLE_SLIC_DEBUG_MACROS=ON``,
while `SLIC_INFO` macros are always available.
* The `SLIC_*_ROOT` variants can help reduce logging verbosity when called in an MPI application, especially if all
MPI ranks are expected to have the same data (for example, if a value was broadcast from one rank to all the other ranks).
* The `SLIC_*_ONCE` variants can help reduce logging verbosity when only the first invocation at a call-site is necessary.
Expand Down
64 changes: 46 additions & 18 deletions src/axom/slic/interface/slic_macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
///@}

// Use complete debug macros when not on device
#if defined(AXOM_DEBUG) && !defined(AXOM_DEVICE_CODE)
#if (defined(AXOM_DEBUG) || defined(AXOM_ENABLE_SLIC_DEBUG_MACROS)) && !defined(AXOM_DEVICE_CODE)

//-----------------------------------------------------------------------------
/// @{
Expand All @@ -324,7 +324,9 @@
* \param [in] EXP user-supplied boolean expression.
*
* \warning This macro calls processAbort() iff EXP is false.
* \note This macro is only active when AXOM_DEBUG is defined.
* \note This macro is active when the AXOM_DEBUG_DEFINE CMake setting enables
* AXOM_DEBUG (by default in Debug and RelWithDebInfo builds), or when
* AXOM_ENABLE_SLIC_DEBUG_MACROS=ON.
*
* Usage:
* \code
Expand All @@ -342,7 +344,9 @@
* \param [in] msg user-supplied message
*
* \warning This macro calls processAbort() iff EXP is false.
* \note This macro is only active when AXOM_DEBUG is defined.
* \note This macro is active when the AXOM_DEBUG_DEFINE CMake setting enables
* AXOM_DEBUG (by default in Debug and RelWithDebInfo builds), or when
* AXOM_ENABLE_SLIC_DEBUG_MACROS=ON.
* \see SLIC_ASSERT( EXP )
*
* Usage:
Expand Down Expand Up @@ -399,7 +403,9 @@
* application is not aborted.
*
* \param [in] EXP user-supplied boolean expression.
* \note This macro is only active when AXOM_DEBUG is defined.
* \note This macro is active when the AXOM_DEBUG_DEFINE CMake setting enables
* AXOM_DEBUG (by default in Debug and RelWithDebInfo builds), or when
* AXOM_ENABLE_SLIC_DEBUG_MACROS=ON.
*
* Usage:
* \code
Expand All @@ -416,7 +422,9 @@
* \param [in] EXP user-supplied boolean expression.
* \param [in] msg user-supplied message
*
* \note This macro is only active when AXOM_DEBUG is defined.
* \note This macro is active when the AXOM_DEBUG_DEFINE CMake setting enables
* AXOM_DEBUG (by default in Debug and RelWithDebInfo builds), or when
* AXOM_ENABLE_SLIC_DEBUG_MACROS=ON.
* \see SLIC_DEBUG( EXP )
*
* Usage:
Expand Down Expand Up @@ -456,7 +464,7 @@
// Use assert when on device (note that messages are omitted).
// Device HIP assert() tested with rocm@6.1.2
// (ROCm support for device assert() begins with version 5.1.0).
#elif defined(AXOM_DEBUG) && defined(AXOM_DEVICE_CODE)
#elif (defined(AXOM_DEBUG) || defined(AXOM_ENABLE_SLIC_DEBUG_MACROS)) && defined(AXOM_DEVICE_CODE)
#define SLIC_ASSERT(EXP) assert(EXP)
#define SLIC_ASSERT_MSG(EXP, msg) assert(EXP)
#define SLIC_CHECK(EXP) assert(EXP)
Expand All @@ -469,7 +477,7 @@
#define SLIC_CHECK(ignore_EXP) ((void)0)
#define SLIC_CHECK_MSG(ignore_EXP, ignore_msg) ((void)0)

#endif /* END ifdef AXOM_DEBUG */
#endif /* END if debug macros are enabled */

/*!
* \def SLIC_INFO( msg )
Expand Down Expand Up @@ -662,15 +670,17 @@
#define SLIC_INFO_ROOT_IF_ONCE(EXP, msg) \
SLIC_DETAIL_LOG_IF_ONCE(SLIC_INFO_IF, (EXP) && (axom::slic::isRoot()), msg)

#ifdef AXOM_DEBUG
#if defined(AXOM_DEBUG) || defined(AXOM_ENABLE_SLIC_DEBUG_MACROS)

/*!
* \def SLIC_DEBUG( msg )
* \brief Logs a Debug message.
*
* \param [in] msg user-supplied message
*
* \note The SLIC_Debug macro is active when AXOM_DEBUG is defined.
* \note This macro is active when the AXOM_DEBUG_DEFINE CMake setting enables
* AXOM_DEBUG (by default in Debug and RelWithDebInfo builds), or when
* AXOM_ENABLE_SLIC_DEBUG_MACROS=ON.
*
* Usage:
* \code
Expand All @@ -686,7 +696,9 @@
*
* \param [in] msg user-supplied message
*
* \note The SLIC_DEBUG_ONCE macro is active when AXOM_DEBUG is defined.
* \note This macro is active when the AXOM_DEBUG_DEFINE CMake setting enables
* AXOM_DEBUG (by default in Debug and RelWithDebInfo builds), or when
* AXOM_ENABLE_SLIC_DEBUG_MACROS=ON.
*
* Usage:
* \code
Expand All @@ -703,7 +715,9 @@
* \param [in] EXP user-supplied boolean expression.
* \param [in] msg user-supplied message.
*
* \note The SLIC_DEBUG_IF macro is active when AXOM_DEBUG is defined.
* \note This macro is active when the AXOM_DEBUG_DEFINE CMake setting enables
* AXOM_DEBUG (by default in Debug and RelWithDebInfo builds), or when
* AXOM_ENABLE_SLIC_DEBUG_MACROS=ON.
*
* Usage:
* \code
Expand All @@ -729,7 +743,9 @@
* \param [in] EXP user-supplied boolean expression.
* \param [in] msg user-supplied message.
*
* \note The SLIC_DEBUG_IF_ONCE macro is active when AXOM_DEBUG is defined.
* \note This macro is active when the AXOM_DEBUG_DEFINE CMake setting enables
* AXOM_DEBUG (by default in Debug and RelWithDebInfo builds), or when
* AXOM_ENABLE_SLIC_DEBUG_MACROS=ON.
*
* Usage:
* \code
Expand All @@ -745,7 +761,9 @@
*
* \param [in] msg user-supplied message.
*
* \note The SLIC_DEBUG_ROOT macro is active when AXOM_DEBUG is defined.
* \note This macro is active when the AXOM_DEBUG_DEFINE CMake setting enables
* AXOM_DEBUG (by default in Debug and RelWithDebInfo builds), or when
* AXOM_ENABLE_SLIC_DEBUG_MACROS=ON.
*
* Usage:
* \code
Expand All @@ -761,7 +779,9 @@
*
* \param [in] msg user-supplied message.
*
* \note The SLIC_DEBUG_ROOT_ONCE macro is active when AXOM_DEBUG is defined.
* \note This macro is active when the AXOM_DEBUG_DEFINE CMake setting enables
* AXOM_DEBUG (by default in Debug and RelWithDebInfo builds), or when
* AXOM_ENABLE_SLIC_DEBUG_MACROS=ON.
*
* Usage:
* \code
Expand All @@ -779,7 +799,9 @@
* \param [in] EXP user-supplied boolean expression.
* \param [in] msg user-supplied message.
*
* \note The SLIC_DEBUG_ROOT_IF macro is active when AXOM_DEBUG is defined.
* \note This macro is active when the AXOM_DEBUG_DEFINE CMake setting enables
* AXOM_DEBUG (by default in Debug and RelWithDebInfo builds), or when
* AXOM_ENABLE_SLIC_DEBUG_MACROS=ON.
*
* Usage:
* \code
Expand All @@ -796,7 +818,9 @@
* \param [in] EXP user-supplied boolean expression.
* \param [in] msg user-supplied message.
*
* \note The SLIC_DEBUG_ROOT_IF_ONCE macro is active when AXOM_DEBUG is defined.
* \note This macro is active when the AXOM_DEBUG_DEFINE CMake setting enables
* AXOM_DEBUG (by default in Debug and RelWithDebInfo builds), or when
* AXOM_ENABLE_SLIC_DEBUG_MACROS=ON.
*
* Usage:
* \code
Expand All @@ -815,7 +839,9 @@
* \param [in] name The name of the container in the printed message.
* \param [in] container The container (array, vector, view).
*
* \note The SLIC_DEBUG_PRINT_CONTAINER macro is active when AXOM_DEBUG is defined.
* \note This macro is active when the AXOM_DEBUG_DEFINE CMake setting enables
* AXOM_DEBUG (by default in Debug and RelWithDebInfo builds), or when
* AXOM_ENABLE_SLIC_DEBUG_MACROS=ON.
*
* Usage:
* \code
Expand All @@ -840,7 +866,9 @@
* \param [in] name The name of the container in the printed message.
* \param [in] container The container (array, vector, view).
*
* \note The SLIC_DEBUG_PRINT_CONTAINER_ONCE macro is active when AXOM_DEBUG is defined.
* \note This macro is active when the AXOM_DEBUG_DEFINE CMake setting enables
* AXOM_DEBUG (by default in Debug and RelWithDebInfo builds), or when
* AXOM_ENABLE_SLIC_DEBUG_MACROS=ON.
*
* Usage:
* \code
Expand Down
1 change: 1 addition & 0 deletions src/axom/slic/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set(serial_slic_tests
slic_asserts.cpp
slic_fmt.cpp
slic_interface.cpp
slic_enable_debug_macros.cpp
slic_macros.cpp
slic_scoped_abort.cpp
slic_uninit.cpp )
Expand Down
12 changes: 6 additions & 6 deletions src/axom/slic/tests/slic_asserts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SetFixtureS : public ::testing::Test
public:
void SetUp()
{
#ifdef AXOM_DEBUG
#if defined(AXOM_DEBUG) || defined(AXOM_ENABLE_SLIC_DEBUG_MACROS)
EXPECT_DEATH_IF_SUPPORTED(SLIC_ASSERT_MSG(false, "Testing assert in fixture setup"), "");
#else
SLIC_WARNING("Testing warning in fixture setup");
Expand All @@ -83,7 +83,7 @@ class SetFixtureT : public ::testing::Test
public:
void TearDown()
{
#ifdef AXOM_DEBUG
#if defined(AXOM_DEBUG) || defined(AXOM_ENABLE_SLIC_DEBUG_MACROS)
EXPECT_DEATH_IF_SUPPORTED(SLIC_ASSERT_MSG(false, "Testing assert in fixture teardown"), "");
#else
SLIC_WARNING("Testing warning in fixture teardown");
Expand Down Expand Up @@ -115,7 +115,7 @@ class SetFixtureD : public ::testing::Test
TEST(slic_usage, in_test)
{
SLIC_ASSERT_MSG(true, "Testing SLIC assert (true) in test body");
#ifdef AXOM_DEBUG
#if defined(AXOM_DEBUG) || defined(AXOM_ENABLE_SLIC_DEBUG_MACROS)
EXPECT_DEATH_IF_SUPPORTED(SLIC_ASSERT_MSG(false, "Testing SLIC assert(false) in test body"), "")
<< "SLIC assert (false) from a test";
#else
Expand All @@ -128,7 +128,7 @@ TEST(slic_usage, in_test)

TEST(slic_usage, in_ctor)
{
#ifdef AXOM_DEBUG
#if defined(AXOM_DEBUG) || defined(AXOM_ENABLE_SLIC_DEBUG_MACROS)
EXPECT_DEATH_IF_SUPPORTED(AssertCtor(), "") << " SLIC assert from class .ctor ";
#else
AssertCtor();
Expand All @@ -138,7 +138,7 @@ TEST(slic_usage, in_ctor)
TEST(slic_usage, in_method)
{
AssertMethod am;
#ifdef AXOM_DEBUG
#if defined(AXOM_DEBUG) || defined(AXOM_ENABLE_SLIC_DEBUG_MACROS)
EXPECT_DEATH_IF_SUPPORTED(am.foo(), "") << " SLIC assert from class method ";
#else
am.foo();
Expand All @@ -147,7 +147,7 @@ TEST(slic_usage, in_method)

TEST(slic_usage, in_dtor)
{
#ifdef AXOM_DEBUG
#if defined(AXOM_DEBUG) || defined(AXOM_ENABLE_SLIC_DEBUG_MACROS)
EXPECT_DEATH_IF_SUPPORTED(AssertDtor(), "") << " SLIC assert from class .ctor ";
#else
AssertDtor();
Expand Down
36 changes: 36 additions & 0 deletions src/axom/slic/tests/slic_enable_debug_macros.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Lawrence Livermore National Security, LLC and other
// Axom Project Contributors. See top-level LICENSE and COPYRIGHT
// files for dates and other details.
//
// SPDX-License-Identifier: (BSD-3-Clause)

#include "axom/config.hpp"

// Exercise the Slic debug macro guard independently of AXOM_DEBUG.
#ifdef AXOM_DEBUG
#undef AXOM_DEBUG
#endif

#define AXOM_ENABLE_SLIC_DEBUG_MACROS 1

#include "axom/slic.hpp"

#include "gtest/gtest.h"

TEST(slic_enable_debug_macros, enabled_without_axom_debug)
{
axom::slic::SimpleLogger logger;
int evaluation_count = 0;

SLIC_ASSERT(++evaluation_count == 1);
SLIC_CHECK(++evaluation_count == 2);
SLIC_DEBUG(++evaluation_count);

EXPECT_EQ(evaluation_count, 3);
}

int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Loading