Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/helpers/etTimeHelpers.c47
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/helpers/etTimeHelpers.h45
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c18
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h9
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c3
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/src/runtime/RunCRuntimeTestcases.c122
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMessageService.c506
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/src/runtime/helpers/TestEtTimeHelpers.c65
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/src/runtime/helpers/TestEtTimeHelpers.h19
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/tmp/testlog/TestCRuntime.etu15
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/tmp/testlog/TestEtUnitSpecial.etu4
11 files changed, 489 insertions, 364 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/helpers/etTimeHelpers.c b/runtime/org.eclipse.etrice.runtime.c/src/common/helpers/etTimeHelpers.c
index 1aadc102c..82ada3166 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/helpers/etTimeHelpers.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/helpers/etTimeHelpers.c
@@ -1,25 +1,22 @@
-/*******************************************************************************
- * Copyright (c) 2013 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 "helpers/etTimeHelpers.h"
-
-void etTimeHelpers_subtract(etTime *first, etTime* second){
- /* TODO: implement */
-}
-
-void etTimeHelpers_add(etTime *first, etTime* second){
- /* TODO: implement */
-}
-
-etInt32 etTimeHelpers_convertToMSec(etTime *time){
- return time->sec * 1000 + time->nSec / 1000000;
-}
+/*******************************************************************************
+ * Copyright (c) 2013 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 "helpers/etTimeHelpers.h"
+
+etInt32 etTimeHelpers_convertToMSec(etTime *time){
+ return time->sec * 1000 + time->nSec / 1000000;
+}
+
+void etTimeHelpers_convertToEtTime(etTime *result, etInt32 milliSeconds){
+ result->sec = milliSeconds/1000;
+ result->nSec = milliSeconds%1000 * 1000000;
+}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/helpers/etTimeHelpers.h b/runtime/org.eclipse.etrice.runtime.c/src/common/helpers/etTimeHelpers.h
index 71f20e4ce..c7aa1a49a 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/helpers/etTimeHelpers.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/helpers/etTimeHelpers.h
@@ -1,23 +1,22 @@
-/*******************************************************************************
- * Copyright (c) 2013 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)
- *
- *******************************************************************************/
-
-#ifndef ETTIMEHELPERS_H_
-#define ETTIMEHELPERS_H_
-
-#include "osal/etTime.h"
-
-void etTime_subtract(etTime *self, etTime* subtractValue);
-void etTime_add(etTime *self, etTime* addValue);
-etInt32 etTimeHelpers_convertToMSec(etTime *time);
-
-
-#endif /* ETTIMEHELPERS_H_ */
+/*******************************************************************************
+ * Copyright (c) 2013 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)
+ *
+ *******************************************************************************/
+
+#ifndef _ETTIMEHELPERS_H_
+#define _ETTIMEHELPERS_H_
+
+#include "osal/etTime.h"
+
+etInt32 etTimeHelpers_convertToMSec(etTime *time);
+void etTimeHelpers_convertToEtTime(etTime *result, etInt32 milliSeconds);
+
+
+#endif /* _ETTIMEHELPERS_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c
index b1a5fea54..8c87c853f 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c
@@ -19,6 +19,7 @@ void etMessageQueue_init(etMessageQueue* self){
self->first = NULL;
self->last = NULL;
self->highWaterMark = 0;
+ self->lowWaterMark = 0;
self->size = 0;
ET_MSC_LOGGER_SYNC_EXIT
}
@@ -64,6 +65,9 @@ etMessage* etMessageQueue_pop(etMessageQueue* self){
pop_msg->next=NULL;
self->size--;
+ if (self->size < self->lowWaterMark)
+ self->lowWaterMark--;
+
ET_MSC_LOGGER_SYNC_EXIT
return pop_msg;
}
@@ -93,7 +97,19 @@ etBool etMessageQueue_isNotEmpty(etMessageQueue* self){
}
etInt16 etMessageQueue_getHighWaterMark(etMessageQueue* self) {
- ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "getHightWaterMark")
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "getHighWaterMark")
ET_MSC_LOGGER_SYNC_EXIT
return self->highWaterMark;
}
+
+etInt16 etMessageQueue_getLowWaterMark(etMessageQueue* self) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "getLowWaterMark")
+ ET_MSC_LOGGER_SYNC_EXIT
+ return self->lowWaterMark;
+}
+
+void etMessageQueue_resetLowWaterMark(etMessageQueue* self) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "resetLowWaterMark")
+ self->lowWaterMark = self->size;
+ ET_MSC_LOGGER_SYNC_EXIT
+}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h
index f305d1aa9..a9a6cb13e 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h
@@ -20,6 +20,7 @@ typedef struct etMessageQueue {
etMessage* first;
etMessage* last;
etInt16 highWaterMark;
+ etInt16 lowWaterMark;
etInt16 size;
} etMessageQueue;
@@ -27,19 +28,17 @@ typedef struct etMessageQueue {
void etMessageQueue_init(etMessageQueue* self);
void etMessageQueue_push(etMessageQueue* self, etMessage* msg);
-
etMessage* etMessageQueue_pop(etMessageQueue* self);
etMessage* etMessageQueue_getFirst(etMessageQueue* self);
-
etMessage* etMessageQueue_getLast(etMessageQueue* self);
etBool etMessageQueue_isNotEmpty(etMessageQueue* self);
-etInt16 etMessageQueue_getHighWaterMark(etMessageQueue* self);
-
etInt16 etMessageQueue_getSize(etMessageQueue* self);
-
+etInt16 etMessageQueue_getHighWaterMark(etMessageQueue* self);
+etInt16 etMessageQueue_getLowWaterMark(etMessageQueue* self);
+void etMessageQueue_resetLowWaterMark(etMessageQueue* self);
#endif /* _RMESSAGEQUEUE_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c
index 4f70b98e2..9e66c95fd 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c
@@ -111,6 +111,7 @@ void etMessageService_initMessagePool(etMessageService* self){
etMessage* block = (etMessage*) &self->messageBuffer.buffer[i*self->messageBuffer.blockSize];
etMessageQueue_push(&self->messagePool, block);
}
+ etMessageQueue_resetLowWaterMark(&self->messagePool);
ET_MSC_LOGGER_SYNC_EXIT
}
@@ -189,7 +190,7 @@ void etMessageService_execute(etMessageService* self){
etInt16 etMessageService_getMessagePoolLowWaterMark(etMessageService* self){
ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "getMessagePoolLowWaterMark")
- etInt16 lowWaterMark = self->messageBuffer.maxBlocks - etMessageQueue_getHighWaterMark(&self->messageQueue);
+ etInt16 lowWaterMark = etMessageQueue_getLowWaterMark(&self->messagePool);
ET_MSC_LOGGER_SYNC_EXIT
return lowWaterMark;
}
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 1e6c72af9..72b1a5737 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
@@ -1,60 +1,62 @@
-/*******************************************************************************
- * 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)
- *
- *******************************************************************************/
-
-
-/*
- * RunRuntimeTestcases.c
- *
- * Created on: 12.01.2012
- * Author: tschuetz
- */
-
-
-
-#include "RunCRuntimeTestcases.h"
-
-#include "TestEtMessage.h"
-#include "TestEtMessageQueue.h"
-#include "TestEtMessageService.h"
-#include "TestEtUnit.h"
-#include "TestEtMemory.h"
-#include "TestEtQueue.h"
-#include "TestEtTimer.h"
-
-#include "etUnit/etUnit.h"
-#include "debugging/etMSCLogger.h"
-
-
-void RunCRuntimeTestcases(void){
- etInt16 id;
- etMSCLogger_open("tmp/testlog", "test.log");
- etUnit_open("tmp/testlog","TestCRuntime");
-
- TestEtQueue_runSuite();
- TestEtMemory_runSuite();
- TestEtMessage_runSuite();
- TestEtMessageQueue_runSuite();
-// TestEtMessageService_runSuite();
- TestEtUnit_runSuite();
- TestEtTimer_runSuite();
-
- etUnit_close();
-
- /* special situation for testing openAll and closeAll of etUnit
- * this has to be done outside of etUnit_open and etUnit_close */
- id = etUnit_openAll("tmp/testlog","TestEtUnitSpecial", "etUnit", "openAll and closeAll");
- EXPECT_TRUE(id, "Open and Close", TRUE);
- etUnit_closeAll(id);
-
- etMSCLogger_close();
-}
-
+/*******************************************************************************
+ * 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)
+ *
+ *******************************************************************************/
+
+
+/*
+ * RunRuntimeTestcases.c
+ *
+ * Created on: 12.01.2012
+ * Author: tschuetz
+ */
+
+
+
+#include "RunCRuntimeTestcases.h"
+
+#include "TestEtMessage.h"
+#include "TestEtMessageQueue.h"
+#include "TestEtMessageService.h"
+#include "TestEtUnit.h"
+#include "TestEtMemory.h"
+#include "TestEtQueue.h"
+#include "TestEtTimer.h"
+#include "helpers/TestEtTimeHelpers.h"
+
+#include "etUnit/etUnit.h"
+#include "debugging/etMSCLogger.h"
+
+
+void RunCRuntimeTestcases(void){
+ etInt16 id;
+ etMSCLogger_open("tmp/testlog", "test.log");
+ etUnit_open("tmp/testlog","TestCRuntime");
+
+ TestEtQueue_runSuite();
+ TestEtMemory_runSuite();
+ TestEtMessage_runSuite();
+ TestEtMessageQueue_runSuite();
+ TestEtMessageService_runSuite();
+ TestEtUnit_runSuite();
+ TestEtTimer_runSuite();
+ TestEtTimeHelpers_runSuite();
+
+ etUnit_close();
+
+ /* special situation for testing openAll and closeAll of etUnit
+ * this has to be done outside of etUnit_open and etUnit_close */
+ id = etUnit_openAll("tmp/testlog","TestEtUnitSpecial", "etUnit", "openAll and closeAll");
+ EXPECT_TRUE(id, "Open and Close", TRUE);
+ etUnit_closeAll(id);
+
+ etMSCLogger_close();
+}
+
diff --git a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMessageService.c b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMessageService.c
index 201514757..0621d7583 100644
--- a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMessageService.c
+++ b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMessageService.c
@@ -1,245 +1,261 @@
-/*******************************************************************************
- * 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 "TestEtMessageService.h"
-#include "etUnit/etUnit.h"
-#include "messaging/etMessageService.h"
-
-
-/* mocking for MessageDispatcher */
-
-static etInt16 receivedEventIDs[2] = {0,0};
-static etInt16 receivedEventIDCounter = 0;
-
-void MessageReceiver1(const etMessage* msg){
- receivedEventIDs[receivedEventIDCounter] = msg->evtID;
- receivedEventIDCounter++;
-}
-
-void MessageReceiver2(const etMessage* msg){
- receivedEventIDs[receivedEventIDCounter] = msg->evtID;
- receivedEventIDCounter++;
-}
-
-/* dummy message dispatcher */
-void DummyMessageDispatcher(const etMessage* msg){
- switch(msg->address){
- case 11:
- MessageReceiver1(msg);
- break;
- case 22:
- MessageReceiver2(msg);
- break;
- default:
- break;
- }
-}
-
-/* dummy execute dispatcher */
-void DummyExecuteDispatcher(void){
- //nothing to do
-}
-
-void TestEtMessageService_init(etInt16 id){
-
- etMessageService msgService;
- uint16 max = 6;
- uint16 blockSize = 32;
-
- uint8 msgBuffer[max*blockSize];
-
- etMessageService_init(&msgService, msgBuffer, max, blockSize, DummyMessageDispatcher, DummyExecuteDispatcher, EXECMODE_BLOCKED);
-
- EXPECT_EQUAL_PTR(id, "msgService.messagePool.first", msgBuffer, msgService.messagePool.first);
- EXPECT_EQUAL_PTR(id, "msgService.messagePool in between", &msgBuffer[3*blockSize], msgService.messagePool.first->next->next->next);
- EXPECT_EQUAL_PTR(id, "msgService.messagePool.last(1)", &msgBuffer[5*blockSize], msgService.messagePool.first->next->next->next->next->next);
- EXPECT_EQUAL_PTR(id, "msgService.messagePool.last(2)", &msgBuffer[5*blockSize], msgService.messagePool.last);
- EXPECT_EQUAL_PTR(id, "msgService.messagePool.last.next", 0, msgService.messagePool.last->next);
-
-}
-
-void TestEtMessageService_GetPushPopReturn(etInt16 id){
-
- etMessageService msgService;
- uint16 max = 6;
- uint16 blockSize = 32;
- uint8 msgBuffer[max*blockSize];
-
- etMessageService_init(&msgService, msgBuffer, max, blockSize, DummyMessageDispatcher, DummyExecuteDispatcher, EXECMODE_BLOCKED);
-
- // get messages from pool
- etMessage* msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
- etMessage* msg2 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
-
- EXPECT_EQUAL_INT16(id, "msgService.messagePool.size", 4, msgService.messagePool.size);
-
- // define content
- msg1->address = 11;
- msg1->evtID = 111;
- msg2->address = 22;
- msg2->evtID = 222;
-
- // push messages to queue
- etMessageService_pushMessage(&msgService, msg2);
- etMessageService_pushMessage(&msgService, msg1);
-
- EXPECT_EQUAL_INT16(id, "msgService.messageQueue.size", 2, msgService.messageQueue.size);
-
- // pop messages from queue
- etMessage* rcvMsg1 = etMessageService_popMessage(&msgService);
- etMessage* rcvMsg2 = etMessageService_popMessage(&msgService);
-
- EXPECT_EQUAL_INT16(id, "msgService.messageQueue.size",0, msgService.messageQueue.size);
-
-
- EXPECT_EQUAL_INT16(id, "msgService.popMessage", 22, rcvMsg1->address);
- EXPECT_EQUAL_INT16(id, "msgService.popMessage", 222, rcvMsg1->evtID);
- EXPECT_EQUAL_INT16(id, "msgService.popMessage", 11, rcvMsg2->address);
- EXPECT_EQUAL_INT16(id, "msgService.popMessage", 111, rcvMsg2->evtID);
-
- etMessageService_returnMessageBuffer(&msgService, rcvMsg1);
- etMessageService_returnMessageBuffer(&msgService, rcvMsg2);
-
- EXPECT_EQUAL_INT16(id, "msgService.messagePool.size", 6, msgService.messagePool.size);
-}
-
-void TestEtMessageService_GetReturn(etInt16 id){
-
- etMessageService msgService;
- uint16 max = 2;
- uint16 blockSize = 32;
- uint8 msgBuffer[max*blockSize];
-
- etMessageService_init(&msgService, msgBuffer, max, blockSize, DummyMessageDispatcher, DummyExecuteDispatcher, EXECMODE_BLOCKED);
-
- // get one message too much from pool
- etMessage* msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
- etMessage* msg2 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
- etMessage* msg3 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
- EXPECT_TRUE(id, "msgService getMessageBuffer", msg1!=NULL);
- EXPECT_TRUE(id, "msgService getMessageBuffer", msg2!=NULL);
- EXPECT_EQUAL_PTR(id, "msgService getMessageBuffer", msg3, NULL);
-
- // return messages
- etMessageService_returnMessageBuffer(&msgService, msg1);
- etMessageService_returnMessageBuffer(&msgService, msg2);
- EXPECT_EQUAL_INT16(id, "msgService.messagePool.size", 2, msgService.messagePool.size);
-
- // get message bigger than blocksize
- etMessage* msg4 = etMessageService_getMessageBuffer(&msgService, 33);
- EXPECT_EQUAL_PTR(id, "msgService getMessageBuffer", msg4, NULL);
-
-}
-
-void TestEtMessageService_execute(etInt16 id){
- etMessageService msgService;
- uint16 max = 6;
- uint16 blockSize = 32;
- uint8 msgBuffer[max*blockSize];
-
- etMessageService_init(&msgService, msgBuffer, max, blockSize, DummyMessageDispatcher, DummyExecuteDispatcher, EXECMODE_BLOCKED);
-
- // get messages from pool
- etMessage* msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
- etMessage* msg2 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
-
- // define content
- msg1->address = 11;
- msg1->evtID = 111;
- msg2->address = 22;
- msg2->evtID = 222;
-
- // push messages to queue
- etMessageService_pushMessage(&msgService, msg1);
- etMessageService_pushMessage(&msgService, msg2);
-
- /* make sure that receivedEventIDCounter==0 and receivedEventIDs[n]==0*/
- etMessageService_execute(&msgService);
- EXPECT_EQUAL_INT16(id, "deliverAllMessages msg1", msg1->evtID, receivedEventIDs[0]);
- EXPECT_EQUAL_INT16(id, "deliverAllMessages msg2", msg2->evtID, receivedEventIDs[1]);
- EXPECT_EQUAL_INT16(id, "deliverAllMessages receivedEventIDCounter", 2, receivedEventIDCounter);
-}
-
-void TestEtMessageService_getMessagePoolLowWaterMark(etInt16 id){
- etMessageService msgService;
- uint16 max = 6;
- uint16 blockSize = 32;
- uint8 msgBuffer[max*blockSize];
-
- etMessageService_init(&msgService, msgBuffer, max, blockSize, DummyMessageDispatcher, DummyExecuteDispatcher, EXECMODE_BLOCKED);
-
- EXPECT_EQUAL_INT16(id, "inital low water mark", max, etMessageService_getMessagePoolLowWaterMark(&msgService));
-
- // get messages from pool
- etMessage* msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
- etMessage* msg2 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
-
- // define content
- msg1->address = 11;
- msg1->evtID = 111;
- msg2->address = 22;
- msg2->evtID = 222;
-
- // push messages to queue
- etMessageService_pushMessage(&msgService, msg2);
- etMessageService_pushMessage(&msgService, msg1);
-
- EXPECT_EQUAL_INT16(id, "low water mark 1", max-2, etMessageService_getMessagePoolLowWaterMark(&msgService));
-
- // pop messages from queue
- etMessage* rcvMsg1 = etMessageService_popMessage(&msgService);
- etMessage* rcvMsg2 = etMessageService_popMessage(&msgService);
-
- etMessageService_returnMessageBuffer(&msgService, rcvMsg1);
- etMessageService_returnMessageBuffer(&msgService, rcvMsg2);
-
- EXPECT_EQUAL_INT16(id, "low water mark 2", max-2, etMessageService_getMessagePoolLowWaterMark(&msgService));
-
- msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
- msg2 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
- etMessageService_pushMessage(&msgService, msg2);
- etMessageService_pushMessage(&msgService, msg1);
-
- /*still the same*/
- EXPECT_EQUAL_INT16(id, "low water mark 3", max-2, etMessageService_getMessagePoolLowWaterMark(&msgService));
-
- msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
- etMessageService_pushMessage(&msgService, msg2);
- msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
- etMessageService_pushMessage(&msgService, msg2);
- msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
- etMessageService_pushMessage(&msgService, msg2);
- msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
- etMessageService_pushMessage(&msgService, msg2);
-
- /* no message left */
- EXPECT_EQUAL_INT16(id, "low water mark 4", 0, etMessageService_getMessagePoolLowWaterMark(&msgService));
-
- msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
- EXPECT_EQUAL_PTR(id, "check message for NULL", NULL, msg1);
-
- /* still no message left */
- EXPECT_EQUAL_INT16(id, "low water mark 6", 0, etMessageService_getMessagePoolLowWaterMark(&msgService));
-
-
-}
-
-
-void TestEtMessageService_runSuite(void){
- etUnit_openTestSuite("TestEtMessageService");
- ADD_TESTCASE(TestEtMessageService_init);
- ADD_TESTCASE(TestEtMessageService_GetPushPopReturn);
- ADD_TESTCASE(TestEtMessageService_GetReturn);
- ADD_TESTCASE(TestEtMessageService_execute);
- ADD_TESTCASE(TestEtMessageService_getMessagePoolLowWaterMark)
- etUnit_closeTestSuite();
-}
+/*******************************************************************************
+ * 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 "TestEtMessageService.h"
+#include "etUnit/etUnit.h"
+#include "messaging/etMessageService.h"
+
+
+/* mocking for MessageDispatcher */
+
+static etInt16 receivedEventIDs[2] = {0,0};
+static etInt16 receivedEventIDCounter = 0;
+
+void MessageReceiver1(const etMessage* msg){
+ receivedEventIDs[receivedEventIDCounter] = msg->evtID;
+ receivedEventIDCounter++;
+}
+
+void MessageReceiver2(const etMessage* msg){
+ receivedEventIDs[receivedEventIDCounter] = msg->evtID;
+ receivedEventIDCounter++;
+}
+
+/* dummy message dispatcher */
+void DummyMessageDispatcher(const etMessage* msg){
+ switch(msg->address){
+ case 11:
+ MessageReceiver1(msg);
+ break;
+ case 22:
+ MessageReceiver2(msg);
+ break;
+ default:
+ break;
+ }
+}
+
+/* dummy execute dispatcher */
+void DummyExecuteDispatcher(void){
+ //nothing to do
+}
+
+void TestEtMessageService_init(etInt16 id){
+
+ etMessageService msgService;
+ uint16 max = 6;
+ uint16 blockSize = 32;
+
+ uint8 msgBuffer[max*blockSize];
+
+ etMessageService_init(&msgService, msgBuffer, max, blockSize, DummyMessageDispatcher, DummyExecuteDispatcher, EXECMODE_BLOCKED);
+
+ EXPECT_EQUAL_PTR(id, "msgService.messagePool.first", msgBuffer, msgService.messagePool.first);
+ EXPECT_EQUAL_PTR(id, "msgService.messagePool in between", &msgBuffer[3*blockSize], msgService.messagePool.first->next->next->next);
+ EXPECT_EQUAL_PTR(id, "msgService.messagePool.last(1)", &msgBuffer[5*blockSize], msgService.messagePool.first->next->next->next->next->next);
+ EXPECT_EQUAL_PTR(id, "msgService.messagePool.last(2)", &msgBuffer[5*blockSize], msgService.messagePool.last);
+ EXPECT_EQUAL_PTR(id, "msgService.messagePool.last.next", 0, msgService.messagePool.last->next);
+
+ etMessageService_destroy(&msgService);
+}
+
+void TestEtMessageService_GetPushPopReturn(etInt16 id){
+
+ etMessageService msgService;
+ uint16 max = 6;
+ uint16 blockSize = 32;
+ uint8 msgBuffer[max*blockSize];
+
+ etMessageService_init(&msgService, msgBuffer, max, blockSize, DummyMessageDispatcher, DummyExecuteDispatcher, EXECMODE_BLOCKED);
+
+ // get messages from pool
+ etMessage* msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
+ etMessage* msg2 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
+
+ EXPECT_EQUAL_INT16(id, "msgService.messagePool.size", 4, msgService.messagePool.size);
+
+ // define content
+ msg1->address = 11;
+ msg1->evtID = 111;
+ msg2->address = 22;
+ msg2->evtID = 222;
+
+ // push messages to queue
+ etMessageService_pushMessage(&msgService, msg2);
+ etMessageService_pushMessage(&msgService, msg1);
+
+ EXPECT_EQUAL_INT16(id, "msgService.messageQueue.size", 2, msgService.messageQueue.size);
+
+ // pop messages from queue
+ etMessage* rcvMsg1 = etMessageService_popMessage(&msgService);
+ etMessage* rcvMsg2 = etMessageService_popMessage(&msgService);
+
+ EXPECT_EQUAL_INT16(id, "msgService.messageQueue.size",0, msgService.messageQueue.size);
+
+
+ EXPECT_EQUAL_INT16(id, "msgService.popMessage", 22, rcvMsg1->address);
+ EXPECT_EQUAL_INT16(id, "msgService.popMessage", 222, rcvMsg1->evtID);
+ EXPECT_EQUAL_INT16(id, "msgService.popMessage", 11, rcvMsg2->address);
+ EXPECT_EQUAL_INT16(id, "msgService.popMessage", 111, rcvMsg2->evtID);
+
+ etMessageService_returnMessageBuffer(&msgService, rcvMsg1);
+ etMessageService_returnMessageBuffer(&msgService, rcvMsg2);
+
+ EXPECT_EQUAL_INT16(id, "msgService.messagePool.size", 6, msgService.messagePool.size);
+
+ etMessageService_destroy(&msgService);
+}
+
+void TestEtMessageService_GetReturn(etInt16 id){
+
+ etMessageService msgService;
+ uint16 max = 2;
+ uint16 blockSize = 32;
+ uint8 msgBuffer[max*blockSize];
+
+ etMessageService_init(&msgService, msgBuffer, max, blockSize, DummyMessageDispatcher, DummyExecuteDispatcher, EXECMODE_BLOCKED);
+
+ // get one message too much from pool
+ etMessage* msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
+ etMessage* msg2 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
+ etMessage* msg3 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage)); /* this line triggers an error log */
+ EXPECT_TRUE(id, "msgService getMessageBuffer", msg1!=NULL);
+ EXPECT_TRUE(id, "msgService getMessageBuffer", msg2!=NULL);
+ EXPECT_EQUAL_PTR(id, "msgService getMessageBuffer", msg3, NULL);
+
+ // return messages
+ etMessageService_returnMessageBuffer(&msgService, msg1);
+ etMessageService_returnMessageBuffer(&msgService, msg2);
+ EXPECT_EQUAL_INT16(id, "msgService.messagePool.size", 2, msgService.messagePool.size);
+
+ // get message bigger than blocksize
+ etMessage* msg4 = etMessageService_getMessageBuffer(&msgService, 33); /* this line triggers an error log */
+ EXPECT_EQUAL_PTR(id, "msgService getMessageBuffer", msg4, NULL);
+
+ etMessageService_destroy(&msgService);
+}
+
+void TestEtMessageService_execute(etInt16 id){
+ etMessageService msgService;
+ uint16 max = 6;
+ uint16 blockSize = 32;
+ uint8 msgBuffer[max*blockSize];
+
+ etMessageService_init(&msgService, msgBuffer, max, blockSize, DummyMessageDispatcher, DummyExecuteDispatcher, EXECMODE_BLOCKED);
+
+ // get messages from pool
+ etMessage* msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
+ etMessage* msg2 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
+
+ // define content
+ msg1->address = 11;
+ msg1->evtID = 111;
+ msg2->address = 22;
+ msg2->evtID = 222;
+
+ // push messages to queue
+ etMessageService_pushMessage(&msgService, msg1);
+ etMessageService_pushMessage(&msgService, msg2);
+
+
+ msgService.thread.stacksize = 1024;
+ msgService.thread.priority = 1;
+ msgService.thread.threadName = "Thread1";
+ msgService.thread.threadFunction = (etThreadFunction) etMessageService_execute;
+ msgService.thread.threadFunctionData = &msgService;
+
+ etMessageService_start(&msgService);
+ etThread_sleep(100); /* wait 100 ms for the delivery */
+
+ EXPECT_EQUAL_INT16(id, "deliverAllMessages msg1", msg1->evtID, receivedEventIDs[0]);
+ EXPECT_EQUAL_INT16(id, "deliverAllMessages msg2", msg2->evtID, receivedEventIDs[1]);
+ EXPECT_EQUAL_INT16(id, "deliverAllMessages receivedEventIDCounter", 2, receivedEventIDCounter);
+
+ etMessageService_stop(&msgService);
+
+ etMessageService_destroy(&msgService);
+}
+
+void TestEtMessageService_getMessagePoolLowWaterMark(etInt16 id){
+ etMessageService msgService;
+ uint16 max = 6;
+ uint16 blockSize = 32;
+ uint8 msgBuffer[max*blockSize];
+
+ etMessageService_init(&msgService, msgBuffer, max, blockSize, DummyMessageDispatcher, DummyExecuteDispatcher, EXECMODE_BLOCKED);
+
+ EXPECT_EQUAL_INT16(id, "inital low water mark", max, etMessageService_getMessagePoolLowWaterMark(&msgService));
+
+ // get messages from pool
+ etMessage* msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
+ etMessage* msg2 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
+
+ // define content
+ msg1->address = 11;
+ msg1->evtID = 111;
+ msg2->address = 22;
+ msg2->evtID = 222;
+
+ // push messages to queue
+ etMessageService_pushMessage(&msgService, msg2);
+ etMessageService_pushMessage(&msgService, msg1);
+
+ EXPECT_EQUAL_INT16(id, "low water mark 1", max-2, etMessageService_getMessagePoolLowWaterMark(&msgService));
+
+ // pop messages from queue
+ etMessage* rcvMsg1 = etMessageService_popMessage(&msgService);
+ etMessage* rcvMsg2 = etMessageService_popMessage(&msgService);
+
+ etMessageService_returnMessageBuffer(&msgService, rcvMsg1);
+ etMessageService_returnMessageBuffer(&msgService, rcvMsg2);
+
+ EXPECT_EQUAL_INT16(id, "low water mark 2", max-2, etMessageService_getMessagePoolLowWaterMark(&msgService));
+
+ msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
+ msg2 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
+ etMessageService_pushMessage(&msgService, msg2);
+ etMessageService_pushMessage(&msgService, msg1);
+
+ /*still the same*/
+ EXPECT_EQUAL_INT16(id, "low water mark 3", max-2, etMessageService_getMessagePoolLowWaterMark(&msgService));
+
+ msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
+ etMessageService_pushMessage(&msgService, msg2);
+ msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
+ etMessageService_pushMessage(&msgService, msg2);
+ msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
+ etMessageService_pushMessage(&msgService, msg2);
+ msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
+ etMessageService_pushMessage(&msgService, msg2);
+
+ /* no message left */
+ EXPECT_EQUAL_INT16(id, "low water mark 4", 0, etMessageService_getMessagePoolLowWaterMark(&msgService));
+
+ msg1 = etMessageService_getMessageBuffer(&msgService, sizeof(etMessage));
+ EXPECT_EQUAL_PTR(id, "check message for NULL", NULL, msg1);
+
+ /* still no message left */
+ EXPECT_EQUAL_INT16(id, "low water mark 6", 0, etMessageService_getMessagePoolLowWaterMark(&msgService));
+
+
+}
+
+
+void TestEtMessageService_runSuite(void){
+ etUnit_openTestSuite("TestEtMessageService");
+ ADD_TESTCASE(TestEtMessageService_init);
+ ADD_TESTCASE(TestEtMessageService_GetPushPopReturn);
+ ADD_TESTCASE(TestEtMessageService_GetReturn);
+ ADD_TESTCASE(TestEtMessageService_execute);
+ ADD_TESTCASE(TestEtMessageService_getMessagePoolLowWaterMark)
+ etUnit_closeTestSuite();
+}
diff --git a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/helpers/TestEtTimeHelpers.c b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/helpers/TestEtTimeHelpers.c
new file mode 100644
index 000000000..1ff442503
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/helpers/TestEtTimeHelpers.c
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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 "TestEtTimeHelpers.h"
+#include "helpers/etTimeHelpers.h"
+
+#include "etUnit/etUnit.h"
+
+static void TestEtTimeHelpers_convertToMSec (etInt16 id) {
+ etInt32 result;
+ etTime time;
+
+ time.sec = 0;
+ time.nSec = 0;
+ result = etTimeHelpers_convertToMSec(&time);
+ EXPECT_EQUAL_INT32(id, "0 ms", 0, result);
+
+ time.sec = 1;
+ time.nSec = 1000000;
+ result = etTimeHelpers_convertToMSec(&time);
+ EXPECT_EQUAL_INT32(id, "1001 ms", 1001, result);
+
+ time.sec = 1111;
+ time.nSec = 55000000;
+ result = etTimeHelpers_convertToMSec(&time);
+ EXPECT_EQUAL_INT32(id, "111055 ms", 1111055, result);
+
+}
+
+static void TestEtTimeHelpers_convertToEtTime (etInt16 id) {
+ etInt32 ms_time;
+ etTime result;
+
+ ms_time=0;
+ etTimeHelpers_convertToEtTime(&result, ms_time);
+ EXPECT_EQUAL_INT32(id, "0 s", 0, result.sec);
+ EXPECT_EQUAL_INT32(id, "0 ns", 0, result.nSec);
+
+
+ ms_time=1234567;
+ etTimeHelpers_convertToEtTime(&result, ms_time);
+ EXPECT_EQUAL_INT32(id, "1234 s", 1234, result.sec);
+ EXPECT_EQUAL_INT32(id, "567000000 ns", 567000000, result.nSec);
+
+}
+
+
+
+void TestEtTimeHelpers_runSuite(void){
+ etUnit_openTestSuite("TestEtTimeHelpers");
+ ADD_TESTCASE(TestEtTimeHelpers_convertToMSec);
+ ADD_TESTCASE(TestEtTimeHelpers_convertToEtTime);
+ etUnit_closeTestSuite();
+}
+
+
diff --git a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/helpers/TestEtTimeHelpers.h b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/helpers/TestEtTimeHelpers.h
new file mode 100644
index 000000000..899888304
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/helpers/TestEtTimeHelpers.h
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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)
+ *
+ *******************************************************************************/
+
+#ifndef _TESTETTIMEHELPERS_H_
+#define _TESTETTIMEHELPERS_H_
+
+void TestEtTimeHelpers_runSuite(void);
+
+
+#endif /* _TESTETTIMEHELPERS_H_ */
diff --git a/tests/org.eclipse.etrice.runtime.c.tests/tmp/testlog/TestCRuntime.etu b/tests/org.eclipse.etrice.runtime.c.tests/tmp/testlog/TestCRuntime.etu
index ebfaba24c..770a013c8 100644
--- a/tests/org.eclipse.etrice.runtime.c.tests/tmp/testlog/TestCRuntime.etu
+++ b/tests/org.eclipse.etrice.runtime.c.tests/tmp/testlog/TestCRuntime.etu
@@ -6,7 +6,7 @@ ts start: TestMemory
tc start 2: TestEtMemory_testFixedSize
tc end 2: 10
tc start 3: TestEtMemory_testFreeList
-tc end 3: 0
+tc end 3: 4
ts start: TestMessage
tc start 4: TestEtMessage_testBasicMessage
tc end 4: 0
@@ -18,8 +18,19 @@ tc end 6: 21
ts start: TestEtUnit
tc start 7: TestEtUnit_Expect_Order
tc end 7: 0
-tc start 8: TestEtUnit_Expect
+tc start 8: TestEtMessageService_GetPushPopReturn
tc end 8: 0
+tc start 9: TestEtMessageService_GetReturn
+tc end 9: 0
+tc start 10: TestEtMessageService_execute
+tc end 10: 100
+tc start 11: TestEtMessageService_getMessagePoolLowWaterMark
+tc end 11: 0
+ts start: TestEtUnit
+tc start 12: TestEtUnit_Expect_Order
+tc end 12: 0
+tc start 13: TestEtUnit_Expect
+tc end 13: 0
ts start: TestEtTimer
tc start 9: TestEtTimer_lifecycle
tc end 9: 1501
diff --git a/tests/org.eclipse.etrice.runtime.c.tests/tmp/testlog/TestEtUnitSpecial.etu b/tests/org.eclipse.etrice.runtime.c.tests/tmp/testlog/TestEtUnitSpecial.etu
index 78f14cc25..1da4cc53a 100644
--- a/tests/org.eclipse.etrice.runtime.c.tests/tmp/testlog/TestEtUnitSpecial.etu
+++ b/tests/org.eclipse.etrice.runtime.c.tests/tmp/testlog/TestEtUnitSpecial.etu
@@ -1,4 +1,4 @@
etUnit report
ts start: etUnit
-tc start 11: openAll and closeAll
-tc end 11: 0
+tc start 18: openAll and closeAll
+tc end 18: 0

Back to the top