expect.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Kaspar Schleiser <kaspar@schleiser.de>
3  * Copyright (C) 2015 INRIA
4  * Copyright (C) 2016 Freie Universität Berlin
5  *
6  * This file is subject to the terms and conditions of the GNU Lesser
7  * General Public License v2.1. See the file LICENSE in the top level
8  * directory for more details.
9  */
10 
11 #pragma once
12 
27 #include <stdio.h>
28 #include "compiler_hints.h"
29 #include "panic.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
45 NORETURN static inline void _expect_failure(const char *file, unsigned line)
46 {
47  printf("%s:%u => failed condition\n", file, line);
48  core_panic(PANIC_EXPECT_FAIL, "CONDITION FAILED.");
49 }
50 
79 #define expect(cond) (likely(cond) ? (void)0 : _expect_failure(__FILE__, __LINE__))
80 
81 #ifdef __cplusplus
82 }
83 #endif
84 
Common macros and compiler attributes/pragmas configuration.
#define NORETURN
The NORETURN keyword tells the compiler to assume that the function cannot return.
#define printf(...)
A wrapper for the printf() function that passes arguments through unmodified, but fails to compile if...
Definition: stdio.h:60
static NORETURN void _expect_failure(const char *file, unsigned line)
Function to handle failed expectation.
Definition: expect.h:45
Crash handling header.
NORETURN void core_panic(core_panic_t crash_code, const char *message)
Handle an unrecoverable error by halting or rebooting the system.