Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
124 lines (99 loc) · 3.37 KB

File metadata and controls

124 lines (99 loc) · 3.37 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
Copyright (C) 2011 Markus Kauppila <markus.kauppila@gmail.com>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
May 23, 2011
May 23, 2011
21
#include "SDL/SDL.h"
22
23
24
25
26
27
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
May 23, 2011
May 23, 2011
28
29
int main(int argc, char *argv[]) {
May 23, 2011
May 23, 2011
30
31
32
33
34
35
36
37
38
// Handle command line arguments
// print: Testing againts SDL version fuu (rev: bar)
int failureCount = 0, passCount = 0;
const Uint32 startTicks = SDL_GetTicks();
39
40
41
42
43
44
45
char *libName = "libtest.so";
void *library = SDL_LoadObject(libName);
if(library == NULL) {
printf("Loading %s failed\n", libName);
printf("%s\n", SDL_GetError());
}
May 23, 2011
May 23, 2011
46
47
const char **(*suite)(void);
suite = (const char **(*)(void)) SDL_LoadFunction(library, "suite");
48
if(suite == NULL) {
May 23, 2011
May 23, 2011
49
printf("Retrieving test names failed, suite == NULL\n");
50
51
printf("%s\n", SDL_GetError());
} else {
May 23, 2011
May 23, 2011
52
const char **tests = suite();
53
54
55
char *testname = NULL;
int counter = 0;
May 23, 2011
May 23, 2011
56
for(; (testname = (char *) tests[counter]); ++counter) {
57
58
int childpid = fork();
May 23, 2011
May 23, 2011
59
if(childpid == 0) {
60
61
62
63
void (*test)(void *arg);
test = (void (*)(void *)) SDL_LoadFunction(library, testname);
if(test == NULL) {
May 23, 2011
May 23, 2011
64
printf("Loading test failed, tests == NULL\n");
65
66
67
68
69
70
71
72
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);
May 23, 2011
May 23, 2011
73
74
75
char *errorMsg = NULL;
int passed = -1;
76
if(WIFEXITED(stat_lock)) {
May 23, 2011
May 23, 2011
77
int returnValue = WEXITSTATUS(stat_lock);
May 23, 2011
May 23, 2011
79
80
81
82
83
if(returnValue == 0) {
passed = 1;
} else {
passed = 0;
}
84
85
} else if(WIFSIGNALED(stat_lock)) {
int signal = WTERMSIG(stat_lock);
May 23, 2011
May 23, 2011
86
87
88
89
90
91
//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;
92
93
94
95
} else if(WIFSTOPPED(stat_lock)) {
//int signal = WSTOPSIG(stat_lock);
//printf("%d: %d was stopped by signal nro %d\n", pid, child, signal);
}
May 23, 2011
May 23, 2011
96
97
98
99
100
101
102
103
104
105
106
107
108
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);
}
}
109
110
111
112
113
}
}
}
SDL_UnloadObject(library);
May 23, 2011
May 23, 2011
114
115
116
117
118
119
120
121
122
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);