diff options
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.c/src')
-rw-r--r-- | runtime/org.eclipse.etrice.runtime.c/src/etDatatypes.h | 142 | ||||
-rw-r--r-- | runtime/org.eclipse.etrice.runtime.c/src/etLogger.c | 156 | ||||
-rw-r--r-- | runtime/org.eclipse.etrice.runtime.c/src/etLogger.h | 96 | ||||
-rw-r--r-- | runtime/org.eclipse.etrice.runtime.c/src/etMSCLogger.c | 57 | ||||
-rw-r--r-- | runtime/org.eclipse.etrice.runtime.c/src/etMSCLogger.h | 56 | ||||
-rw-r--r-- | runtime/org.eclipse.etrice.runtime.c/src/etMessage.c | 46 | ||||
-rw-r--r-- | runtime/org.eclipse.etrice.runtime.c/src/etMessage.h | 52 | ||||
-rw-r--r-- | runtime/org.eclipse.etrice.runtime.c/src/etMessageQueue.c | 178 | ||||
-rw-r--r-- | runtime/org.eclipse.etrice.runtime.c/src/etMessageQueue.h | 90 | ||||
-rw-r--r-- | runtime/org.eclipse.etrice.runtime.c/src/etMessageService.c | 155 | ||||
-rw-r--r-- | runtime/org.eclipse.etrice.runtime.c/src/etMessageService.h | 91 | ||||
-rw-r--r-- | runtime/org.eclipse.etrice.runtime.c/src/etPort.c | 40 | ||||
-rw-r--r-- | runtime/org.eclipse.etrice.runtime.c/src/etPort.h | 83 | ||||
-rw-r--r-- | runtime/org.eclipse.etrice.runtime.c/src/etUnit.c | 676 | ||||
-rw-r--r-- | runtime/org.eclipse.etrice.runtime.c/src/etUnit.h | 140 |
15 files changed, 1118 insertions, 940 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etDatatypes.h b/runtime/org.eclipse.etrice.runtime.c/src/etDatatypes.h index ee798d237..bba9160a4 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/etDatatypes.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/etDatatypes.h @@ -1,71 +1,71 @@ -/******************************************************************************* - * 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) - * - *******************************************************************************/ - -#ifndef _ETDATATYPES_H_ -#define _ETDATATYPES_H_ - -/* - * typedefs for platform specific datatypes - * - * */ - -#include <stdio.h> - -/* unsigned integer datatypes */ -typedef unsigned char uint8; -typedef unsigned short int uint16; -typedef unsigned long uint32; -typedef unsigned long long uint64; - -/* signed integer datatypes */ -typedef char int8; -typedef short int int16; -typedef long int32; -typedef long long int64; - - -/* float datatypes */ -typedef float float32; -typedef double float64; - -/* boolean datatypes and values */ -typedef char boolean; /* TODO: bool, Bool, Boolean, and boolean are already defined in some platforms*/ -#ifndef TRUE - #define TRUE 1 -#endif -#ifndef FALSE - #define FALSE 0 -#endif - -/* - * typedefs for eTrice Runtime and Testing - * - * */ - -typedef int8 etInt8; -typedef int16 etInt16; -typedef int32 etInt32; - -typedef uint8 etUInt8; -typedef uint16 etUInt16; -typedef uint32 etUInt32; - -typedef boolean etBool; - -typedef float32 etFloat32; -typedef float64 etFloat64; - -typedef FILE* etFileHandle; - -typedef int8 etAddressId; - -#endif /* _DATATYPES_H_ */ +/*******************************************************************************
+ * 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)
+ *
+ *******************************************************************************/
+
+#ifndef _ETDATATYPES_H_
+#define _ETDATATYPES_H_
+
+/*
+ * typedefs for platform specific datatypes
+ *
+ * */
+
+#include <stdio.h>
+
+/* unsigned integer datatypes */
+typedef unsigned char uint8;
+typedef unsigned short int uint16;
+typedef unsigned long uint32;
+typedef unsigned long long uint64;
+
+/* signed integer datatypes */
+typedef char int8;
+typedef short int int16;
+typedef long int32;
+typedef long long int64;
+
+
+/* float datatypes */
+typedef float float32;
+typedef double float64;
+
+/* boolean datatypes and values */
+typedef char boolean; /* TODO: bool, Bool, Boolean, and boolean are already defined in some platforms*/
+#ifndef TRUE
+ #define TRUE 1
+#endif
+#ifndef FALSE
+ #define FALSE 0
+#endif
+
+/*
+ * typedefs for eTrice Runtime and Testing
+ *
+ * */
+
+typedef int8 etInt8;
+typedef int16 etInt16;
+typedef int32 etInt32;
+
+typedef uint8 etUInt8;
+typedef uint16 etUInt16;
+typedef uint32 etUInt32;
+
+typedef boolean etBool;
+
+typedef float32 etFloat32;
+typedef float64 etFloat64;
+
+typedef FILE* etFileHandle;
+
+typedef int8 etAddressId;
+
+#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 index 9d58dd2ca..13c2fea0a 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/etLogger.c +++ b/runtime/org.eclipse.etrice.runtime.c/src/etLogger.c @@ -1,78 +1,78 @@ -/******************************************************************************* - * 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\n", message); -} - -void etLogger_logWarning(const char* message){ - printf("WARNING: %s\n", message); -} - -void etLogger_logInfo(const char* message){ - printf("INFO: %s\n", message); -} - -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 ); -} +/*******************************************************************************
+ * 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\n", message);
+}
+
+void etLogger_logWarning(const char* message){
+ printf("WARNING: %s\n", message);
+}
+
+void etLogger_logInfo(const char* message){
+ printf("INFO: %s\n", message);
+}
+
+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 index b353e6f1a..6c46889a8 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/etLogger.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/etLogger.h @@ -1,48 +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_ */ +/*******************************************************************************
+ * 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/etMSCLogger.c b/runtime/org.eclipse.etrice.runtime.c/src/etMSCLogger.c new file mode 100644 index 000000000..9abc9be9d --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/etMSCLogger.c @@ -0,0 +1,57 @@ +/*******************************************************************************
+ * Copyright (c) 2012 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)
+ *
+ *******************************************************************************/
+
+#include "etMSCLogger.h"
+
+#include "etLogger.h"
+
+static etFileHandle etMSCLogger_fileHandle = NULL;
+static char* etMSCLogger_objectName = "";
+
+#define ET_MAX_FILENAME_LEN 256
+
+void etMSCLogger_open(char* logPath, char* mscName){
+ char path[ET_MAX_FILENAME_LEN];
+ sprintf(path, "%s/%s.seq", logPath, mscName);
+ etMSCLogger_fileHandle = etLogger_fopen(path, "w+");
+}
+
+void etMSCLogger_close(void){
+ if (etMSCLogger_fileHandle != NULL){
+ etLogger_fclose(etMSCLogger_fileHandle);
+ }
+
+}
+
+void etMSCLogger_setObjectName(char* objectName){
+ etMSCLogger_objectName = objectName;
+}
+
+char* etMSCLogger_getObjectName(void){
+ return etMSCLogger_objectName;
+}
+
+void etMSCLogger_syncCall(char* sourceName, char* messageName, char* targetName){
+ etLogger_fprintf(etMSCLogger_fileHandle, "%s ==> %s %s\n", sourceName, targetName, messageName);
+}
+
+void etMSCLogger_syncReturn(char* sourceName, char* targetName){
+ etLogger_fprintf(etMSCLogger_fileHandle, "%s <== %s\n", sourceName, targetName);
+}
+
+void etMSCLogger_asyncOut(char* sourceName, char* messageName, char* targetName){
+ etLogger_fprintf(etMSCLogger_fileHandle, "%s >-- %s %s\n", sourceName, targetName, messageName);
+}
+
+void etMSCLogger_asyncIn(char* sourceName, char* messageName, char* targetName){
+ etLogger_fprintf(etMSCLogger_fileHandle, "%s --> %s %s\n", sourceName, targetName, messageName);
+}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etMSCLogger.h b/runtime/org.eclipse.etrice.runtime.c/src/etMSCLogger.h new file mode 100644 index 000000000..af78894bd --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/etMSCLogger.h @@ -0,0 +1,56 @@ +/*******************************************************************************
+ * Copyright (c) 2012 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)
+ *
+ *******************************************************************************/
+
+#ifndef _ETMSCLOGGER_H_
+#define _ETMSCLOGGER_H_
+
+#define ET_MSC_LOGGER_ACTIVATE
+
+void etMSCLogger_open(char* logPath, char* mscName);
+void etMSCLogger_close(void);
+
+void etMSCLogger_setObjectName(char* objectName);
+char* etMSCLogger_getObjectName(void);
+
+void etMSCLogger_syncCall(char* sourceName, char* messageName, char* targetName);
+void etMSCLogger_syncReturn(char* sourceName, char* targetName);
+
+void etMSCLogger_asyncOut(char* sourceName, char* messageName, char* targetName);
+void etMSCLogger_asyncIn(char* sourceName, char* messageName, char* targetName);
+
+#ifdef ET_MSC_LOGGER_ACTIVATE
+ #define ET_MSC_LOGGER_OPEN(object) \
+ etMSCLogger_open("tmp", "msc"); \
+ etMSCLogger_setObjectName(object);
+
+ #define ET_MSC_LOGGER_CLOSE etMSCLogger_close();
+
+ #define ET_MSC_LOGGER_SYNC_ENTRY(object, message) \
+ char* sourceName = etMSCLogger_getObjectName(); \
+ char* targetName = object; \
+ etMSCLogger_syncCall(sourceName, message, targetName); \
+ etMSCLogger_setObjectName(targetName);
+
+ #define ET_MSC_LOGGER_SYNC_EXIT \
+ etMSCLogger_syncReturn(sourceName, targetName); \
+ etMSCLogger_setObjectName(sourceName);
+
+#else
+ #define ET_MSC_LOGGER_OPEN
+ #define ET_MSC_LOGGER_CLOSE
+
+ #define ET_MSC_LOGGER_SYNC_ENTRY(object, message)
+ #define ET_MSC_LOGGER_SYNC_EXIT
+#endif
+
+
+#endif /* _ETMSCLOGGER_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etMessage.c b/runtime/org.eclipse.etrice.runtime.c/src/etMessage.c index 940dc61c2..146467c23 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/etMessage.c +++ b/runtime/org.eclipse.etrice.runtime.c/src/etMessage.c @@ -1,21 +1,25 @@ -/******************************************************************************* - * 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) - * - *******************************************************************************/ - -#include "etMessage.h" - -#include <stddef.h> - -void etMessage_init(etMessage* self){ - self->next = NULL; - self->address = 0; - self->evtID = 0; -} +/*******************************************************************************
+ * 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)
+ *
+ *******************************************************************************/
+
+#include "etMessage.h"
+
+#include "etMSCLogger.h"
+
+#include <stddef.h>
+
+void etMessage_init(etMessage* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessage", "init")
+ self->next = NULL;
+ self->address = 0;
+ self->evtID = 0;
+ ET_MSC_LOGGER_SYNC_EXIT
+}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etMessage.h b/runtime/org.eclipse.etrice.runtime.c/src/etMessage.h index 7bba6a1f3..698a89c09 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/etMessage.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/etMessage.h @@ -1,26 +1,26 @@ -/******************************************************************************* - * 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) - * - *******************************************************************************/ - -#ifndef _ETMESSAGE_H_ -#define _ETMESSAGE_H_ - -#include "etDatatypes.h" - -typedef struct etMessage{ - struct etMessage* next; - etInt16 address; - etInt16 evtID; -} etMessage; - -void etMessage_init(etMessage* self); - -#endif /* _ETMESSAGE_H_ */ +/*******************************************************************************
+ * 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)
+ *
+ *******************************************************************************/
+
+#ifndef _ETMESSAGE_H_
+#define _ETMESSAGE_H_
+
+#include "etDatatypes.h"
+
+typedef struct etMessage{
+ struct etMessage* next;
+ etInt16 address;
+ etInt16 evtID;
+} etMessage;
+
+void etMessage_init(etMessage* self);
+
+#endif /* _ETMESSAGE_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etMessageQueue.c b/runtime/org.eclipse.etrice.runtime.c/src/etMessageQueue.c index 2575d1a1d..27c949bd1 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/etMessageQueue.c +++ b/runtime/org.eclipse.etrice.runtime.c/src/etMessageQueue.c @@ -1,79 +1,99 @@ -/******************************************************************************* - * 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) - * - *******************************************************************************/ - -#include "etMessageQueue.h" - -void etMessageQueue_init(etMessageQueue* self){ - self->first = NULL; - self->last = NULL; - self->highWaterMark = 0; - self->size = 0; -} - - -void etMessageQueue_push(etMessageQueue* self, etMessage* msg){ - // TODO: optimize queue for concurrent push / pop - if (self->first == NULL) { - /*no message in queue*/ - self->first = self->last = msg; - } - else { - /*at least one message in queue*/ - self->last->next = msg; - self->last = msg; - } - msg->next = NULL; /*TODO: optimization: this line could be removed if we assume that all messages are initialized*/ - - if (++self->size > self->highWaterMark) - self->highWaterMark++; -} - -etMessage* etMessageQueue_pop(etMessageQueue* self){ - etMessage* pop_msg = self->first; - if(self->first == NULL){ - /*no message in queue*/ - return NULL; - } - if (self->first->next==NULL){ - /*only one message in queue*/ - self->first = self->last = NULL; - } - else { - /*more than one message in queue -> set first to nex message*/ - self->first = self->first->next; - } - - pop_msg->next=NULL; - self->size--; - - return pop_msg; -} - -etInt16 etMessageQueue_getSize(etMessageQueue* self) { - return self->size; -} - -etMessage* etMessageQueue_getFirst(etMessageQueue* self){ - return self->first; -} - -etMessage* etMessageQueue_getLast(etMessageQueue* self){ - return self->last; -} - -etBool etMessageQueue_isNotEmpty(etMessageQueue* self){ - return self->last != NULL; -} - -etInt16 etMessageQueue_getHightWaterMark(etMessageQueue* self) { - return self->highWaterMark; -} +/*******************************************************************************
+ * 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)
+ *
+ *******************************************************************************/
+
+#include "etMessageQueue.h"
+
+#include "etMSCLogger.h"
+
+void etMessageQueue_init(etMessageQueue* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "init")
+ self->first = NULL;
+ self->last = NULL;
+ self->highWaterMark = 0;
+ self->size = 0;
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+
+void etMessageQueue_push(etMessageQueue* self, etMessage* msg){
+ // TODO: optimize queue for concurrent push / pop
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "push")
+ if (self->first == NULL) {
+ /*no message in queue*/
+ self->first = self->last = msg;
+ }
+ else {
+ /*at least one message in queue*/
+ self->last->next = msg;
+ self->last = msg;
+ }
+ msg->next = NULL; /*TODO: optimization: this line could be removed if we assume that all messages are initialized*/
+
+ if (++self->size > self->highWaterMark)
+ self->highWaterMark++;
+
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+etMessage* etMessageQueue_pop(etMessageQueue* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "pop")
+ etMessage* pop_msg = self->first;
+ if(self->first == NULL){
+ /*no message in queue*/
+ ET_MSC_LOGGER_SYNC_EXIT
+ return NULL;
+ }
+ if (self->first->next==NULL){
+ /*only one message in queue*/
+ self->first = self->last = NULL;
+ }
+ else {
+ /*more than one message in queue -> set first to nex message*/
+ self->first = self->first->next;
+ }
+
+ pop_msg->next=NULL;
+ self->size--;
+
+ ET_MSC_LOGGER_SYNC_EXIT
+ return pop_msg;
+}
+
+etInt16 etMessageQueue_getSize(etMessageQueue* self) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "init")
+ ET_MSC_LOGGER_SYNC_EXIT
+ return self->size;
+}
+
+etMessage* etMessageQueue_getFirst(etMessageQueue* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "init")
+ ET_MSC_LOGGER_SYNC_EXIT
+ return self->first;
+}
+
+etMessage* etMessageQueue_getLast(etMessageQueue* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "init")
+ ET_MSC_LOGGER_SYNC_EXIT
+ return self->last;
+}
+
+etBool etMessageQueue_isNotEmpty(etMessageQueue* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "init")
+ ET_MSC_LOGGER_SYNC_EXIT
+ return self->last != NULL;
+}
+
+etInt16 etMessageQueue_getHightWaterMark(etMessageQueue* self) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "init")
+ ET_MSC_LOGGER_SYNC_EXIT
+ return self->highWaterMark;
+}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etMessageQueue.h b/runtime/org.eclipse.etrice.runtime.c/src/etMessageQueue.h index 7fa27ff8a..f08b19901 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/etMessageQueue.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/etMessageQueue.h @@ -1,45 +1,45 @@ -/******************************************************************************* - * 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) - * - *******************************************************************************/ - -#ifndef _ETMESSAGEQUEUE_H_ -#define _ETMESSAGEQUEUE_H_ - -#include "etMessage.h" -#include <stddef.h> - -typedef struct etMessageQueue { - etMessage* first; - etMessage* last; - etInt16 highWaterMark; - etInt16 size; - -} etMessageQueue; - -void etMessageQueue_init(etMessageQueue* self); - -void etMessageQueue_push(etMessageQueue* self, etMessage* msg); - -etMessage* etMessageQueue_pop(etMessageQueue* self); - -etMessage* etMessageQueue_getFirst(etMessageQueue* self); - -etMessage* etMessageQueue_getLast(etMessageQueue* self); - -etBool etMessageQueue_isNotEmpty(etMessageQueue* self); - -etInt16 etMessageQueue_getHightWaterMark(etMessageQueue* self); - -etInt16 etMessageQueue_getSize(etMessageQueue* self); - - - -#endif /* _RMESSAGEQUEUE_H_ */ +/*******************************************************************************
+ * 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)
+ *
+ *******************************************************************************/
+
+#ifndef _ETMESSAGEQUEUE_H_
+#define _ETMESSAGEQUEUE_H_
+
+#include "etMessage.h"
+#include <stddef.h>
+
+typedef struct etMessageQueue {
+ etMessage* first;
+ etMessage* last;
+ etInt16 highWaterMark;
+ etInt16 size;
+
+} etMessageQueue;
+
+void etMessageQueue_init(etMessageQueue* self);
+
+void etMessageQueue_push(etMessageQueue* self, etMessage* msg);
+
+etMessage* etMessageQueue_pop(etMessageQueue* self);
+
+etMessage* etMessageQueue_getFirst(etMessageQueue* self);
+
+etMessage* etMessageQueue_getLast(etMessageQueue* self);
+
+etBool etMessageQueue_isNotEmpty(etMessageQueue* self);
+
+etInt16 etMessageQueue_getHightWaterMark(etMessageQueue* self);
+
+etInt16 etMessageQueue_getSize(etMessageQueue* self);
+
+
+
+#endif /* _RMESSAGEQUEUE_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etMessageService.c b/runtime/org.eclipse.etrice.runtime.c/src/etMessageService.c index dcf04e0ba..8dd93a9ad 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/etMessageService.c +++ b/runtime/org.eclipse.etrice.runtime.c/src/etMessageService.c @@ -1,60 +1,95 @@ -/******************************************************************************* - * 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) - * - *******************************************************************************/ - - -#include "etMessageService.h" - -void etMessageService_init(etMessageService* self, etUInt8* buffer, etUInt16 maxBlocks, etUInt16 blockSize){ - self->messageBuffer.buffer = buffer; - self->messageBuffer.maxBlocks = maxBlocks; - self->messageBuffer.blockSize = blockSize; - etMessageQueue_init(&self->messagePool); - etMessageQueue_init(&self->messageQueue); - - etMessageService_initMessagePool(self); -} - -/* - * initialize message pool with block buffer - * all blocks are added to pool - */ -void etMessageService_initMessagePool(etMessageService* self){ - etInt16 i; - - for (i=0; i<self->messageBuffer.maxBlocks; i++){ - etMessage* block = (etMessage*) &self->messageBuffer.buffer[i*self->messageBuffer.blockSize]; - etMessageQueue_push(&self->messagePool, block); - } -} - -void etMessageService_pushMessage(etMessageService* self, etMessage* msg){ - etMessageQueue_push(&self->messageQueue, msg); - -} - -etMessage* etMessageService_popMessage(etMessageService* self){ - return etMessageQueue_pop(&self->messageQueue); -} - - -etMessage* etMessageService_getMessageBuffer(etMessageService* self, etUInt16 size){ - if (size<=self->messageBuffer.blockSize){ - if (self->messagePool.size>0){ - return etMessageQueue_pop(&self->messagePool); - } - } - return NULL; -} - -void etMessageService_returnMessageBuffer(etMessageService* self, etMessage* buffer){ - etMessageQueue_push(&self->messagePool, buffer); -} +/*******************************************************************************
+ * 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)
+ *
+ *******************************************************************************/
+
+
+#include "etMessageService.h"
+
+
+#include "etLogger.h"
+#include "etMSCLogger.h"
+
+void etMessageService_init(etMessageService* self, etUInt8* buffer, etUInt16 maxBlocks, etUInt16 blockSize){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "init")
+ self->messageBuffer.buffer = buffer;
+ self->messageBuffer.maxBlocks = maxBlocks;
+ self->messageBuffer.blockSize = blockSize;
+ etMessageQueue_init(&self->messagePool);
+ etMessageQueue_init(&self->messageQueue);
+
+ etMessageService_initMessagePool(self);
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+/*
+ * initialize message pool with block buffer
+ * all blocks are added to pool
+ */
+void etMessageService_initMessagePool(etMessageService* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "initMessagePool")
+ etInt16 i;
+
+ for (i=0; i<self->messageBuffer.maxBlocks; i++){
+ etMessage* block = (etMessage*) &self->messageBuffer.buffer[i*self->messageBuffer.blockSize];
+ etMessageQueue_push(&self->messagePool, block);
+ }
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+void etMessageService_pushMessage(etMessageService* self, etMessage* msg){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "pushMessage")
+ etMessageQueue_push(&self->messageQueue, msg);
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+etMessage* etMessageService_popMessage(etMessageService* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "popMessage")
+ etMessage* msg = etMessageQueue_pop(&self->messageQueue);
+ ET_MSC_LOGGER_SYNC_EXIT
+ return msg;
+}
+
+
+etMessage* etMessageService_getMessageBuffer(etMessageService* self, etUInt16 size){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "getMessageBuffer")
+ if (size<=self->messageBuffer.blockSize){
+ if (self->messagePool.size>0){
+ etMessage* msg = etMessageQueue_pop(&self->messagePool);
+ ET_MSC_LOGGER_SYNC_EXIT
+ return msg;
+ }
+ }
+ ET_MSC_LOGGER_SYNC_EXIT
+ return NULL;
+}
+
+void etMessageService_returnMessageBuffer(etMessageService* self, etMessage* buffer){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "returnMessageBuffer")
+ etMessageQueue_push(&self->messagePool, buffer);
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+void etMessageService_deliverAllMessages(etMessageService* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "deliverAllMessages")
+ while (self->messageQueue.size > 0){
+ etMessage* msg = etMessageService_popMessage(self);
+ etLogger_logInfoF("Message ID=%d, Address=%d", msg->evtID, msg->address);
+ etMessageService_returnMessageBuffer(self, msg);
+ }
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+void etMessageService_execute(etMessageService* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "execute")
+ etMessageService_deliverAllMessages(self);
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etMessageService.h b/runtime/org.eclipse.etrice.runtime.c/src/etMessageService.h index 12f02885b..b17665542 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/etMessageService.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/etMessageService.h @@ -1,44 +1,47 @@ -/******************************************************************************* - * 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) - * - *******************************************************************************/ - -#ifndef _ETMESSAGESERVICE_H_ -#define _ETMESSAGESERVICE_H_ - -#include <stddef.h> -#include "etDatatypes.h" -#include "etMessageQueue.h" - - -typedef struct RBuffer{ - etUInt8 *buffer; - etUInt16 maxBlocks; - etUInt16 blockSize; -} RBuffer; - -typedef struct etMessageService { - etMessageQueue messageQueue; - etMessageQueue messagePool; - RBuffer messageBuffer; -} etMessageService; - -void etMessageService_init(etMessageService* self, etUInt8* buffer, etUInt16 maxBlocks, etUInt16 blockSize); - -void etMessageService_initMessagePool(etMessageService* self); - -void etMessageService_pushMessage(etMessageService* self, etMessage* msg); -etMessage* etMessageService_popMessage(etMessageService* self); - - -etMessage* etMessageService_getMessageBuffer(etMessageService* self, etUInt16 size); -void etMessageService_returnMessageBuffer(etMessageService* self, etMessage* buffer); - -#endif /* RMESSAGESERVICE_H_ */ +/*******************************************************************************
+ * 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)
+ *
+ *******************************************************************************/
+
+#ifndef _ETMESSAGESERVICE_H_
+#define _ETMESSAGESERVICE_H_
+
+#include <stddef.h>
+#include "etDatatypes.h"
+#include "etMessageQueue.h"
+
+
+typedef struct RBuffer{
+ etUInt8 *buffer;
+ etUInt16 maxBlocks;
+ etUInt16 blockSize;
+} RBuffer;
+
+typedef struct etMessageService {
+ etMessageQueue messageQueue;
+ etMessageQueue messagePool;
+ RBuffer messageBuffer;
+} etMessageService;
+
+void etMessageService_init(etMessageService* self, etUInt8* buffer, etUInt16 maxBlocks, etUInt16 blockSize);
+
+void etMessageService_initMessagePool(etMessageService* self);
+
+void etMessageService_pushMessage(etMessageService* self, etMessage* msg);
+etMessage* etMessageService_popMessage(etMessageService* self);
+
+
+etMessage* etMessageService_getMessageBuffer(etMessageService* self, etUInt16 size);
+void etMessageService_returnMessageBuffer(etMessageService* self, etMessage* buffer);
+
+void etMessageService_execute(etMessageService* self);
+
+
+#endif /* RMESSAGESERVICE_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etPort.c b/runtime/org.eclipse.etrice.runtime.c/src/etPort.c index 6f122c15b..75db77d8d 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/etPort.c +++ b/runtime/org.eclipse.etrice.runtime.c/src/etPort.c @@ -1,18 +1,22 @@ -/******************************************************************************* - * Copyright (c) 2012 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) - * - *******************************************************************************/ - -#include "etPort.h" - -void etPort_receive(etPort* self, etMessage* msg) { - (self->receiveMessageFunc)(self->myActor, self->localId, msg); -} - +/*******************************************************************************
+ * Copyright (c) 2012 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)
+ *
+ *******************************************************************************/
+
+#include "etPort.h"
+
+#include "etMSCLogger.h"
+
+void etPort_receive(etPort* self, etMessage* msg) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etPort", "receive")
+ (self->receiveMessageFunc)(self->myActor, self->localId, msg);
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etPort.h b/runtime/org.eclipse.etrice.runtime.c/src/etPort.h index c10abc870..7a9cb65a3 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/etPort.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/etPort.h @@ -1,42 +1,41 @@ -/******************************************************************************* - * Copyright (c) 2012 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) - * - *******************************************************************************/ - - - -#ifndef _ETPORT_H_ -#define _ETPORT_H_ - - -#include "etMessage.h" -#include "etMessageReceiver.h" -#include "etMessageService.h" - -typedef struct { - void* myActor; - etReceiveMessage receiveMessageFunc; - etMessageService* msgService; - etAddressId peerAddress; - etAddressId localId; - - #ifdef etDEBUG - etAddressId address; - /* thread ID from msg service: msgService->threadId */ - #endif -} -etPort; - -void etPort_receive(etPort* self, etMessage* msg); - - - - -#endif /* _ETPORT_H_ */ +/*******************************************************************************
+ * Copyright (c) 2012 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)
+ *
+ *******************************************************************************/
+
+
+
+#ifndef _ETPORT_H_
+#define _ETPORT_H_
+
+
+#include "etMessage.h"
+#include "etMessageReceiver.h"
+#include "etMessageService.h"
+
+typedef struct {
+ void* myActor;
+ etReceiveMessage receiveMessageFunc;
+ etMessageService* msgService;
+ etAddressId peerAddress;
+ etAddressId localId;
+
+ #ifdef etDEBUG
+ etAddressId address;
+ /* thread ID from msg service: msgService->threadId */
+ #endif
+} etPort;
+
+void etPort_receive(etPort* self, etMessage* msg);
+
+
+
+
+#endif /* _ETPORT_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etUnit.c b/runtime/org.eclipse.etrice.runtime.c/src/etUnit.c index c798cb92f..405c3d6ac 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/etUnit.c +++ b/runtime/org.eclipse.etrice.runtime.c/src/etUnit.c @@ -1,338 +1,338 @@ -/******************************************************************************* - * 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) - * - *******************************************************************************/ - -#include "etUnit.h" -#include <string.h> -#include <time.h> -#include "etLogger.h" - - -/*** member variables */ - -/* file handling */ -static FILE* etUnit_reportfile = NULL; - -/* names */ -static char* etUnit_TestFileName = NULL; -static char* etUnit_TestResultPath = NULL; - -static char* etUnit_TestSuiteName = NULL; -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; - -#define ETUNIT_FAILURE_TEXT_LEN 256 - -static char etUnit_failureText[ETUNIT_FAILURE_TEXT_LEN]; - -/* time measuring */ -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, 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); - -/* public functions */ - -void etUnit_open(char* testResultPath, char* testFileName) { - etUnit_passCount = 0; - etUnit_failCount = 0; - strcpy(etUnit_failureText,""); - - etUnit_TestFileName = testFileName; - etUnit_TestResultPath = testResultPath; - - 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 = etLogger_fopen(filename, "w+"); - if (etUnit_reportfile != NULL) { - etLogger_fprintf(etUnit_reportfile, "<testsuites name=\"%s\" tests=\"0\" failures=\"0\" errors=\"0\" time=\"0\">\n", etUnit_TestFileName); - } else { - etLogger_logErrorF("Unable to open file %s/%s.xml", etUnit_TestResultPath, etUnit_TestFileName); - } - } - /* prepare time measurement */ - etUnit_startTime = clock(); - etUnit_currentTime = clock(); - etLogger_logInfoF("Start Time: %ld", etUnit_startTime); - -} - -void etUnit_close(void) { - etLogger_logInfoF(""); - if (etUnit_failCount > 0) { - 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 { - etLogger_logInfoF(" ******* ALL TESTS PASSED ******"); - } - etLogger_logInfoF("***************************************"); - - if (etUnit_reportfile != NULL) { - etLogger_fprintf(etUnit_reportfile, "</testsuites>\n"); - etLogger_fclose(etUnit_reportfile); - etUnit_reportfile = NULL; - } -} - -void etUnit_openTestSuite(char* testSuiteName) { - etUnit_TestSuiteName = testSuiteName; - if (etUnit_reportfile != NULL) { - 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) { - etLogger_fprintf(etUnit_reportfile, "\t</testsuite>\n"); - } -} - -void etUnit_openTestCase(char* testCaseName) { - etUnit_TestCaseName = testCaseName; - etUnit_testcaseSuccess = TRUE; - strcpy(etUnit_failureText,""); -} - -void etUnit_closeTestCase(void) { - if (etUnit_reportfile != NULL && etUnit_TestSuiteName != NULL) { - etUnit_writeTestLog(etUnit_TestCaseName, etUnit_testcaseSuccess, etUnit_failureText); - } -} - -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]; - sprintf(testresult, "%s: *** EXPECT_TRUE == FALSE", message); - etUnit_handleExpect(FALSE, testresult); - } else { - etUnit_handleExpect(TRUE, ""); - } -} - -void EXPECT_FALSE(const char* message, etBool condition) { - if (condition == TRUE) { - char testresult[ETUNIT_FAILURE_TEXT_LEN]; - sprintf(testresult, "%s: EXPECT_FALSE == TRUE", message); - etUnit_handleExpect(FALSE, testresult); - } else { - etUnit_handleExpect(TRUE, ""); - } -} - -void EXPECT_EQUAL_INT8(const char* message, etInt8 expected, etInt8 actual) { - expect_equal_int(message, (etInt32) expected, (etInt32) actual); -} - -void EXPECT_EQUAL_INT16(const char* message, etInt16 expected, etInt16 actual) { - expect_equal_int(message, (etInt32) expected, (etInt32) actual); -} - -void EXPECT_EQUAL_INT32(const char* message, etInt32 expected, etInt32 actual) { - expect_equal_int(message, (etInt32) expected, (etInt32) actual); -} - -void EXPECT_EQUAL_UINT8(const char* message, etUInt8 expected, etUInt8 actual) { - expect_equal_uint(message, (etUInt32) expected, (etUInt32) actual); -} - -void EXPECT_EQUAL_UINT16(const char* message, etUInt16 expected, etUInt16 actual) { - expect_equal_uint(message, (etUInt32) expected, (etUInt32) actual); -} - -void EXPECT_EQUAL_UINT32(const char* message, etUInt32 expected, etUInt32 actual) { - expect_equal_uint(message, (etUInt32) expected, (etUInt32) actual); -} - - -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_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 */ - -void expect_equal_int(const char* message, etInt32 expected, etInt32 actual) { - if (expected != actual) { - char testresult[ETUNIT_FAILURE_TEXT_LEN]; - sprintf(testresult, "%s: expected=%ld, actual=%ld", message, expected, actual); - etUnit_handleExpect(FALSE, testresult); - } else { - etUnit_handleExpect(TRUE, ""); - } -} - -void expect_equal_uint(const char* message, etUInt32 expected, etUInt32 actual) { - if (expected != actual) { - char testresult[ETUNIT_FAILURE_TEXT_LEN]; - sprintf(testresult, "%s: expected=%lu, actual=%lu", message, expected, actual); - etUnit_handleExpect(FALSE, testresult); - } else { - etUnit_handleExpect(TRUE, ""); - } -} - - -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); - etUnit_handleExpect(FALSE, testresult); - } else { - etUnit_handleExpect(TRUE, ""); - } -} - -void expect_equal_void_ptr(const char* message, const void* expected, const void* actual) { - if (expected != actual) { - char testresult[ETUNIT_FAILURE_TEXT_LEN]; - sprintf(testresult, "%s: expected=%ld, actual=%ld", message, (etUInt32) expected, (etUInt32) actual); - etUnit_handleExpect(FALSE, testresult); - } else { - etUnit_handleExpect(TRUE, ""); - } -} - - -//_________ - -void etUnit_handleExpect(etBool result, const char *resulttext){ - if (result == TRUE) { - /* nothing to do because no failure */ - } - else { - if (etUnit_testcaseSuccess == TRUE){ - /* first failure will be remembered */ - etUnit_testcaseSuccess = FALSE; - strcpy(etUnit_failureText, resulttext); - } - else{ - /* more than one error will be ignored */ - } - } -} - -void etUnit_buildTestLogXML(char* xml, const char *testcase, etBool result, const char *resulttext, clock_t time) { - if (result == TRUE) { - sprintf(xml, "\t\t<testcase name=\"%s\" time=\"%ld\"/>\n", testcase, time); - } else { - sprintf( - xml, - "\t\t<testcase name=\"%s\" classname=\"none\" time=\"%ld\">\n\t\t<failure>%s</failure>\n\t</testcase>\n", - testcase, time, resulttext); - } -} - -void etUnit_writeTestLog(const char *testcase, etBool result, const char *resulttext) { - char writeBuffer[ETUNIT_FAILURE_TEXT_LEN]; - - // counting - if (result == TRUE) { - etUnit_passCount++; - etUnit_passCountTotal++; - etLogger_logInfoF("PASS: %s %s", testcase, resulttext); - } else { - etUnit_failCount++; - etUnit_failCountTotal++; - etLogger_logInfoF("FAIL: %s : %s", testcase, resulttext); - } - - clock_t time = clock() - etUnit_currentTime; - etUnit_currentTime = clock(); - - // writing to file - if (etUnit_reportfile != NULL) { - etUnit_buildTestLogXML(writeBuffer, testcase, result, resulttext, time); - etLogger_fprintf(etUnit_reportfile, writeBuffer); - } -} - +/*******************************************************************************
+ * 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)
+ *
+ *******************************************************************************/
+
+#include "etUnit.h"
+#include <string.h>
+#include <time.h>
+#include "etLogger.h"
+
+
+/*** member variables */
+
+/* file handling */
+static FILE* etUnit_reportfile = NULL;
+
+/* names */
+static char* etUnit_TestFileName = NULL;
+static char* etUnit_TestResultPath = NULL;
+
+static char* etUnit_TestSuiteName = NULL;
+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;
+
+#define ETUNIT_FAILURE_TEXT_LEN 256
+
+static char etUnit_failureText[ETUNIT_FAILURE_TEXT_LEN];
+
+/* time measuring */
+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, 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);
+
+/* public functions */
+
+void etUnit_open(char* testResultPath, char* testFileName) {
+ etUnit_passCount = 0;
+ etUnit_failCount = 0;
+ strcpy(etUnit_failureText,"");
+
+ etUnit_TestFileName = testFileName;
+ etUnit_TestResultPath = testResultPath;
+
+ 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 = etLogger_fopen(filename, "w+");
+ if (etUnit_reportfile != NULL) {
+ etLogger_fprintf(etUnit_reportfile, "<testsuites name=\"%s\" tests=\"0\" failures=\"0\" errors=\"0\" time=\"0\">\n", etUnit_TestFileName);
+ } else {
+ etLogger_logErrorF("Unable to open file %s/%s.xml", etUnit_TestResultPath, etUnit_TestFileName);
+ }
+ }
+ /* prepare time measurement */
+ etUnit_startTime = clock();
+ etUnit_currentTime = clock();
+ etLogger_logInfoF("Start Time: %ld", etUnit_startTime);
+
+}
+
+void etUnit_close(void) {
+ etLogger_logInfoF("");
+ if (etUnit_failCount > 0) {
+ 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 {
+ etLogger_logInfoF(" ******* ALL TESTS PASSED ******");
+ }
+ etLogger_logInfoF("***************************************");
+
+ if (etUnit_reportfile != NULL) {
+ etLogger_fprintf(etUnit_reportfile, "</testsuites>\n");
+ etLogger_fclose(etUnit_reportfile);
+ etUnit_reportfile = NULL;
+ }
+}
+
+void etUnit_openTestSuite(char* testSuiteName) {
+ etUnit_TestSuiteName = testSuiteName;
+ if (etUnit_reportfile != NULL) {
+ 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) {
+ etLogger_fprintf(etUnit_reportfile, "\t</testsuite>\n");
+ }
+}
+
+void etUnit_openTestCase(char* testCaseName) {
+ etUnit_TestCaseName = testCaseName;
+ etUnit_testcaseSuccess = TRUE;
+ strcpy(etUnit_failureText,"");
+}
+
+void etUnit_closeTestCase(void) {
+ if (etUnit_reportfile != NULL && etUnit_TestSuiteName != NULL) {
+ etUnit_writeTestLog(etUnit_TestCaseName, etUnit_testcaseSuccess, etUnit_failureText);
+ }
+}
+
+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];
+ sprintf(testresult, "%s: *** EXPECT_TRUE == FALSE", message);
+ etUnit_handleExpect(FALSE, testresult);
+ } else {
+ etUnit_handleExpect(TRUE, "");
+ }
+}
+
+void EXPECT_FALSE(const char* message, etBool condition) {
+ if (condition == TRUE) {
+ char testresult[ETUNIT_FAILURE_TEXT_LEN];
+ sprintf(testresult, "%s: EXPECT_FALSE == TRUE", message);
+ etUnit_handleExpect(FALSE, testresult);
+ } else {
+ etUnit_handleExpect(TRUE, "");
+ }
+}
+
+void EXPECT_EQUAL_INT8(const char* message, etInt8 expected, etInt8 actual) {
+ expect_equal_int(message, (etInt32) expected, (etInt32) actual);
+}
+
+void EXPECT_EQUAL_INT16(const char* message, etInt16 expected, etInt16 actual) {
+ expect_equal_int(message, (etInt32) expected, (etInt32) actual);
+}
+
+void EXPECT_EQUAL_INT32(const char* message, etInt32 expected, etInt32 actual) {
+ expect_equal_int(message, (etInt32) expected, (etInt32) actual);
+}
+
+void EXPECT_EQUAL_UINT8(const char* message, etUInt8 expected, etUInt8 actual) {
+ expect_equal_uint(message, (etUInt32) expected, (etUInt32) actual);
+}
+
+void EXPECT_EQUAL_UINT16(const char* message, etUInt16 expected, etUInt16 actual) {
+ expect_equal_uint(message, (etUInt32) expected, (etUInt32) actual);
+}
+
+void EXPECT_EQUAL_UINT32(const char* message, etUInt32 expected, etUInt32 actual) {
+ expect_equal_uint(message, (etUInt32) expected, (etUInt32) actual);
+}
+
+
+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_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 */
+
+void expect_equal_int(const char* message, etInt32 expected, etInt32 actual) {
+ if (expected != actual) {
+ char testresult[ETUNIT_FAILURE_TEXT_LEN];
+ sprintf(testresult, "%s: expected=%ld, actual=%ld", message, expected, actual);
+ etUnit_handleExpect(FALSE, testresult);
+ } else {
+ etUnit_handleExpect(TRUE, "");
+ }
+}
+
+void expect_equal_uint(const char* message, etUInt32 expected, etUInt32 actual) {
+ if (expected != actual) {
+ char testresult[ETUNIT_FAILURE_TEXT_LEN];
+ sprintf(testresult, "%s: expected=%lu, actual=%lu", message, expected, actual);
+ etUnit_handleExpect(FALSE, testresult);
+ } else {
+ etUnit_handleExpect(TRUE, "");
+ }
+}
+
+
+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);
+ etUnit_handleExpect(FALSE, testresult);
+ } else {
+ etUnit_handleExpect(TRUE, "");
+ }
+}
+
+void expect_equal_void_ptr(const char* message, const void* expected, const void* actual) {
+ if (expected != actual) {
+ char testresult[ETUNIT_FAILURE_TEXT_LEN];
+ sprintf(testresult, "%s: expected=%ld, actual=%ld", message, (etUInt32) expected, (etUInt32) actual);
+ etUnit_handleExpect(FALSE, testresult);
+ } else {
+ etUnit_handleExpect(TRUE, "");
+ }
+}
+
+
+//_________
+
+void etUnit_handleExpect(etBool result, const char *resulttext){
+ if (result == TRUE) {
+ /* nothing to do because no failure */
+ }
+ else {
+ if (etUnit_testcaseSuccess == TRUE){
+ /* first failure will be remembered */
+ etUnit_testcaseSuccess = FALSE;
+ strcpy(etUnit_failureText, resulttext);
+ }
+ else{
+ /* more than one error will be ignored */
+ }
+ }
+}
+
+void etUnit_buildTestLogXML(char* xml, const char *testcase, etBool result, const char *resulttext, clock_t time) {
+ if (result == TRUE) {
+ sprintf(xml, "\t\t<testcase name=\"%s\" time=\"%ld\"/>\n", testcase, time);
+ } else {
+ sprintf(
+ xml,
+ "\t\t<testcase name=\"%s\" classname=\"none\" time=\"%ld\">\n\t\t<failure>%s</failure>\n\t</testcase>\n",
+ testcase, time, resulttext);
+ }
+}
+
+void etUnit_writeTestLog(const char *testcase, etBool result, const char *resulttext) {
+ char writeBuffer[ETUNIT_FAILURE_TEXT_LEN];
+
+ // counting
+ if (result == TRUE) {
+ etUnit_passCount++;
+ etUnit_passCountTotal++;
+ etLogger_logInfoF("PASS: %s %s", testcase, resulttext);
+ } else {
+ etUnit_failCount++;
+ etUnit_failCountTotal++;
+ etLogger_logInfoF("FAIL: %s : %s", testcase, resulttext);
+ }
+
+ clock_t time = clock() - etUnit_currentTime;
+ etUnit_currentTime = clock();
+
+ // writing to file
+ if (etUnit_reportfile != NULL) {
+ etUnit_buildTestLogXML(writeBuffer, testcase, result, resulttext, time);
+ 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 dcaa28306..34284c541 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/etUnit.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/etUnit.h @@ -1,70 +1,70 @@ -/******************************************************************************* - * 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) - * - *******************************************************************************/ - -#ifndef _ETUNIT_H_ -#define _ETUNIT_H_ - -#include "etDatatypes.h" - - -/* open / close */ -void etUnit_open(char* testResultPath, char* testFileName); -void etUnit_close(void); -void etUnit_openTestSuite(char* testSuiteName); -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); - -/* signed integer values */ -void EXPECT_EQUAL_INT8(const char* testcase, etInt8 expected, etInt8 actual); -void EXPECT_EQUAL_INT16(const char* testcase, etInt16 expected, etInt16 actual); -void EXPECT_EQUAL_INT32(const char* testcase, etInt32 expected, etInt32 actual); - -/* unsigned integer values */ -void EXPECT_EQUAL_UINT8(const char* testcase, etUInt8 expected, etUInt8 actual); -void EXPECT_EQUAL_UINT16(const char* testcase, etUInt16 expected, etUInt16 actual); -void EXPECT_EQUAL_UINT32(const char* testcase, etUInt32 expected, etUInt32 actual); - -/* float values */ -void EXPECT_EQUAL_FLOAT32(const char* testcase, etFloat32 expected, etFloat32 actual, etFloat32 precision); -void EXPECT_EQUAL_FLOAT64(const char* testcase, etFloat64 expected, etFloat64 actual, etFloat64 precision); - -/* Pointers */ -#define EXPECT_EQUAL_PTR(testcase, expected, actual) \ - expect_equal_void_ptr(testcase, (const void*) expected, (const void*) actual); - -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) \ - etUnit_openTestCase(#testcase); \ - testcase(); \ - etUnit_closeTestCase(); - - -#endif /* _ETUNIT_H_ */ +/*******************************************************************************
+ * 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)
+ *
+ *******************************************************************************/
+
+#ifndef _ETUNIT_H_
+#define _ETUNIT_H_
+
+#include "etDatatypes.h"
+
+
+/* open / close */
+void etUnit_open(char* testResultPath, char* testFileName);
+void etUnit_close(void);
+void etUnit_openTestSuite(char* testSuiteName);
+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);
+
+/* signed integer values */
+void EXPECT_EQUAL_INT8(const char* testcase, etInt8 expected, etInt8 actual);
+void EXPECT_EQUAL_INT16(const char* testcase, etInt16 expected, etInt16 actual);
+void EXPECT_EQUAL_INT32(const char* testcase, etInt32 expected, etInt32 actual);
+
+/* unsigned integer values */
+void EXPECT_EQUAL_UINT8(const char* testcase, etUInt8 expected, etUInt8 actual);
+void EXPECT_EQUAL_UINT16(const char* testcase, etUInt16 expected, etUInt16 actual);
+void EXPECT_EQUAL_UINT32(const char* testcase, etUInt32 expected, etUInt32 actual);
+
+/* float values */
+void EXPECT_EQUAL_FLOAT32(const char* testcase, etFloat32 expected, etFloat32 actual, etFloat32 precision);
+void EXPECT_EQUAL_FLOAT64(const char* testcase, etFloat64 expected, etFloat64 actual, etFloat64 precision);
+
+/* Pointers */
+#define EXPECT_EQUAL_PTR(testcase, expected, actual) \
+ expect_equal_void_ptr(testcase, (const void*) expected, (const void*) actual);
+
+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) \
+ etUnit_openTestCase(#testcase); \
+ testcase(); \
+ etUnit_closeTestCase();
+
+
+#endif /* _ETUNIT_H_ */
|