Commit 73fa28c7 authored by Markus Kauppila's avatar Markus Kauppila

Added doxygen-compatible comments

parent 7004e4ae
This diff is collapsed.
...@@ -27,7 +27,12 @@ ...@@ -27,7 +27,12 @@
#include "tests/SDL_test.h" #include "tests/SDL_test.h"
void *LoadLibrary() { /*!
* Loads test suite which is implemented as dynamic library.
*
* \return Loaded test suite
*/
void *LoadTestSuite() {
#if defined(linux) || defined( __linux) #if defined(linux) || defined( __linux)
char *libName = "tests/libtest.so"; char *libName = "tests/libtest.so";
#else #else
...@@ -43,10 +48,16 @@ void *LoadLibrary() { ...@@ -43,10 +48,16 @@ void *LoadLibrary() {
return library; return library;
} }
/*!
* Loads the test case references from the given test suite.
* \param library Previously loaded dynamic library AKA test suite
* \return Loaded TestCaseReferences
*/
TestCaseReference **QueryTestCases(void *library) { TestCaseReference **QueryTestCases(void *library) {
TestCaseReference **(*suite)(void); TestCaseReference **(*suite)(void);
suite = (TestCaseReference **(*)(void)) SDL_LoadFunction(library, "QueryTestCaseReferences"); suite = (TestCaseReference **(*)(void)) SDL_LoadFunction(library, "QueryTestSuite");
if(suite == NULL) { if(suite == NULL) {
printf("Loading QueryTestCaseReferences() failed.\n"); printf("Loading QueryTestCaseReferences() failed.\n");
printf("%s\n", SDL_GetError()); printf("%s\n", SDL_GetError());
...@@ -61,6 +72,21 @@ TestCaseReference **QueryTestCases(void *library) { ...@@ -61,6 +72,21 @@ TestCaseReference **QueryTestCases(void *library) {
return tests; return tests;
} }
/*
*
*/
/*!
* Success or failure of test case is determined by
* it's return value. If test case succeeds, it'll
* return 0, if not it will return a positive integer.
*
* The function checks the return value and returns value
* based on it. If the test is aborted due to a signal
* function warn about it.
*
* \return 1 if test case succeeded, 0 otherwise
*/
int HandleTestReturnValue(int stat_lock) { int HandleTestReturnValue(int stat_lock) {
if(WIFEXITED(stat_lock)) { if(WIFEXITED(stat_lock)) {
int returnValue = WEXITSTATUS(stat_lock); int returnValue = WEXITSTATUS(stat_lock);
...@@ -71,13 +97,8 @@ int HandleTestReturnValue(int stat_lock) { ...@@ -71,13 +97,8 @@ int HandleTestReturnValue(int stat_lock) {
} else if(WIFSIGNALED(stat_lock)) { } else if(WIFSIGNALED(stat_lock)) {
int signal = WTERMSIG(stat_lock); int signal = WTERMSIG(stat_lock);
printf("FAILURE: test was aborted due to signal nro %d\n", signal); printf("FAILURE: test was aborted due to signal nro %d\n", signal);
//errorMsg =
//errorMsg = SDL_malloc(256 * sizeof(char));
//sprintf(errorMsg, "was aborted due to signal nro %d", signal);
} else if(WIFSTOPPED(stat_lock)) { } else if(WIFSTOPPED(stat_lock)) {
//int signal = WSTOPSIG(stat_lock);
//printf("%d: %d was stopped by signal nro %d\n", pid, child, signal);
} }
return 0; return 0;
...@@ -86,7 +107,7 @@ int HandleTestReturnValue(int stat_lock) { ...@@ -86,7 +107,7 @@ int HandleTestReturnValue(int stat_lock) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
// Handle command line arguments //! \todo Handle command line arguments
// print: Testing againts SDL version fuu (rev: bar) // print: Testing againts SDL version fuu (rev: bar)
...@@ -96,58 +117,59 @@ int main(int argc, char *argv[]) { ...@@ -96,58 +117,59 @@ int main(int argc, char *argv[]) {
const Uint32 startTicks = SDL_GetTicks(); const Uint32 startTicks = SDL_GetTicks();
void *library = LoadLibrary(); void *suite = LoadTestSuite();
TestCaseReference **tests = QueryTestCases(library); TestCaseReference **tests = QueryTestCases(suite);
TestCaseReference *reference = NULL; TestCaseReference *reference = NULL;
int counter = 0; int counter = 0;
printf("DEBUG: Starting to run test\n");
fflush(stdout);
for(reference = tests[counter]; reference; reference = tests[++counter]) { for(reference = tests[counter]; reference; reference = tests[++counter]) {
char *testname = reference->name; if(reference->enabled == TEST_DISABLED) {
printf("Running %s (in %s):\n", testname, libName); printf("Test %s (in %s) disabled. Omitting...\n", reference->name, libName);
int childpid = fork();
if(childpid == 0) {
void (*test)(void *arg);
test = (void (*)(void *)) SDL_LoadFunction(library, testname);
if(test == NULL) {
printf("Loading test failed, tests == NULL\n");
printf("%s\n", SDL_GetError());
} else {
test(0x0);
}
return 0; // exit the child if the test didn't exit
} else { } else {
int stat_lock = -1; char *testname = reference->name;
int child = wait(&stat_lock);
printf("Running %s (in %s):\n", testname, libName);
int childpid = fork();
if(childpid == 0) {
void (*test)(void *arg);
test = (void (*)(void *)) SDL_LoadFunction(suite, testname);
if(test == NULL) {
printf("Loading test failed, tests == NULL\n");
printf("%s\n", SDL_GetError());
} else {
test(0x0);
}
return 0; // exit the child if the test didn't exit
} else {
int stat_lock = -1;
int child = wait(&stat_lock);
int passed = -1; int passed = -1;
passed = HandleTestReturnValue(stat_lock); passed = HandleTestReturnValue(stat_lock);
if(passed) { if(passed) {
passCount++; passCount++;
printf("%s (in %s): ok\n", testname, libName); printf("%s (in %s): ok\n", testname, libName);
} else { } else {
failureCount++; failureCount++;
printf("%s (in %s): failed\n", testname, libName); printf("%s (in %s): failed\n", testname, libName);
}
} }
} }
printf("\n"); printf("\n");
} }
SDL_UnloadObject(library); SDL_UnloadObject(suite);
const Uint32 endTicks = SDL_GetTicks(); const Uint32 endTicks = SDL_GetTicks();
printf("Ran %d tests in %0.3f seconds.\n", (passCount + failureCount), (endTicks-startTicks)/1000.0f); printf("Ran %d tests in %0.3f seconds.\n", (passCount + failureCount), (endTicks-startTicks)/1000.0f);
printf("all tests executed\n");
printf("%d tests passed\n", passCount); printf("%d tests passed\n", passCount);
printf("%d tests failed\n", failureCount); printf("%d tests failed\n", failureCount);
......
...@@ -25,16 +25,17 @@ ...@@ -25,16 +25,17 @@
#include <stdlib.h> #include <stdlib.h>
/*! \brief return value of test case. Non-zero value means that the test failed */
static int _testReturnValue; static int _testReturnValue;
void void
TestInit() TestCaseInit()
{ {
_testReturnValue = 0; _testReturnValue = 0;
} }
void void
TestQuit() TestCaseQuit()
{ {
exit(_testReturnValue); exit(_testReturnValue);
} }
......
...@@ -23,15 +23,34 @@ ...@@ -23,15 +23,34 @@
#include <SDL/SDL.h> #include <SDL/SDL.h>
// \todo Should these be consts?
#define TEST_ENABLED 1
#define TEST_DISABLED 0
/*!
* Holds information about a test case
*/
typedef struct TestCaseReference { typedef struct TestCaseReference {
char *name; /* "Func2Stress" */ char *name; /*!< "Func2Stress" */
char *description; /* "This test beats the crap out of func2()" */ char *description; /*!< "This test beats the crap out of func2()" */
int enabled; /* Set to TEST_ENABLED or TEST_DISABLED */ int enabled; /*!< Set to TEST_ENABLED or TEST_DISABLED */
long requirements; /* Set to TEST_REQUIRES_OPENGL, TEST_REQUIRES_AUDIO, ... */ long requirements; /*!< Set to TEST_REQUIRES_OPENGL, TEST_REQUIRES_AUDIO, ... */
} TestCaseReference; } TestCaseReference;
void TestInit(); /*! \fn TestCaseInit
void TestQuit(); * Initialized the test case. Must be called at
* the beginning of every test case, before doing
* anything else.
*/
void TestCaseInit();
/*! \fn TestCaseQuit
* Deinitializes and exits the test case
*
*/
void TestCaseQuit();
void AssertEquals(char *message, Uint32 expected, Uint32 actual); void AssertEquals(char *message, Uint32 expected, Uint32 actual);
......
...@@ -28,50 +28,56 @@ ...@@ -28,50 +28,56 @@
#include "SDL_test.h" #include "SDL_test.h"
/* Test cases */ /* Test cases */
static const TestCaseReference test1 = static const TestCaseReference test1 =
(TestCaseReference){ "hello", "description", 1, 0 }; (TestCaseReference){ "hello", "description", TEST_ENABLED, 0 };
static const TestCaseReference test2 = static const TestCaseReference test2 =
(TestCaseReference){ "hello2", "description", 1, 0 }; (TestCaseReference){ "hello2", "description", TEST_DISABLED, 0 };
static const TestCaseReference test3 =
(TestCaseReference){ "hello3", "description", TEST_ENABLED, 0 };
/* Test suite */ /* Test suite */
extern const TestCaseReference *testSuite[] = { extern const TestCaseReference *testSuite[] = {
&test1, &test2, NULL &test1, &test2, &test3, NULL
}; };
TestCaseReference **QueryTestCaseReferences() { TestCaseReference **QueryTestSuite() {
return (TestCaseReference **)testSuite; return (TestCaseReference **)testSuite;
} }
void hello(void *arg){ /* Test case functions */
TestInit(); void hello(void *arg)
{
TestCaseInit();
const char *revision = SDL_GetRevision(); const char *revision = SDL_GetRevision();
printf("Revision is %s\n", revision); printf("Revision is %s\n", revision);
AssertEquals("will fail", 3, 5); AssertEquals("will fail", 3, 5);
TestQuit(); TestCaseQuit();
} }
void hello2(void *arg) { void hello2(void *arg)
TestInit(); {
TestCaseInit();
// why this isn't segfaulting?
char *msg = "eello"; char *msg = "eello";
msg[0] = 'H'; msg[0] = 'H';
TestQuit(); TestCaseQuit();
} }
void hello3(void *arg) { void hello3(void *arg)
TestInit(); {
TestCaseInit();
printf("hello3\n"); printf("hello3\n");
AssertEquals("passes", 3, 3); AssertEquals("passes", 3, 3);
TestQuit(); TestCaseQuit();
} }
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment