xref: /aosp_15_r20/external/pigweed/pw_assert_fuchsia/public/pw_assert_fuchsia/check_backend.h (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2024 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 <zircon/assert.h>
17 
18 #define PW_HANDLE_CRASH(fmt, ...) ZX_PANIC(fmt, ##__VA_ARGS__)
19 
20 #define PW_HANDLE_ASSERT_FAILURE(x, msg, ...)    \
21   ZX_PANIC("ASSERT FAILED at (%s:%d): %s\n" msg, \
22            __FILE__,                             \
23            __LINE__,                             \
24            #x,                                   \
25            ##__VA_ARGS__)
26 
27 #define PW_HANDLE_ASSERT_BINARY_COMPARE_FAILURE(arg_a_str,                 \
28                                                 arg_a_val,                 \
29                                                 comparison_op_str,         \
30                                                 arg_b_str,                 \
31                                                 arg_b_val,                 \
32                                                 type_fmt,                  \
33                                                 msg,                       \
34                                                 ...)                       \
35   ZX_PANIC("ASSERT FAILED at (%s:%d): " arg_a_str " (=" type_fmt           \
36            ") " comparison_op_str " " arg_b_str " (=" type_fmt ") \n" msg, \
37            __FILE__,                                                       \
38            __LINE__,                                                       \
39            arg_a_val,                                                      \
40            arg_b_val,                                                      \
41            ##__VA_ARGS__)
42