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 
25 #ifndef TEST_UTILS_EXPECT_H
26 #define TEST_UTILS_EXPECT_H
27 
28 #include <stdio.h>
29 #include "panic.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #ifndef RIOT_FILE_RELATIVE
36 #define RIOT_FILE_RELATIVE (__FILE__)
37 #endif
38 
49 NORETURN static inline void _expect_failure(const char *file, unsigned line)
50 {
51  printf("%s:%u => failed condition\n", file, line);
52  core_panic(PANIC_EXPECT_FAIL, "CONDITION FAILED.");
53 }
54 
83 #define expect(cond) ((cond) ? (void)0 : _expect_failure(RIOT_FILE_RELATIVE, \
84  __LINE__))
85 
86 #ifdef __cplusplus
87 }
88 #endif
89 
90 #endif /* TEST_UTILS_EXPECT_H */
91 
_expect_failure
static NORETURN void _expect_failure(const char *file, unsigned line)
Function to handle failed expectation.
Definition: expect.h:49
NORETURN
#define NORETURN
The NORETURN keyword tells the compiler to assume that the function cannot return.
Definition: kernel_defines.h:74
panic.h
Crash handling header.
core_panic
NORETURN void core_panic(core_panic_t crash_code, const char *message)
Handle an unrecoverable error by halting or rebooting the system.