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

Latest commit

 

History

History
763 lines (614 loc) · 20.1 KB

File metadata and controls

763 lines (614 loc) · 20.1 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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
Jun 5, 2011
Jun 5, 2011
26
#include <string.h>
Jun 7, 2011
Jun 7, 2011
27
#include <dirent.h>
Jun 5, 2011
Jun 5, 2011
28
29
30
#include <sys/types.h>
May 30, 2011
May 30, 2011
31
#include "SDL_test.h"
Jun 26, 2011
Jun 26, 2011
32
#include "logger.h"
Jun 9, 2011
Jun 9, 2011
33
May 30, 2011
May 30, 2011
34
//!< Function pointer to a test case function
Jun 9, 2011
Jun 9, 2011
35
typedef void (*TestCaseFp)(void *arg);
Jun 4, 2011
Jun 4, 2011
36
//!< Function pointer to a test case init function
Jun 26, 2011
Jun 26, 2011
37
typedef void (*TestCaseInitFp)(const int);
Jun 4, 2011
Jun 4, 2011
38
//!< Function pointer to a test case quit function
Jun 9, 2011
Jun 9, 2011
39
40
typedef int (*TestCaseQuitFp)(void);
May 30, 2011
May 30, 2011
41
Jun 1, 2011
Jun 1, 2011
42
43
//!< Flag for executing tests in-process
static int execute_inproc = 0;
Jun 13, 2011
Jun 13, 2011
44
45
//!< Flag for only printing out the test names
static int only_print_tests = 0;
Jun 5, 2011
Jun 5, 2011
46
47
48
49
//!< Flag for executing only test with selected name
static int only_selected_test = 0;
//!< Flag for executing only the selected test suite
static int only_selected_suite = 0;
Jun 9, 2011
Jun 9, 2011
50
51
//!< Flag for executing only tests that contain certain string in their name
static int only_tests_with_string = 0;
Jun 26, 2011
Jun 26, 2011
52
53
//!< Flag for enabling XML logging
static int xml_enabled = 0;
Jun 30, 2011
Jun 30, 2011
54
55
//! Flag for enabling user-supplied style sheet for XML test report
static int custom_xsl_enabled = 0;
Jun 9, 2011
Jun 9, 2011
56
Jun 5, 2011
Jun 5, 2011
57
Jun 8, 2011
Jun 8, 2011
58
//!< Size of the test and suite name buffers
Jun 7, 2011
Jun 7, 2011
59
#define NAME_BUFFER_SIZE 1024
Jun 5, 2011
Jun 5, 2011
60
61
62
63
//!< Name of the selected test
char selected_test_name[NAME_BUFFER_SIZE];
//!< Name of the selected suite
char selected_suite_name[NAME_BUFFER_SIZE];
Jun 4, 2011
Jun 4, 2011
64
Jun 9, 2011
Jun 9, 2011
65
66
67
//!< substring of test case name
char testcase_name_substring[NAME_BUFFER_SIZE];
Jun 30, 2011
Jun 30, 2011
68
69
70
//! Name for user-supplied XSL style sheet name
char xsl_stylesheet_name[NAME_BUFFER_SIZE];
Jun 8, 2011
Jun 8, 2011
71
72
73
//! Default directory of the test suites
#define DEFAULT_TEST_DIRECTORY "tests/"
Jun 9, 2011
Jun 9, 2011
74
Jun 7, 2011
Jun 7, 2011
75
/*!
Jun 9, 2011
Jun 9, 2011
76
77
* Holds information about test suite such as it's name
* and pointer to dynamic library. Implemented as linked list.
Jun 7, 2011
Jun 7, 2011
78
79
*/
typedef struct TestSuiteReference {
Jun 9, 2011
Jun 9, 2011
80
char *name; //!< test suite name
Jun 9, 2011
Jun 9, 2011
81
void *library; //!< pointer to shared/dynamic library implementing the suite
Jun 9, 2011
Jun 9, 2011
82
Jun 7, 2011
Jun 7, 2011
83
84
85
struct TestSuiteReference *next; //!< Pointer to next item in the list
} TestSuiteReference;
Jun 9, 2011
Jun 9, 2011
86
87
88
89
90
91
/*!
* Holds information about the tests that will be executed.
*
* Implemented as linked list.
*/
Jun 9, 2011
Jun 9, 2011
92
93
94
95
typedef struct TestCaseItem {
char *testName;
char *suiteName;
Jun 26, 2011
Jun 26, 2011
96
97
98
99
char *description;
long requirements;
long timeout;
Jun 9, 2011
Jun 9, 2011
100
101
102
TestCaseInitFp testCaseInit;
TestCaseFp testCase;
TestCaseQuitFp testCaseQuit;
Jun 9, 2011
Jun 9, 2011
103
104
struct TestCaseItem *next;
Jun 9, 2011
Jun 9, 2011
105
106
107
108
109
110
111
112
113
114
} TestCase;
/*! Some function prototypes. Add the rest of functions and move to runner.h */
TestCaseFp LoadTestCaseFunction(void *suite, char *testName);
TestCaseInitFp LoadTestCaseInitFunction(void *suite);
TestCaseQuitFp LoadTestCaseQuitFunction(void *suite);
TestCaseReference **QueryTestCaseReferences(void *library);
Jun 4, 2011
Jun 4, 2011
115
May 30, 2011
May 30, 2011
116
/*!
Jun 7, 2011
Jun 7, 2011
117
118
* Scans the tests/ directory and returns the names
* of the dynamic libraries implementing the test suites.
Jun 8, 2011
Jun 8, 2011
119
*
Jun 7, 2011
Jun 7, 2011
120
121
* Note: currently function assumes that test suites names
* are in following format: libtestsuite.dylib or libtestsuite.so.
May 30, 2011
May 30, 2011
122
*
Jun 8, 2011
Jun 8, 2011
123
124
125
126
* Note: if only_selected_suite flags is non-zero, only the selected
* test will be loaded.
*
* \param directoryName Name of the directory which will be scanned
Jun 9, 2011
Jun 9, 2011
127
* \param extension What file extension is used with dynamic objects
Jun 8, 2011
Jun 8, 2011
128
*
Jun 7, 2011
Jun 7, 2011
129
* \return Pointer to TestSuiteReference which holds all the info about suites
May 30, 2011
May 30, 2011
130
*/
Jun 7, 2011
Jun 7, 2011
131
TestSuiteReference *
Jun 9, 2011
Jun 9, 2011
132
133
ScanForTestSuites(char *directoryName, char *extension)
{
Jun 7, 2011
Jun 7, 2011
134
typedef struct dirent Entry;
Jun 8, 2011
Jun 8, 2011
135
DIR *directory = opendir(directoryName);
Jun 7, 2011
Jun 7, 2011
136
137
138
139
TestSuiteReference *suites = NULL;
Entry *entry = NULL;
Jun 9, 2011
Jun 9, 2011
140
if(!directory) {
Jun 9, 2011
Jun 9, 2011
141
perror("Couldn't open test suite directory!");
Jun 9, 2011
Jun 9, 2011
142
}
Jun 7, 2011
Jun 7, 2011
143
Jun 9, 2011
Jun 9, 2011
144
while(entry = readdir(directory)) {
Jun 11, 2011
Jun 11, 2011
145
if(strlen(entry->d_name) > 2) { // discards . and ..
Jun 9, 2011
Jun 9, 2011
146
147
148
const char *delimiters = ".";
char *name = strtok(entry->d_name, delimiters);
char *ext = strtok(NULL, delimiters);
Jun 8, 2011
Jun 8, 2011
149
Jun 9, 2011
Jun 9, 2011
150
151
152
153
154
// filter out all other suites but the selected test suite
int ok = 1;
if(only_selected_suite) {
ok = SDL_strncmp(selected_suite_name, name, NAME_BUFFER_SIZE) == 0;
}
Jun 8, 2011
Jun 8, 2011
155
Jun 9, 2011
Jun 9, 2011
156
157
158
if(ok && SDL_strcmp(ext, extension) == 0) {
char buffer[NAME_BUFFER_SIZE];
memset(buffer, 0, NAME_BUFFER_SIZE);
Jun 7, 2011
Jun 7, 2011
159
Jun 9, 2011
Jun 9, 2011
160
161
162
163
strcat(buffer, directoryName);
strcat(buffer, name);
strcat(buffer, ".");
strcat(buffer, ext);
Jun 7, 2011
Jun 7, 2011
164
Jun 9, 2011
Jun 9, 2011
165
166
167
// create test suite reference
TestSuiteReference *reference = (TestSuiteReference *) SDL_malloc(sizeof(TestSuiteReference));
memset(reference, 0, sizeof(TestSuiteReference));
Jun 7, 2011
Jun 7, 2011
168
Jun 9, 2011
Jun 9, 2011
169
170
int length = strlen(buffer) + 1; // + 1 for '\0'?
reference->name = SDL_malloc(length * sizeof(char));
Jun 8, 2011
Jun 8, 2011
171
Jun 9, 2011
Jun 9, 2011
172
strcpy(reference->name, buffer);
Jun 7, 2011
Jun 7, 2011
173
Jun 9, 2011
Jun 9, 2011
174
175
reference->next = suites;
suites = reference;
Jun 7, 2011
Jun 7, 2011
176
Jun 9, 2011
Jun 9, 2011
177
//printf("Reference added to: %s\n", buffer);
Jun 7, 2011
Jun 7, 2011
178
179
180
181
}
}
}
Jun 9, 2011
Jun 9, 2011
182
183
closedir(directory);
Jun 7, 2011
Jun 7, 2011
184
return suites;
Jun 1, 2011
Jun 1, 2011
185
186
}
May 25, 2011
May 25, 2011
187
Jun 9, 2011
Jun 9, 2011
188
189
190
191
192
193
/*!
* Goes through the previously loaded test suites and
* loads test cases from them. Test cases are filtered
* during the process. Function will only return the
* test cases which aren't filtered out.
*
Jun 9, 2011
Jun 9, 2011
194
* \param suites previously loaded test suites
Jun 9, 2011
Jun 9, 2011
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
*
* \return Test cases that survived filtering process.
*/
TestCase *
LoadTestCases(TestSuiteReference *suites)
{
TestCase *testCases = NULL;
TestSuiteReference *suiteReference = NULL;
for(suiteReference = suites; suiteReference; suiteReference = suiteReference->next) {
TestCaseReference **tests = QueryTestCaseReferences(suiteReference->library);
TestCaseReference *testReference = NULL;
int counter = 0;
for(testReference = tests[counter]; testReference; testReference = tests[++counter]) {
void *suite = suiteReference->library;
// Load test case functions
TestCaseInitFp testCaseInit = LoadTestCaseInitFunction(suiteReference->library);
TestCaseQuitFp testCaseQuit = LoadTestCaseQuitFunction(suiteReference->library);
TestCaseFp testCase = (TestCaseFp) LoadTestCaseFunction(suiteReference->library, testReference->name);
// Do the filtering
if(FilterTestCase(testReference)) {
TestCase *item = SDL_malloc(sizeof(TestCase));
memset(item, 0, sizeof(TestCase));
item->testCaseInit = testCaseInit;
item->testCase = testCase;
item->testCaseQuit = testCaseQuit;
Jun 26, 2011
Jun 26, 2011
227
// copy suite name
Jun 27, 2011
Jun 27, 2011
228
int length = SDL_strlen(suiteReference->name) + 1;
Jun 9, 2011
Jun 9, 2011
229
item->suiteName = SDL_malloc(length);
Jun 27, 2011
Jun 27, 2011
230
strncpy(item->suiteName, suiteReference->name, length);
Jun 9, 2011
Jun 9, 2011
231
Jun 26, 2011
Jun 26, 2011
232
// copy test name
Jun 27, 2011
Jun 27, 2011
233
length = SDL_strlen(testReference->name) + 1;
Jun 9, 2011
Jun 9, 2011
234
item->testName = SDL_malloc(length);
Jun 27, 2011
Jun 27, 2011
235
strncpy(item->testName, testReference->name, length);
Jun 9, 2011
Jun 9, 2011
236
Jun 26, 2011
Jun 26, 2011
237
// copy test description
Jun 27, 2011
Jun 27, 2011
238
length = SDL_strlen(testReference->description) + 1;
Jun 26, 2011
Jun 26, 2011
239
item->description = SDL_malloc(length);
Jun 27, 2011
Jun 27, 2011
240
strncpy(item->description, testReference->description, length);
Jun 26, 2011
Jun 26, 2011
241
242
243
244
item->requirements = testReference->requirements;
item->timeout = testReference->timeout;
Jun 9, 2011
Jun 9, 2011
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
// prepend the list
item->next = testCases;
testCases = item;
//printf("Added test: %s\n", testReference->name);
}
}
}
return testCases;
}
/*!
* Unloads the given TestCases. Frees all the resources
* allocated for test cases.
*
* \param testCases Test cases to be deallocated
*/
void
UnloadTestCases(TestCase *testCases)
{
TestCase *ref = testCases;
while(ref) {
SDL_free(ref->testName);
SDL_free(ref->suiteName);
Jun 26, 2011
Jun 26, 2011
271
SDL_free(ref->description);
Jun 9, 2011
Jun 9, 2011
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
TestCase *temp = ref->next;
SDL_free(ref);
ref = temp;
}
testCases = NULL;
}
/*!
* Filters a test case based on its properties in TestCaseReference and user
* preference.
*
* \return Non-zero means test will be added to execution list, zero means opposite
*/
int
FilterTestCase(TestCaseReference *testReference)
{
int retVal = 1;
if(testReference->enabled == TEST_DISABLED) {
retVal = 0;
}
Jun 9, 2011
Jun 9, 2011
297
298
299
300
301
302
303
304
if(only_selected_test) {
if(SDL_strncmp(testReference->name, selected_test_name, NAME_BUFFER_SIZE) == 0) {
retVal = 1;
} else {
retVal = 0;
}
}
Jun 9, 2011
Jun 9, 2011
305
306
307
308
309
310
311
312
313
314
315
316
if(only_tests_with_string) {
if(strstr(testReference->name, testcase_name_substring) != NULL) {
retVal = 1;
} else {
retVal = 0;
}
}
return retVal;
}
Jun 1, 2011
Jun 1, 2011
317
318
319
/*!
* Loads test suite which is implemented as dynamic library.
*
Jun 4, 2011
Jun 4, 2011
320
* \param testSuiteName Name of the test suite which will be loaded
Jun 1, 2011
Jun 1, 2011
321
322
323
324
325
326
327
*
* \return Pointer to loaded test suite, or NULL if library could not be loaded
*/
void *
LoadTestSuite(char *testSuiteName)
{
void *library = SDL_LoadObject(testSuiteName);
328
if(library == NULL) {
Jun 1, 2011
Jun 1, 2011
329
fprintf(stderr, "Loading %s failed\n", testSuiteName);
May 31, 2011
May 31, 2011
330
fprintf(stderr, "%s\n", SDL_GetError());
May 26, 2011
May 26, 2011
333
334
335
return library;
}
Jun 5, 2011
Jun 5, 2011
336
Jun 9, 2011
Jun 9, 2011
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
/*!
* Goes through all the given TestSuiteReferences
* and loads the dynamic libraries. Updates the suites
* parameter on-the-fly and returns it.
*
* \param suites Suites that will be loaded
*
* \return Updated TestSuiteReferences with pointer to loaded libraries
*/
TestSuiteReference *
LoadTestSuites(TestSuiteReference *suites)
{
TestSuiteReference *reference = NULL;
for(reference = suites; reference; reference = reference->next) {
reference->library = LoadTestSuite(reference->name);
}
return suites;
}
/*!
* Unloads the given TestSuiteReferences. Frees all
* the allocated resources including the dynamic libraries.
*
* \param suites TestSuiteReferences for deallocation process
*/
void
UnloadTestSuites(TestSuiteReference *suites)
{
TestSuiteReference *ref = suites;
while(ref) {
SDL_free(ref->name);
SDL_UnloadObject(ref->library);
TestSuiteReference *temp = ref->next;
SDL_free(ref);
ref = temp;
}
suites = NULL;
}
May 30, 2011
May 30, 2011
381
382
383
384
/*!
* Loads the test case references from the given test suite.
* \param library Previously loaded dynamic library AKA test suite
May 31, 2011
May 31, 2011
385
* \return Pointer to array of TestCaseReferences or NULL if function failed
May 30, 2011
May 30, 2011
386
*/
May 30, 2011
May 30, 2011
387
TestCaseReference **
Jun 9, 2011
Jun 9, 2011
388
QueryTestCaseReferences(void *library)
May 30, 2011
May 30, 2011
389
{
Jun 9, 2011
Jun 9, 2011
390
TestCaseReference **(*suite)(void);
May 26, 2011
May 26, 2011
391
Jun 9, 2011
Jun 9, 2011
392
393
394
395
396
suite = (TestCaseReference **(*)(void)) SDL_LoadFunction(library, "QueryTestSuite");
if(suite == NULL) {
fprintf(stderr, "Loading QueryTestCaseReferences() failed.\n");
fprintf(stderr, "%s\n", SDL_GetError());
}
May 26, 2011
May 26, 2011
397
Jun 9, 2011
Jun 9, 2011
398
399
400
401
402
TestCaseReference **tests = suite();
if(tests == NULL) {
fprintf(stderr, "Failed to load test references.\n");
fprintf(stderr, "%s\n", SDL_GetError());
}
May 26, 2011
May 26, 2011
403
Jun 9, 2011
Jun 9, 2011
404
return tests;
May 26, 2011
May 26, 2011
405
406
}
Jun 4, 2011
Jun 4, 2011
407
May 30, 2011
May 30, 2011
408
409
410
/*!
* Loads test case from a test suite
*
May 30, 2011
May 30, 2011
411
412
* \param suite a test suite
* \param testName Name of the test that is going to be loaded
May 30, 2011
May 30, 2011
413
*
May 31, 2011
May 31, 2011
414
* \return Function Pointer (TestCase) to loaded test case, NULL if function failed
May 30, 2011
May 30, 2011
415
*/
Jun 9, 2011
Jun 9, 2011
416
417
TestCaseFp
LoadTestCaseFunction(void *suite, char *testName)
May 30, 2011
May 30, 2011
418
{
Jun 9, 2011
Jun 9, 2011
419
TestCaseFp test = (TestCaseFp) SDL_LoadFunction(suite, testName);
May 30, 2011
May 30, 2011
420
if(test == NULL) {
May 31, 2011
May 31, 2011
421
422
fprintf(stderr, "Loading test failed, tests == NULL\n");
fprintf(stderr, "%s\n", SDL_GetError());
May 30, 2011
May 30, 2011
423
424
425
426
427
}
return test;
}
Jun 5, 2011
Jun 5, 2011
428
Jun 4, 2011
Jun 4, 2011
429
430
431
432
433
434
435
436
/*!
* Loads function that initialises the test case from the
* given test suite.
*
* \param suite Used test suite
*
* \return Function pointer (TestCaseInit) which points to loaded init function. NULL if function fails.
*/
Jun 9, 2011
Jun 9, 2011
437
438
439
TestCaseInitFp
LoadTestCaseInitFunction(void *suite) {
TestCaseInitFp testCaseInit = (TestCaseInitFp) SDL_LoadFunction(suite, "_TestCaseInit");
Jun 4, 2011
Jun 4, 2011
440
441
442
443
444
445
446
447
if(testCaseInit == NULL) {
fprintf(stderr, "Loading TestCaseInit function failed, testCaseInit == NULL\n");
fprintf(stderr, "%s\n", SDL_GetError());
}
return testCaseInit;
}
Jun 5, 2011
Jun 5, 2011
448
Jun 4, 2011
Jun 4, 2011
449
450
451
452
453
454
455
456
/*!
* Loads function that deinitialises the executed test case from the
* given test suite.
*
* \param suite Used test suite
*
* \return Function pointer (TestCaseInit) which points to loaded init function. NULL if function fails.
*/
Jun 9, 2011
Jun 9, 2011
457
458
459
TestCaseQuitFp
LoadTestCaseQuitFunction(void *suite) {
TestCaseQuitFp testCaseQuit = (TestCaseQuitFp) SDL_LoadFunction(suite, "_TestCaseQuit");
Jun 4, 2011
Jun 4, 2011
460
461
462
463
464
465
466
if(testCaseQuit == NULL) {
fprintf(stderr, "Loading TestCaseQuit function failed, testCaseQuit == NULL\n");
fprintf(stderr, "%s\n", SDL_GetError());
}
return testCaseQuit;
}
May 30, 2011
May 30, 2011
467
Jun 5, 2011
Jun 5, 2011
468
May 30, 2011
May 30, 2011
469
/*!
May 30, 2011
May 30, 2011
470
471
472
473
* If using out-of-proc execution of tests. This function
* will handle the return value of the child process
* and interprets it to the runner. Also prints warnings
* if child was aborted by a signela.
May 30, 2011
May 30, 2011
474
*
May 30, 2011
May 30, 2011
475
* \param stat_lock information about the exited child process
May 30, 2011
May 30, 2011
476
*
May 30, 2011
May 30, 2011
477
* \return 0 if test case succeeded, 1 otherwise
May 30, 2011
May 30, 2011
478
*/
May 30, 2011
May 30, 2011
479
int
Jun 9, 2011
Jun 9, 2011
480
HandleChildProcessReturnValue(int stat_lock)
May 30, 2011
May 30, 2011
481
{
May 30, 2011
May 30, 2011
482
int returnValue = -1;
May 26, 2011
May 26, 2011
483
May 30, 2011
May 30, 2011
484
485
if(WIFEXITED(stat_lock)) {
returnValue = WEXITSTATUS(stat_lock);
May 26, 2011
May 26, 2011
486
487
} else if(WIFSIGNALED(stat_lock)) {
int signal = WTERMSIG(stat_lock);
May 31, 2011
May 31, 2011
488
fprintf(stderr, "FAILURE: test was aborted due to signal no %d\n", signal);
May 30, 2011
May 30, 2011
489
returnValue = 1;
May 26, 2011
May 26, 2011
490
491
}
May 30, 2011
May 30, 2011
492
return returnValue;
May 26, 2011
May 26, 2011
493
494
}
Jun 5, 2011
Jun 5, 2011
495
Jun 4, 2011
Jun 4, 2011
496
497
498
499
/*!
* Executes a test case. Loads the test, executes it and
* returns the tests return value to the caller.
*
Jun 9, 2011
Jun 9, 2011
500
* \param testItem The test case that will be executed
Jun 4, 2011
Jun 4, 2011
501
502
503
* \return The return value of the test. Zero means success, non-zero failure.
*/
int
Jun 9, 2011
Jun 9, 2011
504
ExecuteTest(TestCase *testItem) {
Jun 4, 2011
Jun 4, 2011
505
506
int retVal = 1;
if(execute_inproc) {
Jun 26, 2011
Jun 26, 2011
507
testItem->testCaseInit(xml_enabled);
Jun 4, 2011
Jun 4, 2011
508
Jun 9, 2011
Jun 9, 2011
509
testItem->testCase(0x0);
Jun 4, 2011
Jun 4, 2011
510
Jun 9, 2011
Jun 9, 2011
511
retVal = testItem->testCaseQuit();
Jun 4, 2011
Jun 4, 2011
512
513
514
} else {
int childpid = fork();
if(childpid == 0) {
Jun 26, 2011
Jun 26, 2011
515
testItem->testCaseInit(xml_enabled);
Jun 4, 2011
Jun 4, 2011
516
Jun 9, 2011
Jun 9, 2011
517
testItem->testCase(0x0);
Jun 4, 2011
Jun 4, 2011
518
Jun 9, 2011
Jun 9, 2011
519
exit(testItem->testCaseQuit());
Jun 4, 2011
Jun 4, 2011
520
521
522
523
} else {
int stat_lock = -1;
int child = wait(&stat_lock);
Jun 9, 2011
Jun 9, 2011
524
retVal = HandleChildProcessReturnValue(stat_lock);
Jun 4, 2011
Jun 4, 2011
525
526
527
528
529
530
531
}
}
return retVal;
}
Jun 4, 2011
Jun 4, 2011
532
533
534
/*!
* Prints usage information
*/
Jun 6, 2011
Jun 6, 2011
535
536
void
printUsage() {
Jun 9, 2011
Jun 9, 2011
537
538
printf("Usage: ./runner [--in-proc] [--suite SUITE] [--test TEST]\n");
printf(" [--name-contains SUBSTR] [--help]\n");
Jun 4, 2011
Jun 4, 2011
539
printf("Options:\n");
Jun 9, 2011
Jun 9, 2011
540
printf(" --in-proc Executes tests in-process\n");
Jun 13, 2011
Jun 13, 2011
541
printf(" --show-tests Prints out all the executable tests\n");
Jun 26, 2011
Jun 26, 2011
542
printf(" --xml Enables XML logger\n");
Jun 30, 2011
Jun 30, 2011
543
printf(" --xsl FILENAME Use the given file as XSL style sheet for XML\n"); // \todo add to wiki
Jun 9, 2011
Jun 9, 2011
544
545
546
547
printf(" -t --test TEST Executes only tests with given name\n");
printf(" -ts --name-contains SUBSTR Executes only tests that have given\n");
printf(" substring in test name\n");
printf(" -s --suite SUITE Executes only the given test suite\n");
Jun 5, 2011
Jun 5, 2011
548
Jun 9, 2011
Jun 9, 2011
549
printf(" -h --help Print this help\n");
Jun 4, 2011
Jun 4, 2011
550
551
}
Jun 5, 2011
Jun 5, 2011
552
May 30, 2011
May 30, 2011
553
554
/*!
* Parse command line arguments
Jun 1, 2011
Jun 1, 2011
555
556
557
*
* \param argc Count of command line arguments
* \param argv Array of commond lines arguments
May 30, 2011
May 30, 2011
558
559
560
561
562
563
564
565
*/
void
ParseOptions(int argc, char *argv[])
{
int i;
for (i = 1; i < argc; ++i) {
const char *arg = argv[i];
Jun 1, 2011
Jun 1, 2011
566
if(SDL_strcmp(arg, "--in-proc") == 0) {
May 30, 2011
May 30, 2011
567
568
execute_inproc = 1;
}
Jun 13, 2011
Jun 13, 2011
569
570
else if(SDL_strcmp(arg, "--show-tests") == 0) {
only_print_tests = 1;
Jun 5, 2011
Jun 5, 2011
571
}
Jun 26, 2011
Jun 26, 2011
572
573
574
else if(SDL_strcmp(arg, "--xml") == 0) {
xml_enabled = 1;
}
Jun 5, 2011
Jun 5, 2011
575
576
else if(SDL_strcmp(arg, "--test") == 0 || SDL_strcmp(arg, "-t") == 0) {
only_selected_test = 1;
Jun 5, 2011
Jun 5, 2011
577
578
579
580
581
582
583
584
585
char *testName = NULL;
if( (i + 1) < argc) {
testName = argv[++i];
} else {
printf("runner: test name is missing\n");
printUsage();
exit(1);
}
Jun 5, 2011
Jun 5, 2011
586
Jun 5, 2011
Jun 5, 2011
587
memset(selected_test_name, 0, NAME_BUFFER_SIZE);
Jun 5, 2011
Jun 5, 2011
588
589
strcpy(selected_test_name, testName);
}
Jun 30, 2011
Jun 30, 2011
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
else if(SDL_strcmp(arg, "--xsl") == 0) {
custom_xsl_enabled = 1;
char *stylesheet = NULL;
if( (i + 1) < argc) {
stylesheet = argv[++i];
} else {
printf("runner: filename of XSL stylesheet is missing\n");
printUsage();
exit(1);
}
memset(xsl_stylesheet_name, 0, NAME_BUFFER_SIZE);
strncpy(xsl_stylesheet_name, stylesheet, NAME_BUFFER_SIZE);
}
Jun 9, 2011
Jun 9, 2011
605
else if(SDL_strcmp(arg, "--name-contains") == 0 || SDL_strcmp(arg, "-ts") == 0) {
Jun 9, 2011
Jun 9, 2011
606
607
608
609
610
611
612
613
614
615
616
617
618
619
only_tests_with_string = 1;
char *substring = NULL;
if( (i + 1) < argc) {
substring = argv[++i];
} else {
printf("runner: substring of test name is missing\n");
printUsage();
exit(1);
}
memset(testcase_name_substring, 0, NAME_BUFFER_SIZE);
strcpy(testcase_name_substring, substring);
}
Jun 5, 2011
Jun 5, 2011
620
621
622
else if(SDL_strcmp(arg, "--suite") == 0 || SDL_strcmp(arg, "-s") == 0) {
only_selected_suite = 1;
Jun 5, 2011
Jun 5, 2011
623
624
625
626
627
628
629
630
631
632
char *suiteName = NULL;
if( (i + 1) < argc) {
suiteName = argv[++i];
} else {
printf("runner: suite name is missing\n");
printUsage();
exit(1);
}
memset(selected_suite_name, 0, NAME_BUFFER_SIZE);
Jun 5, 2011
Jun 5, 2011
633
634
strcpy(selected_suite_name, suiteName);
}
Jun 13, 2011
Jun 13, 2011
635
636
637
638
else if(SDL_strcmp(arg, "--help") == 0 || SDL_strcmp(arg, "-h") == 0) {
printUsage();
exit(0);
}
Jun 5, 2011
Jun 5, 2011
639
else {
Jun 4, 2011
Jun 4, 2011
640
641
printf("runner: unknown command '%s'\n", arg);
printUsage();
Jun 1, 2011
Jun 1, 2011
642
643
exit(0);
}
May 30, 2011
May 30, 2011
644
645
}
}
May 26, 2011
May 26, 2011
646
Jun 5, 2011
Jun 5, 2011
647
May 31, 2011
May 31, 2011
648
649
650
651
652
653
/*!
* Entry point for test runner
*
* \param argc Count of command line arguments
* \param argv Array of commond lines arguments
*/
May 30, 2011
May 30, 2011
654
655
656
657
int
main(int argc, char *argv[])
{
ParseOptions(argc, argv);
May 26, 2011
May 26, 2011
658
May 30, 2011
May 30, 2011
659
// print: Testing against SDL version fuu (rev: bar) if verbose == true
May 26, 2011
May 26, 2011
660
Jun 27, 2011
Jun 27, 2011
661
662
int totalTestfailureCount = 0, totalTestPassCount = 0;
int testFailureCount = 0, testPassCount = 0, testSkipCount = 0;
Jun 6, 2011
Jun 6, 2011
663
664
char *testSuiteName = NULL;
int suiteCounter = 0;
May 26, 2011
May 26, 2011
665
Jun 8, 2011
Jun 8, 2011
666
667
668
669
670
#if defined(linux) || defined( __linux)
char *extension = "so";
#else
char *extension = "dylib";
#endif
Jun 26, 2011
Jun 26, 2011
671
672
if(xml_enabled) {
SetupXMLLogger();
Jun 30, 2011
Jun 30, 2011
673
674
RunStarted(argc, argv, time(0), xsl_stylesheet_name);
Jun 26, 2011
Jun 26, 2011
675
676
} else {
SetupPlainLogger();
Jun 30, 2011
Jun 30, 2011
677
678
RunStarted(argc, argv, time(0), NULL);
Jun 26, 2011
Jun 26, 2011
679
}
Jun 8, 2011
Jun 8, 2011
680
May 26, 2011
May 26, 2011
681
const Uint32 startTicks = SDL_GetTicks();
Jun 9, 2011
Jun 9, 2011
682
Jun 8, 2011
Jun 8, 2011
683
TestSuiteReference *suites = ScanForTestSuites(DEFAULT_TEST_DIRECTORY, extension);
Jun 9, 2011
Jun 9, 2011
684
suites = LoadTestSuites(suites);
Jun 8, 2011
Jun 8, 2011
685
Jun 9, 2011
Jun 9, 2011
686
TestCase *testCases = LoadTestCases(suites);
Jun 5, 2011
Jun 5, 2011
687
Jun 13, 2011
Jun 13, 2011
688
689
690
691
// if --show-tests option is given, only print tests and exit
if(only_print_tests) {
TestCase *testItem = NULL;
for(testItem = testCases; testItem; testItem = testItem->next) {
Jun 26, 2011
Jun 26, 2011
692
//! \todo This should be handled by the logging system?
Jun 13, 2011
Jun 13, 2011
693
694
695
696
697
698
printf("%s (in %s)\n", testItem->testName, testItem->suiteName);
}
return 0;
}
Jun 26, 2011
Jun 26, 2011
699
700
char *currentSuiteName = NULL;
Jun 27, 2011
Jun 27, 2011
701
702
int suiteStartTime = SDL_GetTicks();
Jun 9, 2011
Jun 9, 2011
703
TestCase *testItem = NULL;
Jun 9, 2011
Jun 9, 2011
704
for(testItem = testCases; testItem; testItem = testItem->next) {
Jun 26, 2011
Jun 26, 2011
705
706
if(currentSuiteName == NULL) {
currentSuiteName = testItem->suiteName;
Jun 27, 2011
Jun 27, 2011
707
SuiteStarted(currentSuiteName, time(0));
Jun 27, 2011
Jun 27, 2011
708
709
710
711
712
713
testFailureCount = testPassCount = 0;
suiteCounter++;
}
else if(strncmp(currentSuiteName, testItem->suiteName, NAME_BUFFER_SIZE) != 0) {
Jun 27, 2011
Jun 27, 2011
714
715
716
717
const double suiteRuntime = (SDL_GetTicks() - suiteStartTime) / 1000.0f;
SuiteEnded(testPassCount, testFailureCount, testSkipCount, time(0),
suiteRuntime);
Jun 27, 2011
Jun 27, 2011
718
Jun 29, 2011
Jun 29, 2011
719
720
suiteStartTime = SDL_GetTicks();
Jun 27, 2011
Jun 27, 2011
721
currentSuiteName = testItem->suiteName;
Jun 27, 2011
Jun 27, 2011
722
SuiteStarted(currentSuiteName, time(0));
Jun 27, 2011
Jun 27, 2011
723
724
725
726
testFailureCount = testPassCount = 0;
suiteCounter++;
Jun 26, 2011
Jun 26, 2011
727
728
729
}
TestStarted(testItem->testName, testItem->suiteName,
Jun 27, 2011
Jun 27, 2011
730
731
732
testItem->description, time(0));
const Uint32 testTimeStart = SDL_GetTicks();
Jun 26, 2011
Jun 26, 2011
733
Jun 9, 2011
Jun 9, 2011
734
735
int retVal = ExecuteTest(testItem);
if(retVal) {
Jun 27, 2011
Jun 27, 2011
736
737
totalTestfailureCount++;
testFailureCount++;
Jun 9, 2011
Jun 9, 2011
738
} else {
Jun 27, 2011
Jun 27, 2011
739
740
totalTestPassCount++;
testPassCount++;
Jun 8, 2011
Jun 8, 2011
742
Jun 27, 2011
Jun 27, 2011
743
744
745
const double testTotalRuntime = (SDL_GetTicks() - testTimeStart) / 1000.0f;
TestEnded(testItem->testName, testItem->suiteName, retVal, time(0), testTotalRuntime);
May 23, 2011
May 23, 2011
747
Jun 27, 2011
Jun 27, 2011
748
if(currentSuiteName) {
Jun 27, 2011
Jun 27, 2011
749
750
SuiteEnded(testPassCount, testFailureCount, testSkipCount, time(0),
(SDL_GetTicks() - suiteStartTime) / 1000.0f);
Jun 27, 2011
Jun 27, 2011
751
}
Jun 27, 2011
Jun 27, 2011
752
Jun 9, 2011
Jun 9, 2011
753
754
755
UnloadTestCases(testCases);
UnloadTestSuites(suites);
May 23, 2011
May 23, 2011
756
const Uint32 endTicks = SDL_GetTicks();
Jun 27, 2011
Jun 27, 2011
757
const double totalRunTime = (endTicks - startTicks) / 1000.0f;
May 23, 2011
May 23, 2011
758
Jun 27, 2011
Jun 27, 2011
759
RunEnded(totalTestPassCount + totalTestfailureCount, suiteCounter,
Jun 27, 2011
Jun 27, 2011
760
totalTestPassCount, totalTestfailureCount, time(0), totalRunTime);
May 23, 2011
May 23, 2011
761
Jun 30, 2011
Jun 30, 2011
762
return (totalTestfailureCount ? 1 : 0);