summaryrefslogtreecommitdiff
path: root/host
diff options
context:
space:
mode:
authorlefranc2007-07-24 15:19:59 +0000
committerlefranc2007-07-24 15:19:59 +0000
commit17d3aa84f23be199924f74462906d94f2547e363 (patch)
tree4181bf578bd4e7778c0e755fe9b76a6ccae0dca1 /host
parent45c11da55a2ded30c4a672ccff728fb3d77ec7d3 (diff)
- modified fcall_param_init() to add msg_id
- added fcall_param_reset() - added fcall_return() for async fcall result callback - modified fcall callback prototype to add the fcall context - added the corresponding unit test git-svn-id: svn+ssh://pessac/svn/cesar/trunk@527 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'host')
-rw-r--r--host/fcall.h68
-rw-r--r--host/src/fcall.c66
-rw-r--r--host/src/fcall_param.c33
-rw-r--r--host/src/probe.c16
-rw-r--r--host/test/src/test_fcall.c189
-rw-r--r--host/test/src/test_fcall_param.c66
-rw-r--r--host/test/src/test_host.c1
-rw-r--r--host/test/src/test_probe.c32
8 files changed, 338 insertions, 133 deletions
diff --git a/host/fcall.h b/host/fcall.h
index 672d49decd..9e4406b997 100644
--- a/host/fcall.h
+++ b/host/fcall.h
@@ -36,15 +36,23 @@ typedef enum Function_Call_Type fcall_type_t;
struct fcall_param_elt
{
- char *id; /** parameter id in string format */
- unsigned short *length; /** parameter data length in network format (big endian)*/
- unsigned char *data; /** parameter data */
+ /** parameter id in string format */
+ char *id;
+ /** parameter data length in network format (big endian)*/
+ unsigned short *length;
+ /** parameter data */
+ unsigned char *data;
};
struct fcall_param
{
- char id[FUNCTION_CALL_ID_MAX_SIZE]; /** function id in string format */;
+ /** function id in string format */
+ char id[FUNCTION_CALL_ID_MAX_SIZE];
+ /** identifier for asynchronous function call return */
+ unsigned short msg_id;
+ /** function parameters table */
struct fcall_param_elt param_table[FUNCTION_CALL_PARAM_MAX_NB];
+ /** number of parameter */
int param_nb;
};
@@ -53,25 +61,33 @@ typedef struct fcall_param fcall_param_t;
/** fcall registring list */
struct fcall_function
{
- char id[FUNCTION_CALL_ID_MAX_SIZE]; /** function id in string format */
- int (* function)(fcall_param_t **param, sci_msg_t **msg, void *data); /** callback function to use */
+ /** function id in string format */
+ char id[FUNCTION_CALL_ID_MAX_SIZE];
+ /** callback function to use */
+ int (* function)(fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data);
+ /* pointer to private data called by function */
void *data;
};
/** fcall context definition */
struct fcall_ctx
{
- struct sci_ctx *sci; /** current sci context */
- struct fcall_function function_table[FUNCTION_CALL_FUNCTION_MAX_NB]; /** table of registered functions */
- int function_nb; /** number of registered functions */
+ /** current sci context */
+ struct sci_ctx *sci;
+ /** table of registered functions */
+ struct fcall_function function_table[FUNCTION_CALL_FUNCTION_MAX_NB];
+ /** number of registered functions */
+ int function_nb;
};
/** variable register structure */
struct probe_var
{
- char id[PROBE_ID_MAX_SIZE]; /** var id in string format */
+ /** var id in string format */
+ char id[PROBE_ID_MAX_SIZE];
unsigned short length;
- void *addr; /** memory address of var */
+ /** memory address of var */
+ void *addr;
};
typedef struct probe_var probe_var_t;
@@ -104,11 +120,21 @@ void fcall_param_free(fcall_param_t *param);
* init the parameter table to add new paramters inside the message
* \param param pointer to param context
* \param id string id of parameters' function
+ * \param msg_id id of fcall message to process asynchronous calls
* \return 0 if ok, -1 if failed with errno=
* - EINVAL if fcall or id is NULL
* - ENAMETOOLONG if id length >= FUNCTION_CALL_ID_MAX_SIZE
*/
-int fcall_param_init(fcall_param_t *param, char *id);
+int fcall_param_init(fcall_param_t *param, char *id, unsigned short msg_id);
+
+/**
+ * reset the parameter table and buffer to add new paramters inside the message
+ * function id and msg id stay unmodified
+ * \param param pointer to param context
+ * \return 0 if ok, -1 if failed with errno=
+ * - EINVAL if fcall is NULL
+ */
+int fcall_param_reset(fcall_param_t *param);
static inline void* fcall_param_copy(fcall_param_t *copy, fcall_param_t *source)
{
@@ -182,7 +208,7 @@ int fcall_init(fcall_ctx_t *fcall, sci_ctx_t *sci);
* - ENOSPC if max number of registred function is reached
* - EEXIST if function is already registered
*/
-int fcall_register(fcall_ctx_t *fcall, char *id, int (* function)(fcall_param_t **param, sci_msg_t **msg, void *data), void *data);
+int fcall_register(fcall_ctx_t *fcall, char *id, int (* function)(fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data), void *data);
/**
* fill a blank fcall header with needed parameter number
@@ -200,6 +226,17 @@ int fcall_fill_hdr(
int flags);
/**
+ * send the return parameter list of asynchronous function call
+ * \param fcall pointer to the current fcall context
+ * \param pointer to returned parameter structure
+ * \param msg pointer to returned parameter message buffer
+ * \return 0 if ok, -1 if failed with errno:
+ * - EINVAL if fcall, param or msg is NULL
+ * - errno set by sci_send()
+ */
+int fcall_return(fcall_ctx_t *fcall, fcall_param_t *param, sci_msg_t *msg);
+
+/**
* fill fcall body with all function parameters
* sci_msg_push() is called each time a parameter is added
* \param fcall current fcall context
@@ -268,12 +305,13 @@ int probe_register(probe_ctx_t *probe, char *id, int length, void *addr);
/**
* probe message processing function; called by fcall_recv()
* must be registred to fcall layer as "probe" function id
+ * \param fcall pointer to the current fcall context
* \param param pointer to param
* \param msg pointer to received message with fcall pre-processing
* \return 0 if ok, -1 if failed with errno=
- * - EINVAL if param or msg is NULL
+ * - EINVAL if fcall, param or msg is NULL
*/
-int probe_recv(fcall_param_t **param, sci_msg_t **msg, void *data);
+int probe_recv(fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data);
//END_DECLS
diff --git a/host/src/fcall.c b/host/src/fcall.c
index 096aa9250c..87233fb348 100644
--- a/host/src/fcall.c
+++ b/host/src/fcall.c
@@ -65,7 +65,7 @@ int fcall_init(fcall_ctx_t *fcall, sci_ctx_t *sci)
int fcall_register(
fcall_ctx_t *fcall,
char *id,
- int (* function)(fcall_param_t **param, sci_msg_t **msg, void *data),
+ int (* function)(fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data),
void *data)
{
int index;
@@ -149,12 +149,44 @@ int fcall_fill_hdr(
msg->hdr.fcall->version = FUNCTION_CALL_VERSION;
msg->hdr.fcall->type = FUNCTION_CALL_TYPE_RSP;
msg->hdr.fcall->param_nb = param->param_nb;
+ msg->hdr.fcall->msg_id = htons(param->msg_id);
msg->hdr.fcall->flags = flags;
return 0;
}
/**
+ * send the return parameter list of asynchronous function call
+ * \param fcall pointer to the current fcall context
+ * \param pointer to returned parameter structure
+ * \param msg pointer to returned parameter message buffer
+ * \return 0 if ok, -1 if failed with errno:
+ * - EINVAL if fcall, param or msg is NULL
+ * - errno set by sci_send()
+ */
+int fcall_return(fcall_ctx_t *fcall, fcall_param_t *param, sci_msg_t *msg)
+{
+ if((fcall == NULL)
+ || (param == NULL)
+ || (msg == NULL))
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ /* fill the fcall msg header to prepare the answer */
+ if(fcall_fill_hdr(fcall, msg, param, 0) < 0)
+ return -1;
+
+ /* now fill the sci header */
+ if(sci_fill_hdr(fcall->sci, msg, SCI_MSG_TYPE_FUNCTION_CALL, 0) < 0)
+ return -1;
+
+ /* send the message */
+ return(sci_send(fcall->sci, msg));
+}
+
+/**
* fill fcall body with all function parameters
* sci_msg_push() is called each time a parameter is added
* \param fcall current fcall context
@@ -197,6 +229,7 @@ int fcall_recv(sci_msg_t *msg, void *fcall_data)
int function_index, index;
fcall_ctx_t *fcall;
fcall_param_t param_recv, *param_ref;
+ int is_asynchronous = 0;
fcall = (fcall_ctx_t *)fcall_data;
@@ -208,7 +241,7 @@ int fcall_recv(sci_msg_t *msg, void *fcall_data)
}
param_ref = &param_recv;
- fcall_param_init(&param_recv, "");
+ fcall_param_reset(&param_recv);
/* set header pointer in case of not already done */
msg->hdr.fcall = (struct fcall_msg_hdr *)(msg->data_begin);
@@ -220,18 +253,24 @@ int fcall_recv(sci_msg_t *msg, void *fcall_data)
errno = EPROTOTYPE;
return -1;
}
+ /* get response mode */
+ if(msg->hdr.fcall->flags & FUNCTION_CALL_FLAG_ASYNC)
+ is_asynchronous = 1;
+ else
+ is_asynchronous = 0;
/* fill the param structure */
/* get the parameter number */
param_ref->param_nb = msg->hdr.fcall->param_nb;
+ param_ref->msg_id = ntohs(msg->hdr.fcall->msg_id);
sci_msg_pop(msg, sizeof(struct fcall_msg_hdr));
- /* check id len */
+ /* check function id len */
if((strlen((char *)(msg->data_begin)) == 0)
|| (strlen((char *)(msg->data_begin)) >= FUNCTION_CALL_ID_MAX_SIZE))
{
station_log(fcall->sci->station, STATION_LOG_WARNING, STATION_LOGTYPE_FCALL,
- "%s bad id length", __FUNCTION__);
+ "%s bad function id length", __FUNCTION__);
param_ref->param_nb = 0;
errno = ENOENT;
return -1;
@@ -297,6 +336,7 @@ int fcall_recv(sci_msg_t *msg, void *fcall_data)
fcall->function_table[function_index].function,
param_ref->param_nb);
if((*fcall->function_table[function_index].function)(
+ fcall,
&param_ref,
&msg,
fcall->function_table[function_index].data) < 0)
@@ -308,10 +348,22 @@ int fcall_recv(sci_msg_t *msg, void *fcall_data)
}
else
{
- station_log(fcall->sci->station, STATION_LOG_DEBUG, STATION_LOGTYPE_FCALL,
- "%s function '%s' returned %d parameters (msg->length=%d)", __FUNCTION__, fcall->function_table[function_index].id, param_ref->param_nb, msg->length);
+ if(is_asynchronous)
+ {
+ station_log(fcall->sci->station, STATION_LOG_DEBUG, STATION_LOGTYPE_FCALL,
+ "%s function '%s' returned from asynchronous call", __FUNCTION__, fcall->function_table[function_index].id);
+ }
+ else
+ {
+ station_log(fcall->sci->station, STATION_LOG_DEBUG, STATION_LOGTYPE_FCALL,
+ "%s function '%s' returned %d parameters (msg->length=%d)", __FUNCTION__, fcall->function_table[function_index].id, param_ref->param_nb, msg->length);
+ }
}
-
+
+ if(is_asynchronous)
+ /* asynchronous call: return immediately */
+ return 0;
+
/* after function return, we get a param structure update with return results */
/* be sure to have the same function name */
diff --git a/host/src/fcall_param.c b/host/src/fcall_param.c
index 901a12f43b..26c7451023 100644
--- a/host/src/fcall_param.c
+++ b/host/src/fcall_param.c
@@ -33,13 +33,15 @@
* init the parameter table to add new paramters inside the message
* \param param pointer to param context
* \param id string id of parameters' function
+ * \param msg_id id of fcall message to process asynchronous calls
* \return 0 if ok, -1 if failed with errno=
* - EINVAL if fcall or id is NULL
* - ENAMETOOLONG if id length >= FUNCTION_CALL_ID_MAX_SIZE
*/
-int fcall_param_init(fcall_param_t *param, char *id)
+int fcall_param_init(fcall_param_t *param, char *id, unsigned short msg_id)
{
- if(param == NULL)
+ if((param == NULL)
+ || (id == NULL))
{
errno = EINVAL;
return -1;
@@ -59,10 +61,37 @@ int fcall_param_init(fcall_param_t *param, char *id)
strcpy(param->id, id);
}
+ param->msg_id = msg_id;
+
return 0;
}
/**
+ * reset the parameter table and buffer to add new paramters inside the message
+ * function id and msg id stay unmodified
+ * \param param pointer to param context
+ * \return 0 if ok, -1 if failed with errno=
+ * - EINVAL if fcall is NULL
+ */
+int fcall_param_reset(fcall_param_t *param)
+{
+ int i;
+
+ if(param == NULL)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ param->param_nb = 0;
+ for(i = 0; i < FUNCTION_CALL_PARAM_MAX_NB; i++)
+ {
+ param->param_table[i].id = NULL;
+ }
+ return 0;
+}
+
+/**
* find a parameter according to its id and bind it into a user variable
* \param param pointer to param context
* \param msg sci message containing the parameters
diff --git a/host/src/probe.c b/host/src/probe.c
index 0355efb7a4..6e9422bd6a 100644
--- a/host/src/probe.c
+++ b/host/src/probe.c
@@ -113,12 +113,13 @@ int probe_register(probe_ctx_t *probe, char *id, int length, void *addr)
/**
* probe message processing function; called by fcall_recv()
* must be registred to fcall layer as "probe" function id
+ * \param fcall pointer to the current fcall context
* \param param pointer to param
* \param msg pointer to received message with fcall pre-processing
* \return number of param if ok, -1 if failed with errno=
* - EINVAL if param or msg is NULL
*/
-int probe_recv(fcall_param_t **param, sci_msg_t **msg, void *data)
+int probe_recv(fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
{
int index_param, index_var;
probe_ctx_t *probe;
@@ -128,7 +129,8 @@ int probe_recv(fcall_param_t **param, sci_msg_t **msg, void *data)
probe = (probe_ctx_t *)data;
- if((param == NULL)
+ if((fcall == NULL)
+ || (param == NULL)
|| (*param == NULL)
|| (msg == NULL)
|| (*msg == NULL)
@@ -139,7 +141,7 @@ int probe_recv(fcall_param_t **param, sci_msg_t **msg, void *data)
}
/* init result structures */
- fcall_param_init(&param_result, (*param)->id);
+ fcall_param_init(&param_result, (*param)->id, (*param)->msg_id);
sci_msg_init(&msg_result, buffer, sizeof(buffer));
if((*param)->param_nb == 0)
@@ -175,7 +177,7 @@ int probe_recv(fcall_param_t **param, sci_msg_t **msg, void *data)
if(*(*param)->param_table[index_param].length == 0)
{
/* this is a get request */
- station_log(probe->fcall->sci->station, STATION_LOG_INFO, STATION_LOGTYPE_PROBE,
+ station_log(fcall->sci->station, STATION_LOG_INFO, STATION_LOGTYPE_PROBE,
"%s get '%s' (%d bytes @ %p)",
__FUNCTION__,
probe->var_table[index_var].id,
@@ -189,7 +191,7 @@ int probe_recv(fcall_param_t **param, sci_msg_t **msg, void *data)
probe->var_table[index_var].length,
probe->var_table[index_var].addr
);
- station_log(probe->fcall->sci->station, STATION_LOG_DEBUG, STATION_LOGTYPE_PROBE,
+ station_log(fcall->sci->station, STATION_LOG_DEBUG, STATION_LOGTYPE_PROBE,
"content: %02x-%02x-%02x-%02x",
*((unsigned char *)probe->var_table[index_var].addr),
*((unsigned char *)probe->var_table[index_var].addr + 1),
@@ -205,7 +207,7 @@ int probe_recv(fcall_param_t **param, sci_msg_t **msg, void *data)
(*param)->param_table[index_param].data,
ntohs(*(*param)->param_table[index_param].length)
);
- station_log(probe->fcall->sci->station, STATION_LOG_INFO, STATION_LOGTYPE_PROBE,
+ station_log(fcall->sci->station, STATION_LOG_INFO, STATION_LOGTYPE_PROBE,
"%s set '%s' (%d bytes @ %p)",
__FUNCTION__,
probe->var_table[index_var].id,
@@ -227,7 +229,7 @@ int probe_recv(fcall_param_t **param, sci_msg_t **msg, void *data)
if(index_var >= probe->var_nb)
{
/* variable nor registered: do nothing */
- station_log(probe->fcall->sci->station, STATION_LOG_NOTICE, STATION_LOGTYPE_PROBE,
+ station_log(fcall->sci->station, STATION_LOG_NOTICE, STATION_LOGTYPE_PROBE,
"%s var '%s' not registered",
__FUNCTION__,
(*param)->param_table[index_param].id
diff --git a/host/test/src/test_fcall.c b/host/test/src/test_fcall.c
index b2dbfaea69..ed490c3dcf 100644
--- a/host/test/src/test_fcall.c
+++ b/host/test/src/test_fcall.c
@@ -137,7 +137,7 @@ void fcall_init_test_case(test_t t)
return;
}
-static int _test_register(fcall_param_t **param, sci_msg_t **msg, void *data)
+static int _test_register(fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
{
return 0;
}
@@ -236,7 +236,7 @@ void fcall_fill_hdr_test_case(test_t t)
sci_init(&sci, &station);
fcall_init(&fcall, &sci);
sci_msg_init(&msg, buffer, 256);
- fcall_param_init(&param, "test_function");
+ fcall_param_init(&param, "test_function", 0x1234);
data_int = 12345;
fcall_param_add(&param, &msg, "data_int", sizeof(data_int), &data_int);
@@ -273,85 +273,112 @@ void fcall_fill_hdr_test_case(test_t t)
}
#undef FCALL_DATA_STR
-//void fcall_fill_body_test_case(test_t t)
-//{
-// fcall_ctx_t *fcall;
-// sci_msg_t *msg;
-// fcall_param_t *param;
-// int data_int;
-// char data_str[32];
-// int body_length;
-// unsigned char *ptr;
-//
-// test_case_begin(t, "fill_body");
-// fcall = fcall_new();
-// msg = sci_msg_new(256);
-// param = fcall_param_new("test_function");
-// data_int = 12345;
-// fcall_param_add(param, "data_int", &data_int, sizeof(data_int));
-// fcall_param_add(param, "data_str", FCALL_DATA_STR, strlen(FCALL_DATA_STR));
-// body_length = strlen("test_function") + 1
-// + strlen("data_int") + 1 + sizeof(short) + sizeof(int)
-// + strlen("data_str") + 1 + sizeof(short) + strlen(FCALL_DATA_STR);
-//
-// test_begin(t, "fcall = NULL")
-// {
-// test_fail_unless(
-// (fcall_fill_body(NULL, msg, param) < 0)
-// && (errno == EINVAL)
-// );
-// } test_end;
-//
-// test_begin(t, "msg = NULL")
-// {
-// test_fail_unless(
-// (fcall_fill_body(fcall, NULL, param) < 0)
-// && (errno == EINVAL)
-// );
-// } test_end;
-//
-// test_begin(t, "param = NULL")
-// {
-// test_fail_unless(
-// (fcall_fill_body(fcall, msg, NULL) < 0)
-// && (errno == EINVAL)
-// );
-// } test_end;
-//
-// test_begin(t, "check fill_body")
-// {
-// test_fail_unless(
-// (fcall_fill_body(fcall, msg, param) >= 0)
-// && (msg->length == body_length)
-// && !strcmp(msg->data_begin, "test_function")
-// );
-// ptr = msg->data_begin + strlen((char *)msg->data_begin) + 1;
-// test_fail_unless(
-// !strcmp((char *)ptr, "data_int")
-// && (ntohs((unsigned short)*(ptr + strlen("data_int") + 1)) == sizeof(int))
-// && !memcmp(ptr + strlen("data_int") + 1 + sizeof(short), &data_int, sizeof(int))
-// );
-// ptr += strlen("data_int") + 1 + sizeof(short) + sizeof(int);
-// test_fail_unless(
-// !strcmp((char *)ptr, "data_str")
-// && (ntohs((unsigned short)*(ptr + strlen("data_str") + 1)) == strlen(FCALL_DATA_STG))
-// && !memcmp(ptr + strlen("data_str") + 1 + sizeof(short), FCALL_DATA_STR, strlen(FCALL_DATA_STR))
-// );
-// } test_end;
-//
-// fcall_param_free(param);
-// fcall_free(fcall);
-// sci_msg_free(msg);
-// return;
-//}
-//
-
-
#define FCALL_REQ_STR "this is a request test"
#define FCALL_RES_STR "this is a response test"
+void fcall_return_test_case(test_t t)
+{
+ fcall_ctx_t fcall;
+ station_ctx_t station;
+ sci_ctx_t sci;
+ sci_msg_t msg;
+ fcall_param_t param;
+ sci_msg_hdr_t *hdr;
+ struct fcall_msg_hdr *fcall_hdr;
+ int fd_in;
+ int data_int;
+ unsigned char buffer[1024], *ptr;
+ int len;
+
+ test_case_begin(t, "return");
+ station_init(&station);
+ sci_init(&sci, &station);
+ fcall_init(&fcall, &sci);
+ sci_msg_init(&msg, buffer, 1024);
+ fcall_param_init(&param, "return_function", 30000);
+
+ data_int = 12345;
+ fcall_param_add(&param, &msg, "data_int", sizeof(data_int), &data_int);
+ fcall_param_add(&param, &msg, "data_str", strlen(FCALL_RES_STR), FCALL_RES_STR);
+
+ test_begin(t, "fcall = NULL")
+ {
+ test_fail_unless(
+ (fcall_return(NULL, &param, &msg) < 0)
+ && (errno == EINVAL)
+ );
+ } test_end;
+
+ test_begin(t, "param = NULL")
+ {
+ test_fail_unless(
+ (fcall_return(&fcall, NULL, &msg) < 0)
+ && (errno == EINVAL)
+ );
+ } test_end;
+
+ test_begin(t, "msg = NULL")
+ {
+ test_fail_unless(
+ (fcall_return(&fcall, &param, NULL) < 0)
+ && (errno == EINVAL)
+ );
+ } test_end;
+
+
+ fd_in = open(station.pipe_out_name, O_RDONLY);
+
+ test_begin(t, "fcall_return")
+ {
+ test_fail_unless(
+ (fcall_return(&fcall, &param, &msg) >= 0)
+ );
+
+ test_fail_if(
+ (len = read(fd_in, buffer, sizeof(sci_msg_hdr_t))) != sizeof(sci_msg_hdr_t)
+ );
+ hdr = (sci_msg_hdr_t *)buffer;
+ test_fail_unless(
+ (hdr->type == SCI_MSG_TYPE_FUNCTION_CALL)
+ && (ntohs(hdr->station_id) == station.id)
+ && (ntohs(hdr->msg_id) == (station.sci->current_msg_id | SCI_MSG_ID_STATION))
+ && (htons(hdr->length) == sizeof(struct fcall_msg_hdr)
+ + strlen("return_function") + 1
+ + strlen("data_str") + 1 + sizeof(unsigned short) + strlen(FCALL_RES_STR)
+ + strlen("data_int") + 1 + sizeof(unsigned short) + sizeof(int))
+ );
+ test_fail_unless(
+ ((len = read(fd_in, buffer + sizeof(sci_msg_hdr_t), htons(hdr->length))) == htons(hdr->length))
+ );
+ fcall_hdr = (struct fcall_msg_hdr *)(buffer + sizeof(sci_msg_hdr_t));
+ test_fail_unless(
+ (fcall_hdr->type == FUNCTION_CALL_TYPE_RSP)
+ && (fcall_hdr->param_nb == 2)
+ && (ntohs(fcall_hdr->msg_id) == 30000)
+ && !strcmp((char *)fcall_hdr + sizeof(struct fcall_msg_hdr), "return_function")
+ );
+ ptr = (unsigned char *)fcall_hdr + sizeof(struct fcall_msg_hdr) + strlen("return_function") + 1;
+ test_fail_unless(
+ !strcmp((char *)ptr, "data_str")
+ && (ptr += (strlen("data_str") + 1))
+ && (ntohs(*(unsigned short *)(ptr)) == strlen(FCALL_RES_STR))
+ && !memcmp(ptr + 2, FCALL_RES_STR, strlen(FCALL_RES_STR))
+ );
+ ptr += (2 + strlen(FCALL_RES_STR));
+ test_fail_unless(
+ !strcmp((char *)ptr, "data_int")
+ && (ptr += (strlen("data_int") + 1))
+ && (ntohs(*(unsigned short *)(ptr)) == sizeof(int))
+ && (*(int *)(ptr + 2) == 12345)
+ );
+ } test_end;
+
+ station_down(&station);
+ close(fd_in);
+}
+
int _test_recv_result;
-static int _test_recv(fcall_param_t **param, sci_msg_t **msg, void *data)
+static int _test_recv(fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
{
int data_int;
char data_str[32];
@@ -360,6 +387,7 @@ static int _test_recv(fcall_param_t **param, sci_msg_t **msg, void *data)
private_data = (int *)data;
_test_recv_result = -1;
if(((*param)->param_nb != 2)
+ || ((*param)->msg_id != 0x4321)
|| (private_data == NULL)
|| (*private_data != 0x12345678))
goto failed;
@@ -371,7 +399,7 @@ static int _test_recv(fcall_param_t **param, sci_msg_t **msg, void *data)
goto failed;
/* now modify parameters */
- fcall_param_init(*param, NULL);
+ fcall_param_reset(*param);
data_int = 54321;
fcall_param_add(*param, *msg, "data_int", sizeof(data_int), &data_int);
_test_recv_result = 0;
@@ -403,7 +431,7 @@ void fcall_recv_test_case(test_t t)
fcall_init(&fcall, &sci);
fcall_register(&fcall, "test_function", _test_recv, &private_data);
sci_msg_init(&msg, buffer, 256);
- fcall_param_init(&param, "test_function");
+ fcall_param_init(&param, "test_function", 0x4321);
private_data = 0x12345678;
data_int = 12345;
@@ -454,6 +482,7 @@ void fcall_recv_test_case(test_t t)
test_fail_unless(
(fcall_hdr->type == FUNCTION_CALL_TYPE_RSP)
&& (fcall_hdr->param_nb == 1)
+ && (ntohs(fcall_hdr->msg_id) == 0x4321)
&& !strcmp((char *)fcall_hdr + sizeof(struct fcall_msg_hdr), "test_function")
);
ptr = (unsigned char *)fcall_hdr + sizeof(struct fcall_msg_hdr) + strlen("test_function") + 1;
@@ -473,6 +502,7 @@ void fcall_recv_test_case(test_t t)
} test_end;
station_down(&station);
+ close(fd_in);
return;
}
@@ -483,5 +513,6 @@ void fcall_test_suite(test_t t)
fcall_init_test_case(t);
fcall_register_test_case(t);
fcall_fill_hdr_test_case(t);
+ fcall_return_test_case(t);
fcall_recv_test_case(t);
}
diff --git a/host/test/src/test_fcall_param.c b/host/test/src/test_fcall_param.c
index 923555d00f..36d2b3eb96 100644
--- a/host/test/src/test_fcall_param.c
+++ b/host/test/src/test_fcall_param.c
@@ -29,18 +29,18 @@ void fcall_param_init_test_case(test_t t)
test_begin(t, "param = NULL")
{
test_fail_unless(
- (fcall_param_init(NULL, "test_init") < 0)
+ (fcall_param_init(NULL, "test_init", 20000) < 0)
&& (errno == EINVAL)
);
} test_end;
-// test_begin(t, "id = NULL")
-// {
-// test_fail_unless(
-// (fcall_param_init(&param, NULL) < 0)
-// && (errno == EINVAL)
-// );
-// } test_end;
+ test_begin(t, "id = NULL")
+ {
+ test_fail_unless(
+ (fcall_param_init(&param, NULL, 20000) < 0)
+ && (errno == EINVAL)
+ );
+ } test_end;
test_begin(t, "check init")
{
@@ -52,9 +52,52 @@ void fcall_param_init_test_case(test_t t)
}
param.param_nb = FUNCTION_CALL_PARAM_MAX_NB;
test_fail_unless(
- (fcall_param_init(&param, "test_init") >= 0)
+ (fcall_param_init(&param, "test_init", 20000) >= 0)
&& !strcmp(param.id, "test_init")
&& (param.param_nb == 0)
+ && (param.msg_id == 20000)
+ );
+ for(i = 0; i < FUNCTION_CALL_PARAM_MAX_NB; i++)
+ {
+ test_fail_unless(
+ (param.param_table[i].id == NULL)
+ );
+ }
+ } test_end;
+
+ return;
+}
+
+void fcall_param_reset_test_case(test_t t)
+{
+ fcall_param_t param;
+
+ test_case_begin(t, "reset");
+
+ test_begin(t, "param = NULL")
+ {
+ test_fail_unless(
+ (fcall_param_reset(NULL) < 0)
+ && (errno == EINVAL)
+ );
+ } test_end;
+
+ test_begin(t, "check reset")
+ {
+ int i;
+ strcpy(param.id, "fake_id");
+ param.msg_id = 30000;
+ for(i = 0; i < FUNCTION_CALL_PARAM_MAX_NB; i++)
+ {
+ param.param_table[i].id = "fake_param_id";
+ }
+ param.param_nb = FUNCTION_CALL_PARAM_MAX_NB;
+
+ test_fail_unless(
+ (fcall_param_reset(&param) >= 0)
+ && (param.param_nb == 0)
+ && !strcmp(param.id, "fake_id")
+ && (param.msg_id == 30000)
);
for(i = 0; i < FUNCTION_CALL_PARAM_MAX_NB; i++)
{
@@ -78,7 +121,7 @@ void fcall_param_add_test_case(test_t t)
test_case_begin(t, "add");
- fcall_param_init(&param, "test_add");
+ fcall_param_init(&param, "test_add", 12345);
sci_msg_init(&msg, buffer, 1024);
test_begin(t, "param = NULL")
@@ -168,7 +211,7 @@ void fcall_param_bind_test_case(test_t t)
test_case_begin(t, "bind_param");
- fcall_param_init(&param, "test_bind");
+ fcall_param_init(&param, "test_bind", 54321);
sci_msg_init(&msg, buffer, 256);
@@ -247,6 +290,7 @@ void fcall_param_test_suite(test_t t)
{
test_suite_begin(t, "fcall_param");
fcall_param_init_test_case(t);
+ fcall_param_reset_test_case(t);
fcall_param_add_test_case(t);
fcall_param_bind_test_case(t);
}
diff --git a/host/test/src/test_host.c b/host/test/src/test_host.c
index 902ea8a665..405bed1070 100644
--- a/host/test/src/test_host.c
+++ b/host/test/src/test_host.c
@@ -11,6 +11,7 @@
* \ingroup test
*/
#include "common/std.h"
+#include <stdint.h>
#include "lib/test.h"
diff --git a/host/test/src/test_probe.c b/host/test/src/test_probe.c
index f7a3bb6706..8fe804e57c 100644
--- a/host/test/src/test_probe.c
+++ b/host/test/src/test_probe.c
@@ -179,7 +179,7 @@ void probe_recv_test_case(test_t t)
fcall_init(&fcall, &sci);
probe_init(&probe, &fcall);
sci_msg_init(&msg, buffer, 256);
- fcall_param_init(&param, PROBE_ID);
+ fcall_param_init(&param, PROBE_ID, 12345);
param_ref = &param;
msg_ref = &msg;
@@ -190,10 +190,18 @@ void probe_recv_test_case(test_t t)
fcall_fill_hdr(&fcall, &msg, &param, 0);
msg.hdr.fcall->type = FUNCTION_CALL_TYPE_REQ;
+ test_begin(t, "fcall = NULL")
+ {
+ test_fail_unless(
+ (probe_recv(NULL, &param_ref, &msg_ref, &probe) < 0)
+ && (errno == EINVAL)
+ );
+ } test_end;
+
test_begin(t, "param = NULL")
{
test_fail_unless(
- (probe_recv(NULL, &msg_ref, &probe) < 0)
+ (probe_recv(&fcall, NULL, &msg_ref, &probe) < 0)
&& (errno == EINVAL)
);
} test_end;
@@ -201,7 +209,7 @@ void probe_recv_test_case(test_t t)
test_begin(t, "msg = NULL")
{
test_fail_unless(
- (probe_recv(&param_ref, NULL, &probe) < 0)
+ (probe_recv(&fcall, &param_ref, NULL, &probe) < 0)
&& (errno == EINVAL)
);
} test_end;
@@ -209,7 +217,7 @@ void probe_recv_test_case(test_t t)
test_begin(t, "probe = NULL")
{
test_fail_unless(
- (probe_recv(&param_ref, &msg_ref, NULL) < 0)
+ (probe_recv(&fcall, &param_ref, &msg_ref, NULL) < 0)
&& (errno == EINVAL)
);
} test_end;
@@ -222,7 +230,7 @@ void probe_recv_test_case(test_t t)
strcpy(var2, "deadbeef");
var3 = 'Z';
- fcall_param_init(&param, PROBE_ID);
+ fcall_param_init(&param, PROBE_ID, 54321);
fcall_param_add(&param, &msg, "var1", sizeof(value1), &value1);
fcall_param_add(&param, &msg, "var2", strlen(value2) + 1, value2);
fcall_param_add(&param, &msg, "var3", sizeof(value3), &value3);
@@ -230,7 +238,7 @@ void probe_recv_test_case(test_t t)
test_begin(t, "check recv with set")
{
test_fail_unless(
- (probe_recv(&param_ref, &msg_ref, &probe) == 3)
+ (probe_recv(&fcall, &param_ref, &msg_ref, &probe) == 3)
&& !strcmp(param_ref->id, PROBE_ID)
&& (param_ref->param_nb == 3)
);
@@ -247,7 +255,7 @@ void probe_recv_test_case(test_t t)
);
} test_end;
- fcall_param_init(&param, PROBE_ID);
+ fcall_param_init(&param, PROBE_ID, 0x1234);
fcall_param_add(&param, &msg, "var2", sizeof(var2) + 1, value2);
param_ref = &param;
msg_ref = &msg;
@@ -255,7 +263,7 @@ void probe_recv_test_case(test_t t)
test_begin(t, "check recv with too big set")
{
test_fail_unless(
- (probe_recv(&param_ref, &msg_ref, &probe) == 0)
+ (probe_recv(&fcall, &param_ref, &msg_ref, &probe) == 0)
&& (param_ref->param_nb == 0)
);
} test_end;
@@ -263,7 +271,7 @@ void probe_recv_test_case(test_t t)
value1 = 0xbeefdead;
strcpy(value2, "beefdead");
value3 = 'Y';
- fcall_param_init(&param, PROBE_ID);
+ fcall_param_init(&param, PROBE_ID, 0x4321);
fcall_param_add(&param, &msg, "var1", 0, NULL);
fcall_param_add(&param, &msg, "var2", 0, NULL);
fcall_param_add(&param, &msg, "var3", 0, NULL);
@@ -273,7 +281,7 @@ void probe_recv_test_case(test_t t)
test_begin(t, "check recv with get")
{
test_fail_unless(
- (probe_recv(&param_ref, &msg_ref, &probe) == 3)
+ (probe_recv(&fcall, &param_ref, &msg_ref, &probe) == 3)
&& (param_ref->param_nb == 3)
);
test_fail_unless(
@@ -289,14 +297,14 @@ void probe_recv_test_case(test_t t)
);
} test_end;
- fcall_param_init(&param, PROBE_ID);
+ fcall_param_init(&param, PROBE_ID, 12345);
param_ref = &param;
msg_ref = &msg;
test_begin(t, "check recv with list")
{
test_fail_unless(
- (probe_recv(&param_ref, &msg_ref, &probe) == 3)
+ (probe_recv(&fcall, &param_ref, &msg_ref, &probe) == 3)
&& (param_ref->param_nb == 3)
);
ptr = msg_ref->data_begin;