Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJan Belle2016-10-26 14:36:33 +0000
committerHenrik Rentz-Reichert2016-11-07 08:47:26 +0000
commitcfec11455b4c5d2580af682a7712b55095a53bba (patch)
tree801787f79039398681c120398f591cd1a14aa359 /tests
parenta488ef8e6dd1be4f685c8284c4a2f45aa1cc21ef (diff)
downloadorg.eclipse.etrice-cfec11455b4c5d2580af682a7712b55095a53bba.tar.gz
org.eclipse.etrice-cfec11455b4c5d2580af682a7712b55095a53bba.tar.xz
org.eclipse.etrice-cfec11455b4c5d2580af682a7712b55095a53bba.zip
Refactored messaging to static message allocation
[runtime.cpp] Added StaticMessageMemory and IMemory class for static messaging. [generator.cpp] Adjusted generator to static messaging. [runtime.cpp.tests] Adjusted test cases to fit the runtime changes and added testcase for the StaticMessageMemory. [ui.runtime] updated zipped contents Change-Id: I92adb0c610555b0b954365611714a5a6f873605c
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.etrice.generator.common.tests/models/PingPongThread.etphys12
-rw-r--r--tests/org.eclipse.etrice.runtime.cpp.tests/src/RunAllTestCases.cpp4
-rw-r--r--tests/org.eclipse.etrice.runtime.cpp.tests/src/debugging/DebuggingServiceTest.cpp3
-rw-r--r--tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageDispatcherTest.cpp35
-rw-r--r--tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageServiceControllerTest.cpp4
-rw-r--r--tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageServiceTest.cpp8
-rw-r--r--tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageTest.cpp13
-rw-r--r--tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/StaticMessageMemoryTest.cpp74
-rw-r--r--tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/StaticMessageMemoryTest.h29
9 files changed, 153 insertions, 29 deletions
diff --git a/tests/org.eclipse.etrice.generator.common.tests/models/PingPongThread.etphys b/tests/org.eclipse.etrice.generator.common.tests/models/PingPongThread.etphys
index 5e533211e..1215b84c6 100644
--- a/tests/org.eclipse.etrice.generator.common.tests/models/PingPongThread.etphys
+++ b/tests/org.eclipse.etrice.generator.common.tests/models/PingPongThread.etphys
@@ -3,7 +3,7 @@ PhysicalModel PingPongThread {
PhysicalSystem Sys {
NodeRef node1: PC
}
-
+
NodeClass PC {
runtime = PC
priomin = 1
@@ -13,7 +13,7 @@ PhysicalModel PingPongThread {
execmode = blocked
prio = 5
stacksize = 1024
- msgblocksize = 64
+ msgblocksize = 128
msgpoolsize = 32
}
@@ -21,7 +21,7 @@ PhysicalModel PingPongThread {
execmode = blocked
prio = 5
stacksize = 1024
- msgblocksize = 64
+ msgblocksize = 128
msgpoolsize = 32
}
@@ -29,7 +29,7 @@ PhysicalModel PingPongThread {
execmode = blocked
prio = 5
stacksize = 1024
- msgblocksize = 64
+ msgblocksize = 128
msgpoolsize = 32
}
@@ -37,7 +37,7 @@ PhysicalModel PingPongThread {
execmode = blocked
prio = 5
stacksize = 1024
- msgblocksize = 64
+ msgblocksize = 128
msgpoolsize = 32
}
@@ -46,7 +46,7 @@ PhysicalModel PingPongThread {
interval = 100 ms
prio = 5
stacksize = 1024
- msgblocksize = 64
+ msgblocksize = 128
msgpoolsize = 32
}
}
diff --git a/tests/org.eclipse.etrice.runtime.cpp.tests/src/RunAllTestCases.cpp b/tests/org.eclipse.etrice.runtime.cpp.tests/src/RunAllTestCases.cpp
index 3d7695239..737754cc1 100644
--- a/tests/org.eclipse.etrice.runtime.cpp.tests/src/RunAllTestCases.cpp
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/src/RunAllTestCases.cpp
@@ -23,6 +23,7 @@
#include "messaging/MessageDispatcherTest.h"
#include "messaging/MessageServiceTest.h"
#include "messaging/MessageServiceControllerTest.h"
+#include "messaging/StaticMessageMemoryTest.h"
#include "etUnit/etUnit.h"
@@ -72,6 +73,9 @@ int main() {
MessageServiceControllerTest msgSvcCtrlTest;
msgSvcCtrlTest.run();
+ StaticMessageMemoryTest staticMsgMemTest;
+ staticMsgMemTest.run();
+
etUnit_close();
return 0;
diff --git a/tests/org.eclipse.etrice.runtime.cpp.tests/src/debugging/DebuggingServiceTest.cpp b/tests/org.eclipse.etrice.runtime.cpp.tests/src/debugging/DebuggingServiceTest.cpp
index 9b489d9eb..7a53e2fc9 100644
--- a/tests/org.eclipse.etrice.runtime.cpp.tests/src/debugging/DebuggingServiceTest.cpp
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/src/debugging/DebuggingServiceTest.cpp
@@ -14,6 +14,7 @@
#include "common/debugging/DebuggingService.h"
#include "common/messaging/MessageService.h"
#include "common/messaging/RTServices.h"
+#include "common/messaging/StaticMessageMemory.h"
#include "etUnit/etUnit.h"
using namespace etRuntime;
@@ -21,7 +22,7 @@ using namespace etRuntime;
void DebuggingServiceTest::testLogging() {
MessageService msgSvc(NULL, IMessageService::BLOCKED, 0, 0,
- "TestMessageService");
+ "TestMessageService", new StaticMessageMemory(NULL, "TestMemory", 64, 100));
RTServices::getInstance().getMsgSvcCtrl().addMsgSvc(msgSvc);
RTServices::getInstance().getMsgSvcCtrl().start();
SubSystemClass subSystem(NULL, "TestSubSystem");
diff --git a/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageDispatcherTest.cpp b/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageDispatcherTest.cpp
index f81c3aee9..730a3a7d9 100644
--- a/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageDispatcherTest.cpp
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageDispatcherTest.cpp
@@ -13,6 +13,8 @@
#include "messaging/MessageDispatcherTest.h"
#include "etUnit/etUnit.h"
#include "common/messaging/MessageDispatcher.h"
+#include "common/messaging/MessageService.h"
+#include "common/messaging/StaticMessageMemory.h"
using namespace etRuntime;
@@ -58,19 +60,27 @@ void MessageDispatcherTest::testDispatching() {
const char *failMsg = "MessageDispatcher dispatching test failed";
// Test dispatching Messages
- MessageDispatcher msgDisp(NULL, Address(1, 2, 0), "TestMessageDispatcher");
+ MessageService msgSvc(NULL, IMessageService::BLOCKED, 1, 2,
+ "Test MessageService", new StaticMessageMemory(NULL, "TestMemory", 64, 100));
+ MessageDispatcher msgDisp(&msgSvc, Address(1, 2, 0), "TestMessageDispatcher");
Address addr1 = msgDisp.getFreeAddress();
Address addr2 = msgDisp.getFreeAddress();
Address addr3 = msgDisp.getFreeAddress();
SimpleMessageReceiver recv1(NULL, "Test receiver1", addr1);
SimpleMessageReceiver recv2(NULL, "Test receiver2", addr2);
SimpleMessageReceiver recv3(NULL, "Test receiver3", addr3);
- Message *msg1 = new Message(addr1, 1, NULL);
- Message *msg2 = new Message(addr2, 2, NULL);
- Message *msg3 = new Message(addr3, 3, NULL);
- Message *msg4 = new Message(addr1, 4, NULL);
- Message *msg5 = new Message(addr2, 5, NULL);
- Message *msg6 = new Message(addr3, 6, NULL);
+ Message *msg1 = msgSvc.getMessageBuffer(sizeof(Message));
+ Message *msg2 = msgSvc.getMessageBuffer(sizeof(Message));
+ Message *msg3 = msgSvc.getMessageBuffer(sizeof(Message));
+ Message *msg4 = msgSvc.getMessageBuffer(sizeof(Message));
+ Message *msg5 = msgSvc.getMessageBuffer(sizeof(Message));
+ Message *msg6 = msgSvc.getMessageBuffer(sizeof(Message));
+ msg1 = new (msg1) Message(addr1, 1);
+ msg2 = new (msg2) Message(addr2, 2);
+ msg3 = new (msg3) Message(addr3, 3);
+ msg4 = new (msg4) Message(addr1, 4);
+ msg5 = new (msg5) Message(addr2, 5);
+ msg6 = new (msg6) Message(addr3, 6);
msgDisp.addMessageReceiver(recv1);
msgDisp.receive(msg1);
@@ -98,16 +108,17 @@ void MessageDispatcherTest::testDispatching() {
msgDisp.removeMessageReceiver(recv3);
// Test polling Messages
- Message pollMsg(Address(1, 2, 0), 0, NULL);
+ Message *pollMsg = msgSvc.getMessageBuffer(sizeof(Message));
+ pollMsg = new (pollMsg) Message(Address(1, 2, 0), 0);
msgDisp.addPollingMessageReceiver(recv1);
msgDisp.addPollingMessageReceiver(recv2);
msgDisp.addPollingMessageReceiver(recv3);
- msgDisp.receive(&pollMsg);
- EXPECT_EQUAL_PTR(m_caseId, failMsg, &pollMsg,
+ msgDisp.receive(pollMsg);
+ EXPECT_EQUAL_PTR(m_caseId, failMsg, pollMsg,
recv1.getLastReceivedMessagePtr());
- EXPECT_EQUAL_PTR(m_caseId, failMsg, &pollMsg,
+ EXPECT_EQUAL_PTR(m_caseId, failMsg, pollMsg,
recv2.getLastReceivedMessagePtr());
- EXPECT_EQUAL_PTR(m_caseId, failMsg, &pollMsg,
+ EXPECT_EQUAL_PTR(m_caseId, failMsg, pollMsg,
recv3.getLastReceivedMessagePtr());
msgDisp.removePollingMessageReceiver(recv1);
msgDisp.removePollingMessageReceiver(recv2);
diff --git a/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageServiceControllerTest.cpp b/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageServiceControllerTest.cpp
index 374aaba79..439d9c079 100644
--- a/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageServiceControllerTest.cpp
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageServiceControllerTest.cpp
@@ -61,9 +61,9 @@ void MessageServiceControllerTest::testMsgSvcManagement() {
MessageServiceController& msgSvcController =
RTServices::getInstance().getMsgSvcCtrl();
MessageService msgSvc1(NULL, IMessageService::BLOCKED, 1,
- msgSvcController.getNewID(), "MessageService1");
+ msgSvcController.getNewID(), "MessageService1", new StaticMessageMemory(NULL, "TestMemory", 64, 100));
MessageService msgSvc2(NULL, IMessageService::POLLED, 1,
- msgSvcController.getNewID(), "MessageService2");
+ msgSvcController.getNewID(), "MessageService2", new StaticMessageMemory(NULL, "TestMemory", 64, 100));
msgSvcController.addMsgSvc(msgSvc1);
msgSvcController.addMsgSvc(msgSvc2);
diff --git a/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageServiceTest.cpp b/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageServiceTest.cpp
index e777b405f..728b8efff 100644
--- a/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageServiceTest.cpp
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageServiceTest.cpp
@@ -66,7 +66,7 @@ void MessageServiceTest::testBlocked() {
MessageServiceController& msgSvcCtrl =
RTServices::getInstance().getMsgSvcCtrl();
MessageService msgService(NULL, IMessageService::BLOCKED, 1, 2,
- "Test MessageService");
+ "Test MessageService", new StaticMessageMemory(NULL, "TestMemory", sizeof(Message), 10000000));
msgSvcCtrl.addMsgSvc(msgService);
MessageCounter msgCounter(NULL, "MessageCounter", addr);
msgService.addMessageReceiver(msgCounter);
@@ -110,7 +110,7 @@ void MessageServiceTest::testPolled() {
MessageServiceController& msgSvcCtrl =
RTServices::getInstance().getMsgSvcCtrl();
MessageService msgService(NULL, IMessageService::POLLED, interval, 1, 2,
- "Test MessageService");
+ "Test MessageService", new StaticMessageMemory(NULL, "TestMemory", 64, 100));
msgSvcCtrl.addMsgSvc(msgService);
MessageCounter msgCounter(NULL, "Message Counter",
msgService.getFreeAddress());
@@ -162,7 +162,9 @@ void Sender::terminate() {
void Sender::run() {
while (m_running) {
- m_msgService.receive(new Message(m_addr, 0));
+ Message* msg = m_msgService.getMessageBuffer(sizeof(Message));
+ msg = new (msg) Message(m_addr, 0);
+ m_msgService.receive(msg);
m_messagesSent++;
}
diff --git a/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageTest.cpp b/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageTest.cpp
index db8c29d03..549d31485 100644
--- a/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageTest.cpp
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/MessageTest.cpp
@@ -36,12 +36,15 @@ void MessageTest::testConstructors() {
EXPECT_EQUAL_INT16(m_caseId, failMsg, 1, msg2.getEvtId());
EXPECT_EQUAL_PTR(m_caseId, failMsg, &data, msg2.getData());
- // Test constructor Message(const Address& addr, int evtm_caseId, const void* dataToCopy, std::size_t dataSize)
- Message msg3(addr, 1, &data, sizeof(int));
- EXPECT_TRUE(m_caseId, failMsg, msg3.getAddress() == addr);
- EXPECT_EQUAL_INT16(m_caseId, failMsg, 1, msg3.getEvtId());
+ // Test constructor DataMessage(const Address& addr, int evtm_caseId, const T& dataToCopy)
+ Message* msg3 = (Message*) new uint8_t[sizeof(DataMessage<int>)];
+ new (msg3) DataMessage<int>(addr, 1, data);
+ EXPECT_TRUE(m_caseId, failMsg, msg3->getAddress() == addr);
+ EXPECT_EQUAL_INT16(m_caseId, failMsg, 1, msg3->getEvtId());
EXPECT_TRUE(m_caseId, failMsg,
- *(static_cast<int*>(msg3.getData())) == data);
+ *(static_cast<int*>(msg3->getData())) == data);
+ msg3->~Message();
+ delete[] (uint8_t*) msg3;
}
void MessageTest::testGetters() {
diff --git a/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/StaticMessageMemoryTest.cpp b/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/StaticMessageMemoryTest.cpp
new file mode 100644
index 000000000..0ad73b81c
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/StaticMessageMemoryTest.cpp
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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:
+ * Jan Belle (initial contribution)
+ *
+ *******************************************************************************/
+
+#include "StaticMessageMemoryTest.h"
+#include "common/messaging/Message.h"
+#include "common/messaging/StaticMessageMemory.h"
+#include "etUnit/etUnit.h"
+
+using namespace etRuntime;
+
+void StaticMessageMemoryTest::test() {
+ const char* failMsg = "StaticMessageMemoryTest failed";
+
+ StaticMessageMemory mem(NULL, "TestMemory", sizeof(DataMessage<uint32_t>), 10);
+
+ EXPECT_EQUAL_INT32(m_caseId, failMsg, sizeof(DataMessage<uint32_t>), mem.getBufferSize());
+ EXPECT_EQUAL_INT32(m_caseId, failMsg, 10, mem.getMessagePoolSize());
+
+ Message* msg[10];
+
+ for (int i = 0; i < 10; ++i) {
+ msg[i] = mem.getMessageBuffer(0);
+ EXPECT_TRUE(m_caseId, failMsg, msg[i] != NULL);
+ EXPECT_EQUAL_INT32(m_caseId, failMsg, 9 - i, mem.getMessagePoolSize());
+ new (msg[i]) Message(Address::EMPTY, 0, NULL);
+ }
+ EXPECT_EQUAL_PTR(m_caseId, failMsg, NULL, mem.getMessageBuffer(0));
+ for (int i = 0; i < 10; ++i) {
+ mem.returnMessageBuffer(msg[i]);
+ EXPECT_EQUAL_INT32(m_caseId, failMsg, i + 1, mem.getMessagePoolSize());
+ }
+
+ msg[0] = mem.getMessageBuffer(4);
+ EXPECT_TRUE(m_caseId, failMsg, msg[0] != NULL);
+ msg[1] = mem.getMessageBuffer(2);
+ EXPECT_TRUE(m_caseId, failMsg, msg[1] != NULL);
+ msg[2] = mem.getMessageBuffer(1);
+ EXPECT_TRUE(m_caseId, failMsg, msg[2] != NULL);
+ uint32_t* ui32 = new uint32_t(32);
+ uint16_t* ui16 = new uint16_t(16);
+ uint8_t* ui8 = new uint8_t(8);
+ new (msg[0]) DataMessage<uint32_t>(Address::EMPTY, 1, *ui32);
+ new (msg[1]) DataMessage<uint16_t>(Address::EMPTY, 1, *ui16);
+ new (msg[2]) DataMessage<uint8_t>(Address::EMPTY, 1, *ui8);
+ delete ui32;
+ delete ui16;
+ delete ui8;
+ ui32 = (uint32_t*) msg[0]->getData();
+ ui16 = (uint16_t*) msg[1]->getData();
+ ui8 = (uint8_t*) msg[2]->getData();
+ EXPECT_EQUAL_UINT32(m_caseId, failMsg, 32, *ui32);
+ EXPECT_EQUAL_UINT16(m_caseId, failMsg, 16, *ui16);
+ EXPECT_EQUAL_UINT8(m_caseId, failMsg, 8, *ui8);
+ msg[0]->~Message();
+ msg[1]->~Message();
+ msg[2]->~Message();
+ mem.returnMessageBuffer(msg[2]);
+ mem.returnMessageBuffer(msg[1]);
+ mem.returnMessageBuffer(msg[0]);
+}
+
+void StaticMessageMemoryTest::runAllTestCases() {
+ ADD_TESTCASE_CPP(test)
+}
+
diff --git a/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/StaticMessageMemoryTest.h b/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/StaticMessageMemoryTest.h
new file mode 100644
index 000000000..44b74d060
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/StaticMessageMemoryTest.h
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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:
+ * Jan Belle (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef SRC_MESSAGING_STATICMESSAGEMEMORYTEST_H_
+#define SRC_MESSAGING_STATICMESSAGEMEMORYTEST_H_
+
+#include "util/etTestSuite.h"
+
+class StaticMessageMemoryTest: public etTestSuite {
+public:
+ StaticMessageMemoryTest(void) :
+ etTestSuite("StaticMessageMemoryTest") {
+ }
+
+protected:
+ void runAllTestCases(void);
+ void test(void);
+};
+
+#endif /* SRC_MESSAGING_STATICMESSAGEMEMORYTEST_H_ */

Back to the top