test/test-automation/runner.c
author Markus Kauppila <markus.kauppila@gmail.com>
Sun, 05 Jun 2011 18:44:58 +0300
changeset 5685 731a7c70eded
parent 5684 d67b7490be36
child 5686 a7d699502230
permissions -rw-r--r--
Fix: Use DEFINE instead of plain number.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     1
/*
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     2
  Copyright (C) 2011 Markus Kauppila <markus.kauppila@gmail.com>
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     3
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     4
  This software is provided 'as-is', without any express or implied
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     5
  warranty.  In no event will the authors be held liable for any damages
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     6
  arising from the use of this software.
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     7
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     8
  Permission is granted to anyone to use this software for any purpose,
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     9
  including commercial applications, and to alter it and redistribute it
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    10
  freely, subject to the following restrictions:
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    11
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    12
  1. The origin of this software must not be misrepresented; you must not
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    13
     claim that you wrote the original software. If you use this software
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    14
     in a product, an acknowledgment in the product documentation would be
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    15
     appreciated but is not required.
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    16
  2. Altered source versions must be plainly marked as such, and must not be
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    17
     misrepresented as being the original software.
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    18
  3. This notice may not be removed or altered from any source distribution.
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    19
*/
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    20
5662
57fc58008d76 Tiny changes to runner
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5659
diff changeset
    21
#include "SDL/SDL.h"
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    22
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    23
#include <stdio.h>
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    24
#include <stdlib.h>
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    25
#include <unistd.h>
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    26
#include <string.h>
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    27
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    28
#include <sys/types.h>
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    29
5674
1ee88babe722 Moved tests/SDL_test.{c,h}
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5673
diff changeset
    30
#include "SDL_test.h"
5662
57fc58008d76 Tiny changes to runner
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5659
diff changeset
    31
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
    32
//!< Function pointer to a test case function
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
    33
typedef void (*TestCase)(void *arg);
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
    34
//!< Function pointer to a test case init function
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
    35
typedef void (*TestCaseInit)(void);
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
    36
//!< Function pointer to a test case quit function
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
    37
typedef int  (*TestCaseQuit)(void);
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
    38
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    39
//!< Flag for executing tests in-process
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    40
static int execute_inproc = 0;
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    41
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    42
//!< Flag for executing only test with selected name
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    43
static int only_selected_test  = 0;
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    44
//!< Flag for executing only the selected test suite
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    45
static int only_selected_suite = 0;
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    46
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    47
//<! Size of the test and suite name buffers
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    48
#define NAME_BUFFER_SIZE 256
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    49
//!< Name of the selected test
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    50
char selected_test_name[NAME_BUFFER_SIZE];
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    51
//!< Name of the selected suite
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    52
char selected_suite_name[NAME_BUFFER_SIZE];
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
    53
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
    54
//!< Temporary array to hold test suite names
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
    55
#if defined(linux) || defined( __linux)
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
    56
	char *testSuites[] = { "tests/libtest.so", "tests/libtestrect.so", NULL};
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
    57
#else
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
    58
	char *testSuites[] = { "tests/libtest.dylib", "tests/libtestrect.dylib", NULL};
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
    59
#endif
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
    60
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
    61
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
    62
/*!
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    63
 * Returns the name for the dynamic library
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    64
 * which implements the test suite.
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
    65
 *
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    66
 * (in the future: scans the test/ directory and
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    67
 * returns the names of the dynamic libraries
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    68
 * implementing the test suites)
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    69
 *
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
    70
 * \return Array of test suite names
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
    71
 */
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
    72
char **
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    73
ScanForTestSuites() {
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
    74
	return testSuites;
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    75
}
5666
8feff411cc08 Some fixes for Linux compatibility.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5664
diff changeset
    76
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    77
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    78
/*!
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    79
 * Loads test suite which is implemented as dynamic library.
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    80
 *
5680
e61bdd43a2c3 Fixed old comments and added new ones.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5679
diff changeset
    81
 * \param testSuiteName Name of the test suite which will be loaded
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    82
 *
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    83
 * \return Pointer to loaded test suite, or NULL if library could not be loaded
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    84
 */
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    85
void *
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    86
LoadTestSuite(char *testSuiteName)
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    87
{
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    88
	void *library = SDL_LoadObject(testSuiteName);
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    89
	if(library == NULL) {
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    90
		fprintf(stderr, "Loading %s failed\n", testSuiteName);
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
    91
		fprintf(stderr, "%s\n", SDL_GetError());
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    92
	}
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    93
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
    94
	return library;
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
    95
}
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
    96
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    97
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
    98
/*!
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
    99
 * Loads the test case references from the given test suite.
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   100
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   101
 * \param library Previously loaded dynamic library AKA test suite
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   102
 * \return Pointer to array of TestCaseReferences or NULL if function failed
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   103
 */
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   104
TestCaseReference **
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   105
QueryTestCases(void *library)
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   106
{
5668
3a9b790c00e9 Added TestCaseReference structure.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5667
diff changeset
   107
	TestCaseReference **(*suite)(void);
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   108
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   109
	suite = (TestCaseReference **(*)(void)) SDL_LoadFunction(library, "QueryTestSuite");
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   110
	if(suite == NULL) {
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   111
		fprintf(stderr, "Loading QueryTestCaseReferences() failed.\n");
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   112
		fprintf(stderr, "%s\n", SDL_GetError());
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   113
	}
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   114
5668
3a9b790c00e9 Added TestCaseReference structure.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5667
diff changeset
   115
	TestCaseReference **tests = suite();
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   116
	if(tests == NULL) {
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   117
		fprintf(stderr, "Failed to load test references.\n");
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   118
		fprintf(stderr, "%s\n", SDL_GetError());
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   119
	}
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   120
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   121
	return tests;
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   122
}
5662
57fc58008d76 Tiny changes to runner
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5659
diff changeset
   123
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   124
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   125
/*!
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   126
 * Loads test case from a test suite
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   127
 *
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   128
 * \param suite a test suite
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   129
 * \param testName Name of the test that is going to be loaded
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   130
 *
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   131
 * \return Function Pointer (TestCase) to loaded test case, NULL if function failed
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   132
 */
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   133
TestCase
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   134
LoadTestCase(void *suite, char *testName)
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   135
{
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   136
	TestCase test = (TestCase) SDL_LoadFunction(suite, testName);
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   137
	if(test == NULL) {
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   138
		fprintf(stderr, "Loading test failed, tests == NULL\n");
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   139
		fprintf(stderr, "%s\n", SDL_GetError());
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   140
	}
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   141
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   142
	return test;
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   143
}
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   144
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   145
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   146
/*!
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   147
 * Loads function that initialises the test case from the
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   148
 * given test suite.
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   149
 *
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   150
 * \param suite Used test suite
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   151
 *
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   152
 * \return Function pointer (TestCaseInit) which points to loaded init function. NULL if function fails.
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   153
 */
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   154
TestCaseInit
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   155
LoadTestCaseInit(void *suite) {
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   156
	TestCaseInit testCaseInit = (TestCaseInit) SDL_LoadFunction(suite, "_TestCaseInit");
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   157
	if(testCaseInit == NULL) {
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   158
		fprintf(stderr, "Loading TestCaseInit function failed, testCaseInit == NULL\n");
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   159
		fprintf(stderr, "%s\n", SDL_GetError());
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   160
	}
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   161
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   162
	return testCaseInit;
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   163
}
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   164
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   165
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   166
/*!
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   167
 * Loads function that deinitialises the executed test case from the
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   168
 * given test suite.
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   169
 *
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   170
 * \param suite Used test suite
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   171
 *
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   172
 * \return Function pointer (TestCaseInit) which points to loaded init function. NULL if function fails.
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   173
 */
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   174
TestCaseQuit
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   175
LoadTestCaseQuit(void *suite) {
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   176
	TestCaseQuit testCaseQuit = (TestCaseQuit) SDL_LoadFunction(suite, "_TestCaseQuit");
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   177
	if(testCaseQuit == NULL) {
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   178
		fprintf(stderr, "Loading TestCaseQuit function failed, testCaseQuit == NULL\n");
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   179
		fprintf(stderr, "%s\n", SDL_GetError());
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   180
	}
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   181
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   182
	return testCaseQuit;
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   183
}
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   184
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   185
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   186
/*!
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   187
 * If using out-of-proc execution of tests. This function
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   188
 * will handle the return value of the child process
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   189
 * and interprets it to the runner. Also prints warnings
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   190
 * if child was aborted by a signela.
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   191
 *
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   192
 * \param stat_lock information about the exited child process
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   193
 *
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   194
 * \return 0 if test case succeeded, 1 otherwise
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   195
 */
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   196
int
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   197
HandleTestReturnValue(int stat_lock)
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   198
{
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   199
	//! \todo rename to: HandleChildProcessReturnValue?
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   200
	int returnValue = -1;
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   201
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   202
	if(WIFEXITED(stat_lock)) {
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   203
		returnValue = WEXITSTATUS(stat_lock);
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   204
	} else if(WIFSIGNALED(stat_lock)) {
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   205
		int signal = WTERMSIG(stat_lock);
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   206
		fprintf(stderr, "FAILURE: test was aborted due to signal no %d\n", signal);
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   207
		returnValue = 1;
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   208
	}
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   209
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   210
	return returnValue;
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   211
}
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   212
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   213
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   214
/*!
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   215
 * Executes a test case. Loads the test, executes it and
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   216
 * returns the tests return value to the caller.
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   217
 *
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   218
 * \param suite The suite from which the test will be loaded
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   219
 * \param testReference TestCaseReference of the test under execution
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   220
 * \return The return value of the test. Zero means success, non-zero failure.
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   221
 */
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   222
int
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   223
ExecuteTest(void *suite, TestCaseReference *testReference) {
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   224
	TestCaseInit testCaseInit = LoadTestCaseInit(suite);
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   225
	TestCaseQuit testCaseQuit = LoadTestCaseQuit(suite);
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   226
	TestCase test = (TestCase) LoadTestCase(suite, testReference->name);
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   227
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   228
	int retVal = 1;
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   229
	if(execute_inproc) {
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   230
		testCaseInit();
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   231
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   232
		test(0x0);
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   233
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   234
		retVal = testCaseQuit();
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   235
	} else {
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   236
		int childpid = fork();
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   237
		if(childpid == 0) {
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   238
			testCaseInit();
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   239
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   240
			test(0x0);
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   241
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   242
			exit(testCaseQuit());
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   243
		} else {
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   244
			int stat_lock = -1;
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   245
			int child = wait(&stat_lock);
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   246
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   247
			retVal = HandleTestReturnValue(stat_lock);
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   248
		}
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   249
	}
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   250
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   251
	return retVal;
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   252
}
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   253
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   254
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   255
/*!
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   256
 * Prints usage information
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   257
 */
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   258
void printUsage() {
5683
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   259
	  printf("Usage: ./runner [--in-proc] [--suite SUITE] [--test TEST] [--help]\n");
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   260
	  printf("Options:\n");
5683
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   261
	  printf("    --in-proc        Executes tests in-process\n");
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   262
	  printf(" -t --test TEST      Executes only tests with given name\n");
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   263
	  printf(" -s --suite SUITE    Executes only the given test suite\n");
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   264
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   265
	  printf(" -h --help           Print this help\n");
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   266
}
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   267
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   268
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   269
/*!
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   270
 * Parse command line arguments
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   271
 *
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   272
 * \param argc Count of command line arguments
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   273
 * \param argv Array of commond lines arguments
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   274
 */
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   275
void
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   276
ParseOptions(int argc, char *argv[])
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   277
{
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   278
   int i;
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   279
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   280
   for (i = 1; i < argc; ++i) {
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   281
      const char *arg = argv[i];
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   282
      if(SDL_strcmp(arg, "--in-proc") == 0) {
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   283
         execute_inproc = 1;
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   284
      }
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   285
      else if(SDL_strcmp(arg, "--help") == 0 || SDL_strcmp(arg, "-h") == 0) {
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   286
    	  printUsage();
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   287
    	  exit(0);
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   288
      }
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   289
      else if(SDL_strcmp(arg, "--test") == 0 || SDL_strcmp(arg, "-t") == 0) {
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   290
    	  only_selected_test = 1;
5683
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   291
    	  char *testName = NULL;
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   292
5683
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   293
    	  if( (i + 1) < argc)  {
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   294
    		  testName = argv[++i];
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   295
    	  }  else {
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   296
    		  printf("runner: test name is missing\n");
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   297
    		  printUsage();
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   298
    		  exit(1);
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   299
    	  }
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   300
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   301
    	  memset(selected_test_name, 0, NAME_BUFFER_SIZE);
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   302
    	  strcpy(selected_test_name, testName);
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   303
      }
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   304
      else if(SDL_strcmp(arg, "--suite") == 0 || SDL_strcmp(arg, "-s") == 0) {
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   305
    	  only_selected_suite = 1;
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   306
5683
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   307
    	  char *suiteName = NULL;
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   308
    	  if( (i + 1) < argc)  {
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   309
    		  suiteName = argv[++i];
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   310
    	  }  else {
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   311
    		  printf("runner: suite name is missing\n");
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   312
    		  printUsage();
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   313
    		  exit(1);
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   314
    	  }
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   315
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   316
    	  memset(selected_suite_name, 0, NAME_BUFFER_SIZE);
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   317
    	  strcpy(selected_suite_name, suiteName);
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   318
      }
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   319
      else {
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   320
    	  printf("runner: unknown command '%s'\n", arg);
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   321
    	  printUsage();
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   322
    	  exit(0);
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   323
      }
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   324
   }
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   325
}
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   326
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   327
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   328
/*!
5684
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   329
 * Tests if the given test suite is selected for execution.
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   330
 * If only_selected_suite flag is zero, then all the suites are
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   331
 * automatically selected. If the flags is non-zero, only the suite
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   332
 * which matches the selected suite is selected.
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   333
 *
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   334
 * \param testSuiteName Name of the test suite
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   335
 *
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   336
 * \return 1 if given suite is selected, otherwise 0
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   337
 */
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   338
int
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   339
SuiteIsSelected(char *testSuiteName) {
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   340
	int retVal = 1;
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   341
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   342
	if(only_selected_suite)	{
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   343
		// extract the suite name. Rips the tests/ and file suffix from the suite name
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   344
		char buffer[NAME_BUFFER_SIZE];
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   345
		int len = strlen(testSuiteName);
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   346
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   347
//! \todo Fix this, it's rather horrible way to do it
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   348
#define DIR_NAME_LENGTH 6
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   349
#if defined(linux) || defined( __linux)
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   350
#define FILE_EXT_LENGTH 3
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   351
#else
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   352
#define FILE_EXT_LENGTH 6
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   353
#endif
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   354
		int length = len - DIR_NAME_LENGTH - FILE_EXT_LENGTH;
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   355
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   356
		memset(buffer, 0, NAME_BUFFER_SIZE);
5685
731a7c70eded Fix: Use DEFINE instead of plain number.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5684
diff changeset
   357
		memcpy(buffer, testSuiteName + DIR_NAME_LENGTH, length);
5684
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   358
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   359
		retVal = SDL_strncmp(selected_suite_name, buffer, NAME_BUFFER_SIZE) == 0;
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   360
	}
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   361
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   362
	return retVal;
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   363
}
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   364
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   365
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   366
/*!
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   367
 * Entry point for test runner
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   368
 *
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   369
 * \param argc Count of command line arguments
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   370
 * \param argv Array of commond lines arguments
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   371
 */
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   372
int
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   373
main(int argc, char *argv[])
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   374
{
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   375
	ParseOptions(argc, argv);
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   376
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   377
	// print: Testing against SDL version fuu (rev: bar) if verbose == true
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   378
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   379
	int failureCount = 0, passCount = 0;
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   380
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   381
	const Uint32 startTicks = SDL_GetTicks();
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   382
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   383
	char **testSuiteNames = ScanForTestSuites();
5669
d6873237c96d Little fixes here and there.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5668
diff changeset
   384
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   385
	char *testSuiteName = NULL;
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   386
	int suiteCounter = 0;
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   387
	for(testSuiteName = testSuiteNames[suiteCounter]; testSuiteName; testSuiteName = testSuiteNames[++suiteCounter]) {
5684
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   388
		// if the current suite isn't selected, go to next suite
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   389
		if(SuiteIsSelected(testSuiteName) == 0) {
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   390
			continue;
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   391
		}
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   392
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   393
		void *suite = LoadTestSuite(testSuiteName);
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   394
		TestCaseReference **tests = QueryTestCases(suite);
5668
3a9b790c00e9 Added TestCaseReference structure.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5667
diff changeset
   395
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   396
		TestCaseReference *reference = NULL;
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   397
		int counter = 0;
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   398
		for(reference = tests[counter]; reference; reference = tests[++counter]) {
5684
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   399
			if(only_selected_test && SDL_strncmp(selected_test_name, reference->name, NAME_BUFFER_SIZE) != 0) {
d67b7490be36 Refactored a bit. Extracted the code which checks for
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5683
diff changeset
   400
				continue;
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   401
			}
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   402
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   403
			if(reference->enabled == TEST_DISABLED) {
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   404
				printf("Test %s (in %s) disabled. Omitting...\n", reference->name, testSuiteName);
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   405
			} else {
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   406
				printf("Executing %s (in %s):\n", reference->name, testSuiteName);
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   407
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   408
				int retVal = ExecuteTest(suite, reference);
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   409
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   410
				if(retVal) {
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   411
					failureCount++;
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   412
					if(retVal == 2) {
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   413
						printf("%s (in %s): FAILED -> No asserts\n", reference->name, testSuiteName);
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   414
					} else {
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   415
						printf("%s (in %s): FAILED\n", reference->name, testSuiteName);
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   416
					}
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   417
				} else {
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   418
					passCount++;
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   419
					printf("%s (in %s): ok\n", reference->name, testSuiteName);
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   420
				}
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   421
			}
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   422
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   423
			printf("\n");
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   424
		}
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   425
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   426
		SDL_UnloadObject(suite);
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   427
	}
5662
57fc58008d76 Tiny changes to runner
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5659
diff changeset
   428
57fc58008d76 Tiny changes to runner
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5659
diff changeset
   429
	const Uint32 endTicks = SDL_GetTicks();
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   430
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   431
	printf("Ran %d tests in %0.5f seconds.\n", (passCount + failureCount), (endTicks-startTicks)/1000.0f);
5662
57fc58008d76 Tiny changes to runner
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5659
diff changeset
   432
57fc58008d76 Tiny changes to runner
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5659
diff changeset
   433
	printf("%d tests passed\n", passCount);
57fc58008d76 Tiny changes to runner
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5659
diff changeset
   434
	printf("%d tests failed\n", failureCount);
57fc58008d76 Tiny changes to runner
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5659
diff changeset
   435
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   436
	return 0;
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   437
}