summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Schuetz2013-04-30 08:21:39 (EDT)
committerThomas Schuetz2013-04-30 08:21:39 (EDT)
commit3f26e81bc9be937a2f6c0bf765628093e6eda05b (patch)
treeeaff9059543706bdfc8b08aaf18b0c6562f0eb70
parent557eaf3819ee03755134775d16ce1a2951e74222 (diff)
downloadorg.eclipse.etrice-3f26e81bc9be937a2f6c0bf765628093e6eda05b.zip
org.eclipse.etrice-3f26e81bc9be937a2f6c0bf765628093e6eda05b.tar.gz
org.eclipse.etrice-3f26e81bc9be937a2f6c0bf765628093e6eda05b.tar.bz2
[runtime.c.tests] fixed testcase for etMessageService
https://bugs.eclipse.org/bugs/show_bug.cgi?id=406888 Change-Id: Ifd556ddb0290477e1588672fa6062433ca887448
-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.c2
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMessageService.c24
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/tmp/testlog/TestCRuntime.etu41
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/tmp/testlog/TestEtUnitSpecial.etu4
7 files changed, 72 insertions, 29 deletions
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 b1a5fea..8c87c85 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 f305d1a..a9a6cb1 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 3d119ea..d782873 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
@@ -80,6 +80,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
}
@@ -153,7 +154,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 4ab86cb..df418f3 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
@@ -44,7 +44,7 @@ void RunCRuntimeTestcases(void){
TestEtMemory_runSuite();
TestEtMessage_runSuite();
TestEtMessageQueue_runSuite();
-// TestEtMessageService_runSuite();
+ TestEtMessageService_runSuite();
TestEtUnit_runSuite();
TestEtTimer_runSuite();
TestEtTimeHelpers_runSuite();
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 2015147..07f8acc 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
@@ -65,6 +65,7 @@ void TestEtMessageService_init(etInt16 id){
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){
@@ -110,6 +111,8 @@ void TestEtMessageService_GetPushPopReturn(etInt16 id){
etMessageService_returnMessageBuffer(&msgService, rcvMsg2);
EXPECT_EQUAL_INT16(id, "msgService.messagePool.size", 6, msgService.messagePool.size);
+
+ etMessageService_destroy(&msgService);
}
void TestEtMessageService_GetReturn(etInt16 id){
@@ -124,7 +127,7 @@ void TestEtMessageService_GetReturn(etInt16 id){
// 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));
+ 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);
@@ -135,9 +138,10 @@ void TestEtMessageService_GetReturn(etInt16 id){
EXPECT_EQUAL_INT16(id, "msgService.messagePool.size", 2, msgService.messagePool.size);
// get message bigger than blocksize
- etMessage* msg4 = etMessageService_getMessageBuffer(&msgService, 33);
+ 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){
@@ -162,11 +166,23 @@ void TestEtMessageService_execute(etInt16 id){
etMessageService_pushMessage(&msgService, msg1);
etMessageService_pushMessage(&msgService, msg2);
- /* make sure that receivedEventIDCounter==0 and receivedEventIDs[n]==0*/
- etMessageService_execute(&msgService);
+
+ 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){
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 73347e1..ceff201 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
@@ -1,12 +1,12 @@
etUnit report
ts start: TestQueue
tc start 1: TestEtQueue_test
-tc end 1: 15
+tc end 1: 13
ts start: TestMemory
tc start 2: TestEtMemory_testFixedSize
-tc end 2: 0
+tc end 2: 11
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
@@ -14,19 +14,30 @@ ts start: TestEtMessageQueue
tc start 5: TestEtMessageQueue_testPushPop
tc end 5: 0
tc start 6: TestEtMessageQueue_testMassiveMessaging
-tc end 6: 16
-ts start: TestEtUnit
-tc start 7: TestEtUnit_Expect_Order
+tc end 6: 15
+ts start: TestEtMessageService
+tc start 7: TestEtMessageService_init
tc end 7: 0
-tc start 8: TestEtUnit_Expect
+tc start 8: TestEtMessageService_GetPushPopReturn
tc end 8: 0
-ts start: TestEtTimer
-tc start 9: TestEtTimer_lifecycle
-tc end 9: 1513
-tc start 10: TestEtTimer_multiTimer
-tc end 10: 1014
-ts start: TestEtTimeHelpers
-tc start 11: TestEtTimeHelpers_convertToMSec
+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
-tc start 12: TestEtTimeHelpers_convertToEtTime
+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 14: TestEtTimer_lifecycle
+tc end 14: 1500
+tc start 15: TestEtTimer_multiTimer
+tc end 15: 1001
+ts start: TestEtTimeHelpers
+tc start 16: TestEtTimeHelpers_convertToMSec
+tc end 16: 0
+tc start 17: TestEtTimeHelpers_convertToEtTime
+tc end 17: 0
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 71e5855..1da4cc5 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 13: openAll and closeAll
-tc end 13: 0
+tc start 18: openAll and closeAll
+tc end 18: 0