Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtTimer.c')
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtTimer.c62
1 files changed, 49 insertions, 13 deletions
diff --git a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtTimer.c b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtTimer.c
index 328d1318b..1a54fd3e6 100644
--- a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtTimer.c
+++ b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtTimer.c
@@ -17,18 +17,20 @@
#include "etDatatypes.h"
#include "osal/etTimer.h"
+#include "osal/etThread.h"
#include "osal/etSema.h"
#include "helpers/etTimeHelpers.h"
etSema GlobalSema;
+etInt32 counter;
+etTimerFunction_RETURN_VALUE TestEtTimer_TimerCallback1(etTimerFunction_ARGUMENT_LIST){
+ etSema_wakeup(&GlobalSema);
+}
-VOID CALLBACK TestEtTimer_TimerCallback(HWND arg1, UINT arg2, UINT arg3, DWORD arg4){
-//etTimerFunction_RETURN_VALUE TestEtTimer_TimerCallback(etTimerFunction_ARGUMENT_LIST){
- //etSema_wakeup(&GlobalSema);
- int i=5;
- printf("\nTestEtTimer_TimerCallback: tick: %d", i);
+etTimerFunction_RETURN_VALUE TestEtTimer_TimerCallback2(etTimerFunction_ARGUMENT_LIST){
+ counter++;
}
static void TestEtTimer_lifecycle (etInt16 id) {
@@ -40,29 +42,63 @@ static void TestEtTimer_lifecycle (etInt16 id) {
/* create semaphore */
etSema_construct(&GlobalSema);
/* create and start timer */
- interval.sec = 0; /* = 1000 milliseconds */
+ interval.sec = 1; /* = 1000 milliseconds */
interval.nSec = 500000000; /* = 50 milliseconds */
- etTimer_construct(&timer1, &interval, TestEtTimer_TimerCallback);
- etTimer_start(&timer1);
-
+ etTimer_construct(&timer1, &interval, TestEtTimer_TimerCallback1);
getTimeFromTarget(&startTime);
- etThread_sleep(5000);
- //etSema_waitForWakeup(&GlobalSema); /* wait until callback function releases timer */
+ etTimer_start(&timer1);
+ etSema_waitForWakeup(&GlobalSema); /* wait until callback function releases timer the first time (fires immediately) */
+ etSema_waitForWakeup(&GlobalSema); /* wait until callback function releases timer the second time (fires after first interval)*/
etTimer_stop(&timer1);
getTimeFromTarget(&endTime);
-
- printf("\nelapsed time: %ld\n", etTimeHelpers_convertToMSec(&endTime) - etTimeHelpers_convertToMSec(&startTime));
+ etInt32 elapsed = etTimeHelpers_convertToMSec(&endTime) - etTimeHelpers_convertToMSec(&startTime);
+ EXPECT_TRUE(id, "elapsed time wrong", (elapsed > 1400) && (elapsed < 1600));
/* release resources */
etTimer_destruct(&timer1);
etSema_destruct(&GlobalSema);
}
+static void TestEtTimer_multiTimer (etInt16 id) {
+ etTimer timer1;
+ etTimer timer2;
+ etTime interval;
+ counter = 0;
+
+
+ /* create semaphore */
+ etSema_construct(&GlobalSema);
+
+ interval.sec = 1; /* = 1000 milliseconds */
+ interval.nSec = 0; /* = 0 milliseconds */
+ etTimer_construct(&timer1, &interval, TestEtTimer_TimerCallback1);
+ interval.sec = 0; /* = 1000 milliseconds */
+ interval.nSec = 1000000; /* = 1 millisecond */
+ etTimer_construct(&timer2, &interval, TestEtTimer_TimerCallback2);
+
+ etTimer_start(&timer1);
+ etTimer_start(&timer2);
+
+ etSema_waitForWakeup(&GlobalSema); /* wait until callback function releases timer the first time (fires immediately) */
+ etSema_waitForWakeup(&GlobalSema); /* wait until callback function releases timer the second time (fires after first interval)*/
+
+
+ etTimer_stop(&timer2);
+ etTimer_stop(&timer1);
+
+ EXPECT_TRUE(id, "counter wrong", (counter > 950) && (counter < 1050));
+ etTimer_destruct(&timer2);
+ etTimer_destruct(&timer1);
+
+ etSema_destruct(&GlobalSema);
+
+}
void TestEtTimer_runSuite(void){
etUnit_openTestSuite("TestEtTimer");
ADD_TESTCASE(TestEtTimer_lifecycle);
+ ADD_TESTCASE(TestEtTimer_multiTimer);
etUnit_closeTestSuite();
}

Back to the top