QP/C
Defines | Typedefs | Functions
qassert.h File Reference

Customizable QP assertions. More...

Go to the source code of this file.

Defines

#define Q_DEFINE_THIS_FILE   static char_t const Q_ROM Q_ROM_VAR l_this_file[] = __FILE__;
#define Q_DEFINE_THIS_MODULE(name_)   static char_t const Q_ROM Q_ROM_VAR l_this_file[] = name_;
#define Q_ASSERT(test_)   ((test_) ? (void)0 : Q_onAssert(&l_this_file[0], (int_t)__LINE__))
#define Q_ASSERT_ID(id_, test_)   ((test_) ? (void)0 : Q_onAssert(&l_this_file[0], (int_t)(id_))
#define Q_ALLEGE(test_)   Q_ASSERT(test_)
#define Q_ALLEGE_ID(id_, test_)   Q_ASSERT_ID(id_, test_)
#define Q_ERROR()   Q_onAssert(&l_this_file[0], (int_t)__LINE__)
#define Q_ERROR_ID(id_)   Q_onAssert(l_this_file, (int_t)(id_))
#define Q_REQUIRE(test_)   Q_ASSERT(test_)
#define Q_REQUIRE_ID(id_, test_)   Q_ASSERT_ID(id_, test_)
#define Q_ENSURE(test_)   Q_ASSERT(test_)
#define Q_ENSURE_ID(id_, test_)   Q_ASSERT_ID(id_, test_)
#define Q_INVARIANT(test_)   Q_ASSERT(test_)
#define Q_INVARIANT_ID(id_, test_)   Q_ASSERT_ID(id_, test_)
#define Q_ASSERT_COMPILE(test_)   extern int_t Q_assert_compile[(test_) ? 1 : -1]

Typedefs

typedef int int_t
 Type for line numbers.

Functions

void Q_onAssert (char_t const Q_ROM *const Q_ROM_VAR file, int_t line)

Detailed Description

Customizable QP assertions.

Defines customizable and memory-efficient assertions applicable to embedded systems. This header file can be used in C, C++, and mixed C/C++ programs.

Note:
The preprocessor switch Q_NASSERT disables checking assertions. In particular macros Q_ASSERT, Q_REQUIRE, Q_ENSURE, Q_INVARIANT, Q_ERROR as well as Q_ASSERT_ID, Q_REQUIRE_ID, Q_ENSURE_ID, Q_INVARIANT_ID, and Q_ERROR_ID do NOT evaluate the test condition passed as the argument to these macros. One notable exception is the macro Q_ALLEGE, that still evaluates the test condition, but does not report assertion failures when the switch Q_NASSERT is defined.

Definition in file qassert.h.


Define Documentation

#define Q_ALLEGE (   test_)    Q_ASSERT(test_)

General purpose assertion that ALWAYS evaluates the test_ argument and calls the Q_onAssert() callback if the test_ evaluates to FALSE.

Note:
the test_ argument IS always evaluated even when assertions are disabled with the Q_NASSERT macro. When the Q_NASSERT macro is defined, the Q_onAssert() callback is NOT called, even if the test_ evaluates to FALSE.
See also:
Q_ALLEGE_ID

Definition at line 114 of file qassert.h.

Referenced by QFsm_init(), and QHsm_init().

#define Q_ALLEGE_ID (   id_,
  test_ 
)    Q_ASSERT_ID(id_, test_)

General purpose assertion that ALWAYS evaluates the test_ argument and calls the Q_onAssert() callback if the test_ evaluates to FALSE. This assertion style is better suited for unit testing, because it avoids the volatility of line numbers for identifying assertions.

Note:
the test_ argument IS always evaluated even when assertions are disabled with the Q_NASSERT macro. When the Q_NASSERT macro is defined, the Q_onAssert() callback is NOT called, even if the test_ evaluates to FALSE.
See also:
Q_ALLEGE

Definition at line 127 of file qassert.h.

#define Q_ASSERT (   test_)    ((test_) ? (void)0 : Q_onAssert(&l_this_file[0], (int_t)__LINE__))

General purpose assertion that makes sure the test_ argument is TRUE. Calls the Q_onAssert() callback if the test_ evaluates to FALSE.

Note:
the test_ is NOT evaluated if assertions are disabled with the Q_NASSERT switch.
See also:
Q_ASSERT_ID

Definition at line 89 of file qassert.h.

Referenced by QActive_postFIFO(), QActive_postLIFO(), QActive_recall(), QActive_start(), QEQueue_postFIFO(), QEQueue_postLIFO(), QF_gc(), QF_publish(), QF_tick(), QHsm_dispatch(), QHsm_init(), QMPool_get(), and QMPool_init().

#define Q_ASSERT_COMPILE (   test_)    extern int_t Q_assert_compile[(test_) ? 1 : -1]

Compile-time assertion exploits the fact that in C/C++ a dimension of an array cannot be negative. The following declaration causes a compilation error if the compile-time expression (test_) is not TRUE. The assertion has no runtime side effects.

Definition at line 220 of file qassert.h.

#define Q_ASSERT_ID (   id_,
  test_ 
)    ((test_) ? (void)0 : Q_onAssert(&l_this_file[0], (int_t)(id_))

General purpose assertion that makes sure the test_ argument is TRUE. Calls the Q_onAssert() callback if the test_ evaluates to FALSE. The argument id_ is the ID number (unique within the file) of the assertion. This assertion style is better suited for unit testig, because it avoids the volatility of line numbers for identifying assertions.

Note:
the test_ is NOT evaluated if assertions are disabled with the Q_NASSERT switch.
See also:
Q_ASSERT

Definition at line 102 of file qassert.h.

#define Q_DEFINE_THIS_FILE   static char_t const Q_ROM Q_ROM_VAR l_this_file[] = __FILE__;

Place this macro at the top of each C/C++ module to define the file name string using __FILE__ (NOTE: __FILE__ might contain lengthy path name). This file name will be used in reporting assertions in this file.

Definition at line 72 of file qassert.h.

#define Q_DEFINE_THIS_MODULE (   name_)    static char_t const Q_ROM Q_ROM_VAR l_this_file[] = name_;

Place this macro at the top of each C/C++ module to define the module name as the argument name_. This file name will be used in reporting assertions in this file.

Definition at line 79 of file qassert.h.

#define Q_ENSURE (   test_)    Q_ASSERT(test_)

Assertion that checks for a postcondition. This macro is equivalent to Q_ASSERT, except the name provides a better documentation of the intention of this assertion.

See also:
Q_ENSURE_ID

Definition at line 192 of file qassert.h.

#define Q_ENSURE_ID (   id_,
  test_ 
)    Q_ASSERT_ID(id_, test_)

Assertion that checks for a postcondition. This macro is equivalent to Q_ASSERT_ID, except the name provides a better documentation of the intention of this assertion.

See also:
Q_ENSURE

Definition at line 199 of file qassert.h.

#define Q_ERROR ( )    Q_onAssert(&l_this_file[0], (int_t)__LINE__)

Assertion that always calls the Q_onAssert() callback if ever executed.

Note:
can be disabled with the Q_NASSERT switch.
See also:
Q_ERROR_ID

Definition at line 134 of file qassert.h.

#define Q_ERROR_ID (   id_)    Q_onAssert(l_this_file, (int_t)(id_))

Assertion that always calls the Q_onAssert() callback if ever executed. This assertion style is better suited for unit testing, because it avoids the volatility of line numbers for identifying assertions.

Note:
can be disabled with the Q_NASSERT switch.
See also:
Q_ERROR

Definition at line 144 of file qassert.h.

#define Q_INVARIANT (   test_)    Q_ASSERT(test_)

Assertion that checks for an invariant. This macro is equivalent to Q_ASSERT, except the name provides a better documentation of the intention of this assertion.

See also:
Q_INVARIANT_ID

Definition at line 206 of file qassert.h.

#define Q_INVARIANT_ID (   id_,
  test_ 
)    Q_ASSERT_ID(id_, test_)

Assertion that checks for an invariant. This macro is equivalent to Q_ASSERT_ID, except the name provides a better documentation of the intention of this assertion.

See also:
Q_INVARIANT

Definition at line 213 of file qassert.h.

#define Q_REQUIRE (   test_)    Q_ASSERT(test_)

Assertion that checks for a precondition. This macro is equivalent to Q_ASSERT, except the name provides a better documentation of the intention of this assertion.

See also:
Q_REQUIRE_ID

Definition at line 178 of file qassert.h.

Referenced by QActive_start(), QActive_subscribe(), QActive_unsubscribe(), QActive_unsubscribeAll(), QF_add_(), QF_getPoolMargin(), QF_getQueueMargin(), QF_poolInit(), QF_publish(), QF_remove_(), QFsm_dispatch(), QFsm_init(), QHsm_dispatch(), QHsm_init(), QHsm_isIn(), QMPool_init(), QMPool_put(), QTimeEvt_arm_(), QTimeEvt_ctor(), and QTimeEvt_rearm().

#define Q_REQUIRE_ID (   id_,
  test_ 
)    Q_ASSERT_ID(id_, test_)

Assertion that checks for a precondition. This macro is equivalent to Q_ASSERT_ID, except the name provides a better documentation of the intention of this assertion.

See also:
Q_REQUIRE

Definition at line 185 of file qassert.h.


Typedef Documentation

typedef int int_t

Type for line numbers.

This typedef specifies strong type for line numbers. The use of this type, rather than plain 'int', is in compliance with MISRA-C 2004 Rule 6.3(adv).

Definition at line 158 of file qassert.h.


Function Documentation

void Q_onAssert ( char_t const Q_ROM *const Q_ROM_VAR  file,
int_t  line 
)

callback invoked in case the condition passed to Q_ASSERT, Q_REQUIRE, Q_ENSURE, Q_ERROR, Q_ALLEGE as well as Q_ASSERT_ID, Q_REQUIRE_ID, Q_ENSURE_ID, Q_ERROR_ID, and Q_ALLEGE_ID evaluates to FALSE.

Parameters:
filefile name where the assertion failed
lineline number at which the assertion failed