blob: d7d7770bd8c76a3859ca8b42160166be0ba48308 [file] [log] [blame]
Daniel Boulby6530adf2021-11-26 09:54:01 +00001/*
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 Meakin871b41e2024-06-03 13:45:24 +010013#include <stdint.h>
14
15#include "hf/dlog.h"
Daniel Boulby6530adf2021-11-26 09:54:01 +000016#include "hf/panic.h"
17
18#ifndef PLAT_LOG_LEVEL_ASSERT
19#define PLAT_LOG_LEVEL_ASSERT LOG_LEVEL
20#endif
21
Karl Meakin871b41e2024-06-03 13:45:24 +010022#define assert(e) assert_impl(e, __FILE__, __LINE__, #e)
23
24static 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 Boulby6530adf2021-11-26 09:54:01 +000043
Kathleen Capella4df55202022-12-01 15:39:26 -050044#else
45#include <assert.h>
Daniel Boulby6530adf2021-11-26 09:54:01 +000046#endif /* !defined(__cplusplus) */