Loading...
Searching...
No Matches
expect.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2020 Kaspar Schleiser <kaspar@schleiser.de>
3 * SPDX-FileCopyrightText: 2015 INRIA
4 * SPDX-FileCopyrightText: 2016 Freie Universität Berlin
5 * SPDX-License-Identifier: LGPL-2.1-only
6 */
7
8#pragma once
9
23
24#include <stdio.h>
25#include "compiler_hints.h"
26#include "panic.h"
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
42NORETURN static inline void _expect_failure(const char *file, unsigned line)
43{
44 printf("%s:%u => failed condition\n", file, line);
45 core_panic(PANIC_EXPECT_FAIL, "CONDITION FAILED.");
46}
47
76#define expect(cond) (likely(cond) ? (void)0 : _expect_failure(__FILE__, __LINE__))
77
78#ifdef __cplusplus
79}
80#endif
81
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:57
static NORETURN void _expect_failure(const char *file, unsigned line)
Function to handle failed expectation.
Definition expect.h:42
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.