Skip to content

Commit

Permalink
pw_assert: Update print_and_abort backend formatting
Browse files Browse the repository at this point in the history
Make print_and_abort's formatting more closely match pw_assert_basic.
Also, include the CRASH banner.

Change-Id: Ie9e367a7c3b79dcf18577754f902e9d8abaf2e26
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/177845
Pigweed-Auto-Submit: Wyatt Hepler <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
Reviewed-by: Armando Montanez <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
  • Loading branch information
255 authored and CQ Bot Account committed Oct 26, 2023
1 parent 1355e5b commit bd62666
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@
PW_ASSERT_PRINT_EXPRESSION("CHECK", \
arg_a_str " " comparison_op_str " " arg_b_str); \
fprintf(stderr, \
" EVALUATED CONDITION\n\n " arg_a_str " (=" type_fmt \
") " comparison_op_str " " arg_b_str " (=" type_fmt \
" \033[33mEVALUATED CONDITION\033[0m\n\n " arg_a_str \
" (=" type_fmt ") " comparison_op_str " " arg_b_str " (=" type_fmt \
")" \
".\n\n", \
arg_a_val, \
arg_b_val); \
_PW_ASSERT_PRINT_MESSAGE_AND_ABORT(__VA_ARGS__)

#define _PW_ASSERT_PRINT_MESSAGE_AND_ABORT(...) \
fprintf(stderr, " MESSAGE\n\n " __VA_ARGS__); \
fprintf(stderr, "\n\n"); \
fflush(stderr); \
#define _PW_ASSERT_PRINT_MESSAGE_AND_ABORT(...) \
fprintf(stderr, " \033[33mMESSAGE\033[0m\n\n " __VA_ARGS__); \
fprintf(stderr, "\n\n"); \
fflush(stderr); \
abort()
27 changes: 22 additions & 5 deletions pw_assert/public/pw_assert/internal/print_and_abort.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@
#define _PW_ASSERT_ABORT_FUNCTION __func__
#endif // __GNUC__

// clang-format off
#define _PW_ASSERT_CRASH_BANNER \
"\n" \
" ▄████▄ ██▀███ ▄▄▄ ██████ ██░ ██ \n" \
" ▒██▀ ▀█ ▓██ ▒ ██▒ ▒████▄ ▒██ ▒ ▓██░ ██▒\n" \
" ▒▓█ 💥 ▄ ▓██ ░▄█ ▒ ▒██ ▀█▄ ░ ▓██▄ ▒██▀▀██░\n" \
" ▒▓▓▄ ▄██▒ ▒██▀▀█▄ ░██▄▄▄▄██ ▒ ██▒ ░▓█ ░██ \n" \
" ▒ ▓███▀ ░ ░██▓ ▒██▒ ▓█ ▓██▒ ▒██████▒▒ ░▓█▒░██▓\n" \
" ░ ░▒ ▒ ░ ░ ▒▓ ░▒▓░ ▒▒ ▓▒█░ ▒ ▒▓▒ ▒ ░ ▒ ░░▒░▒\n" \
" ░ ▒ ░▒ ░ ▒░ ▒ ▒▒ ░ ░ ░▒ ░ ░ ▒ ░▒░ ░\n" \
" ░ ░░ ░ ░ ▒ ░ ░ ░ ░ ░░ ░\n" \
" ░ ░ ░ ░ ░ ░ ░ ░ ░\n" \
" ░\n" \
"\n"
// clang-format on

// This assert implementation prints the file path, line number, and assert
// expression using printf. Uses ANSI escape codes for colors.
//
Expand All @@ -39,19 +55,20 @@
fflush(stderr); \
abort()

#define PW_ASSERT_PRINT_EXPRESSION(macro, expression) \
fflush(stdout); \
#define PW_ASSERT_PRINT_EXPRESSION(macro, expression) \
fflush(stdout); \
fprintf(stderr, "\033[31m" _PW_ASSERT_CRASH_BANNER "\033[0m"); \
fprintf(stderr, \
"\033[41m\033[37m\033[1m%s:%d:\033[0m " \
"\033[1m" \
_PW_ASSERT_MACRO(macro) \
" " \
"\033[31mFAILED!\033[0m\n\n" \
" FAILED ASSERTION\n\n" \
" \033[33mFAILED ASSERTION\033[0m\n\n" \
" %s\n\n" \
" FILE & LINE\n\n" \
" \033[33mFILE & LINE\033[0m\n\n" \
" %s:%d\n\n" \
" FUNCTION\n\n" \
" \033[33mFUNCTION\033[0m\n\n" \
" %s\n\n", \
__FILE__, \
__LINE__, \
Expand Down

0 comments on commit bd62666

Please sign in to comment.