Maintenance scheduled 24th July -- expect downtime along that day

Commit 8bd086ca authored by Alessandro Rubini's avatar Alessandro Rubini Committed by Adam Wujek

general: added assert

For wrpc-sw, this depends on a similar commit in wrpc-sw, because
arch-wrpc relies on that implementation (to avoid building two of them).
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent c1858025
......@@ -100,6 +100,15 @@ menu "PTP Protocol Options"
endmenu
config ASSERT
bool "Build assertion checks in the code"
default y
help
Build assertions in the code, to catch unexpected situations.
When an assertion fails the code loops over repeating the
error message every second. OTOH, panic() is always built,
with no Kconfig -- and it does the same, unconditionally.
config EXT_WR
bool
default y if ARCH_WRS || ARCH_WRPC
......
......@@ -21,6 +21,7 @@ OBJ-y += $A/crt0.o \
lib/libc-functions.o \
lib/dump-funcs.o \
lib/cmdline.o \
lib/assert.o \
lib/div64.o
# We only support "bare" time operations
......
#ifndef __ARCH_H__
#define __ARCH_H__
#include <ppsi/assert.h>
static inline int sleep(unsigned int seconds)
{
static volatile int i;
for (i = 0; i < 1000 * 1000 * seconds; i++)
;
return 0;
}
/* Architecture-specific defines, included by top-level stuff */
......
......@@ -22,6 +22,7 @@ OBJ-y += $A/crt0.o \
lib/libc-functions.o \
lib/dump-funcs.o \
lib/cmdline.o \
lib/assert.o \
lib/div64.o
# We only support "bare" time operations
......
#ifndef __ARCH_H__
#define __ARCH_H__
#include <ppsi/assert.h>
static inline int sleep(unsigned int seconds)
{
static volatile int i;
for (i = 0; i < 1000 * 1000 * seconds; i++)
;
return 0;
}
/* Architecture-specific defines, included by top-level stuff */
......
......@@ -12,6 +12,7 @@ OBJ-y += $A/sim-startup.o \
lib/conf.o \
lib/dump-funcs.o \
lib/libc-functions.o \
lib/assert.o \
lib/div64.o
# Support only "sim" time operations
......
#ifndef __ARCH_H__
#define __ARCH_H__
#include <ppsi/assert.h>
/* Architecture-specific defines, included by top-level stuff */
......
......@@ -13,6 +13,7 @@ OBJ-y += $A/unix-startup.o \
lib/libc-functions.o \
lib/dump-funcs.o \
lib/drop.o \
lib/assert.o \
lib/div64.o
# The user can set TIME=, but we pick unix time by default
......
......@@ -5,5 +5,6 @@
#include <arpa/inet.h> /* ntohs etc */
#include <stdlib.h> /* abs */
#include <ppsi/assert.h>
#endif /* __ARCH_H__ */
#ifndef __ARCH_H__
#define __ARCH_H__
#include <assert.h> /* wrpc-sw includes assert already */
/* This arch exports wr functions, so include this for consistency checking */
#include "../proto-ext-whiterabbit/wr-api.h"
......
......@@ -18,6 +18,7 @@ OBJ-y += $A/wrs-startup.o \
lib/libc-functions.o \
lib/dump-funcs.o \
lib/drop.o \
lib/assert.o \
lib/div64.o
# We only support "wrs" time operations
......
#ifndef __ARCH_H__
#define __ARCH_H__
#include <ppsi/assert.h>
/* This arch exports wr functions, so include this for consistency checking */
#include "../proto-ext-whiterabbit/wr-api.h"
......
#ifndef __ASSERT_H__
#define __ASSERT_H__
/*
* Both panic and assert loop over the console, re-printing the
* message, so you can connnect to a paniced node and see the message
* that caused the panic. assert_warn(condition) is once only, like
* warn_on(!condition) in the kernel.
*/
extern void panic(const char *fmt, ...)
__attribute__((format(printf,1,2)));
#define assert(cond, fmt, ...) \
if (CONFIG_HAS_ASSERT && !(cond)) \
__assert(__func__, __LINE__, 1 /* forever */, fmt __VA_ARGS__)
#define assert_warn(cond, fmt, ...) \
if (CONFIG_HAS_ASSERT && !(cond)) \
__assert(__func__, __LINE__, 0 /* once */, fmt __VA_ARGS__)
extern void __assert(const char *func, int line, int forever,
const char *fmt, ...)
__attribute__((format(printf, 4, 5)));
#ifdef CONFIG_ASSERT
# define CONFIG_HAS_ASSERT 1
#else
# define CONFIG_HAS_ASSERT 0
#endif
#endif /* __ASSERT_H__ */
#include <stdarg.h>
#include <ppsi/ppsi.h>
#include <ppsi/assert.h>
#if __STDC_HOSTED__
#include <unistd.h> /* bare archs have no sleep, but a sw loop */
#endif
void panic(const char *fmt, ...)
{
va_list args;
while (1) {
pp_printf("Panic: ");
va_start(args, fmt);
pp_vprintf(fmt, args);
va_end(args);
sleep(1);
}
}
void __assert(const char *func, int line, int forever,
const char *fmt, ...)
{
va_list args;
while (1) {
pp_printf("Assertion failed (%s:%i)", func, line);
if (fmt && fmt[0]) {
pp_printf(": ");
va_start(args, fmt);
pp_vprintf(fmt, args);
va_end(args);
} else {
pp_printf(".\n");
}
if (!forever)
break;
sleep(1);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment