summaryrefslogtreecommitdiff
path: root/host
diff options
context:
space:
mode:
authorlefranc2007-08-28 15:35:24 +0000
committerlefranc2007-08-28 15:35:24 +0000
commitb26c3f6d0af1e9d674baa00e3a1b3fb5153ea9d5 (patch)
tree7d4ce301dcc9f0f22d5102a696edfc44523c72ea /host
parentead6a673d337ab331ca7d2b4b0e4e9f1b97b038d (diff)
- added DBG_ASSERT macro for all EINVAL error into functions
- this macro is enabled by ENABLE_DBG_ASSERT define git-svn-id: svn+ssh://pessac/svn/cesar/trunk@626 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'host')
-rw-r--r--host/fwd.h7
-rw-r--r--host/src/fcall.c13
-rw-r--r--host/src/fcall_param.c19
-rw-r--r--host/src/netclock.c17
-rw-r--r--host/src/probe.c13
-rw-r--r--host/src/sci.c11
-rw-r--r--host/src/sci_msg.c8
-rw-r--r--host/src/station.c9
8 files changed, 97 insertions, 0 deletions
diff --git a/host/fwd.h b/host/fwd.h
index 13b3648328..4f276cf736 100644
--- a/host/fwd.h
+++ b/host/fwd.h
@@ -19,6 +19,13 @@
* \todo
*/
+/* strong assert validation */
+#ifdef ENABLE_DBG_ASSERT
+#define DBG_ASSERT(a) dbg_assert(a)
+#else /* ENABLE_DBG_ASSERT */
+#define DBG_ASSERT(a)
+#endif /* ENABLE_DBG_ASSERT */
+
/** tick type definition; a tick is a period of 40 ns */
typedef unsigned long long tick_t;
diff --git a/host/src/fcall.c b/host/src/fcall.c
index 2088d9c3b9..84a5595c40 100644
--- a/host/src/fcall.c
+++ b/host/src/fcall.c
@@ -38,6 +38,8 @@
*/
int fcall_init(fcall_ctx_t *fcall, sci_ctx_t *sci)
{
+ DBG_ASSERT(fcall);
+ DBG_ASSERT(sci);
if((fcall == NULL)
|| (sci == NULL))
{
@@ -70,6 +72,9 @@ int fcall_register(
{
int index;
+ DBG_ASSERT(fcall);
+ DBG_ASSERT(id);
+ DBG_ASSERT(function);
if((fcall == NULL)
|| (id == NULL)
|| (function == NULL))
@@ -127,6 +132,9 @@ int fcall_fill_hdr(
fcall_param_t *param,
int flags)
{
+ DBG_ASSERT(fcall);
+ DBG_ASSERT(msg);
+ DBG_ASSERT(param);
if((fcall == NULL)
|| (msg == NULL)
|| (param == NULL))
@@ -166,6 +174,9 @@ int fcall_fill_hdr(
*/
int fcall_return(fcall_ctx_t *fcall, fcall_param_t *param, sci_msg_t *msg)
{
+ DBG_ASSERT(fcall);
+ DBG_ASSERT(param);
+ DBG_ASSERT(msg);
if((fcall == NULL)
|| (param == NULL)
|| (msg == NULL))
@@ -236,6 +247,8 @@ int fcall_recv(sci_msg_t *msg, void *fcall_data)
fcall = (fcall_ctx_t *)fcall_data;
+ DBG_ASSERT(fcall);
+ DBG_ASSERT(msg);
if((fcall == NULL)
|| (msg == NULL))
{
diff --git a/host/src/fcall_param.c b/host/src/fcall_param.c
index b3a2786d3f..4da4a0e506 100644
--- a/host/src/fcall_param.c
+++ b/host/src/fcall_param.c
@@ -40,6 +40,9 @@
*/
int fcall_param_init(fcall_param_t *param, char *id, unsigned short msg_id)
{
+
+ DBG_ASSERT(param);
+ DBG_ASSERT(id);
if((param == NULL)
|| (id == NULL))
{
@@ -77,6 +80,7 @@ int fcall_param_reset(fcall_param_t *param)
{
int i;
+ DBG_ASSERT(param);
if(param == NULL)
{
errno = EINVAL;
@@ -107,14 +111,22 @@ int fcall_param_bind(fcall_param_t *param, sci_msg_t *msg, char *id, unsigned in
int index;
unsigned int length;
+ DBG_ASSERT(param);
+ DBG_ASSERT(msg);
+ DBG_ASSERT(id);
+ DBG_ASSERT(data);
+
if((param == NULL)
|| (msg == NULL)
|| (id == NULL)
|| (data == NULL))
{
+
errno = EINVAL;
return -1;
}
+
+ DBG_ASSERT(max_length);
if(max_length == 0)
{
errno = EINVAL;
@@ -174,6 +186,13 @@ int fcall_param_add(fcall_param_t *param, sci_msg_t *msg, char *id, int length,
{
int total_len;
+ DBG_ASSERT(param);
+ DBG_ASSERT(msg);
+ DBG_ASSERT(id);
+ DBG_ASSERT(strlen(id));
+ DBG_ASSERT(length >= 0);
+ DBG_ASSERT(length <= FUNCTION_CALL_PARAM_MAX_SIZE);
+ DBG_ASSERT((length <= 0) || (data != NULL));
if((param == NULL)
|| (msg == NULL)
|| (id == NULL)
diff --git a/host/src/netclock.c b/host/src/netclock.c
index 112ffd8652..31337c20c9 100644
--- a/host/src/netclock.c
+++ b/host/src/netclock.c
@@ -58,6 +58,8 @@ static bool _netclock_node_less(set_node_t *left, set_node_t *right)
*/
int netclock_init(netclock_ctx_t *netclock, sci_ctx_t *sci)
{
+ DBG_ASSERT(netclock);
+ DBG_ASSERT(sci);
if((netclock == NULL)
|| (sci == NULL))
{
@@ -100,6 +102,13 @@ int netclock_schedule(
sci_msg_t msg;
unsigned char buffer[256];
+ DBG_ASSERT(netclock);
+ DBG_ASSERT(callback);
+ DBG_ASSERT(type < NETWORK_CLOCK_TYPE_NB);
+ DBG_ASSERT(schedule_tick >= netclock->sci->station->current_tick_tck);
+ DBG_ASSERT(callback_function);
+ DBG_ASSERT(callback_data);
+ DBG_ASSERT(id);
if((netclock == NULL)
|| (callback == NULL)
|| (type >= NETWORK_CLOCK_TYPE_NB)
@@ -153,6 +162,7 @@ int netclock_unschedule(
sci_msg_t msg;
unsigned char buffer[256];
+ DBG_ASSERT(netclock);
if(netclock == NULL)
{
errno = EINVAL;
@@ -212,6 +222,10 @@ int netclock_fill_hdr(
tick_t tick)
{
+ DBG_ASSERT(netclock);
+ DBG_ASSERT(msg);
+ DBG_ASSERT(type < NETWORK_CLOCK_TYPE_NB);
+ DBG_ASSERT(tick >= netclock->sci->station->current_tick_tck);
if((netclock == NULL)
|| (msg == NULL)
|| (type >= NETWORK_CLOCK_TYPE_NB)
@@ -262,6 +276,8 @@ int netclock_recv(sci_msg_t *msg, void *nclock)
set_node_t *found_node;
netclock_ctx_t *netclock;
+ DBG_ASSERT(msg);
+ DBG_ASSERT(nclock);
if((msg == NULL)
|| (nclock == NULL))
{
@@ -300,6 +316,7 @@ int netclock_recv(sci_msg_t *msg, void *nclock)
netclock->callback_nb--;
/* call the callback function */
+ DBG_ASSERT(found_callback->function);
if(found_callback->function == NULL)
{
station_log(netclock->sci->station, STATION_LOG_WARNING, STATION_LOGTYPE_NETCLOCK, "%s: callback %d is NULL", __FUNCTION__, reference.id);
diff --git a/host/src/probe.c b/host/src/probe.c
index 6e9422bd6a..9cc5b2b104 100644
--- a/host/src/probe.c
+++ b/host/src/probe.c
@@ -37,6 +37,8 @@
*/
int probe_init(probe_ctx_t *probe, fcall_ctx_t *fcall)
{
+ DBG_ASSERT(probe);
+ DBG_ASSERT(fcall);
if((probe == NULL)
|| (fcall == NULL))
{
@@ -65,6 +67,11 @@ int probe_register(probe_ctx_t *probe, char *id, int length, void *addr)
{
int index;
+ DBG_ASSERT(probe);
+ DBG_ASSERT(id);
+ DBG_ASSERT(length > 0);
+ DBG_ASSERT(length < FUNCTION_CALL_PARAM_MAX_SIZE);
+ DBG_ASSERT(addr);
if((probe == NULL)
|| (id == NULL)
|| (length <= 0)
@@ -129,6 +136,12 @@ int probe_recv(fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void
probe = (probe_ctx_t *)data;
+ DBG_ASSERT(fcall);
+ DBG_ASSERT(param);
+ DBG_ASSERT(*param);
+ DBG_ASSERT(msg);
+ DBG_ASSERT(*msg);
+ DBG_ASSERT(probe);
if((fcall == NULL)
|| (param == NULL)
|| (*param == NULL)
diff --git a/host/src/sci.c b/host/src/sci.c
index 72f72d025f..add9add7b2 100644
--- a/host/src/sci.c
+++ b/host/src/sci.c
@@ -50,6 +50,8 @@ sci_ctx_t *sci_new(station_ctx_t *station)
*/
int sci_init(sci_ctx_t *sci, station_ctx_t *station)
{
+ DBG_ASSERT(sci);
+ DBG_ASSERT(station);
if((sci == NULL)
|| (station == NULL))
{
@@ -89,6 +91,9 @@ int sci_register_callback(
int(*function)(sci_msg_t *msg, void *data),
void *data)
{
+ DBG_ASSERT(sci);
+ DBG_ASSERT(type < SCI_MSG_TYPE_NB);
+ DBG_ASSERT(function);
if((sci == NULL)
|| (type >= SCI_MSG_TYPE_NB)
|| (function == NULL))
@@ -120,6 +125,9 @@ int sci_fill_hdr(
sci_msg_type_t type,
int flags)
{
+ DBG_ASSERT(sci);
+ DBG_ASSERT(msg);
+ DBG_ASSERT(type < SCI_MSG_TYPE_NB);
if((sci == NULL)
|| (msg == NULL)
|| (type >= SCI_MSG_TYPE_NB))
@@ -159,6 +167,8 @@ int sci_send(sci_ctx_t *sci, sci_msg_t *msg)
{
int len, total_length;
+ DBG_ASSERT(sci);
+ DBG_ASSERT(msg);
if((sci == NULL)
|| (msg == NULL))
{
@@ -197,6 +207,7 @@ int sci_recv(sci_ctx_t *sci)
int len;
tick_t msg_tick_tck;
+ DBG_ASSERT(sci);
if(sci == NULL)
{
errno = EINVAL;
diff --git a/host/src/sci_msg.c b/host/src/sci_msg.c
index 21bda7f816..f685c41eee 100644
--- a/host/src/sci_msg.c
+++ b/host/src/sci_msg.c
@@ -59,6 +59,10 @@ void sci_msg_free(sci_msg_t *msg)
*/
int sci_msg_init(sci_msg_t *msg, unsigned char *buffer, int max_size)
{
+ DBG_ASSERT(msg);
+ DBG_ASSERT(buffer);
+ DBG_ASSERT(max_size >= (int)sizeof(sci_msg_hdr_t));
+ DBG_ASSERT(max_size <= SCI_MSG_MAX_SIZE);
if((msg == NULL)
|| (buffer == NULL)
|| (max_size < (int)sizeof(sci_msg_hdr_t))
@@ -91,6 +95,8 @@ int sci_msg_init(sci_msg_t *msg, unsigned char *buffer, int max_size)
*/
int sci_msg_push(sci_msg_t *msg, int length)
{
+ DBG_ASSERT(msg);
+ DBG_ASSERT(length >= 0);
if((msg == NULL)
|| (length < 0))
{
@@ -121,6 +127,8 @@ int sci_msg_pop(sci_msg_t *msg, int length)
{
int final_len;
+ DBG_ASSERT(msg);
+ DBG_ASSERT(length >= 0);
if((msg == NULL)
|| (length < 0))
{
diff --git a/host/src/station.c b/host/src/station.c
index 462c008398..30501aa61b 100644
--- a/host/src/station.c
+++ b/host/src/station.c
@@ -64,6 +64,7 @@ static netclock_callback_t _ecos_tick_cb;
*/
int station_init(station_ctx_t *station)
{
+ DBG_ASSERT(station);
if(station == NULL)
{
errno = EINVAL;
@@ -207,6 +208,8 @@ int station_idle(station_ctx_t *station)
struct timeval timeout;
int sel;
+ DBG_ASSERT(station);
+ DBG_ASSERT(station->status != STATION_STATUS_INIT);
if((station == NULL)
|| (station->status == STATION_STATUS_INIT))
//|| !station_is_initialized(station))
@@ -287,6 +290,8 @@ static void _ecos_set_itimer_cb(void *data)
int station_ecos_set_itimer(station_ctx_t *station, tick_t tick)
{
netclock_id_t id;
+ DBG_ASSERT(station);
+ DBG_ASSERT(station->status != STATION_STATUS_INIT);
if((station == NULL)
|| (station->status == STATION_STATUS_INIT))
{
@@ -312,6 +317,10 @@ int station_ecos_set_itimer(station_ctx_t *station, tick_t tick)
*/
int station_log_set_level(station_ctx_t *station, station_log_level_t level)
{
+ DBG_ASSERT(station);
+ DBG_ASSERT(station->status != STATION_STATUS_INIT);
+ DBG_ASSERT(level > STATION_LOG_NONE);
+ DBG_ASSERT(level < STATION_LOG_NB);
if((station == NULL)
|| (station->status == STATION_STATUS_INIT)
|| (level <= STATION_LOG_NONE)