1 // Copyright 2020 The Pigweed Authors
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
7 // https://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
16 #include "pw_assert_basic/handler.h"
17 #include "pw_preprocessor/compiler.h"
18 #include "pw_preprocessor/util.h"
20 // Die with a message with many attributes included. This is the crash macro
21 // frontend that funnels everything into the C handler provided by the user,
22 // pw_assert_basic_HandleFailure().
23 #define PW_HANDLE_CRASH(...) \
24 pw_assert_basic_HandleFailure( \
25 __FILE__, __LINE__, __func__ PW_COMMA_ARGS(__VA_ARGS__))
27 // Die with a message with many attributes included. This is the crash macro
28 // frontend that funnels everything into the C handler provided by the user,
29 // pw_assert_basic_HandleFailure().
30 #define PW_HANDLE_ASSERT_FAILURE(condition_string, message, ...) \
31 pw_assert_basic_HandleFailure(__FILE__, \
34 "Check failed: " condition_string \
35 ". " message PW_COMMA_ARGS(__VA_ARGS__))
37 // Sample assert failure message produced by the below implementation:
39 // Check failed: current_sensor (=610) < new_sensor (=50). More details!
41 // Putting the value next to the operand makes the string easier to read.
44 // This is too hairy for clang format to handle and retain readability.
45 #define PW_HANDLE_ASSERT_BINARY_COMPARE_FAILURE(arg_a_str, \
52 pw_assert_basic_HandleFailure( \
57 arg_a_str " (=" type_fmt ") " \
58 comparison_op_str " " \
59 arg_b_str " (=" type_fmt ")" \
61 arg_a_val, arg_b_val PW_COMMA_ARGS(__VA_ARGS__))