Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Refactor/fix test lib harness, assert and log component; add harness …

…driver; port platform suite from GSOC code
  • Loading branch information
ferzkopp committed Dec 15, 2012
1 parent a8836b0 commit 2ac73343d937f9c8355d3b6facf329c9960f867d
@@ -49,9 +49,13 @@ extern "C" {
/* *INDENT-ON* */
#endif

/* Function prototypes */
/* Global definitions */

/* ADD STUFF HERE */
/*
* Note: Maximum size of SDLTest log message is less than SDLs limit
* to ensure we can fit additional information such as the timestamp.
*/
#define SDLTEST_MAX_LOGMESSAGE_LENGTH 3584

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
@@ -60,17 +60,24 @@ extern "C" {
* \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0).
* \param assertDescription Message to log with the assert describing it.
*/
void SDLTest_Assert(int assertCondition, char *assertDescription);
void SDLTest_Assert(int assertCondition, char *assertDescription, ...);

/**
* \brief Assert for test cases that logs but does not break execution flow on failures.
* \brief Assert for test cases that logs but does not break execution flow on failures. Updates assertion counters.
*
* \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0).
* \param assertDescription Message to log with the assert describing it.
*
* \returns Returns the assertCondition so it can be used to externall to break execution flow if desired.
* \returns Returns the assertCondition so it can be used to externally to break execution flow if desired.
*/
int SDLTest_AssertCheck(int assertCondition, char *assertDescription);
int SDLTest_AssertCheck(int assertCondition, char *assertDescription, ...);

/**
* \brief Explicitely pass without checking an assertion condition. Updates assertion counter.
*
* \param assertDescription Message to log with the assert describing it.
*/
void SDLTest_AssertPass(char *assertDescription, ...);

/**
* \brief Resets the assert summary counters to zero.
@@ -98,6 +98,20 @@ typedef struct SDLTest_TestSuiteReference {
SDLTest_TestCaseTearDownFp testTearDown;
} SDLTest_TestSuiteReference;


/**
* \brief Execute a test suite using the given run seed and execution key.
*
* \param testSuites Suites containing the test case.
* \param userRunSeed Custom run seed provided by user, or NULL to autogenerate one.
* \param userExecKey Custom execution key provided by user, or 0 to autogenerate one.
* \param testIterations Number of iterations to run each test case.
*
* \returns Test run result; 0 when all tests passed, 1 if any tests failed.
*/
int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], char *userRunSeed, Uint64 userExecKey, int testIterations);


/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
@@ -30,10 +30,10 @@
#include "SDL_test.h"

/* Assert check message format */
const char *SDLTest_AssertCheckFmt = "Assert '%s': %s";
const char *SDLTest_AssertCheckFormat = "Assert '%s': %s";

/* Assert summary message format */
const char *SDLTest_AssertSummaryFmt = "Assert Summary: Total=%d Passed=%d Failed=%d";
const char *SDLTest_AssertSummaryFormat = "Assert Summary: Total=%d Passed=%d Failed=%d";

/*! \brief counts the failed asserts */
static Uint32 SDLTest_AssertsFailed = 0;
@@ -44,31 +44,71 @@ static Uint32 SDLTest_AssertsPassed = 0;
/*
* Assert that logs and break execution flow on failures (i.e. for harness errors).
*/
void SDLTest_Assert(int assertCondition, char *assertDescription)
void SDLTest_Assert(int assertCondition, char *assertDescription, ...)
{
SDL_assert((SDLTest_AssertCheck(assertCondition, assertDescription)));
va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];

// Print assert description into a buffer
memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
va_start(list, assertDescription);
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
va_end(list);

// Log, then assert and break on failure
SDL_assert((SDLTest_AssertCheck(assertCondition, logMessage)));
}

/*
* Assert that logs but does not break execution flow on failures (i.e. for test cases).
*/
int SDLTest_AssertCheck(int assertCondition, char *assertDescription)
int SDLTest_AssertCheck(int assertCondition, char *assertDescription, ...)
{
char *fmt = (char *)SDLTest_AssertCheckFmt;
va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
char *logFormat = (char *)SDLTest_AssertCheckFormat;

// Print assert description into a buffer
memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
va_start(list, assertDescription);
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
va_end(list);

// Log pass or fail message
if (assertCondition == ASSERT_FAIL)
{
SDLTest_AssertsFailed++;
SDLTest_LogError(fmt, assertDescription, "Failed");
SDLTest_LogError(logFormat, logMessage, "Failed");
}
else
{
SDLTest_AssertsPassed++;
SDLTest_Log(fmt, assertDescription, "Passed");
SDLTest_Log(logFormat, logMessage, "Passed");
}

return assertCondition;
}

/*
* Explicitly passing Assert that logs (i.e. for test cases).
*/
void SDLTest_AssertPass(char *assertDescription, ...)
{
va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
char *logFormat = (char *)SDLTest_AssertCheckFormat;

// Print assert description into a buffer
memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
va_start(list, assertDescription);
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
va_end(list);

// Log pass message
SDLTest_AssertsPassed++;
SDLTest_Log(logFormat, logMessage, "Pass");
}

/*
* Resets the assert summary counters to zero.
*/
@@ -84,15 +124,15 @@ void SDLTest_ResetAssertSummary()
*/
void SDLTest_LogAssertSummary()
{
char *fmt = (char *)SDLTest_AssertSummaryFmt;
char *logFormat = (char *)SDLTest_AssertSummaryFormat;
Uint32 totalAsserts = SDLTest_AssertsPassed + SDLTest_AssertsFailed;
if (SDLTest_AssertsFailed == 0)
{
SDLTest_Log(fmt, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
SDLTest_Log(logFormat, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
}
else
{
SDLTest_LogError(fmt, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
SDLTest_LogError(logFormat, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
}
}

@@ -58,7 +58,7 @@ SDLTest_FuzzerInit(Uint64 execKey)
}

int
SDLTest_GetInvocationCount()
SDLTest_GetFuzzerInvocationCount()
{
return fuzzerInvocationCounter;
}

0 comments on commit 2ac7334

Please sign in to comment.