1 // Copyright 2021 The Pigweed Authors 2 // 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 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 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 13 // the License. 14 #pragma once 15 16 #include <zephyr/sys/__assert.h> 17 18 #include "pw_preprocessor/compiler.h" 19 20 #define PW_HANDLE_CRASH(...) \ 21 { \ 22 __ASSERT_LOC("PW_CRASH()"); \ 23 __ASSERT_MSG_INFO(__VA_ARGS__); \ 24 __ASSERT_POST_ACTION(); \ 25 PW_UNREACHABLE; \ 26 } 27 28 #define PW_HANDLE_ASSERT_FAILURE(condition_string, ...) \ 29 { \ 30 __ASSERT_LOC("PW_CHECK() or PW_DCHECK() failure"); \ 31 __ASSERT_MSG_INFO("Check failed: " condition_string ". " __VA_ARGS__); \ 32 __ASSERT_POST_ACTION(); \ 33 PW_UNREACHABLE; \ 34 } 35 36 #define PW_HANDLE_ASSERT_BINARY_COMPARE_FAILURE(arg_a_str, \ 37 arg_a_val, \ 38 comparison_op_str, \ 39 arg_b_str, \ 40 arg_b_val, \ 41 type_fmt, \ 42 message, \ 43 ...) \ 44 PW_HANDLE_ASSERT_FAILURE(arg_a_str " (=" type_fmt ") " comparison_op_str \ 45 " " arg_b_str " (=" type_fmt ")", \ 46 message, \ 47 arg_a_val, \ 48 arg_b_val PW_COMMA_ARGS(__VA_ARGS__)) 49