1.1. assert
— Assertions¶
An assertion tests a condition, and either returns an error or stops the application.
There are three kind of assertions in Simba; ASSERT()
,
FATAL_ASSERT()
and PANIC_ASSERT()
.
ASSERT()
is configurable to either return an error code, or call the fatal callback.FATAL_ASSERT()
always calls the fatal callback.PANIC_ASSERT()
calls the panic function, which allows this assertion to be used in interrupt context.
1.1.1. Example usage¶
All assertion macros share the same prototype, in this example testing one condition each.
ASSERT(x > 1);
FATAL_ASSERT(y != 2);
PANIC_ASSERT(z < 3);
Source code: src/kernel/assert.h
Defines
-
FATAL
(n)¶ Make an assert fatal by negating the error code.
-
IS_FATAL
(n)¶ Check is an error code is fatal (negative error code).
-
ASSERT
(cond, ...)¶ Assert given condition and print an error message on assertion failure. Call the system on fatal callback with error code
EASSERT
on fatal error, otherwise return NULL.
-
ASSERTN
(cond, n, ...)¶ Assert given condition and print an error message on assertion failure. Call the system on fatal callback with given error code
n
on fatal error, otherwise return the error code negated.
-
ASSERTRV
(cond, ...)¶ Assert given condition and print an error message on assertion failure. Call the system on fatal callback with error code
EASSERT
on fatal error, otherwise return NULL.
-
ASSERTRN
(cond, ...)¶ Assert given condition and print an error message on assertion failure. Call the system on fatal callback with error code
EASSERT
on fatal error, otherwise return NULL.
-
ASSERTNR
(cond, n, ...)¶ Assert given condition and print an error message. Call the system on fatal callback with given error code
n
on fatal error, otherwise return given error coderes
.
-
ASSERTNRV
(cond, n, ...)¶ Assert given condition and print an error message on assertion failure. Call the system on fatal callback with given error code
n
on fatal error, otherwise return.
-
ASSERTNRN
(cond, n, ...)¶ Assert given condition and print an error message on assertion failure. Call the system on fatal callback with given error code
n
on fatal error, otherwise return NULL.
-
FATAL_ASSERTN
(cond, n, ...)¶ Assert given condition and print an error message on assertion failure, then call the system on fatal callback with given error code
n
.This assertion is not affected by
CONFIG_ASSERT
, but insteadCONFIG_FATAL_ASSERT
.
-
FATAL_ASSERT
(cond, ...)¶ Assert given condition and print an error message on assertion failure, then call the system on fatal callback with error code
EASSERT
.This assertion is not affected by
CONFIG_ASSERT
, but insteadCONFIG_FATAL_ASSERT
.
-
PANIC_ASSERTN
(cond, n, ...)¶ Assert given condition and call
sys_panic()
with given error coden
on assertion failure.This assertion is not affected by
CONFIG_ASSERT
, but insteadCONFIG_PANIC_ASSERT
.
-
PANIC_ASSERT
(cond, ...)¶ Assert given condition and call
sys_panic()
with error codeEASSERT
.This assertion is not affected by
CONFIG_ASSERT
, but insteadCONFIG_PANIC_ASSERT
.