mirror of
https://github.com/ThrowTheSwitch/CException
synced 2025-06-03 19:09:32 -04:00
cleaned up order of inclusion and testability
git-svn-id: http://cexception.svn.sourceforge.net/svnroot/cexception/trunk@3 50f63946-2846-0410-8d77-f904c773002e
This commit is contained in:
parent
fecd94cb5c
commit
7044cfe1a8
54
lib/CException.h
Normal file
54
lib/CException.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#ifndef _CEXCEPTION_H
|
||||||
|
#define _CEXCEPTION_H
|
||||||
|
|
||||||
|
#include <setjmp.h>
|
||||||
|
|
||||||
|
#ifndef EXCEPTION_NONE
|
||||||
|
#define EXCEPTION_NONE (0x5A5A5A5A)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef EXCEPTION_NUM_ID
|
||||||
|
#define EXCEPTION_NUM_ID (1) //there is only the one stack by default
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef EXCEPTION_GET_ID
|
||||||
|
#define EXCEPTION_GET_ID (0) //use the first index always because there is only one anyway
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//exception frame structures
|
||||||
|
typedef struct {
|
||||||
|
jmp_buf* pFrame;
|
||||||
|
volatile unsigned int Exception;
|
||||||
|
volatile unsigned int Details;
|
||||||
|
} EXCEPTION_FRAME_T;
|
||||||
|
extern volatile EXCEPTION_FRAME_T ExceptionFrames[];
|
||||||
|
|
||||||
|
#define MY_FRAME (ExceptionFrames[EXCEPTION_GET_ID])
|
||||||
|
#define MY_FRAME_FAST (ExceptionFrames[MY_ID])
|
||||||
|
#define EXCEPTION_ID (MY_FRAME.Exception)
|
||||||
|
#define EXCEPTION_DETAILS (MY_FRAME.Details)
|
||||||
|
|
||||||
|
#define Try \
|
||||||
|
{ \
|
||||||
|
jmp_buf *PrevFrame, NewFrame; \
|
||||||
|
unsigned int MY_ID = EXCEPTION_GET_ID; \
|
||||||
|
PrevFrame = MY_FRAME.pFrame; \
|
||||||
|
MY_FRAME_FAST.pFrame = &NewFrame; \
|
||||||
|
MY_FRAME_FAST.Details = 0; \
|
||||||
|
MY_FRAME_FAST.Exception = EXCEPTION_NONE; \
|
||||||
|
if (setjmp(NewFrame) == 0) { \
|
||||||
|
if (&PrevFrame)
|
||||||
|
|
||||||
|
#define Catch \
|
||||||
|
else { } \
|
||||||
|
MY_FRAME_FAST.Exception = EXCEPTION_NONE; \
|
||||||
|
} \
|
||||||
|
MY_FRAME_FAST.pFrame = PrevFrame; \
|
||||||
|
} \
|
||||||
|
if (MY_FRAME.Exception != EXCEPTION_NONE)
|
||||||
|
|
||||||
|
#define Throw(id) ThrowDetailed(id, __LINE__)
|
||||||
|
void ThrowDetailed(unsigned int ExceptionID, unsigned int Details);
|
||||||
|
void Rethrow(void);
|
||||||
|
|
||||||
|
#endif // _CEXCEPTION_H
|
@ -1,43 +1,23 @@
|
|||||||
#ifndef _EXCEPTION_H
|
#ifndef _EXCEPTION_H
|
||||||
#define _EXCEPTION_H
|
#define _EXCEPTION_H
|
||||||
|
|
||||||
#include <setjmp.h>
|
// Define the reserved value representing NO EXCEPTION
|
||||||
#include "ExceptionConfig.h"
|
#define EXCEPTION_NONE (0x5A5A5A5A)
|
||||||
|
|
||||||
//exception frame structures
|
// Multi-Tasking environments will need a couple of macros defined to make this library
|
||||||
typedef struct {
|
// properly handle multiple exception stacks. You will need to include and required
|
||||||
jmp_buf* pFrame;
|
// definitions, then define the following macros:
|
||||||
volatile unsigned int Exception;
|
// EXCEPTION_GET_ID - returns the id of the current task indexed 0 to (numtasks - 1)
|
||||||
volatile unsigned int Details;
|
// EXCEPTION_NUM_ID - returns the number of tasks that might be returned
|
||||||
} EXCEPTION_FRAME_T;
|
//
|
||||||
extern volatile EXCEPTION_FRAME_T ExceptionFrames[];
|
// For example, Quadros might include the following implementation:
|
||||||
|
#ifndef TEST
|
||||||
|
#include "OSAPI.h"
|
||||||
|
#define EXCEPTION_GET_ID() (KS_GetTaskID())
|
||||||
|
#define EXCEPTION_NUM_ID (NTASKS + 1)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MY_FRAME (ExceptionFrames[EXCEPTION_GET_ID()])
|
// INCLUDE THE ACTUAL CEXCEPTION LIBRARY
|
||||||
#define MY_FRAME_FAST (ExceptionFrames[MY_ID])
|
#include "CException.h"
|
||||||
#define EXCEPTION_ID (MY_FRAME.Exception)
|
|
||||||
#define EXCEPTION_DETAILS (MY_FRAME.Details)
|
|
||||||
|
|
||||||
#define Try \
|
|
||||||
{ \
|
|
||||||
jmp_buf *PrevFrame, NewFrame; \
|
|
||||||
unsigned int MY_ID = EXCEPTION_GET_ID(); \
|
|
||||||
PrevFrame = MY_FRAME.pFrame; \
|
|
||||||
MY_FRAME_FAST.pFrame = &NewFrame; \
|
|
||||||
MY_FRAME_FAST.Details = 0; \
|
|
||||||
MY_FRAME_FAST.Exception = EXCEPTION_NONE; \
|
|
||||||
if (setjmp(NewFrame) == 0) { \
|
|
||||||
if (&PrevFrame)
|
|
||||||
|
|
||||||
#define Catch \
|
|
||||||
else { } \
|
|
||||||
MY_FRAME_FAST.Exception = EXCEPTION_NONE; \
|
|
||||||
} \
|
|
||||||
MY_FRAME_FAST.pFrame = PrevFrame; \
|
|
||||||
} \
|
|
||||||
if (MY_FRAME.Exception != EXCEPTION_NONE)
|
|
||||||
|
|
||||||
#define Throw(id) ThrowDetailed(id, __LINE__)
|
|
||||||
void ThrowDetailed(unsigned int ExceptionID, unsigned int Details);
|
|
||||||
void Rethrow(void);
|
|
||||||
|
|
||||||
#endif // _EXCEPTION_H
|
#endif // _EXCEPTION_H
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
#ifndef _EXCEPTION_CONFIG_H
|
|
||||||
#define _EXCEPTION_CONFIG_H
|
|
||||||
|
|
||||||
//#define EXCEPTION_MULTI_STACK
|
|
||||||
#define EXCEPTION_NONE (0x5A5A5A5A)
|
|
||||||
|
|
||||||
//if using multistack support and not currently running a test, must include multistack support
|
|
||||||
#undef EXCEPTION_INCLUDE_MULTI_STACK_SUPPORT
|
|
||||||
#ifndef TEST
|
|
||||||
#ifdef EXCEPTION_MULTI_STACK
|
|
||||||
#define EXCEPTION_INCLUDE_MULTI_STACK_SUPPORT
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//define the method of automatically looking up the current frame index (mappable from task ID if the task ID's are consecutive)
|
|
||||||
// The example below supports the Quadros OS in Multi-Stack Mode. Most RTOS will support a similar function call.
|
|
||||||
#ifdef EXCEPTION_INCLUDE_MULTI_STACK_SUPPORT
|
|
||||||
#include "OSAPI.h"
|
|
||||||
#define EXCEPTION_GET_ID() (KS_GetTaskID())
|
|
||||||
#define EXCEPTION_NUM_ID (NTASKS + 1)
|
|
||||||
#else
|
|
||||||
#define EXCEPTION_GET_ID() (0) //use the first index always because there is only one anyway
|
|
||||||
#define EXCEPTION_NUM_ID (1) //there is only the one stack
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif //_EXCEPTION_CONFIG_H
|
|
4
makefile
4
makefile
@ -1,7 +1,7 @@
|
|||||||
#Tool and Lib Locations
|
#Tool and Lib Locations
|
||||||
C_COMPILER=gcc
|
C_COMPILER=gcc
|
||||||
C_LIBS=C:/MinGW/lib
|
C_LIBS=C:/MinGW/lib
|
||||||
UNITY_DIR=../../unity/src
|
UNITY_DIR=vendor/unity/src
|
||||||
|
|
||||||
#Test File To Be Created
|
#Test File To Be Created
|
||||||
OUT_FILE=test_cexceptions
|
OUT_FILE=test_cexceptions
|
||||||
@ -12,7 +12,7 @@ OUT_EXTENSION=.out
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
#Options
|
#Options
|
||||||
SRC_FILES=lib/Exception.c test/TestException.c test/TestException_Runner.c $(UNITY_DIR)/unity.c
|
SRC_FILES=lib/CException.c test/TestException.c test/TestException_Runner.c $(UNITY_DIR)/unity.c
|
||||||
INC_DIRS=-Ilib -Itest -I$(UNITY_DIR)
|
INC_DIRS=-Ilib -Itest -I$(UNITY_DIR)
|
||||||
LIB_DIRS=-L$(C_LIBS)
|
LIB_DIRS=-L$(C_LIBS)
|
||||||
SYMBOLS=-DTEST
|
SYMBOLS=-DTEST
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include <setjmp.h>
|
|
||||||
|
|
||||||
jmp_buf AbortFrame;
|
|
||||||
|
|
||||||
extern void setUp(void);
|
extern void setUp(void);
|
||||||
extern void tearDown(void);
|
extern void tearDown(void);
|
||||||
@ -21,7 +18,7 @@ extern void test_CanThrowADetailedExceptionAndCheckOutTheResults(void);
|
|||||||
|
|
||||||
static void runTest(UnityTestFunction test)
|
static void runTest(UnityTestFunction test)
|
||||||
{
|
{
|
||||||
if (setjmp(AbortFrame) == 0)
|
if (TEST_PROTECT())
|
||||||
{
|
{
|
||||||
setUp();
|
setUp();
|
||||||
Try
|
Try
|
||||||
|
Loading…
x
Reference in New Issue
Block a user