base: Extend gem5_assert to subsume chatty_assert.
If given more than just its condition, gem5_assert will assume it should act like chatty_assert. Because we have our own custom assert now anyway, we can fold the behavior of both into one macro and make life easier for users. Deprecate chatty_assert. Change-Id: I43497b5333802a265c0ad096681f64ab6f0424b1 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/48606 Maintainer: Gabe Black <gabe.black@gmail.com> Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu> Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
#include "base/compiler.hh"
|
||||
@@ -288,26 +289,18 @@ class Logger
|
||||
#define NDEBUG_DEFINED 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The chatty assert macro will function like a normal assert, but will allow
|
||||
* the specification of additional, helpful material to aid debugging why the
|
||||
* assertion actually failed. chatty_assert will not actually check its
|
||||
* condition for fast builds, but the condition must still be valid code.
|
||||
*
|
||||
* @param cond Condition that is checked; if false -> assert
|
||||
* @param ... Printf-based format string with arguments, extends printout.
|
||||
*
|
||||
* \def chatty_assert(cond, ...)
|
||||
*
|
||||
* @ingroup api_logger
|
||||
*/
|
||||
#define chatty_assert(cond, ...) \
|
||||
do { \
|
||||
if (GEM5_UNLIKELY(!NDEBUG_DEFINED && !static_cast<bool>(cond))) \
|
||||
panic("assert(" # cond ") failed: %s", \
|
||||
::gem5::csprintf(__VA_ARGS__)); \
|
||||
} while (0)
|
||||
/** @} */ // end of api_logger
|
||||
template <typename ...Args>
|
||||
inline std::string
|
||||
_assertMsg(const std::string &format, Args... args)
|
||||
{
|
||||
return std::string(": ") + csprintf(format, args...);
|
||||
}
|
||||
|
||||
inline const char *
|
||||
_assertMsg()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* The assert macro will function like a normal assert, but will use panic
|
||||
@@ -316,17 +309,25 @@ class Logger
|
||||
* condition in fast builds, but it must still be valid code.
|
||||
*
|
||||
* @param cond Condition that is checked; if false -> panic
|
||||
* @param ... Printf-based format string with arguments, extends printout.
|
||||
*
|
||||
* \def gem5_assert(cond)
|
||||
* \def gem5_assert(cond, ...)
|
||||
*
|
||||
* @ingroup api_logger
|
||||
*/
|
||||
#define gem5_assert(cond) \
|
||||
#define gem5_assert(cond, ...) \
|
||||
do { \
|
||||
if (GEM5_UNLIKELY(!NDEBUG_DEFINED && !static_cast<bool>(cond))) \
|
||||
panic("assert(" # cond ") failed"); \
|
||||
if (GEM5_UNLIKELY(!NDEBUG_DEFINED && !static_cast<bool>(cond))) { \
|
||||
panic("assert(" #cond ") failed%s", _assertMsg(__VA_ARGS__)); \
|
||||
} \
|
||||
} while (0)
|
||||
/** @} */ // end of api_logger
|
||||
|
||||
#define chatty_assert(...) \
|
||||
do { \
|
||||
gem5_assert(__VA_ARGS__); \
|
||||
GEM5_DEPRECATED_MACRO(chatty_assert, {}, "Please use gem5_assert()"); \
|
||||
} while(0)
|
||||
|
||||
} // namespace gem5
|
||||
#endif // __BASE_LOGGING_HH__
|
||||
|
||||
@@ -543,18 +543,6 @@ TEST(LoggingDeathTest, FatalIf)
|
||||
"fatal: fatal condition true occurred: message\nMemory Usage:"));
|
||||
}
|
||||
|
||||
/** Test macro chatty_assert. */
|
||||
TEST(LoggingDeathTest, ChattyAssert)
|
||||
{
|
||||
#ifdef NDEBUG
|
||||
GTEST_SKIP() << "Skipping as assertions are "
|
||||
"stripped out of fast builds";
|
||||
#endif
|
||||
chatty_assert(true, "message\n");
|
||||
ASSERT_DEATH(chatty_assert(false, "message\n"), ::testing::HasSubstr(
|
||||
"panic: assert(false) failed: message\nMemory Usage:"));
|
||||
}
|
||||
|
||||
/** Test macro gem5_assert. */
|
||||
TEST(LoggingDeathTest, gem5Assert)
|
||||
{
|
||||
@@ -562,6 +550,9 @@ TEST(LoggingDeathTest, gem5Assert)
|
||||
GTEST_SKIP() << "Skipping as assertions are "
|
||||
"stripped out of fast builds";
|
||||
#endif
|
||||
gem5_assert(true, "message\n");
|
||||
ASSERT_DEATH(gem5_assert(false, "message\n"), ::testing::HasSubstr(
|
||||
"panic: assert(false) failed: message\nMemory Usage:"));
|
||||
gem5_assert(true);
|
||||
ASSERT_DEATH(gem5_assert(false), ::testing::HasSubstr(
|
||||
"panic: assert(false) failed\nMemory Usage:"));
|
||||
|
||||
Reference in New Issue
Block a user