Tiny changes to runner
This commit is contained in:
parent
850eb7ba82
commit
58ff822335
4 changed files with 93 additions and 30 deletions
|
@ -18,48 +18,50 @@
|
|||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "SDL/SDL_loadso.h"
|
||||
#include "SDL/SDL.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int pid = getpid();
|
||||
int testsFailed = 0, testsPassed = 0;
|
||||
|
||||
|
||||
// Handle command line arguments
|
||||
|
||||
// print: Testing againts SDL version fuu (rev: bar)
|
||||
|
||||
int failureCount = 0, passCount = 0;
|
||||
|
||||
const Uint32 startTicks = SDL_GetTicks();
|
||||
|
||||
char *libName = "libtest.so";
|
||||
printf("%d: Loading .so containing tests\n", pid);
|
||||
void *library = SDL_LoadObject(libName);
|
||||
if(library == NULL) {
|
||||
printf("Loading %s failed\n", libName);
|
||||
printf("%s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
printf("%d: Asking for the test case names\n", pid);
|
||||
char **(*suite)(void);
|
||||
suite = (char **(*)(void)) SDL_LoadFunction(library, "suite");
|
||||
const char **(*suite)(void);
|
||||
suite = (const char **(*)(void)) SDL_LoadFunction(library, "suite");
|
||||
if(suite == NULL) {
|
||||
printf("%d: Retrieving test names failed, suite == NULL\n", pid);
|
||||
printf("Retrieving test names failed, suite == NULL\n");
|
||||
printf("%s\n", SDL_GetError());
|
||||
} else {
|
||||
char **tests = suite();
|
||||
const char **tests = suite();
|
||||
|
||||
char *testname = NULL;
|
||||
int counter = 0;
|
||||
for(; (testname = tests[counter]); ++counter) {
|
||||
for(; (testname = (char *) tests[counter]); ++counter) {
|
||||
int childpid = fork();
|
||||
if(childpid == 0) {
|
||||
pid = getpid();
|
||||
|
||||
printf("%d: Loading test: %s\n", pid, testname);
|
||||
|
||||
if(childpid == 0) {
|
||||
void (*test)(void *arg);
|
||||
|
||||
test = (void (*)(void *)) SDL_LoadFunction(library, testname);
|
||||
if(test == NULL) {
|
||||
printf("%d: Loading test failed, tests == NULL\n", pid);
|
||||
printf("Loading test failed, tests == NULL\n");
|
||||
printf("%s\n", SDL_GetError());
|
||||
} else {
|
||||
test(0x0);
|
||||
|
@ -68,30 +70,55 @@ int main(int argc, char *argv[]) {
|
|||
} else {
|
||||
int stat_lock = -1;
|
||||
int child = wait(&stat_lock);
|
||||
|
||||
if(WIFEXITED(stat_lock)) {
|
||||
int rv = WEXITSTATUS(stat_lock);
|
||||
printf("%d: %d exited normally with value %d\n", pid, child, rv);
|
||||
|
||||
testsPassed++;
|
||||
char *errorMsg = NULL;
|
||||
int passed = -1;
|
||||
if(WIFEXITED(stat_lock)) {
|
||||
int returnValue = WEXITSTATUS(stat_lock);
|
||||
|
||||
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);
|
||||
|
||||
testsFailed++;
|
||||
//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 = 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d: all tests executed\n", pid);
|
||||
printf("%d: %d tests passed\n", pid, testsPassed);
|
||||
printf("%d: %d tests failed\n", pid, testsFailed);
|
||||
|
||||
SDL_UnloadObject(library);
|
||||
|
||||
|
||||
const Uint32 endTicks = SDL_GetTicks();
|
||||
|
||||
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 failed\n", failureCount);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue