foxBMS-UnitTests
1.0.0
The foxBMS Unit Tests API Documentation
|
Assert macro implementation. More...
#include <stdint.h>
#include "CException.h"
Go to the source code of this file.
Data Structures | |
struct | ASSERT_LOC |
Struct for storing assert information. More... | |
Macros | |
#define | FAS_TRAP (0u == 1u) |
Define that evaluates to essential boolean false thus tripping an assert. More... | |
#define | ASSERT_LEVEL_INF_LOOP_AND_DISABLE_INTERRUPTS (0u) |
This assert level traps the complete program by going into an infinite loop and disabling all interrupts. More... | |
#define | ASSERT_LEVEL_INF_LOOP_FOR_DEBUG (1u) |
This assert level traps the current task by going into an infinite loop. More... | |
#define | ASSERT_LEVEL_NO_OP (2u) |
This assert level does nothing (except for the standard recording of the assert location which does every level). More... | |
#define | ASSERT_LEVEL ASSERT_LEVEL_INF_LOOP_AND_DISABLE_INTERRUPTS |
Set the assert level to a standard value if not set by the build. More... | |
#define | FAS_ASSERT_RECORD() |
Record the assert location. More... | |
#define | FAS_ASSERT(x) |
Assertion macro that asserts that x is true. More... | |
#define | static_assert(cond, msg) _Static_assert(cond, msg) |
static assertion macro More... | |
Typedefs | |
typedef struct ASSERT_LOC | ASSERT_LOC_s |
Struct for storing assert information. More... | |
Functions | |
void | FAS_DisableInterrupts (void) |
Disable interrupts. More... | |
void | fas_storeAssertLoc (uint32_t *pc, uint32_t line) |
Copy the assert location into the assert struct. More... | |
static void | FAS_infiniteLoop () |
static uint32_t | __curpc (void) |
Variables | |
ASSERT_LOC_s | fas_assertLocation |
Stores the information on the last assert. More... | |
Assert macro implementation.
BSD 3-Clause License Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
We kindly request you to use one or more of the following phrases to refer to foxBMS in your hardware, software, documentation or advertising materials:
″This product uses parts of foxBMS®″
″This product includes parts of foxBMS®″
″This product is derived from foxBMS®″
The default implementation accommodates three behaviors, based on ASSERT_LEVEL symbol:
When ASSERT_LEVEL symbol is defined as ASSERT_LEVEL_NO_OP, the FAS_ASSERT macro is defined as empty and does nothing. It might be necessary to activate this mode in ressource-constrained situations. Generally it is not recommended to use this option as it will not notice the undefined system-states that the assert should catch.
Generally assertions should be used for asserting states and values that should occur when the program is executed correctly. Do not assert anything that might be false. As an example it is perfectly good practice to assert that the input to a function is not a null pointer if the function is not designed to accept null pointers, but it is not good to check if a communication error has occurred somewhere. Assertions should never trip in a bug-free program.
Definition in file fassert.h.
#define ASSERT_LEVEL ASSERT_LEVEL_INF_LOOP_AND_DISABLE_INTERRUPTS |
#define ASSERT_LEVEL_INF_LOOP_AND_DISABLE_INTERRUPTS (0u) |
#define ASSERT_LEVEL_INF_LOOP_FOR_DEBUG (1u) |
#define ASSERT_LEVEL_NO_OP (2u) |
#define FAS_ASSERT | ( | x | ) |
Assertion macro that asserts that x is true.
This macro asserts the taken argument x. If the assertion fails it calls FAS_ASSERT_RECORD() and then FAS_infiniteLoop().
In unit tests this is replace by an exception that is thrown in order to be able to test for a failed assertion.
Use this macro if you want to assert. If the assertion fails the macro will take action based on the configuration of this module. See ASSERT_LEVEL for reference.
If the macro passes, it is just ignored. If you want to definitely fail, you can use the value FAS_TRAP as an argument which is designed to fail in all cases.
#define FAS_ASSERT_RECORD | ( | ) |
Record the assert location.
Retrieves the program counter (with __curpc()) and line-number at the current location and passes it to fas_storeAssertLoc().
It is important that this is a macro in order to insert it directly at he assert location in the code
#define FAS_TRAP (0u == 1u) |
Define that evaluates to essential boolean false thus tripping an assert.
Call FAS_ASSERT() with this define in order to stop the code and trip an assertion.
#define static_assert | ( | cond, | |
msg | |||
) | _Static_assert(cond, msg) |
typedef struct ASSERT_LOC ASSERT_LOC_s |
Struct for storing assert information.
This struct is intended for storing, information on the place in the code where an assert has been violated.
void FAS_DisableInterrupts | ( | void | ) |
Disable interrupts.
This alias is mapped to an ASM function and disables all interrupts by writing to the SPSR (Saved Program Status Register) register through the control field mask byte PSR[7:0] (privileged software execution)
|
inlinestatic |
void fas_storeAssertLoc | ( | uint32_t * | pc, |
uint32_t | line | ||
) |
Copy the assert location into the assert struct.
Takes the location of the last assertion and writes it into fas_assertLocation. This definition has to be at this position in order to be used by the macros below. If you get issues in a unit test with this being not defined, try to add this header to the unit tests includes explicitely.
[in] | pc | address of the program counter where the assertion occurred |
[in] | line | line where the assertion occurred |
|
extern |