summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Probert <linus.probert@gmail.com>2023-04-19 11:28:50 +0200
committerGitHub <noreply@github.com>2023-04-19 11:28:50 +0200
commit5ca800c65fba4738dedf85058fef2eca3251fe18 (patch)
tree100b5175f09cc8a75d3d52b1051539665a571585
parenta87a6985b86dce769167a4cb87afcf29abc77fbe (diff)
downloadDLT-daemon-5ca800c65fba4738dedf85058fef2eca3251fe18.tar.gz
logstorage: Adds option to write logs in gzip format (#442)
* logstorage: Adds option to write logs in gzip format Adds functionality to allow storing offline logs in gzipped files instead of standard dlt files. * Ensure tests run safely with or without GZIP compression enabled * Enforce minimum version of zlib if enabling gzip compression
-rw-r--r--CMakeLists.txt11
-rw-r--r--doc/dlt_offline_logstorage.md3
-rw-r--r--src/daemon/CMakeLists.txt3
-rw-r--r--src/offlinelogstorage/dlt_offline_logstorage.c63
-rw-r--r--src/offlinelogstorage/dlt_offline_logstorage.h36
-rw-r--r--src/offlinelogstorage/dlt_offline_logstorage_behavior.c343
-rw-r--r--src/offlinelogstorage/dlt_offline_logstorage_behavior_internal.h8
-rw-r--r--src/offlinelogstorage/dlt_offline_logstorage_internal.h4
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/gtest_dlt_daemon_offline_log.cpp141
10 files changed, 478 insertions, 136 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a47a782..7ce050b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -84,6 +84,7 @@ option(WITH_DLT_PKGCONFIG "Set to ON to generate pkgconfig .pc files"
option(WITH_DLT_CXX11_EXT "Set to ON to build C++11 extensions" OFF)
option(WITH_DLT_COREDUMPHANDLER "EXPERIMENTAL! Set to ON to build src/core_dump_handler binaries. EXPERIMENTAL" OFF)
option(WITH_DLT_LOGSTORAGE_CTRL_UDEV "PROTOTYPE! Set to ON to build logstorage control application with udev support" OFF)
+option(WITH_DLT_LOGSTORAGE_GZIP "Set to ON to build logstorage control application with gzip compression support" OFF)
option(WITH_DLT_USE_IPv6 "Set to ON for IPv6 support" ON)
option(WITH_DLT_KPI "Set to ON to build src/kpi binaries" OFF)
option(WITH_DLT_FATAL_LOG_TRAP "Set to ON to enable DLT_LOG_FATAL trap(trigger segv inside dlt-user library)" OFF)
@@ -104,7 +105,10 @@ set(LICENSE "Mozilla Public License Version 2.0")
# Build, project and include settings
find_package(Threads REQUIRED)
-if(WITH_DLT_COREDUMPHANDLER OR WITH_DLT_FILETRANSFER)
+if(WITH_DLT_LOGSTORAGE_GZIP)
+ set(ZLIB_LIBRARY "-lz")
+ find_package(ZLIB 1.2.9 REQUIRED)
+elseif(WITH_DLT_COREDUMPHANDLER OR WITH_DLT_FILETRANSFER)
set(ZLIB_LIBRARY "-lz")
find_package(ZLIB REQUIRED)
else()
@@ -177,6 +181,10 @@ if (WITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK)
add_definitions(-DWITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK)
endif()
+if (WITH_DLT_LOGSTORAGE_GZIP)
+ add_definitions(-DDLT_LOGSTORAGE_USE_GZIP)
+endif()
+
if(WITH_GPROF)
add_compile_options(-pg)
endif()
@@ -344,6 +352,7 @@ message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_HOST_SYSTEM_PROCESSOR = ${CMAKE_HOST_SYSTEM_PROCESSOR}")
message(STATUS "CMAKE_SYSTEM_PROCESSOR = ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "WITH_DLT_LOGSTORAGE_CTRL_UDEV = ${WITH_DLT_LOGSTORAGE_CTRL_UDEV}")
+message(STATUS "WITH_DLT_LOGSTORAGE_GZIP = ${WITH_DLT_LOGSTORAGE_GZIP}")
message(STATUS "DLT_IPC = ${DLT_IPC}(Path: ${DLT_USER_IPC_PATH})")
message(STATUS "WITH_DLT_DAEMON_VSOCK_IPC = ${WITH_DLT_DAEMON_VSOCK_IPC}")
message(STATUS "WITH_DLT_LIB_VSOCK_IPC = ${WITH_DLT_LIB_VSOCK_IPC}")
diff --git a/doc/dlt_offline_logstorage.md b/doc/dlt_offline_logstorage.md
index 3d29dab..91ef75b 100644
--- a/doc/dlt_offline_logstorage.md
+++ b/doc/dlt_offline_logstorage.md
@@ -74,6 +74,7 @@ NOFiles=<number of files> # Number of created files before oldest is
SyncBehavior=<strategy> # Specify sync strategy. Default: Sync'ed after every message. See Logstorage Rinbuffer Implementation below.
EcuID=<ECUid> # Specify ECU identifier
SpecificSize=<spec size in bytes> # Store logs in storage devices after specific size is reached.
+GzipCompression=<on or off> # Write the logfiles with gzip compression.
```
The Parameter "SyncBehavior","EcuID" and "SpecificSize" are optional - all
@@ -103,6 +104,7 @@ NOFiles=5
EcuID=ECU1
SyncBehavior=ON_SPECIFIC_SIZE
SpecificSize=5000
+GzipCompression=on
[FILTER3]
LogAppName=TEST
@@ -123,6 +125,7 @@ EcuID=<ECUid> # Specify ECU identifier
File=<file name> # Base name of the created files that containing the logs, e.g. "example". For further file naming scheme configurations see man dlt.conf
FileSize=<file size in bytes> # Maximum file size in bytes
NOFiles=<number of files> # Number of created files before oldest is deleted and a new one is created
+GzipCompression=on # Compress the log files
[NON-VERBOSE-LOGLEVEL-CTRL<unique number>] # filter configuration name to control log level of Non-Verbose applications
LogAppName=<APID> # Name of application (wildcard allowed)
diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt
index 9916bb4..c585875 100644
--- a/src/daemon/CMakeLists.txt
+++ b/src/daemon/CMakeLists.txt
@@ -65,6 +65,9 @@ target_link_libraries(dlt-daemon ${RT_LIBRARY} ${SOCKET_LIBRARY} ${CMAKE_THREAD_
if (WITH_SYSTEMD_SOCKET_ACTIVATION)
target_link_libraries(dlt-daemon systemd)
endif()
+if (WITH_DLT_LOGSTORAGE_GZIP)
+ target_link_libraries(dlt-daemon ${ZLIB_LIBRARY})
+endif()
install(TARGETS dlt-daemon
RUNTIME DESTINATION bin
diff --git a/src/offlinelogstorage/dlt_offline_logstorage.c b/src/offlinelogstorage/dlt_offline_logstorage.c
index a03a861..b8793c7 100644
--- a/src/offlinelogstorage/dlt_offline_logstorage.c
+++ b/src/offlinelogstorage/dlt_offline_logstorage.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
+#include <sys/syslog.h>
#include <syslog.h>
#include <sys/stat.h>
#include <sys/stat.h>
@@ -73,6 +74,11 @@ DLT_STATIC void dlt_logstorage_filter_config_free(DltLogStorageFilterConfig *dat
if (data->log != NULL)
fclose(data->log);
+#ifdef DLT_LOGSTORAGE_USE_GZIP
+ if (data->gzlog != NULL)
+ gzclose(data->gzlog);
+#endif
+
if (data->cache != NULL) {
free(data->cache);
data->cache = NULL;
@@ -421,6 +427,34 @@ DLT_STATIC int dlt_logstorage_read_number(unsigned int *number, char *value)
}
/**
+ * dlt_logstorage_read_bool
+ *
+ * Evaluate a boolean config value. Values such as '1', 'on' or 'true' will be
+ * treated as true otherwise the config value will be interpreted as false.
+ *
+ * @param bool The boolean to populate
+ * @param value The string from the config file
+ * @returns 0 on success, -1 on error
+ */
+DLT_STATIC int dlt_logstorage_read_bool(unsigned int *boolean, char *value)
+{
+ int len = 0;
+ if (value == NULL)
+ return -1;
+
+ len = strnlen(value, 5);
+ *boolean = 0;
+ if (strncmp(value, "on", len) == 0) {
+ *boolean = 1;
+ } else if (strncmp(value, "true", len) == 0) {
+ *boolean = 1;
+ } else if (strncmp(value, "1", len) == 0) {
+ *boolean = 1;
+ }
+ return 0;
+}
+
+/**
* dlt_logstorage_get_keys_list
*
* Obtain key list and number of keys for id list passed
@@ -1052,6 +1086,20 @@ DLT_STATIC int dlt_logstorage_check_nofiles(DltLogStorageFilterConfig *config,
return dlt_logstorage_read_number(&config->num_files, value);
}
+DLT_STATIC int dlt_logstorage_check_gzip_compression(DltLogStorageFilterConfig *config,
+ char *value)
+{
+ if ((config == NULL) || (value == NULL))
+ return -1;
+
+ int result = dlt_logstorage_read_bool(&config->gzip_compression, value);
+#ifndef DLT_LOGSTORAGE_USE_GZIP
+ dlt_log(LOG_WARNING, "dlt-daemon not compiled with logstorage gzip support\n");
+ config->gzip_compression = 0;
+#endif
+ return result;
+}
+
DLT_STATIC int dlt_logstorage_check_specificsize(DltLogStorageFilterConfig *config,
char *value)
{
@@ -1195,6 +1243,11 @@ DLT_STATIC DltLogstorageFilterConf
.key = "SpecificSize",
.func = dlt_logstorage_check_specificsize,
.is_opt = 1
+ },
+ [DLT_LOGSTORAGE_FILTER_CONF_GZIP_COMPRESSION] = {
+ .key = "GzipCompression",
+ .func = dlt_logstorage_check_gzip_compression,
+ .is_opt = 1
}
};
@@ -1250,6 +1303,11 @@ DLT_STATIC DltLogstorageFilterConf
.key = NULL,
.func = dlt_logstorage_check_specificsize,
.is_opt = 1
+ },
+ [DLT_LOGSTORAGE_FILTER_CONF_GZIP_COMPRESSION] = {
+ .key = "GzipCompression",
+ .func = dlt_logstorage_check_gzip_compression,
+ .is_opt = 1
}
};
@@ -1304,6 +1362,11 @@ DLT_STATIC DltLogstorageFilterConf
.key = NULL,
.func = dlt_logstorage_check_specificsize,
.is_opt = 1
+ },
+ [DLT_LOGSTORAGE_FILTER_CONF_GZIP_COMPRESSION] = {
+ .key = "GzipCompression",
+ .func = dlt_logstorage_check_gzip_compression,
+ .is_opt = 1
}
};
/**
diff --git a/src/offlinelogstorage/dlt_offline_logstorage.h b/src/offlinelogstorage/dlt_offline_logstorage.h
index 16252bc..8f32a89 100644
--- a/src/offlinelogstorage/dlt_offline_logstorage.h
+++ b/src/offlinelogstorage/dlt_offline_logstorage.h
@@ -53,28 +53,30 @@
#include <search.h>
#include <stdbool.h>
+#include <zlib.h>
#include "dlt_common.h"
#include "dlt-daemon_cfg.h"
#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_KEYS 7 /* Max number of possible keys when searching for */
+#define DLT_OFFLINE_LOGSTORAGE_MAXIDS 100 /* Maximum entries for each apids and ctids */
+#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
-#define DLT_OFFLINE_LOGSTORAGE_FREE 0
-#define DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED 0
-#define DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE 1
+#define DLT_OFFLINE_LOGSTORAGE_INIT_DONE 1 /* For device configuration status */
+#define DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED 1
+#define DLT_OFFLINE_LOGSTORAGE_FREE 0
+#define DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED 0
+#define DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE 1
-#define DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES 2 /* sync logstorage caches */
+#define DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES 2 /* sync logstorage caches */
-#define DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN 15 /* Maximum size for key */
-#define DLT_OFFLINE_LOGSTORAGE_MAX_FILE_NAME_LEN 50 /* Maximum file name length of the log file */
+#define DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN 15 /* Maximum size for key */
+#define DLT_OFFLINE_LOGSTORAGE_MAX_FILE_NAME_LEN 50 /* Maximum file name length of the log file */
-#define DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN 4
-#define DLT_OFFLINE_LOGSTORAGE_INDEX_LEN 3
-#define DLT_OFFLINE_LOGSTORAGE_MAX_INDEX 999
-#define DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN 16
+#define DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN 4
+#define DLT_OFFLINE_LOGSTORAGE_GZ_FILE_EXTENSION_LEN 7
+#define DLT_OFFLINE_LOGSTORAGE_INDEX_LEN 3
+#define DLT_OFFLINE_LOGSTORAGE_MAX_INDEX 999
+#define DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN 16
#define DLT_OFFLINE_LOGSTORAGE_INDEX_OFFSET (DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN + \
DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN + \
DLT_OFFLINE_LOGSTORAGE_INDEX_LEN)
@@ -169,6 +171,7 @@ struct DltLogStorageFilterConfig
unsigned int num_files; /* MAX number of storage files configured for filters */
int sync; /* Sync strategy */
char *ecuid; /* ECU identifier */
+ unsigned int gzip_compression; /* Toggle if log files should be gzip compressed */
/* callback function for filter configurations */
int (*dlt_logstorage_prepare)(DltLogStorageFilterConfig *config,
DltLogStorageUserConfig *file_config,
@@ -191,6 +194,10 @@ struct DltLogStorageFilterConfig
char *dev_path,
int status);
FILE *log; /* current open log file */
+ int fd; /* The file descriptor for the active log file */
+#ifdef DLT_LOGSTORAGE_USE_GZIP
+ gzFile gzlog; /* current open gz log file */
+#endif
void *cache; /* log data cache */
unsigned int specific_size; /* cache size used for specific_size sync strategy */
unsigned int current_write_file_offset; /* file offset for specific_size sync strategy */
@@ -248,6 +255,7 @@ typedef enum {
DLT_LOGSTORAGE_FILTER_CONF_SYNCBEHAVIOR,
DLT_LOGSTORAGE_FILTER_CONF_ECUID,
DLT_LOGSTORAGE_FILTER_CONF_SPECIFIC_SIZE,
+ DLT_LOGSTORAGE_FILTER_CONF_GZIP_COMPRESSION,
DLT_LOGSTORAGE_FILTER_CONF_COUNT
} DltLogstorageFilterConfType;
diff --git a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c
index 35d8306..666a78b 100644
--- a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c
+++ b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c
@@ -28,11 +28,38 @@
#include <stdlib.h>
#include <errno.h>
+#include "dlt_common.h"
#include "dlt_offline_logstorage.h"
#include "dlt_offline_logstorage_behavior.h"
#include "dlt_offline_logstorage_behavior_internal.h"
unsigned int g_logstorage_cache_size;
+
+/**
+ * dlt_logstorage_concat
+ *
+ * Concatenates two strings but keeps the size of the result less then dst_size.
+ *
+ * @param dst The destination string
+ * @param src The source string to concat
+ */
+DLT_STATIC void dlt_logstorage_concat_logfile_name(char *log_file_name, const char *append)
+{
+ size_t dst_len = strnlen(log_file_name, DLT_MOUNT_PATH_MAX);
+ size_t src_len = strlen(append);
+
+ if (dst_len < DLT_MOUNT_PATH_MAX) {
+ size_t rem_len = DLT_MOUNT_PATH_MAX - dst_len - 1;
+ strncat(log_file_name, append, rem_len);
+ } else {
+ dlt_vlog(LOG_ERR, "Log file name reached max len: %s [%d]\n", log_file_name, DLT_MOUNT_PATH_MAX);
+ }
+
+ if (src_len + dst_len >= DLT_MOUNT_PATH_MAX) {
+ dlt_vlog(LOG_ERR, "Log file path too long. Truncated: %s", log_file_name);
+ }
+}
+
/**
* dlt_logstorage_log_file_name
*
@@ -53,18 +80,18 @@ unsigned int g_logstorage_cache_size;
*/
void dlt_logstorage_log_file_name(char *log_file_name,
DltLogStorageUserConfig *file_config,
- char *name,
+ DltLogStorageFilterConfig *filter_config,
int idx)
{
- if ((log_file_name == NULL) || (file_config == NULL))
+ if ((log_file_name == NULL) || (file_config == NULL) || (filter_config == NULL))
return;
char file_index[10] = { '\0' };
/* create log file name */
- memset(log_file_name, 0, DLT_MOUNT_PATH_MAX * sizeof(char));
- strcat(log_file_name, name);
- strncat(log_file_name, &file_config->logfile_delimiter, 1);
+ memset(log_file_name, '\0', DLT_MOUNT_PATH_MAX * sizeof(char));
+ dlt_logstorage_concat_logfile_name(log_file_name, filter_config->file_name);
+ dlt_logstorage_concat_logfile_name(log_file_name, &file_config->logfile_delimiter);
snprintf(file_index, 10, "%d", idx);
@@ -78,11 +105,11 @@ void dlt_logstorage_log_file_name(char *log_file_name,
if (file_config->logfile_counteridxlen > digit_idx)
{
for (i = 0 ; i < (file_config->logfile_counteridxlen - digit_idx) ; i++)
- strcat(log_file_name, "0");
+ dlt_logstorage_concat_logfile_name(log_file_name, "0");
}
}
- strcat(log_file_name, file_index);
+ dlt_logstorage_concat_logfile_name(log_file_name, file_index);
/* Add time stamp if user has configured */
if (file_config->logfile_timestamp) {
@@ -106,10 +133,13 @@ void dlt_logstorage_log_file_name(char *log_file_name,
dlt_vlog(LOG_WARNING, "%s: snprintf truncation %s\n", __func__,
stamp);
}
- strcat(log_file_name, stamp);
+ dlt_logstorage_concat_logfile_name(log_file_name, stamp);
}
- strcat(log_file_name, ".dlt");
+ dlt_logstorage_concat_logfile_name(log_file_name, ".dlt");
+ if (filter_config->gzip_compression) {
+ dlt_logstorage_concat_logfile_name(log_file_name, ".gz");
+ }
}
/**
@@ -209,57 +239,35 @@ void dlt_logstorage_rearrange_file_name(DltLogStorageFileList **head)
*
* Extract index of log file name passed as input argument
*
- * @param file file name to extract the index from
* @param file_config User configurations for log file
+ * @param config Filter configurations for log file
+ * @param file file name to extract the index from
* @return index on success, -1 if no index is found
*/
-unsigned int dlt_logstorage_get_idx_of_log_file(DltLogStorageUserConfig *file_config,
- char *file)
+unsigned int
+dlt_logstorage_get_idx_of_log_file(DltLogStorageUserConfig *file_config,
+ DltLogStorageFilterConfig *config,
+ char *file)
{
- unsigned int idx = -1;
- char *endptr;
- char *filename;
- unsigned int filename_len = 0;
- unsigned int fileindex_len = 0;
-
- if ((file_config == NULL) || (file == NULL))
+ if (file_config == NULL || config == NULL || file == NULL)
return -1;
- /* Calculate actual file name length */
- filename = strchr(file, file_config->logfile_delimiter);
+ int idx = 0;
+ int basename_len;
+ char *sptr, *eptr;
- if (filename == NULL) {
- dlt_vlog(LOG_ERR, "Cannot extract filename from %s\n", file);
- return -1;
- }
-
- filename_len = strlen(file) - strlen(filename);
-
- /* index is retrived from file name */
- if (file_config->logfile_timestamp) {
- fileindex_len = strlen(file) -
- (DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN +
- DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN +
- filename_len + 1);
-
- idx = (int)strtol(&file[strlen(file) -
- (DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN +
- fileindex_len +
- DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN)],
- &endptr,
- 10);
- }
- else {
- fileindex_len = strlen(file) -
- (DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN +
- filename_len + 1);
-
- idx = (int)strtol(&file[strlen(file) -
- (DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN
- + fileindex_len)], &endptr, 10);
- }
+ /* Find the next delimiter after the first one:
+ * Eg. base-log-name_<idx>_<timestamp>.dlt
+ * ^ ^
+ * | |
+ * From here --+ +--- To this position
+ */
+ basename_len = strlen(config->file_name);
+ sptr = file + basename_len + 1;
+ eptr = strchr(file + basename_len + 1, file_config->logfile_delimiter);
+ idx = strtol(sptr, &eptr, 10);
- if ((endptr == file) || (idx == 0))
+ if (idx == 0)
dlt_log(LOG_ERR,
"Unable to calculate index from log file name. Reset to 001.\n");
@@ -322,15 +330,30 @@ int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config,
config->records = NULL;
}
+ char suffix[10];
+ int suffix_len;
+ memset(suffix, 0, 10);
+ if (config->gzip_compression) {
+ suffix_len = DLT_OFFLINE_LOGSTORAGE_GZ_FILE_EXTENSION_LEN;
+ strncpy(suffix, ".dlt.gz", suffix_len);
+ }
+ else {
+ suffix_len = DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN;
+ strncpy(suffix, ".dlt", suffix_len);
+ }
+
for (i = 0; i < cnt; i++) {
int len = 0;
+ int fname_len = 0;
len = strlen(config->file_name);
+ fname_len = strlen(files[i]->d_name);
if ((strncmp(files[i]->d_name, config->file_name, len) == 0) &&
- (files[i]->d_name[len] == file_config->logfile_delimiter)) {
+ (files[i]->d_name[len] == file_config->logfile_delimiter) &&
+ (fname_len > suffix_len && strncmp(&files[i]->d_name[fname_len - suffix_len], suffix, suffix_len) == 0))
+ {
DltLogStorageFileList **tmp = NULL;
- current_idx = dlt_logstorage_get_idx_of_log_file(file_config,
- files[i]->d_name);
+ current_idx = dlt_logstorage_get_idx_of_log_file(file_config, config, files[i]->d_name);
if (config->records == NULL) {
config->records = malloc(sizeof(DltLogStorageFileList));
@@ -394,6 +417,32 @@ int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config,
/**
* dlt_logstorage_open_log_file
*
+ * Open a handle to the logfile
+ *
+ * @param config A pointer to the current DltLogStorageFilterConfig
+ * @param fpath The file path
+ * @param mode The mode to open the file with
+ */
+DLT_STATIC void
+dlt_logstorage_open_log_output_file(DltLogStorageFilterConfig *config,
+ const char *fpath, const char *mode)
+{
+ FILE *file = fopen(fpath, mode);
+ config->fd = fileno(file);
+ if (config->gzip_compression) {
+#ifdef DLT_LOGSTORAGE_USE_GZIP
+ dlt_vlog(LOG_DEBUG, "%s: Opening GZIP log file\n", __func__);
+ config->gzlog = gzdopen(config->fd, mode);
+#endif
+ } else {
+ dlt_vlog(LOG_DEBUG, "%s: Opening log file\n", __func__);
+ config->log = file;
+ }
+}
+
+/**
+ * dlt_logstorage_open_log_file
+ *
* Open a log file. Check storage directory for already created files and open
* the oldest if there is enough space to store at least msg_size.
* Otherwise create a new file, but take configured max number of files into
@@ -451,16 +500,13 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config,
/* need new file*/
if (num_log_files == 0) {
- dlt_logstorage_log_file_name(file_name,
- file_config,
- config->file_name,
- 1);
+ dlt_logstorage_log_file_name(file_name, file_config, config, 1);
/* concatenate path and file and open absolute path */
strcat(absolute_file_path, storage_path);
strcat(absolute_file_path, file_name);
config->working_file_name = strdup(file_name);
- config->log = fopen(absolute_file_path, "a+");
+ dlt_logstorage_open_log_output_file(config, absolute_file_path, "a");
/* Add file to file list */
*tmp = malloc(sizeof(DltLogStorageFileList));
@@ -498,8 +544,8 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config,
ret = stat(absolute_file_path, &s);
/* if size is enough, open it */
- if ((ret == 0) && (s.st_size + msg_size <= (int) config->file_size)) {
- config->log = fopen(absolute_file_path, "a+");
+ if ((ret == 0) && (s.st_size + msg_size <= (int)config->file_size)) {
+ dlt_logstorage_open_log_output_file(config, absolute_file_path, "a");
config->current_write_file_offset = s.st_size;
}
else {
@@ -507,8 +553,7 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config,
unsigned int idx = 0;
/* get index of newest log file */
- idx = dlt_logstorage_get_idx_of_log_file(file_config,
- config->working_file_name);
+ idx = dlt_logstorage_get_idx_of_log_file(file_config, config, config->working_file_name);
idx += 1;
/* wrap around if max index is reached or an error occurred
@@ -518,10 +563,7 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config,
config->wrap_id += 1;
}
- dlt_logstorage_log_file_name(file_name,
- file_config,
- config->file_name,
- idx);
+ dlt_logstorage_log_file_name(file_name, file_config, config, idx);
/* concatenate path and file and open absolute path */
memset(absolute_file_path,
@@ -546,7 +588,7 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config,
__func__, absolute_file_path, num_log_files, config->num_files);
}
- config->log = fopen(absolute_file_path, "a+");
+ dlt_logstorage_open_log_output_file(config, absolute_file_path, "a");
dlt_vlog(LOG_DEBUG,
"%s: Filename and Index after updating [%s]-[%u]\n",
@@ -590,7 +632,11 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config,
}
}
+#ifdef DLT_LOGSTORAGE_USE_GZIP
+ if (config->gzlog == NULL && config->log == NULL) {
+#else
if (config->log == NULL) {
+#endif
if (*tmp != NULL) {
if ((*tmp)->name != NULL) {
free((*tmp)->name);
@@ -665,12 +711,36 @@ DLT_STATIC int dlt_logstorage_find_last_dlt_header(void *ptr,
}
/**
+ * dlt_logstorage_write_to_log
+ *
+ * Write logdata to log storage file
+ *
+ * @param ptr A pointer to the data to write
+ * @param size The size of the data blocks
+ * @param nmemb The number of blocks to write
+ * @param config A pointer to DltLogStorageFilterConfig
+ */
+DLT_STATIC int dlt_logstorage_write_to_log(void *ptr, size_t size, size_t nmemb,
+ DltLogStorageFilterConfig *config)
+{
+#ifdef DLT_LOGSTORAGE_USE_GZIP
+ if (config->gzip_compression) {
+ return gzfwrite(ptr, size, nmemb, config->gzlog);
+ } else {
+ return fwrite(ptr, size, nmemb, config->log);
+ }
+#else
+ return fwrite(ptr, size, nmemb, config->log);
+#endif
+}
+
+/**
* dlt_logstorage_check_write_ret
*
- * check the return value of fwrite
+ * check the return value of fwrite/gzfwrite
*
* @param config DltLogStorageFilterConfig
- * @param ret return value of fwrite call
+ * @param ret return value of fwrite/gzfwrite call
*/
DLT_STATIC void dlt_logstorage_check_write_ret(DltLogStorageFilterConfig *config,
int ret)
@@ -679,20 +749,60 @@ DLT_STATIC void dlt_logstorage_check_write_ret(DltLogStorageFilterConfig *config
dlt_vlog(LOG_ERR, "%s: cannot retrieve config information\n", __func__);
if (ret <= 0) {
- if (ferror(config->log) != 0)
- dlt_vlog(LOG_ERR, "%s: failed to write cache into log file\n", __func__);
+ if (config->gzip_compression) {
+#ifdef DLT_LOGSTORAGE_USE_GZIP
+ const char *msg = gzerror(config->gzlog, &ret);
+ if (msg != NULL) {
+ dlt_vlog(LOG_ERR, "%s: failed to write cache into log file: %s\n", __func__, msg);
+ }
+#endif
+ } else {
+ if (ferror(config->log) != 0)
+ dlt_vlog(LOG_ERR, "%s: failed to write cache into log file\n", __func__);
+ }
}
else {
/* force sync */
- if (fflush(config->log) != 0)
- dlt_vlog(LOG_ERR, "%s: failed to flush log file\n", __func__);
+ if (config->gzip_compression) {
+#ifdef DLT_LOGSTORAGE_USE_GZIP
+ if (gzflush(config->gzlog, Z_SYNC_FLUSH) != 0)
+ dlt_vlog(LOG_ERR, "%s: failed to gzflush log file\n", __func__);
+#endif
+ } else {
+ if (fflush(config->log) != 0)
+ dlt_vlog(LOG_ERR, "%s: failed to flush log file\n", __func__);
+ }
- if (fsync(fileno(config->log)) != 0)
+ if (fsync(config->fd) != 0) {
/* some filesystem doesn't support fsync() */
- if (errno != ENOSYS)
- {
- dlt_vlog(LOG_ERR, "%s: failed to sync log file\n", __func__);
+ if (errno != ENOSYS) {
+ dlt_vlog(LOG_ERR, "%s: failed to sync log file\n",
+ __func__);
}
+ }
+ }
+}
+
+/**
+ * dlt_logstorage_close_file
+ *
+ * Close open file handles if any exist in the provided
+ * DltLogStorageFilterConfig
+ *
+ * @param config The DltLogStorageFilterConfig to operate on
+ */
+DLT_STATIC void dlt_logstorage_close_file(DltLogStorageFilterConfig *config)
+{
+
+#ifdef DLT_LOGSTORAGE_USE_GZIP
+ if (config->gzlog) {
+ gzclose(config->gzlog);
+ config->gzlog = NULL;
+ }
+#endif
+ if (config->log) {
+ fclose(config->log);
+ config->log = NULL;
}
}
@@ -734,11 +844,8 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config,
/* In case of cached-based strategy, the newest file information
* must be updated everytime of synchronization.
*/
- if (config->log) {
- fclose(config->log);
- config->log = NULL;
- config->current_write_file_offset = 0;
- }
+ dlt_logstorage_close_file(config);
+ config->current_write_file_offset = 0;
if (dlt_logstorage_open_log_file(config, file_config,
dev_path, count, true) != 0) {
@@ -761,13 +868,11 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config,
if ((start_index >= 0) && (end_index > start_index) &&
(count > 0) && (count <= remain_file_size))
{
- ret = fwrite((uint8_t*)config->cache + start_offset + start_index,
- count, 1, config->log);
+ dlt_logstorage_write_to_log((uint8_t*)config->cache + start_offset + start_index, count, 1, config);
dlt_logstorage_check_write_ret(config, ret);
/* Close log file */
- fclose(config->log);
- config->log = NULL;
+ dlt_logstorage_close_file(config);
config->current_write_file_offset = 0;
footer->last_sync_offset = start_offset + count;
@@ -776,8 +881,7 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config,
else
{
/* Close log file */
- fclose(config->log);
- config->log = NULL;
+ dlt_logstorage_close_file(config);
config->current_write_file_offset = 0;
}
}
@@ -798,8 +902,7 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config,
}
}
- ret = fwrite((uint8_t*)config->cache + start_offset + start_index, count, 1,
- config->log);
+ ret = dlt_logstorage_write_to_log((uint8_t *)config->cache + start_offset + start_index, count, 1, config);
dlt_logstorage_check_write_ret(config, ret);
config->current_write_file_offset += count;
@@ -835,12 +938,16 @@ int dlt_logstorage_prepare_on_msg(DltLogStorageFilterConfig *config,
if ((config == NULL) || (file_config == NULL) || (dev_path == NULL) ||
(newest_file_info == NULL)) {
- dlt_vlog(LOG_INFO, "Wrong paratemters\n");
+ dlt_vlog(LOG_DEBUG, "Wrong paratemters\n");
return -1;
}
/* This is for ON_MSG/UNSET strategy */
+#ifdef DLT_LOGSTORAGE_USE_GZIP
+ if (config->log == NULL && config->gzlog == NULL) {
+#else
if (config->log == NULL) {
+#endif
/* Sync the wrap id and working file name before opening log file */
if (config->wrap_id < newest_file_info->wrap_id) {
config->wrap_id = newest_file_info->wrap_id;
@@ -859,17 +966,20 @@ int dlt_logstorage_prepare_on_msg(DltLogStorageFilterConfig *config,
true);
}
else { /* already open, check size and create a new file if needed */
- ret = fstat(fileno(config->log), &s);
+ ret = fstat(config->fd, &s);
if (ret == 0) {
- /* check if adding new data do not exceed max file size */
- /* Check if wrap id needs to be updated*/
+ /* Check if adding new data do not exceed max file size
+ *
+ * This is inaccurate for gz compressed files but as long as log
+ * messages aren't gigantic it should be negligeble
+ *
+ * Also check if wrap id needs to be updated */
if ((s.st_size + log_msg_size > (int)config->file_size) ||
(strcmp(config->working_file_name, newest_file_info->newest_file) != 0) ||
(config->wrap_id < newest_file_info->wrap_id)) {
- fclose(config->log);
- config->log = NULL;
+ dlt_logstorage_close_file(config);
/* Sync the wrap id and working file name before opening log file */
if (config->wrap_id <= newest_file_info->wrap_id) {
@@ -935,22 +1045,29 @@ int dlt_logstorage_write_on_msg(DltLogStorageFilterConfig *config,
return -1;
}
- ret = fwrite(data1, 1, size1, config->log);
+ ret = dlt_logstorage_write_to_log(data1, 1, size1, config);
if (ret != size1)
dlt_log(LOG_WARNING, "Wrote less data than specified\n");
- ret = fwrite(data2, 1, size2, config->log);
-
+ ret = dlt_logstorage_write_to_log(data2, 1, size2, config);
if (ret != size2)
dlt_log(LOG_WARNING, "Wrote less data than specified\n");
- ret = fwrite(data3, 1, size3, config->log);
-
+ ret = dlt_logstorage_write_to_log(data3, 1, size3, config);
if (ret != size3)
dlt_log(LOG_WARNING, "Wrote less data than specified\n");
+#ifdef DLT_LOGSTORAGE_USE_GZIP
+ if (config->gzip_compression) {
+ gzerror(config->gzlog, &ret);
+ return ret;
+ } else {
+ return ferror(config->log);
+ }
+#else
return ferror(config->log);
+#endif
}
/**
@@ -969,8 +1086,6 @@ int dlt_logstorage_sync_on_msg(DltLogStorageFilterConfig *config,
char *dev_path,
int status)
{
- int ret;
-
(void)file_config; /* satisfy compiler */
(void)dev_path;
@@ -978,10 +1093,15 @@ int dlt_logstorage_sync_on_msg(DltLogStorageFilterConfig *config,
return -1;
if (status == DLT_LOGSTORAGE_SYNC_ON_MSG) { /* sync on every message */
- ret = fflush(config->log);
-
- if (ret != 0)
- dlt_log(LOG_ERR, "fflush failed\n");
+ if (config->gzip_compression) {
+#ifdef DLT_LOGSTORAGE_USE_GZIP
+ if (gzflush(config->gzlog, Z_SYNC_FLUSH) != 0)
+ dlt_vlog(LOG_ERR, "%s: failed to gzflush log file\n", __func__);
+#endif
+ } else {
+ if (fflush(config->log) != 0)
+ dlt_vlog(LOG_ERR, "%s: failed to flush log file\n", __func__);
+ }
}
return 0;
@@ -1234,7 +1354,7 @@ int dlt_logstorage_write_msg_cache(DltLogStorageFilterConfig *config,
memcpy(curr_write_addr, data2, size2);
curr_write_addr += size2;
memcpy(curr_write_addr, data3, size3);
- }
+ }
}
@@ -1335,8 +1455,7 @@ int dlt_logstorage_sync_msg_cache(DltLogStorageFilterConfig *config,
if (status == DLT_LOGSTORAGE_SYNC_ON_FILE_SIZE)
{
/* Close log file */
- fclose(config->log);
- config->log = NULL;
+ dlt_logstorage_close_file(config);
config->current_write_file_offset = 0;
}
}
diff --git a/src/offlinelogstorage/dlt_offline_logstorage_behavior_internal.h b/src/offlinelogstorage/dlt_offline_logstorage_behavior_internal.h
index b493db4..fd23bb8 100644
--- a/src/offlinelogstorage/dlt_offline_logstorage_behavior_internal.h
+++ b/src/offlinelogstorage/dlt_offline_logstorage_behavior_internal.h
@@ -51,15 +51,17 @@
void dlt_logstorage_log_file_name(char *log_file_name,
DltLogStorageUserConfig *file_config,
- char *name,
+ DltLogStorageFilterConfig *filter_config,
int idx);
unsigned int 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);
+unsigned int
+dlt_logstorage_get_idx_of_log_file(DltLogStorageUserConfig *file_config,
+ DltLogStorageFilterConfig *config,
+ char *file);
int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config,
char *path,
diff --git a/src/offlinelogstorage/dlt_offline_logstorage_internal.h b/src/offlinelogstorage/dlt_offline_logstorage_internal.h
index d150b6f..ed126eb 100644
--- a/src/offlinelogstorage/dlt_offline_logstorage_internal.h
+++ b/src/offlinelogstorage/dlt_offline_logstorage_internal.h
@@ -68,6 +68,8 @@ DLT_STATIC int dlt_logstorage_count_ids(const char *str);
DLT_STATIC int dlt_logstorage_read_number(unsigned int *number, char *value);
+DLT_STATIC int dlt_logstorage_read_bool(unsigned int *boolean, char *value);
+
DLT_STATIC int dlt_logstorage_read_list_of_names(char **names, char *value);
DLT_STATIC int dlt_logstorage_check_apids(DltLogStorageFilterConfig *config, char *value);
@@ -76,6 +78,8 @@ DLT_STATIC int dlt_logstorage_check_ctids(DltLogStorageFilterConfig *config, cha
DLT_STATIC int dlt_logstorage_check_loglevel(DltLogStorageFilterConfig *config, char *value);
+DLT_STATIC int dlt_logstorage_check_gzip_compression(DltLogStorageFilterConfig *config, char *value);
+
DLT_STATIC int dlt_logstorage_check_filename(DltLogStorageFilterConfig *config, char *value);
DLT_STATIC int dlt_logstorage_check_filesize(DltLogStorageFilterConfig *config, char *value);
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index be0889c..579d730 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -64,7 +64,7 @@ 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})
+ 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")
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;