diff --git a/doc/dlt_offline_logstorage.md b/doc/dlt_offline_logstorage.md index 5c7a9d4a1..0d77a5001 100644 --- a/doc/dlt_offline_logstorage.md +++ b/doc/dlt_offline_logstorage.md @@ -336,3 +336,56 @@ the clients are able to update any log level to user contexts. By setting ```MaintainLogstorageLogLevel=ON``` or ```MaintainLogstorageLogLevel=1``` or not set, the logstorage will maintain its log level as the highest priority. + +## Logstorage Negative Filter + +The DLT Logstorage also provides negative filter feature, which allows filtering +unwanted Application or Context. + +The following strategies are implemented: +- Exclude a pair of Application and Context + + ``` + [FILTER1] + ... + ExcludedLogAppName=LOG + ExcludedContextName=TEST + ``` +- Exclude single Application or list of Applications + + ``` + [FILTER1] + ... + ExcludedLogAppName=LOG + + [FILTER2] + ... + ExcludedLogAppName=LOG1,LOG2,LOG3 + ``` +- Exclude single Context or list of Contexts + + ``` + [FILTER1] + ... + ExcludedContextName=TEST + + [FILTER2] + ... + ExcludedContextName=TEST1,TEST2,TEST3 + ``` + +Note : + +DLT offline logstorage does not support multiple Application and multiple Context filter. +The following configuration is not supported and the behavior will be undefinded: + ``` + [FILTER1] + ... + LogAppName=LOG1,LOG2,LOG3 + ContextName=TEST1,TEST2,TEST3 + + [FILTER2] + ... + ExcludedLogAppName=LOG1,LOG2,LOG3 + ExcludedContextName=TEST1,TEST2,TEST3 + ``` \ No newline at end of file diff --git a/src/offlinelogstorage/dlt_offline_logstorage.c b/src/offlinelogstorage/dlt_offline_logstorage.c index 3c7900b2a..165ad1c19 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage.c +++ b/src/offlinelogstorage/dlt_offline_logstorage.c @@ -56,6 +56,16 @@ DLT_STATIC void dlt_logstorage_filter_config_free(DltLogStorageFilterConfig *dat data->ctids = NULL; } + if (data->excluded_apids) { + free(data->excluded_apids); + data->excluded_apids = NULL; + } + + if (data->excluded_ctids) { + free(data->excluded_ctids); + data->excluded_ctids = NULL; + } + if (data->file_name) { free(data->file_name); data->file_name = NULL; @@ -162,6 +172,12 @@ DLT_STATIC int dlt_logstorage_list_add_config(DltLogStorageFilterConfig *data, if (data->ctids != NULL) (*listdata)->ctids = strdup(data->ctids); + if (data->excluded_apids != NULL) + (*listdata)->excluded_apids = strdup(data->excluded_apids); + + if (data->excluded_ctids != NULL) + (*listdata)->excluded_ctids = strdup(data->excluded_ctids); + if (data->file_name != NULL) (*listdata)->file_name = strdup(data->file_name); @@ -529,6 +545,45 @@ DLT_STATIC int dlt_logstorage_get_keys_list(char *ids, char *sep, char **list, return 0; } +DLT_STATIC bool dlt_logstorage_check_excluded_ids(char *id, char *delim, char *excluded_ids) +{ + char *token = NULL; + char *tmp_token = NULL; + char *ids_local = NULL; + + if ((id == NULL) || (delim == NULL) || (excluded_ids == NULL)) { + dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__); + return false; + } + + ids_local = strdup(excluded_ids); + + if (ids_local == NULL) { + dlt_vlog(LOG_ERR, "%s: Cannot duplicate string.\n", __func__); + return false; + } + + token = strtok_r(ids_local, delim, &tmp_token); + + if (token == NULL) { + dlt_vlog(LOG_ERR, "%s: %s could not be parsed.\n", __func__, ids_local); + free(ids_local); + return false; + } + + while (token != NULL) { + if(strncmp(id, token, DLT_ID_SIZE) == 0) { + free(ids_local); + return true; + } + + token = strtok_r(NULL, delim, &tmp_token); + } + + free(ids_local); + return false; +} + /** * dlt_logstorage_create_keys_only_ctid * @@ -969,6 +1024,28 @@ DLT_STATIC int dlt_logstorage_check_ctids(DltLogStorageFilterConfig *config, return dlt_logstorage_read_list_of_names(&config->ctids, (const char*)value); } +DLT_STATIC int dlt_logstorage_store_config_excluded_apids(DltLogStorageFilterConfig *config, + char *value) +{ + if ((config == NULL) || (value == NULL)) { + dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__); + return -1; + } + + return dlt_logstorage_read_list_of_names(&config->excluded_apids, value); +} + +DLT_STATIC int dlt_logstorage_store_config_excluded_ctids(DltLogStorageFilterConfig *config, + char *value) +{ + if ((config == NULL) || (value == NULL)) { + dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__); + return -1; + } + + return dlt_logstorage_read_list_of_names(&config->excluded_ctids, (const char*)value); +} + DLT_STATIC int dlt_logstorage_set_loglevel(int *log_level, int value) { @@ -1327,6 +1404,16 @@ DLT_STATIC DltLogstorageFilterConf .func = dlt_logstorage_check_ctids, .is_opt = 1 }, + [DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_LOGAPPNAME] = { + .key = "ExcludedLogAppName", + .func = dlt_logstorage_store_config_excluded_apids, + .is_opt = 1 + }, + [DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_CONTEXTNAME] = { + .key = "ExcludedContextName", + .func = dlt_logstorage_store_config_excluded_ctids, + .is_opt = 1 + }, [DLT_LOGSTORAGE_FILTER_CONF_LOGLEVEL] = { .key = "LogLevel", .func = dlt_logstorage_check_loglevel, @@ -1397,6 +1484,16 @@ DLT_STATIC DltLogstorageFilterConf .func = dlt_logstorage_check_ctids, .is_opt = 0 }, + [DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_LOGAPPNAME] = { + .key = NULL, + .func = dlt_logstorage_store_config_excluded_apids, + .is_opt = 1 + }, + [DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_CONTEXTNAME] = { + .key = NULL, + .func = dlt_logstorage_store_config_excluded_ctids, + .is_opt = 1 + }, [DLT_LOGSTORAGE_FILTER_CONF_LOGLEVEL] = { .key = NULL, .func = dlt_logstorage_check_loglevel, @@ -1466,6 +1563,16 @@ DLT_STATIC DltLogstorageFilterConf .func = dlt_logstorage_check_ctids, .is_opt = 0 }, + [DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_LOGAPPNAME] = { + .key = NULL, + .func = dlt_logstorage_store_config_excluded_apids, + .is_opt = 1 + }, + [DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_CONTEXTNAME] = { + .key = NULL, + .func = dlt_logstorage_store_config_excluded_ctids, + .is_opt = 1 + }, [DLT_LOGSTORAGE_FILTER_CONF_LOGLEVEL] = { .key = "LogLevel", .func = dlt_logstorage_check_loglevel, @@ -1685,6 +1792,16 @@ DLT_STATIC int dlt_daemon_offline_setup_filter_properties(DltLogStorage *handle, tmp_data.ctids = NULL; } + if (tmp_data.excluded_apids != NULL) { + free(tmp_data.excluded_apids); + tmp_data.excluded_apids = NULL; + } + + if (tmp_data.excluded_ctids != NULL) { + free(tmp_data.excluded_ctids); + tmp_data.excluded_ctids = NULL; + } + if (tmp_data.file_name != NULL) { free(tmp_data.file_name); tmp_data.file_name = NULL; @@ -1704,6 +1821,11 @@ DLT_STATIC int dlt_daemon_offline_setup_filter_properties(DltLogStorage *handle, } } + if(dlt_logstorage_count_ids(tmp_data.excluded_apids) > 1 && dlt_logstorage_count_ids(tmp_data.excluded_ctids) > 1) { + dlt_vlog(LOG_WARNING, "%s: Logstorage does not support both multiple excluded applications and contexts\n", __func__); + return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR; + } + /* filter configuration is valid */ ret = dlt_logstorage_setup_table(handle, &tmp_data); @@ -2339,6 +2461,33 @@ DLT_STATIC int dlt_logstorage_filter(DltLogStorage *handle, "%s: ECUID does not match (Requested=%s, config[%d]=%s). Set the config to NULL and continue the filter loop\n", __func__, ecuid, i, config[i]->ecuid); config[i] = NULL; + continue; + } + } + + if(config[i]->excluded_apids != NULL && config[i]->excluded_ctids != NULL) { + /* Filter on excluded application and context */ + if(apid != NULL && ctid != NULL && dlt_logstorage_check_excluded_ids(apid, ",", config[i]->excluded_apids) + && dlt_logstorage_check_excluded_ids(ctid, ",", config[i]->excluded_ctids)) { + dlt_vlog(LOG_DEBUG, "%s: %s matches with [%s] and %s matches with [%s]. Set the config to NULL and continue the filter loop\n", + __func__, apid, config[i]->excluded_apids, ctid, config[i]->excluded_ctids); + config[i] = NULL; + } + } + else if(config[i]->excluded_apids == NULL) { + /* Only filter on excluded contexts */ + if(ctid != NULL && config[i]->excluded_ctids != NULL && dlt_logstorage_check_excluded_ids(ctid, ",", config[i]->excluded_ctids)) { + dlt_vlog(LOG_DEBUG, "%s: %s matches with [%s]. Set the config to NULL and continue the filter loop\n", + __func__, ctid, config[i]->excluded_ctids); + config[i] = NULL; + } + } + else if(config[i]->excluded_ctids == NULL) { + /* Only filter on excluded applications */ + if(apid != NULL && config[i]->excluded_apids != NULL && dlt_logstorage_check_excluded_ids(apid, ",", config[i]->excluded_apids)) { + dlt_vlog(LOG_DEBUG, "%s: %s matches with [%s]. Set the config to NULL and continue the filter loop\n", + __func__, apid, config[i]->excluded_apids); + config[i] = NULL; } } } diff --git a/src/offlinelogstorage/dlt_offline_logstorage.h b/src/offlinelogstorage/dlt_offline_logstorage.h index 61e8896c8..f26d7f4fa 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage.h +++ b/src/offlinelogstorage/dlt_offline_logstorage.h @@ -171,6 +171,8 @@ struct DltLogStorageFilterConfig /* filter section */ char *apids; /* Application IDs configured for filter */ char *ctids; /* Context IDs configured for filter */ + char *excluded_apids; /* Excluded Application IDs configured for filter */ + char *excluded_ctids; /* Excluded Context IDs configured for filter */ int log_level; /* Log level number configured for filter */ int reset_log_level; /* reset Log level to be sent on disconnect */ char *file_name; /* File name for log storage configured for filter */ @@ -265,6 +267,8 @@ typedef struct { typedef enum { DLT_LOGSTORAGE_FILTER_CONF_LOGAPPNAME = 0, DLT_LOGSTORAGE_FILTER_CONF_CONTEXTNAME, + DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_LOGAPPNAME, + DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_CONTEXTNAME, DLT_LOGSTORAGE_FILTER_CONF_LOGLEVEL, DLT_LOGSTORAGE_FILTER_CONF_RESET_LOGLEVEL, DLT_LOGSTORAGE_FILTER_CONF_FILE, diff --git a/src/offlinelogstorage/dlt_offline_logstorage_internal.h b/src/offlinelogstorage/dlt_offline_logstorage_internal.h index 6c659b99e..ea9352cd1 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage_internal.h +++ b/src/offlinelogstorage/dlt_offline_logstorage_internal.h @@ -76,6 +76,12 @@ DLT_STATIC int dlt_logstorage_check_apids(DltLogStorageFilterConfig *config, cha DLT_STATIC int dlt_logstorage_check_ctids(DltLogStorageFilterConfig *config, char *value); +DLT_STATIC int dlt_logstorage_store_config_excluded_apids(DltLogStorageFilterConfig *config, char *value); + +DLT_STATIC int dlt_logstorage_store_config_excluded_ctids(DltLogStorageFilterConfig *config, char *value); + +DLT_STATIC bool dlt_logstorage_check_excluded_ids(char *id, char *delim, char *excluded_ids); + DLT_STATIC int dlt_logstorage_check_loglevel(DltLogStorageFilterConfig *config, char *value); DLT_STATIC int dlt_logstorage_check_gzip_compression(DltLogStorageFilterConfig *config, char *value); diff --git a/tests/gtest_dlt_daemon_offline_log.cpp b/tests/gtest_dlt_daemon_offline_log.cpp index 06cce109b..0ee6cd069 100644 --- a/tests/gtest_dlt_daemon_offline_log.cpp +++ b/tests/gtest_dlt_daemon_offline_log.cpp @@ -31,6 +31,10 @@ extern "C" #include } + +#define DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR 1 +#define DLT_CONFIG_FILE_SECTIONS 3 + unsigned int g_logstorage_cache_max; /* Begin Method: dlt_logstorage::t_dlt_logstorage_list_add*/ TEST(t_dlt_logstorage_list_add, normal) @@ -324,12 +328,12 @@ TEST(t_dlt_logstorage_check_apids, normal) { char value[] = "a,b,c,d"; DltLogStorageFilterConfig config; - memset(&config, 0, sizeof(DltLogStorageFilterConfig)); + /* Initialize id pointer as NULL pointer for testing only */ config.apids = (char *)calloc (1, sizeof(char)); if (config.apids != NULL) { EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_apids(&config, value)); - + EXPECT_EQ(DLT_RETURN_OK, strncmp(config.apids, value, 7)); free(config.apids); } } @@ -344,12 +348,12 @@ TEST(t_dlt_logstorage_check_ctids, normal) { char value[] = "a,b,c,d"; DltLogStorageFilterConfig config; - memset(&config, 0, sizeof(DltLogStorageFilterConfig)); + /* Initialize id pointer as NULL pointer for testing only */ config.ctids = (char *)calloc (1, sizeof(char)); if (config.ctids != NULL) { EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_ctids(&config, value)); - + EXPECT_EQ(DLT_RETURN_OK, strncmp(config.ctids, value, 7)); free(config.ctids); } } @@ -359,6 +363,63 @@ 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_store_config_excluded_apids*/ +TEST(t_dlt_logstorage_store_config_excluded_apids, normal) +{ + char value[] = "a,b,c,d"; + DltLogStorageFilterConfig config; + /* Initialize id pointer as NULL pointer for testing only */ + config.excluded_apids = (char *)calloc (1, sizeof(char)); + + if (config.excluded_apids != NULL) { + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_store_config_excluded_apids(&config, value)); + EXPECT_EQ(DLT_RETURN_OK, strncmp(config.excluded_apids, value, 7)); + free(config.excluded_apids); + } +} + +TEST(t_dlt_logstorage_store_config_excluded_apids, null) +{ + EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_store_config_excluded_apids(NULL, NULL)); +} + +/* Begin Method: dlt_logstorage::t_dlt_logstorage_store_config_excluded_ctids*/ +TEST(t_dlt_logstorage_store_config_excluded_ctids, normal) +{ + char value[] = "a,b,c,d"; + DltLogStorageFilterConfig config; + /* Initialize id pointer as NULL pointer for testing only */ + config.excluded_ctids = (char *)calloc (1, sizeof(char)); + + if (config.excluded_ctids != NULL) { + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_store_config_excluded_ctids(&config, value)); + EXPECT_EQ(DLT_RETURN_OK, strncmp(config.excluded_ctids, value, 7)); + free(config.excluded_ctids); + } +} + +TEST(t_dlt_logstorage_store_config_excluded_ctids, null) +{ + EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_store_config_excluded_ctids(NULL, NULL)); +} + +/* Begin Method: dlt_logstorage::t_dlt_logstorage_check_excluded_ids*/ +TEST(t_dlt_logstorage_check_excluded_ids, normal) +{ + char id[] = "log4"; + char not_excluded_id[] = "log0"; + char delim[] = ","; + char excluded_ids[] = "log1,log2,log3,log4"; + + EXPECT_TRUE(dlt_logstorage_check_excluded_ids(id, delim, excluded_ids)); + EXPECT_FALSE(dlt_logstorage_check_excluded_ids(not_excluded_id, delim, excluded_ids)); +} + +TEST(t_dlt_logstorage_check_excluded_ids, null) +{ + EXPECT_FALSE(dlt_logstorage_check_excluded_ids(NULL, NULL, NULL)); +} + /* Begin Method: dlt_logstorage::t_dlt_logstorage_check_loglevel*/ TEST(t_dlt_logstorage_check_loglevel, normal) { @@ -512,7 +573,9 @@ TEST(t_dlt_logstorage_check_param, null) TEST(t_dlt_logstorage_store_filters, normal) { DltLogStorage handle; + memset(&handle, 0, sizeof(DltLogStorage)); DltLogStorageUserConfig file_config; + memset(&file_config, 0, sizeof(DltLogStorageUserConfig)); char *path = (char*)"/tmp"; char config_file_name[] = "/tmp/dlt_logstorage.conf"; handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; @@ -663,11 +726,12 @@ TEST(t_dlt_logstorage_filter, normal) { char apid[] = "1234"; char ctid[] = "5678"; + char t_apid[] = "4321"; + char t_ctid[] = "8765"; char ecuid[] = "12"; char filename[] = "file_name"; int num = 1; - DltLogStorageFilterConfig value; - memset(&value, 0, sizeof(DltLogStorageFilterConfig)); + DltLogStorageFilterConfig value = {}; value.apids = apid; value.ctids = ctid; value.ecuid = ecuid; @@ -676,7 +740,7 @@ 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_CONFIG_FILE_SECTIONS_MAX] = { 0 }; + DltLogStorageFilterConfig *config[DLT_CONFIG_FILE_SECTIONS] = { 0 }; DltLogStorage handle; handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; handle.config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE; @@ -691,6 +755,117 @@ TEST(t_dlt_logstorage_filter, normal) num = dlt_logstorage_filter(&handle, config, apid, ctid, ecuid, 0); EXPECT_EQ(num, 3); + EXPECT_TRUE(config[0] != NULL); + EXPECT_TRUE(config[1] != NULL); + EXPECT_TRUE(config[2] != NULL); + + /* Filter on excluded application and context */ + value.excluded_apids = apid; + value.excluded_ctids = ctid; + DltLogStorageFilterConfig *neg_filter_config[DLT_CONFIG_FILE_SECTIONS] = { 0 }; + handle.config_list = NULL; + handle.newest_file_list = NULL; + + 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, neg_filter_config, apid, ctid, ecuid, 0); + + EXPECT_EQ(num, 3); + EXPECT_TRUE(neg_filter_config[0] == NULL); + EXPECT_TRUE(neg_filter_config[1] == NULL); + EXPECT_TRUE(neg_filter_config[2] == NULL); + + /* Change excluded fields */ + value.excluded_apids = t_apid; + value.excluded_ctids = t_ctid; + DltLogStorageFilterConfig *t_neg_filter_config[DLT_CONFIG_FILE_SECTIONS] = { 0 }; + handle.config_list = NULL; + handle.newest_file_list = NULL; + + 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, t_neg_filter_config, apid, ctid, ecuid, 0); + + EXPECT_EQ(num, 3); + EXPECT_TRUE(t_neg_filter_config[0] != NULL); + EXPECT_TRUE(t_neg_filter_config[1] != NULL); + EXPECT_TRUE(t_neg_filter_config[2] != NULL); + + /* Only filter on excluded contexts */ + value.excluded_apids = NULL; + value.excluded_ctids = ctid; + DltLogStorageFilterConfig *neg_filter_ctid_only_config[DLT_CONFIG_FILE_SECTIONS] = { 0 }; + handle.config_list = NULL; + handle.newest_file_list = NULL; + + 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, neg_filter_ctid_only_config, apid, ctid, ecuid, 0); + + EXPECT_EQ(num, 3); + EXPECT_TRUE(neg_filter_ctid_only_config[0] == NULL); + EXPECT_TRUE(neg_filter_ctid_only_config[1] == NULL); + EXPECT_TRUE(neg_filter_ctid_only_config[2] == NULL); + + /* Change excluded fields */ + value.excluded_apids = NULL; + value.excluded_ctids = t_ctid; + DltLogStorageFilterConfig *t_neg_filter_ctid_only_config[DLT_CONFIG_FILE_SECTIONS] = { 0 }; + handle.config_list = NULL; + handle.newest_file_list = NULL; + + 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, t_neg_filter_ctid_only_config, apid, ctid, ecuid, 0); + + EXPECT_EQ(num, 3); + EXPECT_TRUE(t_neg_filter_ctid_only_config[0] != NULL); + EXPECT_TRUE(t_neg_filter_ctid_only_config[1] != NULL); + EXPECT_TRUE(t_neg_filter_ctid_only_config[2] != NULL); + + /* Only filter on excluded applications */ + value.excluded_apids = apid; + value.excluded_ctids = NULL; + DltLogStorageFilterConfig *neg_filter_apid_only_config[DLT_CONFIG_FILE_SECTIONS] = { 0 }; + handle.config_list = NULL; + handle.newest_file_list = NULL; + + 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, neg_filter_apid_only_config, apid, ctid, ecuid, 0); + + EXPECT_EQ(num, 3); + EXPECT_TRUE(neg_filter_apid_only_config[0] == NULL); + EXPECT_TRUE(neg_filter_apid_only_config[1] == NULL); + EXPECT_TRUE(neg_filter_apid_only_config[2] == NULL); + + /* Change excluded fields */ + value.excluded_apids = t_apid; + value.excluded_ctids = NULL; + DltLogStorageFilterConfig *t_neg_filter_apid_only_config[DLT_CONFIG_FILE_SECTIONS] = { 0 }; + handle.config_list = NULL; + handle.newest_file_list = NULL; + + 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, t_neg_filter_apid_only_config, apid, ctid, ecuid, 0); + + EXPECT_EQ(num, 3); + EXPECT_TRUE(t_neg_filter_apid_only_config[0] != NULL); + EXPECT_TRUE(t_neg_filter_apid_only_config[1] != NULL); + EXPECT_TRUE(t_neg_filter_apid_only_config[2] != NULL); } TEST(t_dlt_logstorage_filter, null) @@ -715,8 +890,7 @@ TEST(t_dlt_logstorage_write, normal) handle.config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE; handle.config_list = NULL; handle.newest_file_list = NULL; - DltLogStorageFilterConfig value; - memset(&value, 0, sizeof(DltLogStorageFilterConfig)); + DltLogStorageFilterConfig value = {}; value.apids = apid; value.ctids = ctid; value.ecuid = ecuid; @@ -775,8 +949,7 @@ TEST(t_dlt_logstorage_sync_caches, normal) DltLogStorage handle; handle.num_configs = 1; handle.config_list = NULL; - DltLogStorageFilterConfig configs; - memset(&configs, 0, sizeof(DltLogStorageFilterConfig)); + DltLogStorageFilterConfig configs = {}; configs.apids = apid; configs.ctids = ctid; configs.ecuid = ecuid; @@ -1844,8 +2017,7 @@ TEST(t_dlt_daemon_logstorage_sync_cache, normal) daemon.storage_handle->num_configs = 1; daemon.storage_handle->config_list = NULL; strncpy(daemon.storage_handle->device_mount_point, "/tmp", 5); - DltLogStorageFilterConfig configs; - memset(&configs, 0, sizeof(DltLogStorageFilterConfig)); + DltLogStorageFilterConfig configs = {}; configs.apids = apid; configs.ctids = ctid; configs.ecuid = ecuid; diff --git a/tests/gtest_dlt_daemon_offline_log.sh b/tests/gtest_dlt_daemon_offline_log.sh index 5e51f7ae9..b42585cb0 100755 --- a/tests/gtest_dlt_daemon_offline_log.sh +++ b/tests/gtest_dlt_daemon_offline_log.sh @@ -24,6 +24,7 @@ cleanup() cd $tmpPath rm -rf $tmpPath/dlt_logstorage.conf rm -rf $tmpPath/Test*.dlt + rm -rf $tmpPath/*_dlt_logstorage.conf return 0 } @@ -50,6 +51,68 @@ setupTest() echo "File=Test" >>$tmpPath/dlt_logstorage.conf echo "FileSize=1000000" >>$tmpPath/dlt_logstorage.conf echo "NOFiles=1" >>$tmpPath/dlt_logstorage.conf + + touch $tmpPath/pair_dlt_logstorage.conf + if [ $? -eq '1' ] + then + echo "Error in creating pair_dlt_logstorage.conf file" + return 1 + fi + echo "[FILTER1]" >>$tmpPath/pair_dlt_logstorage.conf + echo "LogAppName=NEGF,POSF" >>$tmpPath/pair_dlt_logstorage.conf + echo "ContextName=TS1" >>$tmpPath/pair_dlt_logstorage.conf + echo "ExcludedLogAppName=NEGF" >>$tmpPath/pair_dlt_logstorage.conf + echo "ExcludedContextName=TS1" >>$tmpPath/pair_dlt_logstorage.conf + echo "LogLevel=DLT_LOG_ERROR" >>$tmpPath/pair_dlt_logstorage.conf + echo "File=Test" >>$tmpPath/pair_dlt_logstorage.conf + echo "FileSize=1000000" >>$tmpPath/pair_dlt_logstorage.conf + echo "NOFiles=1" >>$tmpPath/pair_dlt_logstorage.conf + + touch $tmpPath/only_ctid_dlt_logstorage.conf + if [ $? -eq '1' ] + then + echo "Error in creating only_ctid_dlt_logstorage.conf file" + return 1 + fi + echo "[FILTER1]" >>$tmpPath/only_ctid_dlt_logstorage.conf + echo "LogAppName=NEGF" >>$tmpPath/only_ctid_dlt_logstorage.conf + echo "ContextName=TS1" >>$tmpPath/only_ctid_dlt_logstorage.conf + echo "ExcludedContextName=TS1,TS2" >>$tmpPath/only_ctid_dlt_logstorage.conf + echo "LogLevel=DLT_LOG_ERROR" >>$tmpPath/only_ctid_dlt_logstorage.conf + echo "File=Test" >>$tmpPath/only_ctid_dlt_logstorage.conf + echo "FileSize=1000000" >>$tmpPath/only_ctid_dlt_logstorage.conf + echo "NOFiles=1" >>$tmpPath/only_ctid_dlt_logstorage.conf + + touch $tmpPath/only_apid_dlt_logstorage.conf + if [ $? -eq '1' ] + then + echo "Error in creating only_apid_dlt_logstorage.conf file" + return 1 + fi + echo "[FILTER1]" >>$tmpPath/only_apid_dlt_logstorage.conf + echo "LogAppName=NEGF" >>$tmpPath/only_apid_dlt_logstorage.conf + echo "ContextName=TS1" >>$tmpPath/only_apid_dlt_logstorage.conf + echo "ExcludedLogAppName=NEGF,POSF" >>$tmpPath/only_apid_dlt_logstorage.conf + echo "LogLevel=DLT_LOG_ERROR" >>$tmpPath/only_apid_dlt_logstorage.conf + echo "File=Test" >>$tmpPath/only_apid_dlt_logstorage.conf + echo "FileSize=1000000" >>$tmpPath/only_apid_dlt_logstorage.conf + echo "NOFiles=1" >>$tmpPath/only_apid_dlt_logstorage.conf + + touch $tmpPath/abnormal_dlt_logstorage.conf + if [ $? -eq '1' ] + then + echo "Error in creating abnormal_dlt_logstorage.conf file" + return 1 + fi + echo "[FILTER1]" >>$tmpPath/abnormal_dlt_logstorage.conf + echo "LogAppName=NEGF" >>$tmpPath/abnormal_dlt_logstorage.conf + echo "ContextName=TS1" >>$tmpPath/abnormal_dlt_logstorage.conf + echo "ExcludedLogAppName=NEGF,POSF" >>$tmpPath/abnormal_dlt_logstorage.conf + echo "ExcludedContextName=TS1,TS2" >>$tmpPath/abnormal_dlt_logstorage.conf + echo "LogLevel=DLT_LOG_ERROR" >>$tmpPath/abnormal_dlt_logstorage.conf + echo "File=Test" >>$tmpPath/abnormal_dlt_logstorage.conf + echo "FileSize=1000000" >>$tmpPath/abnormal_dlt_logstorage.conf + echo "NOFiles=1" >>$tmpPath/abnormal_dlt_logstorage.conf return 0 } #main function