Refactoring the massive main() to smaller functions.
--HG-- rename : test/test-automation/tests/asserts.c => test/test-automation/tests/SDL_test.c rename : test/test-automation/tests/asserts.h => test/test-automation/tests/SDL_test.h
This commit is contained in:
parent
4540a8a1b9
commit
d6d8dec05e
7 changed files with 137 additions and 83 deletions
|
@ -25,21 +25,13 @@
|
|||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "tests/SDL_test.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
// Handle command line arguments
|
||||
|
||||
// print: Testing againts SDL version fuu (rev: bar)
|
||||
|
||||
int failureCount = 0, passCount = 0;
|
||||
|
||||
const Uint32 startTicks = SDL_GetTicks();
|
||||
|
||||
void *LoadLibrary() {
|
||||
#if defined(linux) || defined( __linux)
|
||||
char *libName = "tests/libtest.so";
|
||||
#else
|
||||
char *libName = "tests/libtest.0.dylib";
|
||||
#else
|
||||
char *libName = "tests/libtest.dylib";
|
||||
#endif
|
||||
|
||||
void *library = SDL_LoadObject(libName);
|
||||
|
@ -48,71 +40,100 @@ int main(int argc, char *argv[]) {
|
|||
printf("%s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
const char **(*suite)(void);
|
||||
suite = (const char **(*)(void)) SDL_LoadFunction(library, "suite");
|
||||
return library;
|
||||
}
|
||||
|
||||
char **QueryTestCases(void *library) {
|
||||
char **(*suite)(void);
|
||||
|
||||
suite = (char **(*)(void)) SDL_LoadFunction(library, "queryTestNames");
|
||||
if(suite == NULL) {
|
||||
printf("Retrieving test names failed, suite == NULL\n");
|
||||
printf("Quering test names failed, suite == NULL\n");
|
||||
printf("%s\n", SDL_GetError());
|
||||
} else {
|
||||
const char **tests = suite();
|
||||
}
|
||||
|
||||
char *testname = NULL;
|
||||
int counter = 0;
|
||||
for(; (testname = (char *) tests[counter]); ++counter) {
|
||||
int childpid = fork();
|
||||
char **tests = suite();
|
||||
if(tests == NULL) {
|
||||
printf("Failed to load test cases. tests == NULL\n");
|
||||
printf("%s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
if(childpid == 0) {
|
||||
void (*test)(void *arg);
|
||||
return tests;
|
||||
}
|
||||
|
||||
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
|
||||
int HandleTestReturnValue(int stat_lock) {
|
||||
if(WIFEXITED(stat_lock)) {
|
||||
int returnValue = WEXITSTATUS(stat_lock);
|
||||
|
||||
if(returnValue == 0) {
|
||||
return 1;
|
||||
}
|
||||
} else if(WIFSIGNALED(stat_lock)) {
|
||||
int signal = WTERMSIG(stat_lock);
|
||||
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)) {
|
||||
//int signal = WSTOPSIG(stat_lock);
|
||||
//printf("%d: %d was stopped by signal nro %d\n", pid, child, signal);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
// Handle command line arguments
|
||||
|
||||
// print: Testing againts SDL version fuu (rev: bar)
|
||||
|
||||
int failureCount = 0, passCount = 0;
|
||||
char *testname = NULL;
|
||||
int counter = 0;
|
||||
|
||||
char *libName = "libtest";
|
||||
|
||||
const Uint32 startTicks = SDL_GetTicks();
|
||||
|
||||
void *library = LoadLibrary();
|
||||
char **tests = QueryTestCases(library);
|
||||
|
||||
for(testname = tests[counter]; testname; testname = tests[++counter]) {
|
||||
printf("Running %s (in %s):\n", testname, 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 {
|
||||
int stat_lock = -1;
|
||||
int child = wait(&stat_lock);
|
||||
test(0x0);
|
||||
}
|
||||
return 0; // exit the child if the test didn't exit
|
||||
} else {
|
||||
int stat_lock = -1;
|
||||
int child = wait(&stat_lock);
|
||||
|
||||
char *errorMsg = NULL;
|
||||
int passed = -1;
|
||||
if(WIFEXITED(stat_lock)) {
|
||||
int returnValue = WEXITSTATUS(stat_lock);
|
||||
int passed = -1;
|
||||
|
||||
if(returnValue == 0) {
|
||||
passed = 1;
|
||||
} else {
|
||||
passed = 0;
|
||||
}
|
||||
} else if(WIFSIGNALED(stat_lock)) {
|
||||
int signal = WTERMSIG(stat_lock);
|
||||
//printf("%d: %d was killed by signal nro %d\n", pid, child, signal);
|
||||
//errorMsg =
|
||||
errorMsg = SDL_malloc(256 * sizeof(char));
|
||||
sprintf(errorMsg, "was aborted due to signal nro %d", signal);
|
||||
passed = HandleTestReturnValue(stat_lock);
|
||||
|
||||
passed = 0;
|
||||
} else if(WIFSTOPPED(stat_lock)) {
|
||||
//int signal = WSTOPSIG(stat_lock);
|
||||
//printf("%d: %d was stopped by signal nro %d\n", pid, child, signal);
|
||||
}
|
||||
|
||||
printf("%s (in %s):", testname, libName);
|
||||
if(passed) {
|
||||
passCount++;
|
||||
printf("\tok\n");
|
||||
} else {
|
||||
failureCount++;
|
||||
printf("\tfailed\n");
|
||||
if(errorMsg) {
|
||||
printf("\t%s\n", errorMsg);
|
||||
SDL_free(errorMsg);
|
||||
}
|
||||
}
|
||||
if(passed) {
|
||||
passCount++;
|
||||
printf("%s (in %s): ok\n", testname, libName);
|
||||
} else {
|
||||
failureCount++;
|
||||
printf("%s (in %s): failed\n", testname, libName);
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
SDL_UnloadObject(library);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue