summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/dlt_user.c9
-rw-r--r--src/system/dlt-system-journal.c28
-rw-r--r--src/system/dlt-system-options.c5
-rw-r--r--src/system/dlt-system.conf3
-rw-r--r--src/system/dlt-system.h1
-rw-r--r--src/tests/dlt-test-user.c86
6 files changed, 120 insertions, 12 deletions
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index 55e57bf..4206dd2 100644
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -1538,6 +1538,7 @@ DltReturnValue dlt_user_log_write_start_id(DltContext *handle,
log->args_num = 0;
log->log_level = loglevel;
log->size = 0;
+ log->use_timestamp = DLT_AUTO_TIMESTAMP;
/* In non-verbose mode, insert message id */
if (dlt_user.verbose_mode == 0) {
@@ -3584,8 +3585,14 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, int mtype)
/* Set header extra parameters */
dlt_set_id(msg.headerextra.ecu, dlt_user.ecuID);
+
/*msg.headerextra.seid = 0; */
- msg.headerextra.tmsp = dlt_uptime();
+ if (log->use_timestamp == DLT_AUTO_TIMESTAMP) {
+ msg.headerextra.tmsp = dlt_uptime();
+ }
+ else {
+ msg.headerextra.tmsp = log->user_timestamp;
+ }
if (dlt_message_set_extraparameters(&msg, 0) == DLT_RETURN_ERROR)
return DLT_RETURN_ERROR;
diff --git a/src/system/dlt-system-journal.c b/src/system/dlt-system-journal.c
index 5c10c50..2845406 100644
--- a/src/system/dlt-system-journal.c
+++ b/src/system/dlt-system-journal.c
@@ -202,6 +202,7 @@ void journal_thread(void *v_conf)
sd_journal *j;
char match[DLT_SYSTEM_JOURNAL_BOOT_ID_MAX_LENGTH] = "_BOOT_ID=";
sd_id128_t boot_id;
+ uint32_t ts;
char buffer_process[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 },
buffer_priority[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 },
@@ -345,13 +346,26 @@ void journal_thread(void *v_conf)
snprintf(buffer_priority, DLT_SYSTEM_JOURNAL_BUFFER_SIZE, "prio_unknown:");
/* write log entry */
- DLT_LOG(journalContext, loglevel,
- DLT_STRING(timestamp.real),
- DLT_STRING(timestamp.monotonic),
- DLT_STRING(buffer_process),
- DLT_STRING(buffer_priority),
- DLT_STRING(buffer_message)
- );
+ if (conf->Journal.UseOriginalTimestamp == 0) {
+ DLT_LOG(journalContext, loglevel,
+ DLT_STRING(timestamp.real),
+ DLT_STRING(timestamp.monotonic),
+ DLT_STRING(buffer_process),
+ DLT_STRING(buffer_priority),
+ DLT_STRING(buffer_message)
+ );
+
+ }
+ else {
+ /* since we are talking about points in time, I'd prefer truncating over arithmetic rounding */
+ ts = (uint32_t)(atof(timestamp.monotonic) * 10000);
+ DLT_LOG_TS(journalContext, loglevel, ts,
+ DLT_STRING(timestamp.real),
+ DLT_STRING(buffer_process),
+ DLT_STRING(buffer_priority),
+ DLT_STRING(buffer_message)
+ );
+ }
}
else {
r = sd_journal_wait(j, 1000000);
diff --git a/src/system/dlt-system-options.c b/src/system/dlt-system-options.c
index 667db9c..5fa31cb 100644
--- a/src/system/dlt-system-options.c
+++ b/src/system/dlt-system-options.c
@@ -148,6 +148,7 @@ void init_configuration(DltSystemConfiguration *config)
config->Journal.CurrentBoot = 1;
config->Journal.Follow = 0;
config->Journal.MapLogLevels = 1;
+ config->Journal.UseOriginalTimestamp = 1;
/* File transfer */
config->Filetransfer.Enable = 0;
@@ -289,6 +290,10 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name)
{
config->Journal.MapLogLevels = atoi(value);
}
+ else if (strcmp(token, "JournalUseOriginalTimestamp") == 0)
+ {
+ config->Journal.UseOriginalTimestamp = atoi(value);
+ }
/* File transfer */
else if (strcmp(token, "FiletransferEnable") == 0)
diff --git a/src/system/dlt-system.conf b/src/system/dlt-system.conf
index b3677f9..4010b70 100644
--- a/src/system/dlt-system.conf
+++ b/src/system/dlt-system.conf
@@ -74,6 +74,9 @@ JournalFollow = 0
# 7 Debug DLT_LOG_DEBUG
JournalMapLogLevels = 1
+# Use the original timestamp (uptime when the event actually occured) as DLT timestamp (Default: 1)
+JournalUseOriginalTimestamp = 1
+
########################################################################
# Filetransfer Manager
########################################################################
diff --git a/src/system/dlt-system.h b/src/system/dlt-system.h
index ed2b50b..46738b8 100644
--- a/src/system/dlt-system.h
+++ b/src/system/dlt-system.h
@@ -107,6 +107,7 @@ typedef struct {
int CurrentBoot;
int Follow;
int MapLogLevels;
+ int UseOriginalTimestamp;
} JournalOptions;
typedef struct {
diff --git a/src/tests/dlt-test-user.c b/src/tests/dlt-test-user.c
index bc4012e..cd6224f 100644
--- a/src/tests/dlt-test-user.c
+++ b/src/tests/dlt-test-user.c
@@ -74,7 +74,9 @@
#include "dlt.h"
-#define DLT_TEST_NUM_CONTEXT 9
+#define DLT_TEST_NUM_CONTEXT 10
+
+#define DLT_MAX_TIMESTAMP 0xFFFFFFFF
/* LogLevel string representation */
static const char *loglevelstr[DLT_LOG_MAX] = {
@@ -99,6 +101,7 @@ int test6m(void);
int test7m(void);
int test8m(void);
int test9m(void);
+int test10m(void);
/* for function interface */
int test1f(void);
@@ -110,6 +113,7 @@ int test6f(void);
int test7f(void);
int test8f(void);
int test9f(void);
+int test10f(void);
/* Declaration of callback functions */
int test_injection_macro_callback(uint32_t service_id, void *data, uint32_t length);
@@ -154,6 +158,7 @@ void usage()
printf(" 7m: (Macro IF) Test network trace\n");
printf(" 8m: (Macro IF) Test truncated network trace\n");
printf(" 9m: (Macro IF) Test segmented network trace\n");
+ printf(" 10m: (Macro IF) Test user-specified timestamps\n");
printf(" 1f: (Function IF) Test all log levels\n");
printf(" 2f: (Function IF) Test all variable types (verbose) \n");
printf(" 3f: (Function IF) Test all variable types (non-verbose) \n");
@@ -163,6 +168,7 @@ void usage()
printf(" 7f: (Function IF) Test network trace\n");
printf(" 8f: (Function IF) Test truncated network trace\n");
printf(" 9f: (Function IF) Test segmented network trace\n");
+ printf(" 10f: (Function IF) Test user-specified timestamps\n");
}
/**
@@ -177,7 +183,7 @@ int main(int argc, char *argv[])
int c;
int i;
- char ctid[4], ctdesc[255];
+ char ctid[5], ctdesc[255];
int num, maxnum;
@@ -243,7 +249,7 @@ int main(int argc, char *argv[])
DLT_REGISTER_CONTEXT(context_macro_callback, "CBM", "Callback Test context for macro interface");
for (i = 0; i < DLT_TEST_NUM_CONTEXT; i++) {
- snprintf(ctid, 4, "TM%d", i + 1);
+ snprintf(ctid, 5, "TM%02d", i + 1);
snprintf(ctdesc, 255, "Test %d context for macro interface", i + 1);
DLT_REGISTER_CONTEXT(context_macro_test[i], ctid, ctdesc);
}
@@ -252,7 +258,7 @@ int main(int argc, char *argv[])
dlt_register_context(&context_function_callback, "CBF", "Callback Test context for function interface");
for (i = 0; i < DLT_TEST_NUM_CONTEXT; i++) {
- snprintf(ctid, 4, "TF%d", i + 1);
+ snprintf(ctid, 5, "TF%02d", i + 1);
snprintf(ctdesc, 255, "Test %d context for function interface", i + 1);
dlt_register_context(&(context_function_test[i]), ctid, ctdesc);
}
@@ -292,6 +298,7 @@ int main(int argc, char *argv[])
test7m();
test8m();
test9m();
+ test10m();
/* with function interface */
test1f();
@@ -303,6 +310,7 @@ int main(int argc, char *argv[])
test7f();
test8f();
test9f();
+ test10f();
/* wait 1 second before next repeat of tests */
sleep(1);
@@ -643,6 +651,34 @@ int test9m(void)
return 0;
}
+int test10m(void)
+{
+ unsigned long timestamp[] = { 0, 100000, DLT_MAX_TIMESTAMP };
+ /* Test 10: test minimum, regular and maximum timestamp for both verbose and non verbose mode*/
+
+ printf("Test10m: (Macro IF) Test user-supplied time stamps\n");
+ DLT_LOG_STRING(context_info, DLT_LOG_INFO, "Test10: (Macro IF) Test user-supplied timestamps");
+
+ for (int i = 0; i < 3; i++) {
+ char s[12];
+ snprintf(s, 12, "%d.%04d", (int)(timestamp[i] / 10000), (int)(timestamp[i] % 10000));
+
+ DLT_VERBOSE_MODE();
+ DLT_LOG_TS(context_macro_test[9], DLT_LOG_INFO, timestamp[i], DLT_STRING("Tested Timestamp:"), DLT_STRING(s));
+
+ DLT_NONVERBOSE_MODE();
+ DLT_LOG_ID_TS(context_macro_test[9], DLT_LOG_INFO, 16, timestamp[i], DLT_STRING(s));
+ }
+
+ DLT_VERBOSE_MODE();
+
+ /* wait 2 second before next test */
+ sleep(2);
+ DLT_LOG(context_info, DLT_LOG_INFO, DLT_STRING("Test10: (Macro IF) finished"));
+
+ return 0;
+}
+
int test1f(void)
{
/* Test 1: (Function IF) Test all log levels */
@@ -1180,6 +1216,48 @@ int test9f(void)
return 0;
}
+int test10f(void)
+{
+ unsigned long timestamp[] = { 0, 100000, DLT_MAX_TIMESTAMP };
+ /* Test 10: test minimum, regular and maximum timestamp for both verbose and non verbose mode*/
+
+ printf("Test10f: (Function IF) Test user-supplied timestamps\n");
+ if (dlt_user_log_write_start(&context_info, &context_data, DLT_LOG_INFO) > 0) {
+ dlt_user_log_write_string(&context_data, "Test10: (Function IF) Test user-supplied time stamps");
+ dlt_user_log_write_finish(&context_data);
+ }
+
+ for (int i = 0; i < 3; i++) {
+ char s[12];
+ snprintf(s, 12, "%d.%04d", (int)(timestamp[i] / 10000), (int)(timestamp[i] % 10000));
+
+ dlt_verbose_mode();
+ if (dlt_user_log_write_start(&context_function_test[9], &context_data, DLT_LOG_INFO) > 0) {
+ context_data.use_timestamp = DLT_USER_TIMESTAMP;
+ context_data.user_timestamp = (uint32_t) timestamp[i];
+ dlt_user_log_write_string(&context_data, "Tested Timestamp:");
+ dlt_user_log_write_string(&context_data, s);
+ dlt_user_log_write_finish(&context_data);
+ }
+
+ dlt_nonverbose_mode();
+ if (dlt_user_log_write_start_id(&(context_function_test[9]), &context_data, DLT_LOG_INFO, 16) > 0) {
+ context_data.use_timestamp = DLT_USER_TIMESTAMP;
+ context_data.user_timestamp = (uint32_t) timestamp[i];
+ dlt_user_log_write_string(&context_data, s);
+ dlt_user_log_write_finish(&context_data);
+ }
+ }
+
+ dlt_verbose_mode();
+
+ /* wait 2 second before next test */
+ sleep(2);
+ DLT_LOG(context_info, DLT_LOG_INFO, DLT_STRING("Test10: (Macro IF) finished"));
+
+ return 0;
+}
+
int test_injection_macro_callback(uint32_t service_id, void *data, uint32_t length)
{
char text[1024];