spinn_common 7.1.1
Support code for SpiNNaker applications.
Loading...
Searching...
No Matches
Macros | Functions
assert.h File Reference

SpiNNaker debug header file. More...

#include "spin-print.h"

Go to the source code of this file.

Macros

#define abort(n)   do { exit(n); } while (0)
 This macro is intended to mimic the behaviour of 'C's exit system call.
 
#define LOG_ERROR   10
 The log level for errors.
 
#define LOG_WARNING   20
 The log level for warnings.
 
#define LOG_INFO   30
 The log level for information.
 
#define LOG_DEBUG   40
 The log level for debugging.
 
#define LOG_LEVEL   LOG_DEBUG
 The logging level.
 
#define check(condition, message, ...)
 This macro prints out a check message to the log file.
 
#define sentinel(message, ...)
 This macro prints out a sentinel message to the log file and aborts.
 
#define assert(assertion)
 This macro performs an assertion check on a condition and aborts if the condition is not met.
 
#define assert_info(assertion, message, ...)
 This macro performs an assertion check on a condition and aborts if the condition is not met.
 
#define check_memory(a)   check((a), "Out of memory")
 This macro tests whether a pointer returned by malloc is null.
 
#define check_itcm(a)
 This macro tests whether a pointer's address lies in itcm.
 
#define check_dtcm(a)
 This macro tests whether a pointer's address lies in dtcm.
 
#define check_sysram(a)
 This macro tests whether a pointer's address lies in sysram.
 
#define check_sdram(a)
 This macro tests whether a pointer's address lies in sdram.
 

Functions

static unsigned int __addr__ (void *ptr)
 This function returns the unsigned integer associated with a pointer address.
 

Detailed Description

SpiNNaker debug header file.

Author
Dave Lester (david.nosp@m..r.l.nosp@m.ester.nosp@m.@man.nosp@m.chest.nosp@m.er.a.nosp@m.c.uk)
Date
12 December, 2013

A header file that can be used to incorporate and control debug information. It is switched ON by default; to switch OFF, the code is compiled with

-DPRODUCTION_CODE

or

-DNDEBUG

By default it is used for SpiNNaker ARM code; it can also be used in host-side C, by compiling with -DDEBUG_ON_HOST

EXAMPLES

To use, you must ‘hash-include’ debug.h:

Assertions:

assert(0.0 < c && c < 1.0);             // assertion checking

Checking:

check(1==1, "1 !=1 !!!!!!");            // assertion with message
xp = malloc(n); check_memory(xp);       // checks malloc is non-null

Sentinels:

switch(n) {
...
default: sentinel("switch: out of range"); // used for control flow checks
.... }

SpiNNaker memory checking:

If we are running on SpiNNaker hardware, we have the following additional checks available:

check_itcm(addr);
check_dtcm(addr);
check_sysram(addr);
check_sdram(addr);

Controlling the volume of logging information:

-DNO_DEBUG_INFO            Switches OFF the [INFO] information
-D'DEBUG_LOG(n)=(n>10)'    Switches OFF [ERROR]s with number less than or equal 10
-D'DEBUG_WARN(n)=(n>5)'    Switches OFF [WARNING]s with number less than or equal 5

By default all information is printed.

There is no way to switch off [ASSERT]s except by using either of the compilation flags: -DPRODUCTION_CODE or -DNDEBUG

Macro Definition Documentation

◆ abort

#define abort (   n)    do { exit(n); } while (0)

This macro is intended to mimic the behaviour of 'C's exit system call.

Parameters
[in]nValue to pass to exit()

◆ check

#define check (   condition,
  message,
  ... 
)
Value:
do { \
if (!(condition)) { \
io_printf(IO_BUF, "[CHECK] ", message, ##__VA_ARGS__); \
} \
} while (0)

This macro prints out a check message to the log file.

Parameters
[in]conditionThe condition being tested.
[in]messageThe message to be printed if the condition is false

◆ sentinel

#define sentinel (   message,
  ... 
)
Value:
do { \
io_printf(IO_BUF, "[SENTINEL] ", message, ##__VA_ARGS__); \
abort(0); \
} while (0)

This macro prints out a sentinel message to the log file and aborts.

Parameters
[in]messageThe message to be printed if execution reaches this point

◆ assert

#define assert (   assertion)
Value:
do { \
if (!(assertion)) { \
io_printf(IO_BUF, "[ASSERT] ", "assertion check fails!"); \
abort(0); \
} \
} while (0)

This macro performs an assertion check on a condition and aborts if the condition is not met.

Parameters
[in]assertionThe condition being tested.

◆ assert_info

#define assert_info (   assertion,
  message,
  ... 
)
Value:
do { \
if (!(assertion)) { \
io_printf(IO_BUF, "[ASSERT] ", message, ##__VA_ARGS__); \
abort(0); \
} \
} while (0)

This macro performs an assertion check on a condition and aborts if the condition is not met.

Parameters
[in]assertionThe condition being tested.
[in]messageThe message to be printed if the condition is false

◆ check_memory

#define check_memory (   a)    check((a), "Out of memory")

This macro tests whether a pointer returned by malloc is null.

Parameters
[in]aThe address returned by malloc.

◆ check_itcm

#define check_itcm (   a)
Value:
check((ITCM_BASE <= __addr__(a) && __addr__(a) < ITCM_TOP), \
"%x is not in ITCM", (a))
#define check(condition, message,...)
This macro prints out a check message to the log file.
Definition assert.h:127
static unsigned int __addr__(void *ptr)
This function returns the unsigned integer associated with a pointer address.
Definition assert.h:176

This macro tests whether a pointer's address lies in itcm.

Parameters
[in]aThe pointer.

◆ check_dtcm

#define check_dtcm (   a)
Value:
check((DTCM_BASE <= __addr__(a) && __addr__(a) < DTCM_TOP), \
"%x is not in DTCM", (a))

This macro tests whether a pointer's address lies in dtcm.

Parameters
[in]aThe pointer.

◆ check_sysram

#define check_sysram (   a)
Value:
check((SYSRAM_BASE <= __addr__(a) && __addr__(a) < SYSRAM_TOP), \
"%x is not in sysRAM", (a))

This macro tests whether a pointer's address lies in sysram.

Parameters
[in]aThe pointer.

◆ check_sdram

#define check_sdram (   a)
Value:
check((SDRAM_BASE <= __addr__(a) && __addr__(a) < SDRAM_TOP), \
"%x is not in sdram", (a))

This macro tests whether a pointer's address lies in sdram.

Parameters
[in]aThe pointer.

Function Documentation

◆ __addr__()

static unsigned int __addr__ ( void *  ptr)
inlinestatic

This function returns the unsigned integer associated with a pointer address.

Parameters
[in]ptrThe pointer whose address is required.
Returns
The value as an unsigned integer.