From b7124c33826a53a1a66d3c6b7230ebd33735ab4a Mon Sep 17 00:00:00 2001 From: Vo Trung Chi Date: Wed, 20 Mar 2019 14:15:54 +0700 Subject: dlt_offline_logstorage: fix multiple file creation error (#85, #94) Rootcause: The dlt-daemon rotates files for each key, but not for each [FILTER] because dlt-daemon creates the DltLogStorageFilterConfig for each key (CTXT: or APPID: or APPID:CTXTID) then added to the DltLogStorageFilterList. And each DltLogStorageFilterConfig has it's own records (The list of files that was recorded in the offline logstorage directory), that's why one [FILTER] might be has multiple records and then its lead to the problem. Solution: Instead of creating the DltLogStorageFilterConfig for each key, dlt-daemon will create the DltLogStorageFilterConfig for each [FILTER] and DltLogStorageFilterConfig has an information of all the keys in this [FILTER]. Signed-off-by: Vo Trung Chi --- src/daemon/dlt_daemon_offline_logstorage.c | 110 +++++----- src/offlinelogstorage/dlt_offline_logstorage.c | 228 +++++++++++++-------- src/offlinelogstorage/dlt_offline_logstorage.h | 10 +- .../dlt_offline_logstorage_internal.h | 6 +- tests/gtest_dlt_daemon_offline_log.cpp | 82 ++++---- 5 files changed, 261 insertions(+), 175 deletions(-) diff --git a/src/daemon/dlt_daemon_offline_logstorage.c b/src/daemon/dlt_daemon_offline_logstorage.c index 8ec7016..8f78065 100644 --- a/src/daemon/dlt_daemon_offline_logstorage.c +++ b/src/daemon/dlt_daemon_offline_logstorage.c @@ -482,7 +482,7 @@ DLT_STATIC DltReturnValue dlt_daemon_logstorage_force_reset_level(DltDaemon *dae int ll = DLT_LOG_DEFAULT; int num = 0; int i = 0; - DltLogStorageFilterConfig *config[DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS] = { 0 }; + DltLogStorageFilterConfig *config[DLT_CONFIG_FILE_SECTIONS_MAX] = { 0 }; if ((daemon == NULL) || (daemon_local == NULL) || (ecuid == NULL) || (apid == NULL) || (ctxid == NULL) || (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT)) { @@ -768,6 +768,7 @@ void dlt_daemon_logstorage_reset_application_loglevel(DltDaemon *daemon, char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { '\0' }; int num_device_configured = 0; unsigned int status; + int log_level = 0; PRINT_FUNCTION_VERBOSE(verbose); @@ -796,31 +797,37 @@ void dlt_daemon_logstorage_reset_application_loglevel(DltDaemon *daemon, /* for all filters (keys) check if application context are already running * and log level need to be reset*/ tmp = &(handle->config_list); + while (*(tmp) != NULL) + { + for (i = 0; i < (*tmp)->num_keys; i++) + { + memset(key, 0, sizeof(key)); + + strncpy(key, ((*tmp)->key_list + + (i * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)), + DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); + + if (num_device_configured == 1) + { + /* Reset context log level and send to application */ + log_level = DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL; + } + else + { + /** + * Reset context log level do not send to application as other + * devices can have same configuration + * */ + log_level = DLT_DAEMON_LOGSTORAGE_RESET_LOGLEVEL; + } - while (*(tmp) != NULL) { - memset(key, 0, sizeof(key)); - - strncpy(key, - (*tmp)->key, - DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); - - if (num_device_configured == 1) - /* Reset context log level and send to application */ dlt_logstorage_update_context_loglevel( - daemon, - daemon_local, - key, - DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL, - verbose); - else /* Reset context log level do not send to application as other - * devices can have same configuration */ - dlt_logstorage_update_context_loglevel( - daemon, - daemon_local, - key, - DLT_DAEMON_LOGSTORAGE_RESET_LOGLEVEL, - verbose); - + daemon, + daemon_local, + key, + log_level, + verbose); + } tmp = &(*tmp)->next; } @@ -862,10 +869,13 @@ void dlt_daemon_logstorage_update_application_loglevel(DltDaemon *daemon, DltLogStorage *handle = NULL; DltLogStorageFilterList **tmp = NULL; char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { '\0' }; + int i = 0; + int log_level = 0; PRINT_FUNCTION_VERBOSE(verbose); - if ((daemon == NULL) || (dev_num < 0)) { + if ((daemon == NULL) || (daemon_local == NULL) || (dev_num < 0)) + { dlt_vlog(LOG_ERR, "Invalid function parameters used for %s\n", __func__); @@ -881,30 +891,31 @@ void dlt_daemon_logstorage_update_application_loglevel(DltDaemon *daemon, /* for all filters (keys) check if application or context already running * and log level need to be updated*/ tmp = &(handle->config_list); + while (*(tmp) != NULL) + { + for (i = 0; i < (*tmp)->num_keys; i++) + { + memset(key, 0, sizeof(key)); + + strncpy(key, ((*tmp)->key_list + + (i * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)), + DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); + + /* Obtain storage configuration data */ + log_level = dlt_logstorage_get_loglevel_by_key(handle, key); + if (log_level < 0) + { + dlt_log(LOG_ERR, "Failed to get log level by key \n"); + return; + } - while (*(tmp) != NULL) { - int log_level = -1; - - memset(key, 0, sizeof(key)); - - strncpy(key, - (*tmp)->key, - DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); - - /* Obtain storage configuration data */ - log_level = dlt_logstorage_get_loglevel_by_key(handle, key); - - if (log_level < 0) { - dlt_log(LOG_ERR, "Failed to get log level by key \n"); - return; + /* Update context log level with storage configuration log level */ + dlt_logstorage_update_context_loglevel(daemon, + daemon_local, + key, + log_level, + verbose); } - - /* Update context log level with storage configuration log level */ - dlt_logstorage_update_context_loglevel(daemon, - daemon_local, - key, - log_level, - verbose); tmp = &(*tmp)->next; } @@ -928,7 +939,7 @@ int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon, char *apid, char *ctid) { - DltLogStorageFilterConfig *config[DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS] = { 0 }; + DltLogStorageFilterConfig *config[DLT_CONFIG_FILE_SECTIONS_MAX] = { 0 }; int i = 0; int j = 0; int8_t storage_loglevel = -1; @@ -952,7 +963,8 @@ int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon, continue; } - for (j = 0; j < DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS; j++) { + for (j = 0; j < num_config; j++) + { if (config[j] == NULL) continue; diff --git a/src/offlinelogstorage/dlt_offline_logstorage.c b/src/offlinelogstorage/dlt_offline_logstorage.c index 8571b7a..483bf8a 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage.c +++ b/src/offlinelogstorage/dlt_offline_logstorage.c @@ -79,6 +79,15 @@ DLT_STATIC void dlt_logstorage_filter_config_free(DltLogStorageFilterConfig *dat } } +/** + * dlt_logstorage_list_destroy + * + * Destroy Filter configurations list. + * + * @param list List of the filter configurations will be destroyed. + * @param reason Reason for the destroying of Filter configurations list + * @return 0 on success, -1 on error + */ DLT_STATIC int dlt_logstorage_list_destroy(DltLogStorageFilterList **list, int reason) { @@ -89,10 +98,10 @@ DLT_STATIC int dlt_logstorage_list_destroy(DltLogStorageFilterList **list, while (*(list) != NULL) { tmp = *list; *list = (*list)->next; - - if (tmp->key != NULL) { - free(tmp->key); - tmp->key = NULL; + if (tmp->key_list != NULL) + { + free(tmp->key_list); + tmp->key_list = NULL; } if (tmp->data != NULL) { @@ -148,21 +157,25 @@ DLT_STATIC int dlt_logstorage_list_add_config(DltLogStorageFilterConfig *data, return 0; } -DLT_STATIC int dlt_logstorage_list_add(char *key, +/** + * dlt_logstorage_list_add + * + * Add Filter configurations to the list. + * + * @param keys Keys will be added to the list. + * @param num_keys Number of keys + * @param data Filter configurations data will be added to the list. + * @param list List of the filter configurations + * @return 0 on success, -1 on error + */ +DLT_STATIC int dlt_logstorage_list_add(char *keys, + int num_keys, DltLogStorageFilterConfig *data, DltLogStorageFilterList **list) { DltLogStorageFilterList *tmp = NULL; while (*(list) != NULL) { - /* if the key is already present then the data should be updated */ - if (strncmp((*list)->key, key, DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN) == 0) { - if (dlt_logstorage_list_add_config(data, &((*list)->data)) != 0) - return -1; - - return 0; - } - list = &(*list)->next; } @@ -171,24 +184,34 @@ DLT_STATIC int dlt_logstorage_list_add(char *key, if (tmp == NULL) return -1; - tmp->key = strdup(key); + tmp->key_list = (char *)calloc( + (num_keys * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN), sizeof(char)); + if (tmp->key_list == NULL) + { + free(tmp); + tmp = NULL; + return -1; + } + + memcpy(tmp->key_list, keys, num_keys * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); + tmp->num_keys = num_keys; tmp->next = NULL; tmp->data = calloc(1, sizeof(DltLogStorageFilterConfig)); if (tmp->data == NULL) { - free(tmp->key); + free(tmp->key_list); + tmp->key_list = NULL; free(tmp); - tmp->key = NULL; tmp = NULL; return -1; } if (dlt_logstorage_list_add_config(data, &(tmp->data)) != 0) { - free(tmp->key); + free(tmp->key_list); + tmp->key_list = NULL; free(tmp->data); - free(tmp); - tmp->key = NULL; tmp->data = NULL; + free(tmp); tmp = NULL; return -1; } @@ -198,17 +221,39 @@ DLT_STATIC int dlt_logstorage_list_add(char *key, return 0; } -DLT_STATIC void *dlt_logstorage_list_find(char *key, - DltLogStorageFilterList **list) +/** + * dlt_logstorage_list_find + * + * Find all Filter configurations corresponding with key provided. + * + * @param key Key to find the filter configurations + * @param list List of the filter configurations + * @param config Filter configurations corresponding with the key. + * @return Number of the filter configuration found. + */ +DLT_STATIC int dlt_logstorage_list_find(char *key, + DltLogStorageFilterList **list, + DltLogStorageFilterConfig **config) { + int i = 0; + int num = 0; + while (*(list) != NULL) { - if (strncmp((*list)->key, key, DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN) == 0) - return (*list)->data; - else - list = &(*list)->next; + for (i = 0; i < (*list)->num_keys; i++) + { + if (strncmp(((*list)->key_list + + (i * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)), + key, DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN) == 0) + { + config[num] = (*list)->data; + num++; + break; + } + } + list = &(*list)->next; } - return NULL; + return num; } /* Configuration file parsing helper functions */ @@ -676,7 +721,6 @@ DLT_STATIC int dlt_logstorage_prepare_table(DltLogStorage *handle, int ret = 0; int num_keys = 0; char *keys = NULL; - int idx = 0; if ((handle == NULL) || (data == NULL)) { dlt_vlog(LOG_ERR, "Invalid parameters in %s\n", __func__); @@ -695,24 +739,20 @@ DLT_STATIC int dlt_logstorage_prepare_table(DltLogStorage *handle, } /* hash_add */ - for (idx = 0; idx < num_keys; idx++) { - if (dlt_logstorage_list_add(keys + (idx * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN), - data, - &(handle->config_list)) != 0) { - dlt_log(LOG_ERR, - "Adding to hash table failed, returning failure\n"); - - dlt_logstorage_free(handle, DLT_LOGSTORAGE_SYNC_ON_ERROR); - - free(keys); - return -1; - } - - /* update filter keys and number of keys */ - handle->num_filter_keys += 1; + if (dlt_logstorage_list_add(keys, + num_keys, + data, + &(handle->config_list)) != 0) + { + dlt_log(LOG_ERR, "Adding to hash table failed, returning failure\n"); + dlt_logstorage_free(handle, DLT_LOGSTORAGE_SYNC_ON_ERROR); + free(keys); + keys = NULL; + return -1; } free(keys); + keys = NULL; return 0; } @@ -1329,8 +1369,7 @@ DLT_STATIC int dlt_logstorage_setup_table(DltLogStorage *handle, ret = dlt_logstorage_prepare_table(handle, tmp_data); if (ret != 0) { - dlt_vlog(LOG_ERR, "%s Error: Storing filter values failed\n", - __func__); + dlt_vlog(LOG_ERR, "%s Error: Storing filter values failed\n", __func__); ret = DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR; } @@ -1405,17 +1444,16 @@ DLT_STATIC int dlt_daemon_offline_setup_filter_properties(DltLogStorage *handle, ret = dlt_logstorage_setup_table(handle, &tmp_data); if (ret != 0) { - dlt_vlog(LOG_ERR, "%s Error: Storing filter values failed\n", - __func__); + dlt_vlog(LOG_ERR, "%s Error: Storing filter values failed\n", __func__); ret = DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR; } else { /* move to next free filter configuration, if no error occurred */ handle->num_configs += 1; - - /* free tmp_data */ - dlt_logstorage_filter_config_free(&tmp_data); } + /* free tmp_data */ + dlt_logstorage_filter_config_free(&tmp_data); + return ret; } @@ -1588,7 +1626,7 @@ int dlt_logstorage_device_connected(DltLogStorage *handle, char *mount_point) handle->connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; handle->config_status = 0; handle->write_errors = 0; - handle->num_filter_keys = 0; + handle->num_configs = 0; /* Setup logstorage with config file settings */ return dlt_logstorage_load_config(handle); @@ -1618,7 +1656,6 @@ int dlt_logstorage_device_disconnected(DltLogStorage *handle, int reason) handle->connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED; handle->config_status = 0; handle->write_errors = 0; - handle->num_filter_keys = 0; handle->num_configs = 0; return 0; @@ -1637,7 +1674,10 @@ int dlt_logstorage_device_disconnected(DltLogStorage *handle, int reason) */ int dlt_logstorage_get_loglevel_by_key(DltLogStorage *handle, char *key) { - DltLogStorageFilterConfig *config = NULL; + DltLogStorageFilterConfig *config[DLT_CONFIG_FILE_SECTIONS_MAX] = { 0 }; + int num_configs = 0; + int i = 0; + int log_level = 0; /* Check if handle is NULL,already initialized or already configured */ if ((handle == NULL) || @@ -1646,30 +1686,51 @@ int dlt_logstorage_get_loglevel_by_key(DltLogStorage *handle, char *key) (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)) return -1; - config = (DltLogStorageFilterConfig *) - dlt_logstorage_list_find(key, &(handle->config_list)); + num_configs = dlt_logstorage_list_find(key, &(handle->config_list), config); - if (config == NULL) { + if (num_configs == 0) + { dlt_vlog(LOG_WARNING, "Configuration for key [%s] not found!\n", key); return -1; } + else if (num_configs == 1) + { + if (config[0] != NULL) + { + log_level = config[0]->log_level; + } + } + else + { + /** + * Multiple configurations found, raise a warning to the user and go + * for the more verbose one. + */ + dlt_vlog(LOG_WARNING, "Multiple configuration for key [%s] found," + " return the highest log level!\n", key); + + for (i = 0; i < num_configs; i++) + { + if ((config[i] != NULL) && (config[i]->log_level > log_level)) + { + log_level = config[i]->log_level; + } + } + } - return config->log_level; + return log_level; } /** * dlt_logstorage_get_config * * Obtain the configuration data of all filters for provided apid and ctid - * For a given apid and ctid, there can be 3 possiblities of configuration - * data available in the Hash map, this function will return the address - * of configuration data for all these 3 combinations * * @param handle DltLogStorage handle - * @param config Pointer to array of filter configurations + * @param config [out] Pointer to array of filter configurations * @param apid application id * @param ctid context id - * @return number of found configurations + * @return number of configurations found */ int dlt_logstorage_get_config(DltLogStorage *handle, DltLogStorageFilterConfig **config, @@ -1677,13 +1738,14 @@ int dlt_logstorage_get_config(DltLogStorage *handle, char *ctid, char *ecuid) { - DltLogStorageFilterConfig *ptr_config = NULL; - char key[DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS][DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN] = + DltLogStorageFilterConfig **cur_config_ptr = NULL; + char key[DLT_CONFIG_FILE_SECTIONS_MAX][DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN] = { { '\0' }, { '\0' }, { '\0' } }; int i = 0; int apid_len = 0; int ctid_len = 0; int ecuid_len = 0; + int num_configs = 0; int num = 0; /* Check if handle is NULL,already initialized or already configured */ @@ -1714,15 +1776,9 @@ int dlt_logstorage_get_config(DltLogStorage *handle, strncat(key[0], ":", 1); strncat(key[0], ":", 1); - ptr_config = (DltLogStorageFilterConfig *)dlt_logstorage_list_find( - key[0], &(handle->config_list)); - - if (ptr_config != NULL) { - config[num] = ptr_config; - num += 1; - } - - return num; + num_configs = dlt_logstorage_list_find(key[0], &(handle->config_list), + config); + return num_configs; } apid_len = strlen(apid); @@ -1776,17 +1832,20 @@ int dlt_logstorage_get_config(DltLogStorage *handle, strncat(key[6], ":", 1); /* Search the list three times with keys as -apid: , :ctid and apid:ctid */ - for (i = 0; i < DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS; i++) { - ptr_config = (DltLogStorageFilterConfig *) - dlt_logstorage_list_find(key[i], &(handle->config_list)); - - if (ptr_config != NULL) { - config[num] = ptr_config; - num += 1; + for (i = 0; i < DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_KEYS; i++) + { + cur_config_ptr = &config[num_configs]; + num = dlt_logstorage_list_find(key[i], &(handle->config_list), + cur_config_ptr); + num_configs += num; + /* If all filter configurations matched, stop and return */ + if (num_configs == handle->num_configs) + { + break; } } - return num; + return num_configs; } /** @@ -1827,7 +1886,8 @@ DLT_STATIC int dlt_logstorage_filter(DltLogStorage *handle, return 0; } - for (i = 0; i < DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS; i++) { + for (i = 0 ; i < num ; i++) + { if (config[i] == NULL) continue; @@ -1870,7 +1930,8 @@ int dlt_logstorage_write(DltLogStorage *handle, unsigned char *data3, int size3) { - DltLogStorageFilterConfig *config[DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS] = { 0 }; + DltLogStorageFilterConfig *config[DLT_CONFIG_FILE_SECTIONS_MAX] = { 0 }; + int i = 0; int ret = 0; int num = 0; @@ -1953,7 +2014,8 @@ int dlt_logstorage_write(DltLogStorage *handle, } /* store log message in every found filter */ - for (i = 0; i < DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS; i++) { + for (i = 0; i < num; i++) + { if (config[i] == NULL) continue; diff --git a/src/offlinelogstorage/dlt_offline_logstorage.h b/src/offlinelogstorage/dlt_offline_logstorage.h index c2160b5..e28e535 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage.h +++ b/src/offlinelogstorage/dlt_offline_logstorage.h @@ -60,7 +60,7 @@ #include "dlt_config_file_parser.h" #define DLT_OFFLINE_LOGSTORAGE_MAXIDS 100 /* Maximum entries for each apids and ctids */ -#define DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS 7 /* max number of possible filters when searching for */ +#define DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_KEYS 7 /* Max number of possible keys when searching for */ #define DLT_OFFLINE_LOGSTORAGE_INIT_DONE 1 /* For device configuration status */ #define DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED 1 @@ -191,7 +191,8 @@ typedef struct DltLogStorageFilterList DltLogStorageFilterList; struct DltLogStorageFilterList { - char *key; /* Key to find data */ + char *key_list; /* List of key */ + int num_keys; /* Number of keys */ DltLogStorageFilterConfig *data; /* Filter data */ DltLogStorageFilterList *next; /* Pointer to next */ }; @@ -199,9 +200,8 @@ struct DltLogStorageFilterList typedef struct { DltLogStorageFilterList *config_list; /* List of all filters */ - DltLogStorageUserConfig uconfig; /* User configurations for file name*/ - int num_configs; /* Number of configs */ - int num_filter_keys; /* Number of keys */ + DltLogStorageUserConfig uconfig; /* User configurations for file name*/ + int num_configs; /* Number of configs */ char device_mount_point[DLT_MOUNT_PATH_MAX + 1]; /* Device mount path */ unsigned int connection_type; /* Type of connection */ unsigned int config_status; /* Status of configuration */ diff --git a/src/offlinelogstorage/dlt_offline_logstorage_internal.h b/src/offlinelogstorage/dlt_offline_logstorage_internal.h index 11da0dd..9d1eaf7 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage_internal.h +++ b/src/offlinelogstorage/dlt_offline_logstorage_internal.h @@ -56,11 +56,13 @@ DLT_STATIC int dlt_logstorage_list_destroy(DltLogStorageFilterList **list, DLT_STATIC int dlt_logstorage_list_add_config(DltLogStorageFilterConfig *data, DltLogStorageFilterConfig **listdata); DLT_STATIC int dlt_logstorage_list_add(char *key, + int num_keys, DltLogStorageFilterConfig *data, DltLogStorageFilterList **list); -DLT_STATIC void *dlt_logstorage_list_find(char *key, - DltLogStorageFilterList **list); +DLT_STATIC int dlt_logstorage_list_find(char *key, + DltLogStorageFilterList **list, + DltLogStorageFilterConfig **config); DLT_STATIC int dlt_logstorage_count_ids(const char *str); diff --git a/tests/gtest_dlt_daemon_offline_log.cpp b/tests/gtest_dlt_daemon_offline_log.cpp index 549ac5c..21156fa 100644 --- a/tests/gtest_dlt_daemon_offline_log.cpp +++ b/tests/gtest_dlt_daemon_offline_log.cpp @@ -38,13 +38,14 @@ TEST(t_dlt_logstorage_list_add, normal) DltLogStorageFilterList *list = NULL; DltLogStorageFilterConfig *data = NULL; char key = 1; + int num_keys = 1; data = (DltLogStorageFilterConfig *)calloc(1, sizeof(DltLogStorageFilterConfig)); if (data != NULL) { dlt_logstorage_filter_set_strategy(data, DLT_LOGSTORAGE_SYNC_ON_MSG); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(&key, data, &list)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(&key, num_keys, data, &list)); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_destroy(&list, 0)); } } @@ -71,13 +72,14 @@ TEST(t_dlt_logstorage_list_destroy, normal) DltLogStorageFilterList *list = NULL; DltLogStorageFilterConfig *data = NULL; char key = 1; + int num_keys = 1; data = (DltLogStorageFilterConfig *)calloc(1, sizeof(DltLogStorageFilterConfig)); if (data != NULL) { dlt_logstorage_filter_set_strategy(data, DLT_LOGSTORAGE_SYNC_ON_MSG); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(&key, data, &list)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(&key, num_keys, data, &list)); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_destroy(&list, 0)); } } @@ -87,10 +89,12 @@ TEST(t_dlt_logstorage_list_find, normal) { DltLogStorageFilterList *list = NULL; DltLogStorageFilterConfig *data = NULL; - DltLogStorageFilterConfig *retData; - char key[] = "1"; + int num_configs = 0; + char key[] = ":1234:5678"; char apid[] = "1234"; char ctid[] = "5678"; + int num_keys = 1; + DltLogStorageFilterConfig *config[DLT_CONFIG_FILE_SECTIONS_MAX] = { 0 }; data = (DltLogStorageFilterConfig *)calloc(1, sizeof(DltLogStorageFilterConfig)); @@ -99,15 +103,15 @@ TEST(t_dlt_logstorage_list_find, normal) data->ctids = strdup(ctid); dlt_logstorage_filter_set_strategy(data, DLT_LOGSTORAGE_SYNC_ON_MSG); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, data, &list)); + ASSERT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, num_keys, data, &list)); - retData = (DltLogStorageFilterConfig *)dlt_logstorage_list_find(key, &list); - EXPECT_NE((DltLogStorageFilterConfig *)NULL, retData); + num_configs = dlt_logstorage_list_find(key, &list, config); - if (retData != NULL) { - EXPECT_STREQ(apid, retData->apids); - EXPECT_STREQ(ctid, retData->ctids); - } + ASSERT_EQ(1, num_configs); + ASSERT_NE((DltLogStorageFilterConfig *)NULL, config[0]); + + EXPECT_STREQ(apid, config[0]->apids); + EXPECT_STREQ(ctid, config[0]->ctids); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_destroy(&list, 0)); } @@ -122,13 +126,14 @@ TEST(t_dlt_logstorage_free, normal) int reason = 0; handle.num_configs = 0; handle.config_list = NULL; + int num_keys = 1; data = (DltLogStorageFilterConfig *)calloc(1, sizeof(DltLogStorageFilterConfig)); if (data != NULL) { dlt_logstorage_filter_set_strategy(data, DLT_LOGSTORAGE_SYNC_ON_MSG); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(&key, data, &handle.config_list)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(&key, num_keys, data, &handle.config_list)); dlt_logstorage_free(&handle, reason); } @@ -190,7 +195,6 @@ TEST(t_dlt_logstorage_prepare_table, normal) char ctids[] = "5678"; data.apids = apids; data.ctids = ctids; - handle.num_filter_keys = 1; data.records = NULL; data.log = NULL; data.cache = NULL; @@ -438,7 +442,6 @@ TEST(t_dlt_logstorage_store_filters, normal) handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; handle.config_status = 0; handle.write_errors = 0; - handle.num_filter_keys = 0; handle.config_list = NULL; @@ -458,7 +461,6 @@ TEST(t_dlt_logstorage_load_config, normal) handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; handle.config_status = 0; handle.write_errors = 0; - handle.num_filter_keys = 0; handle.config_list = NULL; strncpy(handle.device_mount_point, "/tmp", DLT_MOUNT_PATH_MAX); @@ -478,7 +480,6 @@ TEST(t_dlt_logstorage_device_connected, normal) handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED; handle.config_status = 0; handle.write_errors = 0; - handle.num_filter_keys = 0; handle.config_list = NULL; strncpy(handle.device_mount_point, "/tmp", DLT_MOUNT_PATH_MAX); @@ -515,13 +516,14 @@ TEST(t_dlt_logstorage_get_loglevel_by_key, normal) handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; handle.config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE; handle.config_list = NULL; + int num_keys = 1; config = (DltLogStorageFilterConfig *)calloc(1, sizeof(DltLogStorageFilterConfig)); if (config != NULL) { config->log_level = DLT_LOG_ERROR; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, config, &(handle.config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, num_keys, config, &(handle.config_list))); EXPECT_GE(DLT_LOG_ERROR, dlt_logstorage_get_loglevel_by_key(&handle, key)); free(config); @@ -555,10 +557,11 @@ TEST(t_dlt_logstorage_get_config, normal) handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; handle.config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE; handle.config_list = NULL; + int num_keys = 1; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key0, &value, &(handle.config_list))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key1, &value, &(handle.config_list))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key2, &value, &(handle.config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key0, num_keys, &value, &(handle.config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key1, num_keys, &value, &(handle.config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key2, num_keys, &value, &(handle.config_list))); num_config = dlt_logstorage_get_config(&handle, config, apid, ctid, ecuid); @@ -590,15 +593,16 @@ TEST(t_dlt_logstorage_filter, normal) char key0[] = ":1234:\000\000\000\000"; char key1[] = "::5678\000\000\000\000"; char key2[] = ":1234:5678"; - DltLogStorageFilterConfig *config[DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS] = { 0 }; + DltLogStorageFilterConfig *config[DLT_CONFIG_FILE_SECTIONS_MAX] = { 0 }; DltLogStorage handle; handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; handle.config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE; handle.config_list = NULL; + int num_keys = 1; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key0, &value, &(handle.config_list))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key1, &value, &(handle.config_list))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key2, &value, &(handle.config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key0, num_keys, &value, &(handle.config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key1, num_keys, &value, &(handle.config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key2, num_keys, &value, &(handle.config_list))); num = dlt_logstorage_filter(&handle, config, apid, ctid, ecuid, 0); @@ -638,10 +642,11 @@ TEST(t_dlt_logstorage_write, normal) char key0[] = ":1234:\000\000\000\000"; char key1[] = "::5678\000\000\000\000"; char key2[] = ":1234:5678"; + int num_keys = 1; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key0, &value, &(handle.config_list))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key1, &value, &(handle.config_list))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key2, &value, &(handle.config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key0, num_keys, &value, &(handle.config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key1, num_keys, &value, &(handle.config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key2, num_keys, &value, &(handle.config_list))); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write(&handle, &uconfig, data1, size1, data2, size2, data3, size3)); } @@ -666,9 +671,11 @@ TEST(t_dlt_logstorage_sync_caches, normal) configs.ctids = ctid; configs.ecuid = ecuid; configs.file_name = filename; + int num_keys = 1; + dlt_logstorage_filter_set_strategy(&configs, DLT_LOGSTORAGE_SYNC_ON_MSG); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, &configs, &(handle.config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, num_keys, &configs, &(handle.config_list))); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_sync_caches(&handle)); } @@ -1215,11 +1222,12 @@ TEST(t_dlt_daemon_logstorage_get_loglevel, normal) 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->config_list = NULL; + daemon.storage_handle->num_configs = 1; + int num_keys = 1; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, &value, &(daemon.storage_handle->config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, num_keys, &value, &(daemon.storage_handle->config_list))); EXPECT_NO_THROW(dlt_daemon_logstorage_update_application_loglevel(&daemon, &daemon_local, device_index, 0)); EXPECT_EQ(4, dlt_daemon_logstorage_get_loglevel(&daemon, 1, apid, ctid)); @@ -1267,11 +1275,11 @@ TEST(t_dlt_daemon_logstorage_update_application_loglevel, normal) 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->config_list = NULL; + int num_keys = 1; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, &value, &(daemon.storage_handle->config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, num_keys, &value, &(daemon.storage_handle->config_list))); EXPECT_NO_THROW(dlt_daemon_logstorage_update_application_loglevel(&daemon, &daemon_local, device_index, 0)); } @@ -1324,10 +1332,11 @@ TEST(t_dlt_daemon_logstorage_write, normal) char key0[] = "1234:\000\000\000\000"; char key1[] = ":5678\000\000\000\000"; char key2[] = "1234:5678"; + int num_keys = 1; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key0, &value, &(daemon.storage_handle->config_list))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key1, &value, &(daemon.storage_handle->config_list))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key2, &value, &(daemon.storage_handle->config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key0, num_keys, &value, &(daemon.storage_handle->config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key1, num_keys, &value, &(daemon.storage_handle->config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key2, num_keys, &value, &(daemon.storage_handle->config_list))); EXPECT_NO_THROW(dlt_daemon_logstorage_write(&daemon, &uconfig, data1, size, data2, size, data3, size)); } @@ -1420,8 +1429,9 @@ TEST(t_dlt_daemon_logstorage_sync_cache, normal) configs.ecuid = ecuid; configs.file_name = file_name; dlt_logstorage_filter_set_strategy(&configs, DLT_LOGSTORAGE_SYNC_ON_MSG); + int num_keys = 1; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, &configs, &(daemon.storage_handle->config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, num_keys, &configs, &(daemon.storage_handle->config_list))); EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_logstorage_sync_cache(&daemon, &daemon_local, path, 0)); } -- cgit v1.2.1