diff options
author | Thomas Schuetz | 2013-04-29 22:17:31 +0000 |
---|---|---|
committer | Thomas Schuetz | 2013-04-29 22:17:31 +0000 |
commit | 9d880c611d45f933b7029e79b8776b2f4d429cee (patch) | |
tree | fd192b8dbbc9cb194bbbf63c421587886af62370 | |
parent | 2903767e47d1d2a6d3135d7a26d2913987792f52 (diff) | |
download | org.eclipse.etrice-9d880c611d45f933b7029e79b8776b2f4d429cee.tar.gz org.eclipse.etrice-9d880c611d45f933b7029e79b8776b2f4d429cee.tar.xz org.eclipse.etrice-9d880c611d45f933b7029e79b8776b2f4d429cee.zip |
[runtime.c] implementation of etTimer for MinGW and unit tests for etTimer
10 files changed, 115 insertions, 51 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/.cproject b/runtime/org.eclipse.etrice.runtime.c/.cproject index 30786f557..7fae49897 100644 --- a/runtime/org.eclipse.etrice.runtime.c/.cproject +++ b/runtime/org.eclipse.etrice.runtime.c/.cproject @@ -23,7 +23,7 @@ <folderInfo id="cdt.managedbuild.config.gnu.mingw.lib.debug.505530637." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.mingw.lib.debug.897987799" name="MinGW GCC" superClass="cdt.managedbuild.toolchain.gnu.mingw.lib.debug">
<targetPlatform id="cdt.managedbuild.target.gnu.platform.mingw.lib.debug.1195644765" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.mingw.lib.debug"/>
- <builder buildPath="${workspace_loc:/org.eclipse.etrice.runtime.c/Debug}" id="cdt.managedbuild.tool.gnu.builder.mingw.base.1199468624" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="CDT Internal Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="cdt.managedbuild.tool.gnu.builder.mingw.base">
+ <builder buildPath="${workspace_loc:/org.eclipse.etrice.runtime.c/Debug}" id="cdt.managedbuild.tool.gnu.builder.mingw.base.1199468624" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="CDT Internal Builder" parallelBuildOn="false" superClass="cdt.managedbuild.tool.gnu.builder.mingw.base">
<outputEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="outputPath" name="Debug"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="outputPath" name="Release"/>
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.c b/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.c index d5e0b7d89..8f153591f 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.c +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.c @@ -24,6 +24,7 @@ static FILE* etUnit_reportfile = NULL; /* counters */
static etInt16 etUnit_nextCaseId = 1;
+static etInt32 etUnit_errorCounter = 0;
#define ETUNIT_MAX_TEST_CASES 256
static etBool etUnit_testcaseSuccess[ETUNIT_MAX_TEST_CASES];
@@ -94,6 +95,7 @@ void etUnit_close(void) { etUnit_reportfile = NULL;
}
etLogger_logInfoF("End Time: %ld", clock());
+ etLogger_logErrorF("Error Counter: %ld", etUnit_errorCounter);
etLogger_logInfoF("************* TEST END **************");
}
@@ -314,6 +316,7 @@ static void etUnit_handleExpect(etInt16 id, etBool result, const char *resulttex /* nothing to do because no failure */
}
else {
+ etUnit_errorCounter++;
if (etUnit_testcaseSuccess[id] == TRUE){
/* first failure will be remembered */
etUnit_testcaseSuccess[id] = FALSE;
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etTimer.h b/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etTimer.h index b332b63b9..f782f9455 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etTimer.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etTimer.h @@ -15,7 +15,6 @@ #include "etDatatypes.h" #include "etTime.h" -#include "etThread.h" /** @@ -23,13 +22,13 @@ * the struct has to be filled before calling etThread_construct except for osData and osId **/ typedef struct etTimer{ - etOSTimerId osTimerId; /**< OS specific timer id (e.g. handle or id) -> is filled in by etTimer_construct **/ + etOSTimerData osTimerData; /**< OS specific timer id (e.g. handle or id) -> is filled in by etTimer_construct **/ etTime timerInterval; /**< timer interval **/ etTimerFunction timerFunction; /**< call back function to be called by timer -> has to be filled in by caller of etTimer_construct **/ } etTimer; -void etTimer_construct(etTimer* self, etTime* timerInterval, etTimerFunction threadFunction); +void etTimer_construct(etTimer* self, etTime* timerInterval, etTimerFunction timerFunction); void etTimer_start(etTimer* self); void etTimer_stop(etTimer* self); void etTimer_destruct(etTimer* self); diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etDatatypes.h b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etDatatypes.h index ff5f6ad61..b7cfa1077 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etDatatypes.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etDatatypes.h @@ -21,8 +21,8 @@ #include <stdio.h> +#define WINVER 0x0500 #include <windows.h> -#include <process.h> /* unsigned integer datatypes */ typedef unsigned char uint8; @@ -90,24 +90,15 @@ typedef int16 etAddressId; * typedefs for OS-specific types */ - typedef CRITICAL_SECTION etOSMutexData; - typedef HANDLE etOSThreadData; - typedef DWORD etOSThreadId; - typedef HANDLE etOSSemaData; - - typedef UINT_PTR etOSTimerId; - -//typedef TIMERPROC etTimerFunction; -typedef VOID(CALLBACK *etTimerFunction)(HWND,UINT,UINT,DWORD); -//typedef void (*etThreadFunction)(void *); +typedef CRITICAL_SECTION etOSMutexData; +typedef HANDLE etOSThreadData; +typedef DWORD etOSThreadId; +typedef HANDLE etOSSemaData; +typedef HANDLE etOSTimerData; +typedef DWORD etOSTimerId; +typedef VOID(CALLBACK *etTimerFunction)(PVOID lpParam, BOOLEAN TimerOrWaitFired); #define etTimerFunction_RETURN_VALUE VOID CALLBACK - -#define etTimerFunction_ARGUMENT_LIST HWND arg1, UINT arg2, UINT arg3, DWORD arg4 - - -//typedef void (*etTimerFunction)(void); /**< OS specific timer callback function **/ -//typedef VOID(CALLBACK *TIMERPROC)(HWND,UINT,UINT,DWORD); - +#define etTimerFunction_ARGUMENT_LIST PVOID lpParam, BOOLEAN TimerOrWaitFired #endif /* _DATATYPES_H_ */ diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etThread.c b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etThread.c index 14ea2b98a..61be3103d 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etThread.c +++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etThread.c @@ -21,6 +21,8 @@ #include "debugging/etLogger.h" #include "debugging/etMSCLogger.h" +#include <process.h> + void etThread_execute(etThread* self); void etThread_construct(etThread* self){ diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etTimer.c b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etTimer.c index 3cbd39fe6..7e98fc932 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etTimer.c +++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etTimer.c @@ -19,25 +19,49 @@ #include "osal/etTimer.h" #include "helpers/etTimeHelpers.h" -void etTimer_construct(etTimer* self, etTime* timerInterval, etTimerFunction threadFunction){ - self->osTimerId = 0; +#include "debugging/etLogger.h" +#include "debugging/etMSCLogger.h" + + +/** global handle for the Windows timer queue */ +static HANDLE hTimerQueue = NULL; + +void etTimer_construct(etTimer* self, etTime* timerInterval, etTimerFunction timerFunction){ + self->osTimerData = NULL; self->timerInterval.sec = timerInterval->sec; self->timerInterval.nSec = timerInterval->nSec; - self->timerFunction = threadFunction; + self->timerFunction = timerFunction; + if (hTimerQueue == NULL){ + /* the Windows timer queue is only needed once for all timers */ + hTimerQueue = CreateTimerQueue(); + if (hTimerQueue == NULL){ + etLogger_logError("etTimer_construct: CreateTimerQueue failed"); + } + } } void etTimer_start(etTimer* self){ UINT elapse; /* calculate the time in milliseconds -> accuracy will of nSec will get lost in windows! */ elapse = etTimeHelpers_convertToMSec(&(self->timerInterval)); - /*TODO: should we replace the forced cast by a platform specific implementation of the timer callback function? */ - self->osTimerId = SetTimer(NULL, 0, elapse, self->timerFunction); + + if (hTimerQueue == NULL){ + etLogger_logError("etTimer_start: no Timer Queue to create timer (NULL)"); + } + else { + if (CreateTimerQueueTimer( &(self->osTimerData), hTimerQueue, self->timerFunction, NULL , 0, elapse, 0) == FALSE){ + etLogger_logError("etTimer_start: Timer could not be created"); + } + } } void etTimer_stop(etTimer* self){ - KillTimer(NULL, self->osTimerId); + if (DeleteTimerQueueTimer(hTimerQueue, self->osTimerData, NULL) == FALSE){ + etLogger_logError("etTimer_stop: Timer could not be stopped"); + } } void etTimer_destruct(etTimer* self){ - /* no implementation needed for this operating system */ + /* TODO: destroy hTimerQueue if last timer is destroyed */ + /* DeleteTimerQueue(hTimerQueue); */ } diff --git a/tests/org.eclipse.etrice.runtime.c.tests/.cproject b/tests/org.eclipse.etrice.runtime.c.tests/.cproject index e456f50a9..5f4951153 100644 --- a/tests/org.eclipse.etrice.runtime.c.tests/.cproject +++ b/tests/org.eclipse.etrice.runtime.c.tests/.cproject @@ -18,7 +18,7 @@ <folderInfo id="cdt.managedbuild.config.gnu.mingw.exe.debug.1638834921." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.mingw.exe.debug.26197628" name="MinGW GCC" superClass="cdt.managedbuild.toolchain.gnu.mingw.exe.debug">
<targetPlatform id="cdt.managedbuild.target.gnu.platform.mingw.exe.debug.1073090191" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.mingw.exe.debug"/>
- <builder buildPath="${workspace_loc:/org.eclipse.etrice.runtime.c.tests/Debug}" id="cdt.managedbuild.tool.gnu.builder.mingw.base.64789272" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="CDT Internal Builder" superClass="cdt.managedbuild.tool.gnu.builder.mingw.base"/>
+ <builder buildPath="${workspace_loc:/org.eclipse.etrice.runtime.c.tests/Debug}" id="cdt.managedbuild.tool.gnu.builder.mingw.base.64789272" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="CDT Internal Builder" parallelBuildOn="false" superClass="cdt.managedbuild.tool.gnu.builder.mingw.base"/>
<tool id="cdt.managedbuild.tool.gnu.assembler.mingw.exe.debug.1179559506" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.mingw.exe.debug">
<option id="gnu.both.asm.option.include.paths.216630259" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value=""${workspace_loc:/org.eclipse.etrice.runtime.c}""/>
@@ -123,6 +123,13 @@ <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
</scannerConfigBuildInfo>
</storageModule>
- <storageModule moduleId="refreshScope"/>
+ <storageModule moduleId="refreshScope" versionNumber="2">
+ <configuration configurationName="Release">
+ <resource resourceType="PROJECT" workspacePath="/org.eclipse.etrice.runtime.c.tests"/>
+ </configuration>
+ <configuration configurationName="Debug">
+ <resource resourceType="PROJECT" workspacePath="/org.eclipse.etrice.runtime.c.tests"/>
+ </configuration>
+ </storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
</cproject>
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(); } 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 86fa46b51..4bdbf94a6 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: 19
+tc end 1: 0
ts start: TestMemory
tc start 2: TestEtMemory_testFixedSize
-tc end 2: 9
+tc end 2: 15
tc start 3: TestEtMemory_testFreeList
-tc end 3: 2
+tc end 3: 0
ts start: TestMessage
tc start 4: TestEtMessage_testBasicMessage
tc end 4: 0
@@ -14,7 +14,7 @@ ts start: TestEtMessageQueue tc start 5: TestEtMessageQueue_testPushPop
tc end 5: 0
tc start 6: TestEtMessageQueue_testMassiveMessaging
-tc end 6: 9
+tc end 6: 0
ts start: TestEtUnit
tc start 7: TestEtUnit_Expect_Order
tc end 7: 0
@@ -22,4 +22,6 @@ tc start 8: TestEtUnit_Expect tc end 8: 0
ts start: TestEtTimer
tc start 9: TestEtTimer_lifecycle
-tc end 9: 11142
+tc end 9: 1513
+tc start 10: TestEtTimer_multiTimer
+tc end 10: 1014
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 e8abf2c61..78f14cc25 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 10: openAll and closeAll
-tc end 10: 0
+tc start 11: openAll and closeAll
+tc end 11: 0
|