Daniel Boulby | 6530adf | 2021-11-26 09:54:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021 The Hafnium Authors. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style |
| 5 | * license that can be found in the LICENSE file or at |
| 6 | * https://opensource.org/licenses/BSD-3-Clause. |
| 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #if !defined(__cplusplus) |
| 12 | |
Karl Meakin | 902af08 | 2024-11-28 14:58:38 +0000 | [diff] [blame] | 13 | #include <stdbool.h> |
Karl Meakin | 871b41e | 2024-06-03 13:45:24 +0100 | [diff] [blame] | 14 | #include <stdint.h> |
| 15 | |
| 16 | #include "hf/dlog.h" |
Daniel Boulby | 6530adf | 2021-11-26 09:54:01 +0000 | [diff] [blame] | 17 | #include "hf/panic.h" |
| 18 | |
| 19 | #ifndef PLAT_LOG_LEVEL_ASSERT |
| 20 | #define PLAT_LOG_LEVEL_ASSERT LOG_LEVEL |
| 21 | #endif |
| 22 | |
Karl Meakin | 871b41e | 2024-06-03 13:45:24 +0100 | [diff] [blame] | 23 | #define assert(e) assert_impl(e, __FILE__, __LINE__, #e) |
| 24 | |
| 25 | static inline void assert_impl(bool cond, const char *file, uint32_t line, |
| 26 | const char *expr) |
| 27 | { |
| 28 | if (!ENABLE_ASSERTIONS) { |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | if (cond) { |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | if (PLAT_LOG_LEVEL_ASSERT >= LOG_LEVEL_VERBOSE) { |
| 37 | panic("ASSERT: %s:%d:%s\n", file, line, expr); |
| 38 | } else if (PLAT_LOG_LEVEL_ASSERT >= LOG_LEVEL_INFO) { |
| 39 | panic("ASSERT: %s:%d\n", file, line); |
| 40 | } else { |
| 41 | panic("ASSERT\n"); |
| 42 | } |
| 43 | } |
Daniel Boulby | 6530adf | 2021-11-26 09:54:01 +0000 | [diff] [blame] | 44 | |
Kathleen Capella | 4df5520 | 2022-12-01 15:39:26 -0500 | [diff] [blame] | 45 | #else |
| 46 | #include <assert.h> |
Daniel Boulby | 6530adf | 2021-11-26 09:54:01 +0000 | [diff] [blame] | 47 | #endif /* !defined(__cplusplus) */ |