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 | 871b41e | 2024-06-03 13:45:24 +0100 | [diff] [blame] | 13 | #include <stdint.h> |
| 14 | |
| 15 | #include "hf/dlog.h" |
Daniel Boulby | 6530adf | 2021-11-26 09:54:01 +0000 | [diff] [blame] | 16 | #include "hf/panic.h" |
| 17 | |
| 18 | #ifndef PLAT_LOG_LEVEL_ASSERT |
| 19 | #define PLAT_LOG_LEVEL_ASSERT LOG_LEVEL |
| 20 | #endif |
| 21 | |
Karl Meakin | 871b41e | 2024-06-03 13:45:24 +0100 | [diff] [blame] | 22 | #define assert(e) assert_impl(e, __FILE__, __LINE__, #e) |
| 23 | |
| 24 | static inline void assert_impl(bool cond, const char *file, uint32_t line, |
| 25 | const char *expr) |
| 26 | { |
| 27 | if (!ENABLE_ASSERTIONS) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | if (cond) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | if (PLAT_LOG_LEVEL_ASSERT >= LOG_LEVEL_VERBOSE) { |
| 36 | panic("ASSERT: %s:%d:%s\n", file, line, expr); |
| 37 | } else if (PLAT_LOG_LEVEL_ASSERT >= LOG_LEVEL_INFO) { |
| 38 | panic("ASSERT: %s:%d\n", file, line); |
| 39 | } else { |
| 40 | panic("ASSERT\n"); |
| 41 | } |
| 42 | } |
Daniel Boulby | 6530adf | 2021-11-26 09:54:01 +0000 | [diff] [blame] | 43 | |
Kathleen Capella | 4df5520 | 2022-12-01 15:39:26 -0500 | [diff] [blame] | 44 | #else |
| 45 | #include <assert.h> |
Daniel Boulby | 6530adf | 2021-11-26 09:54:01 +0000 | [diff] [blame] | 46 | #endif /* !defined(__cplusplus) */ |