From 361cd531b68cfb7ac11a9682dab5bfeb062ccb5e Mon Sep 17 00:00:00 2001 From: bg- Date: Fri, 11 Aug 2006 13:37:21 +0000 Subject: [PATCH] Assertions are useful. --- core/lib/assert.c | 42 ++++++++++++++++++++++++++++++++++++++++++ core/lib/assert.h | 43 +++++++++++++++++++++++++++++++++++++++++++ platform/sky/Makefile | 4 ++-- 3 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 core/lib/assert.c create mode 100644 core/lib/assert.h diff --git a/core/lib/assert.c b/core/lib/assert.c new file mode 100644 index 000000000..288c9d5f1 --- /dev/null +++ b/core/lib/assert.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2006, Swedish Institute of Computer Science + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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. + * + * @(#)$Id: assert.c,v 1.1 2006/08/11 13:37:21 bg- Exp $ + */ + +#include + +void +_xassert(const char *file, int lineno) +{ + printf("Assertion failed: file %s, line %d.\n", file, lineno); + /* + * loop for a while; + * call _reset_vector__(); + */ +} diff --git a/core/lib/assert.h b/core/lib/assert.h new file mode 100644 index 000000000..43cf3a87d --- /dev/null +++ b/core/lib/assert.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2006, Swedish Institute of Computer Science + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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. + * + * @(#)$Id: assert.h,v 1.1 2006/08/11 13:37:21 bg- Exp $ + */ + +#ifndef ASSERT_H +#define ASSERT_H + +#ifdef NDEBUG +#define assert(e) ((void)0) +#else +#define assert(e) ((e) ? (void)0 : _xassert(__FILE__, __LINE__)) +void _xassert(const char *, int); +#endif + + +#endif /* ASSERT_H */ diff --git a/platform/sky/Makefile b/platform/sky/Makefile index 5b80081a4..2ac29fe49 100644 --- a/platform/sky/Makefile +++ b/platform/sky/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.1 2006/08/02 14:44:46 bg- Exp $ +# $Id: Makefile,v 1.2 2006/08/11 13:37:21 bg- Exp $ # # This makefile requires GNU make! @@ -25,7 +25,7 @@ UIP=uip.o uiplib.o tcpip.o uip-fw.o uip-fw-service.o uipbuf.o \ tcpdump.o psock.o dhcpc.o uaodv.o uaodv-rt.o UIPDRIVERS=slip.o slip_uart1.o \ cc2420.o cc2420_uart0.o cc2420_send_ip.o cc2420_send_uaodv.o -LIBS=memb.o list.o malloc.o realloc.o malloc_compact.o rand.o crtk.o +LIBS=memb.o list.o malloc.o realloc.o malloc_compact.o rand.o assert.o crtk.o SYSAPPS=tcp_loader.o LIBFILES=$(SYSTEM) $(ARCH) $(UIP) $(UIPDRIVERS) $(LIBS) $(SYSAPPS)