Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/48606 )

Change subject: base: Extend gem5_assert to subsume chatty_assert.
......................................................................

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 <[email protected]>
Maintainer: Bobby R. Bruce <[email protected]>
Reviewed-by: Bobby R. Bruce <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/base/logging.hh
M src/base/logging.test.cc
2 files changed, 28 insertions(+), 36 deletions(-)

Approvals:
  Bobby R. Bruce: Looks good to me, approved; Looks good to me, approved
  Gabe Black: Looks good to me, approved
  kokoro: Regressions pass




diff --git a/src/base/logging.hh b/src/base/logging.hh
index f2d2822..8949b0c 100644
--- a/src/base/logging.hh
+++ b/src/base/logging.hh
@@ -43,6 +43,7 @@

 #include <cassert>
 #include <sstream>
+#include <tuple>
 #include <utility>

 #include "base/compiler.hh"
@@ -288,26 +289,18 @@
 #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 @@
  * 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__
diff --git a/src/base/logging.test.cc b/src/base/logging.test.cc
index da80682..38cc605 100644
--- a/src/base/logging.test.cc
+++ b/src/base/logging.test.cc
@@ -543,18 +543,6 @@
         "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 @@
     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:"));

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/48606
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I43497b5333802a265c0ad096681f64ab6f0424b1
Gerrit-Change-Number: 48606
Gerrit-PatchSet: 5
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to