summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt15
-rw-r--r--tests/gtest_dlt_common.cpp92
-rw-r--r--tests/gtest_dlt_daemon_gateway.cpp2
-rw-r--r--tests/gtest_dlt_daemon_multiple_files_logging.cpp277
-rw-r--r--tests/gtest_dlt_daemon_offline_log.cpp141
-rw-r--r--tests/gtest_dlt_user.cpp87
6 files changed, 602 insertions, 12 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index b3a9339..d627ed2 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -21,8 +21,12 @@ else()
set(LIBRARIES socket)
endif()
+if(WITH_SYSTEMD)
+ set(SYSTEMD_LIBS systemd)
+endif(WITH_SYSTEMD)
+
set(DLT_LIBRARIES dlt ${GTEST_LIBS} ${LIBRARIES})
-set(DLT_DAEMON_LIBRARIES dlt_daemon ${GTEST_LIBS} ${LIBRARIES})
+set(DLT_DAEMON_LIBRARIES dlt_daemon ${GTEST_LIBS} ${LIBRARIES} ${SYSTEMD_LIBS})
set(DLT_CONTROL_LIBRARIES dlt dlt_control_common_lib ${GTEST_LIBS})
#Receiver used for QTs. add_test() is not required
@@ -54,8 +58,8 @@ endforeach()
###################
set(TARGET_LIST gtest_dlt_daemon_gateway
gtest_dlt_daemon_offline_log
- gtest_dlt_daemon_filter
gtest_dlt_daemon_event_handler
+ gtest_dlt_daemon_multiple_files_logging
)
if(WITH_DLT_SHM_ENABLE)
list(APPEND TARGET_LIST gtest_dlt_shm)
@@ -64,9 +68,10 @@ endif()
foreach(target IN LISTS TARGET_LIST)
set(target_SRCS ${target})
add_executable(${target} ${target_SRCS} ${systemd_SRCS})
- target_link_libraries(${target} ${DLT_DAEMON_LIBRARIES})
- if(${target} STREQUAL "gtest_dlt_daemon_event_handler" OR
- ${target} STREQUAL "gtest_dlt_shm")
+ target_link_libraries(${target} ${DLT_DAEMON_LIBRARIES} ${ZLIB_LIBRARY})
+ if(${target} STREQUAL "gtest_dlt_daemon_event_handler"
+ OR ${target} STREQUAL "gtest_dlt_shm"
+ OR ${target} STREQUAL "gtest_dlt_daemon_multiple_files_logging")
add_test(NAME ${target}
COMMAND ${target})
else()
diff --git a/tests/gtest_dlt_common.cpp b/tests/gtest_dlt_common.cpp
index 9a375ce..18830be 100644
--- a/tests/gtest_dlt_common.cpp
+++ b/tests/gtest_dlt_common.cpp
@@ -34,6 +34,8 @@ extern "C"
#include "dlt-daemon_cfg.h"
#include "dlt_user_cfg.h"
#include "dlt_version.h"
+#include "dlt_client.h"
+#include "dlt_protocol.h"
int dlt_buffer_increase_size(DltBuffer *);
int dlt_buffer_minimize_size(DltBuffer *);
@@ -4260,7 +4262,97 @@ TEST(dlt_get_minor_version, nullpointer)
/* End Method:dlt_common::dlt_get_minor_version */
+TEST(dlt_client_parse_get_log_info_resp_text, normal)
+{
+ char input[] = "get_log_info, 07, 02 00 4c 4f 47 00 03 00 54 45 53 54 ff ff 18 00 54 65 73 74 20 43 6f 6e 74 65 78 74 20 66 6f 72 20 4c 6f 67 67 69 6e 67 54 53 31 00 ff ff 1b 00 54 65 73 74 20 43 6f 6e 74 65 78 74 31 20 66 6f 72 20 69 6e 6a 65 63 74 69 6f 6e 54 53 32 00 ff ff 1b 00 54 65 73 74 20 43 6f 6e 74 65 78 74 32 20 66 6f 72 20 69 6e 6a 65 63 74 69 6f 6e 1c 00 54 65 73 74 20 41 70 70 6c 69 63 61 74 69 6f 6e 20 66 6f 72 20 4c 6f 67 67 69 6e 67 53 59 53 00 02 00 4a 4f 55 52 ff ff 0f 00 4a 6f 75 72 6e 61 6c 20 41 64 61 70 74 65 72 4d 47 52 00 ff ff 22 00 43 6f 6e 74 65 78 74 20 6f 66 20 6d 61 69 6e 20 64 6c 74 20 73 79 73 74 65 6d 20 6d 61 6e 61 67 65 72 12 00 44 4c 54 20 53 79 73 74 65 6d 20 4d 61 6e 61 67 65 72 72 65 6d 6f";
+ /* expected output:
+ * APID:LOG- Test Application for Logging
+ * CTID:TEST -1 -1 Test Context for Logging
+ * CTID:TS1- -1 -1 Test Context1 for injection
+ * CTID:TS2- -1 -1 Test Context2 for injection
+ * APID:SYS- DLT System Manager
+ * CTID:JOUR -1 -1 Journal Adapter
+ * CTID:MGR- -1 -1 Context of main dlt system manager
+ */
+
+ DltServiceGetLogInfoResponse * resp = (DltServiceGetLogInfoResponse *)malloc(sizeof(DltServiceGetLogInfoResponse ));
+ DltReturnValue ret = (DltReturnValue) dlt_set_loginfo_parse_service_id(
+ input, &resp->service_id, &resp->status);
+ EXPECT_EQ(DLT_RETURN_OK, ret);
+ EXPECT_EQ(DLT_SERVICE_ID_GET_LOG_INFO, resp->service_id);
+ EXPECT_EQ(GET_LOG_INFO_STATUS_MAX, resp->status);
+
+ ret = dlt_client_parse_get_log_info_resp_text(resp, input);
+ EXPECT_EQ(DLT_RETURN_OK, ret);
+
+ EXPECT_EQ(2,resp->log_info_type.count_app_ids);
+
+ EXPECT_EQ(0, memcmp( "LOG", resp->log_info_type.app_ids[0].app_id,4));
+ EXPECT_EQ(0, strcmp("Test Application for Logging", resp->log_info_type.app_ids[0].app_description));
+ EXPECT_EQ(28, resp->log_info_type.app_ids[0].len_app_description);
+
+ EXPECT_EQ(3, resp->log_info_type.app_ids[0].count_context_ids);
+
+ EXPECT_EQ(0, memcmp( "TEST", resp->log_info_type.app_ids[0].context_id_info[0].context_id,4));
+ EXPECT_EQ(0, strcmp( "Test Context for Logging",resp->log_info_type.app_ids[0].context_id_info[0].context_description ));
+ EXPECT_EQ(24,resp->log_info_type.app_ids[0].context_id_info[0].len_context_description);
+ EXPECT_EQ(-1,resp->log_info_type.app_ids[0].context_id_info[0].log_level);
+ EXPECT_EQ(-1,resp->log_info_type.app_ids[0].context_id_info[0].trace_status);
+
+ EXPECT_EQ(0, memcmp( "TS1", resp->log_info_type.app_ids[0].context_id_info[1].context_id,4));
+ EXPECT_EQ(0, strcmp( "Test Context1 for injection",resp->log_info_type.app_ids[0].context_id_info[1].context_description ));
+ EXPECT_EQ(27,resp->log_info_type.app_ids[0].context_id_info[1].len_context_description);
+ EXPECT_EQ(-1,resp->log_info_type.app_ids[0].context_id_info[1].log_level);
+ EXPECT_EQ(-1,resp->log_info_type.app_ids[0].context_id_info[1].trace_status);
+
+ EXPECT_EQ(0, memcmp( "TS2", resp->log_info_type.app_ids[0].context_id_info[2].context_id,4));
+ EXPECT_EQ(0, strcmp( "Test Context2 for injection",resp->log_info_type.app_ids[0].context_id_info[2].context_description ));
+ EXPECT_EQ(27,resp->log_info_type.app_ids[0].context_id_info[2].len_context_description);
+ EXPECT_EQ(-1,resp->log_info_type.app_ids[0].context_id_info[2].log_level);
+ EXPECT_EQ(-1,resp->log_info_type.app_ids[0].context_id_info[2].trace_status);
+
+ EXPECT_EQ(0, memcmp( "SYS", resp->log_info_type.app_ids[1].app_id,4));
+ EXPECT_EQ(0, strcmp("DLT System Manager", resp->log_info_type.app_ids[1].app_description));
+ EXPECT_EQ(18, resp->log_info_type.app_ids[1].len_app_description);
+
+ EXPECT_EQ(2, resp->log_info_type.app_ids[1].count_context_ids);
+ EXPECT_EQ(0, memcmp( "JOUR", resp->log_info_type.app_ids[1].context_id_info[0].context_id,4));
+ EXPECT_EQ(0, strcmp( "Journal Adapter",resp->log_info_type.app_ids[1].context_id_info[0].context_description ));
+ EXPECT_EQ(15,resp->log_info_type.app_ids[1].context_id_info[0].len_context_description);
+ EXPECT_EQ(-1,resp->log_info_type.app_ids[1].context_id_info[0].log_level);
+ EXPECT_EQ(-1,resp->log_info_type.app_ids[1].context_id_info[0].trace_status);
+
+ EXPECT_EQ(0, memcmp( "MGR", resp->log_info_type.app_ids[1].context_id_info[1].context_id,4));
+ EXPECT_EQ(0, strcmp( "Context of main dlt system manager",resp->log_info_type.app_ids[1].context_id_info[1].context_description ));
+ EXPECT_EQ(34,resp->log_info_type.app_ids[1].context_id_info[1].len_context_description);
+ EXPECT_EQ(-1,resp->log_info_type.app_ids[1].context_id_info[1].log_level);
+ EXPECT_EQ(-1,resp->log_info_type.app_ids[1].context_id_info[1].trace_status);
+
+ ret = (DltReturnValue)dlt_client_cleanup_get_log_info(resp);
+ EXPECT_EQ(DLT_RETURN_OK,ret);
+}
+
+TEST(dlt_getloginfo_conv_ascii_to_string, normal)
+{
+ /* NULL-Pointer, expect exeption */
+ char rp_1[] = "72 65 6d 6f";
+ char rp_2[] = "123456789 72 65 6d 6f";
+ int rp_count = 0;
+ char rp_str[] =
+ { 0x72, 0x65, 0x6d, 0x6f, 0x00 };
+ char wp[5];
+
+ dlt_getloginfo_conv_ascii_to_string(rp_1, &rp_count, wp, 4);
+ EXPECT_EQ(0, strcmp(rp_str, wp));
+ EXPECT_EQ(12, rp_count);
+
+ rp_count = 10;
+ dlt_getloginfo_conv_ascii_to_string(rp_2, &rp_count, wp, 4);
+ EXPECT_EQ(0, strcmp(rp_str, wp));
+ EXPECT_EQ(22, rp_count);
+
+}
/*##############################################################################################################################*/
/*##############################################################################################################################*/
diff --git a/tests/gtest_dlt_daemon_gateway.cpp b/tests/gtest_dlt_daemon_gateway.cpp
index 418ed86..02c80a1 100644
--- a/tests/gtest_dlt_daemon_gateway.cpp
+++ b/tests/gtest_dlt_daemon_gateway.cpp
@@ -146,8 +146,6 @@ TEST(t_dlt_gateway_send_control_message, Normal)
TEST(t_dlt_gateway_send_control_message, nullpointer)
{
DltDaemonLocal daemon_local;
- DltFilterConfiguration current;
- daemon_local.pFilter.current = &current;
DltGatewayConnection connections;
DltConnection connections1;
DltReceiver receiver1;
diff --git a/tests/gtest_dlt_daemon_multiple_files_logging.cpp b/tests/gtest_dlt_daemon_multiple_files_logging.cpp
new file mode 100644
index 0000000..05b58f2
--- /dev/null
+++ b/tests/gtest_dlt_daemon_multiple_files_logging.cpp
@@ -0,0 +1,277 @@
+/*
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2011-2015, BMW AG
+ *
+ * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
+ *
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License (MPL), 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/.
+ *
+ * For further information see http://www.genivi.org/.
+ */
+
+/*!
+ * \author
+ * Oleg Tropmann <oleg.tropmann@daimler.com>
+ * Daniel Weber <daniel.w.weber@daimler.com>
+ *
+ * \copyright Copyright © 2022 Daimler TSS GmbH. \n
+ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
+ *
+ * \file gtest_dlt_daemon_multiple_files_logging.ccpp
+ */
+
+#include <gtest/gtest.h>
+
+int connectServer(void);
+
+extern "C"
+{
+#include "dlt_common.h"
+#include <syslog.h>
+#include <dirent.h>
+#include <string.h>
+}
+
+// publish prototypes
+void configure(const char* path, const char* file_name, bool enable_limit, int file_size, int max_files_size);
+void write_log_message();
+void verify_multiple_files(const char* path, const char* file_name, int file_size, int max_files_size);
+void verify_single_file(const char* path, const char* file_name);
+void verify_in_one_file(const char* path, const char* file_name, const char* log1, const char* log2);
+bool file_contains_strings(const char* abs_file_path, const char* str1, const char* str2);
+int get_file_index(char* file_name);
+int compare_int(const void* a, const void* b);
+
+/**
+ * Configure dlt logging using file size limits.
+ */
+TEST(t_dlt_logging_multiple_files, normal)
+{
+ const char* path = "/tmp";
+ const char* file_name = "dlt.log";
+ const int file_size = 128;
+ const int max_file_size = 512;
+ configure(path, file_name, true, file_size, max_file_size);
+ write_log_message();
+ EXPECT_NO_THROW(dlt_log_free());
+ verify_multiple_files(path, file_name, file_size, max_file_size);
+}
+
+/**
+ * Configure dlt logging using file size limits.
+ * Though, due to an error during initialization dlt logging defaults to one file logging.
+ */
+TEST(t_dlt_logging_one_file_as_fallback, normal)
+{
+ const char* path = "/tmp";
+ const char* file_name = "dltlog";
+ configure(path, file_name, true, 128, 512);
+ write_log_message();
+ EXPECT_NO_THROW(dlt_log_free());
+ verify_single_file(path, file_name);
+}
+
+/**
+ * Configure dlt logging without file size limits resulting in one file logging.
+ */
+TEST(t_dlt_logging_one_file, normal)
+{
+ const char* path = "/tmp";
+ const char* file_name = "dlt.log";
+ configure(path, file_name, false, 128, 512);
+ write_log_message();
+ EXPECT_NO_THROW(dlt_log_free());
+ verify_single_file(path, file_name);
+}
+
+/**
+ * The dlt_daemon calls dlt_log_init multiple times. In the past, so we create
+ * unnecessary two files. The reinit have to append to the first file.
+ */
+TEST(t_dlt_logging_multiple_files_append_reinit, normal)
+{
+ const char* path = "/tmp";
+ const char* file_name = "dlt.log";
+ const int file_size = 256;
+ const int max_file_size = 512;
+
+ const char* log1 = "ONE\n";
+ const char* log2 = "TWO\n";
+
+ configure(path, file_name, true, file_size, max_file_size);
+ dlt_vlog(LOG_INFO, "%s", log1);
+ EXPECT_NO_THROW(dlt_log_free());
+
+ configure(path, file_name, true, file_size, max_file_size);
+ dlt_vlog(LOG_INFO, "%s", log2);
+ EXPECT_NO_THROW(dlt_log_free());
+ verify_in_one_file(path, file_name, log1, log2);
+}
+
+void configure(const char *path, const char* file_name, const bool enable_limit, const int file_size, const int max_files_size)
+{
+ char abs_file_path[PATH_MAX];
+ snprintf(abs_file_path, sizeof(abs_file_path), "%s/%s", path, file_name);
+ printf("debug test: %s\n", abs_file_path);
+
+ EXPECT_NO_THROW(dlt_log_set_filename(abs_file_path));
+ EXPECT_NO_THROW(dlt_log_set_level(6));
+ EXPECT_NO_THROW(dlt_log_init_multiple_logfiles_support(DLT_LOG_TO_FILE, enable_limit, file_size, max_files_size));
+}
+
+void write_log_message()
+{
+ for (unsigned int i = 0; i < 10; i++) {
+ dlt_vlog(LOG_INFO, "%d. Unit test logging into multiple files if configured.\n", i);
+ }
+}
+
+void verify_multiple_files(const char* path, const char* file_name, const int file_size, const int max_files_size)
+{
+ int sum_size = 0;
+ int num_files = 0;
+ int file_indices[100];
+
+ char filename[PATH_MAX + 1];
+ struct dirent *dp;
+ struct stat status;
+
+ char file_name_copy[NAME_MAX];
+ strncpy(file_name_copy, file_name, NAME_MAX);
+ char filename_base[NAME_MAX];
+ EXPECT_TRUE(dlt_extract_base_name_without_ext(file_name_copy, filename_base, sizeof(filename_base)));
+ const char *filename_ext = get_filename_ext(file_name);
+ EXPECT_TRUE(filename_ext);
+
+ DIR *dir = opendir(path);
+ while ((dp = readdir(dir)) != NULL) {
+ if (strstr(dp->d_name, filename_base) &&
+ strstr(dp->d_name, filename_ext)) {
+
+ snprintf(filename, sizeof(filename), "%s/%s", path, dp->d_name);
+
+ if (0 == stat(filename, &status)) {
+ EXPECT_LE(status.st_size, file_size);
+ EXPECT_GE(status.st_size, file_size/2);
+ sum_size += status.st_size;
+ file_indices[num_files++] = get_file_index(filename);
+ } else {
+ EXPECT_TRUE(false);
+ }
+ }
+ }
+
+ EXPECT_LE(sum_size, max_files_size);
+ EXPECT_GT(sum_size, 0);
+ EXPECT_GT(num_files, 0);
+
+ //check that file indices are successive in ascending order
+ qsort(file_indices, num_files, sizeof(int), compare_int);
+ int index = file_indices[0];
+ for (int i=1; i<num_files; i++) {
+ EXPECT_EQ(file_indices[i], ++index);
+ }
+}
+
+void verify_single_file(const char* path, const char* file_name)
+{
+ char abs_file_path[PATH_MAX];
+ snprintf(abs_file_path, sizeof(abs_file_path), "%s/%s", path, file_name);
+
+ struct stat status;
+ if (0 == stat(abs_file_path, &status)) {
+ EXPECT_GT(status.st_size, 0);
+ } else {
+ EXPECT_TRUE(false);
+ }
+}
+
+void verify_in_one_file(const char* path, const char* file_name, const char* log1, const char* log2)
+{
+ char abs_file_path[PATH_MAX + 1];
+ struct dirent *dp;
+
+ char file_name_copy[NAME_MAX];
+ strncpy(file_name_copy, file_name, NAME_MAX);
+ char filename_base[NAME_MAX];
+ EXPECT_TRUE(dlt_extract_base_name_without_ext(file_name_copy, filename_base, sizeof(filename_base)));
+ const char *filename_ext = get_filename_ext(file_name);
+ EXPECT_TRUE(filename_ext);
+
+ bool found = false;
+
+ DIR *dir = opendir(path);
+ while ((dp = readdir(dir)) != NULL) {
+ if (strstr(dp->d_name, filename_base) &&
+ strstr(dp->d_name, filename_ext)) {
+
+ snprintf(abs_file_path, sizeof(abs_file_path), "%s/%s", path, dp->d_name);
+
+ if (file_contains_strings(abs_file_path, log1, log2)) {
+ found = true;
+ break;
+ }
+ }
+ }
+
+ EXPECT_TRUE(found);
+}
+
+bool file_contains_strings(const char* abs_file_path, const char* str1, const char* str2)
+{
+ bool found = false;
+ FILE *file = fopen(abs_file_path, "r");
+ if (file != nullptr) {
+ fseek (file , 0 , SEEK_END);
+ long size = ftell (file);
+ rewind (file);
+
+ char* buffer = (char*) malloc(size);
+ long read_bytes = fread(buffer, 1, size, file);
+
+ EXPECT_EQ(size, read_bytes);
+
+ if ((strstr(buffer, str1) != nullptr) &&
+ (strstr(buffer, str2) != nullptr)) {
+
+ found = true;
+ }
+
+ fclose(file);
+ free(buffer);
+ }
+ return found;
+}
+
+int get_file_index(char* file_name)
+{
+ char *dot = strrchr(file_name, '.');
+ *dot = '\0';
+
+ //start with the first zero
+ char *iterator = strchr(file_name, '0');
+ do {} while (*(++iterator) == '0');
+ //now iterator points to the first character after 0
+
+ return atoi(iterator);
+}
+
+int compare_int(const void* a, const void* b)
+{
+ if (*((int*)a) == *((int*)b)) return 0;
+ else if (*((int*)a) < *((int*)b)) return -1;
+ else return 1;
+}
+
+int main(int argc, char **argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ ::testing::FLAGS_gtest_break_on_failure = true;
+ /*::testing::FLAGS_gtest_filter = "*.normal"; */
+ /*::testing::FLAGS_gtest_repeat = 10000; */
+ return RUN_ALL_TESTS();
+}
diff --git a/tests/gtest_dlt_daemon_offline_log.cpp b/tests/gtest_dlt_daemon_offline_log.cpp
index 0eb7715..e2ed88c 100644
--- a/tests/gtest_dlt_daemon_offline_log.cpp
+++ b/tests/gtest_dlt_daemon_offline_log.cpp
@@ -175,10 +175,62 @@ TEST(t_dlt_logstorage_read_number, null)
EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_read_number(&number, NULL));
}
+TEST(t_dlt_logstorage_read_boolean, normal)
+{
+ unsigned int val;
+ {
+ char str[] = "0";
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_read_bool(&val, str));
+ EXPECT_EQ(0, val);
+ }
+ {
+ char str[] = "1";
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_read_bool(&val, str));
+ EXPECT_EQ(1, val);
+ }
+ {
+ char str[] = "off";
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_read_bool(&val, str));
+ EXPECT_EQ(0, val);
+ }
+ {
+ char str[] = "on";
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_read_bool(&val, str));
+ EXPECT_EQ(1, val);
+ }
+ {
+ char str[] = "false";
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_read_bool(&val, str));
+ EXPECT_EQ(0, val);
+ }
+ {
+ char str[] = "true";
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_read_bool(&val, str));
+ EXPECT_EQ(1, val);
+ }
+ {
+ char str[] = "invalidvalue";
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_read_bool(&val, str));
+ EXPECT_EQ(0, val);
+ }
+ {
+ char str[] = "not";
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_read_bool(&val, str));
+ EXPECT_EQ(0, val);
+ }
+}
+
+TEST(t_dlt_logstorage_read_boolean, null)
+{
+ unsigned int val;
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_read_bool(&val, NULL));
+}
+
/* Begin Method: dlt_logstorage::t_dlt_logstorage_create_keys*/
TEST(t_dlt_logstorage_create_keys, normal)
{
DltLogStorageFilterConfig data;
+ memset(&data, 0, sizeof(DltLogStorageFilterConfig));
char *keys = NULL;
int num_keys = 0;
char apids[] = "1234";
@@ -235,6 +287,7 @@ TEST(t_dlt_logstorage_validate_filter_name, null)
TEST(t_dlt_logstorage_filter_set_strategy, normal)
{
DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
dlt_logstorage_filter_set_strategy(&config, DLT_LOGSTORAGE_SYNC_ON_MSG);
EXPECT_EQ(&dlt_logstorage_prepare_on_msg, config.dlt_logstorage_prepare);
@@ -269,6 +322,7 @@ TEST(t_dlt_logstorage_check_apids, normal)
{
char value[] = "a,b,c,d";
DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
config.apids = (char *)calloc (1, sizeof(char));
if (config.apids != NULL) {
@@ -288,6 +342,7 @@ TEST(t_dlt_logstorage_check_ctids, normal)
{
char value[] = "a,b,c,d";
DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
config.ctids = (char *)calloc (1, sizeof(char));
if (config.ctids != NULL) {
@@ -307,6 +362,7 @@ TEST(t_dlt_logstorage_check_loglevel, normal)
{
char value[] = "DLT_LOG_FATAL";
DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_loglevel(&config, value));
EXPECT_EQ(1, config.log_level);
@@ -322,6 +378,7 @@ TEST(t_dlt_logstorage_check_filename, normal)
{
char value[] = "file_name";
DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
config.file_name = (char *)calloc (1, sizeof(char));
if (config.file_name != NULL) {
@@ -335,6 +392,7 @@ TEST(t_dlt_logstorage_check_filename, abnormal)
{
char value[] = "../file_name";
DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
config.file_name = (char *)calloc (1, sizeof(char));
if (config.file_name != NULL) {
@@ -354,6 +412,7 @@ TEST(t_dlt_logstorage_check_filesize, normal)
{
char value[] = "100";
DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_filesize(&config, value));
EXPECT_EQ(100, config.file_size);
@@ -369,6 +428,7 @@ TEST(t_dlt_logstorage_check_nofiles, normal)
{
char value[] = "100";
DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_nofiles(&config, value));
EXPECT_EQ(100, config.num_files);
@@ -384,6 +444,7 @@ TEST(t_dlt_logstorage_check_sync_strategy, normal)
{
char value[] = "ON_MSG";
DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
config.sync = 0;
EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_sync_strategy(&config, value));
@@ -394,6 +455,7 @@ TEST(t_dlt_logstorage_check_sync_strategy, abnormal)
{
char value[] = "UNKNOWN";
DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
config.sync = 0;
EXPECT_EQ(DLT_RETURN_TRUE, dlt_logstorage_check_sync_strategy(&config, value));
@@ -410,6 +472,7 @@ TEST(t_dlt_logstorage_check_ecuid, normal)
{
char value[] = "213";
DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
config.ecuid = (char *)calloc (1, sizeof(char));
if (config.ecuid != NULL) {
@@ -432,6 +495,7 @@ TEST(t_dlt_logstorage_check_param, normal)
{
char value[] = "100";
DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_param(&config, DLT_LOGSTORAGE_FILTER_CONF_FILESIZE, value));
EXPECT_EQ(100, config.file_size);
@@ -560,6 +624,7 @@ TEST(t_dlt_logstorage_get_config, normal)
char file_name[] = "file_name";
int num_config = 0;
DltLogStorageFilterConfig value;
+ memset(&value, 0, sizeof(DltLogStorageFilterConfig));
value.log_level = 0;
value.apids = apid;
value.ctids = ctid;
@@ -601,6 +666,7 @@ TEST(t_dlt_logstorage_filter, normal)
char filename[] = "file_name";
int num = 1;
DltLogStorageFilterConfig value;
+ memset(&value, 0, sizeof(DltLogStorageFilterConfig));
value.apids = apid;
value.ctids = ctid;
value.ecuid = ecuid;
@@ -653,6 +719,7 @@ TEST(t_dlt_logstorage_write, normal)
handle.config_list = NULL;
handle.newest_file_list = NULL;
DltLogStorageFilterConfig value;
+ memset(&value, 0, sizeof(DltLogStorageFilterConfig));
value.apids = apid;
value.ctids = ctid;
value.ecuid = ecuid;
@@ -685,6 +752,7 @@ TEST(t_dlt_logstorage_sync_caches, normal)
handle.num_configs = 1;
handle.config_list = NULL;
DltLogStorageFilterConfig configs;
+ memset(&configs, 0, sizeof(DltLogStorageFilterConfig));
configs.apids = apid;
configs.ctids = ctid;
configs.ecuid = ecuid;
@@ -708,7 +776,12 @@ TEST(t_dlt_logstorage_log_file_name, normal)
file_config.logfile_counteridxlen = 10;
int cmpRes = 0;
char name[] = "log";
- dlt_logstorage_log_file_name(log_file_name, &file_config, name, 0);
+
+ DltLogStorageFilterConfig filter_config;
+ memset(&filter_config, 0, sizeof(filter_config));
+ filter_config.file_name = &name[0];
+
+ dlt_logstorage_log_file_name(log_file_name, &file_config, &filter_config, 0);
cmpRes = strncmp(log_file_name, "log/0000000000", 14);
EXPECT_EQ(0, cmpRes);
@@ -716,8 +789,7 @@ TEST(t_dlt_logstorage_log_file_name, normal)
TEST(t_dlt_logstorage_log_file_name, null)
{
- char name[] = "log";
- dlt_logstorage_log_file_name(NULL, NULL, name, 0);
+ dlt_logstorage_log_file_name(NULL, NULL, NULL, 0);
}
/* Begin Method: dlt_logstorage::t_dlt_logstorage_sort_file_name*/
@@ -878,13 +950,23 @@ TEST(t_dlt_logstorage_get_idx_of_log_file, normal)
file_config.logfile_delimiter = { '_' };
file_config.logfile_maxcounter = 2;
file_config.logfile_counteridxlen = 2;
+ char name[] = "Test";
char *file = (char *)"Test_002_20160509_191132.dlt";
- EXPECT_EQ(2, dlt_logstorage_get_idx_of_log_file(&file_config, file));
+ DltLogStorageFilterConfig filter_config;
+ memset(&filter_config, 0, sizeof(filter_config));
+ filter_config.file_name = &name[0];
+
+ EXPECT_EQ(2, dlt_logstorage_get_idx_of_log_file(&file_config, &filter_config, file));
+
+ char *gz_file = (char *)"Test_142_20160509_191132.dlt.gz";
+ filter_config.gzip_compression = 1;
+
+ EXPECT_EQ(142, dlt_logstorage_get_idx_of_log_file(&file_config, &filter_config, gz_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));
+ EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_get_idx_of_log_file(NULL, NULL, NULL));
}
/* Begin Method: dlt_logstorage::t_dlt_logstorage_storage_dir_info*/
@@ -897,6 +979,7 @@ TEST(t_dlt_logstorage_storage_dir_info, normal)
file_config.logfile_counteridxlen = 2;
char *path = (char *)"/tmp";
DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
char apids;
char ctids;
config.apids = &apids;
@@ -921,6 +1004,7 @@ TEST(t_dlt_logstorage_open_log_file, normal)
file_config.logfile_counteridxlen = 2;
char *path = (char *)"/tmp";
DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
char apids;
char ctids;
config.apids = &apids;
@@ -947,6 +1031,7 @@ TEST(t_dlt_logstorage_prepare_on_msg, normal1)
file_config.logfile_counteridxlen = 2;
char *path = (char *)"/tmp";
DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
char apids;
char ctids;
config.apids = &apids;
@@ -975,6 +1060,7 @@ TEST(t_dlt_logstorage_prepare_on_msg, normal2)
file_config.logfile_counteridxlen = 2;
char *path = (char *)"/tmp";
DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
char apids;
char ctids;
config.apids = &apids;
@@ -1016,6 +1102,7 @@ TEST(t_dlt_logstorage_prepare_on_msg, normal3)
file_config.logfile_counteridxlen = 2;
char *path = (char *)"/tmp";
DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
char apids;
char ctids;
char *working_file_name = (char *)"Test_002_20160509_191132.dlt";
@@ -1064,6 +1151,7 @@ TEST(t_dlt_logstorage_write_on_msg, normal)
file_config.logfile_counteridxlen = 2;
char *path = (char *)"/tmp";
DltLogStorageFilterConfig config;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
char apids;
char ctids;
config.apids = &apids;
@@ -1073,6 +1161,7 @@ TEST(t_dlt_logstorage_write_on_msg, normal)
config.log = NULL;
config.working_file_name = NULL;
config.wrap_id = 0;
+ config.gzip_compression = 0;
unsigned int size = 8;
unsigned char data1[] = "dlt_data";
unsigned char data2[] = "dlt_data";
@@ -1089,6 +1178,42 @@ TEST(t_dlt_logstorage_write_on_msg, normal)
data1, size, data2, size, data3, size));
}
+TEST(t_dlt_logstorage_write_on_msg, gzip)
+{
+ 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;
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
+ char apids;
+ char ctids;
+ config.apids = &apids;
+ config.ctids = &ctids;
+ config.file_name = (char *)"Test";
+ config.records = NULL;
+ config.log = NULL;
+ config.working_file_name = NULL;
+ config.wrap_id = 0;
+ config.gzip_compression = 1;
+ unsigned int size = 8;
+ unsigned char data1[] = "dlt_data";
+ unsigned char data2[] = "dlt_data";
+ unsigned char data3[] = "dlt_data";
+
+ DltNewestFileName newest_file_name;
+ newest_file_name.file_name = (char *)"Test";
+ newest_file_name.newest_file = (char *)"Test_003_20200728_191132.dlt.gz";
+ newest_file_name.wrap_id = 0;
+ newest_file_name.next = NULL;
+
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_on_msg(&config, &file_config, path, 1, &newest_file_name));
+ EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write_on_msg(&config, &file_config, path,
+ 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, NULL, NULL, 0, NULL, 0, NULL, 0));
@@ -1130,6 +1255,8 @@ TEST(t_dlt_logstorage_prepare_msg_cache, normal)
char *path = (char *)"/tmp";
DltLogStorageFilterConfig config;
DltNewestFileName newest_info;
+ memset(&newest_info, 0, sizeof(DltNewestFileName));
+ memset(&config, 0, sizeof(DltLogStorageFilterConfig));
char apids;
char ctids;
config.apids = &apids;
@@ -1374,6 +1501,7 @@ TEST(t_dlt_daemon_logstorage_get_loglevel, normal)
memset(&daemon_local, 0, sizeof(DltDaemonLocal));
memset(&daemon_local.pGateway, 0, sizeof(DltGateway));
DltLogStorageFilterConfig value;
+ memset(&value, 0, sizeof(DltLogStorageFilterConfig));
value.log_level = 4;
value.apids = apid;
value.ctids = ctid;
@@ -1427,6 +1555,7 @@ TEST(t_dlt_daemon_logstorage_update_application_loglevel, normal)
memset(&daemon_local, 0, sizeof(DltDaemonLocal));
memset(&daemon_local.pGateway, 0, sizeof(DltGateway));
DltLogStorageFilterConfig value;
+ memset(&value, 0, sizeof(DltLogStorageFilterConfig));
value.log_level = 5;
value.apids = apid;
value.ctids = ctid;
@@ -1499,6 +1628,7 @@ TEST(t_dlt_daemon_logstorage_write, normal)
daemon.storage_handle->config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE;
daemon.storage_handle->config_list = NULL;
DltLogStorageFilterConfig value;
+ memset(&value, 0, sizeof(DltLogStorageFilterConfig));
value.apids = apid;
value.ctids = ctid;
value.ecuid = ecuid;
@@ -1598,6 +1728,7 @@ TEST(t_dlt_daemon_logstorage_sync_cache, normal)
daemon.storage_handle->config_list = NULL;
strncpy(daemon.storage_handle->device_mount_point, "/tmp", 5);
DltLogStorageFilterConfig configs;
+ memset(&configs, 0, sizeof(DltLogStorageFilterConfig));
configs.apids = apid;
configs.ctids = ctid;
configs.ecuid = ecuid;
diff --git a/tests/gtest_dlt_user.cpp b/tests/gtest_dlt_user.cpp
index cc7851a..aa8b28e 100644
--- a/tests/gtest_dlt_user.cpp
+++ b/tests/gtest_dlt_user.cpp
@@ -30,6 +30,7 @@
#include <string.h>
#include <stdint.h>
#include <float.h>
+#include <chrono>
extern "C" {
#include "dlt_user.h"
@@ -5249,6 +5250,92 @@ TEST(t_dlt_user_is_logLevel_enabled, nullpointer)
}
/*/////////////////////////////////////// */
+/* t_dlt_user_shutdown_while_init_is_running */
+
+struct ShutdownWhileInitParams {
+ ShutdownWhileInitParams() = default;
+ // delete copy constructor
+ ShutdownWhileInitParams(const ShutdownWhileInitParams&) = delete;
+
+ std::chrono::time_point<std::chrono::steady_clock> stop_time;
+
+ pthread_cond_t dlt_free_done = PTHREAD_COND_INITIALIZER;
+ pthread_mutex_t dlt_free_mtx = PTHREAD_MUTEX_INITIALIZER;
+ bool has_error = false;
+
+};
+
+void* dlt_free_call_and_deadlock_detection(void *arg) {
+ auto *params = static_cast<ShutdownWhileInitParams *>(arg);
+
+ // allow thread to be canceled
+ int old_thread_type;
+ pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old_thread_type);
+
+ dlt_free();
+
+ // signal that we are done
+ pthread_mutex_lock(&params->dlt_free_mtx);
+ pthread_cond_signal(&params->dlt_free_done);
+ pthread_mutex_unlock(&params->dlt_free_mtx);
+ return nullptr;
+}
+
+void *dlt_free_thread(void *arg) {
+ auto *params = static_cast<ShutdownWhileInitParams *>(arg);
+ while (std::chrono::steady_clock::now() < params->stop_time && !params->has_error) {
+
+ // pthread cond_timedwait expects an absolute time to wait
+ struct timespec abs_time{};
+ clock_gettime(CLOCK_REALTIME, &abs_time);
+ abs_time.tv_sec += 3; // wait at most 3 seconds
+
+ pthread_t dlt_free_deadlock_detection_thread_id;
+
+ pthread_mutex_lock(&params->dlt_free_mtx);
+ pthread_create(&dlt_free_deadlock_detection_thread_id, nullptr, dlt_free_call_and_deadlock_detection, params);
+ const auto err = pthread_cond_timedwait(&params->dlt_free_done, &params->dlt_free_mtx, &abs_time);
+ pthread_mutex_unlock(&params->dlt_free_mtx);
+
+ if (err == ETIMEDOUT) {
+ fprintf(stderr, "\n%s: detected DLT-deadlock!\n", __func__);
+ params->has_error = true;
+
+ // cancel thread after timeout, so join won't block forever.
+ pthread_cancel(dlt_free_deadlock_detection_thread_id);
+ }
+
+ pthread_join(dlt_free_deadlock_detection_thread_id, nullptr);
+ }
+
+ return nullptr;
+}
+
+TEST(t_dlt_user_shutdown_while_init_is_running, normal) {
+ const auto max_runtime = std::chrono::seconds(15);
+ const auto stop_time = std::chrono::steady_clock::now() + max_runtime;
+
+ struct ShutdownWhileInitParams args{};
+ args.stop_time = stop_time;
+
+ pthread_t dlt_free_thread_id;
+ pthread_create(&dlt_free_thread_id, nullptr, dlt_free_thread, &args);
+
+ while (std::chrono::steady_clock::now() < stop_time && !args.has_error) {
+ dlt_init();
+ }
+
+ pthread_join(dlt_free_thread_id, nullptr);
+ EXPECT_FALSE(args.has_error);
+
+ const auto last_init = dlt_init();
+ const auto last_free = dlt_free();
+
+ EXPECT_EQ(last_init, DLT_RETURN_OK);
+ EXPECT_EQ(last_free, DLT_RETURN_OK);
+}
+
+/*/////////////////////////////////////// */
/* main */
int main(int argc, char **argv)
{