Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2019-04-09 10:37:15 -0400
committerHenrik Rentz-Reichert2019-06-07 05:23:37 -0400
commit209b20087c67f90cc513a4ae1935de81dc90dc8e (patch)
treec0a72a5171eac6cdf15a2e2f6978270d3004530d
parent8fea4bc9cc0c8220ee6d2de18dbceac669551a17 (diff)
downloadorg.eclipse.etrice-209b20087c67f90cc513a4ae1935de81dc90dc8e.tar.gz
org.eclipse.etrice-209b20087c67f90cc513a4ae1935de81dc90dc8e.tar.xz
org.eclipse.etrice-209b20087c67f90cc513a4ae1935de81dc90dc8e.zip
Bug 546346: logger interface shall be separated from concrete output
* new sender interface for sending buffers * simple and flexible logger based on this sender Change-Id: I4ebb31662d7b44a80f7bd0a7e2d95da7d8fbc84c
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c2
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_VariableSize.c2
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etBufferSender.h45
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etConsoleLogger.c54
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etConsoleLogger.h42
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etLogger.c150
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etLogger.h87
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.c18
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/runtime/etRuntime.c24
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/src/runtime/RunCRuntimeTestcases.c2
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtConsoleLogger.c48
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtConsoleLogger.h23
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMemory.c23
13 files changed, 492 insertions, 28 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c
index 724059bac..205b1ba84 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c
@@ -202,7 +202,7 @@ etMemory* etMemory_FreeList_init(void* heap, etUInt32 size, etUInt16 nslots) {
etUInt32 actual_size = size - data_size;
etMemory* result = NULL;
- if (heap!=NULL & size > data_size) {
+ if (heap!=NULL && size > data_size) {
result = &self->base;
etMemory_init(result, actual_size, etMemory_FreeList_alloc, etMemory_FreeList_free);
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_VariableSize.c b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_VariableSize.c
index dba017d79..889e0f1de 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_VariableSize.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_VariableSize.c
@@ -76,7 +76,7 @@ etMemory* etMemory_VariableSize_init(void* heap, etUInt32 size) {
ET_MSC_LOGGER_SYNC_ENTRY("etMemory", "init")
- if (heap!=NULL & size > data_size) {
+ if (heap!=NULL && size > data_size) {
result = &self->base;
etMemory_init(result, actual_size, etMemory_VariableSize_alloc, etMemory_VariableSize_free);
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etBufferSender.h b/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etBufferSender.h
new file mode 100644
index 000000000..cb4fd5f95
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etBufferSender.h
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2019 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+/**
+ * \file etSender.h
+ *
+ * an interface for sending a buffer contents
+ *
+ * \author: hrentzreichert
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _ETBUFFERSENDER_H_
+#define _ETBUFFERSENDER_H_
+
+#include <stddef.h>
+#include "etDatatypes.h"
+
+struct etBufferSender;
+
+typedef void* etBufferSender_getBuffer(struct etBufferSender* self, size_t size);
+typedef void etBufferSender_sendBuffer(struct etBufferSender* self, void* buffer, size_t size);
+
+typedef struct etBufferSender {
+ etBufferSender_getBuffer* getBuffer;
+ etBufferSender_sendBuffer* sendBuffer;
+}
+etBufferSender;
+
+#endif /* _ETBUFFERSENDER_H_ */
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etConsoleLogger.c b/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etConsoleLogger.c
new file mode 100644
index 000000000..87d173e99
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etConsoleLogger.c
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2019 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+#include <stdio.h>
+#include "debugging/etConsoleLogger.h"
+
+#define BUFFER_SIZE 1024
+static char buffer[BUFFER_SIZE];
+
+etLogger theConsoleLogger;
+static etBufferSender theConsoleSender;
+
+/*
+ * console sender with fixed buffer (may need synchronization)
+ */
+
+static void* etConsoleSender_getBuffer(etBufferSender* self, size_t size) {
+ if (size<BUFFER_SIZE) {
+ return buffer;
+ }
+ else {
+ return NULL;
+ }
+}
+
+void etConsoleSender_sendBuffer(etBufferSender* self, void* buffer, size_t size) {
+ fprintf(stdout, buffer);
+ fflush(stdout);
+}
+
+
+void etConsoleLogger_init() {
+ static etBool initialized = ET_FALSE;
+ if (!initialized) {
+ initialized = ET_TRUE;
+
+ theConsoleSender.getBuffer = etConsoleSender_getBuffer;
+ theConsoleSender.sendBuffer = etConsoleSender_sendBuffer;
+
+ etLogger_init(&theConsoleLogger, &theConsoleSender);
+
+ etLogger_setAppendNewline(&theConsoleLogger, ET_TRUE);
+ etLogger_setUsePrefix(&theConsoleLogger, ET_TRUE);
+ }
+}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etConsoleLogger.h b/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etConsoleLogger.h
new file mode 100644
index 000000000..f7aec5e74
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etConsoleLogger.h
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2019 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+/**
+ * \file etConsoleLogger.h
+ *
+ * an interface for writing a buffer contents to stdout. This implementation is a singleton.
+ *
+ * \author: hrentzreichert
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _ETCONSOLELOGGER_H_
+#define _ETCONSOLELOGGER_H_
+
+#include <debugging/etBufferSender.h>
+#include "etLogger.h"
+
+extern etLogger theConsoleLogger;
+
+/**
+ * initializes the console logger. This function may be called several times but initializes only once.
+ * If used in a multi-threaded environment, synchronization is needed (supply a lock).
+ */
+void etConsoleLogger_init();
+
+#endif /* _ETCONSOLELOGGER_H_ */
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etLogger.c b/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etLogger.c
new file mode 100644
index 000000000..bb3f5030f
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etLogger.c
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+#include "debugging/etLogger.h"
+#include "osal/etTime.h"
+
+#include <stdarg.h>
+
+static char* prefixes[] = {
+ "E: ",
+ "W: ",
+ "I: "
+ };
+
+static const char* TIMESTAMP_FORMAT = "#%011d.%09d# ";
+static const int TIMESTAMP_LENGTH = 24;
+
+static const int PREFIX_LEN = 3;
+static const int N_PREFIXES = sizeof(prefixes)/sizeof(*prefixes);
+
+#define DO_LOCK \
+ if (self->lock!=NULL) { \
+ self->lock->lockFct(self->lock->lockData); \
+ }
+
+#define DO_UNLOCK \
+ if (self->lock!=NULL) { \
+ self->lock->unlockFct(self->lock->lockData); \
+ }
+
+void etLogger_init(etLogger* logger, etBufferSender* sender) {
+ logger->sender = sender;
+ logger->lock = NULL;
+ logger->nDropped = 0;
+ logger->logLevel = LOG_ERROR;
+ logger->usePrefix = ET_TRUE;
+ logger->appendNewline = ET_FALSE;
+ logger->useTimestamp = ET_FALSE;
+}
+
+void etLogger_setAppendNewline(etLogger* logger, etBool appendNewline) {
+ logger->appendNewline = appendNewline;
+}
+
+void etLogger_setUsePrefix(etLogger* logger, etBool usePrefix) {
+ logger->usePrefix = usePrefix;
+}
+
+void etLogger_setUseTimestamp(etLogger* logger, etBool useTimestamp) {
+ logger->useTimestamp = useTimestamp;
+}
+
+void etLogger_log(etLogger* self, LogSeverity severity, const char* msg) {
+ if (severity <= self->logLevel) {
+ DO_LOCK
+ {
+ size_t msgLen = strlen(msg);
+ size_t size = msgLen
+ + (self->appendNewline ? 1:0)
+ + (self->useTimestamp ? TIMESTAMP_LENGTH : 0)
+ + (self->usePrefix ? PREFIX_LEN:0) + 1;
+ void* buffer = self->sender->getBuffer(self->sender, size);
+ char* pos = (char*) buffer;
+
+ if (buffer!=NULL) {
+
+ if (severity<0) {
+ severity = 0;
+ }
+ else if (severity>=N_PREFIXES) {
+ severity = N_PREFIXES-1;
+ }
+
+ if (self->useTimestamp) {
+ etTime time;
+ getTimeFromTarget(&time);
+ pos += sprintf(pos, TIMESTAMP_FORMAT, time.sec, time.nSec);
+ }
+ if (self->usePrefix) {
+ strcpy(pos, prefixes[severity]);
+ pos += PREFIX_LEN;
+ }
+ strcpy(pos, msg);
+ if (self->appendNewline) {
+ pos += msgLen;
+ strcpy(pos, "\n");
+ }
+
+ self->sender->sendBuffer(self->sender, buffer, size);
+ }
+ else {
+ ++self->nDropped;
+ }
+ }
+ DO_UNLOCK
+ }
+}
+
+void etLogger_logF(etLogger* self, LogSeverity severity, const char* format, ... ) {
+ if (severity <= self->logLevel) {
+ DO_LOCK
+ {
+ va_list arglist;
+ va_start(arglist, format);
+ {
+ int msgLen = vsnprintf(NULL, 0, format, arglist);
+ size_t size = msgLen
+ + (self->appendNewline ? 1:0)
+ + (self->useTimestamp ? TIMESTAMP_LENGTH : 0)
+ + (self->usePrefix ? PREFIX_LEN:0) + 1;
+ void* buffer = self->sender->getBuffer(self->sender, size);
+ char* pos = (char*) buffer;
+
+ if (severity<0) {
+ severity = 0;
+ }
+ else if (severity>=N_PREFIXES) {
+ severity = N_PREFIXES-1;
+ }
+
+ if (self->useTimestamp) {
+ etTime time;
+ getTimeFromTarget(&time);
+ pos += sprintf(pos, TIMESTAMP_FORMAT, time.sec, time.nSec);
+ }
+ if (self->usePrefix) {
+ strcpy(pos, prefixes[severity]);
+ pos += PREFIX_LEN;
+ }
+ pos += vsnprintf(pos, size, format, arglist);
+ if (self->appendNewline) {
+ strcpy(pos, "\n");
+ }
+
+ self->sender->sendBuffer(self->sender, buffer, size);
+ }
+ va_end(arglist);
+ }
+ DO_UNLOCK
+ }
+}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etLogger.h b/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etLogger.h
index a4bb8c0c2..a95cce0fb 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etLogger.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etLogger.h
@@ -95,6 +95,93 @@ void etLogger_logInfoF(const char* format, ... );
*/
void etLogger_fprintf(etFileHandle file, const char* format, ... );
+/***************************************************************************************************/
+/*
+ * new interface
+ */
+/***************************************************************************************************/
+
+#include <debugging/etBufferSender.h>
+#include "osal/etLock.h"
+
+typedef enum LogSeverity {
+ LOG_ERROR,
+ LOG_WARNING,
+ LOG_INFO
+}
+LogSeverity;
+
+typedef struct etLogger {
+ etBufferSender* sender; /**< the configured sender */
+ etLock* lock; /**< an optional lock for synchronization */
+ uint16 nDropped; /**< number of unsent messages */
+ LogSeverity logLevel; /**< filter away messages with larger level, default is LOG_ERROR */
+ etBool appendNewline; /**< append a new line character to each message, default is false */
+ etBool usePrefix; /**< prefix each message with the severity, default is true */
+ etBool useTimestamp; /**< prefix each message with a timestamp, default is false */
+}
+etLogger;
+
+/**
+ * initializes the logger object with default values
+ *
+ * \param logger the logger object
+ * \param the sender to be used
+ */
+void etLogger_init(etLogger* logger, etBufferSender* sender);
+
+/**
+ * sets the value of the appendNewline flag
+ *
+ * \param logger the logger object
+ * \param appendNewline the flag
+ */
+void etLogger_setAppendNewline(etLogger* logger, etBool appendNewline);
+
+/**
+ * sets the value of the usePrefix flag
+ *
+ * \param logger the logger object
+ * \param usePrefix the flag
+ */
+void etLogger_setUsePrefix(etLogger* logger, etBool usePrefix);
+
+/**
+ * sets the value of the useTimestamp flag
+ *
+ * \param logger the logger object
+ * \param useTimestamp the flag
+ */
+void etLogger_setUseTimestamp(etLogger* logger, etBool useTimestamp);
+
+/**
+ * supply optional user lock/unlock functions for usage in a multi-threaded environment.
+ *
+ * \param mem pointer to the memory management struct
+ * \lock pointer to a user supplied locking struct
+ */
+void etLogger_setUserLock(etLogger* logger, etLock* lock);
+
+/**
+ * logs a message with a given severity level
+ *
+ * \param self the logger
+ * \param severity the severity level
+ * \param msg the message string
+ */
+void etLogger_log(etLogger* self, LogSeverity severity, const char* msg);
+
+/**
+ * logs a formatted message (like the printf family) with a given severity level
+ *
+ * \param self the logger
+ * \param severity the severity level
+ * \param format the format string
+ * \param ... parameters for the fields
+ */
+void etLogger_logF(etLogger* self, LogSeverity severity, const char* format, ... );
+
+
#endif /* _ETLOGGER_H_ */
#ifdef __cplusplus
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.c b/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.c
index e8ee2e176..b00ab0935 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.c
@@ -252,9 +252,9 @@ void expect_equal_void_ptr(etInt16 id, const char* message, const void* expected
if (expected != actual) {
char testresult[ETUNIT_FAILURE_TEXT_LEN];
char exp[16], act[16];
- snprintf(testresult, sizeof(testresult), "%s: expected=%ld, actual=%ld", message, (etUInt32) expected, (etUInt32) actual);
- sprintf(exp, "%ld", (etUInt32) expected);
- sprintf(act, "%ld", (etUInt32) actual);
+ snprintf(testresult, sizeof(testresult), "%s: expected=%p, actual=%p", message, expected, actual);
+ sprintf(exp, "%p", expected);
+ sprintf(act, "%p", actual);
etUnit_handleExpect(id, ET_FALSE, testresult, exp, act, file, line);
} else {
etUnit_handleExpect(id, ET_TRUE, "", NULL, NULL, file, line);
@@ -348,9 +348,9 @@ static void expect_equal_int(etInt16 id, const char* message, etInt32 expected,
if (expected != actual) {
char testresult[ETUNIT_FAILURE_TEXT_LEN];
char exp[16], act[16];
- snprintf(testresult, sizeof(testresult), "%s: expected=%ld, actual=%ld", message, expected, actual);
- sprintf(exp, "%ld", expected);
- sprintf(act, "%ld", actual);
+ snprintf(testresult, sizeof(testresult), "%s: expected=%d, actual=%d", message, expected, actual);
+ sprintf(exp, "%d", expected);
+ sprintf(act, "%d", actual);
etUnit_handleExpect(id, ET_FALSE, testresult, exp, act, file, line);
} else {
etUnit_handleExpect(id, ET_TRUE, "", NULL, NULL, file, line);
@@ -381,9 +381,9 @@ static void expect_equal_uint(etInt16 id, const char* message, etUInt32 expected
if (expected != actual) {
char testresult[ETUNIT_FAILURE_TEXT_LEN];
char exp[16], act[16];
- snprintf(testresult, sizeof(testresult), "%s: expected=%lu, actual=%lu", message, expected, actual);
- sprintf(exp, "%lu", expected);
- sprintf(act, "%lu", actual);
+ snprintf(testresult, sizeof(testresult), "%s: expected=%u, actual=%u", message, expected, actual);
+ sprintf(exp, "%u", expected);
+ sprintf(act, "%u", actual);
etUnit_handleExpect(id, ET_FALSE, testresult, exp, act, file, line);
} else {
etUnit_handleExpect(id, ET_TRUE, "", NULL, NULL, file, line);
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/runtime/etRuntime.c b/runtime/org.eclipse.etrice.runtime.c/src/common/runtime/etRuntime.c
index 7b1ac14fe..7ef3c23c8 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/runtime/etRuntime.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/runtime/etRuntime.c
@@ -50,7 +50,7 @@ int etRuntime_getMessageServiceCount() {
etRuntime_initInternal();
{
etMessageService* p = etRuntime_msgsvc_head;
- while (p!=null) {
+ while (p!=NULL) {
++count;
p = p->next;
}
@@ -67,7 +67,7 @@ int etRuntime_getMessageServiceByName(const char* name) {
{
etMessageService* p = etRuntime_msgsvc_head;
int idx = 0;
- while (p!=null) {
+ while (p!=NULL) {
if (strcmp(p->name, name)==0) {
ET_MSC_LOGGER_SYNC_EXIT
return idx;
@@ -88,7 +88,7 @@ const etMessageServiceStatistics* etRuntime_getMessageServiceStatistics(unsigned
{
etMessageService* p = etRuntime_msgsvc_head;
int count = 0;
- while (p!=null) {
+ while (p!=NULL) {
if (count==i) {
ET_MSC_LOGGER_SYNC_EXIT
return &p->statistics;
@@ -109,7 +109,7 @@ const char* etRuntime_getMessageServiceName(unsigned int i) {
{
etMessageService* p = etRuntime_msgsvc_head;
int count = 0;
- while (p!=null) {
+ while (p!=NULL) {
if (count==i) {
ET_MSC_LOGGER_SYNC_EXIT
return p->name;
@@ -129,7 +129,7 @@ void etRuntime_resetAllMessageServiceStatistics() {
{
etMessageService* p = etRuntime_msgsvc_head;
- while (p!=null) {
+ while (p!=NULL) {
p->resetStatistics = ET_TRUE;
p = p->next;
}
@@ -162,7 +162,7 @@ void etRuntime_unregisterMessageService(etMessageService* msgService) {
{
etMessageService* p = etRuntime_msgsvc_head;
etMessageService* last = NULL;
- while (p!=null) {
+ while (p!=NULL) {
if (p==msgService) {
if (last==NULL) {
/* remove the first one */
@@ -205,7 +205,7 @@ void etRuntime_unregisterMemoryManagement(etMemory* mem) {
{
etMemory* p = etRuntime_memmgmt_head;
etMemory* last = NULL;
- while (p!=null) {
+ while (p!=NULL) {
if (p==mem) {
if (last==NULL) {
/* remove the first one */
@@ -231,7 +231,7 @@ int etRuntime_getMemoryManagementCount() {
{
etMemory* p = etRuntime_memmgmt_head;
- while (p!=null) {
+ while (p!=NULL) {
++count;
p = p->next;
}
@@ -248,7 +248,7 @@ int etRuntime_getMemoryManagementByName(const char* name) {
{
etMemory* p = etRuntime_memmgmt_head;
int idx = 0;
- while (p!=null) {
+ while (p!=NULL) {
if (strcmp(p->name, name)==0) {
ET_MSC_LOGGER_SYNC_EXIT
return idx;
@@ -269,7 +269,7 @@ const etMemoryStatistics* etRuntime_getMemoryManagementStatistics(unsigned int i
{
etMemory* p = etRuntime_memmgmt_head;
int count = 0;
- while (p!=null) {
+ while (p!=NULL) {
if (count==i) {
ET_MSC_LOGGER_SYNC_EXIT
return &p->statistics;
@@ -290,7 +290,7 @@ const char* etRuntime_getMemoryManagementName(unsigned int i) {
{
etMemory* p = etRuntime_memmgmt_head;
int count = 0;
- while (p!=null) {
+ while (p!=NULL) {
if (count==i) {
ET_MSC_LOGGER_SYNC_EXIT
return p->name;
@@ -310,7 +310,7 @@ void etRuntime_resetAllMemoryManagementStatistics() {
{
etMemory* p = etRuntime_memmgmt_head;
- while (p!=null) {
+ while (p!=NULL) {
etMemory_resetStatistics(p);
p = p->next;
}
diff --git a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/RunCRuntimeTestcases.c b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/RunCRuntimeTestcases.c
index 40be33446..31594f3ff 100644
--- a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/RunCRuntimeTestcases.c
+++ b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/RunCRuntimeTestcases.c
@@ -29,6 +29,7 @@
#include "TestEtQueue.h"
#include "TestEtTimer.h"
#include "TestEtDatatypes.h"
+#include "TestEtConsoleLogger.h"
#include "helpers/TestEtTimeHelpers.h"
#include "util/TestUtil.h"
@@ -53,6 +54,7 @@ void RunCRuntimeTestcases(void){
TestEtDatatypes_runSuite();
TestEtTimeHelpers_runSuite();
TestUtil_runSuite();
+ TestEtConsoleLogger_runSuite();
TestEtStaticDeque_runSuite();
diff --git a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtConsoleLogger.c b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtConsoleLogger.c
new file mode 100644
index 000000000..5cf0f9c04
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtConsoleLogger.c
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2019 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+
+/*
+ * TestEtConsoleLogger.c
+ */
+
+#include "TestEtConsoleLogger.h"
+#include "debugging/etConsoleLogger.h"
+#include "etUnit/etUnit.h"
+
+static void TestEtUnit_useConsoleLogging(etInt16 id) {
+ etConsoleLogger_init();
+
+ /* will be dropped because of log level ERROR by default */
+ etLogger_log(&theConsoleLogger, LOG_WARNING, "first message for testing (WARNING)");
+
+ theConsoleLogger.logLevel = LOG_WARNING;
+ etLogger_log(&theConsoleLogger, LOG_WARNING, "first message for testing (WARNING)");
+ etLogger_logF(&theConsoleLogger, LOG_ERROR, "%d. message for testing (ERROR)", 2);
+}
+
+static void TestEtUnit_useConsoleLoggingWithTimestamp(etInt16 id) {
+ etConsoleLogger_init();
+
+ etLogger_setUseTimestamp(&theConsoleLogger, ET_TRUE);
+
+ etLogger_logF(&theConsoleLogger, LOG_ERROR, "%d. message for testing (ERROR with timestamp)", 3);
+}
+
+void TestEtConsoleLogger_runSuite(void){
+ etUnit_openTestSuite("org.eclipse.etrice.runtime.c.tests.TestEtConsoleLogger");
+ ADD_TESTCASE(TestEtUnit_useConsoleLogging);
+ ADD_TESTCASE(TestEtUnit_useConsoleLoggingWithTimestamp);
+ etUnit_closeTestSuite();
+}
+
+
diff --git a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtConsoleLogger.h b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtConsoleLogger.h
new file mode 100644
index 000000000..641450f72
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtConsoleLogger.h
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2019 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+
+/*
+ * TestEtConsoleLogger.h
+ */
+
+#ifndef _TESTETCONSOLELOGGER_H_
+#define _TESTETCONSOLELOGGER_H_
+
+void TestEtConsoleLogger_runSuite(void);
+
+#endif /* _TESTETCONSOLELOGGER_H_ */
diff --git a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMemory.c b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMemory.c
index ee60fbc8a..2dfecd216 100644
--- a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMemory.c
+++ b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMemory.c
@@ -18,6 +18,7 @@
#include "base/etMemory_VariableSize.h"
#include "base/etMemory_FixedSize.h"
#include "base/etMemory_FreeList.h"
+#include "runtime/etRuntime.h"
#define KBYTE 1024
#define BUF_SIZE (256*KBYTE)
@@ -213,7 +214,7 @@ static void TestEtMemory_testFreeListOverflow(etInt16 id) {
}
static void TestEtMemory_testStatistics(etInt16 id) {
- etMemoryStatistics* stat;
+ const etMemoryStatistics* stat;
int n;
EXPECT_EQUAL_INT32(id, "tests created some memory managements", 4, etRuntime_getMemoryManagementCount());
@@ -231,7 +232,11 @@ static void TestEtMemory_testStatistics(etInt16 id) {
EXPECT_TRUE(id, "stat!=NULL", stat!=NULL);
printf("checking memory management %d, %s, max %d, fail %d\n", n, etRuntime_getMemoryManagementName(n), stat->maxUsed, stat->nFailingRequests);
fflush(stdout);
- EXPECT_EQUAL_INT32(id, "maxUsed", 261784, stat->maxUsed);
+ /*
+ * the computation is too architecture dependent, we have a detailed check in TestEtMemory_testFreeList
+ *
+ * EXPECT_EQUAL_INT32(id, "maxUsed", 261784, stat->maxUsed);
+ */
EXPECT_EQUAL_INT32(id, "nFailingRequests", 0, stat->nFailingRequests);
n = 2;
@@ -239,7 +244,11 @@ static void TestEtMemory_testStatistics(etInt16 id) {
EXPECT_TRUE(id, "stat!=NULL", stat!=NULL);
printf("checking memory management %d, %s, max %d, fail %d\n", n, etRuntime_getMemoryManagementName(n), stat->maxUsed, stat->nFailingRequests);
fflush(stdout);
- EXPECT_EQUAL_INT32(id, "maxUsed", 131144, stat->maxUsed);
+ /*
+ * the computation is too architecture dependent, we have a detailed check in TestEtMemory_testFixedSize
+ *
+ * EXPECT_EQUAL_INT32(id, "maxUsed", 131144, stat->maxUsed);
+ */
EXPECT_EQUAL_INT32(id, "nFailingRequests", 0, stat->nFailingRequests);
n = 3;
@@ -247,7 +256,11 @@ static void TestEtMemory_testStatistics(etInt16 id) {
EXPECT_TRUE(id, "stat!=NULL", stat!=NULL);
printf("checking memory management %d, %s, max %d, fail %d\n", n, etRuntime_getMemoryManagementName(n), stat->maxUsed, stat->nFailingRequests);
fflush(stdout);
- EXPECT_EQUAL_INT32(id, "maxUsed", 260016, stat->maxUsed);
+ /*
+ * the computation is too architecture dependent, we have a detailed check in TestEtMemory_testVariableSize
+ *
+ * EXPECT_EQUAL_INT32(id, "maxUsed", 260016, stat->maxUsed);
+ */
EXPECT_EQUAL_INT32(id, "nFailingRequests", 1, stat->nFailingRequests);
}
@@ -257,7 +270,7 @@ void TestEtMemory_runSuite(void){
ADD_TESTCASE(TestEtMemory_testFixedSize);
ADD_TESTCASE(TestEtMemory_testFreeList);
ADD_TESTCASE(TestEtMemory_testFreeListOverflow);
- /*ADD_TESTCASE(TestEtMemory_testStatistics);*/
+ ADD_TESTCASE(TestEtMemory_testStatistics);
etUnit_closeTestSuite();
}

Back to the top