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

Latest commit

 

History

History
159 lines (119 loc) · 4.11 KB

File metadata and controls

159 lines (119 loc) · 4.11 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 26, 2011
May 26, 2011
28
#include "tests/SDL_test.h"
May 23, 2011
May 23, 2011
29
May 26, 2011
May 26, 2011
30
void *LoadLibrary() {
May 25, 2011
May 25, 2011
31
32
#if defined(linux) || defined( __linux)
char *libName = "tests/libtest.so";
May 26, 2011
May 26, 2011
33
34
#else
char *libName = "tests/libtest.dylib";
May 25, 2011
May 25, 2011
35
36
#endif
37
38
39
40
41
42
void *library = SDL_LoadObject(libName);
if(library == NULL) {
printf("Loading %s failed\n", libName);
printf("%s\n", SDL_GetError());
}
May 26, 2011
May 26, 2011
43
44
45
return library;
}
May 26, 2011
May 26, 2011
46
47
TestCaseReference **QueryTestCases(void *library) {
TestCaseReference **(*suite)(void);
May 26, 2011
May 26, 2011
48
May 26, 2011
May 26, 2011
49
suite = (TestCaseReference **(*)(void)) SDL_LoadFunction(library, "QueryTestCaseReferences");
50
if(suite == NULL) {
May 26, 2011
May 26, 2011
51
printf("Loading QueryTestCaseReferences() failed.\n");
May 26, 2011
May 26, 2011
52
53
54
printf("%s\n", SDL_GetError());
}
May 26, 2011
May 26, 2011
55
TestCaseReference **tests = suite();
May 26, 2011
May 26, 2011
56
if(tests == NULL) {
May 26, 2011
May 26, 2011
57
printf("Failed to load test references.\n");
58
printf("%s\n", SDL_GetError());
May 26, 2011
May 26, 2011
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
}
return tests;
}
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 *libName = "libtest";
const Uint32 startTicks = SDL_GetTicks();
void *library = LoadLibrary();
May 26, 2011
May 26, 2011
100
101
TestCaseReference **tests = QueryTestCases(library);
May 26, 2011
May 26, 2011
102
103
104
105
106
107
108
109
110
111
112
TestCaseReference *reference = NULL;
int counter = 0;
printf("DEBUG: Starting to run test\n");
fflush(stdout);
for(reference = tests[counter]; reference; reference = tests[++counter]) {
// segfaults immediately after trying to access name -> out of bounds
// all the values of reference is garbage.
char *testname = reference->name;
//char *testname = reference; // for some reason this works
May 26, 2011
May 26, 2011
113
114
115
116
117
118
119
120
121
122
123
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());
May 26, 2011
May 26, 2011
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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;
passed = HandleTestReturnValue(stat_lock);
if(passed) {
passCount++;
printf("%s (in %s): ok\n", testname, libName);
} else {
failureCount++;
printf("%s (in %s): failed\n", testname, libName);
May 26, 2011
May 26, 2011
144
145
printf("\n");
146
147
148
}
SDL_UnloadObject(library);
May 23, 2011
May 23, 2011
149
150
151
152
153
154
155
156
157
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);