[runtime.c] Minor changes in the posix implementation of etThread
[runtime.cpp.tests] Fixed MessageDispatcherTest and RTObjectTest
Added documentation for CppCheck, GnuCoverage, Valgrind memcheck

Change-Id: Idc12f40c8f3c8c5bbeedeec020519521f706060d
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_POSIX_GENERIC_GCC/etThread.c b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_POSIX_GENERIC_GCC/etThread.c
index cb4beb2..f3c5b04 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_POSIX_GENERIC_GCC/etThread.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_POSIX_GENERIC_GCC/etThread.c
@@ -64,12 +64,13 @@
 			self->priority = maxPriority;
 
 		param.sched_priority = self->priority;
+		pthread_attr_init(&attr);
 		pthread_attr_setschedparam(&attr, &param);
 		pthread_attr_setschedpolicy(&attr, policy);
 		pthread_attr_setstacksize(&attr, self->stacksize);
 
-		/* TODO: attr doesn't work */
-		pthread_create(&(self->osData), NULL/*&attr*/, (threadFunc) etThread_execute, self);
+		pthread_create(&(self->osData), &attr, (threadFunc) etThread_execute, self);
+		pthread_attr_destroy(&attr);
 	}
 	ET_MSC_LOGGER_SYNC_EXIT
 }
@@ -84,14 +85,13 @@
 
 void etThread_destruct(etThread* self){
 	ET_MSC_LOGGER_SYNC_ENTRY("etThread", "destruct")
-	pthread_cancel(self->osData);
+	pthread_detach(self->osData);
 	ET_MSC_LOGGER_SYNC_EXIT
 }
 
 void etThread_sleep(etInt32 millis){
 	ET_MSC_LOGGER_SYNC_ENTRY("etThread", "sleep")
 	{
-		/* TODO: nanosleep doesn't work at all */
 		struct timespec time;
 		time.tv_sec = millis / 1000;
 		time.tv_nsec = (millis - time.tv_sec * 1000) * 1000*1000;
@@ -99,9 +99,6 @@
 			if(errno != EINTR)
 				break;
 		}
-//		if (millis<1000)
-//			millis = 1000;
-//		sleep(millis/1000);
 	}
 	ET_MSC_LOGGER_SYNC_EXIT
 }
diff --git a/tests/org.eclipse.etrice.runtime.cpp.tests/doc/doc.txt b/tests/org.eclipse.etrice.runtime.cpp.tests/doc/doc.txt
new file mode 100644
index 0000000..d482f6e
--- /dev/null
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/doc/doc.txt
@@ -0,0 +1,16 @@
+Gnu Coverage:
+	1. Install Linux tools in Eclipse
+	2. Add -ftest-coverage and -fprofile-arcs to the compiler and the linker flags (Properties -> C++ Build -> Settings -> Miscellaneous)
+	3. Compile and run the application
+	4. Open one of the generated .gcov files
+
+CppCheck:
+	1. Download, install, open CppCheck
+	2. Choose Check Directory and select the source-folder
+	
+Valgrind:
+	1. Valgrind only works on Linux
+	2. Download the Valgrind source files and install them on the system (http://valgrind.org/docs/manual/dist.install.html)
+	3. Install Linux tools in Eclipse
+	4. Create a new profile configuration and select the tab Profiler
+	5. Switch to memcheck and press the button Profile
\ No newline at end of file
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 113d20d..f81c3ae 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
@@ -98,16 +98,16 @@
 	msgDisp.removeMessageReceiver(recv3);
 
 	// Test polling Messages
-	Message *pollMsg = new Message(Address(1, 2, 0), 0, NULL);
+	Message pollMsg(Address(1, 2, 0), 0, NULL);
 	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/RTObjectTest.cpp b/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/RTObjectTest.cpp
index fa2b28a..f84456f 100644
--- a/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/RTObjectTest.cpp
+++ b/tests/org.eclipse.etrice.runtime.cpp.tests/src/messaging/RTObjectTest.cpp
@@ -103,6 +103,9 @@
 	EXPECT_EQUAL_INT16(m_caseId, failMsg, -1,
 			rto4->getThreadForPath(rto4->getInstancePath()));
 
+	delete rto4;
+	delete rto3;
+	delete rto2;
 	delete rto1;
 }