Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Schuetz2012-01-17 18:39:21 +0000
committerThomas Schuetz2012-01-17 18:39:21 +0000
commit3a48b46b2613b03230e97c909846244ba8034fb1 (patch)
treeeaee50dd5bd35c961deb7cb3741a29d09817f400 /runtime
parentaa4c792743f27f427be53a1e535c41907743c8db (diff)
downloadorg.eclipse.etrice-3a48b46b2613b03230e97c909846244ba8034fb1.tar.gz
org.eclipse.etrice-3a48b46b2613b03230e97c909846244ba8034fb1.tar.xz
org.eclipse.etrice-3a48b46b2613b03230e97c909846244ba8034fb1.zip
[runtime.c] added interface and implementation for portable logger
Diffstat (limited to 'runtime')
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/Debug/liborg.eclipse.etrice.runtime.c.abin61590 -> 91062 bytes
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/Release/liborg.eclipse.etrice.runtime.c.abin11248 -> 0 bytes
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/etDatatypes.h8
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/etLogger.c82
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/etLogger.h48
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/etUnit.c121
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/etUnit.h15
7 files changed, 239 insertions, 35 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/Debug/liborg.eclipse.etrice.runtime.c.a b/runtime/org.eclipse.etrice.runtime.c/Debug/liborg.eclipse.etrice.runtime.c.a
index 6d43fcbb1..2def3aaec 100644
--- a/runtime/org.eclipse.etrice.runtime.c/Debug/liborg.eclipse.etrice.runtime.c.a
+++ b/runtime/org.eclipse.etrice.runtime.c/Debug/liborg.eclipse.etrice.runtime.c.a
Binary files differ
diff --git a/runtime/org.eclipse.etrice.runtime.c/Release/liborg.eclipse.etrice.runtime.c.a b/runtime/org.eclipse.etrice.runtime.c/Release/liborg.eclipse.etrice.runtime.c.a
deleted file mode 100644
index 89c30a148..000000000
--- a/runtime/org.eclipse.etrice.runtime.c/Release/liborg.eclipse.etrice.runtime.c.a
+++ /dev/null
Binary files differ
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etDatatypes.h b/runtime/org.eclipse.etrice.runtime.c/src/etDatatypes.h
index e2622cbdf..f1edfa670 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/etDatatypes.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/etDatatypes.h
@@ -18,6 +18,8 @@
*
* */
+#include <stdio.h>
+
/* unsigned integer datatypes */
typedef unsigned char uint8;
typedef unsigned short int uint16;
@@ -45,11 +47,11 @@ typedef char boolean; /* TODO: bool, Bool, Boolean, and boolean are already def
#endif
/*
- * typedefs for Runtime and Testing
+ * typedefs for eTrice Runtime and Testing
*
* */
-typedef uint8 etInt8;
+typedef int8 etInt8;
typedef int16 etInt16;
typedef int32 etInt32;
@@ -62,4 +64,6 @@ typedef boolean etBool;
typedef float32 etFloat32;
typedef float64 etFloat64;
+typedef FILE* etFileHandle;
+
#endif /* _DATATYPES_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etLogger.c b/runtime/org.eclipse.etrice.runtime.c/src/etLogger.c
new file mode 100644
index 000000000..bbba4a628
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.c/src/etLogger.c
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+/*
+ * etLogger.c
+ *
+ * Created on: 16.01.2012
+ * Author: tschuetz
+ */
+
+
+#include "etLogger.h"
+
+#include <stdarg.h>
+
+
+void etLogger_logError(const char* message){
+ printf("ERROR: %s", message);
+ printf("\n");
+}
+
+void etLogger_logWarning(const char* message){
+ printf("WARNING: %s", message);
+ printf("\n");
+}
+
+void etLogger_logInfo(const char* message){
+ printf("INFO: %s", message);
+ printf("\n");
+}
+
+void etLogger_logErrorF(const char* format, ... ){
+ printf("ERROR: ");
+ va_list arglist;
+ va_start( arglist, format );
+ vprintf( format, arglist );
+ va_end( arglist );
+ printf("\n");
+}
+
+void etLogger_logWarningF(const char* format, ... ){
+ printf("WARNING: ");
+ va_list arglist;
+ va_start( arglist, format );
+ vprintf( format, arglist );
+ va_end( arglist );
+ printf("\n");
+}
+
+void etLogger_logInfoF(const char* format, ... ){
+ printf("INFO: ");
+ va_list arglist;
+ va_start( arglist, format );
+ vprintf( format, arglist );
+ va_end( arglist );
+ printf("\n");
+}
+
+etFileHandle etLogger_fopen(const char* filename, const char* mode){
+ return( fopen(filename, mode) );
+}
+
+int etLogger_fclose(etFileHandle file){
+ return( fclose(file) );
+}
+
+void etLogger_fprintf(etFileHandle file, const char* format, ... ){
+ va_list arglist;
+ va_start( arglist, format );
+ vfprintf(file, format, arglist );
+ va_end( arglist );
+
+}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etLogger.h b/runtime/org.eclipse.etrice.runtime.c/src/etLogger.h
new file mode 100644
index 000000000..b353e6f1a
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.c/src/etLogger.h
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+/*
+ * etLogger.h
+ *
+ * Created on: 16.01.2012
+ * Author: tschuetz
+ */
+
+#ifndef _ETLOGGER_H_
+#define _ETLOGGER_H_
+
+#include <stdio.h>
+#include "etDatatypes.h"
+/* logging */
+
+void etLogger_logError(const char* message);
+
+void etLogger_logWarning(const char* message);
+
+void etLogger_logInfo(const char* message);
+
+void etLogger_logErrorF(const char* format, ... );
+
+void etLogger_logWarningF(const char* format, ... );
+
+void etLogger_logInfoF(const char* format, ... );
+
+
+/* File handling */
+
+etFileHandle etLogger_fopen(const char* filename, const char* mode);
+
+int etLogger_fclose(etFileHandle file);
+
+void etLogger_fprintf(etFileHandle file, const char* format, ... );
+
+#endif /* _ETLOGGER_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etUnit.c b/runtime/org.eclipse.etrice.runtime.c/src/etUnit.c
index 3fc5e70b6..30460e278 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/etUnit.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/etUnit.c
@@ -12,6 +12,9 @@
#include "etUnit.h"
#include <string.h>
+#include <time.h>
+#include "etLogger.h"
+
/*** member variables */
@@ -28,6 +31,8 @@ static char* etUnit_TestCaseName = NULL;
/* counters */
static etInt32 etUnit_passCount = 0;
static etInt32 etUnit_failCount = 0;
+static etInt32 etUnit_passCountTotal = 0;
+static etInt32 etUnit_failCountTotal = 0;
static etBool etUnit_testcaseSuccess = TRUE;
@@ -39,12 +44,10 @@ static char etUnit_failureText[ETUNIT_FAILURE_TEXT_LEN];
static clock_t etUnit_startTime = 0;
static clock_t etUnit_currentTime = 0;
-/* */
-
/* forward declarations of private functions */
void expect_equal_int(const char* message, etInt32 expected, etInt32 actual);
void expect_equal_uint(const char* message, etUInt32 expected, etUInt32 actual);
-void expect_equal_float(const char* message, float64 expected, float64 actual, float64 precision);
+void expect_equal_float(const char* message, etFloat64 expected, etFloat64 actual, etFloat64 precision);
void etUnit_writeTestLog(const char *testcase, etBool result, const char *resulttext);
void etUnit_handleExpect(etBool result, const char *resulttext);
@@ -58,44 +61,49 @@ void etUnit_open(char* testResultPath, char* testFileName) {
etUnit_TestFileName = testFileName;
etUnit_TestResultPath = testResultPath;
- printf("************* TEST START (%s) **************\n", etUnit_TestFileName);
+ etLogger_logInfoF("************* TEST START (%s) **************", etUnit_TestFileName);
char filename[ETUNIT_FAILURE_TEXT_LEN];
sprintf(filename, "%s/%s.xml", etUnit_TestResultPath, etUnit_TestFileName);
if (etUnit_reportfile == NULL) {
- etUnit_reportfile = fopen(filename, "w+");
+ etUnit_reportfile = etLogger_fopen(filename, "w+");
if (etUnit_reportfile != NULL) {
- fprintf(etUnit_reportfile, "<testsuites name=\"%s\" tests=\"0\" failures=\"0\" errors=\"0\" time=\"0\">\n",
- etUnit_TestFileName);
+ etLogger_fprintf(etUnit_reportfile, "<testsuites name=\"%s\" tests=\"0\" failures=\"0\" errors=\"0\" time=\"0\">\n", etUnit_TestFileName);
} else {
- printf("Unable to open file %s/%s.xml\n", etUnit_TestResultPath, etUnit_TestFileName);
+ etLogger_logErrorF("Unable to open file %s/%s.xml", etUnit_TestResultPath, etUnit_TestFileName);
}
}
// prepare time measurement
etUnit_startTime = clock();
etUnit_currentTime = clock();
- printf("Start Time: %ld\n", etUnit_startTime);
+ etLogger_logInfoF("Start Time: %ld", etUnit_startTime);
}
void etUnit_close(void) {
- printf("\n");
+ etLogger_logInfoF("");
if (etUnit_failCount > 0) {
- printf("************* TEST FAILED *************\n");
+ etLogger_logInfoF("************* TEST FAILED *************");
+ } else {
+ etLogger_logInfoF("************* TEST PASSED *************");
+ }
+ etLogger_logInfoF("Number of Tests: %ld", etUnit_failCount + etUnit_passCount);
+ etLogger_logInfoF("Failed: %ld", etUnit_failCount);
+ etLogger_logInfoF("Passed: %ld", etUnit_passCount);
+ etLogger_logInfoF("Time: %ld", clock() - etUnit_startTime);
+ etLogger_logInfoF("End Time: %ld[ms]", (clock() / 1000) * CLOCKS_PER_SEC );
+ etLogger_logInfoF("***************************************");
+ if (etUnit_failCountTotal > 0) {
+ etLogger_logInfoF(" ******* %d TEST(S) FAILED *****", etUnit_failCountTotal);
} else {
- printf("************* TEST PASSED *************\n");
+ etLogger_logInfoF(" ******* ALL TESTS PASSED ******");
}
- printf("Number of Tests: %ld\n", etUnit_failCount + etUnit_passCount);
- printf("Failed: %ld\n", etUnit_failCount);
- printf("Passed: %ld\n", etUnit_passCount);
- printf("Total Time: %ld\n", clock() - etUnit_startTime);
- printf("End Time: %ld, CLOCKS_PER_SEC: %ld\n", clock(), CLOCKS_PER_SEC);
- printf("***************************************\n");
+ etLogger_logInfoF("***************************************");
if (etUnit_reportfile != NULL) {
- fprintf(etUnit_reportfile, "</testsuites>\n");
- fclose(etUnit_reportfile);
+ etLogger_fprintf(etUnit_reportfile, "</testsuites>\n");
+ etLogger_fclose(etUnit_reportfile);
etUnit_reportfile = NULL;
}
}
@@ -103,14 +111,14 @@ void etUnit_close(void) {
void etUnit_openTestSuite(char* testSuiteName) {
etUnit_TestSuiteName = testSuiteName;
if (etUnit_reportfile != NULL) {
- fprintf(etUnit_reportfile, "\t<testsuite name=\"%s\" tests=\"0\" failures=\"0\" errors=\"0\" time=\"0\">\n",
+ etLogger_fprintf(etUnit_reportfile, "\t<testsuite name=\"%s\" tests=\"0\" failures=\"0\" errors=\"0\" time=\"0\">\n",
etUnit_TestSuiteName);
}
}
void etUnit_closeTestSuite(void) {
if (etUnit_reportfile != NULL) {
- fprintf(etUnit_reportfile, "\t</testsuite>\n");
+ etLogger_fprintf(etUnit_reportfile, "\t</testsuite>\n");
}
}
@@ -126,6 +134,18 @@ void etUnit_closeTestCase(void) {
}
}
+void etUnit_openAll(char* testResultPath, char* testFileName, char* testSuiteName, char* testCaseName){
+ etUnit_open(testResultPath, testFileName);
+ etUnit_openTestSuite(testSuiteName);
+ etUnit_openTestCase(testCaseName);
+}
+
+void etUnit_closeAll(void){
+ etUnit_closeTestCase();
+ etUnit_closeTestSuite();
+ etUnit_close();
+}
+
void EXPECT_TRUE(const char* message, etBool condition) {
if (condition == FALSE) {
char testresult[ETUNIT_FAILURE_TEXT_LEN];
@@ -171,14 +191,53 @@ void EXPECT_EQUAL_UINT32(const char* message, etUInt32 expected, etUInt32 actual
}
-void EXPECT_EQUAL_FLOAT32(const char* message, float32 expected, float32 actual, float32 precision) {
- expect_equal_float(message, (float64) expected, (float64) actual, (float64) precision);
+void EXPECT_EQUAL_FLOAT32(const char* message, etFloat32 expected, etFloat32 actual, etFloat32 precision) {
+ expect_equal_float(message, (etFloat64) expected, (etFloat64) actual, (etFloat64) precision);
+}
+
+void EXPECT_EQUAL_FLOAT64(const char* message, etFloat64 expected, etFloat64 actual, etFloat64 precision) {
+ expect_equal_float(message, (etFloat64) expected, (etFloat64) actual, (etFloat64) precision);
+}
+
+/* order */
+static etInt16 etUnit_orderCurrentIndex = 0;
+static etInt16 etUnit_orderSize = 0;
+static etInt16* etUnit_orderList = NULL;
+
+void EXPECT_ORDER_START(etInt16* list, etInt16 size){
+ etUnit_orderCurrentIndex = 0;
+ etUnit_orderSize = size;
+ etUnit_orderList = list;
}
-void EXPECT_EQUAL_FLOAT64(const char* message, float64 expected, float64 actual, float64 precision) {
- expect_equal_float(message, (float64) expected, (float64) actual, (float64) precision);
+void EXPECT_ORDER(const char* message, etInt16 identifier){
+ if (etUnit_orderCurrentIndex < etUnit_orderSize) {
+ if (etUnit_orderList[etUnit_orderCurrentIndex] != identifier){
+ char testresult[ETUNIT_FAILURE_TEXT_LEN];
+ sprintf(testresult, "EXPECT_ORDER %s: index=%d, expected=%d, actual=%d", message, etUnit_orderCurrentIndex, identifier, etUnit_orderList[etUnit_orderCurrentIndex]);
+ etUnit_handleExpect(FALSE, testresult);
+ }
+ else {
+ etUnit_handleExpect(TRUE, "");
+ etUnit_orderCurrentIndex++;
+ }
+ }
+ else {
+ char testresult[ETUNIT_FAILURE_TEXT_LEN];
+ sprintf(testresult, "EXPECT_ORDER: index(%d) is too big in %s", etUnit_orderCurrentIndex, message);
+ etUnit_handleExpect(FALSE, testresult);
+ etLogger_logInfoF("EXPECT_ORDER: index too big in %s", message);
+ }
}
+void EXPECT_ORDER_END(const char* message, etInt16 identifier){
+ EXPECT_ORDER(message, identifier);
+ if (etUnit_orderCurrentIndex != etUnit_orderSize){
+ char testresult[ETUNIT_FAILURE_TEXT_LEN];
+ sprintf(testresult, "EXPECT_ORDER_END %s: wrong index at the end: expected=%d, actual=%d", message, etUnit_orderSize, etUnit_orderCurrentIndex);
+ etUnit_handleExpect(FALSE, testresult);
+ }
+}
/* private functions */
@@ -203,7 +262,7 @@ void expect_equal_uint(const char* message, etUInt32 expected, etUInt32 actual)
}
-void expect_equal_float(const char* message, float64 expected, float64 actual, float64 precision) {
+void expect_equal_float(const char* message, etFloat64 expected, etFloat64 actual, etFloat64 precision) {
if (expected - actual < -precision || expected - actual > precision) {
char testresult[ETUNIT_FAILURE_TEXT_LEN];
sprintf(testresult, "%s: expected=%lf, actual=%lf", message, expected, actual);
@@ -259,10 +318,12 @@ void etUnit_writeTestLog(const char *testcase, etBool result, const char *result
// counting
if (result == TRUE) {
etUnit_passCount++;
- printf("PASS: %s: %s\n", testcase, resulttext);
+ etUnit_passCountTotal++;
+ etLogger_logInfoF("PASS: %s %s", testcase, resulttext);
} else {
etUnit_failCount++;
- printf("FAIL: %s: %s\n", testcase, resulttext);
+ etUnit_failCountTotal++;
+ etLogger_logInfoF("FAIL: %s : %s", testcase, resulttext);
}
clock_t time = clock() - etUnit_currentTime;
@@ -271,7 +332,7 @@ void etUnit_writeTestLog(const char *testcase, etBool result, const char *result
// writing to file
if (etUnit_reportfile != NULL) {
etUnit_buildTestLogXML(writeBuffer, testcase, result, resulttext, time);
- fprintf(etUnit_reportfile, writeBuffer);
+ etLogger_fprintf(etUnit_reportfile, writeBuffer);
}
}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etUnit.h b/runtime/org.eclipse.etrice.runtime.c/src/etUnit.h
index e98615c5c..dcaa28306 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/etUnit.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/etUnit.h
@@ -14,11 +14,9 @@
#define _ETUNIT_H_
#include "etDatatypes.h"
-#include <stdio.h>
-#include <time.h>
-// open / close
+/* open / close */
void etUnit_open(char* testResultPath, char* testFileName);
void etUnit_close(void);
void etUnit_openTestSuite(char* testSuiteName);
@@ -26,6 +24,11 @@ void etUnit_closeTestSuite(void);
void etUnit_openTestCase(char* testCaseName);
void etUnit_closeTestCase(void);
+/* functions for more convenience for model and generator tests */
+
+void etUnit_openAll(char* testResultPath, char* testFileName, char* testSuiteName, char* testCaseName);
+void etUnit_closeAll(void);
+
/* boolean values */
void EXPECT_TRUE(const char* testcase, etBool condition);
void EXPECT_FALSE(const char* testcase, etBool condition);
@@ -50,6 +53,12 @@ void EXPECT_EQUAL_FLOAT64(const char* testcase, etFloat64 expected, etFloat64 ac
void expect_equal_void_ptr(const char* testcase, const void* expected, const void* actual);
+/* more specialized functions */
+void EXPECT_ORDER_START(etInt16* list, etInt16 size);
+void EXPECT_ORDER(const char* message, etInt16 identifier);
+void EXPECT_ORDER_END(const char* message, etInt16 identifier);
+
+
/* Helpers for adding testcases */
#define ADD_TESTCASE(testcase) \

Back to the top