Customizable and memory-efficient Design by Contract (DbC) for embedded systems. More...
Go to the source code of this file.
Macros | |
#define | Q_ASSERT_ID(id_, expr_) |
#define | Q_ERROR_ID(id_) Q_onAssert(&Q_this_module_[0], (id_)) |
#define | Q_ALLEGE_ID(id_, expr_) Q_ASSERT_ID((id_), (expr_)) |
#define | Q_ASSERT(expr_) Q_ASSERT_ID(__LINE__, (expr_)) |
#define | Q_ERROR() Q_ERROR_ID(__LINE__) |
#define | Q_REQUIRE_ID(id_, expr_) Q_ASSERT_ID((id_), (expr_)) |
#define | Q_REQUIRE(expr_) Q_ASSERT(expr_) |
#define | Q_ENSURE_ID(id_, expr_) Q_ASSERT_ID((id_), (expr_)) |
#define | Q_ENSURE(expr_) Q_ASSERT(expr_) |
#define | Q_INVARIANT_ID(id_, expr_) Q_ASSERT_ID((id_), (expr_)) |
#define | Q_INVARIANT(expr_) Q_ASSERT(expr_) |
#define | Q_ALLEGE(expr_) Q_ALLEGE_ID(__LINE__, (expr_)) |
#define | Q_ASSERT_STATIC(expr_) extern char Q_static_assert_[(expr_) ? 1 : -1] |
#define | Q_NORETURN _Noreturn void |
#define | Q_DIM(array_) (sizeof(array_) / sizeof((array_)[0U])) |
Typedefs | |
typedef int | int_t |
Functions | |
Q_NORETURN | Q_onAssert (char const *module, int_t location) |
Definition in file qassert.h.
#define Q_ASSERT_ID | ( | id_, | |
expr_ | |||
) |
General-purpose assertion with user-specified ID number.
Evaluates the Boolean expression expr_
and does nothing else when it evaluates to 'true'. However, when expr_
evaluates to 'false', the Q_ASSERT_ID() macro calls the no-return function Q_onAssert().
[in] | id_ | ID number (unique within the module) of the assertion |
[in] | expr_ | Boolean expression to check |
expr_
is not evaluated and the callback function Q_onAssert() is not called.#define Q_ERROR_ID | ( | id_ | ) | Q_onAssert(&Q_this_module_[0], (id_)) |
Assertion with user-specified ID for a wrong path through the code
Calls the Q_onAssert() callback if ever executed. This assertion takes the user-supplied parameter id_
to identify the location of this assertion within the file. This avoids the volatility of using line numbers, which change whenever a line of code is added or removed upstream from the assertion.
[in] | id_ | ID number (unique within the module) of the assertion |
#define Q_ALLEGE_ID | ( | id_, | |
expr_ | |||
) | Q_ASSERT_ID((id_), (expr_)) |
General purpose assertion with user-specified ID number that always evaluates the expr_
expression.
Like the Q_ASSERT_ID() macro, except it always evaluates the expr_
expression even when assertions are disabled with the Q_NASSERT macro. However, when the Q_NASSERT macro is defined, the Q_onAssert() callback is not called, even if expr_
evaluates to FALSE.
[in] | id_ | ID number (unique within the module) of the assertion |
[in] | expr_ | Boolean expression to check |
#define Q_ASSERT | ( | expr_ | ) | Q_ASSERT_ID(__LINE__, (expr_)) |
General-purpose assertion (with LINE used as location in the file)
Equivalent to Q_ASSERT_ID(), except it uses LINE to identify the assertion within a file.
[in] | expr_ | Boolean expression to check |
#define Q_ERROR | ( | ) | Q_ERROR_ID(__LINE__) |
Assertion for a wrong path through the code
Calls the Q_onAssert() callback if ever executed.
#define Q_REQUIRE_ID | ( | id_, | |
expr_ | |||
) | Q_ASSERT_ID((id_), (expr_)) |
Assertion for checking preconditions.
Equivalent to Q_ASSERT_ID(), except the name provides a better documentation of the intention of this assertion.
[in] | id_ | ID number (unique within the module) of the assertion |
[in] | expr_ | Boolean expression |
#define Q_REQUIRE | ( | expr_ | ) | Q_ASSERT(expr_) |
Assertion for checking preconditions (based on LINE).
Equivalent to Q_ASSERT(), except the name provides a better documentation of the intention of this assertion.
[in] | expr_ | Boolean expression |
#define Q_ENSURE_ID | ( | id_, | |
expr_ | |||
) | Q_ASSERT_ID((id_), (expr_)) |
Assertion for checking postconditions.
Equivalent to Q_ASSERT_ID(), except the name provides a better documentation of the intention of this assertion.
[in] | id_ | ID number (unique within the module) of the assertion |
[in] | expr_ | Boolean expression |
#define Q_ENSURE | ( | expr_ | ) | Q_ASSERT(expr_) |
Assertion for checking postconditions.
Equivalent to Q_ASSERT(), except the name provides a better documentation of the intention of this assertion.
[in] | expr_ | Boolean expression |
#define Q_INVARIANT_ID | ( | id_, | |
expr_ | |||
) | Q_ASSERT_ID((id_), (expr_)) |
Assertion for checking invariants.
Equivalent to Q_ASSERT_ID(), except the name provides a better documentation of the intention of this assertion.
[in] | id_ | ID number (unique within the module) of the assertion |
[in] | expr_ | Boolean expression |
#define Q_INVARIANT | ( | expr_ | ) | Q_ASSERT(expr_) |
Assertion for checking invariants.
Equivalent to Q_ASSERT(), except the name provides a better documentation of the intention of this assertion.
[in] | expr_ | Boolean expression |
#define Q_ALLEGE | ( | expr_ | ) | Q_ALLEGE_ID(__LINE__, (expr_)) |
General purpose assertion with user-specified ID number that always evaluates the expr_
expression.
Equivalent to Q_ALLEGE_ID(), except it identifies the problem location with the line number __LINE__
, which might change as the code is modified.
[in] | expr_ | Boolean expression to check |
#define Q_ASSERT_STATIC | ( | expr_ | ) | extern char Q_static_assert_[(expr_) ? 1 : -1] |
Static (compile-time) assertion.
This type of assertion deliberately causes a compile-time error when the expr_
Boolean expression evaluates to FALSE. The macro exploits the fact that in C/C++ a dimension of an array cannot be negative. The compile-time assertion has no runtime side effects.
[in] | expr_ | Compile-time Boolean expression |
_Static_assert()
, which should be used instead of Q_ASSERT_STATIC().#define Q_NORETURN _Noreturn void |
No-return function specifier for the Q_onAssert() callback function.
If the Q_NORETURN
macro is undefined, the default definition uses the C99 specifier _Noreturn
.
Q_NORETURN
macro can be defined in the QP port (typically in qep_port.h
or qep_port.hpp
). If such definition is porvided the default won't be used.#define Q_DIM | ( | array_ | ) | (sizeof(array_) / sizeof((array_)[0U])) |
Helper macro to calculate static dimension of a 1-dim array_
array_ | 1-dimensional array |
typedef int int_t |
Q_NORETURN Q_onAssert | ( | char const * | module, |
int_t | location | ||
) |
Callback function invoked in case of an assertion failure.
This callback function needs to be defined in the application to perform any corrective action after a non-recoverable error has been detected. The Q_onAssert() function is the last line of defense after the system failure and its implementation shouild be very carefully designed and tested under various fault conditions, including but not limited to: stack overflow, stack corruption, or calling Q_onAssert() from an interrupt.
[in] | module | name of the file/module in which the assertion failed (constant, zero-terminated C string) |
[in] | location | location of the assertion within the module. This could be a line number or a user-specified ID-number. |
Called by the following: Q_ASSERT_ID(), Q_ERROR_ID(), Q_REQUIRE_ID(), Q_ENSURE_ID(), Q_INVARIANT_ID() and Q_ALLEGE_ID() as well as: Q_ASSERT(), Q_ERROR(), Q_REQUIRE(), Q_ENSURE(), Q_INVARIANT(), and Q_ALLEGE().