test/test-automation/runner.c
author Markus Kauppila <markus.kauppila@gmail.com>
Sun, 03 Jul 2011 20:22:30 +0300
changeset 5740 d035de3f1306
parent 5738 8fc92ff2054b
child 5741 0e08b8021648
permissions -rw-r--r--
Help usage missed ] which added.
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>
5689
f1ab815aa4af Initial version of "scan tests/ for test suites" functionality.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5687
diff changeset
    27
#include <dirent.h>
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    28
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    29
#include <sys/types.h>
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    30
5674
1ee88babe722 Moved tests/SDL_test.{c,h}
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5673
diff changeset
    31
#include "SDL_test.h"
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
    32
#include "logger.h"
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
    33
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
    34
//!< Function pointer to a test case function
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
    35
typedef void (*TestCaseFp)(void *arg);
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
    36
//!< Function pointer to a test case init function
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
    37
typedef void (*TestCaseInitFp)(const int);
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
    38
//!< Function pointer to a test case quit function
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
    39
typedef int  (*TestCaseQuitFp)(void);
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
    40
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
    41
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    42
//!< 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
    43
static int execute_inproc = 0;
5700
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
    44
//!< Flag for only printing out the test names
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
    45
static int only_print_tests = 0;
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    46
//!< 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
    47
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
    48
//!< 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
    49
static int only_selected_suite = 0;
5693
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
    50
//!< Flag for executing only tests that contain certain string in their name
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
    51
static int only_tests_with_string = 0;
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
    52
//!< Flag for enabling XML logging
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
    53
static int xml_enabled = 0;
5728
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5727
diff changeset
    54
//! Flag for enabling user-supplied style sheet for XML test report
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5727
diff changeset
    55
static int custom_xsl_enabled = 0;
5731
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
    56
//! Flag for disabling xsl-style from xml report
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
    57
static int xsl_enabled = 0;
5693
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
    58
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    59
5691
c0b4bcd901a0 Removed unnecessary function.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5690
diff changeset
    60
//!< Size of the test and suite name buffers
5689
f1ab815aa4af Initial version of "scan tests/ for test suites" functionality.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5687
diff changeset
    61
#define NAME_BUFFER_SIZE 1024
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    62
//!< Name of the selected test
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    63
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
    64
//!< Name of the selected suite
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    65
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
    66
5693
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
    67
//!< substring of test case name
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
    68
char testcase_name_substring[NAME_BUFFER_SIZE];
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
    69
5728
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5727
diff changeset
    70
//! Name for user-supplied XSL style sheet name
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5727
diff changeset
    71
char xsl_stylesheet_name[NAME_BUFFER_SIZE];
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5727
diff changeset
    72
5691
c0b4bcd901a0 Removed unnecessary function.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5690
diff changeset
    73
//! Default directory of the test suites
c0b4bcd901a0 Removed unnecessary function.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5690
diff changeset
    74
#define DEFAULT_TEST_DIRECTORY "tests/"
c0b4bcd901a0 Removed unnecessary function.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5690
diff changeset
    75
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
    76
5689
f1ab815aa4af Initial version of "scan tests/ for test suites" functionality.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5687
diff changeset
    77
/*!
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
    78
 * Holds information about test suite such as it's name
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
    79
 * and pointer to dynamic library. Implemented as linked list.
5689
f1ab815aa4af Initial version of "scan tests/ for test suites" functionality.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5687
diff changeset
    80
 */
f1ab815aa4af Initial version of "scan tests/ for test suites" functionality.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5687
diff changeset
    81
typedef struct TestSuiteReference {
5692
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
    82
	char *name; //!< test suite name
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
    83
	char *directoryPath; //!< test suites path (eg. tests/libtestsuite)
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
    84
	void *library; //!< pointer to shared/dynamic library implementing the suite
5692
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
    85
5689
f1ab815aa4af Initial version of "scan tests/ for test suites" functionality.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5687
diff changeset
    86
	struct TestSuiteReference *next; //!< Pointer to next item in the list
f1ab815aa4af Initial version of "scan tests/ for test suites" functionality.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5687
diff changeset
    87
} TestSuiteReference;
f1ab815aa4af Initial version of "scan tests/ for test suites" functionality.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5687
diff changeset
    88
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
    89
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
    90
/*!
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
    91
 * Holds information about the tests that will be executed.
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
    92
 *
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
    93
 * Implemented as linked list.
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
    94
 */
5692
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
    95
typedef struct TestCaseItem {
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
    96
	char *testName;
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
    97
	char *suiteName;
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
    98
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
    99
	char *description;
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   100
	long requirements;
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   101
	long timeout;
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   102
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   103
	TestCaseInitFp testCaseInit;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   104
	TestCaseFp testCase;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   105
	TestCaseQuitFp testCaseQuit;
5692
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   106
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   107
	struct TestCaseItem *next;
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   108
} TestCase;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   109
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   110
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   111
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   112
/*! Some function prototypes. Add the rest of functions and move to runner.h */
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   113
TestCaseFp LoadTestCaseFunction(void *suite, char *testName);
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   114
TestCaseInitFp LoadTestCaseInitFunction(void *suite);
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   115
TestCaseQuitFp LoadTestCaseQuitFunction(void *suite);
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   116
TestCaseReference **QueryTestCaseReferences(void *library);
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   117
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   118
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   119
/*!
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   120
 * Goes through the previously loaded test suites and
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   121
 * loads test cases from them. Test cases are filtered
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   122
 * during the process. Function will only return the
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   123
 * test cases which aren't filtered out.
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   124
 *
5696
e902fa6e6960 Fixed doxygen comments and usage help.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5695
diff changeset
   125
 * \param suites previously loaded test suites
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   126
 *
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   127
 * \return Test cases that survived filtering process.
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   128
 */
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   129
TestCase *
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   130
LoadTestCases(TestSuiteReference *suites)
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   131
{
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   132
	TestCase *testCases = NULL;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   133
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   134
	TestSuiteReference *suiteReference = NULL;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   135
	for(suiteReference = suites; suiteReference; suiteReference = suiteReference->next) {
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   136
		TestCaseReference **tests = QueryTestCaseReferences(suiteReference->library);
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   137
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   138
		TestCaseReference *testReference = NULL;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   139
		int counter = 0;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   140
		for(testReference = tests[counter]; testReference; testReference = tests[++counter]) {
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   141
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   142
			void *suite = suiteReference->library;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   143
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   144
			// Load test case functions
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   145
			TestCaseInitFp testCaseInit = LoadTestCaseInitFunction(suiteReference->library);
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   146
			TestCaseQuitFp testCaseQuit = LoadTestCaseQuitFunction(suiteReference->library);
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   147
			TestCaseFp testCase = (TestCaseFp) LoadTestCaseFunction(suiteReference->library, testReference->name);
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   148
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   149
			// Do the filtering
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   150
			if(FilterTestCase(testReference)) {
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   151
				TestCase *item = SDL_malloc(sizeof(TestCase));
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   152
				memset(item, 0, sizeof(TestCase));
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   153
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   154
				item->testCaseInit = testCaseInit;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   155
				item->testCase = testCase;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   156
				item->testCaseQuit = testCaseQuit;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   157
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   158
				// copy suite name
5715
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   159
				int length = SDL_strlen(suiteReference->name) + 1;
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   160
				item->suiteName = SDL_malloc(length);
5715
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   161
				strncpy(item->suiteName, suiteReference->name, length);
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   162
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   163
				// copy test name
5715
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   164
				length = SDL_strlen(testReference->name) + 1;
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   165
				item->testName = SDL_malloc(length);
5715
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   166
				strncpy(item->testName, testReference->name, length);
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   167
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   168
				// copy test description
5715
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   169
				length = SDL_strlen(testReference->description) + 1;
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   170
				item->description = SDL_malloc(length);
5715
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   171
				strncpy(item->description, testReference->description, length);
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   172
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   173
				item->requirements = testReference->requirements;
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   174
				item->timeout = testReference->timeout;
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   175
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   176
				// prepend the list
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   177
				item->next = testCases;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   178
				testCases = item;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   179
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   180
				//printf("Added test: %s\n", testReference->name);
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   181
			}
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   182
		}
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   183
	}
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   184
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   185
	return testCases;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   186
}
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   187
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   188
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   189
/*!
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   190
 * Unloads the given TestCases. Frees all the resources
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   191
 * allocated for test cases.
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   192
 *
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   193
 * \param testCases Test cases to be deallocated
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   194
 */
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   195
void
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   196
UnloadTestCases(TestCase *testCases)
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   197
{
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   198
	TestCase *ref = testCases;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   199
	while(ref) {
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   200
		SDL_free(ref->testName);
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   201
		SDL_free(ref->suiteName);
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   202
		SDL_free(ref->description);
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   203
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   204
		TestCase *temp = ref->next;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   205
		SDL_free(ref);
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   206
		ref = temp;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   207
	}
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   208
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   209
	testCases = NULL;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   210
}
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   211
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   212
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   213
/*!
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   214
 * Filters a test case based on its properties in TestCaseReference and user
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   215
 * preference.
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   216
 *
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   217
 * \return Non-zero means test will be added to execution list, zero means opposite
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   218
 */
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   219
int
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   220
FilterTestCase(TestCaseReference *testReference)
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   221
{
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   222
	int retVal = 1;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   223
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   224
	if(testReference->enabled == TEST_DISABLED) {
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   225
		retVal = 0;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   226
	}
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   227
5695
6d81a581e6f5 Updated test case filter.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5694
diff changeset
   228
	if(only_selected_test) {
6d81a581e6f5 Updated test case filter.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5694
diff changeset
   229
		if(SDL_strncmp(testReference->name, selected_test_name, NAME_BUFFER_SIZE) == 0) {
6d81a581e6f5 Updated test case filter.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5694
diff changeset
   230
			retVal = 1;
6d81a581e6f5 Updated test case filter.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5694
diff changeset
   231
		} else {
6d81a581e6f5 Updated test case filter.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5694
diff changeset
   232
			retVal = 0;
6d81a581e6f5 Updated test case filter.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5694
diff changeset
   233
		}
6d81a581e6f5 Updated test case filter.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5694
diff changeset
   234
	}
6d81a581e6f5 Updated test case filter.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5694
diff changeset
   235
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   236
	if(only_tests_with_string) {
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   237
		if(strstr(testReference->name, testcase_name_substring) != NULL) {
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   238
			retVal = 1;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   239
		} else {
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   240
			retVal = 0;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   241
		}
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   242
	}
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   243
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   244
	return retVal;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   245
}
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   246
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   247
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   248
/*!
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   249
 * Scans the tests/ directory and returns the names
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   250
 * of the dynamic libraries implementing the test suites.
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   251
 *
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   252
 * Note: currently function assumes that test suites names
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   253
 * are in following format: libtestsuite.dylib or libtestsuite.so.
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   254
 *
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   255
 * Note: if only_selected_suite flags is non-zero, only the selected
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   256
 * test will be loaded.
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   257
 *
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   258
 * \param directoryName Name of the directory which will be scanned
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   259
 * \param extension What file extension is used with dynamic objects
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   260
 *
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   261
 * \return Pointer to TestSuiteReference which holds all the info about suites
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   262
 */
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   263
TestSuiteReference *
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   264
ScanForTestSuites(char *directoryName, char *extension)
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   265
{
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   266
	typedef struct dirent Entry;
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   267
	DIR *directory = opendir(directoryName);
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   268
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   269
	TestSuiteReference *suites = NULL;
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   270
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   271
	Entry *entry = NULL;
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   272
	if(!directory) {
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   273
		perror("Couldn't open test suite directory!");
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   274
	}
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   275
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   276
	while(entry = readdir(directory)) {
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   277
		if(strlen(entry->d_name) > 2) { // discards . and ..
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   278
			const char *delimiters = ".";
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   279
			char *name = strtok(entry->d_name, delimiters);
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   280
			char *ext = strtok(NULL, delimiters);
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   281
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   282
			// filter out all other suites but the selected test suite
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   283
			int ok = 1;
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   284
			if(only_selected_suite) {
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   285
				ok = SDL_strncmp(selected_suite_name, name, NAME_BUFFER_SIZE) == 0;
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   286
			}
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   287
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   288
			if(ok && SDL_strcmp(ext, extension)  == 0) {
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   289
				// create test suite reference
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   290
				TestSuiteReference *reference = (TestSuiteReference *) SDL_malloc(sizeof(TestSuiteReference));
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   291
				memset(reference, 0, sizeof(TestSuiteReference));
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   292
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   293
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   294
				const int dirSize = SDL_strlen(directoryName);
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   295
				const int extSize = SDL_strlen(ext);
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   296
				const int nameSize = SDL_strlen(name) + 1;
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   297
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   298
				// copy the name
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   299
				reference->name = SDL_malloc(nameSize * sizeof(char));
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   300
				if(reference->name == NULL) {
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   301
					SDL_free(reference);
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   302
					return NULL;
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   303
				}
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   304
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   305
				SDL_snprintf(reference->name, nameSize, "%s", name);
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   306
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   307
				// copy the directory path
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   308
				const int dpSize = dirSize + nameSize + 1 + extSize + 1;
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   309
				reference->directoryPath = SDL_malloc(dpSize * sizeof(char));
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   310
				if(reference->directoryPath == NULL) {
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   311
					SDL_free(reference->name);
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   312
					SDL_free(reference);
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   313
					return NULL;
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   314
				}
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   315
				SDL_snprintf(reference->directoryPath, dpSize, "%s%s.%s",
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   316
						directoryName, name, ext);
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   317
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   318
				reference->next = suites;
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   319
				suites = reference;
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   320
			}
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   321
		}
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   322
	}
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   323
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   324
	closedir(directory);
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   325
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   326
	return suites;
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   327
}
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   328
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   329
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   330
/*!
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   331
 * 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
   332
 *
5733
9c9eeded847a Fixed doxygen markup error.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   333
 * \param suite Reference to test suite that'll be loaded
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   334
 *
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   335
 * \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
   336
 */
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   337
void *
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   338
LoadTestSuite(const TestSuiteReference *suite)
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   339
{
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   340
	void *library = SDL_LoadObject(suite->directoryPath);
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   341
	if(library == NULL) {
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   342
		fprintf(stderr, "Loading %s failed\n", suite->name);
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   343
		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
   344
	}
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   345
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   346
	return library;
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   347
}
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   348
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   349
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   350
/*!
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   351
 * Goes through all the given TestSuiteReferences
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   352
 * and loads the dynamic libraries. Updates the suites
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   353
 * parameter on-the-fly and returns it.
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   354
 *
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   355
 * \param suites Suites that will be loaded
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   356
 *
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   357
 * \return Updated TestSuiteReferences with pointer to loaded libraries
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   358
 */
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   359
TestSuiteReference *
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   360
LoadTestSuites(TestSuiteReference *suites)
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   361
{
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   362
	TestSuiteReference *reference = NULL;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   363
	for(reference = suites; reference; reference = reference->next) {
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   364
		reference->library = LoadTestSuite(reference);
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   365
	}
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   366
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   367
	return suites;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   368
}
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   369
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   370
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   371
/*!
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   372
 * Unloads the given TestSuiteReferences. Frees all
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   373
 * the allocated resources including the dynamic libraries.
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   374
 *
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   375
 * \param suites TestSuiteReferences for deallocation process
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   376
 */
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   377
void
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   378
UnloadTestSuites(TestSuiteReference *suites)
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   379
{
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   380
	TestSuiteReference *ref = suites;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   381
	while(ref) {
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   382
		SDL_free(ref->name);
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   383
		SDL_free(ref->directoryPath);
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   384
		SDL_UnloadObject(ref->library);
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   385
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   386
		TestSuiteReference *temp = ref->next;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   387
		SDL_free(ref);
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   388
		ref = temp;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   389
	}
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   390
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   391
	suites = NULL;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   392
}
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   393
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   394
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   395
/*!
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   396
 * 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
   397
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   398
 * \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
   399
 * \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
   400
 */
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   401
TestCaseReference **
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   402
QueryTestCaseReferences(void *library)
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   403
{
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   404
        TestCaseReference **(*suite)(void);
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   405
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   406
        suite = (TestCaseReference **(*)(void)) SDL_LoadFunction(library, "QueryTestSuite");
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   407
        if(suite == NULL) {
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   408
                fprintf(stderr, "Loading QueryTestCaseReferences() failed.\n");
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   409
                fprintf(stderr, "%s\n", SDL_GetError());
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   410
        }
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   411
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   412
        TestCaseReference **tests = suite();
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   413
        if(tests == NULL) {
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   414
                fprintf(stderr, "Failed to load test references.\n");
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   415
                fprintf(stderr, "%s\n", SDL_GetError());
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   416
        }
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   417
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   418
        return tests;
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   419
}
5662
57fc58008d76 Tiny changes to runner
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5659
diff changeset
   420
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   421
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   422
/*!
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   423
 * Loads test case from a test suite
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   424
 *
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   425
 * \param suite a test suite
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   426
 * \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
   427
 *
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   428
 * \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
   429
 */
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   430
TestCaseFp
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   431
LoadTestCaseFunction(void *suite, char *testName)
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   432
{
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   433
	TestCaseFp test = (TestCaseFp) SDL_LoadFunction(suite, testName);
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   434
	if(test == NULL) {
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   435
		fprintf(stderr, "Loading test failed, tests == NULL\n");
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   436
		fprintf(stderr, "%s\n", SDL_GetError());
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   437
	}
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   438
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   439
	return test;
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   440
}
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   441
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   442
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   443
/*!
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   444
 * 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
   445
 * given test suite.
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   446
 *
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   447
 * \param suite Used test suite
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   448
 *
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   449
 * \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
   450
 */
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   451
TestCaseInitFp
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   452
LoadTestCaseInitFunction(void *suite) {
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   453
	TestCaseInitFp testCaseInit = (TestCaseInitFp) SDL_LoadFunction(suite, "_TestCaseInit");
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   454
	if(testCaseInit == NULL) {
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   455
		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
   456
		fprintf(stderr, "%s\n", SDL_GetError());
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   457
	}
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   458
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   459
	return testCaseInit;
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   460
}
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   461
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   462
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   463
/*!
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   464
 * 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
   465
 * given test suite.
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   466
 *
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   467
 * \param suite Used test suite
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   468
 *
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   469
 * \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
   470
 */
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   471
TestCaseQuitFp
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   472
LoadTestCaseQuitFunction(void *suite) {
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   473
	TestCaseQuitFp testCaseQuit = (TestCaseQuitFp) SDL_LoadFunction(suite, "_TestCaseQuit");
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   474
	if(testCaseQuit == NULL) {
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   475
		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
   476
		fprintf(stderr, "%s\n", SDL_GetError());
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   477
	}
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   478
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   479
	return testCaseQuit;
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   480
}
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   481
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   482
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   483
/*!
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   484
 * 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
   485
 * 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
   486
 * 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
   487
 * if child was aborted by a signela.
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   488
 *
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   489
 * \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
   490
 *
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   491
 * \return 0 if test case succeeded, 1 otherwise
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   492
 */
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   493
int
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   494
HandleChildProcessReturnValue(int stat_lock)
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   495
{
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   496
	int returnValue = -1;
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   497
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   498
	if(WIFEXITED(stat_lock)) {
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   499
		returnValue = WEXITSTATUS(stat_lock);
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   500
	} else if(WIFSIGNALED(stat_lock)) {
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   501
		int signal = WTERMSIG(stat_lock);
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   502
		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
   503
		returnValue = 1;
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   504
	}
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   505
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   506
	return returnValue;
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   507
}
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   508
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   509
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   510
/*!
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   511
 * 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
   512
 * 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
   513
 *
5696
e902fa6e6960 Fixed doxygen comments and usage help.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5695
diff changeset
   514
 * \param testItem The test case that will be executed
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   515
 * \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
   516
 */
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   517
int
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   518
ExecuteTest(TestCase *testItem) {
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   519
	int retVal = 1;
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   520
	if(execute_inproc) {
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   521
		testItem->testCaseInit(xml_enabled);
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   522
5692
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   523
		testItem->testCase(0x0);
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   524
5692
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   525
		retVal = testItem->testCaseQuit();
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   526
	} else {
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   527
		int childpid = fork();
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   528
		if(childpid == 0) {
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   529
			testItem->testCaseInit(xml_enabled);
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   530
5692
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   531
			testItem->testCase(0x0);
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   532
5692
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   533
			exit(testItem->testCaseQuit());
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   534
		} else {
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   535
			int stat_lock = -1;
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   536
			int child = wait(&stat_lock);
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   537
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   538
			retVal = HandleChildProcessReturnValue(stat_lock);
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   539
		}
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   540
	}
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   541
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   542
	return retVal;
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   543
}
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   544
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   545
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   546
/*!
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   547
 * Prints usage information
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   548
 */
5687
4a61fa7362ed Minor refactorings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5686
diff changeset
   549
void
4a61fa7362ed Minor refactorings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5686
diff changeset
   550
printUsage() {
5696
e902fa6e6960 Fixed doxygen comments and usage help.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5695
diff changeset
   551
	  printf("Usage: ./runner [--in-proc] [--suite SUITE] [--test TEST]\n");
5740
d035de3f1306 Help usage missed ] which added.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5738
diff changeset
   552
	  printf("                [--name-contains SUBSTR] [--show-tests]\n");
5738
8fc92ff2054b Changed the usage help.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5733
diff changeset
   553
	  printf("                [--xml] [--xsl [STYLESHEET]] [--help]\n");
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   554
	  printf("Options:\n");
5696
e902fa6e6960 Fixed doxygen comments and usage help.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5695
diff changeset
   555
	  printf("     --in-proc                Executes tests in-process\n");
5700
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
   556
	  printf("     --show-tests             Prints out all the executable tests\n");
5731
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   557
	  printf("     --xml                    Enables XML logger\n");
5738
8fc92ff2054b Changed the usage help.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5733
diff changeset
   558
	  printf("     --xsl [STYLESHEET]       Adds XSL stylesheet to the XML test reports for\n");
8fc92ff2054b Changed the usage help.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5733
diff changeset
   559
	  printf("                              browser viewing. Optionally uses the specified XSL\n");
8fc92ff2054b Changed the usage help.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5733
diff changeset
   560
	  printf("                              file or URL instead of the default one\n");
5696
e902fa6e6960 Fixed doxygen comments and usage help.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5695
diff changeset
   561
	  printf(" -t  --test TEST              Executes only tests with given name\n");
e902fa6e6960 Fixed doxygen comments and usage help.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5695
diff changeset
   562
	  printf(" -ts --name-contains SUBSTR   Executes only tests that have given\n");
e902fa6e6960 Fixed doxygen comments and usage help.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5695
diff changeset
   563
	  printf("                              substring in test name\n");
e902fa6e6960 Fixed doxygen comments and usage help.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5695
diff changeset
   564
	  printf(" -s  --suite SUITE            Executes only the given test suite\n");
5683
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   565
5696
e902fa6e6960 Fixed doxygen comments and usage help.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5695
diff changeset
   566
	  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
   567
}
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   568
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   569
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   570
/*!
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   571
 * 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
   572
 *
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   573
 * \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
   574
 * \param argv Array of commond lines arguments
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   575
 */
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   576
void
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   577
ParseOptions(int argc, char *argv[])
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   578
{
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   579
   int i;
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   580
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   581
   for (i = 1; i < argc; ++i) {
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   582
      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
   583
      if(SDL_strcmp(arg, "--in-proc") == 0) {
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   584
         execute_inproc = 1;
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   585
      }
5700
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
   586
      else if(SDL_strcmp(arg, "--show-tests") == 0) {
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
   587
    	  only_print_tests = 1;
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   588
      }
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   589
      else if(SDL_strcmp(arg, "--xml") == 0) {
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   590
    	  xml_enabled = 1;
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   591
      }
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   592
      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
   593
    	  only_selected_test = 1;
5683
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   594
    	  char *testName = NULL;
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   595
5683
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   596
    	  if( (i + 1) < argc)  {
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   597
    		  testName = argv[++i];
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   598
    	  }  else {
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   599
    		  printf("runner: test name is missing\n");
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   600
    		  printUsage();
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   601
    		  exit(1);
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   602
    	  }
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   603
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   604
    	  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
   605
    	  strcpy(selected_test_name, testName);
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   606
      }
5728
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5727
diff changeset
   607
      else if(SDL_strcmp(arg, "--xsl") == 0) {
5731
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   608
    	  xsl_enabled = 1;
5728
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5727
diff changeset
   609
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5727
diff changeset
   610
    	  if( (i + 1) < argc)  {
5731
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   611
    		  char *stylesheet = argv[++i];
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   612
    		  if(stylesheet[0] != '-') {
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   613
    	    	  custom_xsl_enabled = 1;
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   614
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   615
    	    	  memset(xsl_stylesheet_name, 0, NAME_BUFFER_SIZE);
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   616
    	    	  strncpy(xsl_stylesheet_name, stylesheet, NAME_BUFFER_SIZE);
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   617
    		  }
5728
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5727
diff changeset
   618
    	  }
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5727
diff changeset
   619
      }
5696
e902fa6e6960 Fixed doxygen comments and usage help.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5695
diff changeset
   620
      else if(SDL_strcmp(arg, "--name-contains") == 0 || SDL_strcmp(arg, "-ts") == 0) {
5693
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
   621
    	  only_tests_with_string = 1;
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
   622
    	  char *substring = NULL;
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
   623
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
   624
    	  if( (i + 1) < argc)  {
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
   625
    		  substring = argv[++i];
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
   626
    	  }  else {
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
   627
    		  printf("runner: substring of test name is missing\n");
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
   628
    		  printUsage();
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
   629
    		  exit(1);
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
   630
    	  }
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
   631
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
   632
    	  memset(testcase_name_substring, 0, NAME_BUFFER_SIZE);
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
   633
    	  strcpy(testcase_name_substring, substring);
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
   634
      }
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   635
      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
   636
    	  only_selected_suite = 1;
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   637
5683
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   638
    	  char *suiteName = NULL;
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   639
    	  if( (i + 1) < argc)  {
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   640
    		  suiteName = argv[++i];
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   641
    	  }  else {
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   642
    		  printf("runner: suite name is missing\n");
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   643
    		  printUsage();
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   644
    		  exit(1);
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   645
    	  }
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   646
1905dcc7ad20 Small fixes to previous commit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5682
diff changeset
   647
    	  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
   648
    	  strcpy(selected_suite_name, suiteName);
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   649
      }
5700
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
   650
      else if(SDL_strcmp(arg, "--help") == 0 || SDL_strcmp(arg, "-h") == 0) {
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
   651
    	  printUsage();
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
   652
    	  exit(0);
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
   653
      }
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   654
      else {
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   655
    	  printf("runner: unknown command '%s'\n", arg);
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   656
    	  printUsage();
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   657
    	  exit(0);
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   658
      }
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   659
   }
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   660
}
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   661
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   662
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   663
/*!
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   664
 * Entry point for test runner
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   665
 *
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   666
 * \param argc Count of command line arguments
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   667
 * \param argv Array of commond lines arguments
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   668
 */
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   669
int
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   670
main(int argc, char *argv[])
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   671
{
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   672
	ParseOptions(argc, argv);
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   673
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   674
	// 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
   675
5715
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   676
	int totalTestfailureCount = 0, totalTestPassCount = 0;
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   677
	int testFailureCount = 0, testPassCount = 0, testSkipCount = 0;
5687
4a61fa7362ed Minor refactorings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5686
diff changeset
   678
	char *testSuiteName = NULL;
4a61fa7362ed Minor refactorings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5686
diff changeset
   679
	int suiteCounter = 0;
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   680
5691
c0b4bcd901a0 Removed unnecessary function.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5690
diff changeset
   681
#if defined(linux) || defined( __linux)
c0b4bcd901a0 Removed unnecessary function.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5690
diff changeset
   682
	char *extension = "so";
c0b4bcd901a0 Removed unnecessary function.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5690
diff changeset
   683
#else
c0b4bcd901a0 Removed unnecessary function.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5690
diff changeset
   684
	char *extension = "dylib";
c0b4bcd901a0 Removed unnecessary function.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5690
diff changeset
   685
#endif
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   686
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   687
	if(xml_enabled) {
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   688
		SetupXMLLogger();
5728
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5727
diff changeset
   689
5731
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   690
		char *sheet = NULL;
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   691
		if(xsl_enabled) {
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   692
			sheet = "style.xsl"; // default style sheet;
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   693
		}
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   694
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   695
		if(custom_xsl_enabled) {
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   696
			sheet = xsl_stylesheet_name;
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   697
		}
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   698
507fffef86ad Redefined the usage of --xsl command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5730
diff changeset
   699
		RunStarted(argc, argv, time(0), sheet);
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   700
	} else {
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   701
		SetupPlainLogger();
5728
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5727
diff changeset
   702
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5727
diff changeset
   703
		RunStarted(argc, argv, time(0), NULL);
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   704
	}
5691
c0b4bcd901a0 Removed unnecessary function.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5690
diff changeset
   705
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   706
	const Uint32 startTicks = SDL_GetTicks();
5692
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   707
5691
c0b4bcd901a0 Removed unnecessary function.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5690
diff changeset
   708
	TestSuiteReference *suites = ScanForTestSuites(DEFAULT_TEST_DIRECTORY, extension);
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   709
	suites = LoadTestSuites(suites);
5689
f1ab815aa4af Initial version of "scan tests/ for test suites" functionality.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5687
diff changeset
   710
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   711
	TestCase *testCases = LoadTestCases(suites);
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   712
5700
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
   713
	// if --show-tests option is given, only print tests and exit
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
   714
	if(only_print_tests) {
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
   715
		TestCase *testItem = NULL;
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
   716
		for(testItem = testCases; testItem; testItem = testItem->next) {
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
   717
			printf("%s (in %s)\n", testItem->testName, testItem->suiteName);
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
   718
		}
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
   719
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
   720
		return 0;
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
   721
	}
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
   722
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   723
	char *currentSuiteName = NULL;
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   724
5716
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   725
	int suiteStartTime = SDL_GetTicks();
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   726
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   727
	TestCase *testItem = NULL;
5692
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   728
	for(testItem = testCases; testItem; testItem = testItem->next) {
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   729
		if(currentSuiteName == NULL) {
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   730
			currentSuiteName = testItem->suiteName;
5716
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   731
			SuiteStarted(currentSuiteName, time(0));
5715
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   732
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   733
			testFailureCount = testPassCount = 0;
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   734
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   735
			suiteCounter++;
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   736
		}
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   737
		else if(strncmp(currentSuiteName, testItem->suiteName, NAME_BUFFER_SIZE) != 0) {
5716
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   738
			const double suiteRuntime = (SDL_GetTicks() - suiteStartTime) / 1000.0f;
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   739
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   740
			SuiteEnded(testPassCount, testFailureCount, testSkipCount, time(0),
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   741
						suiteRuntime);
5715
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   742
5724
efb267579adc Fixed the calculation of total runtime for a suite.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5719
diff changeset
   743
			suiteStartTime = SDL_GetTicks();
efb267579adc Fixed the calculation of total runtime for a suite.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5719
diff changeset
   744
5715
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   745
			currentSuiteName = testItem->suiteName;
5719
84d118544c1b Fixed test suite start time.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   746
			SuiteStarted(currentSuiteName, time(0));
5715
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   747
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   748
			testFailureCount = testPassCount = 0;
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   749
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   750
			suiteCounter++;
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   751
		}
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   752
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   753
		TestStarted(testItem->testName, testItem->suiteName,
5716
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   754
                    testItem->description, time(0));
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   755
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   756
		const Uint32 testTimeStart = SDL_GetTicks();
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   757
5692
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   758
		int retVal = ExecuteTest(testItem);
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   759
		if(retVal) {
5715
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   760
			totalTestfailureCount++;
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   761
			testFailureCount++;
5692
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   762
		} else {
5715
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   763
			totalTestPassCount++;
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   764
			testPassCount++;
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   765
		}
5691
c0b4bcd901a0 Removed unnecessary function.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5690
diff changeset
   766
5716
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   767
		const double testTotalRuntime = (SDL_GetTicks() - testTimeStart) / 1000.0f;
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   768
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   769
		TestEnded(testItem->testName, testItem->suiteName, retVal, time(0), testTotalRuntime);
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   770
	}
5662
57fc58008d76 Tiny changes to runner
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5659
diff changeset
   771
5715
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   772
	if(currentSuiteName) {
5716
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   773
		SuiteEnded(testPassCount, testFailureCount, testSkipCount, time(0),
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   774
					(SDL_GetTicks() - suiteStartTime) / 1000.0f);
5715
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   775
	}
5714
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
   776
5692
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   777
	UnloadTestCases(testCases);
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   778
	UnloadTestSuites(suites);
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   779
5662
57fc58008d76 Tiny changes to runner
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5659
diff changeset
   780
	const Uint32 endTicks = SDL_GetTicks();
5716
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   781
	const double totalRunTime = (endTicks - startTicks) / 1000.0f;
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   782
5715
372709daa525 Refining the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5714
diff changeset
   783
	RunEnded(totalTestPassCount + totalTestfailureCount, suiteCounter,
5716
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   784
			 totalTestPassCount, totalTestfailureCount, time(0), totalRunTime);
5662
57fc58008d76 Tiny changes to runner
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5659
diff changeset
   785
5727
390fdae0a318 Cleaned the XSL style a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5724
diff changeset
   786
	return (totalTestfailureCount ? 1 : 0);
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   787
}