summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManikandan C <mchockalingam@de.adit-jv.com>2018-10-29 16:32:17 +0100
committerChristoph Lipka <clipka@users.noreply.github.com>2018-11-23 11:10:47 +0100
commitd515020fa1bcb5d874084a68c9de9434dc9d994e (patch)
tree339074f3d4e0858dfbe1c528705ed3e4343521f3
parent3cfb292aa43774428ce8dfe120fe16785942b086 (diff)
downloadDLT-daemon-d515020fa1bcb5d874084a68c9de9434dc9d994e.tar.gz
Gateway Improvements
-Support to send and parse periodic control messages -add application/contexts to passive ECU list -Refactor dlt_gateway_send_control_message -Gateway issues with corrupted data and on demand connection -Unit Test update Signed-off-by: Saya Sugiura ssugiura@jp.adit-jv.com Signed-off-by: Christoph Lipka clipka@jp.adit-jv.com Signed-off-by: S. Hameed shameed@jp.adit-jv.com Signed-off-by: ManikandanC Manikandan.Chockalingam@in.bosch.com
-rw-r--r--include/dlt/dlt_client.h27
-rw-r--r--include/dlt/dlt_common.h103
-rw-r--r--include/dlt/dlt_protocol.h9
-rw-r--r--src/console/dlt-control-common.c1
-rw-r--r--src/console/dlt-control.c422
-rw-r--r--src/console/dlt-receive.c2
-rw-r--r--src/daemon/CMakeLists.txt10
-rw-r--r--src/daemon/dlt_daemon_client.c11
-rw-r--r--src/daemon/dlt_daemon_offline_logstorage.c48
-rw-r--r--src/gateway/dlt_gateway.c1197
-rw-r--r--src/gateway/dlt_gateway.conf5
-rw-r--r--src/gateway/dlt_gateway.h44
-rw-r--r--src/gateway/dlt_gateway_types.h33
-rw-r--r--src/lib/dlt_client.c379
-rw-r--r--src/shared/dlt_common.c145
-rwxr-xr-xtests/g_test_dlt_daemon_gateway.sh6
-rw-r--r--tests/gtest_common.h251
-rw-r--r--tests/gtest_dlt_daemon_event_handler.cpp3
-rw-r--r--tests/gtest_dlt_daemon_gateway.cpp266
-rw-r--r--tests/gtest_dlt_daemon_offline_log.cpp1375
20 files changed, 3445 insertions, 892 deletions
diff --git a/include/dlt/dlt_client.h b/include/dlt/dlt_client.h
index 8943184..e56c9ff 100644
--- a/include/dlt/dlt_client.h
+++ b/include/dlt/dlt_client.h
@@ -180,6 +180,18 @@ DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ct
*/
int dlt_client_get_log_info(DltClient *client);
/**
+ * Send an request to get default log level to the dlt daemon
+ * @param client pointer to dlt client structure
+ * @return negative value if there was an error
+ */
+DltReturnValue dlt_client_get_default_log_level(DltClient *client);
+/**
+ * Send an request to get software version to the dlt daemon
+ * @param client pointer to dlt client structure
+ * @return negative value if there was an error
+ */
+int dlt_client_get_software_version(DltClient *client);
+/**
* Initialise get log info structure
* @param void
* @return void
@@ -280,6 +292,21 @@ int dlt_client_set_serial_device(DltClient *client, char *serial_device);
*/
int dlt_client_set_socket_path(DltClient *client, char *socket_path);
+/**
+ * Parse GET_LOG_INFO response text
+ * @param resp GET_LOG_INFO response
+ * @param resp_text response text represented by ASCII
+ * @return 0 on success, -1 otherwise
+ */
+int dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoResponse *resp,
+ char *resp_text);
+
+/**
+ * Free memory allocated for get log info message
+ * @param resp response
+ * @return 0 on success, -1 otherwise
+ */
+int dlt_client_cleanup_get_log_info(DltServiceGetLogInfoResponse *resp);
#ifdef __cplusplus
}
#endif
diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h
index 0b9fd8d..d76d190 100644
--- a/include/dlt/dlt_common.h
+++ b/include/dlt/dlt_common.h
@@ -208,6 +208,25 @@ enum {
#define DLT_SIZE_WTMS (sizeof(uint32_t))
/**
+ * Definitions for GET_LOG_INFO
+ */
+#define DLT_RECEIVE_TEXTBUFSIZE 1024 /* Size of buffer for text output */
+#define DLT_GET_LOG_INFO_HEADER 18 /*Get log info header size in response text */
+#define GET_LOG_INFO_LENGTH 13
+#define SERVICE_OPT_LENGTH 3
+
+/* checks if received size is big enough for expected data */
+#define DLT_CHECK_RCV_DATA_SIZE(received, required) \
+ ({ \
+ int _ret = DLT_RETURN_OK; \
+ if (((int)received - (int)required) < 0) { \
+ dlt_vlog(LOG_WARNING, "%s: Received data not complete\n", __func__); \
+ _ret = DLT_RETURN_ERROR; \
+ } \
+ _ret; \
+ })
+
+/**
* Get the size of extra header parameters, depends on htyp.
*/
#define DLT_STANDARD_HEADER_EXTRA_SIZE(htyp) ( (DLT_IS_HTYP_WEID(htyp) ? DLT_SIZE_WEID : 0) + (DLT_IS_HTYP_WSID(htyp) ? DLT_SIZE_WSID : 0) + (DLT_IS_HTYP_WTMS(htyp) ? DLT_SIZE_WTMS : 0) )
@@ -452,6 +471,46 @@ typedef struct
char com[DLT_ID_SIZE]; /**< communication interface */
} PACKED DltServiceGetLogInfoRequest;
+typedef struct
+{
+ uint32_t service_id; /**< service ID */
+} PACKED DltServiceGetDefaultLogLevelRequest;
+
+/**
+ * The structure of the DLT Service Get Log Info response.
+ */
+typedef struct
+{
+ char context_id[DLT_ID_SIZE];
+ int16_t log_level;
+ int16_t trace_status;
+ uint16_t len_context_description;
+ char *context_description;
+} ContextIDsInfoType;
+
+typedef struct
+{
+ char app_id[DLT_ID_SIZE];
+ uint16_t count_context_ids;
+ ContextIDsInfoType *context_id_info; /**< holds info about a specific con id */
+ uint16_t len_app_description;
+ char *app_description;
+} AppIDsType;
+
+typedef struct
+{
+ uint16_t count_app_ids;
+ AppIDsType *app_ids; /**< holds info about a specific app id */
+} LogInfoType;
+
+typedef struct
+{
+ uint32_t service_id; /**< service ID */
+ uint8_t status; /**< type of request */
+ LogInfoType log_info_type; /**< log info type */
+ char com[DLT_ID_SIZE]; /**< communication interface */
+} DltServiceGetLogInfoResponse;
+
/**
* The structure of the DLT Service Set Log Level.
*/
@@ -1396,6 +1455,50 @@ extern "C"
*/
void dlt_check_envvar();
+ /**
+ * Parse the response text and identifying service id and its options.
+ *
+ * @param resp_text char *
+ * @param service_id int *
+ * @param service_opt int *
+ * @return pointer to resp_text
+ */
+ int dlt_set_loginfo_parse_service_id(char *resp_text, uint32_t *service_id, uint8_t *service_opt);
+
+ /**
+ * Convert get log info from ASCII to uint16
+ *
+ * @param rp char
+ * @param rp_count int
+ * @return length
+ */
+ int16_t dlt_getloginfo_conv_ascii_to_uint16_t(char *rp, int *rp_count);
+
+ /**
+ * Convert get log info from ASCII to int16
+ *
+ * @param rp char
+ * @param rp_count int
+ * @return length
+ */
+ int16_t dlt_getloginfo_conv_ascii_to_int16_t(char *rp, int *rp_count);
+
+ /**
+ * Convert get log info from ASCII to ID
+ *
+ * @param rp char
+ * @param rp_count int
+ */
+ void dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len);
+
+ /**
+ * Convert from hex ASCII to binary
+ * @param ptr const char
+ * @param binary uint8_t
+ * @param size int
+ */
+ void dlt_hex_ascii_to_binary(const char *ptr, uint8_t *binary, int *size);
+
#ifndef DLT_USE_UNIX_SOCKET_IPC
/**
* Create the specified path, recursive if necessary
diff --git a/include/dlt/dlt_protocol.h b/include/dlt/dlt_protocol.h
index 7c194b1..53dea25 100644
--- a/include/dlt/dlt_protocol.h
+++ b/include/dlt/dlt_protocol.h
@@ -221,6 +221,15 @@
#define DLT_CONNECTION_STATUS_DISCONNECTED 0x01 /**< Client is disconnected */
#define DLT_CONNECTION_STATUS_CONNECTED 0x02 /**< Client is connected */
+/*
+ * Definitions of DLT GET_LOG_INFO status
+ */
+#define GET_LOG_INFO_STATUS_MIN 3
+#define GET_LOG_INFO_STATUS_MAX 7
+#define GET_LOG_INFO_STATUS_NO_MATCHING_CTX 8
+#define GET_LOG_INFO_STATUS_RESP_DATA_OVERFLOW 9
+
+
/**
\}
*/
diff --git a/src/console/dlt-control-common.c b/src/console/dlt-control-common.c
index d299c6d..127eb4b 100644
--- a/src/console/dlt-control-common.c
+++ b/src/console/dlt-control-common.c
@@ -69,7 +69,6 @@
#define DLT_CTRL_APID "DLTC"
#define DLT_CTRL_CTID "DLTC"
#define DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH "/tmp/dlt-ctrl.sock"
-#define DLT_RECEIVE_TEXTBUFSIZE 1024
/** @brief Analyze the daemon answer
*
diff --git a/src/console/dlt-control.c b/src/console/dlt-control.c
index 7e90c7c..4398b9d 100644
--- a/src/console/dlt-control.c
+++ b/src/console/dlt-control.c
@@ -65,7 +65,6 @@
#include "dlt_user.h"
#include "dlt-control-common.h"
-#define DLT_RECEIVE_TEXTBUFSIZE 10024 /* Size of buffer for text output */
#define DLT_GLOGINFO_APID_NUM_MAX 150
@@ -78,29 +77,11 @@
typedef struct
{
- char apid[DLT_ID_SIZE + 1]; /**< application id */
- char ctid[DLT_ID_SIZE + 1]; /**< context id */
- char *apid_desc; /**< apid description */
- char *ctid_desc; /**< ctxt description */
- int log_level; /**< log level */
- int trace_status; /**< trace_status */
- int disp; /**< display flag */
-} DltLoginfoDetail;
-
-typedef struct
-{
- DltLoginfoDetail info[DLT_GLOGINFO_DATA_MAX]; /**< structure for each ctxt/app entry*/
- int count; /**< Number of app and ctxt entries */
-} DltLoginfo;
-
-
-typedef struct
-{
uint32_t service_id; /**< service ID */
} PACKED DltServiceGetDefaultLogLevel;
DltClient g_dltclient;
-DltLoginfo g_get_loginfo;
+DltServiceGetLogInfoResponse *g_resp = NULL;
/* Function prototypes */
int dlt_receive_message_callback(DltMessage *message, void *data);
@@ -131,60 +112,6 @@ typedef struct {
} DltReceiveData;
-void hexAsciiToBinary (const char *ptr,uint8_t *binary,int *size)
-{
-
- char ch = *ptr;
- int pos = 0;
- binary[pos] = 0;
- int first = 1;
- int found;
-
- for(;;)
- {
-
- if(ch == 0)
- {
- *size = pos;
- return;
- }
-
-
- found = 0;
- if (ch >= '0' && ch <= '9')
- {
- binary[pos] = (binary[pos] << 4) + (ch - '0');
- found = 1;
- }
- else if (ch >= 'A' && ch <= 'F')
- {
- binary[pos] = (binary[pos] << 4) + (ch - 'A' + 10);
- found = 1;
- }
- else if (ch >= 'a' && ch <= 'f')
- {
- binary[pos] = (binary[pos] << 4) + (ch - 'a' + 10);
- found = 1;
- }
- if(found)
- {
- if(first)
- first = 0;
- else
- {
- first = 1;
- pos++;
- if(pos>=*size)
- return;
- binary[pos]=0;
- }
- }
-
- ch = *(++ptr);
- }
-
-}
-
/**
* Print usage information of tool.
*/
@@ -240,9 +167,19 @@ void usage()
void dlt_process_get_log_info(void)
{
char apid[DLT_ID_SIZE+1] = {0};
- int cnt;
+ char ctid[DLT_ID_SIZE+1] = {0};
+ AppIDsType app;
+ ContextIDsInfoType con;
+ int i = 0;
+ int j = 0;
+
+ g_resp = (DltServiceGetLogInfoResponse*) calloc(1, sizeof(DltServiceGetLogInfoResponse));
- dlt_getloginfo_init();
+ if (g_resp == NULL)
+ {
+ fprintf(stderr, "%s: Calloc failed for resp..\n", __func__);
+ return;
+ }
/* send control message*/
if (0 != dlt_client_get_log_info(&g_dltclient))
@@ -251,31 +188,43 @@ void dlt_process_get_log_info(void)
return;
}
- for (cnt = 0; cnt < g_get_loginfo.count; cnt++)
+ if (dlt_client_main_loop(&g_dltclient, NULL, 0) == DLT_RETURN_TRUE)
{
- if (strncmp(apid, g_get_loginfo.info[cnt].apid, DLT_ID_SIZE) != 0)
- {
- printf("APID:%4s ", g_get_loginfo.info[cnt].apid);
- apid[DLT_ID_SIZE] = 0;
- dlt_set_id(apid, g_get_loginfo.info[cnt].apid);
+ fprintf(stdout, "DLT-daemon's response is invalid.\n");
+ }
- if (g_get_loginfo.info[cnt].apid_desc != 0)
- {
- printf("%s\n", g_get_loginfo.info[cnt].apid_desc);
- }
- else
- {
- printf("\n");
- }
- }
+ for (i = 0; i < g_resp->log_info_type.count_app_ids; i++)
+ {
+ app = g_resp->log_info_type.app_ids[i];
+
+ dlt_set_id(apid, app.app_id);
- if (strncmp(apid, g_get_loginfo.info[cnt].apid, DLT_ID_SIZE) == 0)
+ if (app.app_description != 0)
{
- printf("%4s %2d %2d %s\n", g_get_loginfo.info[cnt].ctid, g_get_loginfo.info[cnt].log_level,
- g_get_loginfo.info[cnt].trace_status, g_get_loginfo.info[cnt].ctid_desc);
+ printf("APID:%4s %s\n", apid, app.app_description);
}
- }
- dlt_getloginfo_free();
+ else
+ {
+ printf("APID:%4s \n", apid);
+ }
+
+ for (j = 0; j < app.count_context_ids; j++)
+ {
+ con = app.context_id_info[j];
+
+ dlt_set_id(ctid, con.context_id);
+
+ printf("%4s %2d %2d %s\n",
+ ctid,
+ con.log_level,
+ con.trace_status,
+ con.context_description);
+ }
+ }
+
+ dlt_client_free_get_log_info(g_resp);
+ free(g_resp);
+ g_resp = NULL;
}
/**
@@ -437,7 +386,7 @@ int main(int argc, char* argv[])
}
case '?':
{
- if (optopt == 'o' || optopt == 'f')
+ if ((optopt == 'o') || (optopt == 'f'))
{
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
}
@@ -581,7 +530,7 @@ int main(int argc, char* argv[])
printf("ConId: %s\n",dltdata.cvalue);
printf("ServiceId: %d\n",dltdata.svalue);
printf("Message: %s\n",dltdata.xvalue);
- hexAsciiToBinary(dltdata.xvalue,buffer,&size);
+ dlt_hex_ascii_to_binary(dltdata.xvalue,buffer,&size);
printf("Size: %d\n",size);
/* send control message in hex */
if (dlt_client_send_inject_msg(&g_dltclient,
@@ -727,11 +676,11 @@ int main(int argc, char* argv[])
/* Wait timeout */
usleep(dltdata.tvalue*1000);
-
- /* Dlt Client Cleanup */
- dlt_client_cleanup(&g_dltclient,dltdata.vflag);
}
+ /* Dlt Client Cleanup */
+ dlt_client_cleanup(&g_dltclient,dltdata.vflag);
+
if (g_dltclient.socketPath != NULL)
free(g_dltclient.socketPath);
@@ -742,266 +691,10 @@ int main(int argc, char* argv[])
return 0;
}
-void dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len)
-{
- char number16[6]={0};
- char *endptr;
- int count;
-
- if ((rp == NULL) || (rp_count == NULL) || (wp == NULL))
- {
- return;
- }
- /* ------------------------------------------------------
- from: [72 65 6d 6f ] -> to: [0x72,0x65,0x6d,0x6f,0x00]
- ------------------------------------------------------ */
- number16[0] = '+';
- number16[1] = '0';
- number16[2] = 'x';
- for (count = 0; count < (len - 1); count++)
- {
- number16[3] = *(rp + *rp_count + 0);
- number16[4] = *(rp + *rp_count + 1);
- *(wp + count) = strtol(number16, &endptr, 16);
- *rp_count += 3;
- }
- *(wp + count) = 0;
- return;
-}
-
-uint16_t dlt_getloginfo_conv_ascii_to_uint16_t(char *rp, int *rp_count)
-{
- char num_work[8];
- char *endptr;
-
- if ((rp == NULL) || (rp_count == NULL))
- {
- return -1;
- }
- /* ------------------------------------------------------
- from: [89 13 ] -> to: ['+0x'1389\0] -> to num
- ------------------------------------------------------ */
- num_work[0] = '+';
- num_work[1] = '0';
- num_work[2] = 'x';
- num_work[3] = *(rp + *rp_count + 3);
- num_work[4] = *(rp + *rp_count + 4);
- num_work[5] = *(rp + *rp_count + 0);
- num_work[6] = *(rp + *rp_count + 1);
- num_work[7] = 0;
- *rp_count += 6;
-
- return strtol(num_work, &endptr, 16);
-}
-int16_t dlt_getloginfo_conv_ascii_to_int16_t(char *rp, int *rp_count)
-{
- char num_work[6];
- char *endptr;
-
- if ((rp == NULL) || (rp_count == NULL))
- {
- return -1;
- }
- /* ------------------------------------------------------
- from: [89 ] -> to: ['0x'89\0] -> to num
- ------------------------------------------------------ */
- num_work[0] = '0';
- num_work[1] = 'x';
- num_work[2] = *(rp + *rp_count + 0);
- num_work[3] = *(rp + *rp_count + 1);
- num_work[4] = 0;
- *rp_count += 3;
-
- return (signed char)strtol(num_work, &endptr, 16);
-}
-
-void dlt_getloginfo_init(void)
-{
- int cnt;
-
- g_get_loginfo.count = 0;
- for (cnt = 0; cnt < DLT_GLOGINFO_DATA_MAX; cnt++)
- {
- g_get_loginfo.info[cnt].apid_desc = NULL;
- g_get_loginfo.info[cnt].ctid_desc = NULL;
- }
-}
-
-void dlt_getloginfo_free(void)
-{
- int cnt;
-
- for (cnt = 0; cnt < DLT_GLOGINFO_DATA_MAX; cnt++)
- {
- if (g_get_loginfo.info[cnt].apid_desc != 0)
- {
- free(g_get_loginfo.info[cnt].apid_desc);
- }
- if (g_get_loginfo.info[cnt].ctid_desc != 0)
- {
- free(g_get_loginfo.info[cnt].ctid_desc);
- }
- }
-}
-
-/**
- * Function to parse the response text and identifying service id and its options.
- */
-int dlt_set_loginfo_parse_service_id(char *resp_text, int *service_id, int *service_opt, char *cb_result)
-{
- int ret;
- char get_log_info_tag[13];
- char service_opt_str[3];
-
- if ((resp_text == NULL) || (service_id == NULL) || (service_opt == NULL) || (cb_result == NULL))
- {
- return -1;
- }
- /* ascii type, syntax is 'get_log_info, ..' */
- /* check target id */
- strncpy(get_log_info_tag, "get_log_info", strlen("get_log_info"));
- ret = memcmp((void *)resp_text, (void *)get_log_info_tag, sizeof(get_log_info_tag)-1);
- if (ret == 0)
- {
- *service_id = DLT_SERVICE_ID_GET_LOG_INFO;
- *cb_result = 0;
- /* reading the response mode from the resp_text. eg. option 7*/
- service_opt_str[0] = *(resp_text+14);
- service_opt_str[1] = *(resp_text+15);
- service_opt_str[2] = 0;
- *service_opt = atoi( service_opt_str );
- }
-
- return ret;
-}
-
-/**
- * Main function to convert the response text in to proper get log info data and
- * filling it in the DltLoginfo structure.
- */
-int dlt_getloginfo_make_loginfo(char *resp_text, int service_opt)
-{
- char *rp;
- int rp_count;
- int loginfo_count;
- uint16_t reg_apid_count;
- uint16_t reg_ctid_count;
- uint16_t reg_apid_num;
- uint16_t reg_ctid_num;
- uint16_t reg_apid_dsc_len;
- uint16_t reg_ctid_dsc_len;
- char reg_apid[DLT_ID_SIZE+1];
- char reg_ctid[DLT_ID_SIZE+1];
- char *reg_apid_dsc;
- char *reg_ctid_dsc;
-
- if (resp_text == NULL)
- {
- return -1;
- }
- /* ------------------------------------------------------
- get_log_info data structure(all data is ascii)
-
- get_log_info, aa, bb bb cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. ..
- ~~ ~~~~~ ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~
- cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. ..
- jj jj kk kk kk .. ..
- ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~
- aa : get mode (fix value at 0x07)
- bb bb : list num of apid (little endian)
- cc cc cc cc: apid
- dd dd : list num of ctid (little endian)
- ee ee ee ee: ctid
- ff : log level
- gg : trase status
- hh hh : description length of ctid
- ii ii .. : description text of ctid
- jj jj : description length of apid
- kk kk .. : description text of apid
- ------------------------------------------------------ */
-
- /* create all target convert list */
-
- /* rp set header */
- rp = (resp_text + DLT_GET_LOG_INFO_HEADER);
- rp_count = 0;
- /* get reg_apid_num */
- reg_apid_num = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
- loginfo_count = g_get_loginfo.count;
-
- if (reg_apid_num > DLT_GLOGINFO_APID_NUM_MAX)
- {
- fprintf(stderr, "GET_LOG_INFO ERROR: APID MAX Over\n");
- g_get_loginfo.count = 0;
- return -1;
- }
-
- /* search for target apid */
- for (reg_apid_count = 0; reg_apid_count < reg_apid_num; reg_apid_count++)
- {
- /* get reg_apid */
- dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, reg_apid, DLT_ID_SIZE+1);
-
- /* get reg_ctid_num of current reg_apid */
- reg_ctid_num = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
- if (loginfo_count + reg_ctid_num > DLT_GLOGINFO_DATA_MAX)
- {
- fprintf(stderr, "GET_LOG_INFO ERROR: LOG DATA MAX Over\n");
- g_get_loginfo.count = 0;
- return -1;
- }
- for (reg_ctid_count = 0; reg_ctid_count < reg_ctid_num; reg_ctid_count++)
- {
- /* get reg_ctid */
- dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, reg_ctid, DLT_ID_SIZE+1);
-
- g_get_loginfo.info[ loginfo_count ].apid[DLT_ID_SIZE] = 0;
- dlt_set_id(g_get_loginfo.info[ loginfo_count ].apid, reg_apid);
- g_get_loginfo.info[ loginfo_count ].ctid[DLT_ID_SIZE] = 0;
- dlt_set_id(g_get_loginfo.info[ loginfo_count ].ctid, reg_ctid);
- g_get_loginfo.info[ loginfo_count ].log_level = dlt_getloginfo_conv_ascii_to_int16_t(rp, &rp_count);
- g_get_loginfo.info[ loginfo_count ].trace_status = dlt_getloginfo_conv_ascii_to_int16_t(rp, &rp_count);
-
- /* Description Information */
- if (service_opt == DLT_SERVICE_GET_LOG_INFO_OPT7)
- {
- reg_ctid_dsc_len = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
- reg_ctid_dsc = (char *)malloc(sizeof(char) * reg_ctid_dsc_len + 1);
- if (reg_ctid_dsc == 0)
- {
- fprintf(stderr, "malloc failed for ctxt desc\n");
- return -1;
- }
- dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, reg_ctid_dsc, reg_ctid_dsc_len+1);
- g_get_loginfo.info[ loginfo_count ].ctid_desc = reg_ctid_dsc;
- }
- loginfo_count++;
- }
- /* Description Information */
- if (service_opt == DLT_SERVICE_GET_LOG_INFO_OPT7)
- {
- reg_apid_dsc_len = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
- reg_apid_dsc = (char *)malloc(sizeof(char) * reg_apid_dsc_len + 1);
- if (reg_apid_dsc == 0)
- {
- fprintf(stderr, "malloc failed for apid desc\n");
- return -1;
- }
- dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, reg_apid_dsc, reg_apid_dsc_len+1);
- g_get_loginfo.info[ loginfo_count - reg_ctid_num ].apid_desc = reg_apid_dsc;
- }
- }
- g_get_loginfo.count = loginfo_count;
-
- return 0;
-}
-
int dlt_receive_message_callback(DltMessage *message, void *data)
{
static char resp_text[DLT_RECEIVE_TEXTBUFSIZE];
- int ret;
- int service_id;
- int service_opt;
+ int ret = DLT_RETURN_ERROR;
char cb_result;
/* parameter check */
@@ -1040,10 +733,17 @@ int dlt_receive_message_callback(DltMessage *message, void *data)
}
/* check service id */
- ret = dlt_set_loginfo_parse_service_id(resp_text, &service_id, &service_opt, &cb_result);
- if ((ret == 0) && (service_id == DLT_SERVICE_ID_GET_LOG_INFO ))
+ if (g_resp == NULL)
+ {
+ fprintf(stderr, "%s: g_resp isn't allocated.\n", __func__);
+ dlt_client_cleanup(&g_dltclient, 0);
+ return -1;
+ }
+
+ ret = dlt_set_loginfo_parse_service_id(resp_text, &g_resp->service_id, &g_resp->status, &cb_result);
+ if ((ret == 0) && (g_resp->service_id == DLT_SERVICE_ID_GET_LOG_INFO))
{
- ret = dlt_getloginfo_make_loginfo(resp_text, service_opt);
+ ret = dlt_client_parse_get_log_info_resp_text(g_resp, resp_text);
if (ret != 0)
{
diff --git a/src/console/dlt-receive.c b/src/console/dlt-receive.c
index a4aef2e..fd19f83 100644
--- a/src/console/dlt-receive.c
+++ b/src/console/dlt-receive.c
@@ -82,8 +82,6 @@
#include "dlt_client.h"
-#define DLT_RECEIVE_TEXTBUFSIZE 10024 /* Size of buffer for text output */
-
#define DLT_RECEIVE_ECU_ID "RECV"
/* Function prototypes */
diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt
index 063913b..9a22ccd 100644
--- a/src/daemon/CMakeLists.txt
+++ b/src/daemon/CMakeLists.txt
@@ -32,13 +32,13 @@ install(TARGETS dlt-daemon
COMPONENT base)
if (WITH_DLT_UNIT_TESTS)
- add_library(dlt_daemon ${dlt_daemon_SRCS} ${systemd_SRCS})
+ add_library(dlt_daemon ${dlt_daemon_SRCS})
target_link_libraries(dlt_daemon rt ${CMAKE_THREAD_LIBS_INIT})
install(TARGETS dlt_daemon
- RUNTIME DESTINATION bin
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/static
- COMPONENT base)
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/static
+ COMPONENT base)
endif(WITH_DLT_UNIT_TESTS)
INSTALL(FILES dlt.conf
diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c
index dd69326..bd3233f 100644
--- a/src/daemon/dlt_daemon_client.c
+++ b/src/daemon/dlt_daemon_client.c
@@ -68,17 +68,6 @@
#include "dlt_daemon_offline_logstorage.h"
#include "dlt_gateway.h"
-/* checks if received size is big enough for expected data */
-#define DLT_CHECK_RCV_DATA_SIZE(received, required) \
- ({ \
- int _ret = DLT_RETURN_OK; \
- if (((int)received - (int)required) < 0) { \
- dlt_vlog(LOG_WARNING, "%s: Received data not complete\n", __func__); \
- _ret = DLT_RETURN_ERROR; \
- } \
- _ret; \
- })
-
/** Global text output buffer, mainly used for creation of error/warning strings */
static char str[DLT_DAEMON_TEXTBUFSIZE];
diff --git a/src/daemon/dlt_daemon_offline_logstorage.c b/src/daemon/dlt_daemon_offline_logstorage.c
index fe4d8a7..109cc73 100644
--- a/src/daemon/dlt_daemon_offline_logstorage.c
+++ b/src/daemon/dlt_daemon_offline_logstorage.c
@@ -347,15 +347,47 @@ STATIC DltReturnValue dlt_daemon_logstorage_update_passive_node_context(
int loglevel,
int verbose)
{
- // Need to be updated
- // To avoid compiler warning
- (void) daemon_local;
- (void) apid;
- (void) ctid;
- (void) ecuid;
- (void) loglevel;
- (void) verbose;
+ DltServiceSetLogLevel req = {0};
+ DltPassiveControlMessage ctrl = {0};
+ DltGatewayConnection *con = NULL;
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if ((daemon_local == NULL) || (apid == NULL) || (ctid == NULL) || (ecuid == NULL) ||
+ (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT))
+ {
+ dlt_vlog(LOG_ERR, "%s: Wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ con = dlt_gateway_get_connection(&daemon_local->pGateway, ecuid, verbose);
+
+ if (con == NULL)
+ {
+ dlt_vlog(LOG_ERR,
+ "Failed to fond connection to passive node %s\n",
+ ecuid);
+ return DLT_RETURN_ERROR;
+ }
+
+ ctrl.id = DLT_SERVICE_ID_SET_LOG_LEVEL;
+ ctrl.type = CONTROL_MESSAGE_ON_DEMAND;
+
+ dlt_set_id(req.apid, apid);
+ dlt_set_id(req.ctid, ctid);
+
+ req.log_level = loglevel;
+
+ if (dlt_gateway_send_control_message(con, &ctrl, (void *) &req, verbose) != 0)
+ {
+ dlt_vlog(LOG_ERR,
+ "Failed to forward SET_LOG_LEVEL message to passive node %s\n",
+ ecuid);
+
+ return DLT_RETURN_ERROR;
+ }
+
+ return DLT_RETURN_OK;
return DLT_RETURN_OK;
}
diff --git a/src/gateway/dlt_gateway.c b/src/gateway/dlt_gateway.c
index dda1833..411630b 100644
--- a/src/gateway/dlt_gateway.c
+++ b/src/gateway/dlt_gateway.c
@@ -20,8 +20,9 @@
/*!
* \author
* Christoph Lipka <clipka@jp.adit-jv.com>
+ * Saya Sugiura <ssugiura@jp.adit-jv.com>
*
- * \copyright Copyright © 2015 Advanced Driver Information Technology. \n
+ * \copyright Copyright © 2015-2017 Advanced Driver Information Technology. \n
* License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
*
* \file dlt_gateway.c
@@ -41,16 +42,17 @@
#include "dlt_config_file_parser.h"
#include "dlt_common.h"
#include "dlt-daemon_cfg.h"
+#include "dlt_daemon_common_cfg.h"
#include "dlt_daemon_event_handler.h"
#include "dlt_daemon_connection.h"
#include "dlt_daemon_client.h"
+#include "dlt_daemon_offline_logstorage.h"
typedef struct {
char *key; /* The configuration key*/
int (*func)(DltGatewayConnection *con, char *value); /* Conf handler */
int is_opt; /* If the configuration is optional or not */
} DltGatewayConf;
-#ifndef DLT_UNIT_TESTS
typedef enum {
GW_CONF_IP_ADDRESS = 0,
GW_CONF_PORT,
@@ -58,10 +60,11 @@ typedef enum {
GW_CONF_CONNECT,
GW_CONF_TIMEOUT,
GW_CONF_SEND_CONTROL,
+ GW_CONF_SEND_PERIODIC_CONTROL,
GW_CONF_SEND_SERIAL_HEADER,
GW_CONF_COUNT
} DltGatewayConfType;
-#endif
+
/**
* Check if given string is a valid IP address
*
@@ -72,11 +75,12 @@ typedef enum {
STATIC int dlt_gateway_check_ip(DltGatewayConnection *con, char *value)
{
struct sockaddr_in sa;
- int ret = -1;
+ int ret = DLT_RETURN_ERROR;
- if (con == NULL || value == NULL)
+ if ((con == NULL) || (value == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
ret = inet_pton(AF_INET, value, &(sa.sin_addr));
@@ -89,17 +93,17 @@ STATIC int dlt_gateway_check_ip(DltGatewayConnection *con, char *value)
if (con->ip_address == NULL)
{
dlt_log(LOG_ERR, "Cannot copy passive node IP address string\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
- return 0;
+ return DLT_RETURN_OK;
}
else
{
dlt_log(LOG_ERR, "IP address is not valid\n");
}
- return -1;
+ return DLT_RETURN_ERROR;
}
/**
@@ -113,25 +117,26 @@ STATIC int dlt_gateway_check_port(DltGatewayConnection *con, char *value)
{
int tmp = -1;
- if (con == NULL || value == NULL)
+ if ((con == NULL) || (value == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
tmp = (int) strtol(value, NULL, 10);
/* port ranges for unprivileged applications */
- if (tmp > IPPORT_RESERVED && tmp <= USHRT_MAX)
+ if ((tmp > IPPORT_RESERVED) && (tmp <= USHRT_MAX))
{
con->port = tmp;
- return 0;
+ return DLT_RETURN_OK;
}
else
{
dlt_log(LOG_ERR, "Port number is invalid\n");
}
- return -1;
+ return DLT_RETURN_ERROR;
}
/**
@@ -143,19 +148,20 @@ STATIC int dlt_gateway_check_port(DltGatewayConnection *con, char *value)
*/
STATIC int dlt_gateway_check_ecu(DltGatewayConnection *con, char *value)
{
- if (con == NULL || value == NULL)
+ if ((con == NULL) || (value == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
con->ecuid = strdup(value);
if (con->ecuid == NULL)
{
- return -1;
+ return DLT_RETURN_ERROR;
}
- return 0;
+ return DLT_RETURN_OK;
}
/**
@@ -168,9 +174,10 @@ STATIC int dlt_gateway_check_ecu(DltGatewayConnection *con, char *value)
STATIC int dlt_gateway_check_connect_trigger(DltGatewayConnection *con,
char *value)
{
- if (con == NULL || value == NULL)
+ if ((con == NULL) || (value == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
if (strncasecmp(value, "OnStartup", strlen("OnStartup")) == 0)
@@ -185,10 +192,10 @@ STATIC int dlt_gateway_check_connect_trigger(DltGatewayConnection *con,
{
dlt_log(LOG_ERR, "Wrong connection trigger state given.\n");
con->trigger = DLT_GATEWAY_UNDEFINED;
- return -1;
+ return DLT_RETURN_ERROR;
}
- return 0;
+ return DLT_RETURN_OK;
}
/**
@@ -200,19 +207,20 @@ STATIC int dlt_gateway_check_connect_trigger(DltGatewayConnection *con,
*/
STATIC int dlt_gateway_check_timeout(DltGatewayConnection *con, char *value)
{
- if (con == NULL || value == NULL)
+ if ((con == NULL) || (value == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
con->timeout = (int) strtol(value, NULL, 10);
if (con->timeout > 0)
{
- return 0;
+ return DLT_RETURN_OK;
}
- return -1;
+ return DLT_RETURN_ERROR;
}
/**
@@ -224,14 +232,57 @@ STATIC int dlt_gateway_check_timeout(DltGatewayConnection *con, char *value)
*/
STATIC int dlt_gateway_check_send_serial(DltGatewayConnection *con, char *value)
{
- if (con == NULL || value == NULL)
+ if ((con == NULL) || (value == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
con->send_serial = !!((int) strtol(value, NULL, 10));
- return 0;
+ return DLT_RETURN_OK;
+}
+
+/**
+ * Allocate passive control messages
+ *
+ * @param con DltGatewayConnection to be updated
+ * @return 0 on success, -1 otherwise
+ */
+STATIC int dlt_gateway_allocate_control_messages(DltGatewayConnection *con)
+{
+ if (con == NULL)
+ {
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ if (con->p_control_msgs == NULL)
+ {
+ con->p_control_msgs = calloc(1, sizeof(DltPassiveControlMessage));
+
+ if (!con->p_control_msgs)
+ {
+ dlt_log(LOG_ERR,
+ "Passive Control Message could not be allocated\n");
+ return DLT_RETURN_ERROR;
+ }
+ }
+ else
+ {
+ con->p_control_msgs->next = calloc(1, sizeof(DltPassiveControlMessage));
+
+ if (!con->p_control_msgs->next)
+ {
+ dlt_log(LOG_ERR,
+ "Passive Control Message could not be allocated\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ con->p_control_msgs = con->p_control_msgs->next;
+ }
+
+ return DLT_RETURN_OK;
}
/**
@@ -247,51 +298,202 @@ STATIC int dlt_gateway_check_control_messages(DltGatewayConnection *con,
/* list of allowed clients given */
char *token = NULL;
char *rest = NULL;
- int i = 0;
- char error_msg[DLT_DAEMON_TEXTBUFSIZE];
+ DltPassiveControlMessage *head = NULL;
- if (con == NULL || value == NULL)
+ if ((con == NULL) || (value == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
if (strlen(value) == 0)
{
- memset(con->control_msgs,
- 0,
- sizeof(int) * DLT_GATEWAY_MAX_STARTUP_CTRL_MSG);
- return 0;
+ return DLT_RETURN_OK;
}
+ /* set on startup control msg id and interval*/
token = strtok_r(value, ",", &rest);
- while (token != NULL && i < DLT_GATEWAY_MAX_STARTUP_CTRL_MSG)
+
+ while (token != NULL)
{
+ if (dlt_gateway_allocate_control_messages(con) == -1)
+ {
+ dlt_log(LOG_ERR,
+ "Passive Control Message could not be allocated\n");
+ return DLT_RETURN_ERROR;
+ }
- con->control_msgs[i] = strtol(token, NULL, 16);
+ con->p_control_msgs->id = strtol(token, NULL, 16);
+ con->p_control_msgs->user_id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECT;
+ con->p_control_msgs->type = CONTROL_MESSAGE_ON_STARTUP;
+ con->p_control_msgs->req = CONTROL_MESSAGE_NOT_REQUESTED;
+ con->p_control_msgs->interval = -1;
- if (errno == EINVAL || errno == ERANGE)
+ if (head == NULL)
{
- snprintf(error_msg,
- DLT_DAEMON_TEXTBUFSIZE-1,
- "Control message ID is not an integer: %s\n", token);
- dlt_log(LOG_ERR, error_msg);
- return -1;
+ head = con->p_control_msgs;
}
- else if (con->control_msgs[i] < DLT_SERVICE_ID_SET_LOG_LEVEL ||
- con->control_msgs[i] >= DLT_SERVICE_ID_LAST_ENTRY)
+
+ if ((errno == EINVAL) || (errno == ERANGE))
{
- snprintf(error_msg,
- DLT_DAEMON_TEXTBUFSIZE-1,
- "Control message ID is not valid: %s\n", token);
- dlt_log(LOG_ERR, error_msg);
- return -1;
+ dlt_vlog(LOG_ERR,
+ "Control message ID is not an integer: %s\n",
+ token);
+ return DLT_RETURN_ERROR;
+ }
+ else if ((con->p_control_msgs->id < DLT_SERVICE_ID_SET_LOG_LEVEL) ||
+ (con->p_control_msgs->id >= DLT_SERVICE_ID_LAST_ENTRY))
+ {
+ dlt_vlog(LOG_ERR,
+ "Control message ID is not valid: %s\n",
+ token);
+ return DLT_RETURN_ERROR;
+ }
+
+ token = strtok_r(NULL, ",", &rest);
+ }
+
+ /* get back to head */
+ con->p_control_msgs = head;
+ con->head = head;
+
+ return DLT_RETURN_OK;
+}
+
+/**
+ * Check the specified periodic control messages identifier
+ *
+ * @param con DltGatewayConnection to be updated
+ * @param value string to be tested
+ * @return 0 on success, -1 otherwise
+ */
+STATIC int dlt_gateway_check_periodic_control_messages(DltGatewayConnection *con,
+ char *value)
+{
+ char *token = NULL;
+ char *rest = NULL;
+ DltPassiveControlMessage *head = NULL;
+
+ if ((con == NULL) || (value == NULL))
+ {
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ if (strlen(value) == 0)
+ {
+ return DLT_RETURN_OK;
+ }
+
+ /* store head address */
+ head = con->p_control_msgs;
+
+ /* set periodic control msg id and interval*/
+ token = strtok_r(value, ",", &rest);
+
+ while (token != NULL)
+ {
+ char *p_token = NULL;
+ char *p_rest = NULL;
+ uint32_t id = 0;
+
+ p_token = strtok_r(token, ":", &p_rest);
+
+ if ((p_token != NULL) && (strlen(p_token) != 0))
+ {
+ id = strtol(p_token, NULL, 16);
+
+ /* get back to head */
+ con->p_control_msgs = head;
+
+ /* check if there is already id set in p_control_msgs */
+ while (con->p_control_msgs != NULL)
+ {
+ if (con->p_control_msgs->id == id)
+ {
+ con->p_control_msgs->type = CONTROL_MESSAGE_BOTH;
+ con->p_control_msgs->interval = strtol(p_rest, NULL, 10);
+ if (con->p_control_msgs->interval <= 0)
+ {
+ dlt_vlog(LOG_WARNING,
+ "%s interval is %d. It won't be send periodically.\n",
+ dlt_get_service_name(con->p_control_msgs->id),
+ con->p_control_msgs->interval);
+ }
+ break;
+ }
+
+ con->p_control_msgs = con->p_control_msgs->next;
+ }
+
+ /* if the id is not added yet, p_control_msgs supposed to be NULL */
+ if (con->p_control_msgs == NULL)
+ {
+ /* get back to head */
+ con->p_control_msgs = head;
+
+ /* go to last pointer */
+ while (con->p_control_msgs != NULL)
+ {
+ if (con->p_control_msgs->next == NULL)
+ {
+ break;
+ }
+
+ con->p_control_msgs = con->p_control_msgs->next;
+ }
+
+ if (dlt_gateway_allocate_control_messages(con) == -1)
+ {
+ dlt_log(LOG_ERR,
+ "Passive Control Message could not be allocated\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ con->p_control_msgs->id = id;
+ con->p_control_msgs->user_id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECT;
+ con->p_control_msgs->type = CONTROL_MESSAGE_PERIODIC;
+ con->p_control_msgs->req = CONTROL_MESSAGE_NOT_REQUESTED;
+ con->p_control_msgs->interval = strtol(p_rest, NULL, 10);
+ if (con->p_control_msgs->interval <= 0)
+ {
+ dlt_vlog(LOG_WARNING,
+ "%s interval is %d. It won't be send periodically.\n",
+ dlt_get_service_name(con->p_control_msgs->id),
+ con->p_control_msgs->interval);
+ }
+
+ if (head == NULL)
+ {
+ head = con->p_control_msgs;
+ }
+ }
+ }
+
+ if ((errno == EINVAL) || (errno == ERANGE))
+ {
+ dlt_vlog(LOG_ERR,
+ "Control message ID is not an integer: %s\n",
+ p_token);
+ return DLT_RETURN_ERROR;
+ }
+ else if ((con->p_control_msgs->id < DLT_SERVICE_ID_SET_LOG_LEVEL) ||
+ (con->p_control_msgs->id >= DLT_SERVICE_ID_LAST_ENTRY))
+ {
+ dlt_vlog(LOG_ERR,
+ "Control message ID is not valid: %s\n",
+ p_token);
+ return DLT_RETURN_ERROR;
}
token = strtok_r(NULL, ",", &rest);
- i++;
}
- return 0;
+ /* get back to head */
+ con->p_control_msgs = head;
+ con->head = head;
+
+ return DLT_RETURN_OK;
}
/**
@@ -325,6 +527,10 @@ STATIC DltGatewayConf configuration_entries[GW_CONF_COUNT] =
.key = "SendControl",
.func = dlt_gateway_check_control_messages,
.is_opt = 1 },
+ [GW_CONF_SEND_PERIODIC_CONTROL] = {
+ .key = "SendPeriodicControl",
+ .func = dlt_gateway_check_periodic_control_messages,
+ .is_opt = 1 },
[GW_CONF_SEND_SERIAL_HEADER] = {
.key = "SendSerialHeader",
.func = dlt_gateway_check_send_serial,
@@ -347,15 +553,16 @@ STATIC int dlt_gateway_check_param(DltGateway *gateway,
DltGatewayConfType ctype,
char *value)
{
- if (gateway == NULL || con == NULL || value == NULL)
+ if ((gateway == NULL) || (con == NULL) || (value == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
if (ctype < GW_CONF_COUNT)
return configuration_entries[ctype].func(con, value);
- return -1;
+ return DLT_RETURN_ERROR;
}
/**
@@ -371,13 +578,13 @@ int dlt_gateway_store_connection(DltGateway *gateway,
int verbose)
{
int i = 0;
- int ret = 0;
PRINT_FUNCTION_VERBOSE(verbose);
- if (gateway == NULL || tmp == NULL)
+ if ((gateway == NULL) || (tmp == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
/* find next free entry in connection array */
@@ -391,9 +598,9 @@ int dlt_gateway_store_connection(DltGateway *gateway,
i++;
}
- if (&gateway->connections[i] == NULL)
+ if (&(gateway->connections[i]) == NULL)
{
- return -1;
+ return DLT_RETURN_ERROR;
}
/* store values */
@@ -407,9 +614,8 @@ int dlt_gateway_store_connection(DltGateway *gateway,
gateway->connections[i].timeout = tmp->timeout;
gateway->connections[i].handle = 0;
gateway->connections[i].status = DLT_GATEWAY_INITIALIZED;
- memcpy(gateway->connections[i].control_msgs,
- tmp->control_msgs,
- sizeof(tmp->control_msgs));
+ gateway->connections[i].p_control_msgs = tmp->p_control_msgs;
+ gateway->connections[i].head = tmp->head;
gateway->connections[i].send_serial = tmp->send_serial;
if (dlt_client_init_port(&gateway->connections[i].client,
@@ -417,9 +623,13 @@ int dlt_gateway_store_connection(DltGateway *gateway,
verbose) != 0)
{
free(gateway->connections[i].ip_address);
+ gateway->connections[i].ip_address = NULL;
free(gateway->connections[i].ecuid);
- dlt_log(LOG_CRIT, "dlt_client_init() failed for gateway connection\n");
- return -1;
+ gateway->connections[i].ecuid = NULL;
+ free(gateway->connections[i].p_control_msgs);
+ gateway->connections[i].p_control_msgs = NULL;
+ dlt_log(LOG_CRIT, "dlt_client_init_port() failed for gateway connection\n");
+ return DLT_RETURN_ERROR;
}
dlt_receiver_init(&gateway->connections[i].client.receiver,
gateway->connections[i].client.sock,
@@ -430,18 +640,10 @@ int dlt_gateway_store_connection(DltGateway *gateway,
{
dlt_log(LOG_ERR,
"dlt_client_set_server_ip() failed for gateway connection \n");
- return -1;
+ return DLT_RETURN_ERROR;
}
- if (ret != 0)
- {
- free(gateway->connections[i].ip_address);
- free(gateway->connections[i].ecuid);
- dlt_log(LOG_ERR, "Gateway: DltClient initialization failed\n");
- return -1;
- }
-
- return 0;
+ return DLT_RETURN_OK;
}
/**
@@ -460,9 +662,10 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose)
PRINT_FUNCTION_VERBOSE(verbose);
- if (gateway == NULL || config_file == 0 || config_file[0] == '\0')
+ if ((gateway == NULL) || (config_file == 0) || (config_file[0] == '\0'))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
/* read configuration file */
@@ -475,7 +678,7 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose)
{
dlt_config_file_release(file);
dlt_log(LOG_ERR, "Invalid number of sections in configuration file\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
gateway->connections = calloc(sizeof(DltGatewayConnection),
@@ -485,12 +688,11 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose)
{
dlt_config_file_release(file);
dlt_log(LOG_CRIT, "Memory allocation for gateway connections failed\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
for (i = 0; i < gateway->num_connections; i++)
{
- char local_str[DLT_DAEMON_TEXTBUFSIZE] = { '\0' };
DltGatewayConnection tmp;
int invalid = 0;
DltGatewayConfType j = 0;
@@ -515,20 +717,16 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose)
if ((ret != 0) && configuration_entries[j].is_opt)
{
/* Use default values for this key */
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
+ dlt_vlog(LOG_WARNING,
"Using default for %s.\n",
configuration_entries[j].key);
- dlt_log(LOG_WARNING, local_str);
continue;
}
else if (ret != 0)
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
+ dlt_vlog(LOG_WARNING,
"Missing configuration for %s.\n",
configuration_entries[j].key);
- dlt_log(LOG_WARNING, local_str);
invalid = 1;
break;
}
@@ -538,22 +736,19 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose)
if (ret != 0)
{
- sprintf(local_str,
- "Configuration %s = %s is invalid.\n"
- "Using default.\n",
- configuration_entries[j].key, value);
- dlt_log(LOG_ERR, local_str);
+ dlt_vlog(LOG_ERR,
+ "Configuration %s = %s is invalid.\n"
+ "Using default.\n",
+ configuration_entries[j].key, value);
}
}
if (invalid)
{
- memset(local_str, 0, DLT_DAEMON_TEXTBUFSIZE);
- sprintf(local_str,
- "%s configuration is invalid.\n"
- "Ignoring.\n",
- section);
- dlt_log(LOG_ERR, local_str);
+ dlt_vlog(LOG_ERR,
+ "%s configuration is invalid.\n"
+ "Ignoring.\n",
+ section);
}
else
{
@@ -567,7 +762,9 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose)
/* strdup used inside some get_value function */
free(tmp.ecuid);
+ tmp.ecuid = NULL;
free(tmp.ip_address);
+ tmp.ip_address = NULL;
}
dlt_config_file_release(file);
@@ -580,7 +777,8 @@ int dlt_gateway_init(DltDaemonLocal *daemon_local, int verbose)
if (daemon_local == NULL)
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
DltGateway *gateway = &daemon_local->pGateway;
@@ -595,27 +793,29 @@ int dlt_gateway_init(DltDaemonLocal *daemon_local, int verbose)
verbose) != 0)
{
dlt_log(LOG_ERR, "Gateway initialization failed\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
}
else
{
dlt_log(LOG_CRIT, "Pointer to Gateway structure is NULL\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
/* ignore return value */
dlt_gateway_establish_connections(gateway, daemon_local, verbose);
- return 0;
+ return DLT_RETURN_OK;
}
void dlt_gateway_deinit(DltGateway *gateway, int verbose)
{
+ DltPassiveControlMessage *msg;
int i = 0;
if (gateway == NULL)
{
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
return;
}
@@ -626,11 +826,91 @@ void dlt_gateway_deinit(DltGateway *gateway, int verbose)
DltGatewayConnection *c = &gateway->connections[i];
dlt_client_cleanup(&c->client, verbose);
free(c->ip_address);
+ c->ip_address = NULL;
free(c->ecuid);
+ c->ecuid = NULL;
+ while (c->p_control_msgs != NULL)
+ {
+ msg = c->p_control_msgs->next;
+ free(c->p_control_msgs);
+ c->p_control_msgs = msg;
+ }
}
free(gateway->connections);
- free(gateway);
+ gateway->connections = NULL;
+}
+
+/**
+ * If connection to passive node established, add to event loop
+ *
+ * @param daemon_local DltDaemonLocal
+ * @param con DltGatewayConnection
+ * @param verbose verbose flag
+ * @return 0 on success, -1 otherwise
+ */
+STATIC int dlt_gateway_add_to_event_loop(DltDaemonLocal *daemon_local,
+ DltGatewayConnection *con,
+ int verbose)
+{
+ DltPassiveControlMessage *control_msg = NULL;
+ int sendtime = 1;
+
+ if ((daemon_local == NULL) || (con == NULL))
+ {
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ /* connection to passive node established, add to event loop */
+ con->status = DLT_GATEWAY_CONNECTED;
+ con->reconnect_cnt = 0;
+ con->timeout_cnt = 0;
+ con->sendtime_cnt = 0;
+
+ /* setup dlt connection and add to epoll event loop here */
+ if (dlt_connection_create(daemon_local,
+ &daemon_local->pEvent,
+ con->client.sock,
+ EPOLLIN,
+ DLT_CONNECTION_GATEWAY) != 0)
+ {
+ dlt_log(LOG_ERR, "Gateway connection creation failed\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ /* immediately send configured control messages */
+ control_msg = con->p_control_msgs;
+
+ while (control_msg != NULL)
+ {
+ if ((control_msg->type == CONTROL_MESSAGE_ON_STARTUP) ||
+ (control_msg->type == CONTROL_MESSAGE_BOTH))
+ {
+ if (dlt_gateway_send_control_message(con,
+ control_msg,
+ NULL,
+ verbose) == DLT_RETURN_OK)
+ {
+ control_msg->req = CONTROL_MESSAGE_REQUESTED;
+ }
+ }
+
+ /* multiply periodic sending time */
+ if (((control_msg->type == CONTROL_MESSAGE_PERIODIC) ||
+ (control_msg->type == CONTROL_MESSAGE_BOTH)) &&
+ (control_msg->interval > 0))
+ {
+ sendtime *= control_msg->interval;
+ }
+ control_msg = control_msg->next;
+ }
+
+ /* set periodic sending time */
+ con->sendtime = sendtime;
+ con->sendtime_cnt = con->sendtime;
+
+ return DLT_RETURN_OK;
}
int dlt_gateway_establish_connections(DltGateway *gateway,
@@ -642,50 +922,37 @@ int dlt_gateway_establish_connections(DltGateway *gateway,
PRINT_FUNCTION_VERBOSE(verbose);
- if (gateway == NULL || daemon_local == NULL)
+ if ((gateway == NULL) || (daemon_local == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
for (i = 0; i < gateway->num_connections; i++)
{
DltGatewayConnection *con = &(gateway->connections[i]);
+ DltPassiveControlMessage *control_msg = NULL;
+
if (con == NULL)
{
dlt_log(LOG_CRIT, "Cannot retrieve gateway connection details\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
- if (con->status != DLT_GATEWAY_CONNECTED &&
- con->trigger != DLT_GATEWAY_ON_DEMAND &&
- con->trigger != DLT_GATEWAY_DISABLED)
+ if ((con->status != DLT_GATEWAY_CONNECTED) &&
+ (con->trigger != DLT_GATEWAY_ON_DEMAND) &&
+ (con->trigger != DLT_GATEWAY_DISABLED))
{
ret = dlt_client_connect(&con->client, verbose);
if (ret == 0)
{
- /* connection to passive node established, add to event loop */
- con->status = DLT_GATEWAY_CONNECTED;
- con->reconnect_cnt = 0;
- con->timeout_cnt = 0;
-
/* setup dlt connection and add to epoll event loop here */
- if (dlt_connection_create(daemon_local,
- &daemon_local->pEvent,
- con->client.sock,
- EPOLLIN,
- DLT_CONNECTION_GATEWAY) != 0)
+ if (dlt_gateway_add_to_event_loop(daemon_local, con, verbose) != DLT_RETURN_OK)
{
dlt_log(LOG_ERR, "Gateway connection creation failed\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
-
- /* immediately send configured control messages */
- dlt_gateway_send_control_message(con,
- gateway,
- daemon_local,
- verbose);
-
}
else
{
@@ -702,9 +969,53 @@ int dlt_gateway_establish_connections(DltGateway *gateway,
}
}
}
+ else if ((con->status == DLT_GATEWAY_CONNECTED) &&
+ (con->trigger != DLT_GATEWAY_DISABLED))
+ {
+ /* setup dlt connection and add to epoll event loop here */
+ if (dlt_connection_create(daemon_local,
+ &daemon_local->pEvent,
+ con->client.sock,
+ EPOLLIN,
+ DLT_CONNECTION_GATEWAY) != 0)
+ {
+ dlt_log(LOG_ERR, "Gateway connection creation failed\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ /* immediately send periodic configured control messages */
+ control_msg = con->p_control_msgs;
+
+ while (control_msg != NULL)
+ {
+ if ((control_msg->type == CONTROL_MESSAGE_PERIODIC) ||
+ (control_msg->type == CONTROL_MESSAGE_BOTH))
+ {
+ if (dlt_gateway_send_control_message(con,
+ control_msg,
+ NULL,
+ verbose) == DLT_RETURN_OK)
+ {
+ control_msg->req = CONTROL_MESSAGE_REQUESTED;
+ }
+ }
+ control_msg = control_msg->next;
+ }
+
+ /* check sendtime counter */
+ if (con->sendtime_cnt > 0)
+ {
+ con->sendtime_cnt--;
+ }
+
+ if (con->sendtime_cnt == 0)
+ {
+ con->sendtime_cnt = con->sendtime;
+ }
+ }
}
- return 0;
+ return DLT_RETURN_OK;
}
DltReceiver *dlt_gateway_get_connection_receiver(DltGateway *gateway, int fd)
@@ -713,6 +1024,7 @@ DltReceiver *dlt_gateway_get_connection_receiver(DltGateway *gateway, int fd)
if (gateway == NULL)
{
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
return NULL;
}
@@ -728,6 +1040,238 @@ DltReceiver *dlt_gateway_get_connection_receiver(DltGateway *gateway, int fd)
return NULL;
}
+/**
+ * Parse GET_LOG_INFO
+ *
+ * @param daemon DltDaemon
+ * @param daemon_local DltDaemonLocal
+ * @param msg DltMessage
+ * @param req 1 if requested from gateway, 0 otherwise
+ * @param verbose verbose flag
+ * @return 0 on success, -1 otherwise
+ */
+STATIC int dlt_gateway_parse_get_log_info(DltDaemon *daemon,
+ char *ecu,
+ DltMessage *msg,
+ int req,
+ int verbose)
+{
+ char resp_text[DLT_RECEIVE_TEXTBUFSIZE] = {'\0'};
+ DltServiceGetLogInfoResponse *resp = NULL;
+ AppIDsType app;
+ ContextIDsInfoType con;
+ int i = 0;
+ int j = 0;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if ((msg == NULL) || (msg->databuffer == NULL))
+ {
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ if (DLT_CHECK_RCV_DATA_SIZE(msg->datasize, sizeof(DltServiceGetLogInfoResponse)) < 0)
+ {
+ return DLT_RETURN_ERROR;
+ }
+
+ /* if the request was send from gateway, clear all application and context list */
+ if (req == CONTROL_MESSAGE_REQUESTED)
+ {
+ /* clear application list */
+ if (dlt_daemon_applications_clear(daemon, ecu, verbose) == DLT_RETURN_ERROR)
+ {
+ dlt_log(LOG_ERR, "Cannot clear applications list\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ /* clear context list */
+ if (dlt_daemon_contexts_clear(daemon, ecu, verbose) == DLT_RETURN_ERROR)
+ {
+ dlt_log(LOG_ERR, "Cannot clear contexts list\n");
+ return DLT_RETURN_ERROR;
+ }
+ }
+
+ /* check response */
+ if (dlt_message_payload(msg,
+ resp_text,
+ DLT_RECEIVE_TEXTBUFSIZE,
+ DLT_OUTPUT_ASCII, 0) != DLT_RETURN_OK)
+ {
+ dlt_log(LOG_ERR, "GET_LOG_INFO payload failed\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ /* prepare pointer to message request */
+ resp = (DltServiceGetLogInfoResponse*) calloc(1, sizeof(DltServiceGetLogInfoResponse));
+
+ if (resp == NULL)
+ {
+ dlt_log(LOG_ERR,
+ "Get Log Info Response could not be allocated\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ if (dlt_set_loginfo_parse_service_id(resp_text, &resp->service_id, &resp->status) != DLT_RETURN_OK)
+ {
+ dlt_log(LOG_ERR, "Parsing GET_LOG_INFO failed\n");
+ dlt_client_cleanup_get_log_info(resp);
+ return DLT_RETURN_ERROR;
+ }
+
+ if (dlt_client_parse_get_log_info_resp_text(resp, resp_text) != DLT_RETURN_OK)
+ {
+ dlt_log(LOG_ERR, "Parsing GET_LOG_INFO failed\n");
+ dlt_client_cleanup_get_log_info(resp);
+ return DLT_RETURN_ERROR;
+ }
+
+ for (i = 0; i < resp->log_info_type.count_app_ids; i++)
+ {
+ app = resp->log_info_type.app_ids[i];
+
+ /* add application */
+ if (dlt_daemon_application_add(daemon,
+ app.app_id,
+ 0,
+ app.app_description,
+ -1,
+ ecu,
+ verbose) == 0)
+ {
+ dlt_vlog(LOG_WARNING,
+ "%s: dlt_daemon_application_add failed\n",
+ __func__);
+ dlt_client_cleanup_get_log_info(resp);
+ return DLT_RETURN_ERROR;
+ }
+
+ for (j = 0; j < app.count_context_ids; j++)
+ {
+ con = app.context_id_info[j];
+
+ /* add context */
+ if (dlt_daemon_context_add(daemon,
+ app.app_id,
+ con.context_id,
+ con.log_level,
+ con.trace_status,
+ 0,
+ -1,
+ con.context_description,
+ ecu,
+ verbose) == 0)
+ {
+ dlt_vlog(LOG_WARNING,
+ "%s: dlt_daemon_context_add failed for %4s\n",
+ __func__,
+ app.app_id);
+ dlt_client_cleanup_get_log_info(resp);
+ return DLT_RETURN_ERROR;
+ }
+ }
+ }
+
+ /* free response */
+ dlt_client_cleanup_get_log_info(resp);
+
+ return DLT_RETURN_OK;
+}
+
+/**
+ * Parse GET_DEFAULT_LOG_LEVEL
+ *
+ * @param daemon DltDaemon
+ * @param daemon_local DltDaemonLocal
+ * @param msg DltMessage
+ * @param verbose verbose flag
+ * @return 0 on success, -1 otherwise
+ */
+STATIC int dlt_gateway_parse_get_default_log_level(DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ char *ecu,
+ DltMessage *msg,
+ int verbose)
+{
+ DltServiceGetDefaultLogLevelResponse *resp = NULL;
+ DltGatewayConnection *con = NULL;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if ((daemon == NULL) || (daemon_local == NULL))
+ {
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ if (DLT_CHECK_RCV_DATA_SIZE(msg->datasize,
+ sizeof(DltServiceGetDefaultLogLevelResponse)) < 0)
+ {
+ dlt_log(LOG_ERR, "Received data incomplete.\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ /* prepare pointer to message request */
+ resp = (DltServiceGetDefaultLogLevelResponse *) (msg->databuffer);
+
+ con = dlt_gateway_get_connection(&daemon_local->pGateway,
+ ecu,
+ verbose);
+
+ if (con == NULL)
+ {
+ dlt_vlog(LOG_ERR, "No information about passive ECU: %s\n",
+ ecu);
+
+ return DLT_RETURN_ERROR;
+ }
+
+ con->default_log_level = resp->log_level;
+
+ return DLT_RETURN_OK;
+}
+
+/**
+ * Service offline logstorage
+ *
+ * @param daemon DltDaemon
+ * @param daemon_local DltDaemonLocal
+ * @param verbose int
+ * @return 0 on success, -1 otherwise
+ */
+STATIC int dlt_gateway_control_service_logstorage(DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ int verbose)
+{
+ unsigned int connection_type = 0;
+ int i = 0;
+
+ if (daemon_local->flags.offlineLogstorageMaxDevices <= 0)
+ {
+ dlt_log(LOG_INFO,
+ "Logstorage functionality not enabled or MAX device set is 0\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++)
+ {
+ connection_type = daemon->storage_handle[i].connection_type;
+
+ if (connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED)
+ {
+ /* Check if log level of running application needs an update */
+ dlt_daemon_logstorage_update_application_loglevel(daemon,
+ daemon_local,
+ i,
+ verbose);
+ }
+ }
+
+ return DLT_RETURN_OK;
+}
+
int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
DltDaemonLocal *daemon_local,
DltReceiver *receiver,
@@ -739,9 +1283,10 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
DltMessage msg;
char local_str[DLT_DAEMON_TEXTBUFSIZE];
- if (daemon == NULL || daemon_local == NULL || receiver == NULL)
+ if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
PRINT_FUNCTION_VERBOSE(verbose);
@@ -750,7 +1295,7 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
if (gateway == NULL)
{
dlt_log(LOG_ERR, "Gateway structure is NULL\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
for (i = 0; i < gateway->num_connections; i++)
@@ -765,7 +1310,7 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
if (con == NULL)
{
dlt_log(LOG_ERR, "Cannot associate fd to passive Node connection\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
/* now the corresponding passive node connection is available */
@@ -773,7 +1318,7 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
{
dlt_log(LOG_ERR,
"Cannot initialize DLT message for passive node forwarding\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
/* nearly copy and paste of dlt_client_main_loop function */
@@ -783,7 +1328,7 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
if (dlt_message_free(&msg, verbose) < 0)
{
dlt_log(LOG_ERR, "Cannot free DLT message\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
dlt_log(LOG_WARNING, "Connection to passive node lost\n");
@@ -804,7 +1349,7 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
dlt_log(LOG_ERR, "Remove passive node Connection failed\n");
}
}
- return 0;
+ return DLT_RETURN_OK;
}
while (dlt_message_read(&msg,
@@ -821,14 +1366,69 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
/* only forward messages if the received ECUid is the expected one */
if (strncmp(header->ecu, con->ecuid, strlen(con->ecuid)) == 0)
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
+ uint32_t id;
+ uint32_t id_tmp;
+ DltPassiveControlMessage *control_msg = con->p_control_msgs;
+
+ dlt_vlog(LOG_DEBUG,
"Received ECUid (%s) similar to configured ECUid(%s). "
"Forwarding message (%s).\n",
header->ecu,
con->ecuid,
msg.databuffer);
- dlt_log(LOG_DEBUG, local_str);
+
+ id_tmp = *((uint32_t*)(msg.databuffer));
+ id = DLT_ENDIAN_GET_32(msg.standardheader->htyp, id_tmp);
+
+ /* if ID is GET_LOG_INFO, parse msg */
+ if (id == DLT_SERVICE_ID_GET_LOG_INFO)
+ {
+ while (control_msg)
+ {
+ if (control_msg->id == id)
+ {
+ if (dlt_gateway_parse_get_log_info(daemon,
+ header->ecu,
+ &msg,
+ control_msg->req,
+ verbose) == DLT_RETURN_ERROR)
+ {
+ dlt_log(LOG_WARNING, "Parsing GET_LOG_INFO message failed!\n");
+ }
+
+ /* Check for logstorage */
+ dlt_gateway_control_service_logstorage(daemon,
+ daemon_local,
+ verbose);
+
+ /* initialize the flag */
+ control_msg->req = CONTROL_MESSAGE_NOT_REQUESTED;
+ break;
+ }
+ control_msg = control_msg->next;
+ }
+ }
+ else if (id == DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL)
+ {
+ if (dlt_gateway_parse_get_default_log_level(
+ daemon,
+ daemon_local,
+ header->ecu,
+ &msg,
+ verbose) == DLT_RETURN_ERROR)
+ {
+ dlt_log(LOG_WARNING,
+ "Parsing GET_DEFAULT_LOG_LEVEL message failed!\n");
+ }
+ }
+
+ /* prepare storage header */
+ if (dlt_set_storageheader(msg.storageheader,
+ msg.headerextra.ecu) == DLT_RETURN_ERROR)
+ {
+ dlt_vlog(LOG_ERR, "%s: Can't set storage header\n", __func__);
+ return DLT_DAEMON_ERROR_UNKNOWN;
+ }
if (dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL,
daemon,
@@ -846,27 +1446,25 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
}
else /* otherwise remove this connection and do not connect again */
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
+ dlt_vlog(LOG_WARNING,
"Received ECUid (%s) differs to configured ECUid(%s). "
"Discard this message.\n",
header->ecu,
con->ecuid);
- dlt_log(LOG_WARNING, local_str);
/* disconnect from passive node */
- con->status = DLT_GATEWAY_DISCONNECTED;
- con->trigger = DLT_GATEWAY_DISABLED;
- if (dlt_event_handler_unregister_connection(&daemon_local->pEvent,
- daemon_local,
- receiver->fd)
- != 0)
- {
- dlt_log(LOG_ERR, "Remove passive node Connection failed\n");
- }
+ con->status = DLT_GATEWAY_DISCONNECTED;
+ con->trigger = DLT_GATEWAY_DISABLED;
+ if (dlt_event_handler_unregister_connection(&daemon_local->pEvent,
+ daemon_local,
+ receiver->fd)
+ != 0)
+ {
+ dlt_log(LOG_ERR, "Remove passive node Connection failed\n");
+ }
- dlt_log(LOG_WARNING,
- "Disconnect from passive node due to invalid ECUid\n");
+ dlt_log(LOG_WARNING,
+ "Disconnect from passive node due to invalid ECUid\n");
}
if (msg.found_serialheader)
@@ -879,7 +1477,7 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
{
/* Return value ignored */
dlt_message_free(&msg,verbose);
- return -1;
+ return DLT_RETURN_ERROR;
}
}
else
@@ -891,7 +1489,7 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
{
/* Return value ignored */
dlt_message_free(&msg,verbose);
- return -1;
+ return DLT_RETURN_ERROR;
}
}
}
@@ -900,15 +1498,15 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
{
/* Return value ignored */
dlt_message_free(&msg, verbose);
- return -1;
+ return DLT_RETURN_ERROR;
}
if (dlt_message_free(&msg, verbose) == -1)
{
- return -1;
+ return DLT_RETURN_ERROR;
}
- return 0;
+ return DLT_RETURN_OK;
}
int dlt_gateway_process_gateway_timer(DltDaemon *daemon,
@@ -918,28 +1516,25 @@ int dlt_gateway_process_gateway_timer(DltDaemon *daemon,
{
uint64_t expir = 0;
ssize_t res = 0;
- char local_str[DLT_DAEMON_TEXTBUFSIZE];
PRINT_FUNCTION_VERBOSE(verbose);
if ((daemon_local == NULL) || (daemon == NULL) || (receiver == NULL))
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
- "%s: invalid parameters",
+ dlt_vlog(LOG_ERR,
+ "%s: invalid parameters\n",
__func__);
- dlt_log(LOG_ERR, local_str);
- return -1;
+ return DLT_RETURN_WRONG_PARAMETER;
}
res = read(receiver->fd, &expir, sizeof(expir));
if(res < 0)
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
- "%s: Fail to read timer (%s)\n", __func__, strerror(errno));
- dlt_log(LOG_WARNING, local_str);
+ dlt_vlog(LOG_WARNING,
+ "%s: Fail to read timer (%s)\n",
+ __func__,
+ strerror(errno));
/* Activity received on timer_wd, but unable to read the fd:
let's go on sending notification */
}
@@ -951,7 +1546,7 @@ int dlt_gateway_process_gateway_timer(DltDaemon *daemon,
dlt_log(LOG_DEBUG, "Gateway Timer\n");
- return 0;
+ return DLT_RETURN_OK;
}
int dlt_gateway_forward_control_message(DltGateway *gateway,
@@ -963,12 +1558,15 @@ int dlt_gateway_forward_control_message(DltGateway *gateway,
int i = 0;
int ret = 0;
DltGatewayConnection *con = NULL;
+ uint32_t id_tmp;
+ uint32_t id;
PRINT_FUNCTION_VERBOSE(verbose);
if (gateway == NULL || daemon_local == NULL || msg == NULL || ecu == NULL)
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
for (i = 0; i < gateway->num_connections; i++)
@@ -985,13 +1583,13 @@ int dlt_gateway_forward_control_message(DltGateway *gateway,
if (con == NULL)
{
dlt_log(LOG_WARNING, "Unknown passive node identifier\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
if (con->status != DLT_GATEWAY_CONNECTED)
{
dlt_log(LOG_INFO, "Passive node is not connected\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
if (con->send_serial) /* send serial header */
@@ -1004,7 +1602,7 @@ int dlt_gateway_forward_control_message(DltGateway *gateway,
if (ret == -1)
{
dlt_log(LOG_ERR, "Sending message to passive DLT Daemon failed\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
}
@@ -1015,7 +1613,7 @@ int dlt_gateway_forward_control_message(DltGateway *gateway,
if (ret == -1)
{
dlt_log(LOG_ERR, "Sending message to passive DLT Daemon failed\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
else
{
@@ -1023,12 +1621,17 @@ int dlt_gateway_forward_control_message(DltGateway *gateway,
if (ret == -1)
{
dlt_log(LOG_ERR, "Sending message to passive DLT Daemon failed\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
}
- dlt_log(LOG_INFO, "Control message forwarded\n");
- return 0;
+ id_tmp = *((uint32_t*)(msg->databuffer));
+ id = DLT_ENDIAN_GET_32(msg->standardheader->htyp, id_tmp);
+
+ dlt_vlog(LOG_INFO,
+ "Control message forwarded : %s\n",
+ dlt_get_service_name(id));
+ return DLT_RETURN_OK;
}
int dlt_gateway_process_on_demand_request(DltGateway *gateway,
@@ -1042,9 +1645,10 @@ int dlt_gateway_process_on_demand_request(DltGateway *gateway,
PRINT_FUNCTION_VERBOSE(verbose);
- if (gateway == NULL || daemon_local == NULL || node_id == NULL)
+ if ((gateway == NULL) || (daemon_local == NULL) || (node_id == NULL))
{
- return -1;
+ dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
/* find connection by ECU id */
@@ -1060,7 +1664,7 @@ int dlt_gateway_process_on_demand_request(DltGateway *gateway,
if (con == NULL)
{
dlt_log(LOG_WARNING, "Specified ECUid not found\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
if (connection_status == 1) /* try to connect */
@@ -1069,23 +1673,17 @@ int dlt_gateway_process_on_demand_request(DltGateway *gateway,
{
if (dlt_client_connect(&con->client, verbose) == 0)
{
- con->status = DLT_GATEWAY_CONNECTED;
-
/* setup dlt connection and add to epoll event loop here */
- if (dlt_connection_create(daemon_local,
- &daemon_local->pEvent,
- con->client.sock,
- EPOLLIN,
- DLT_CONNECTION_GATEWAY) != 0)
+ if (dlt_gateway_add_to_event_loop(daemon_local, con, verbose) != DLT_RETURN_OK)
{
dlt_log(LOG_ERR, "Gateway connection creation failed\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
}
else
{
dlt_log(LOG_ERR, "Could not connect to passive node\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
}
else
@@ -1104,194 +1702,105 @@ int dlt_gateway_process_on_demand_request(DltGateway *gateway,
dlt_log(LOG_ERR,
"Remove passive node event handler connection failed\n");
}
-
- if (dlt_client_cleanup(&con->client, verbose) != 0)
- {
- dlt_log(LOG_ERR, "Could not cleanup DltClient structure\n");
- return -1;
- }
}
else
{
dlt_log(LOG_ERR, "Unknown command (connection_status)\n");
- return -1;
+ return DLT_RETURN_ERROR;
}
- return 0;
+ return DLT_RETURN_OK;
}
-void dlt_gateway_send_control_message(DltGatewayConnection *con,
- DltGateway *gateway,
- DltDaemonLocal *daemon_local,
- int verbose)
+int dlt_gateway_send_control_message(DltGatewayConnection *con,
+ DltPassiveControlMessage *control_msg,
+ void *data,
+ int verbose)
{
- int i = 0;
- uint32_t len = 0;
- DltMessage msg;
- char local_str[DLT_DAEMON_TEXTBUFSIZE];
+ int ret = DLT_RETURN_OK;
PRINT_FUNCTION_VERBOSE(verbose);
- if (con == NULL || gateway == NULL || daemon_local == NULL)
+ if (con == NULL)
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
- "%s: Invalid parameter given\n", __func__);
- dlt_log(LOG_WARNING, local_str);
- return;
+ dlt_vlog(LOG_WARNING,
+ "%s: Invalid parameter given\n",
+ __func__);
+ return DLT_RETURN_WRONG_PARAMETER;
}
- for (i = 0; i < DLT_GATEWAY_MAX_STARTUP_CTRL_MSG; i++)
+ /* no (more) control message to be send */
+ if (control_msg->id == 0)
{
- if (con->control_msgs[i] == 0)
- {
- break; /* no (more) control message to be send */
- }
-
- memset(&msg, 0, sizeof(msg));
+ return DLT_RETURN_ERROR;
+ }
- if (dlt_message_init(&msg, verbose) == -1)
+ /* check sendtime counter and message interval */
+ /* sendtime counter is 0 on startup, otherwise positive value */
+ if ((control_msg->type != CONTROL_MESSAGE_ON_DEMAND) && (con->sendtime_cnt > 0))
+ {
+ if (control_msg->interval <= 0)
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
- "Initialization of message failed\n");
- dlt_log(LOG_WARNING, local_str);
- return;
+ return DLT_RETURN_ERROR;
}
- if (con->control_msgs[i] == DLT_SERVICE_ID_GET_LOG_INFO)
+ if ((control_msg->type == CONTROL_MESSAGE_PERIODIC) ||
+ (control_msg->type == CONTROL_MESSAGE_BOTH))
{
- DltServiceGetLogInfoRequest *req;
- msg.databuffer = (uint8_t *)
- malloc(sizeof(DltServiceGetLogInfoRequest));
- if (msg.databuffer == NULL)
+ if ((con->sendtime_cnt - 1) % control_msg->interval != 0)
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
- "Initialization of 'GetLogInfo' failed\n");
- dlt_log(LOG_WARNING, local_str);
- dlt_message_free(&msg, verbose);
- return;
+ return DLT_RETURN_ERROR;
}
-
- req = (DltServiceGetLogInfoRequest *)msg.databuffer;
- req->service_id = DLT_SERVICE_ID_GET_LOG_INFO;
- req->options = 7;
- dlt_set_id(req->apid, "");
- dlt_set_id(req->ctid, "");
- dlt_set_id(req->com, "remo");
-
- msg.databuffersize = sizeof(DltServiceGetLogInfoRequest);
- msg.datasize = msg.databuffersize;
- }
- else if (con->control_msgs[i] == DLT_SERVICE_ID_GET_SOFTWARE_VERSION)
- {
- DltServiceGetSoftwareVersion *req;
-
- msg.databuffer = (uint8_t *)
- malloc(sizeof(DltServiceGetSoftwareVersion));
- if (msg.databuffer == NULL)
- {
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
- "Initialization of 'GetSoftwareVersion' failed\n");
- dlt_log(LOG_WARNING, local_str);
- dlt_message_free(&msg, verbose);
- return;
- }
-
- req = (DltServiceGetSoftwareVersion *)msg.databuffer;
- req->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION;
-
- msg.databuffersize = sizeof(DLT_SERVICE_ID_GET_SOFTWARE_VERSION);
- msg.datasize = msg.databuffersize;
- }
- else
- {
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
- "Unknown control message. Skip.\n");
- dlt_log(LOG_WARNING, local_str);
- dlt_message_free(&msg, verbose);
- return;
- }
-
- /* prepare storage header */
- msg.storageheader = (DltStorageHeader*)msg.headerbuffer;
-
- if (dlt_set_storageheader(msg.storageheader,"") == DLT_RETURN_ERROR)
- {
- dlt_message_free(&msg,0);
- return;
- }
-
- /* prepare standard header */
- msg.standardheader = (DltStandardHeader*)(msg.headerbuffer + sizeof(DltStorageHeader));
- msg.standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1 ;
-
- #if (BYTE_ORDER==BIG_ENDIAN)
- msg.standardheader->htyp = (msg.standardheader->htyp | DLT_HTYP_MSBF);
- #endif
-
- msg.standardheader->mcnt = 0;
-
- /* Set header extra parameters */
- dlt_set_id(msg.headerextra.ecu,"");
- //msg.headerextra.seid = 0;
- msg.headerextra.tmsp = dlt_uptime();
-
- /* Copy header extra parameters to headerbuffer */
- if (dlt_message_set_extraparameters(&msg,0) == DLT_RETURN_ERROR)
- {
- dlt_message_free(&msg,0);
- return;
}
+ }
- /* prepare extended header */
- msg.extendedheader = (DltExtendedHeader*)(msg.headerbuffer +
- sizeof(DltStorageHeader) +
- sizeof(DltStandardHeader) +
- DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp) );
-
- msg.extendedheader->msin = DLT_MSIN_CONTROL_REQUEST;
-
- msg.extendedheader->noar = 1; /* number of arguments */
-
- dlt_set_id(msg.extendedheader->apid, "APP");
- dlt_set_id(msg.extendedheader->ctid, "CON");
-
- /* prepare length information */
- msg.headersize = sizeof(DltStorageHeader) +
- sizeof(DltStandardHeader) +
- sizeof(DltExtendedHeader) +
- DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp);
+ if (con->send_serial) /* send serial header */
+ {
+ ret = send(con->client.sock,
+ (void *)dltSerialHeader,
+ sizeof(dltSerialHeader),
+ 0);
- len=msg.headersize - sizeof(DltStorageHeader) + msg.datasize;
- if (len>UINT16_MAX)
+ if (ret == -1)
{
- fprintf(stderr,"Critical: Huge injection message discarded!\n");
- dlt_message_free(&msg,0);
-
- return;
+ dlt_log(LOG_ERR, "Sending message to passive DLT Daemon failed\n");
+ return DLT_RETURN_ERROR;
}
+ }
- msg.standardheader->len = DLT_HTOBE_16(len);
-
- /* forward message to passive node */
- if (dlt_gateway_forward_control_message(gateway,
- daemon_local,
- &msg,
- con->ecuid,
- verbose) != 0)
+ switch(control_msg->id)
+ {
+ case DLT_SERVICE_ID_GET_LOG_INFO:
+ return dlt_client_get_log_info(&con->client);
+ break;
+ case DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL:
+ return dlt_client_get_default_log_level(&con->client);
+ break;
+ case DLT_SERVICE_ID_GET_SOFTWARE_VERSION:
+ return dlt_client_get_software_version(&con->client);
+ break;
+ case DLT_SERVICE_ID_SET_LOG_LEVEL:
+ if (data == NULL)
{
- snprintf(local_str,
- DLT_DAEMON_TEXTBUFSIZE,
- "Failed to forward message to passive node.\n");
- dlt_log(LOG_WARNING, local_str);
+ dlt_vlog(LOG_WARNING,
+ "Insufficient data for %s received. Send control request failed.\n",
+ dlt_get_service_name(control_msg->id));
+ return DLT_RETURN_ERROR;
}
- dlt_message_free(&msg, verbose);
+ DltServiceSetLogLevel *req = (DltServiceSetLogLevel *) data;
+ return dlt_client_send_log_level(&con->client,
+ req->apid,
+ req->ctid,
+ req->log_level);
+ break;
+ default:
+ dlt_vlog(LOG_WARNING,
+ "Cannot forward request: %s.\n",
+ dlt_get_service_name(control_msg->id));
}
+
+ return DLT_RETURN_OK;
}
DltGatewayConnection *dlt_gateway_get_connection(DltGateway *gateway,
diff --git a/src/gateway/dlt_gateway.conf b/src/gateway/dlt_gateway.conf
index 645847a..c68aa4f 100644
--- a/src/gateway/dlt_gateway.conf
+++ b/src/gateway/dlt_gateway.conf
@@ -9,11 +9,14 @@ EcuID=ECU2
; Stop connecting to passive node, if not successful after 10 seconds
Timeout=10
; Send following control messages after connection is established
-; SendControl=0x03,0x13
+; SendControl=0x03,0x04,0x13
; Send Serial Header with control messages. Value in dlt.conf is used as default if not specified.
; SendSerialHeader=0
+; Send following control messages periodically (<control:interval[in seconds]>)
+; SendPeriodicControl=0x03:5,0x13:10
; Supported Control messages:
; DLT_SERVICE_ID_GET_LOG_INFO 0x03
+; DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL 0x04
; DLT_SERVICE_ID_GET_SOFTWARE_VERSION 0x13
diff --git a/src/gateway/dlt_gateway.h b/src/gateway/dlt_gateway.h
index 571a76a..2da2118 100644
--- a/src/gateway/dlt_gateway.h
+++ b/src/gateway/dlt_gateway.h
@@ -163,17 +163,18 @@ int dlt_gateway_process_on_demand_request(DltGateway *g,
int verbose);
/**
- * Send control message to passive node.
+ * Send control message to passive node
*
* @param con DltGatewayConnection
- * @param g DltGateway
- * @param daemon_local DltDaemonLocal
+ * @param control_msg DltPassiveControlMessage
+ * @param msg DltMessage
* @param verbose verbose flag
+ * @return 0 on success, -1 otherwise
*/
-void dlt_gateway_send_control_message(DltGatewayConnection *con,
- DltGateway *g,
- DltDaemonLocal *daemon_local,
- int verbose);
+int dlt_gateway_send_control_message(DltGatewayConnection *con,
+ DltPassiveControlMessage *control_msg,
+ void *data,
+ int verbose);
/**
* Gets the connection handle of passive node with specified ECU
@@ -189,33 +190,4 @@ DltGatewayConnection *dlt_gateway_get_connection(DltGateway *g,
/* _ONLY_ for development purposes */
void print_gateway_connection_details(const DltGateway *g);
-#ifdef DLT_UNIT_TESTS
-typedef enum {
- GW_CONF_IP_ADDRESS = 0,
- GW_CONF_PORT,
- GW_CONF_ECUID,
- GW_CONF_CONNECT,
- GW_CONF_TIMEOUT,
- GW_CONF_SEND_CONTROL,
- GW_CONF_SEND_SERIAL_HEADER,
- GW_CONF_COUNT
-} DltGatewayConfType;
-int dlt_gateway_check_ip(DltGatewayConnection *con, char *value);
-int dlt_gateway_check_port(DltGatewayConnection *con, char *value);
-int dlt_gateway_check_ecu(DltGatewayConnection *con, char *value);
-int dlt_gateway_check_connect_trigger(DltGatewayConnection *con,
- char *value);
-int dlt_gateway_check_timeout(DltGatewayConnection *con, char *value);
-int dlt_gateway_check_send_serial(DltGatewayConnection *con, char *value);
-int dlt_gateway_check_control_messages(DltGatewayConnection *con,
- char *value);
-int dlt_gateway_check_param(DltGateway *gateway,
- DltGatewayConnection *con,
- DltGatewayConfType ctype,
- char *value);
-int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose);
-int dlt_gateway_store_connection(DltGateway *gateway,
- DltGatewayConnection *tmp,
- int verbose);
-#endif
#endif
diff --git a/src/gateway/dlt_gateway_types.h b/src/gateway/dlt_gateway_types.h
index 7c3d45e..4d0de0d 100644
--- a/src/gateway/dlt_gateway_types.h
+++ b/src/gateway/dlt_gateway_types.h
@@ -58,6 +58,7 @@
#ifndef DLT_GATEWAY_TYPES_H_
#define DLT_GATEWAY_TYPES_H_
+#include "dlt_protocol.h"
#include "dlt_client.h"
#define DLT_GATEWAY_CONFIG_PATH CONFIGURATION_FILES_DIR "/dlt_gateway.conf"
@@ -85,6 +86,32 @@ typedef enum
DLT_GATEWAY_DISABLED /* disable this connection due to problems */
} connection_trigger;
+typedef enum
+{
+ CONTROL_MESSAGE_UNDEFINED = -1,
+ CONTROL_MESSAGE_ON_STARTUP, /* send on startup */
+ CONTROL_MESSAGE_PERIODIC, /* send periodically */
+ CONTROL_MESSAGE_BOTH, /* send on startup and periodically */
+ CONTROL_MESSAGE_ON_DEMAND /* send on demand only */
+} control_msg_trigger;
+
+typedef enum
+{
+ CONTROL_MESSAGE_REQUEST_UNDEFINED = -1,
+ CONTROL_MESSAGE_NOT_REQUESTED, /* control msg not requested (default) */
+ CONTROL_MESSAGE_REQUESTED /* control msg requested */
+} control_msg_request;
+
+/* Passive control message */
+typedef struct DltPassiveControlMessage {
+ uint32_t id; /* msg ID */
+ uint32_t user_id;
+ control_msg_trigger type; /* on startup or periodic or both */
+ control_msg_request req; /* whether it is requested from gateway or not */
+ int interval; /* interval for periodic sending. if on startup, -1 */
+ struct DltPassiveControlMessage *next; /* for multiple passive control message */
+} DltPassiveControlMessage;
+
/* DLT Gateway connection structure */
typedef struct {
int handle; /* connection handle */
@@ -99,9 +126,13 @@ typedef struct {
int timeout; /* connection timeout */
int timeout_cnt; /* connection timeout counter */
int reconnect_cnt; /* reconnection counter */
- int control_msgs[DLT_GATEWAY_MAX_STARTUP_CTRL_MSG]; /* msg IDs send on startup */
+ int sendtime; /* periodic sending max time */
+ int sendtime_cnt; /* periodic sending counter */
+ DltPassiveControlMessage *p_control_msgs; /* passive control msgs */
+ DltPassiveControlMessage *head; /* to go back to the head pointer of p_control_msgs */
int send_serial; /* Send serial header with control messages */
DltClient client; /* DltClient structure */
+ int default_log_level; /* Default Log Level on passive node */
} DltGatewayConnection;
/* DltGateway structure */
diff --git a/src/lib/dlt_client.c b/src/lib/dlt_client.c
index 60a97f5..9c38827 100644
--- a/src/lib/dlt_client.c
+++ b/src/lib/dlt_client.c
@@ -412,6 +412,8 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti
int ret;
int32_t len;
+ uint32_t id_tmp;
+ uint32_t id;
if ((client==0) || (client->sock<0) || (apid==0) || (ctid==0))
{
@@ -510,15 +512,26 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti
{
/* via FileDescriptor */
ret=write(client->sock, msg.headerbuffer+sizeof(DltStorageHeader),msg.headersize-sizeof(DltStorageHeader));
- if (0 > ret){
- dlt_message_free(&msg,0);
- return DLT_RETURN_ERROR;
- }
+ if (0 > ret)
+ {
+ dlt_log(LOG_ERR, "Sending message failed\n");
+ dlt_message_free(&msg,0);
+ return DLT_RETURN_ERROR;
+ }
+
ret=write(client->sock, msg.databuffer,msg.datasize);
- if (0 > ret){
- dlt_message_free(&msg,0);
- return DLT_RETURN_ERROR;
- }
+ if (0 > ret){
+ dlt_log(LOG_ERR, "Sending message failed\n");
+ dlt_message_free(&msg,0);
+ return DLT_RETURN_ERROR;
+ }
+
+ id_tmp = *((uint32_t*)(msg.databuffer));
+ id = DLT_ENDIAN_GET_32(msg.standardheader->htyp, id_tmp);
+
+ dlt_vlog(LOG_INFO,
+ "Control message forwarded : %s\n",
+ dlt_get_service_name(id));
}
else
{
@@ -571,16 +584,19 @@ DltReturnValue dlt_client_send_inject_msg(DltClient *client, char *apid, char *c
DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ctid, uint8_t logLevel)
{
DltServiceSetLogLevel *req;
- uint8_t *payload;
+ int ret = DLT_RETURN_ERROR;
- payload = (uint8_t *) malloc(sizeof(DltServiceSetLogLevel));
-
- if(payload==0)
+ if ((client == NULL) || (apid == NULL) || (ctid == NULL))
{
- return DLT_RETURN_ERROR;
+ return ret;
}
- req = (DltServiceSetLogLevel *) payload;
+
+ req = (DltServiceSetLogLevel *) malloc(sizeof(DltServiceSetLogLevel));
+ if (req == NULL)
+ {
+ return ret;
+ }
memset(req, 0, sizeof(DltServiceSetLogLevel));
req->service_id = DLT_SERVICE_ID_SET_LOG_LEVEL;
dlt_set_id(req->apid,apid);
@@ -589,37 +605,35 @@ DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ct
dlt_set_id(req->com,"remo");
/* free message */
- if (dlt_client_send_ctrl_msg(client,"APP","CON",payload,sizeof(DltServiceSetLogLevel)) == DLT_RETURN_ERROR)
- {
- free(payload);
- return DLT_RETURN_ERROR;
- }
+ ret = dlt_client_send_ctrl_msg(client,
+ "APP",
+ "CON",
+ (uint8_t*) req,
+ sizeof(DltServiceSetLogLevel));
- free(payload);
- return DLT_RETURN_OK;
+ free(req);
+
+ return ret;
}
-int dlt_client_get_log_info(DltClient *client)
+DltReturnValue dlt_client_get_log_info(DltClient *client)
{
DltServiceGetLogInfoRequest *req;
- uint8_t *payload;
- int ret_main_loop = 0;
- int ret = -1;
+ int ret = DLT_RETURN_ERROR;
if (client == NULL)
{
return ret;
}
- payload = (uint8_t *) malloc(sizeof(DltServiceGetLogInfoRequest));
- if (payload == 0)
+ req = (DltServiceGetLogInfoRequest *) malloc(sizeof(DltServiceGetLogInfoRequest));
+
+ if (req == NULL)
{
return ret;
}
- req = (DltServiceGetLogInfoRequest *) payload;
-
req->service_id = DLT_SERVICE_ID_GET_LOG_INFO;
req->options = 7;
dlt_set_id(req->apid, "");
@@ -627,20 +641,73 @@ int dlt_client_get_log_info(DltClient *client)
dlt_set_id(req->com, "remo");
/* send control message to daemon*/
- ret = dlt_client_send_ctrl_msg(client, "", "", payload, sizeof(DltServiceGetLogInfoRequest));
- free(payload);
- if (ret == -1)
+ ret = dlt_client_send_ctrl_msg(client,
+ "",
+ "",
+ (uint8_t *) req,
+ sizeof(DltServiceGetLogInfoRequest));
+
+ free(req);
+
+ return ret;
+}
+
+DltReturnValue dlt_client_get_default_log_level(DltClient *client)
+{
+ DltServiceGetDefaultLogLevelRequest *req;
+ int ret = DLT_RETURN_ERROR;
+
+ if (client == NULL)
{
- return -1;
+ return ret;
}
- ret_main_loop = dlt_client_main_loop(client, NULL, 0);
- if (ret_main_loop == 1)
+ req = (DltServiceGetDefaultLogLevelRequest *)
+ malloc(sizeof(DltServiceGetDefaultLogLevelRequest));
+
+ if (req == NULL)
{
- printf("DLT-daemon's response is invalid.\n");
+ return ret;
}
- return 0;
+ req->service_id = DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL;
+
+ /* send control message to daemon*/
+ ret = dlt_client_send_ctrl_msg(client,
+ "",
+ "",
+ (uint8_t *) req,
+ sizeof(DltServiceGetDefaultLogLevelRequest));
+
+ free(req);
+
+ return ret;
+}
+
+DltReturnValue dlt_client_get_software_version(DltClient *client)
+{
+ DltServiceGetSoftwareVersion *req;
+ int ret = DLT_RETURN_ERROR;
+
+ if (client == NULL)
+ {
+ return ret;
+ }
+
+ req = (DltServiceGetSoftwareVersion *) malloc(sizeof(DltServiceGetSoftwareVersion));
+
+ req->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION;
+
+ /* send control message to daemon*/
+ ret = dlt_client_send_ctrl_msg(client,
+ "",
+ "",
+ (uint8_t *) req,
+ sizeof(DltServiceGetSoftwareVersion));
+
+ free(req);
+
+ return ret;
}
DltReturnValue dlt_client_send_trace_status(DltClient *client, char *apid, char *ctid, uint8_t traceStatus)
@@ -905,3 +972,241 @@ int dlt_client_set_socket_path(DltClient *client, char *socket_path)
}
return DLT_RETURN_OK;
}
+/**
+ * free allocation when calloc failed
+ *
+ * @param resp DltServiceGetLogInfoResponse
+ * @param count_app_ids number of app_ids which needs to be freed
+ */
+STATIC void dlt_client_free_calloc_failed_get_log_info(DltServiceGetLogInfoResponse *resp,
+ int count_app_ids)
+{
+ AppIDsType *app = NULL;
+ ContextIDsInfoType *con = NULL;
+ int i = 0;
+ int j = 0;
+
+ for (i = 0; i < count_app_ids; i++)
+ {
+ app = &(resp->log_info_type.app_ids[i]);
+
+ for (j = 0; j < app->count_context_ids; j++)
+ {
+ con = &(app->context_id_info[j]);
+
+ free(con->context_description);
+ con->context_description = NULL;
+ }
+
+ free(app->app_description);
+ app->app_description = NULL;
+
+ free(app->context_id_info);
+ app->context_id_info = NULL;
+ }
+
+ free(resp->log_info_type.app_ids);
+ resp->log_info_type.app_ids = NULL;
+
+ return;
+}
+
+int dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoResponse *resp,
+ char *resp_text)
+{
+ AppIDsType *app = NULL;
+ ContextIDsInfoType *con = NULL;
+ int i = 0;
+ int j = 0;
+ char *rp = NULL;
+ int rp_count = 0;
+
+ if ((resp == NULL) || (resp_text == NULL))
+ {
+ return DLT_RETURN_ERROR;
+ }
+
+ /* ------------------------------------------------------
+ get_log_info data structure(all data is ascii)
+
+ get_log_info, aa, bb bb cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. ..
+ ~~ ~~~~~ ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~
+ cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. ..
+ jj jj kk kk kk .. ..
+ ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~
+ aa : get mode (fix value at 0x07)
+ bb bb : list num of apid (little endian)
+ cc cc cc cc: apid
+ dd dd : list num of ctid (little endian)
+ ee ee ee ee: ctid
+ ff : log level
+ gg : trace status
+ hh hh : description length of ctid
+ ii ii .. : description text of ctid
+ jj jj : description length of apid
+ kk kk .. : description text of apid
+ ------------------------------------------------------ */
+
+ rp = resp_text + DLT_GET_LOG_INFO_HEADER;
+ rp_count = 0;
+
+ /* check if status is acceptable */
+ if ((resp->status < GET_LOG_INFO_STATUS_MIN) ||
+ (resp->status > GET_LOG_INFO_STATUS_MAX))
+ {
+ if (resp->status == GET_LOG_INFO_STATUS_NO_MATCHING_CTX)
+ {
+ dlt_vlog(LOG_WARNING,
+ "The status(%d) is invalid: NO matching Context IDs\n",
+ resp->status);
+ }
+ else if (resp->status == GET_LOG_INFO_STATUS_RESP_DATA_OVERFLOW)
+ {
+ dlt_vlog(LOG_WARNING,
+ "The status(%d) is invalid: Response data over flow\n",
+ resp->status);
+ }
+ else
+ {
+ dlt_vlog(LOG_WARNING,
+ "The status(%d) is invalid\n",
+ resp->status);
+ }
+ return DLT_RETURN_ERROR;
+ }
+
+ /* count_app_ids */
+ resp->log_info_type.count_app_ids = dlt_getloginfo_conv_ascii_to_uint16_t(rp,
+ &rp_count);
+
+ resp->log_info_type.app_ids = (AppIDsType *)calloc
+ (resp->log_info_type.count_app_ids, sizeof(AppIDsType));
+
+ if (resp->log_info_type.app_ids == NULL)
+ {
+ dlt_vlog(LOG_ERR, "calloc failed for app_ids\n");
+ dlt_client_free_calloc_failed_get_log_info(resp, 0);
+ return DLT_RETURN_ERROR;
+ }
+
+ for (i = 0; i < resp->log_info_type.count_app_ids; i++)
+ {
+ app = &(resp->log_info_type.app_ids[i]);
+ /* get app id */
+ dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, app->app_id, DLT_ID_SIZE);
+
+ /* count_con_ids */
+ app->count_context_ids = dlt_getloginfo_conv_ascii_to_uint16_t(rp,
+ &rp_count);
+
+ app->context_id_info = (ContextIDsInfoType *)calloc
+ (app->count_context_ids, sizeof(ContextIDsInfoType));
+
+ if (app->context_id_info == NULL)
+ {
+ dlt_vlog(LOG_ERR,
+ "calloc failed for context_id_info\n");
+ dlt_client_free_calloc_failed_get_log_info(resp, i);
+ return DLT_RETURN_ERROR;
+ }
+
+ for (j = 0; j < app->count_context_ids; j++)
+ {
+ con = &(app->context_id_info[j]);
+ /* get con id */
+ dlt_getloginfo_conv_ascii_to_id(rp,
+ &rp_count,
+ con->context_id,
+ DLT_ID_SIZE);
+
+ /* log_level */
+ if ((resp->status == 4) || (resp->status == 6) || (resp->status == 7))
+ {
+ con->log_level = dlt_getloginfo_conv_ascii_to_int16_t(rp,
+ &rp_count);
+ }
+
+ /* trace status */
+ if ((resp->status == 5) || (resp->status == 6) || (resp->status == 7))
+ {
+ con->trace_status = dlt_getloginfo_conv_ascii_to_int16_t(rp,
+ &rp_count);
+ }
+
+ /* context desc */
+ if (resp->status == 7){
+ con->len_context_description = dlt_getloginfo_conv_ascii_to_uint16_t(rp,
+ &rp_count);
+ con->context_description = (char *)calloc
+ (con->len_context_description + 1, sizeof(char));
+ if (con->context_description == 0)
+ {
+ dlt_log(LOG_ERR, "calloc failed for context description\n");
+ dlt_client_free_calloc_failed_get_log_info(resp, i);
+ return DLT_RETURN_ERROR;
+ }
+ dlt_getloginfo_conv_ascii_to_id(rp,
+ &rp_count,
+ con->context_description,
+ con->len_context_description);
+ }
+ }
+
+ /* application desc */
+ if (resp->status == 7)
+ {
+ app->len_app_description = dlt_getloginfo_conv_ascii_to_uint16_t(rp,
+ &rp_count);
+ app->app_description = (char *)calloc
+ (app->len_app_description + 1, sizeof(char));
+ if (app->app_description == 0)
+ {
+ dlt_log(LOG_ERR, "calloc failed for application description\n");
+ dlt_client_free_calloc_failed_get_log_info(resp, i);
+ return DLT_RETURN_ERROR;
+ }
+ dlt_getloginfo_conv_ascii_to_id(rp,
+ &rp_count,
+ app->app_description,
+ app->len_app_description);
+ }
+ }
+
+ return DLT_RETURN_OK;
+}
+
+int dlt_client_cleanup_get_log_info(DltServiceGetLogInfoResponse *resp)
+{
+ AppIDsType app;
+ int i = 0;
+ int j = 0;
+
+ if (resp == NULL)
+ {
+ return DLT_RETURN_OK;
+ }
+
+ for (i = 0; i < resp->log_info_type.count_app_ids; i++)
+ {
+ app = resp->log_info_type.app_ids[i];
+
+ for (j = 0; j < app.count_context_ids; j++)
+ {
+ free(app.context_id_info[j].context_description);
+ app.context_id_info[j].context_description = NULL;
+ }
+
+ free(app.context_id_info);
+ app.context_id_info = NULL;
+ free(app.app_description);
+ app.app_description = NULL;
+ }
+
+ free(resp->log_info_type.app_ids);
+ resp->log_info_type.app_ids = NULL;
+
+ free(resp);
+ resp = NULL;
+
+ return DLT_RETURN_OK;
+}
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index 28df590..a77459d 100644
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -3912,6 +3912,151 @@ void dlt_check_envvar()
}
}
+int dlt_set_loginfo_parse_service_id(char *resp_text,
+ uint32_t *service_id,
+ uint8_t *service_opt)
+{
+ int ret = -1;
+ char get_log_info_tag[GET_LOG_INFO_LENGTH];
+ char service_opt_str[SERVICE_OPT_LENGTH];
+
+ if ((resp_text == NULL) || (service_id == NULL) || (service_opt == NULL))
+ {
+ return DLT_RETURN_ERROR;
+ }
+ /* ascii type, syntax is 'get_log_info, ..' */
+ /* check target id */
+ strncpy(get_log_info_tag, "get_log_info", strlen("get_log_info"));
+ ret = memcmp((void *)resp_text, (void *)get_log_info_tag, sizeof(get_log_info_tag)-1);
+ if (ret == 0)
+ {
+ *service_id = DLT_SERVICE_ID_GET_LOG_INFO;
+ /* reading the response mode from the resp_text. eg. option 7*/
+ service_opt_str[0] = *(resp_text + GET_LOG_INFO_LENGTH + 1);
+ service_opt_str[1] = *(resp_text + GET_LOG_INFO_LENGTH + 2);
+ service_opt_str[2] = 0;
+ *service_opt = atoi(service_opt_str);
+ }
+
+ return ret;
+}
+
+int16_t dlt_getloginfo_conv_ascii_to_uint16_t(char *rp, int *rp_count)
+{
+ char num_work[5] = {0};
+ char *endptr;
+
+ if ((rp == NULL) || (rp_count == NULL))
+ {
+ return DLT_RETURN_ERROR;
+ }
+ /* ------------------------------------------------------
+ from: [89 13 ] -> to: ['+0x'1389\0] -> to num
+ ------------------------------------------------------ */
+ num_work[0] = *(rp + *rp_count + 3);
+ num_work[1] = *(rp + *rp_count + 4);
+ num_work[2] = *(rp + *rp_count + 0);
+ num_work[3] = *(rp + *rp_count + 1);
+ num_work[4] = 0;
+ *rp_count += 6;
+
+ return (unsigned char)strtol(num_work, &endptr, 16);
+}
+
+int16_t dlt_getloginfo_conv_ascii_to_int16_t(char *rp, int *rp_count)
+{
+ char num_work[3] = {0};
+ char *endptr;
+
+ if ((rp == NULL) || (rp_count == NULL))
+ {
+ return DLT_RETURN_ERROR;
+ }
+ /* ------------------------------------------------------
+ from: [89 ] -> to: ['0x'89\0] -> to num
+ ------------------------------------------------------ */
+ num_work[0] = *(rp + *rp_count + 0);
+ num_work[1] = *(rp + *rp_count + 1);
+ num_work[2] = 0;
+ *rp_count += 3;
+
+ return (signed char)strtol(num_work, &endptr, 16);
+}
+
+void dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len)
+{
+ char number16[2] = {0};
+ char *endptr;
+ int count;
+
+ if ((rp == NULL) || (rp_count == NULL) || (wp == NULL))
+ {
+ return;
+ }
+ /* ------------------------------------------------------
+ from: [72 65 6d 6f ] -> to: [0x72,0x65,0x6d,0x6f,0x00]
+ ------------------------------------------------------ */
+ for (count = 0; count < len; count++)
+ {
+ number16[0] = *(rp + *rp_count + 0);
+ number16[1] = *(rp + *rp_count + 1);
+ *(wp + count) = strtol(number16, &endptr, 16);
+ *rp_count += 3;
+ }
+ *(wp + count) = 0;
+ return;
+}
+
+void dlt_hex_ascii_to_binary(const char *ptr,uint8_t *binary,int *size)
+{
+ char ch = *ptr;
+ int pos = 0;
+ binary[pos] = 0;
+ int first = 1;
+ int found;
+
+ for(;;)
+ {
+ if(ch == 0)
+ {
+ *size = pos;
+ return;
+ }
+
+ found = 0;
+ if (ch >= '0' && ch <= '9')
+ {
+ binary[pos] = (binary[pos] << 4) + (ch - '0');
+ found = 1;
+ }
+ else if (ch >= 'A' && ch <= 'F')
+ {
+ binary[pos] = (binary[pos] << 4) + (ch - 'A' + 10);
+ found = 1;
+ }
+ else if (ch >= 'a' && ch <= 'f')
+ {
+ binary[pos] = (binary[pos] << 4) + (ch - 'a' + 10);
+ found = 1;
+ }
+ if(found)
+ {
+ if(first)
+ first = 0;
+ else
+ {
+ first = 1;
+ pos++;
+ if(pos>=*size)
+ return;
+ binary[pos]=0;
+ }
+ }
+
+ ch = *(++ptr);
+ }
+}
+
#ifndef DLT_USE_UNIX_SOCKET_IPC
int dlt_mkdir_recursive(const char *dir)
{
diff --git a/tests/g_test_dlt_daemon_gateway.sh b/tests/g_test_dlt_daemon_gateway.sh
index bb76a6b..85f37db 100755
--- a/tests/g_test_dlt_daemon_gateway.sh
+++ b/tests/g_test_dlt_daemon_gateway.sh
@@ -54,9 +54,9 @@ cleanup()
return 1
fi
fi
- return 0
-
rm $tmpPath/dlt.conf
+ rm $tmpPath/idlt_gateway.conf
+ return 0
}
#
# Function: -setupTest()
@@ -106,6 +106,8 @@ setupTest()
echo "EcuID=ECU1" >>$tmpPath/dlt_gateway.conf
echo "Connect=OnStartup" >>$tmpPath/dlt_gateway.conf
echo "Timeout=10" >>$tmpPath/dlt_gateway.conf
+ echo "SendControl=0x03,0x13" >>$tmpPath/dlt_gateway.conf
+ echo "SendSerialHeader=0" >>$tmpPath/dlt_gateway.conf
echo "NOFiles=1" >>$tmpPath/dlt_gateway.conf
return 0
}
diff --git a/tests/gtest_common.h b/tests/gtest_common.h
new file mode 100644
index 0000000..0ca9f7e
--- /dev/null
+++ b/tests/gtest_common.h
@@ -0,0 +1,251 @@
+/**
+ * @licence app begin@
+ * Copyright (C) 2016 Advanced Driver Information Technology.
+ * This code is developed by Advanced Driver Information Technology.
+ * Copyright of Advanced Driver Information Technology, Bosch and DENSO.
+ *
+ * DLT gtest common header file.
+ *
+ * \copyright
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
+ * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ *
+ * \author Onkar Palkar <onkar.palkar@wipro.com>
+ *
+ * \file: gtest_common.h
+ * For further information see http://www.genivi.org/.
+ * @licence end@
+ */
+
+/*******************************************************************************
+ * **
+ * SRC-MODULE: gtest_common.h **
+ * **
+ * TARGET : linux **
+ * **
+ * PROJECT : DLT **
+ * **
+ * AUTHOR : onkar.palkar@wipro.com **
+ * PURPOSE : **
+ * **
+ * REMARKS : **
+ * **
+ * PLATFORM DEPENDANT [yes/no]: yes **
+ * **
+ * TO BE CHANGED BY USER [yes/no]: no **
+ * **
+ ******************************************************************************/
+
+/*******************************************************************************
+* Author Identity **
+*******************************************************************************
+* **
+* Initials Name Company **
+* -------- ------------------------- ---------------------------------- **
+* op Onkar Palkar Wipro **
+*******************************************************************************/
+#ifndef GTEST_COMMON_H
+#define GTEST_COMMON_H
+int dlt_logstorage_split_key(char *key, char *appid, char *ctxid);
+int dlt_logstorage_update_all_contexts(DltDaemon *daemon,
+ char *id,
+ int curr_log_level,
+ int cmp_flag,
+ int verbose);
+int dlt_logstorage_update_context(DltDaemon *daemon,
+ char *apid,
+ char *ctxid,
+ char *ecuid,
+ int curr_log_level,
+ int verbose);
+int dlt_logstorage_update_context_loglevel(DltDaemon *daemon,
+ char *key,
+ int curr_log_level,
+ int verbose);
+void dlt_daemon_logstorage_reset_application_loglevel(DltDaemon *daemon,
+ int dev_num,
+ int max_device,
+ int verbose);
+typedef struct {
+ char *key; /* The configuration key */
+ int (*func)(DltLogStorage *handle, char *value); /* conf handler */
+ int is_opt; /* If configuration is optional or not */
+} DltLogstorageGeneralConf;
+
+typedef enum {
+ DLT_LOGSTORAGE_GENERAL_CONF_BLOCKMODE = 0,
+ DLT_LOGSTORAGE_GENERAL_CONF_COUNT
+} DltLogstorageGeneralConfType;
+
+typedef struct {
+ char *key; /* Configuration key */
+ int (*func)(DltLogStorageFilterConfig *config, char *value); /* conf handler */
+ int is_opt; /* If configuration is optional or not */
+} DltLogstorageFilterConf;
+
+typedef enum {
+ DLT_LOGSTORAGE_FILTER_CONF_LOGAPPNAME = 0,
+ DLT_LOGSTORAGE_FILTER_CONF_CONTEXTNAME,
+ DLT_LOGSTORAGE_FILTER_CONF_LOGLEVEL,
+ DLT_LOGSTORAGE_FILTER_CONF_FILE,
+ DLT_LOGSTORAGE_FILTER_CONF_FILESIZE,
+ DLT_LOGSTORAGE_FILTER_CONF_NOFILES,
+ DLT_LOGSTORAGE_FILTER_CONF_SYNCBEHAVIOR,
+ DLT_LOGSTORAGE_FILTER_CONF_ECUID,
+ DLT_LOGSTORAGE_FILTER_CONF_COUNT
+} DltLogstorageFilterConfType;
+
+ int dlt_logstorage_hash_create(int num_entries,
+ struct hsearch_data *htab);
+ int dlt_logstorage_hash_destroy(struct hsearch_data *htab);
+ int dlt_logstorage_hash_add(char *key, void *value,
+ struct hsearch_data *htab);
+ void *dlt_logstorage_hash_find(char *key, struct hsearch_data *htab);
+ int dlt_logstorage_count_ids(const char *str);
+ int dlt_logstorage_read_number(unsigned int *number, char *value);
+ int dlt_logstorage_read_list_of_names(char **names, char *value);
+ int dlt_logstorage_check_apids(DltLogStorageFilterConfig *config, char *value);
+ int dlt_logstorage_check_ctids(DltLogStorageFilterConfig *config, char *value);
+ int dlt_logstorage_check_loglevel(DltLogStorageFilterConfig *config, char *value);
+ int dlt_logstorage_check_filename(DltLogStorageFilterConfig *config, char *value);
+ int dlt_logstorage_check_filesize(DltLogStorageFilterConfig *config, char *value);
+ int dlt_logstorage_check_nofiles(DltLogStorageFilterConfig *config, char *value);
+ int dlt_logstorage_check_sync_strategy(DltLogStorageFilterConfig *config, char *value);
+ int dlt_logstorage_check_ecuid(DltLogStorageFilterConfig *config, char *value);
+ int dlt_logstorage_check_param(DltLogStorageFilterConfig *config,
+ DltLogstorageFilterConfType ctype,
+ char *value);
+ int dlt_logstorage_check_blockmode(DltLogStorage *handle,
+ char *value);
+ int dlt_logstorage_check_general_param(DltLogStorage *handle,
+ DltLogstorageGeneralConfType ctype,
+ char *value);
+ int dlt_daemon_setup_general_properties(DltLogStorage *handle,
+ DltConfigFile *config_file,
+ char *sec_name);
+ int dlt_logstorage_store_filters(DltLogStorage *handle,
+ char *config_file_name);
+ void dlt_logstorage_free(DltLogStorage *handle, int reason);
+ int dlt_logstorage_create_keys(char *appids,
+ char *ctxids,
+ char **keys,
+ int *num_keys);
+ int dlt_logstorage_prepare_table(DltLogStorage *handle,
+ DltLogStorageFilterConfig *data);
+ int dlt_logstorage_validate_filter_name(char *name);
+ void dlt_logstorage_filter_set_strategy(DltLogStorageFilterConfig *config,
+ int strategy);
+ int dlt_logstorage_load_config(DltLogStorage *handle);
+ int dlt_logstorage_filter(DltLogStorage *handle,
+ DltLogStorageFilterConfig **config,
+ char *apid,
+ char *ctid,
+ char *ecuid,
+ int log_level);
+void dlt_logstorage_log_file_name(char *log_file_name,
+ DltLogStorageUserConfig *file_config,
+ char *name,
+ int idx);
+void dlt_logstorage_sort_file_name(DltLogStorageFileList **head);
+void dlt_logstorage_rearrange_file_name(DltLogStorageFileList **head);
+unsigned int dlt_logstorage_get_idx_of_log_file(
+ DltLogStorageUserConfig *file_config,
+ char *file);
+int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config,
+ char *path,
+ DltLogStorageFilterConfig *config);
+int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config,
+ DltLogStorageUserConfig *file_config,
+ char *dev_path,
+ int msg_size);
+/* gtest_dlt_daemon_gateway */
+typedef enum {
+ GW_CONF_IP_ADDRESS = 0,
+ GW_CONF_PORT,
+ GW_CONF_ECUID,
+ GW_CONF_CONNECT,
+ GW_CONF_TIMEOUT,
+ GW_CONF_SEND_CONTROL,
+ GW_CONF_SEND_PERIODIC_CONTROL,
+ GW_CONF_SEND_SERIAL_HEADER,
+ GW_CONF_COUNT
+} DltGatewayConfType;
+int enable_all(DltServiceIdFlag *flags);
+int init_flags(DltServiceIdFlag *flags);
+int set_bit(DltServiceIdFlag *flags, int id);
+int bit(DltServiceIdFlag *flags, int id);
+int dlt_daemon_filter_name(DltMessageFilter *mf,
+ DltFilterConfiguration *config,
+ char *value);
+int dlt_daemon_filter_level(DltMessageFilter *mf,
+ DltFilterConfiguration *config,
+ char *value);
+int dlt_daemon_filter_control_mask(DltMessageFilter *mf,
+ DltFilterConfiguration *config,
+ char *value);
+int dlt_daemon_filter_client_mask(DltMessageFilter *mf,
+ DltFilterConfiguration *config,
+ char *value);
+int dlt_daemon_filter_injections(DltMessageFilter *mf,
+ DltFilterConfiguration *config,
+ char *value);
+int dlt_daemon_set_injection_service_ids(int **ids,
+ int *num,
+ char *value);
+DltInjectionConfig *dlt_daemon_filter_find_injection_by_name(
+ DltInjectionConfig *injections,
+ char *name);
+int dlt_daemon_injection_name(DltMessageFilter *mf,
+ DltInjectionConfig *config,
+ char *value);
+int dlt_daemon_injection_apid(DltMessageFilter *mf,
+ DltInjectionConfig *config,
+ char *value);
+int dlt_daemon_injection_ctid(DltMessageFilter *mf,
+ DltInjectionConfig *config,
+ char *value);
+int dlt_daemon_injection_ecu_id(DltMessageFilter *mf,
+ DltInjectionConfig *config,
+ char *value);
+int dlt_daemon_injection_service_id(DltMessageFilter *mf,
+ DltInjectionConfig *config,
+ char *value);
+int dlt_daemon_get_name(DltMessageFilter *mf, char *val);
+int dlt_daemon_get_default_level(DltMessageFilter *mf, char *val);
+int dlt_daemon_get_backend(DltMessageFilter *mf, char *val);
+int dlt_daemon_setup_filter_section(DltMessageFilter *mf,
+ DltConfigFile *config,
+ char *sec_name);
+int dlt_daemon_setup_filter_properties(DltMessageFilter *mf,
+ DltConfigFile *config,
+ char *sec_name);
+void dlt_daemon_filter_backend_level_changed(unsigned int level,
+ void *ptr1,
+ void *ptr2);
+int dlt_gateway_check_ip(DltGatewayConnection *con, char *value);
+int dlt_gateway_check_port(DltGatewayConnection *con, char *value);
+int dlt_gateway_check_ecu(DltGatewayConnection *con, char *value);
+int dlt_gateway_check_connect_trigger(DltGatewayConnection *con,
+ char *value);
+int dlt_gateway_check_timeout(DltGatewayConnection *con, char *value);
+int dlt_gateway_check_send_serial(DltGatewayConnection *con, char *value);
+int dlt_gateway_allocate_control_messages(DltGatewayConnection *con);
+int dlt_gateway_check_control_messages(DltGatewayConnection *con,
+ char *value);
+int dlt_gateway_check_periodic_control_messages(DltGatewayConnection *con,
+ char *value);
+int dlt_gateway_check_param(DltGateway *gateway,
+ DltGatewayConnection *con,
+ DltGatewayConfType ctype,
+ char *value);
+int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose);
+int dlt_gateway_store_connection(DltGateway *gateway,
+ DltGatewayConnection *tmp,
+ int verbose);
+int dlt_gateway_parse_get_log_info(DltDaemon *daemon,
+ char *ecu,
+ DltMessage *msg,
+ int verbose);
+#endif
diff --git a/tests/gtest_dlt_daemon_event_handler.cpp b/tests/gtest_dlt_daemon_event_handler.cpp
index 86cfb1d..b4a00e0 100644
--- a/tests/gtest_dlt_daemon_event_handler.cpp
+++ b/tests/gtest_dlt_daemon_event_handler.cpp
@@ -216,6 +216,7 @@ TEST(t_dlt_event_handler_cleanup_connections, normal)
}
/* Begin Method: dlt_daemon_event_handler::dlt_connection_check_activate*/
+/*
TEST(t_dlt_connection_check_activate, normal)
{
int ret;
@@ -240,7 +241,7 @@ TEST(t_dlt_connection_check_activate, nullpointer)
{
EXPECT_EQ(DLT_RETURN_ERROR, dlt_connection_check_activate(NULL, NULL, DEACTIVATE));
}
-
+*/
/* Begin Method: dlt_daemon_event_handler::dlt_event_handler_register_connection*/
TEST(t_dlt_event_handler_register_connection, normal)
{
diff --git a/tests/gtest_dlt_daemon_gateway.cpp b/tests/gtest_dlt_daemon_gateway.cpp
index 950f260..f681243 100644
--- a/tests/gtest_dlt_daemon_gateway.cpp
+++ b/tests/gtest_dlt_daemon_gateway.cpp
@@ -61,35 +61,8 @@
extern "C"
{
-#include "dlt-daemon.h"
-#include "dlt_user.h"
-#include "dlt_user_shared.h"
-#include "dlt_user_shared_cfg.h"
-#include "dlt_user_cfg.h"
-#include "dlt-daemon_cfg.h"
-#include "dlt_version.h"
#include "dlt_gateway.h"
-#include "dlt_daemon_common.h"
-#include "dlt_daemon_connection_types.h"
-#include "dlt_daemon_event_handler.h"
-#include "dlt_daemon_connection.h"
-#include "dlt_daemon_event_handler_types.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <limits.h>
-#include <errno.h>
-#include "dlt_config_file_parser.h"
-#include "dlt_common.h"
-#include "dlt-daemon_cfg.h"
-#include "dlt_daemon_event_handler.h"
-#include "dlt_daemon_connection.h"
-#include "dlt_daemon_client.h"
+#include "gtest_common.h"
}
/* Begin Method: dlt_gateway::t_dlt_gateway_init*/
@@ -99,17 +72,20 @@ TEST(t_dlt_gateway_init, normal)
DltGatewayConnection connections;
daemon_local.pGateway.connections = &connections;
daemon_local.pGateway.num_connections = 1;
-
+ daemon_local.flags.lflag = 0;
+ DltFilterConfiguration current;
+ daemon_local.pFilter.current = &current;
DltConnection connections1;
DltReceiver receiver;
daemon_local.pEvent.connections = &connections1;
daemon_local.pEvent.connections->receiver = &receiver;
daemon_local.pEvent.connections->next = NULL;
-
memset(daemon_local.flags.gatewayConfigFile,0,DLT_DAEMON_FLAG_MAX);
strncpy(daemon_local.flags.gatewayConfigFile, "/tmp/dlt_gateway.conf", DLT_DAEMON_FLAG_MAX - 1);
EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_init(&daemon_local, 1));
+
+ dlt_gateway_deinit(&daemon_local.pGateway, 0);
}
TEST(t_dlt_gateway_init, nullpointer)
@@ -123,6 +99,8 @@ TEST(t_dlt_gateway_send_control_message, Normal)
{
int ret = 0;
DltDaemonLocal daemon_local;
+ DltFilterConfiguration current;
+ daemon_local.pFilter.current = &current;
DltGatewayConnection connections;
DltConnection connections1;
DltReceiver receiver1;
@@ -132,11 +110,12 @@ TEST(t_dlt_gateway_send_control_message, Normal)
daemon_local.pEvent.connections->receiver = &receiver1;
memset(daemon_local.flags.gatewayConfigFile,0,DLT_DAEMON_FLAG_MAX);
strncpy(daemon_local.flags.gatewayConfigFile, "/tmp/dlt_gateway.conf", DLT_DAEMON_FLAG_MAX - 1);
-
ret = dlt_gateway_init(&daemon_local, 0);
+
EXPECT_EQ(DLT_RETURN_OK, ret);
- dlt_gateway_send_control_message(daemon_local.pGateway.connections, &daemon_local.pGateway, &daemon_local, 0);
+ dlt_gateway_send_control_message(daemon_local.pGateway.connections, daemon_local.pGateway.connections->p_control_msgs, NULL, 0);
+ dlt_gateway_deinit(&daemon_local.pGateway, 0);
}
TEST(t_dlt_gateway_send_control_message, nullpointer)
@@ -153,11 +132,9 @@ TEST(t_dlt_gateway_store_connection, normal)
DltGateway gateway;
DltGatewayConnection tmp;
DltGatewayConnection tmp1;
-
gateway.num_connections = 1;
gateway.connections = &tmp1;
gateway.connections->status = DLT_GATEWAY_UNINITIALIZED;
-
tmp.ip_address = ip_address;
tmp.ecuid = ecuid;
tmp.sock_domain = 1;
@@ -168,12 +145,18 @@ TEST(t_dlt_gateway_store_connection, normal)
tmp.timeout = 500;
EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_store_connection(&gateway, &tmp, 0));
+ EXPECT_EQ(gateway.connections->sock_domain, tmp.sock_domain);
+ EXPECT_EQ(gateway.connections->sock_type, tmp.sock_type);
+ EXPECT_EQ(gateway.connections->port, tmp.port);
}
TEST(t_dlt_gateway_store_connection, nullpointer)
{
// NULL-Pointer, expect -1
+ DltGateway gateway;
+
EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_store_connection(NULL , NULL, 0));
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_store_connection(&gateway , NULL, 0));
}
/* Begin Method: dlt_gateway::t_dlt_gateway_check_ip*/
@@ -200,6 +183,7 @@ TEST(t_dlt_gateway_check_send_serial, normal)
DltGatewayConnection *con;
char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "134dltgatway";
con = &tmp;
+
EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_check_send_serial(con, value));
}
@@ -209,14 +193,29 @@ TEST(t_dlt_gateway_check_send_serial, nullpointer)
EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_send_serial(NULL,NULL));
}
+/* Begin Method: dlt_gateway::t_dlt_gateway_allocate_control_messages*/
+TEST(t_dlt_gateway_allocate_control_messages, normal)
+{
+ DltGatewayConnection tmp;
+ DltGatewayConnection *con;
+ tmp.p_control_msgs = NULL;
+ con = &tmp;
+ EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_allocate_control_messages(con));
+}
+
+TEST(t_dlt_gateway_allocate_control_messages, nullpointer)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_allocate_control_messages(NULL));
+}
+
/* Begin Method: dlt_gateway::t_dlt_gateway_check_control_messages*/
TEST(t_dlt_gateway_check_control_messages, normal)
{
DltGatewayConnection tmp;
DltGatewayConnection *con;
char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "1,2,3,4,5";
+ tmp.p_control_msgs = NULL;
con = &tmp;
- con->control_msgs[0] = DLT_SERVICE_ID_LAST_ENTRY;
EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_check_control_messages(con, value));
}
@@ -226,6 +225,22 @@ TEST(t_dlt_gateway_check_control_messages, nullpointer)
EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_control_messages(NULL,NULL));
}
+/* Begin Method: dlt_gateway::t_dlt_gateway_check_periodic_control_messages*/
+TEST(t_dlt_gateway_check_periodic_control_messages, normal)
+{
+ DltGatewayConnection tmp;
+ DltGatewayConnection *con;
+ char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "1:5,2:10";
+ tmp.p_control_msgs = NULL;
+ con = &tmp;
+ EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_check_periodic_control_messages(con, value));
+}
+
+TEST(t_dlt_gateway_check_periodic_control_messages, nullpointer)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_periodic_control_messages(NULL,NULL));
+}
+
/* Begin Method: dlt_gateway::t_dlt_gateway_check_port*/
TEST(t_dlt_gateway_check_port, normal)
{
@@ -233,6 +248,7 @@ TEST(t_dlt_gateway_check_port, normal)
DltGatewayConnection *con;
char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "3490";
con = &tmp;
+
EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_check_port(con, value));
}
@@ -242,6 +258,7 @@ TEST(t_dlt_gateway_check_port, abnormal)
DltGatewayConnection *con;
char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "9999999999";
con = &tmp;
+
EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_port(con, value));
}
@@ -258,6 +275,7 @@ TEST(t_dlt_gateway_check_ecu, normal)
DltGatewayConnection *con;
char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "ECU2";
con = &tmp;
+
EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_check_ecu(con, value));
}
@@ -274,6 +292,7 @@ TEST(t_dlt_gateway_check_connect_trigger, normal)
DltGatewayConnection *con;
char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "OnStartup";
con = &tmp;
+
EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_check_connect_trigger(con, value));
}
@@ -283,6 +302,7 @@ TEST(t_dlt_gateway_check_connect_trigger, abnormal)
DltGatewayConnection *con;
char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "wrong_parameter";
con = &tmp;
+
EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_connect_trigger(con, value));
}
@@ -299,6 +319,7 @@ TEST(t_dlt_gateway_check_timeout, normal)
DltGatewayConnection *con;
char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "10";
con = &tmp;
+
EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_check_timeout(con, value));
}
@@ -308,6 +329,7 @@ TEST(t_dlt_gateway_check_timeout, abnormal)
DltGatewayConnection *con;
char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "0";
con = &tmp;
+
EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_timeout(con, value));
}
@@ -325,7 +347,9 @@ TEST(t_dlt_gateway_establish_connections, normal)
DltGatewayConnection connections;
gateway->num_connections = 1;
gateway->connections = &connections;
- gateway->connections->status = DLT_GATEWAY_CONNECTED;
+ gateway->connections->status = DLT_GATEWAY_INITIALIZED;
+ gateway->connections->trigger = DLT_GATEWAY_ON_STARTUP;
+
EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_establish_connections(gateway, &daemon_local, 0));
}
@@ -348,6 +372,7 @@ TEST(t_dlt_gateway_get_connection_receiver, normal)
gateway.connections->client.receiver.fd = 12;
gateway.connections->status = DLT_GATEWAY_CONNECTED;
ret = dlt_gateway_get_connection_receiver(&gateway, fd);
+
EXPECT_EQ(12, ret->fd);
}
@@ -362,6 +387,7 @@ TEST(t_dlt_gateway_get_connection_receiver, abnormal)
gateway.connections->client.sock = fd;
gateway.connections->client.receiver.fd = 12;
ret = dlt_gateway_get_connection_receiver(&gateway, fd);
+
EXPECT_EQ(NULL, ret);
}
@@ -370,9 +396,120 @@ TEST(t_dlt_gateway_get_connection_receiver, nullpointer)
// NULL-Pointer, expect -1
DltReceiver *ret;
ret = dlt_gateway_get_connection_receiver(NULL, 0);
+
EXPECT_EQ(NULL, ret);
}
+/* Begin Method: dlt_gateway::t_dlt_gateway_parse_get_log_info*/
+TEST(t_dlt_gateway_parse_get_log_info, normal)
+{
+ int32_t len;
+ DltDaemon daemon;
+ DltGateway gateway;
+ DltMessage msg;
+ char ecuid[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "ECU2";
+ uint32_t sid = DLT_SERVICE_ID_GET_LOG_INFO;
+ uint8_t status = 7;
+ uint16_t count_app_ids = 1;
+ uint16_t count_context_ids = 1;
+ const char *apid = "LOG";
+ const char *ctid = "TEST";
+ const char *com = "remo";
+ char app_description[] = "Test Application for Logging";
+ char context_description[] = "Test Context for Logging";
+ uint16_t len_app = 0;
+ uint16_t len_con = 0;
+ int8_t log_level = -1;
+ int8_t trace_status = -1;;
+ int offset = 0;
+ memset(&daemon, 0, sizeof(DltDaemon));
+ dlt_set_id(daemon.ecuid, ecuid);
+ EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0));
+ EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu);
+
+ /* create response message */
+ msg.datasize = sizeof(DltServiceGetLogInfoResponse) +
+ sizeof(AppIDsType) +
+ sizeof(ContextIDsInfoType);
+ msg.databuffer = (uint8_t *) malloc(msg.datasize);
+ msg.databuffersize = msg.datasize;
+ memset(msg.databuffer, 0, msg.datasize);
+
+ memcpy(msg.databuffer, &sid, sizeof(uint32_t));
+ offset += sizeof(uint32_t);
+
+ memcpy(msg.databuffer + offset, &status, sizeof(int8_t));
+ offset += sizeof(int8_t);
+
+ memcpy(msg.databuffer + offset, &count_app_ids, sizeof(uint16_t));
+ offset += sizeof(uint16_t);
+
+ dlt_set_id((char*)(msg.databuffer + offset), apid);
+ offset += sizeof(ID4);
+
+ memcpy(msg.databuffer + offset, &count_context_ids, sizeof(uint16_t));
+ offset += sizeof(uint16_t);
+
+ dlt_set_id((char*)(msg.databuffer + offset), ctid);
+ offset += sizeof(ID4);
+
+ memcpy(msg.databuffer + offset, &log_level, sizeof(int8_t));
+ offset += sizeof(int8_t);
+
+ memcpy(msg.databuffer + offset, &trace_status, sizeof(int8_t));
+ offset += sizeof(int8_t);
+
+ len_con = strlen(context_description);
+ memcpy(msg.databuffer + offset, &len_con, sizeof(uint16_t));
+ offset += sizeof(uint16_t);
+
+ memcpy(msg.databuffer + offset, context_description, strlen(context_description));
+ offset += strlen(context_description);
+
+ len_app = strlen(app_description);
+ memcpy(msg.databuffer + offset, &len_app, sizeof(uint16_t));
+ offset += sizeof(uint16_t);
+
+ memcpy(msg.databuffer + offset, app_description, strlen(app_description));
+ offset += strlen(app_description);
+
+ dlt_set_id((char*)(msg.databuffer + offset), com);
+
+ msg.storageheader = (DltStorageHeader*)msg.headerbuffer;
+ dlt_set_storageheader(msg.storageheader, "");
+
+ msg.standardheader = (DltStandardHeader*)(msg.headerbuffer + sizeof(DltStorageHeader));
+ msg.standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1 ;
+ msg.standardheader->mcnt = 0;
+
+ dlt_set_id(msg.headerextra.ecu, ecuid);
+ msg.headerextra.tmsp = dlt_uptime();
+ dlt_message_set_extraparameters(&msg, 0);
+
+ msg.extendedheader = (DltExtendedHeader*)(msg.headerbuffer +
+ sizeof(DltStorageHeader) +
+ sizeof(DltStandardHeader) +
+ DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp) );
+ msg.extendedheader->msin = DLT_MSIN_CONTROL_RESPONSE;
+ msg.extendedheader->noar = 1;
+ dlt_set_id(msg.extendedheader->apid, "");
+ dlt_set_id(msg.extendedheader->ctid, "");
+
+ msg.headersize = sizeof(DltStorageHeader) +
+ sizeof(DltStandardHeader) +
+ sizeof(DltExtendedHeader) +
+ DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp);
+ len = msg.headersize - sizeof(DltStorageHeader) + msg.datasize;
+ msg.standardheader->len = DLT_HTOBE_16(len);
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_parse_get_log_info(&daemon, ecuid, &msg, 0));
+}
+
+TEST(t_dlt_gateway_parse_get_log_info, nullpointer)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_parse_get_log_info(NULL, NULL, NULL, 0));
+}
+
/* Begin Method: dlt_gateway::t_dlt_gateway_process_passive_node_messages*/
TEST(t_dlt_gateway_process_passive_node_messages, normal)
{
@@ -380,9 +517,14 @@ TEST(t_dlt_gateway_process_passive_node_messages, normal)
DltDaemonLocal daemon_local;
DltReceiver receiver;
DltGatewayConnection connections;
+ memset(&daemon, 0, sizeof(DltDaemon));
+ memset(&daemon_local, 0, sizeof(DltDaemonLocal));
+ memset(&receiver, 0, sizeof(DltReceiver));
+ memset(&connections, 0, sizeof(DltGatewayConnection));
daemon_local.pGateway.connections = &connections;
daemon_local.pGateway.num_connections = 1;
daemon_local.pGateway.connections->status = DLT_GATEWAY_CONNECTED;
+
EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_process_passive_node_messages(&daemon,&daemon_local,&receiver,1));
}
@@ -404,13 +546,13 @@ TEST(t_dlt_gateway_process_gateway_timer, normal)
daemon_local.pGateway.connections = &connections;
daemon_local.pGateway.num_connections = 1;
DltLogStorage storage_handle;
- daemon_local.pGateway.connections->status = DLT_GATEWAY_CONNECTED;
+ daemon_local.pGateway.connections->status = DLT_GATEWAY_INITIALIZED;
+ daemon_local.pGateway.connections->trigger = DLT_GATEWAY_ON_STARTUP;
daemon_local.pEvent.connections = &connections1;
daemon_local.pEvent.connections->receiver = &receiver;
daemon.ECUVersionString = ECUVersionString;
daemon.storage_handle = &storage_handle;
-
daemon_local.pEvent.connections->receiver->fd = -1;
EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_process_gateway_timer(&daemon,&daemon_local,daemon_local.pEvent.connections->receiver,1));
@@ -427,12 +569,12 @@ TEST(t_dlt_gateway_process_on_demand_request, normal)
{
char node_id[DLT_ID_SIZE] = "123";
uint32_t connection_status = 1;
-
DltDaemonLocal daemon_local;
DltGatewayConnection connections;
daemon_local.pGateway.connections = &connections;
daemon_local.pGateway.num_connections = 1;
connections.status = DLT_GATEWAY_CONNECTED;
+ connections.trigger = DLT_GATEWAY_ON_STARTUP;
connections.ecuid = node_id;
EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_process_on_demand_request(&daemon_local.pGateway,
@@ -446,7 +588,6 @@ TEST(t_dlt_gateway_process_on_demand_request, abnormal)
{
char node_id[DLT_ID_SIZE] = "123";
uint32_t connection_status = 1;
-
DltDaemonLocal daemon_local;
DltGatewayConnection connections;
daemon_local.pGateway.connections = &connections;
@@ -491,7 +632,6 @@ TEST(t_dlt_gateway_check_param, normal)
TEST(t_dlt_gateway_check_param, abnormal)
{
char value_1[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "10.11.22.33";
-
DltGateway gateway;
DltGatewayConnection tmp;
gateway.connections = &tmp;
@@ -516,7 +656,8 @@ TEST(t_dlt_gateway_configure, Normal)
gateway.connections = &tmp;
gateway.num_connections = 1;
char gatewayConfigFile[DLT_DAEMON_FLAG_MAX];
- strncpy(gatewayConfigFile, DLT_GATEWAY_CONFIG_PATH, DLT_DAEMON_FLAG_MAX - 1);
+ strncpy(gatewayConfigFile, "/tmp/dlt_gateway.conf", DLT_DAEMON_FLAG_MAX - 1);
+
EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_configure(&gateway, gatewayConfigFile, 0));
}
@@ -526,49 +667,10 @@ TEST(t_dlt_gateway_configure, nullpointer)
EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_configure(NULL, NULL, 0));
}
-/* Begin Method: dlt_gateway::t_dlt_gateway_forward_control_message*/
-TEST(t_dlt_gateway_forward_control_message, normal)
-{
- int ret = 0;
- char ecu[DLT_ID_SIZE] = {'E', 'C', 'U', '1'};
- DltDaemonLocal daemon_local;
- DltGatewayConnection connections;
- DltConnection connections1;
- DltReceiver receiver1;
-
- daemon_local.pGateway.connections = &connections;
- daemon_local.pEvent.connections = &connections1;
- daemon_local.pEvent.connections->receiver = &receiver1;
- daemon_local.pEvent.connections->receiver->fd = 1;
- daemon_local.pEvent.connections->next = NULL;
- daemon_local.pGateway.num_connections = 1;
- daemon_local.pEvent.connections->type = DLT_CONNECTION_CLIENT_MSG_TCP;
-
- DltMessage msg;
- memset(daemon_local.flags.gatewayConfigFile,0,DLT_DAEMON_FLAG_MAX);
- strncpy(daemon_local.flags.gatewayConfigFile, "/tmp/dlt_gateway.conf", DLT_DAEMON_FLAG_MAX - 1);
-
- ret = dlt_gateway_init(&daemon_local, 0);
- EXPECT_EQ(DLT_RETURN_OK, ret);
-
- ret = dlt_gateway_forward_control_message(&daemon_local.pGateway,
- &daemon_local,
- &msg,
- ecu,
- 0);
- EXPECT_EQ(DLT_RETURN_OK, ret);
-}
-
-TEST(t_dlt_gateway_forward_control_message, nullpointer)
-{
- // NULL-Pointer, expect -1
- EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_forward_control_message(NULL, NULL, NULL, NULL, 0));
-}
-
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
// ::testing::FLAGS_gtest_break_on_failure = true;
-// ::testing::FLAGS_gtest_filter = "t_dlt_gateway_forward_control_message*";
+// ::testing::FLAGS_gtest_filter = "t_dlt_gateway_process_passive_node_messages*";
return RUN_ALL_TESTS();
}
diff --git a/tests/gtest_dlt_daemon_offline_log.cpp b/tests/gtest_dlt_daemon_offline_log.cpp
new file mode 100644
index 0000000..7711839
--- /dev/null
+++ b/tests/gtest_dlt_daemon_offline_log.cpp
@@ -0,0 +1,1375 @@
+/*!
+ * file gtest_dlt_daemon_logstorage.cpp
+ *
+ * Descriptiom : Unit test for dlt_logstorage.c
+ *
+ * Author : Onkar Palkar
+ *
+ * Email : onkar.palkar@wipro.com
+ *
+ * History : 30-Jun-2016
+*/
+#include <gtest/gtest.h>
+
+extern "C"
+{
+#include "dlt_offline_logstorage.h"
+#include "dlt_offline_logstorage_behavior.h"
+#include "dlt_daemon_offline_logstorage.h"
+#include "dlt_daemon_common_cfg.h"
+#include "gtest_common.h"
+}
+
+#ifndef DLT_DAEMON_BLOCKING_TEST
+#define DLT_DAEMON_BLOCKING_TEST 1
+#endif
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_hash_create*/
+TEST(t_dlt_logstorage_hash_create, normal)
+{
+ struct hsearch_data htab;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5,&htab));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_destroy(&htab));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_hash_add*/
+TEST(t_dlt_logstorage_hash_add, normal)
+{
+ struct hsearch_data htab;
+ char key = 1;
+ char value = 5;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5,&htab));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(&key, &value, &htab));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_destroy(&htab));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_hash_destroy*/
+TEST(t_dlt_logstorage_hash_destroy, normal)
+{
+ struct hsearch_data htab;
+ char key = 1;
+ char value = 5;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5,&htab));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(&key, &value, &htab));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_destroy(&htab));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_hash_find*/
+TEST(t_dlt_logstorage_hash_find, normal)
+{
+ struct hsearch_data htab;
+ char key = 1;
+ char value = 5;
+ char *retData;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5,&htab));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(&key, &value, &htab));
+
+ retData = (char*)dlt_logstorage_hash_find(&key, &htab);
+
+ EXPECT_EQ(5, *retData);
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_destroy(&htab));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_free*/
+TEST(t_dlt_logstorage_free, normal)
+{
+ char key = 1;
+ char value = 5;
+ DltLogStorage handle;
+ int reason = 0;
+ handle.num_configs = 0;
+ handle.filter_keys = (char *)calloc (1, sizeof(char));
+ handle.configs = (DltLogStorageFilterConfig *)calloc (1, sizeof(DltLogStorageFilterConfig));
+ if(handle.filter_keys != NULL && handle.configs != NULL)
+ {
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5,&handle.config_htab));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(&key, &value, &handle.config_htab));
+
+ dlt_logstorage_free(&handle, reason);
+ }
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_count_ids*/
+TEST(t_dlt_logstorage_count_ids, normal)
+{
+ char const *str = "a,b,c,d";
+
+ EXPECT_EQ(4, dlt_logstorage_count_ids(str));
+}
+
+TEST(t_dlt_logstorage_count_ids, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_count_ids(NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_read_number*/
+TEST(t_dlt_logstorage_read_number, normal)
+{
+ char str[] = "100";
+ unsigned int number;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_read_number(&number, str));
+ EXPECT_EQ(100, number);
+}
+
+TEST(t_dlt_logstorage_read_number, null)
+{
+ unsigned int number;
+
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_read_number(&number, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_create_keys*/
+TEST(t_dlt_logstorage_create_keys, normal)
+{
+ DltLogStorageFilterConfig data;
+ char *keys = NULL;
+ int num_keys = 0;
+ char apids;
+ char ctids;
+ data.apids = &apids;
+ data.ctids = &ctids;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_create_keys(data.apids, data.ctids, &keys, &num_keys));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_prepare_table*/
+TEST(t_dlt_logstorage_prepare_table, normal)
+{
+ DltLogStorage handle;
+ DltLogStorageFilterConfig data;
+ memset(&handle, 0, sizeof(DltLogStorage));
+ memset(&data, 0, sizeof(DltLogStorageFilterConfig));
+ char apids;
+ char ctids;
+ char filter_keys;
+ data.apids = &apids;
+ data.ctids = &ctids;
+ handle.num_filter_keys = 1;
+ data.records = NULL;
+ data.log = NULL;
+ data.cache = NULL;
+ handle.filter_keys = &filter_keys;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5,&handle.config_htab));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_table(&handle, &data));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_destroy(&handle.config_htab));
+}
+
+TEST(t_dlt_logstorage_prepare_table, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_prepare_table(NULL, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_validate_filter_name*/
+TEST(t_dlt_logstorage_validate_filter_name, normal)
+{
+ char name[] = "FILTER100";
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_validate_filter_name(name));
+}
+
+TEST(t_dlt_logstorage_validate_filter_name, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_validate_filter_name(NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_filter_set_strategy*/
+TEST(t_dlt_logstorage_filter_set_strategy, normal)
+{
+ DltLogStorageFilterConfig config;
+ dlt_logstorage_filter_set_strategy(&config, DLT_LOGSTORAGE_SYNC_ON_MSG);
+
+ EXPECT_EQ(&dlt_logstorage_prepare_on_msg, config.dlt_logstorage_prepare);
+
+ dlt_logstorage_filter_set_strategy(&config, 2);
+
+ EXPECT_EQ(&dlt_logstorage_prepare_msg_cache, config.dlt_logstorage_prepare);
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_read_list_of_names*/
+TEST(t_dlt_logstorage_read_list_of_names, normal)
+{
+ char *namesPtr = NULL;
+ char value[] = "a,b,c,d";
+
+ namesPtr = (char *)calloc (1, sizeof(char));
+ if(namesPtr != NULL)
+ {
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_read_list_of_names(&namesPtr, value));
+
+ free(namesPtr);
+ }
+}
+
+TEST(t_dlt_logstorage_read_list_of_names, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_read_list_of_names(NULL, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_check_apids*/
+TEST(t_dlt_logstorage_check_apids, normal)
+{
+ char value[] = "a,b,c,d";
+ DltLogStorageFilterConfig config;
+ config.apids = (char *)calloc (1, sizeof(char));
+ if(config.apids != NULL)
+ {
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_apids(&config, value));
+
+ free(config.apids);
+ }
+}
+
+TEST(t_dlt_logstorage_check_apids, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_check_apids(NULL, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_check_ctids*/
+TEST(t_dlt_logstorage_check_ctids, normal)
+{
+ char value[] = "a,b,c,d";
+ DltLogStorageFilterConfig config;
+ config.ctids = (char *)calloc (1, sizeof(char));
+ if(config.ctids != NULL)
+ {
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_ctids(&config, value));
+
+ free(config.ctids);
+ }
+}
+
+TEST(t_dlt_logstorage_check_ctids, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_check_ctids(NULL, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_check_loglevel*/
+TEST(t_dlt_logstorage_check_loglevel, normal)
+{
+ char value[] = "DLT_LOG_FATAL";
+ DltLogStorageFilterConfig config;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_loglevel(&config, value));
+ EXPECT_EQ(1, config.log_level);
+}
+
+TEST(t_dlt_logstorage_check_loglevel, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_check_loglevel(NULL, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_check_filename*/
+TEST(t_dlt_logstorage_check_filename, normal)
+{
+ char value[] = "file_name";
+ DltLogStorageFilterConfig config;
+ config.file_name = (char *)calloc (1, sizeof(char));
+ if(config.file_name != NULL)
+ {
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_filename(&config, value));
+
+ free(config.file_name);
+ }
+}
+
+TEST(t_dlt_logstorage_check_filename, abnormal)
+{
+ char value[] = "../file_name";
+ DltLogStorageFilterConfig config;
+ config.file_name = (char *)calloc (1, sizeof(char));
+ if(config.file_name != NULL)
+ {
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_check_filename(&config, value));
+
+ free(config.file_name);
+ }
+}
+
+TEST(t_dlt_logstorage_check_filename, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_check_filename(NULL, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_check_filesize*/
+TEST(t_dlt_logstorage_check_filesize, normal)
+{
+ char value[] = "100";
+ DltLogStorageFilterConfig config;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_filesize(&config, value));
+ EXPECT_EQ(100, config.file_size);
+}
+
+TEST(t_dlt_logstorage_check_filesize, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_check_filesize(NULL, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_check_nofiles*/
+TEST(t_dlt_logstorage_check_nofiles, normal)
+{
+ char value[] = "100";
+ DltLogStorageFilterConfig config;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_nofiles(&config, value));
+ EXPECT_EQ(100, config.num_files);
+}
+
+TEST(t_dlt_logstorage_check_nofiles, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_check_nofiles(NULL, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_check_sync_strategy*/
+TEST(t_dlt_logstorage_check_sync_strategy, normal)
+{
+ char value[] = "ON_MSG";
+ DltLogStorageFilterConfig config;
+ config.sync = 0;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_sync_strategy(&config, value));
+ EXPECT_EQ(DLT_LOGSTORAGE_SYNC_ON_MSG, config.sync);
+}
+
+TEST(t_dlt_logstorage_check_sync_strategy, abnormal)
+{
+ char value[] = "UNKNOWN";
+ DltLogStorageFilterConfig config;
+ config.sync = 0;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_sync_strategy(&config, value));
+ EXPECT_EQ(DLT_LOGSTORAGE_SYNC_ON_MSG, config.sync);
+}
+
+TEST(t_dlt_logstorage_check_sync_strategy, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_check_sync_strategy(NULL, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_check_ecuid*/
+TEST(t_dlt_logstorage_check_ecuid, normal)
+{
+ char value[] = "213";
+ DltLogStorageFilterConfig config;
+ config.ecuid = (char *)calloc (1, sizeof(char));
+ if(config.ecuid != NULL)
+ {
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_ecuid(&config, value));
+ EXPECT_EQ('2', *config.ecuid);
+ EXPECT_EQ('1', *(config.ecuid+1));
+ EXPECT_EQ('3', *(config.ecuid+2));
+
+ free(config.ecuid);
+ }
+}
+
+TEST(t_dlt_logstorage_check_ecuid, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_check_ecuid(NULL, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_check_param*/
+TEST(t_dlt_logstorage_check_param, normal)
+{
+ char value[] = "100";
+ DltLogStorageFilterConfig config;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_param(&config, DLT_LOGSTORAGE_FILTER_CONF_FILESIZE, value));
+ EXPECT_EQ(100, config.file_size);
+}
+
+TEST(t_dlt_logstorage_check_param, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_check_param(NULL, DLT_LOGSTORAGE_FILTER_CONF_FILESIZE, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_store_filters*/
+TEST(t_dlt_logstorage_store_filters, normal)
+{
+ DltLogStorage handle;
+ char config_file_name[] = "/tmp/dlt_logstorage.conf";
+ handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED;
+ handle.config_status = 0;
+ handle.write_errors = 0;
+ handle.num_filter_keys = 0;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5,&(handle.config_htab)));
+
+ handle.configs = NULL;
+ handle.filter_keys = NULL;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_store_filters(&handle, config_file_name));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_destroy(&handle.config_htab));
+}
+
+TEST(t_dlt_logstorage_store_filters, null)
+{
+ EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_logstorage_store_filters(NULL, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_load_config*/
+TEST(t_dlt_logstorage_load_config, normal)
+{
+ DltLogStorage handle;
+ handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED;
+ handle.config_status = 0;
+ handle.write_errors = 0;
+ handle.num_filter_keys = 0;
+ handle.configs = NULL;
+ handle.filter_keys = NULL;
+ strncpy(handle.device_mount_point, "/tmp", DLT_MOUNT_PATH_MAX);
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_load_config(&handle));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_destroy(&handle.config_htab));
+}
+
+TEST(t_dlt_logstorage_load_config, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_load_config(NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_device_connected*/
+TEST(t_dlt_logstorage_device_connected, normal)
+{
+ DltLogStorage handle;
+ char mount_point[DLT_MOUNT_PATH_MAX] = "/tmp";
+ handle.config_status = 0;
+ handle.connection_type = 0;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_device_connected(&handle, mount_point));
+}
+
+TEST(t_dlt_logstorage_device_connected, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_device_connected(NULL, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_device_disconnected*/
+TEST(t_dlt_logstorage_device_disconnected, normal)
+{
+ DltLogStorage handle;
+ int reason = 0;
+ handle.config_status = 0;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_device_disconnected(&handle, reason));
+}
+
+TEST(t_dlt_logstorage_device_disconnected, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_device_disconnected(NULL, 1));
+}
+
+TEST(t_dlt_logstorage_get_loglevel_by_key, normal)
+{
+ char arr[] = "abc";
+ char *key = arr;
+ DltLogStorageFilterConfig config;
+ DltLogStorage handle;
+ handle.config_status = 0;
+ handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED;
+ handle.config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE;
+
+ config.log_level = DLT_LOG_ERROR;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5,&(handle.config_htab)));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key, &config, &(handle.config_htab)));
+ EXPECT_GE(DLT_LOG_ERROR, dlt_logstorage_get_loglevel_by_key(&handle, key));
+}
+
+TEST(t_dlt_logstorage_get_loglevel_by_key, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_get_loglevel_by_key(NULL, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_get_config*/
+TEST(t_dlt_logstorage_get_config, normal)
+{
+ char apid[] = "1234";
+ char ctid[] = "5678";
+ char ecuid[] = "12";
+ int num_config = 0;
+ DltLogStorageFilterConfig value;
+ value.log_level = 0;
+ value.apids = apid;
+ value.ctids = ctid;
+ value.ecuid = ecuid;
+ char key0[] = "1234:\000\000\000\000";
+ char key1[] = ":5678\000\000\000\000";
+ char key2[] = "1234:5678";
+ DltLogStorageFilterConfig *config[3] = {0};
+ DltLogStorage handle;
+ handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED;
+ handle.config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5, &(handle.config_htab)));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key0, &value, &(handle.config_htab)));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key1, &value, &(handle.config_htab)));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key2, &value, &(handle.config_htab)));
+
+ num_config = dlt_logstorage_get_config(&handle, config, apid, ctid);
+
+ EXPECT_EQ(num_config, 3);
+}
+
+TEST(t_dlt_logstorage_get_config, null)
+{
+ int num = -1;
+ num = dlt_logstorage_get_config(NULL, NULL, NULL, NULL);
+
+ EXPECT_EQ(num, 0);
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_filter*/
+TEST(t_dlt_logstorage_filter, normal)
+{
+ char apid[] = "1234";
+ char ctid[] = "5678";
+ char ecuid[] = "12";
+ int num = 1;
+ DltLogStorageFilterConfig value;
+ value.apids = apid;
+ value.ctids = ctid;
+ value.ecuid = ecuid;
+ char key0[] = "1234:\000\000\000\000";
+ char key1[] = ":5678\000\000\000\000";
+ char key2[] = "1234:5678";
+ DltLogStorageFilterConfig *config[3] = {0};
+ DltLogStorage handle;
+ handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED;
+ handle.config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5, &(handle.config_htab)));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key0, &value, &(handle.config_htab)));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key1, &value, &(handle.config_htab)));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key2, &value, &(handle.config_htab)));
+
+ num = dlt_logstorage_filter(&handle, config, apid, ctid, ecuid, 0);
+
+ EXPECT_EQ(num, 3);
+}
+
+TEST(t_dlt_logstorage_filter, null)
+{
+ DltLogStorageFilterConfig *config[3] = {0};
+ int num = dlt_logstorage_filter(NULL, config, NULL, NULL, NULL, 0);
+ EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, num);
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_write*/
+TEST(t_dlt_logstorage_write, normal)
+{
+ char apid[] = "1234";
+ char ctid[] = "5678";
+ char ecuid[] = "12";
+ DltLogStorage handle;
+ DltLogStorageUserConfig uconfig;
+ unsigned char data1[] = "123";
+ int size1 = 3;
+ unsigned char data2[] = "123";
+ int size2 = 3;
+ unsigned char data3[] = "123";
+ int size3 = 3;
+ handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED;
+ handle.config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE;
+ DltLogStorageFilterConfig value;
+ value.apids = apid;
+ value.ctids = ctid;
+ value.ecuid = ecuid;
+ char key0[] = "1234:\000\000\000\000";
+ char key1[] = ":5678\000\000\000\000";
+ char key2[] = "1234:5678";
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5, &(handle.config_htab)));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key0, &value, &(handle.config_htab)));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key1, &value, &(handle.config_htab)));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key2, &value, &(handle.config_htab)));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write(&handle, &uconfig, data1, size1, data2, size2, data3, size3));
+}
+
+TEST(t_dlt_logstorage_write, null)
+{
+ EXPECT_EQ(0, dlt_logstorage_write(NULL, NULL, NULL, 1, NULL, 1, NULL, 1));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_sync_caches*/
+TEST(t_dlt_logstorage_sync_caches, normal)
+{
+ char apid[] = "1234";
+ char ctid[] = "5678";
+ char ecuid[] = "12";
+ DltLogStorage handle;
+ handle.num_configs = 1;
+ DltLogStorageFilterConfig configs;
+ handle.configs = &configs;
+ configs.apids = apid;
+ configs.ctids = ctid;
+ configs.ecuid = ecuid;
+ dlt_logstorage_filter_set_strategy(handle.configs, DLT_LOGSTORAGE_SYNC_ON_MSG);
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_sync_caches(&handle));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_log_file_name*/
+TEST(t_dlt_logstorage_log_file_name, normal)
+{
+ char log_file_name[DLT_MOUNT_PATH_MAX] = {'\0'};
+ DltLogStorageUserConfig file_config;
+ file_config.logfile_delimiter = '/';
+ file_config.logfile_maxcounter = 0;
+ file_config.logfile_timestamp = 1;
+ file_config.logfile_counteridxlen = 10;
+ int cmpRes = 0;
+ char name[] = "log";
+ dlt_logstorage_log_file_name(log_file_name, &file_config, name, 0);
+ cmpRes = strncmp(log_file_name, "log/0000000000", 14);
+
+ EXPECT_EQ(0, cmpRes);
+}
+
+TEST(t_dlt_logstorage_log_file_name, null)
+{
+ char name[] = "log";
+ dlt_logstorage_log_file_name(NULL, NULL, name, 0);
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_sort_file_name*/
+TEST(t_dlt_logstorage_sort_file_name, normal)
+{
+ DltLogStorageFileList *node1, *node2, *node3;;
+ DltLogStorageFileList **head;
+ node1 = (DltLogStorageFileList *)calloc (1, sizeof(DltLogStorageFileList));
+ node2 = (DltLogStorageFileList *)calloc (1, sizeof(DltLogStorageFileList));
+ node3 = (DltLogStorageFileList *)calloc (1, sizeof(DltLogStorageFileList));
+ if(node1 != NULL && node2 != NULL && node3 != NULL)
+ {
+ node1->next = node2;
+ node2->next = node3;
+ node3->next = NULL;
+ head = &node1;
+
+ node1->idx = 8;
+ node2->idx = 4;
+ node3->idx = 1;
+
+ EXPECT_EQ(8, (*head)->idx);
+ EXPECT_EQ(4, ((*head)->next)->idx);
+ EXPECT_EQ(1, ((((*head)->next)->next)->idx));
+
+ dlt_logstorage_sort_file_name(head);
+
+ EXPECT_EQ(1, (*head)->idx);
+ EXPECT_EQ(4, ((*head)->next)->idx);
+ EXPECT_EQ(8, ((((*head)->next)->next)->idx));
+ free((((*head)->next)->next));
+ free(((*head)->next));
+ free(*head);
+ node1 = NULL;
+ node2 = NULL;
+ node3 = NULL;
+ }
+ if(node1 != NULL)
+ {
+ free(node1);
+ }
+ if(node2 != NULL)
+ {
+ free(node2);
+ }
+ if(node3 != NULL)
+ {
+ free(node3);
+ }
+}
+
+TEST(t_dlt_logstorage_sort_file_name, null)
+{
+ dlt_logstorage_sort_file_name(NULL);
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_rearrange_file_name*/
+TEST(t_dlt_logstorage_rearrange_file_name, normal)
+{
+ DltLogStorageFileList *node1, *node2, *node3;;
+ DltLogStorageFileList **head;
+ node1 = (DltLogStorageFileList *)calloc (1, sizeof(DltLogStorageFileList));
+ node2 = (DltLogStorageFileList *)calloc (1, sizeof(DltLogStorageFileList));
+ node3 = (DltLogStorageFileList *)calloc (1, sizeof(DltLogStorageFileList));
+ if((node1 != NULL) && (node2 != NULL) && (node3 != NULL))
+ {
+
+ node1->next = node2;
+ node2->next = node3;
+ node3->next = NULL;
+
+ head = &node1;
+
+ node1->idx = 8;
+ node2->idx = 4;
+ node3->idx = 1;
+
+ EXPECT_EQ(8, (*head)->idx);
+ EXPECT_EQ(4, ((*head)->next)->idx);
+ EXPECT_EQ(1, ((((*head)->next)->next)->idx));
+
+ dlt_logstorage_rearrange_file_name(head);
+
+ EXPECT_EQ(1, (*head)->idx);
+ EXPECT_EQ(8, ((*head)->next)->idx);
+ EXPECT_EQ(4, ((((*head)->next)->next)->idx));
+ free((((*head)->next)->next));
+ free(((*head)->next));
+ free(*head);
+ node1 = NULL;
+ node2 = NULL;
+ node3 = NULL;
+ }
+ if(node1 != NULL)
+ {
+ free(node1);
+ }
+ if(node2 != NULL)
+ {
+ free(node2);
+ }
+ if(node3 != NULL)
+ {
+ free(node3);
+ }
+}
+
+TEST(t_dlt_logstorage_rearrange_file_name, null)
+{
+ dlt_logstorage_rearrange_file_name(NULL);
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_get_idx_of_log_file*/
+TEST(t_dlt_logstorage_get_idx_of_log_file, normal)
+{
+ DltLogStorageUserConfig file_config;
+ file_config.logfile_timestamp =191132;
+ file_config.logfile_delimiter = {'_'};
+ file_config.logfile_maxcounter = 2;
+ file_config.logfile_counteridxlen = 2;
+ char *file = (char*)"Test_002_20160509_191132.dlt";
+
+ EXPECT_EQ(2, dlt_logstorage_get_idx_of_log_file(&file_config, file));
+}
+TEST(t_dlt_logstorage_get_idx_of_log_file, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_get_idx_of_log_file(NULL, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_storage_dir_info*/
+TEST(t_dlt_logstorage_storage_dir_info, normal)
+{
+ DltLogStorageUserConfig file_config;
+ file_config.logfile_timestamp =191132;
+ file_config.logfile_delimiter = {'_'};
+ file_config.logfile_maxcounter = 2;
+ file_config.logfile_counteridxlen = 2;
+ char *path = (char*)"/tmp";
+ DltLogStorageFilterConfig config;
+ char apids;
+ char ctids;
+ config.apids = &apids;
+ config.ctids = &ctids;
+ config.file_name = (char*)"Test_002_20160509_191132.dlt";
+ config.records = NULL;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_storage_dir_info(&file_config, path, &config));
+}
+TEST(t_dlt_logstorage_storage_dir_info, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_storage_dir_info(NULL, NULL, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_open_log_file*/
+TEST(t_dlt_logstorage_open_log_file, normal)
+{
+ DltLogStorageUserConfig file_config;
+ file_config.logfile_timestamp =191132;
+ file_config.logfile_delimiter = {'_'};
+ file_config.logfile_maxcounter = 2;
+ file_config.logfile_counteridxlen = 2;
+ char *path = (char*)"/tmp";
+ DltLogStorageFilterConfig config;
+ char apids;
+ char ctids;
+ config.apids = &apids;
+ config.ctids = &ctids;
+ config.file_name = (char*)"Test";
+ config.records = NULL;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_open_log_file(&config, &file_config, path, 1));
+}
+TEST(t_dlt_logstorage_open_log_file, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_open_log_file(NULL, NULL, NULL, 0));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_prepare_on_msg*/
+TEST(t_dlt_logstorage_prepare_on_msg, normal)
+{
+ DltLogStorageUserConfig file_config;
+ file_config.logfile_timestamp =191132;
+ file_config.logfile_delimiter = {'_'};
+ file_config.logfile_maxcounter = 2;
+ file_config.logfile_counteridxlen = 2;
+ char *path = (char*)"/tmp";
+ DltLogStorageFilterConfig config;
+ char apids;
+ char ctids;
+ config.apids = &apids;
+ config.ctids = &ctids;
+ config.file_name = (char*)"Test";
+ config.records = NULL;
+ config.log = NULL;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_on_msg(&config, &file_config, path, 1));
+}
+
+TEST(t_dlt_logstorage_prepare_on_msg, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_prepare_on_msg(NULL, NULL, NULL, 0));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_write_on_msg*/
+TEST(t_dlt_logstorage_write_on_msg, normal)
+{
+ DltLogStorageUserConfig file_config;
+ file_config.logfile_timestamp =191132;
+ file_config.logfile_delimiter = {'_'};
+ file_config.logfile_maxcounter = 2;
+ file_config.logfile_counteridxlen = 2;
+ char *path = (char*)"/tmp";
+ DltLogStorageFilterConfig config;
+ char apids;
+ char ctids;
+ config.apids = &apids;
+ config.ctids = &ctids;
+ config.file_name = (char*)"Test";
+ config.records = NULL;
+ config.log = NULL;
+ unsigned int size = 8;
+ unsigned char data1[] = "dlt_data";
+ unsigned char data2[] = "dlt_data";
+ unsigned char data3[] = "dlt_data";
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_on_msg(&config, &file_config, path, 1));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write_on_msg(&config, data1, size, data2, size, data3, size));
+}
+
+TEST(t_dlt_logstorage_write_on_msg, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_write_on_msg(NULL, NULL, 0, NULL, 0, NULL, 0));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_sync_on_msg*/
+TEST(t_dlt_logstorage_sync_on_msg, normal)
+{
+ DltLogStorageFilterConfig config;
+ char apids;
+ char ctids;
+ config.apids = &apids;
+ config.ctids = &ctids;
+ config.file_name = (char*)"Test";
+ config.records = NULL;
+ config.log = NULL;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_sync_on_msg(&config, DLT_LOGSTORAGE_SYNC_ON_MSG));
+}
+
+TEST(t_dlt_logstorage_sync_on_msg, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_sync_on_msg(NULL, 0));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_prepare_msg_cache*/
+TEST(t_dlt_logstorage_prepare_msg_cache, normal)
+{
+ DltLogStorageUserConfig file_config;
+ file_config.logfile_timestamp =191132;
+ file_config.logfile_delimiter = {'_'};
+ file_config.logfile_maxcounter = 2;
+ file_config.logfile_counteridxlen = 2;
+ char *path = (char*)"/tmp";
+ DltLogStorageFilterConfig config;
+ char apids;
+ char ctids;
+ config.apids = &apids;
+ config.ctids = &ctids;
+ config.file_name = (char*)"Test";
+ config.records = NULL;
+ config.log = NULL;
+ config.cache = NULL;
+ config.file_size = 0;
+ g_logstorage_cache_max = 16;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_msg_cache(&config, &file_config, path, 1));
+
+ free(config.cache);
+}
+
+TEST(t_dlt_logstorage_prepare_msg_cache, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_prepare_msg_cache(NULL, NULL, NULL, 0));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_write_msg_cache*/
+TEST(t_dlt_logstorage_write_msg_cache, normal)
+{
+ unsigned int size = 10;
+ unsigned char data1[10] = "dlt_data1";
+ unsigned char data2[10] = "dlt_data2";
+ unsigned char data3[10] = "dlt_dat3";
+ DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
+
+ config.cache = calloc(1, 50 + sizeof(DltLogStorageCacheFooter));
+ if(config.cache != NULL)
+ {
+ config.file_size = 50;
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write_msg_cache(&config, data1, size, data2, size, data3, size));
+
+ free(config.cache);
+ config.cache = NULL;
+ }
+}
+
+TEST(t_dlt_logstorage_write_msg_cache, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_write_msg_cache(NULL, NULL, 0, NULL, 0, NULL, 0));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_split_key*/
+TEST(t_dlt_logstorage_split_key, normal)
+{
+ char key[] = "dlt:1020";
+ char appid[] = "2345";
+ char ctxid[] = "6789";
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_split_key(key, appid, ctxid));
+}
+
+TEST(t_dlt_logstorage_split_key, null)
+{
+ char key[] = "dlt:1020";
+ char appid[] = "2345";
+ char ctxid[] = "6789";
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_split_key(NULL, NULL, NULL));
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_split_key(NULL, appid, ctxid));
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_split_key(key, NULL, ctxid));
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_split_key(key, appid, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_update_all_contexts*/
+TEST(t_dlt_logstorage_update_all_contexts, normal)
+{
+ DltDaemon daemon;
+ DltGateway gateway;
+ memset(&daemon, 0, sizeof(DltDaemon));
+ memset(&gateway, 0, sizeof(DltGateway));
+ char ecu[] = "ECU1";
+
+ EXPECT_EQ(0, dlt_daemon_init(&daemon,
+ DLT_DAEMON_RINGBUFFER_MIN_SIZE,
+ DLT_DAEMON_RINGBUFFER_MAX_SIZE,
+ DLT_DAEMON_RINGBUFFER_STEP_SIZE,
+ DLT_RUNTIME_DEFAULT_DIRECTORY,
+ DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0));
+ dlt_set_id(daemon.ecuid, ecu);
+ EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_update_all_contexts(&daemon, ecu, 1, 1, 0));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_update_all_contexts(&daemon, ecu, 0, 1, 0));
+}
+
+TEST(t_dlt_logstorage_update_all_contexts, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_update_all_contexts(NULL, NULL, 0, 0, 0));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_update_context*/
+TEST(t_dlt_logstorage_update_context, normal)
+{
+ DltDaemon daemon;
+ DltGateway gateway;
+ DltDaemonContext *daecontext = NULL;
+ memset(&daemon, 0, sizeof(DltDaemon));
+ memset(&gateway, 0, sizeof(DltGateway));
+
+ char apid[] = "123";
+ char ctid[] = "456";
+ char desc[255] = "TEST dlt_logstorage_update_context";
+ char ecu[] = "ECU1";
+
+ EXPECT_EQ(0, dlt_daemon_init(&daemon,
+ DLT_DAEMON_RINGBUFFER_MIN_SIZE,
+ DLT_DAEMON_RINGBUFFER_MAX_SIZE,
+ DLT_DAEMON_RINGBUFFER_STEP_SIZE,
+ DLT_RUNTIME_DEFAULT_DIRECTORY,
+ DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0));
+ dlt_set_id(daemon.ecuid, ecu);
+ EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0));
+ daecontext = dlt_daemon_context_add(&daemon, apid, ctid, DLT_LOG_DEFAULT,
+ DLT_TRACE_STATUS_DEFAULT, 0, 0, desc, daemon.ecuid, 0);
+ EXPECT_EQ((DltDaemonContext*)(NULL), daecontext);
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_update_context(&daemon, apid, ctid, 1, 0));
+}
+
+TEST(t_dlt_logstorage_update_context, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_update_context(NULL, NULL, NULL, 0, 0));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_update_context_loglevel*/
+TEST(t_dlt_logstorage_update_context_loglevel, normal)
+{
+ DltDaemon daemon;
+ DltGateway gateway;
+ DltDaemonContext *daecontext = NULL;
+ memset(&daemon, 0, sizeof(DltDaemon));
+ memset(&gateway, 0, sizeof(DltGateway));
+
+ char apid[] = "123";
+ char ctid[] = "456";
+ char key[] = "123:456";
+ char desc[255] = "TEST dlt_logstorage_update_context";
+ char ecu[] = "ECU1";
+
+ EXPECT_EQ(0, dlt_daemon_init(&daemon,
+ DLT_DAEMON_RINGBUFFER_MIN_SIZE,
+ DLT_DAEMON_RINGBUFFER_MAX_SIZE,
+ DLT_DAEMON_RINGBUFFER_STEP_SIZE,
+ DLT_RUNTIME_DEFAULT_DIRECTORY,
+ DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0));
+ dlt_set_id(daemon.ecuid, ecu);
+ EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0));
+
+ daecontext = dlt_daemon_context_add(&daemon, apid, ctid, DLT_LOG_DEFAULT,
+ DLT_TRACE_STATUS_DEFAULT, 0, 0, desc, daemon.ecuid, 0);
+
+ EXPECT_EQ((DltDaemonContext*)(NULL), daecontext);
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_update_context_loglevel
+ (&daemon, key, 1, 0));
+}
+
+TEST(t_dlt_logstorage_update_context_loglevel, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_update_context_loglevel(NULL, NULL, 0, 0));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_daemon_logstorage_reset_application_loglevel*/
+TEST(t_dlt_daemon_logstorage_reset_application_loglevel, normal)
+{
+ DltDaemon daemon;
+ DltGateway gateway;
+ memset(&daemon, 0, sizeof(DltDaemon));
+ memset(&gateway, 0, sizeof(DltGateway));
+ char ecu[] = "ECU1";
+ int device_index = 0;
+ EXPECT_EQ(0, dlt_daemon_init(&daemon,
+ DLT_DAEMON_RINGBUFFER_MIN_SIZE,
+ DLT_DAEMON_RINGBUFFER_MAX_SIZE,
+ DLT_DAEMON_RINGBUFFER_STEP_SIZE,
+ DLT_RUNTIME_DEFAULT_DIRECTORY,
+ DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0));
+ dlt_set_id(daemon.ecuid, ecu);
+ EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0));
+ EXPECT_NO_THROW(dlt_daemon_logstorage_reset_application_loglevel(&daemon, device_index, 1, 0));
+}
+
+TEST(t_dlt_daemon_logstorage_reset_application_loglevel, null)
+{
+ EXPECT_NO_THROW(dlt_daemon_logstorage_reset_application_loglevel(NULL, 0, 0, 0));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_daemon_logstorage_update_application_loglevel*/
+TEST(t_dlt_daemon_logstorage_update_application_loglevel, normal)
+{
+ char ecu[] = "ECU1";
+ int device_index = 0;
+ DltDaemon daemon;
+ DltGateway gateway;
+ memset(&daemon, 0, sizeof(DltDaemon));
+ memset(&gateway, 0, sizeof(DltGateway));
+ DltLogStorageFilterConfig value;
+ value.log_level = 5;
+ DltLogStorage storage_handle;
+
+ EXPECT_EQ(0, dlt_daemon_init(&daemon,
+ DLT_DAEMON_RINGBUFFER_MIN_SIZE,
+ DLT_DAEMON_RINGBUFFER_MAX_SIZE,
+ DLT_DAEMON_RINGBUFFER_STEP_SIZE,
+ DLT_RUNTIME_DEFAULT_DIRECTORY,
+ DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0));
+ dlt_set_id(daemon.ecuid, ecu);
+ EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0));
+
+ daemon.storage_handle = &storage_handle;
+ daemon.storage_handle->connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED;
+ daemon.storage_handle->num_filter_keys = 1;
+ daemon.storage_handle->config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE;
+ daemon.storage_handle->filter_keys = (char*)calloc(
+ DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN, sizeof(char));
+ strncpy(daemon.storage_handle->filter_keys, "key:1020",
+ DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN);
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5, &(daemon.storage_handle->config_htab)));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(daemon.storage_handle->filter_keys, &value, &(daemon.storage_handle->config_htab)));
+ EXPECT_NO_THROW(dlt_daemon_logstorage_update_application_loglevel(&daemon, device_index, 0));
+ free(daemon.storage_handle->filter_keys);
+}
+
+TEST(t_dlt_daemon_logstorage_update_application_loglevel, null)
+{
+ EXPECT_NO_THROW(dlt_daemon_logstorage_update_application_loglevel(NULL, 0, 0));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_daemon_logstorage_get_loglevel*/
+TEST(t_dlt_daemon_logstorage_get_loglevel, normal)
+{
+ char ecu[] = "ECU1";
+ char apid[] = "1234";
+ char ctid[] = "5678";
+ int device_index = 0;
+ DltDaemon daemon;
+ DltGateway gateway;
+ memset(&daemon, 0, sizeof(DltDaemon));
+ memset(&gateway, 0, sizeof(DltGateway));
+ DltLogStorageFilterConfig value;
+ value.log_level = 5;
+ value.apids = apid;
+ value.ctids = ctid;
+ value.ecuid = ecu;
+ DltLogStorage storage_handle;
+
+ EXPECT_EQ(0, dlt_daemon_init(&daemon,
+ DLT_DAEMON_RINGBUFFER_MIN_SIZE,
+ DLT_DAEMON_RINGBUFFER_MAX_SIZE,
+ DLT_DAEMON_RINGBUFFER_STEP_SIZE,
+ DLT_RUNTIME_DEFAULT_DIRECTORY,
+ DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0));
+ dlt_set_id(daemon.ecuid, ecu);
+ EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0));
+
+ daemon.storage_handle = &storage_handle;
+ daemon.storage_handle->connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED;
+ daemon.storage_handle->num_filter_keys = 1;
+ daemon.storage_handle->config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE;
+ daemon.storage_handle->filter_keys = (char*)calloc(
+ DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN, sizeof(char));
+ strncpy(daemon.storage_handle->filter_keys, "1234:5678",
+ DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN);
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5, &(daemon.storage_handle->config_htab)));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(daemon.storage_handle->
+ filter_keys, &value, &(daemon.storage_handle->config_htab)));
+ EXPECT_NO_THROW(dlt_daemon_logstorage_update_application_loglevel(&daemon, device_index, 0));
+
+ EXPECT_EQ(5, dlt_daemon_logstorage_get_loglevel(&daemon, 1, apid, ctid));
+ free(daemon.storage_handle->filter_keys);
+}
+
+TEST(t_dlt_daemon_logstorage_get_loglevel, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_daemon_logstorage_get_loglevel(NULL, 0, NULL, NULL));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_daemon_logstorage_write*/
+TEST(t_dlt_daemon_logstorage_write, normal)
+{
+ DltDaemon daemon;
+ DltGateway gateway;
+ memset(&daemon, 0, sizeof(DltDaemon));
+ memset(&gateway, 0, sizeof(DltGateway));
+ char ecu[] = "ECU1";
+ DltLogStorage storage_handle;
+
+ EXPECT_EQ(0, dlt_daemon_init(&daemon,
+ DLT_DAEMON_RINGBUFFER_MIN_SIZE,
+ DLT_DAEMON_RINGBUFFER_MAX_SIZE,
+ DLT_DAEMON_RINGBUFFER_STEP_SIZE,
+ DLT_RUNTIME_DEFAULT_DIRECTORY,
+ DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0));
+ dlt_set_id(daemon.ecuid, ecu);
+ EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0));
+ daemon.storage_handle = &storage_handle;
+ char apid[] = "1234";
+ char ctid[] = "5678";
+ char ecuid[] = "12";
+ DltDaemonFlags uconfig;
+ uconfig.offlineLogstorageTimestamp = 1;
+ uconfig.offlineLogstorageDelimiter = '/';
+ uconfig.offlineLogstorageMaxCounter = 5;
+ uconfig.offlineLogstorageMaxCounterIdx = 1;
+ uconfig.offlineLogstorageMaxDevices = 1;
+ unsigned char data1[] = "123";
+ unsigned char data2[] = "123";
+ unsigned char data3[] = "123";
+ int size = 10 * sizeof(uint32_t);;
+ daemon.storage_handle->connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED;
+ daemon.storage_handle->config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE;
+ DltLogStorageFilterConfig value;
+ value.apids = apid;
+ value.ctids = ctid;
+ value.ecuid = ecuid;
+ char key0[] = "1234:\000\000\000\000";
+ char key1[] = ":5678\000\000\000\000";
+ char key2[] = "1234:5678";
+ DltLogStorageFilterConfig configs;
+ daemon.storage_handle->configs = &configs;
+ daemon.storage_handle->configs->apids = apid;
+ daemon.storage_handle->configs->ctids = ctid;
+ daemon.storage_handle->configs->ecuid = ecuid;
+ daemon.storage_handle->configs->log_level = 5;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5, &(daemon.storage_handle->config_htab)));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key0, &value, &(daemon.storage_handle->config_htab)));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key1, &value, &(daemon.storage_handle->config_htab)));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key2, &value, &(daemon.storage_handle->config_htab)));
+ EXPECT_NO_THROW(dlt_daemon_logstorage_write(&daemon, &uconfig, data1, size, data2, size, data3, size));
+}
+
+TEST(t_dlt_daemon_logstorage_write, null)
+{
+ EXPECT_NO_THROW(dlt_daemon_logstorage_write(NULL, NULL, NULL, 0, NULL, 0,NULL, 0));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_daemon_logstorage_setup_internal_storage*/
+TEST(t_dlt_daemon_logstorage_setup_internal_storage, normal)
+{
+ DltDaemon daemon;
+ DltGateway gateway;
+ memset(&daemon, 0, sizeof(DltDaemon));
+ memset(&gateway, 0, sizeof(DltGateway));
+ char ecu[] = "ECU1";
+ char path[] = "/tmp";
+ EXPECT_EQ(0, dlt_daemon_init(&daemon,
+ DLT_DAEMON_RINGBUFFER_MIN_SIZE,
+ DLT_DAEMON_RINGBUFFER_MAX_SIZE,
+ DLT_DAEMON_RINGBUFFER_STEP_SIZE,
+ DLT_RUNTIME_DEFAULT_DIRECTORY,
+ DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0));
+ dlt_set_id(daemon.ecuid, ecu);
+ EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0));
+ DltLogStorage storage_handle;
+ daemon.storage_handle = &storage_handle;
+ daemon.storage_handle->config_status = 0;
+ daemon.storage_handle->connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED;
+ EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_logstorage_setup_internal_storage(&daemon, path, 1, 0));
+}
+
+TEST(t_dlt_daemon_logstorage_setup_internal_storage, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_daemon_logstorage_setup_internal_storage(NULL, NULL, 0, 0));
+}
+
+/* Begin Method: dlt_logstorage::dlt_daemon_logstorage_set_logstorage_cache_size*/
+TEST(t_dlt_daemon_logstorage_set_logstorage_cache_size, normal)
+{
+ EXPECT_NO_THROW(dlt_daemon_logstorage_set_logstorage_cache_size(1));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_daemon_logstorage_cleanup*/
+TEST(t_dlt_daemon_logstorage_cleanup, normal)
+{
+ DltDaemon daemon;
+ DltDaemonLocal daemon_local;
+ daemon_local.flags.offlineLogstorageMaxDevices = 1;
+ DltLogStorage storage_handle;
+ daemon.storage_handle = &storage_handle;
+ daemon.storage_handle->config_status = 0;
+ EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_logstorage_cleanup(&daemon, &daemon_local, 0));
+}
+
+TEST(t_dlt_daemon_logstorage_cleanup, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_daemon_logstorage_cleanup(NULL, NULL, 0));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_daemon_logstorage_sync_cache*/
+TEST(t_dlt_daemon_logstorage_sync_cache, normal)
+{
+ DltDaemon daemon;
+ DltDaemonLocal daemon_local;
+ daemon_local.flags.offlineLogstorageMaxDevices = 1;
+ DltLogStorage storage_handle;
+ daemon.storage_handle = &storage_handle;
+ daemon.storage_handle->config_status = 0;
+ char path[] = "/tmp";
+ char apid[] = "1234";
+ char ctid[] = "5678";
+ char ecuid[] = "12";
+ daemon.storage_handle->num_configs = 1;
+ DltLogStorageFilterConfig configs;
+ daemon.storage_handle->configs = &configs;
+ configs.apids = apid;
+ configs.ctids = ctid;
+ configs.ecuid = ecuid;
+ dlt_logstorage_filter_set_strategy(daemon.storage_handle->configs, DLT_LOGSTORAGE_SYNC_ON_MSG);
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_logstorage_sync_cache(&daemon, &daemon_local, path, 0));
+}
+
+TEST(t_dlt_daemon_logstorage_sync_cache, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_daemon_logstorage_sync_cache(NULL, NULL, NULL, 0));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_daemon_logstorage_get_device*/
+TEST(t_dlt_daemon_logstorage_get_device, normal)
+{
+ DltDaemon daemon;
+ DltDaemonLocal daemon_local;
+ daemon_local.flags.offlineLogstorageMaxDevices = 1;
+ DltLogStorage storage_handle;
+ daemon.storage_handle = &storage_handle;
+ daemon.storage_handle->config_status = 0;
+ char path[] = "/tmp";
+ strncpy(daemon.storage_handle->device_mount_point, "/tmp", 5);
+
+ EXPECT_NE((DltLogStorage *)NULL, dlt_daemon_logstorage_get_device(&daemon, &daemon_local, path, 0));
+}
+
+TEST(t_dlt_daemon_logstorage_get_device, null)
+{
+ EXPECT_EQ((DltLogStorage *)NULL, dlt_daemon_logstorage_get_device(NULL, NULL, NULL, 0));
+}
+
+/* Begin Method: dlt_logstorage::t_dlt_logstorage_sync_msg_cache*/
+TEST(t_dlt_logstorage_sync_msg_cache, normal)
+{
+ DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
+ config.sync = 1;
+ config.log = fopen("/tmp/test.log", "a+");
+ if(config.log != NULL)
+ {
+ config.cache = calloc(1, 1 + sizeof(DltLogStorageCacheFooter));
+ if(config.cache != NULL)
+ {
+ config.file_size = 1;
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_sync_msg_cache(&config, 1));
+ free(config.cache);
+ config.cache = NULL;
+ }
+ }
+}
+
+TEST(t_dlt_logstorage_sync_msg_cache, null)
+{
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_sync_msg_cache(NULL, 0));
+}
+
+int main(int argc, char **argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ ::testing::FLAGS_gtest_break_on_failure = true;
+ return RUN_ALL_TESTS();
+}