This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
runner.c
837 lines (673 loc) · 22 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.
*/
21
#include "SDL/SDL.h"
22
23
24
25
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
26
#include <string.h>
27
#include <dirent.h>
28
29
30
#include <sys/types.h>
31
32
#include "config.h"
33
#include "SDL_test.h"
34
35
36
#include "plain_logger.h"
#include "xml_logger.h"
37
#include "logger.h"
38
39
//!< Function pointer to a test case function
40
typedef void (*TestCaseFp)(void *arg);
41
//!< Function pointer to a test case init function
42
typedef void (*TestCaseInitFp)(void);
43
//!< Function pointer to a test case quit function
44
45
typedef int (*TestCaseQuitFp)(void);
46
47
48
//!< Flag for executing tests in-process
static int execute_inproc = 0;
49
50
//!< Flag for only printing out the test names
static int only_print_tests = 0;
51
52
53
54
//!< 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;
55
56
//!< Flag for executing only tests that contain certain string in their name
static int only_tests_with_string = 0;
57
58
//!< Flag for enabling XML logging
static int xml_enabled = 0;
59
60
//! Flag for enabling user-supplied style sheet for XML test report
static int custom_xsl_enabled = 0;
61
62
//! Flag for disabling xsl-style from xml report
static int xsl_enabled = 0;
63
64
65
//!< Size of the test and suite name buffers
66
#define NAME_BUFFER_SIZE 1024
67
68
69
70
//!< Name of the selected test
char selected_test_name[NAME_BUFFER_SIZE];
//!< Name of the selected suite
char selected_suite_name[NAME_BUFFER_SIZE];
71
72
73
74
//!< substring of test case name
char testcase_name_substring[NAME_BUFFER_SIZE];
75
76
77
//! Name for user-supplied XSL style sheet name
char xsl_stylesheet_name[NAME_BUFFER_SIZE];
78
79
80
//! Default directory of the test suites
#define DEFAULT_TEST_DIRECTORY "tests/"
81
82
/*!
83
84
* Holds information about test suite such as it's name
* and pointer to dynamic library. Implemented as linked list.
85
86
*/
typedef struct TestSuiteReference {
87
char *name; //!< test suite name
88
char *directoryPath; //!< test suites path (eg. tests/libtestsuite)
89
void *library; //!< pointer to shared/dynamic library implementing the suite
90
91
92
93
struct TestSuiteReference *next; //!< Pointer to next item in the list
} TestSuiteReference;
94
95
96
97
98
99
/*!
* Holds information about the tests that will be executed.
*
* Implemented as linked list.
*/
100
101
102
103
typedef struct TestCaseItem {
char *testName;
char *suiteName;
104
105
106
107
char *description;
long requirements;
long timeout;
108
109
110
TestCaseInitFp testCaseInit;
TestCaseFp testCase;
TestCaseQuitFp testCaseQuit;
111
112
struct TestCaseItem *next;
113
114
115
116
117
118
119
120
121
122
} 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);
123
124
125
126
127
128
129
130
131
132
133
134
/*! Pointers to selected logger implementation */
RunStartedFp RunStarted = NULL;
RunEndedFp RunEnded = NULL;
SuiteStartedFp SuiteStarted = NULL;
SuiteEndedFp SuiteEnded = NULL;
TestStartedFp TestStarted = NULL;
TestEndedFp TestEnded = NULL;
AssertFp Assert = NULL;
AssertWithValuesFp AssertWithValues = NULL;
AssertSummaryFp AssertSummary = NULL;
LogFp Log = NULL;
135
136
137
138
139
140
141
/*!
* 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.
*
142
* \param suites previously loaded test suites
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
*
* \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;
175
// copy suite name
176
int length = SDL_strlen(suiteReference->name) + 1;
177
item->suiteName = SDL_malloc(length);
178
strncpy(item->suiteName, suiteReference->name, length);
179
180
// copy test name
181
length = SDL_strlen(testReference->name) + 1;
182
item->testName = SDL_malloc(length);
183
strncpy(item->testName, testReference->name, length);
184
185
// copy test description
186
length = SDL_strlen(testReference->description) + 1;
187
item->description = SDL_malloc(length);
188
strncpy(item->description, testReference->description, length);
189
190
191
192
item->requirements = testReference->requirements;
item->timeout = testReference->timeout;
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// 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);
219
SDL_free(ref->description);
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
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;
}
245
246
247
248
249
250
251
252
if(only_selected_test) {
if(SDL_strncmp(testReference->name, selected_test_name, NAME_BUFFER_SIZE) == 0) {
retVal = 1;
} else {
retVal = 0;
}
}
253
254
255
256
257
258
259
260
261
262
263
264
if(only_tests_with_string) {
if(strstr(testReference->name, testcase_name_substring) != NULL) {
retVal = 1;
} else {
retVal = 0;
}
}
return retVal;
}
265
266
267
268
269
270
271
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*!
* Scans the tests/ directory and returns the names
* of the dynamic libraries implementing the test suites.
*
* Note: currently function assumes that test suites names
* are in following format: libtestsuite.dylib or libtestsuite.so.
*
* 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
* \param extension What file extension is used with dynamic objects
*
* \return Pointer to TestSuiteReference which holds all the info about suites
*/
TestSuiteReference *
ScanForTestSuites(char *directoryName, char *extension)
{
typedef struct dirent Entry;
DIR *directory = opendir(directoryName);
TestSuiteReference *suites = NULL;
Entry *entry = NULL;
if(!directory) {
perror("Couldn't open test suite directory!");
}
while(entry = readdir(directory)) {
if(strlen(entry->d_name) > 2) { // discards . and ..
const char *delimiters = ".";
char *name = strtok(entry->d_name, delimiters);
char *ext = strtok(NULL, delimiters);
// 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;
}
if(ok && SDL_strcmp(ext, extension) == 0) {
// create test suite reference
TestSuiteReference *reference = (TestSuiteReference *) SDL_malloc(sizeof(TestSuiteReference));
memset(reference, 0, sizeof(TestSuiteReference));
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
const int dirSize = SDL_strlen(directoryName);
const int extSize = SDL_strlen(ext);
const int nameSize = SDL_strlen(name) + 1;
// copy the name
reference->name = SDL_malloc(nameSize * sizeof(char));
if(reference->name == NULL) {
SDL_free(reference);
return NULL;
}
SDL_snprintf(reference->name, nameSize, "%s", name);
// copy the directory path
const int dpSize = dirSize + nameSize + 1 + extSize + 1;
reference->directoryPath = SDL_malloc(dpSize * sizeof(char));
if(reference->directoryPath == NULL) {
SDL_free(reference->name);
SDL_free(reference);
return NULL;
}
SDL_snprintf(reference->directoryPath, dpSize, "%s%s.%s",
directoryName, name, ext);
334
335
336
337
338
339
340
341
342
343
344
345
346
reference->next = suites;
suites = reference;
}
}
}
closedir(directory);
return suites;
}
347
348
349
/*!
* Loads test suite which is implemented as dynamic library.
*
350
* \param suite Reference to test suite that'll be loaded
351
352
353
354
*
* \return Pointer to loaded test suite, or NULL if library could not be loaded
*/
void *
355
LoadTestSuite(const TestSuiteReference *suite)
356
{
357
void *library = SDL_LoadObject(suite->directoryPath);
358
if(library == NULL) {
359
fprintf(stderr, "Loading %s failed\n", suite->name);
360
fprintf(stderr, "%s\n", SDL_GetError());
361
362
}
363
364
365
return library;
}
366
367
368
369
370
371
372
373
374
375
376
/*!
* 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 *
377
LoadTestSuites(TestSuiteReference *suites)
378
379
380
{
TestSuiteReference *reference = NULL;
for(reference = suites; reference; reference = reference->next) {
381
reference->library = LoadTestSuite(reference);
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
}
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);
400
SDL_free(ref->directoryPath);
401
402
403
404
405
406
407
408
409
410
411
SDL_UnloadObject(ref->library);
TestSuiteReference *temp = ref->next;
SDL_free(ref);
ref = temp;
}
suites = NULL;
}
412
413
414
415
/*!
* Loads the test case references from the given test suite.
* \param library Previously loaded dynamic library AKA test suite
416
* \return Pointer to array of TestCaseReferences or NULL if function failed
417
*/
418
TestCaseReference **
419
QueryTestCaseReferences(void *library)
420
{
421
TestCaseReference **(*suite)(void);
422
423
424
425
426
427
suite = (TestCaseReference **(*)(void)) SDL_LoadFunction(library, "QueryTestSuite");
if(suite == NULL) {
fprintf(stderr, "Loading QueryTestCaseReferences() failed.\n");
fprintf(stderr, "%s\n", SDL_GetError());
}
428
429
430
431
432
433
TestCaseReference **tests = suite();
if(tests == NULL) {
fprintf(stderr, "Failed to load test references.\n");
fprintf(stderr, "%s\n", SDL_GetError());
}
434
435
return tests;
436
437
}
438
439
440
441
/*!
* Loads test case from a test suite
*
442
443
* \param suite a test suite
* \param testName Name of the test that is going to be loaded
444
*
445
* \return Function Pointer (TestCase) to loaded test case, NULL if function failed
446
*/
447
448
TestCaseFp
LoadTestCaseFunction(void *suite, char *testName)
449
{
450
TestCaseFp test = (TestCaseFp) SDL_LoadFunction(suite, testName);
451
if(test == NULL) {
452
453
fprintf(stderr, "Loading test failed, tests == NULL\n");
fprintf(stderr, "%s\n", SDL_GetError());
454
455
456
457
458
}
return test;
}
459
460
461
462
463
464
465
466
467
/*!
* 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.
*/
468
469
470
TestCaseInitFp
LoadTestCaseInitFunction(void *suite) {
TestCaseInitFp testCaseInit = (TestCaseInitFp) SDL_LoadFunction(suite, "_TestCaseInit");
471
472
473
474
475
476
477
478
if(testCaseInit == NULL) {
fprintf(stderr, "Loading TestCaseInit function failed, testCaseInit == NULL\n");
fprintf(stderr, "%s\n", SDL_GetError());
}
return testCaseInit;
}
479
480
481
482
483
484
485
486
487
/*!
* 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.
*/
488
489
490
TestCaseQuitFp
LoadTestCaseQuitFunction(void *suite) {
TestCaseQuitFp testCaseQuit = (TestCaseQuitFp) SDL_LoadFunction(suite, "_TestCaseQuit");
491
492
493
494
495
496
497
if(testCaseQuit == NULL) {
fprintf(stderr, "Loading TestCaseQuit function failed, testCaseQuit == NULL\n");
fprintf(stderr, "%s\n", SDL_GetError());
}
return testCaseQuit;
}
498
499
500
/*!
501
502
503
504
* 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.
505
*
506
* \param stat_lock information about the exited child process
507
*
508
* \return 0 if test case succeeded, 1 otherwise
509
*/
510
int
511
HandleChildProcessReturnValue(int stat_lock)
512
{
513
int returnValue = -1;
514
515
516
if(WIFEXITED(stat_lock)) {
returnValue = WEXITSTATUS(stat_lock);
517
518
} else if(WIFSIGNALED(stat_lock)) {
int signal = WTERMSIG(stat_lock);
519
520
// \todo add this to logger (add signal number)
Log("FAILURE: test was aborted due to signal\n", time(0));
521
returnValue = 1;
522
523
}
524
return returnValue;
525
526
}
527
528
529
530
531
/*!
* Executes a test case. Loads the test, executes it and
* returns the tests return value to the caller.
*
532
* \param testItem The test case that will be executed
533
534
535
* \return The return value of the test. Zero means success, non-zero failure.
*/
int
536
ExecuteTest(TestCase *testItem) {
537
538
int retVal = 1;
if(execute_inproc) {
539
testItem->testCaseInit();
540
541
testItem->testCase(0x0);
542
543
retVal = testItem->testCaseQuit();
544
545
546
} else {
int childpid = fork();
if(childpid == 0) {
547
testItem->testCaseInit();
548
549
testItem->testCase(0x0);
550
551
exit(testItem->testCaseQuit());
552
553
554
555
} else {
int stat_lock = -1;
int child = wait(&stat_lock);
556
retVal = HandleChildProcessReturnValue(stat_lock);
557
558
559
560
561
562
563
}
}
return retVal;
}
564
565
566
/*!
* Prints usage information
*/
567
void
568
PrintUsage() {
569
printf("Usage: ./runner [--in-proc] [--suite SUITE] [--test TEST]\n");
570
printf(" [--name-contains SUBSTR] [--show-tests]\n");
571
printf(" [--xml] [--xsl [STYLESHEET]] [--help]\n");
572
printf("Options:\n");
573
printf(" --in-proc Executes tests in-process\n");
574
printf(" --show-tests Prints out all the executable tests\n");
575
printf(" --xml Enables XML logger\n");
576
577
578
printf(" --xsl [STYLESHEET] Adds XSL stylesheet to the XML test reports for\n");
printf(" browser viewing. Optionally uses the specified XSL\n");
printf(" file or URL instead of the default one\n");
579
580
581
582
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");
583
584
printf(" -h --help Print this help\n");
585
586
}
587
588
589
/*!
* Parse command line arguments
590
591
592
*
* \param argc Count of command line arguments
* \param argv Array of commond lines arguments
593
594
595
596
597
598
599
600
*/
void
ParseOptions(int argc, char *argv[])
{
int i;
for (i = 1; i < argc; ++i) {
const char *arg = argv[i];
601
if(SDL_strcmp(arg, "--in-proc") == 0) {
602
603
execute_inproc = 1;
}
604
605
else if(SDL_strcmp(arg, "--show-tests") == 0) {
only_print_tests = 1;
606
}
607
608
609
else if(SDL_strcmp(arg, "--xml") == 0) {
xml_enabled = 1;
}
610
611
else if(SDL_strcmp(arg, "--test") == 0 || SDL_strcmp(arg, "-t") == 0) {
only_selected_test = 1;
612
613
614
615
616
617
char *testName = NULL;
if( (i + 1) < argc) {
testName = argv[++i];
} else {
printf("runner: test name is missing\n");
618
PrintUsage();
619
620
exit(1);
}
621
622
memset(selected_test_name, 0, NAME_BUFFER_SIZE);
623
624
strcpy(selected_test_name, testName);
}
625
else if(SDL_strcmp(arg, "--xsl") == 0) {
626
xsl_enabled = 1;
627
628
if( (i + 1) < argc) {
629
630
631
char *stylesheet = argv[++i];
if(stylesheet[0] != '-') {
custom_xsl_enabled = 1;
632
633
634
635
636
memset(xsl_stylesheet_name, 0, NAME_BUFFER_SIZE);
strncpy(xsl_stylesheet_name, stylesheet, NAME_BUFFER_SIZE);
}
}
637
}
638
else if(SDL_strcmp(arg, "--name-contains") == 0 || SDL_strcmp(arg, "-ts") == 0) {
639
640
641
642
643
644
645
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");
646
PrintUsage();
647
648
649
650
651
652
exit(1);
}
memset(testcase_name_substring, 0, NAME_BUFFER_SIZE);
strcpy(testcase_name_substring, substring);
}
653
654
655
else if(SDL_strcmp(arg, "--suite") == 0 || SDL_strcmp(arg, "-s") == 0) {
only_selected_suite = 1;
656
657
658
659
660
char *suiteName = NULL;
if( (i + 1) < argc) {
suiteName = argv[++i];
} else {
printf("runner: suite name is missing\n");
661
PrintUsage();
662
663
664
665
exit(1);
}
memset(selected_suite_name, 0, NAME_BUFFER_SIZE);
666
667
strcpy(selected_suite_name, suiteName);
}
668
669
670
671
else if(SDL_strcmp(arg, "--version") == 0) {
fprintf(stdout, "SDL test harness (version %s)\n", PACKAGE_VERSION);
exit(0);
}
672
else if(SDL_strcmp(arg, "--help") == 0 || SDL_strcmp(arg, "-h") == 0) {
673
PrintUsage();
674
675
exit(0);
}
676
else {
677
printf("runner: unknown command '%s'\n", arg);
678
PrintUsage();
679
680
exit(0);
}
681
682
}
}
683
684
685
686
687
688
689
690
/*!
* Entry point for test runner
*
* \param argc Count of command line arguments
* \param argv Array of commond lines arguments
*/
691
692
693
694
int
main(int argc, char *argv[])
{
ParseOptions(argc, argv);
695
696
// print: Testing against SDL version fuu (rev: bar) if verbose == true
697
698
699
int totalTestfailureCount = 0, totalTestPassCount = 0;
int testFailureCount = 0, testPassCount = 0, testSkipCount = 0;
700
701
char *testSuiteName = NULL;
int suiteCounter = 0;
702
703
704
705
706
707
#if defined(linux) || defined( __linux)
char *extension = "so";
#else
char *extension = "dylib";
#endif
708
709
void *loggerData = NULL;
710
if(xml_enabled) {
711
712
713
714
715
716
717
718
719
720
721
722
723
724
RunStarted = XMLRunStarted;
RunEnded = XMLRunEnded;
SuiteStarted = XMLSuiteStarted;
SuiteEnded = XMLSuiteEnded;
TestStarted = XMLTestStarted;
TestEnded = XMLTestEnded;
Assert = XMLAssert;
AssertWithValues = XMLAssertWithValues;
AssertSummary = XMLAssertSummary;
Log = XMLLog;
725
726
727
728
729
730
731
732
733
734
char *sheet = NULL;
if(xsl_enabled) {
sheet = "style.xsl"; // default style sheet;
}
if(custom_xsl_enabled) {
sheet = xsl_stylesheet_name;
}
735
loggerData = sheet;
736
} else {
737
738
739
740
741
742
743
744
745
746
747
748
749
750
RunStarted = PlainRunStarted;
RunEnded = PlainRunEnded;
SuiteStarted = PlainSuiteStarted;
SuiteEnded = PlainSuiteEnded;
TestStarted = PlainTestStarted;
TestEnded = PlainTestEnded;
Assert = PlainAssert;
AssertWithValues = PlainAssertWithValues;
AssertSummary = PlainAssertSummary;
Log = PlainLog;
751
}
752
753
const Uint32 startTicks = SDL_GetTicks();
754
755
TestSuiteReference *suites = ScanForTestSuites(DEFAULT_TEST_DIRECTORY, extension);
756
suites = LoadTestSuites(suites);
757
758
TestCase *testCases = LoadTestCases(suites);
759
760
761
762
763
764
765
766
767
768
769
// 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) {
printf("%s (in %s)\n", testItem->testName, testItem->suiteName);
}
return 0;
}
770
771
772
RunStarted(argc, argv, time(0), loggerData);
773
774
char *currentSuiteName = NULL;
775
776
int suiteStartTime = SDL_GetTicks();
777
TestCase *testItem = NULL;
778
for(testItem = testCases; testItem; testItem = testItem->next) {
779
780
if(currentSuiteName == NULL) {
currentSuiteName = testItem->suiteName;
781
SuiteStarted(currentSuiteName, time(0));
782
783
784
785
786
787
testFailureCount = testPassCount = 0;
suiteCounter++;
}
else if(strncmp(currentSuiteName, testItem->suiteName, NAME_BUFFER_SIZE) != 0) {
788
789
790
791
const double suiteRuntime = (SDL_GetTicks() - suiteStartTime) / 1000.0f;
SuiteEnded(testPassCount, testFailureCount, testSkipCount, time(0),
suiteRuntime);
792
793
794
suiteStartTime = SDL_GetTicks();
795
currentSuiteName = testItem->suiteName;
796
SuiteStarted(currentSuiteName, time(0));
797
798
799
800
testFailureCount = testPassCount = 0;
suiteCounter++;
801
802
803
}
TestStarted(testItem->testName, testItem->suiteName,
804
805
806
testItem->description, time(0));
const Uint32 testTimeStart = SDL_GetTicks();
807
808
809
int retVal = ExecuteTest(testItem);
if(retVal) {
810
811
totalTestfailureCount++;
testFailureCount++;
812
} else {
813
814
totalTestPassCount++;
testPassCount++;
815
}
816
817
818
819
const double testTotalRuntime = (SDL_GetTicks() - testTimeStart) / 1000.0f;
TestEnded(testItem->testName, testItem->suiteName, retVal, time(0), testTotalRuntime);
820
}
821
822
if(currentSuiteName) {
823
824
SuiteEnded(testPassCount, testFailureCount, testSkipCount, time(0),
(SDL_GetTicks() - suiteStartTime) / 1000.0f);
825
}
826
827
828
829
UnloadTestCases(testCases);
UnloadTestSuites(suites);
830
const Uint32 endTicks = SDL_GetTicks();
831
const double totalRunTime = (endTicks - startTicks) / 1000.0f;
832
833
RunEnded(totalTestPassCount + totalTestfailureCount, suiteCounter,
834
totalTestPassCount, totalTestfailureCount, time(0), totalRunTime);
835
836
return (totalTestfailureCount ? 1 : 0);
837
}