Skip to content

Instantly share code, notes, and snippets.

@cloudrain21
Last active January 16, 2016 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloudrain21/bf3d4e3f1a5186261e37 to your computer and use it in GitHub Desktop.
Save cloudrain21/bf3d4e3f1a5186261e37 to your computer and use it in GitHub Desktop.
recovery test framework
#include "rth.h"
#ifdef _RTF_TEST
cmnRTFInfo gTestCaseMap[MAX_RTF_HASH];
static int cmnRTFGetHashVal ( const char* aTestString , int aStrLen )
{
int i;
unsigned int sKey = 0;
char sStrT[128];
unsigned int* sPtr = (unsigned int *)sStrT;
memset_s ( sStrT, 0x00, sizeof( sStrT ) );
strncpy ( sStrT, aTestString, aStrLen );
for ( i = 0; i < aStrLen; i++ )
{
sKey += *( sPtr++ );
}
return sKey % ( MAX_RTF_HASH - 1 );
}
/*
* gTestCaseMap
* --- --- ---
* | | -> | | -> | |
* | 0 | --- ---
* |---| --- ---
* | | -> | | -> | |
* | 1 | --- ---
* |---| ---
* | | -> | |
* | 2 | ---
* |---|
* | |
*/
void cmnRTFEnable( char* aTestCaseName,
int aTargetCount,
int aRTFType,
int aPrintOutF )
{
int sHashVal;
cmnRTFInfo* sCurRTF = NULL;
cmnRTFInfo* sNewRTF = NULL;
cmnRTFInfo* sLastRTF = NULL;
sHashVal = cmnRTFGetHashVal( (const char *)aTestCaseName, strlen_s(aTestCaseName) );
if( gTestCaseMap[sHashVal].mEnable == 1 )
{
if( gTestCaseMap[sHashVal].mNext == NULL )
{
sNewRTF = (cmnRTFInfo *)malloc_s(sizeof(cmnRTFInfo));
memset_s( sNewRTF, 0x00, sizeof(cmnRTFInfo));
gTestCaseMap[sHashVal].mNext = sNewRTF;
}
else
{
sCurRTF = gTestCaseMap[sHashVal].mNext;
while( sCurRTF != NULL )
{
if( sCurRTF->mNext == NULL )
{
sLastRTF = sCurRTF;
}
sCurRTF = sCurRTF->mNext;
}
sNewRTF = (cmnRTFInfo *)malloc_s(sizeof(cmnRTFInfo));
memset_s( sNewRTF, 0x00, sizeof(cmnRTFInfo));
sLastRTF->mNext = sNewRTF;
}
sNewRTF->mEnable = 1;
strcpy_s( sNewRTF->mName, aTestCaseName );
sNewRTF->mRTFType = aRTFType;
sNewRTF->mPrintOutF = aPrintOutF;
sNewRTF->mTargetCount = aTargetCount;
if( aPrintOutF )
{
printf("Enable RTF( %s, %d )\n", sNewRTF->mName, aTargetCount);
}
}
else
{
gTestCaseMap[sHashVal].mEnable = 1;
strcpy_s( gTestCaseMap[sHashVal].mName, aTestCaseName );
gTestCaseMap[sHashVal].mRTFType = aRTFType;
gTestCaseMap[sHashVal].mPrintOutF = aPrintOutF;
gTestCaseMap[sHashVal].mTargetCount = aTargetCount;
if( aPrintOutF )
{
printf("Enable RTF( %s, %d )\n", gTestCaseMap[sHashVal].mName, aTargetCount);
}
}
}
static cmnRTFInfo* cmnFindRTFInfo ( int aHashVal , const char* aTestCaseName )
{
cmnRTFInfo* sCurRTF = NULL;
if ( ! strcmp_s ( gTestCaseMap[aHashVal].mName, aTestCaseName ) )
{
return &gTestCaseMap[aHashVal];
}
sCurRTF = gTestCaseMap[aHashVal].mNext;
while ( sCurRTF != NULL )
{
if ( ! strcmp_s ( sCurRTF->mName, aTestCaseName ) )
{
return sCurRTF;
}
sCurRTF = sCurRTF->mNext;
}
return NULL;
}
_VOID cmnRTFPoint ( const char* aTestCaseName )
{
int sHashVal;
cmnRTFInfo* sFind = NULL;
_TRY
{
if ( _cmn_use_rtf == 0 )
_RETURN;
sHashVal = cmnRTFGetHashVal( aTestCaseName, strlen_s(aTestCaseName) );
sFind = cmnFindRTFInfo( sHashVal, aTestCaseName );
if( sFind == NULL )
{
/*
* 각 cmnRTFPoint 마다 Hash / Find 해보고
* 없으면 그냥 리턴할거다.
*/
_RETURN;
}
if( sFind->mEnable == 1 )
{
sFind->mCurrCount++;
if( sFind->mCurrCount == sFind->mTargetCount )
{
switch( sFind->mRTFType )
{
case CMN_RTF_ABORT:
if( sFind->mPrintOutF )
{
printf("ABORT( %s, %d )\n", sFind->mName, sFind->mTargetCount);
}
exit(1); /* abort message 를 없앨 수가 없어서 그냥 exit 로 */
break;
case CMN_RTF_DEFER_ABORT:
usleep ( 100 * 1000 );
exit(1);
break;
default:
break;
}
}
}
}
_CATCH
{
_CATCH_ERR;
}
_FINALLY
_END
}
#endif /* _RTF_TEST */
/**
* Recovery Test Framework
*/
#ifndef __RTF_H__
#define __RTF_H__
#ifdef __cplusplus
extern "C" {
#endif
#define CMN_RTF_ABORT 0x00
#define CMN_RTF_DEFER_ABORT 0x01
#define MAX_RTF_HASH 100
#ifdef _DEBUG
#define _RTF_TEST
#endif
/*
* 실제 RTF Point 지점에는 RTF_POINT macro 를 사용한다.
*/
#ifdef _RTF_TEST
typedef struct cmnRTFInfo
{
char mName[64];
char mRTFType;
char mEnable;
int mTargetCount;
int mCurrCount;
int mPrintOutF;
struct cmnRTFInfo* mNext;
} cmnRTFInfo;
extern cmnRTFInfo gTestCaseMap[MAX_RTF_HASH];
extern void cmnRTFInit ( );
extern void cmnRTFEnable ( char* aName , int aTargetCount , int aRTFType , int aPrintOutF );
extern int cmnRTFPoint ( const char* aTestString );
#define RTF_POINT(x) cmnRTFPoint( x );
#else
#define cmnRTFEnable(a,...)
#define cmnRTFPoint(x)
#define RTF_POINT(x)
#endif
#ifdef __cplusplus
}
#endif
#endif /* __RTF_H__ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment