Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2021-06-11 08:01:19 +0000
committerJuergen Haug2021-07-09 10:45:48 +0000
commitb363530f2f9fb84dd033e63c6b4cf6f026ad3342 (patch)
treedd15f3d1a273b4ca8468e02f7c12c47c0b627b4a
parentd7109d6b1484d49556311ac012034b519ac1a54f (diff)
downloadorg.eclipse.etrice-b363530f2f9fb84dd033e63c6b4cf6f026ad3342.tar.gz
org.eclipse.etrice-b363530f2f9fb84dd033e63c6b4cf6f026ad3342.tar.xz
org.eclipse.etrice-b363530f2f9fb84dd033e63c6b4cf6f026ad3342.zip
Bug 573910 [runtime.c] etunit removed limit for test cases
* default is singleton test case mode, caseId is 0 * added switch for parallel testing with limited test cases * added more checks and asserts * updated tests, static config test requires 'parallel' cases * added ETUNIT_FAIL * fail unclosed test cases * fixes for order Change-Id: I0a670bf1c7045f721bc9802e1cea56dbbaf3a72b
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.c151
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.h62
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/etunit/EtUnit.java4
-rw-r--r--tests/org.eclipse.etrice.generator.c.tests/model/staticConfigTest/StaticConfigTest.room11
-rw-r--r--tests/org.eclipse.etrice.generator.c.tests/model/traceTest/TraceTest.room55
-rw-r--r--tests/org.eclipse.etrice.generator.common.tests/model/actorCommunicationTest/ActorCommunicationTest.room1
-rw-r--r--tests/org.eclipse.etrice.generator.common.tests/model/dataDrivenTest/DataDrivenTest.room14
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/build.gradle5
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/src/runtime/RunCRuntimeTestcases.c23
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtUnit.c37
10 files changed, 268 insertions, 95 deletions
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 c8ebfe68a..303d6acda 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
@@ -16,6 +16,7 @@
#include <string.h>
#include <time.h>
#include <stdlib.h>
+#include <assert.h>
#include "debugging/etLogger.h"
#include "osal/etSema.h"
#include "runtime/etRuntime.h"
@@ -30,8 +31,10 @@ static FILE* etUnit_reportfile = NULL;
static etInt16 etUnit_nextCaseId;
static etInt32 etUnit_errorCounter;
-#define ETUNIT_MAX_TEST_CASES 512
-static etBool etUnit_testcaseSuccess[ETUNIT_MAX_TEST_CASES];
+static etBool etUnit_parallelTestCases = ET_FALSE;
+#define ETUNIT_MAX_PARALLEL_TEST_CASES 5
+static etBool etUnit_testcaseSuccess[ETUNIT_MAX_PARALLEL_TEST_CASES];
+static etBool etUnit_testcaseOpen[ETUNIT_MAX_PARALLEL_TEST_CASES];
#define ETUNIT_FAILURE_TEXT_LEN 256
@@ -39,8 +42,35 @@ static etBool etUnit_testcaseSuccess[ETUNIT_MAX_TEST_CASES];
static etTime etUnit_startTime;
static etTime etUnit_lastTestCaseTime;
-etInt16 getCurrentEtUnitId() {
- return etUnit_nextCaseId - 1;
+
+/*
+ * Returns index to store current test case state
+ * - 'caseId' for parallel test cases
+ * - 0 for singleton test case
+ */
+static etInt16 getParallelIndex(etInt16 caseId) {
+ etInt16 idx = (etUnit_parallelTestCases) ? caseId - 1 : 0;
+ assert(idx >= 0 && idx < ETUNIT_MAX_PARALLEL_TEST_CASES);
+ return idx;
+}
+
+/* Lookup valid open test case id */
+static etInt16 getOpenTestCaseId(etInt16 id) {
+ etInt16 caseId;
+ if (etUnit_parallelTestCases) {
+ // index is id of parallel test case
+ assert(id > 0);
+ caseId = id;
+ } else {
+ // index is 0, return current open test case
+ assert(id == 0);
+ caseId = etUnit_nextCaseId - 1;
+ }
+ if(!etUnit_testcaseOpen[getParallelIndex(caseId)]) {
+ etLogger_logErrorF("Test case was not opened");
+ }
+
+ return caseId;
}
/* order */
@@ -49,14 +79,14 @@ typedef struct OrderInfo {
etInt16 id;
etInt16 currentIndex;
etInt16 size;
- etInt16* list;
+ const etInt16* list;
} OrderInfo;
static OrderInfo etUnit_orderInfo[ETUNIT_ORDER_MAX];
static OrderInfo* getOrderInfo(etInt16 id) {
- int i;
- for (i = 0; i < ETUNIT_ORDER_MAX; ++i)
- if (etUnit_orderInfo[i].id == id)
+ etInt16 caseId = getOpenTestCaseId(id);
+ for (int i = 0; i < ETUNIT_ORDER_MAX; ++i)
+ if (etUnit_orderInfo[i].id == caseId)
return etUnit_orderInfo + i;
return NULL;
@@ -89,6 +119,11 @@ static void expect_range_float(etInt16 id, const char* message, etUnitFloat min,
static void etUnit_handleExpect(etInt16 id, etBool result, const char *trace, const char* expected, const char* actual, const char* file, int line);
+/* configuration functions */
+
+void etUnit_setParallelTestCases(etBool enabled) {
+ etUnit_parallelTestCases = enabled;
+}
/* public functions */
void etUnit_open(const char* testResultPath, const char* testFileName) {
@@ -96,7 +131,6 @@ void etUnit_open(const char* testResultPath, const char* testFileName) {
{
char filename[ETUNIT_FAILURE_TEXT_LEN];
- int i;
if (testResultPath != NULL)
snprintf(filename, sizeof(filename), "%s/%s.etu", testResultPath, testFileName);
@@ -104,10 +138,13 @@ void etUnit_open(const char* testResultPath, const char* testFileName) {
snprintf(filename, sizeof(filename),"%s.etu", testFileName);
/* init global data */
- for (i = 0; i < ETUNIT_ORDER_MAX; ++i)
+ for (int i = 0; i < ETUNIT_ORDER_MAX; ++i) {
etUnit_orderInfo[i].id = 0;
- for (i = 0; i < ETUNIT_MAX_TEST_CASES; ++i)
+ }
+ for (int i = 0; i < ETUNIT_MAX_PARALLEL_TEST_CASES; ++i) {
etUnit_testcaseSuccess[i] = ET_TRUE;
+ etUnit_testcaseOpen[i] = ET_FALSE;
+ }
etUnit_errorCounter = 0;
etUnit_nextCaseId = 1;
@@ -150,14 +187,16 @@ void etUnit_openTestSuite(const char* testSuiteName) {
void etUnit_closeTestSuite(void) {
}
+/* Opens new test case, if parallel is activated returns new test case id otherwise 0*/
etInt16 etUnit_openTestCase(const char* testCaseName) {
+ if(etUnit_nextCaseId >= INT16_MAX) {
+ etLogger_logErrorF("Too many test cases. Maximum number is %d", INT16_MAX);
+ exit(-1);
+ }
etInt16 caseId = etUnit_nextCaseId++;
-
- if (caseId >= ETUNIT_MAX_TEST_CASES) {
- etLogger_logErrorF("Too many test cases. Maximum number of test cases is %d\n",
- ETUNIT_MAX_TEST_CASES);
- etLogger_logErrorF("ETUNIT_MAX_TEST_CASES (etUnit_openTestCase, %s: %d)", __FILE__,
- __LINE__);
+ etInt16 idx = getParallelIndex(caseId);
+ if (etUnit_parallelTestCases && idx >= ETUNIT_MAX_PARALLEL_TEST_CASES) {
+ etLogger_logErrorF("Too many parallel test cases. Maximum number is %d", ETUNIT_MAX_PARALLEL_TEST_CASES);
exit(-1);
}
if (etUnit_reportfile != NULL) {
@@ -165,28 +204,42 @@ etInt16 etUnit_openTestCase(const char* testCaseName) {
getTimeFromTarget(&etUnit_lastTestCaseTime);
}
- return caseId;
+
+ if(etUnit_testcaseOpen[idx]) {
+ etLogger_logErrorF("Previous test case was not closed");
+ EXPECT_FAIL(idx, "Test case was not closed");
+ }
+ etUnit_testcaseOpen[idx] = ET_TRUE;
+ etUnit_testcaseSuccess[idx] = ET_TRUE;
+
+ return (etUnit_parallelTestCases) ? caseId : 0;
}
void etUnit_closeTestCase(etInt16 id) {
+ // clear order
OrderInfo* info = getOrderInfo(id);
- if(info != NULL){
+ if(info != NULL) {
if (info->currentIndex != info->size) {
- etUnit_handleExpect(id, ET_FALSE, "EXPECT_ORDER was not completed", NULL, NULL, 0, 0);
+ EXPECT_FAIL(id, "EXPECT_ORDER was not completed");
}
+ info->id = 0;
}
+ etInt16 caseId = getOpenTestCaseId(id);
+ etInt16 parallelId = getParallelIndex(caseId);
+ etUnit_testcaseOpen[parallelId] = ET_FALSE;
if (etUnit_reportfile != NULL) {
etTime time;
getTimeFromTarget(&time);
etTimeHelpers_subtract(&time, &etUnit_lastTestCaseTime);
- etLogger_fprintf(etUnit_reportfile, "tc end %d: %d\n", id, etTimeHelpers_convertToMSec(&time));
+ etLogger_fprintf(etUnit_reportfile, "tc end %d: %d\n", caseId, etTimeHelpers_convertToMSec(&time));
}
}
void etUnit_skipTestCase(etInt16 id, const char* msg) {
+ etInt16 caseId = getOpenTestCaseId(id);
if (etUnit_reportfile != NULL) {
- etLogger_fprintf(etUnit_reportfile, "tc skip %d: %s\n", id, msg);
+ etLogger_fprintf(etUnit_reportfile, "tc skip %d: %s\n", caseId, msg);
}
}
@@ -226,6 +279,12 @@ void expectFalse(etInt16 id, const char* message, etBool condition, const char*
}
}
+void expectFail(etInt16 id, const char* message, const char* file, int line) {
+ char testresult[ETUNIT_FAILURE_TEXT_LEN];
+ snprintf(testresult, sizeof(testresult), "%s: EXPECT_FAILED", message);
+ etUnit_handleExpect(id, ET_FALSE, testresult, "NO_FAIL", "FAIL", file, line);
+}
+
void expectEqualInt8(etInt16 id, const char* message, etInt8 expected, etInt8 actual, const char* file, int line) {
expect_equal_int(id, message, (etInt32) expected, (etInt32) actual, file, line);
}
@@ -293,16 +352,24 @@ void expectRangeFloat64(etInt16 id, const char* message, etFloat64 min, etFloat6
}
#endif
-void expectOrderStart(etInt16 id, etInt16* list, etInt16 size, const char* file, int line) {
- int i;
- for (i = 0; i < ETUNIT_ORDER_MAX; ++i)
+void expectOrderStart(etInt16 id, const etInt16* list, etInt16 size, const char* file, int line) {
+ etInt16 caseId = getOpenTestCaseId(id);
+ for (int i = 0; i < ETUNIT_ORDER_MAX; ++i) {
+ if (etUnit_orderInfo[i].id == caseId) {
+ EXPECT_FAIL(id, "previous expect order was not closed");
+ etUnit_orderInfo[i].id = 0;
+ }
+ }
+ for (int i = 0; i < ETUNIT_ORDER_MAX; ++i) {
if (etUnit_orderInfo[i].id == 0) {
- etUnit_orderInfo[i].id = id;
+ etUnit_orderInfo[i].id = caseId;
etUnit_orderInfo[i].currentIndex = 0;
etUnit_orderInfo[i].size = size;
etUnit_orderInfo[i].list = list;
- break;
+ return;
}
+ }
+ EXPECT_FAIL(id, "cannot start order, maximum opened orders reached");
}
void expectOrder(etInt16 id, const char* message, etInt16 identifier, const char* file, int line) {
@@ -327,21 +394,26 @@ void expectOrder(etInt16 id, const char* message, etInt16 identifier, const char
etUnit_handleExpect(id, ET_FALSE, testresult, NULL, NULL, file, line);
etLogger_logInfoF("EXPECT_ORDER: index too big in %s", message);
}
+ } else {
+ EXPECT_FAIL(id, "no order info found");
}
}
void expectOrderEnd(etInt16 id, const char* message, etInt16 identifier, const char* file, int line) {
- OrderInfo* info = getOrderInfo(id);
expectOrder(id, message, identifier, file, line);
- if (info->currentIndex != info->size) {
- char testresult[ETUNIT_FAILURE_TEXT_LEN];
- snprintf(testresult, sizeof(testresult), "EXPECT_ORDER_END %s: wrong index at the end: expected=%d, actual=%d", message, info->size, info->currentIndex);
- etUnit_handleExpect(id, ET_FALSE, testresult, NULL, NULL, file, line);
+ OrderInfo* info = getOrderInfo(id);
+ if (info != NULL) {
+ if(info->currentIndex != info->size) {
+ char testresult[ETUNIT_FAILURE_TEXT_LEN];
+ snprintf(testresult, sizeof(testresult), "EXPECT_ORDER_END %s: wrong index at the end: expected=%d, actual=%d", message, info->size, info->currentIndex);
+ etUnit_handleExpect(id, ET_FALSE, testresult, NULL, NULL, file, line);
+ }
+ info->id = 0;
}
}
etBool etUnit_isSuccess(etInt16 id) {
- return etUnit_testcaseSuccess[id];
+ return etUnit_testcaseSuccess[getParallelIndex(id)];
}
/* private functions */
@@ -446,18 +518,21 @@ static void expect_range_float(etInt16 id, const char* message, etUnitFloat min,
#endif
static void etUnit_handleExpect(etInt16 id, etBool result, const char *resulttext, const char* exp, const char* act, const char* file, int line) {
+ // check open
+ etInt16 caseId = getOpenTestCaseId(id);
if (result == ET_TRUE) {
/* nothing to do because no failure */
} else {
etUnit_errorCounter++;
- if (etUnit_testcaseSuccess[id] == ET_TRUE) {
+ etInt16 parallelId = getParallelIndex(caseId);
+ if (etUnit_testcaseSuccess[parallelId] == ET_TRUE) {
/* first failure will be remembered */
- etUnit_testcaseSuccess[id] = ET_FALSE;
-
+ etUnit_testcaseSuccess[parallelId] = ET_FALSE;
+
if (act != NULL && exp != NULL)
- etLogger_fprintf(etUnit_reportfile, "tc fail %d: #%s#%s#%s:%d#%s\n", id, exp, act, file, line, resulttext);
+ etLogger_fprintf(etUnit_reportfile, "tc fail %d: #%s#%s#%s:%d#%s\n", caseId, exp, act, file, line, resulttext);
else
- etLogger_fprintf(etUnit_reportfile, "tc fail %d: ###%s:%d#%s\n", id, file, line, resulttext);
+ etLogger_fprintf(etUnit_reportfile, "tc fail %d: ###%s:%d#%s\n", caseId, file, line, resulttext);
} else {
/* more than one error will be ignored */
}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.h b/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.h
index e666b00b0..1d373280f 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.h
@@ -33,6 +33,8 @@ ET_EXTERN_C_BEGIN
// compile time evaluated
#define ETUNIT_FILENAME (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__))
+typedef void (*etUnit_WriteFunction)(void* handle, const char* format, ...);
+
/**
* opens a file to protocol the test results
*
@@ -55,12 +57,20 @@ void etUnit_openTestSuite(const char* testSuiteName);
*/
void etUnit_closeTestSuite(void);
/**
+ * enable support for parallel test cases (default false)
+ */
+void etUnit_setParallelTestCases(etBool enabled);
+/**
+ * write etunit output to callback
+ */
+void etUnit_setWriteFunction(etUnit_WriteFunction fct);
+/**
* opens a test case. Multiple test cases can be open at a time
*
* \param testCaseName the name of the test case
*
- * \return an id for the test case which has to be used as an identifier
- * for the expect... and other methods
+ * \return in case of parallel testing an id which has to be used as an identifier
+ * for the expects and other methods, otherwise zero
*/
etInt16 etUnit_openTestCase(const char* testCaseName);
/**
@@ -115,12 +125,12 @@ void etUnit_closeAll(etInt16 id);
* boolean values
*/
-/**
- * calls \ref expectTrue()
- */
+/** calls \ref expectTrue() */
#define EXPECT_TRUE(id, msg, condition) expectTrue(id, msg, condition, ETUNIT_FILENAME, __LINE__)
/** calls \ref expectFalse() */
#define EXPECT_FALSE(id, msg, condition) expectFalse(id, msg, condition, ETUNIT_FILENAME, __LINE__)
+/** calls \ref expectFail() */
+#define EXPECT_FAIL(id, msg) expectFail(id, msg, ETUNIT_FILENAME, __LINE__)
/*
* signed integer values
@@ -186,6 +196,37 @@ void etUnit_closeAll(etInt16 id);
/*
+ * Alternative expects omitting id argument (without parallel testing)
+ */
+
+#define ETUNIT_TRUE(msg, condition) expectTrue(0, msg, condition, ETUNIT_FILENAME, __LINE__)
+#define ETUNIT_FALSE(msg, condition) expectFalse(0, msg, condition, ETUNIT_FILENAME, __LINE__)
+#define ETUNIT_FAIL(msg) expectFail(0, msg, ETUNIT_FILENAME, __LINE__)
+
+#define ETUNIT_EQUAL_INT(msg, expected, actual) expectEqualInt32(0, msg, expected, actual, ETUNIT_FILENAME, __LINE__)
+#define ETUNIT_EQUAL_UINT(msg, expected, actual) expectEqualUInt32(0, msg, expected, actual, ETUNIT_FILENAME, __LINE__)
+
+#ifdef ET_FLOAT32
+#define ETUNIT_EQUAL_FLOAT32(msg, expected, actual, precision) expectEqualFloat32(0, msg, expected, actual, precision, ETUNIT_FILENAME, __LINE__)
+#define ETUNIT_RANGE_FLOAT32(msg, min, max, actual) expectRangeFloat32(0, msg, min, max, actual, ETUNIT_FILENAME, __LINE__)
+#endif
+
+#ifdef ET_FLOAT64
+#define ETUNIT_EQUAL_FLOAT64(msg, expected, actual, precision) expectEqualFloat64(0, msg, expected, actual, precision, ETUNIT_FILENAME, __LINE__)
+#define ETUNIT_RANGE_FLOAT64(msg, min, max, actual) expectRangeFloat64(0, msg, min, max, actual, ETUNIT_FILENAME, __LINE__)
+#endif
+
+#define ETUNIT_EQUAL_PTR(msg, expected, actual) \
+ expect_equal_void_ptr(ETUNIT_SINGLETON_TEST_CASE_ID, msg, (const void*) expected, (const void*) actual, ETUNIT_FILENAME, __LINE__)
+
+#define ETUNIT_EQUAL_STR(msg, expected, actual) expectEqualStr(0, msg, expected, actual, ETUNIT_FILENAME, __LINE__)
+
+#define ETUNIT_ORDER_START(list, size) expectOrderStart(0, list, size, ETUNIT_FILENAME, __LINE__)
+#define ETUNIT_ORDER(msg, val) expectOrder(0, msg, val, ETUNIT_FILENAME, __LINE__)
+#define ETUNIT_ORDER_END(msg, val) expectOrderEnd(0, msg, val, ETUNIT_FILENAME, __LINE__)
+
+
+/*
* Helpers for adding test cases
*/
@@ -225,6 +266,15 @@ void expectTrue(etInt16 id, const char* msg, etBool condition, const char* file,
*/
void expectFalse(etInt16 id, const char* msg, etBool condition, const char* file, int line);
/**
+ * reports an fail
+ *
+ * \param id the test case id
+ * \param msg the result message
+ * \param file the file name with the test case
+ * \param line the line
+ */
+void expectFail(etInt16 id, const char* msg, const char* file, int line);
+/**
* reports an error if two integers aren't equal
*
* \param id the test case id
@@ -398,7 +448,7 @@ void expectEqualStr(etInt16 id, const char* msg, const char* expected, const cha
* \param file the file name with the test case
* \param line the line
*/
-void expectOrderStart(etInt16 id, etInt16* list, etInt16 size, const char* file, int line);
+void expectOrderStart(etInt16 id, const etInt16* list, etInt16 size, const char* file, int line);
/**
* reports an error if the identifier doesn't match the next value in the list
*
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/etunit/EtUnit.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/etunit/EtUnit.java
index 5614eff19..8571fbb13 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/etunit/EtUnit.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/etunit/EtUnit.java
@@ -339,5 +339,9 @@ public class EtUnit {
}
}
}
+
+ public static void etUnit_setParallelTestCases(boolean enabled) {
+ // c api only
+ }
}
diff --git a/tests/org.eclipse.etrice.generator.c.tests/model/staticConfigTest/StaticConfigTest.room b/tests/org.eclipse.etrice.generator.c.tests/model/staticConfigTest/StaticConfigTest.room
index fe886ae5d..1b438f766 100644
--- a/tests/org.eclipse.etrice.generator.c.tests/model/staticConfigTest/StaticConfigTest.room
+++ b/tests/org.eclipse.etrice.generator.c.tests/model/staticConfigTest/StaticConfigTest.room
@@ -33,11 +33,14 @@ RoomModel StaticConfigTest {
}
Behavior {
ctor '''
+ etUnit_setParallelTestCases(true);
etUnit_open("log", "StaticConfigTest");
- etUnit_openTestSuite("org.eclipse.etrice.generator.c.tests.StaticConfigTest");'''
+ etUnit_openTestSuite("org.eclipse.etrice.generator.c.tests.StaticConfigTest");
+ '''
dtor '''
etUnit_closeTestSuite();
- etUnit_close();'''
+ etUnit_close();
+ '''
StateMachine {
Transition init: initial -> state0 {
action '''timer.startTimeout(1000);'''
@@ -46,7 +49,9 @@ RoomModel StaticConfigTest {
triggers {
<timeout: timer>
}
- action '''etUnit_testFinished(-1);'''
+ action '''
+ etUnit_testFinished(-1);
+ '''
}
State state0
}
diff --git a/tests/org.eclipse.etrice.generator.c.tests/model/traceTest/TraceTest.room b/tests/org.eclipse.etrice.generator.c.tests/model/traceTest/TraceTest.room
index 2254c992d..cf544f425 100644
--- a/tests/org.eclipse.etrice.generator.c.tests/model/traceTest/TraceTest.room
+++ b/tests/org.eclipse.etrice.generator.c.tests/model/traceTest/TraceTest.room
@@ -23,9 +23,6 @@ RoomModel TraceTest {
// override etRuntimeConfig
#define ET_MSC_TRACER_ACTIVATE
- etInt16 getCurrentEtUnitId();
-
- #define etUnitId getCurrentEtUnitId()
#define GENMODEL_objId(id) (id - 2)
#define GENMODEL_msgId(id) (id - 1)
'''
@@ -52,32 +49,32 @@ RoomModel TraceTest {
// mocks
void etMSCTracer_asyncOut(uint16 peerObjId, uint8 msgId) {
printf("%d, %d, %d\n", ASYNC_OUT, peerObjId, msgId);
- EXPECT_ORDER(etUnitId, "etMSCTracer_asyncOut", ASYNC_OUT);
- EXPECT_ORDER(etUnitId, "etMSCTracer_asyncOut_peerObjId", peerObjId);
- EXPECT_ORDER(etUnitId, "etMSCTracer_asyncOut_msgId", msgId);
+ ETUNIT_ORDER("etMSCTracer_asyncOut", ASYNC_OUT);
+ ETUNIT_ORDER("etMSCTracer_asyncOut_peerObjId", peerObjId);
+ ETUNIT_ORDER("etMSCTracer_asyncOut_msgId", msgId);
}
void etMSCTracer_asyncBroadcast(uint16 peerObjId, uint8 msgId) {
printf("%d, %d, %d\n", ASYNC_BCAST, peerObjId, msgId);
- EXPECT_ORDER(etUnitId, "etMSCTracer_asyncBCast", ASYNC_BCAST);
- EXPECT_ORDER(etUnitId, "etMSCTracer_asyncBCast_peerObjId", peerObjId);
- EXPECT_ORDER(etUnitId, "etMSCTracer_asyncBCast_msgId", msgId);
+ ETUNIT_ORDER("etMSCTracer_asyncBCast", ASYNC_BCAST);
+ ETUNIT_ORDER("etMSCTracer_asyncBCast_peerObjId", peerObjId);
+ ETUNIT_ORDER("etMSCTracer_asyncBCast_msgId", msgId);
}
void etMSCTracer_asyncIn(uint16 peerObjId, uint8 msgId) {
printf("%d, %d, %d\n", ASYNC_IN, peerObjId, msgId);
- EXPECT_ORDER(etUnitId, "etMSCTracer_asyncIn", ASYNC_IN);
- EXPECT_ORDER(etUnitId, "etMSCTracer_asyncIn_peerObjId", peerObjId);
- EXPECT_ORDER(etUnitId, "etMSCTracer_asyncIn_msgId", msgId);
+ ETUNIT_ORDER("etMSCTracer_asyncIn", ASYNC_IN);
+ ETUNIT_ORDER("etMSCTracer_asyncIn_peerObjId", peerObjId);
+ ETUNIT_ORDER("etMSCTracer_asyncIn_msgId", msgId);
}
void etMSCTracer_setState(uint16 objId, uint8 stateId) {
printf("%d, %d, %d\n", STATE_CH, objId, stateId);
- EXPECT_ORDER(etUnitId, "etMSCTracer_setState", STATE_CH);
- EXPECT_ORDER(etUnitId, "etMSCTracer_setState_objId", objId);
- EXPECT_ORDER(etUnitId, "etMSCTracer_setState_stateId", stateId);
+ ETUNIT_ORDER("etMSCTracer_setState", STATE_CH);
+ ETUNIT_ORDER("etMSCTracer_setState_objId", objId);
+ ETUNIT_ORDER("etMSCTracer_setState_stateId", stateId);
}
void etMSCTracer_setNote(uint16 objId, const char *text) {
printf("%d, %d, %s\n", STATE_CH, objId, text);
- EXPECT_ORDER(etUnitId, "etMSCTracer_setState", ACTOR_NOTE);
- EXPECT_ORDER(etUnitId, "etMSCTracer_setState_objId", objId);
+ ETUNIT_ORDER("etMSCTracer_setState", ACTOR_NOTE);
+ ETUNIT_ORDER("etMSCTracer_setState_objId", objId);
}
'''
SAP timer: PTimer
@@ -92,8 +89,8 @@ RoomModel TraceTest {
etUnit_openAll("log", "TraceTest", "org.eclipse.etrice.generator.c.tests.TraceTest", "TraceTest_case");
// expect stable ordered ids, ids have to match with genmodel
- EXPECT_EQUAL_INT32(etUnitId, "<|MODEL_LOCATION|>", 0, GENMODEL_msgId(PingPongProtocol_OUT_pong));
- EXPECT_EQUAL_INT32(etUnitId, "<|MODEL_LOCATION|>", 1, GENMODEL_msgId(PingPongProtocol_IN_ping));
+ ETUNIT_EQUAL_INT("<|MODEL_LOCATION|>", 0, GENMODEL_msgId(PingPongProtocol_OUT_pong));
+ ETUNIT_EQUAL_INT("<|MODEL_LOCATION|>", 1, GENMODEL_msgId(PingPongProtocol_IN_ping));
#define topActorObjId 1
#define senderObjId 3
@@ -131,11 +128,11 @@ RoomModel TraceTest {
STATE_CH, senderObjId, 5, // next state
99
};
- EXPECT_ORDER_START(etUnitId, resultlist, sizeof(resultlist) / sizeof(int16));
+ ETUNIT_ORDER_START(resultlist, sizeof(resultlist) / sizeof(int16));
'''
dtor '''
- EXPECT_ORDER_END(etUnitId, "TopActor_dtor", 99);
- etUnit_closeAll(etUnitId);
+ ETUNIT_ORDER_END("TopActor_dtor", 99);
+ etUnit_closeAll(0);
'''
}
}
@@ -155,13 +152,13 @@ RoomModel TraceTest {
Behavior {
ctor '''
// expect stable ordered ids, ids have to match with genmodel
- EXPECT_EQUAL_INT32(etUnitId, "<|MODEL_LOCATION|>", 0, GENMODEL_objId(STATE_receiveBroadcast));
+ ETUNIT_EQUAL_INT("<|MODEL_LOCATION|>", 0, GENMODEL_objId(STATE_receiveBroadcast));
// leaf states
- EXPECT_EQUAL_INT32(etUnitId, "<|MODEL_LOCATION|>", 1, GENMODEL_objId(STATE_startPing));
- EXPECT_EQUAL_INT32(etUnitId, "<|MODEL_LOCATION|>", 2, GENMODEL_objId(STATE_sendRepl));
- EXPECT_EQUAL_INT32(etUnitId, "<|MODEL_LOCATION|>", 3, GENMODEL_objId(STATE_sendBroadcast));
- EXPECT_EQUAL_INT32(etUnitId, "<|MODEL_LOCATION|>", 4, GENMODEL_objId(STATE_receiveBroadcast_recv1));
- EXPECT_EQUAL_INT32(etUnitId, "<|MODEL_LOCATION|>", 5, GENMODEL_objId(STATE_final));
+ ETUNIT_EQUAL_INT("<|MODEL_LOCATION|>", 1, GENMODEL_objId(STATE_startPing));
+ ETUNIT_EQUAL_INT("<|MODEL_LOCATION|>", 2, GENMODEL_objId(STATE_sendRepl));
+ ETUNIT_EQUAL_INT("<|MODEL_LOCATION|>", 3, GENMODEL_objId(STATE_sendBroadcast));
+ ETUNIT_EQUAL_INT("<|MODEL_LOCATION|>", 4, GENMODEL_objId(STATE_receiveBroadcast_recv1));
+ ETUNIT_EQUAL_INT("<|MODEL_LOCATION|>", 5, GENMODEL_objId(STATE_final));
'''
StateMachine {
Transition init0: initial -> startPing {
@@ -241,7 +238,7 @@ RoomModel TraceTest {
Behavior {
ctor '''
// expect stable ordered ids, ids have to match with genmodel
- EXPECT_EQUAL_INT32(etUnitId, "<|MODEL_LOCATION|>", 0, GENMODEL_objId(STATE_state0));
+ ETUNIT_EQUAL_INT("<|MODEL_LOCATION|>", 0, GENMODEL_objId(STATE_state0));
'''
StateMachine {
State state0
diff --git a/tests/org.eclipse.etrice.generator.common.tests/model/actorCommunicationTest/ActorCommunicationTest.room b/tests/org.eclipse.etrice.generator.common.tests/model/actorCommunicationTest/ActorCommunicationTest.room
index ce652356a..dc0f585c4 100644
--- a/tests/org.eclipse.etrice.generator.common.tests/model/actorCommunicationTest/ActorCommunicationTest.room
+++ b/tests/org.eclipse.etrice.generator.common.tests/model/actorCommunicationTest/ActorCommunicationTest.room
@@ -65,6 +65,7 @@ RoomModel ActorCommunicationTest {
}
Behavior {
ctor '''
+ etUnit_setParallelTestCases(true);
etUnit_open("log", "ActorCommunicationTest");
etUnit_openTestSuite("org.eclipse.etrice.generator.common.tests.ActorCommunicationTest");'''
dtor '''
diff --git a/tests/org.eclipse.etrice.generator.common.tests/model/dataDrivenTest/DataDrivenTest.room b/tests/org.eclipse.etrice.generator.common.tests/model/dataDrivenTest/DataDrivenTest.room
index b5889c9f2..7ee720e06 100644
--- a/tests/org.eclipse.etrice.generator.common.tests/model/dataDrivenTest/DataDrivenTest.room
+++ b/tests/org.eclipse.etrice.generator.common.tests/model/dataDrivenTest/DataDrivenTest.room
@@ -42,7 +42,7 @@ RoomModel DataDrivenTest {
Transition init: initial -> Idle {
action '''
timer.startTimer(300);
- counter = 0;'''
+ counter = 1;'''
}
Transition tr0: Idle -> Idle {
triggers {
@@ -68,24 +68,26 @@ RoomModel DataDrivenTest {
Attribute resultlist [10]: int16 = "{1,2,3,4,5,6,7,8,9,10}"
}
Behavior {
- ctor '''caseId = etUnit_openAll("log", "DataDrivenTest", "org.eclipse.etrice.generator.common.tests.DataDrivenTest", "DataDrivenTest_case");'''
+ ctor '''
+ caseId = etUnit_openAll("log", "DataDrivenTest", "org.eclipse.etrice.generator.common.tests.DataDrivenTest", "DataDrivenTest_case");
+ EXPECT_ORDER_START(caseId, resultlist, 10);
+ '''
dtor '''etUnit_closeAll(caseId);'''
StateMachine {
Transition init: initial -> Idle {
- action '''counter = 0;'''
+ action '''counter = 1;'''
}
Transition tr0: Idle -> Idle {
guard '''p0.in1==counter'''
action '''
- if (p0.in1==1)
- EXPECT_ORDER_START(caseId, resultlist, 10);
if (p0.in1<10)
EXPECT_ORDER(caseId,"<|MODEL_LOCATION|>", p0.in1);
else if (counter==10) {
EXPECT_ORDER_END(caseId,"<|MODEL_LOCATION|>", 10);
etUnit_testFinished(caseId);
}
- ++counter;'''
+ ++counter;
+ '''
}
State Idle
}
diff --git a/tests/org.eclipse.etrice.runtime.c.tests/build.gradle b/tests/org.eclipse.etrice.runtime.c.tests/build.gradle
index ad6c20e01..684811d3d 100644
--- a/tests/org.eclipse.etrice.runtime.c.tests/build.gradle
+++ b/tests/org.eclipse.etrice.runtime.c.tests/build.gradle
@@ -34,7 +34,8 @@ model {
def exeFile = "$buildDir/exe/etrice_runtime_c_tests/etrice_runtime_c_tests"
def etuFileRuntimeTest = "$buildDir/log/TestCRuntime.etu"
-def etuFileEtUnitTest = "$buildDir/log/TestEtUnitSpecial.etu"
+def etuFileEtUnitTest = "$buildDir/log/TestEtUnit.etu"
+def etuFileEtUnitSpecialTest = "$buildDir/log/TestEtUnitSpecial.etu"
task run(type: Exec, dependsOn: assemble, group: 'verification') {
executable exeFile
@@ -44,7 +45,7 @@ task run(type: Exec, dependsOn: assemble, group: 'verification') {
etunitConvert {
convert {
- source etuFileRuntimeTest, etuFileEtUnitTest
+ source etuFileRuntimeTest, etuFileEtUnitTest, etuFileEtUnitSpecialTest
dependsOn run
}
}
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 99036799c..e99acd931 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
@@ -39,10 +39,20 @@
#include "etUnit/etUnit.h"
#include "debugging/etMSCLogger.h"
-
+#include "debugging/etLogger.h"
void RunCRuntimeTestcases(void){
- etInt16 id;
+ // test etUnit
+ etUnit_open("log","TestEtUnit");
+ TestEtUnit_runSuite();
+ etUnit_close();
+
+ /* special situation for testing openAll and closeAll of etUnit
+ * this has to be done outside of etUnit_open and etUnit_close */
+ int id = etUnit_openAll("log","TestEtUnitSpecial", "org.eclipse.etrice.runtime.c.tests.etUnit", "openAll_and_closeAll");
+ ETUNIT_EQUAL_INT("Open and Close", 0, id);
+ etUnit_closeAll(id);
+
etMSCLogger_open("log", "test.log");
etUnit_open("log","TestCRuntime");
@@ -51,23 +61,14 @@ void RunCRuntimeTestcases(void){
TestEtMessage_runSuite();
TestEtMessageQueue_runSuite();
TestEtMessageService_runSuite();
- TestEtUnit_runSuite();
TestEtTimer_runSuite();
TestEtDatatypes_runSuite();
TestEtTimeHelpers_runSuite();
TestUtil_runSuite();
TestEtConsoleLogger_runSuite();
-
TestEtStaticDeque_runSuite();
etUnit_close();
-
- /* special situation for testing openAll and closeAll of etUnit
- * this has to be done outside of etUnit_open and etUnit_close */
- id = etUnit_openAll("log","TestEtUnitSpecial", "org.eclipse.etrice.runtime.c.tests.etUnit", "openAll_and_closeAll");
- EXPECT_TRUE(id, "Open and Close", ET_TRUE);
- etUnit_closeAll(id);
-
etMSCLogger_close();
}
diff --git a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtUnit.c b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtUnit.c
index 15525b7d0..c1abf810a 100644
--- a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtUnit.c
+++ b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtUnit.c
@@ -23,6 +23,8 @@
#include "TestEtUnit.h"
#include "etUnit/etUnit.h"
+#include <assert.h>
+
void TestEtUnit_Expect(etInt16 id){
EXPECT_TRUE(id, "EXPECT_TRUE", ET_TRUE);
EXPECT_FALSE(id, "EXPECT_FALSE", ET_FALSE);
@@ -60,8 +62,43 @@ void TestEtUnit_Expect_Order(etInt16 id){
EXPECT_ORDER_END(id, "id=4", 4);
}
+void TestEtUnit_Parallel_TestCase(){
+ etUnit_setParallelTestCases(true);
+ {
+ etInt16 id1 = etUnit_openTestCase("Parallel_Tc_1");
+ etInt16 id2 = etUnit_openTestCase("Parallel_Tc_2");
+
+ assert(id1 > 0);
+ EXPECT_TRUE(id1, "id > 0", id1 > 0);
+ assert(id2 > 0);
+ EXPECT_TRUE(id2, "id > 0", id2 > 0);
+ assert(id2 == id1 + 1);
+ EXPECT_TRUE(id2, "id incremented", id2 == id1 + 1);
+
+ etUnit_closeTestCase(id1);
+ etUnit_closeTestCase(id2);
+ }
+ etUnit_setParallelTestCases(false);
+}
+
+void TestEtUnit_Singleton_TestCase(){
+ etInt16 id = etUnit_openTestCase("Singleton_Tc_1");
+ assert(id == 0);
+ ETUNIT_EQUAL_INT("id=0", id, 0);
+ etUnit_closeTestCase(0);
+
+ id = etUnit_openTestCase("Singleton_Tc_2");
+ assert(id == 0);
+ ETUNIT_FALSE("id=0", id);
+ etUnit_closeTestCase(0);
+}
+
+
void TestEtUnit_runSuite(void){
etUnit_openTestSuite("org.eclipse.etrice.runtime.c.tests.TestEtUnit");
+ // test parallel first due test case number restriction
+ TestEtUnit_Parallel_TestCase();
+ TestEtUnit_Singleton_TestCase();
ADD_TESTCASE(TestEtUnit_Expect_Order);
ADD_TESTCASE(TestEtUnit_Expect);
etUnit_closeTestSuite();

Back to the top