test/test-automation/src/runner/runner.c
author Markus Kauppila <markus.kauppila@gmail.com>
Sun, 14 Aug 2011 21:05:08 +0300
changeset 5830 e1a6cc820772
parent 5827 ef0942587b80
child 5831 d0f31485bd81
permissions -rw-r--r--
Updating dummy test suite.
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>
5787
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
    30
#include <sys/stat.h>
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    31
5804
d82711e39c05 Reorganizing the project.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5797
diff changeset
    32
#include "../../include/SDL_test.h"
d82711e39c05 Reorganizing the project.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5797
diff changeset
    33
#include "../../config.h"
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5741
diff changeset
    34
5811
36707a804e66 Trying to fix linux compatibility -> libSDLtest.* is now installed
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5809
diff changeset
    35
#include "../libSDLtest/fuzzer/fuzzer.h"
5746
b7a0b33b08f4 Fixed the interface between tests suites and logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
    36
5811
36707a804e66 Trying to fix linux compatibility -> libSDLtest.* is now installed
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5809
diff changeset
    37
#include "../libSDLtest/plain_logger.h"
36707a804e66 Trying to fix linux compatibility -> libSDLtest.* is now installed
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5809
diff changeset
    38
#include "../libSDLtest/xml_logger.h"
5804
d82711e39c05 Reorganizing the project.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5797
diff changeset
    39
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
    40
#include "logger.h"
5772
a6c404e897af Testing out implementation for skipping unsupported test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5770
diff changeset
    41
#include "support.h"
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
    42
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
    43
//!< 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
    44
typedef void (*TestCaseFp)(void *arg);
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
    45
//!< Function pointer to a test case init function
5797
4936c840d128 Fixing execution key generation based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5796
diff changeset
    46
typedef void (*InitTestInvironmentFp)(Uint64);
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
    47
//!< Function pointer to a test case quit function
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
    48
typedef int  (*QuitTestInvironmentFp)(void);
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
    49
//!< Function pointer to a test case set up function
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
    50
typedef void (*TestCaseSetUpFp)(void *arg);
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
    51
//!< Function pointer to a test case tear down function
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
    52
typedef void  (*TestCaseTearDownFp)(void *arg);
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
    53
//!< Function pointer to a function which returns the failed assert count
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
    54
typedef int (*CountFailedAssertsFp)(void);
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
    55
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
    56
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
    57
//!< 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
    58
static int execute_inproc = 0;
5700
5644a467ec5f Added new command line option: --show-tests
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5697
diff changeset
    59
//!< 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
    60
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
    61
//!< 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
    62
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
    63
//!< 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
    64
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
    65
//!< 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
    66
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
    67
//!< 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
    68
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
    69
//! 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
    70
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
    71
//! 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
    72
static int xsl_enabled = 0;
5769
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
    73
//! Flag for enabling universal timeout for tests
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
    74
static int universal_timeout_enabled = 0;
5785
7fc252ce5d1d Added simple logging levels to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5784
diff changeset
    75
//! Flag for enabling verbose logging
7fc252ce5d1d Added simple logging levels to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5784
diff changeset
    76
static int enable_verbose_logger = 0;
5786
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
    77
//! Flag for using user supplied run seed
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
    78
static int userRunSeed = 0;
5788
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
    79
//! Whether or not logger should log to stdout instead of file
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
    80
static int log_stdout_enabled = 0;
5827
ef0942587b80 Added --include-dummy option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5826
diff changeset
    81
//! Whether or not dummy suite should be included to the test run
ef0942587b80 Added --include-dummy option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5826
diff changeset
    82
static int include_dummy_suite = 0;
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    83
5691
c0b4bcd901a0 Removed unnecessary function.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5690
diff changeset
    84
//!< 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
    85
#define NAME_BUFFER_SIZE 1024
5787
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
    86
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    87
//!< Name of the selected test
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    88
char selected_test_name[NAME_BUFFER_SIZE];
5787
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
    89
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    90
//!< Name of the selected suite
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
    91
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
    92
5693
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
    93
//!< substring of test case name
cd0110de8ad5 Added test and suite names to the output.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5692
diff changeset
    94
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
    95
5728
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5727
diff changeset
    96
//! 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
    97
char xsl_stylesheet_name[NAME_BUFFER_SIZE];
5794
e39e9c62c671 Fixed harness seed generation based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5793
diff changeset
    98
5780
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
    99
//! User-suppled timeout value for tests
5769
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   100
int universal_timeout = -1;
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   101
5691
c0b4bcd901a0 Removed unnecessary function.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5690
diff changeset
   102
//! Default directory of the test suites
c0b4bcd901a0 Removed unnecessary function.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5690
diff changeset
   103
#define DEFAULT_TEST_DIRECTORY "tests/"
c0b4bcd901a0 Removed unnecessary function.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5690
diff changeset
   104
5787
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   105
//! Default directory for placing log files
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   106
#define DEFAULT_LOG_DIRECTORY "logs"
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   107
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   108
//! Default directory of the test suites
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   109
#define DEFAULT_LOG_FILENAME "runner"
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   110
5795
134c0f7ae826 Changed SetUpLogger based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5794
diff changeset
   111
//! Defines directory separator
134c0f7ae826 Changed SetUpLogger based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5794
diff changeset
   112
#define DIRECTORY_SEPARATOR '/'
134c0f7ae826 Changed SetUpLogger based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5794
diff changeset
   113
5827
ef0942587b80 Added --include-dummy option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5826
diff changeset
   114
#define DUMMY_TEST_NAME "libtestdummy"
ef0942587b80 Added --include-dummy option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5826
diff changeset
   115
5795
134c0f7ae826 Changed SetUpLogger based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5794
diff changeset
   116
//! Name of the default stylesheet
134c0f7ae826 Changed SetUpLogger based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5794
diff changeset
   117
const char *defaultXSLStylesheet = "style.xsl";
134c0f7ae826 Changed SetUpLogger based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5794
diff changeset
   118
5786
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   119
//! Fuzzer seed for the harness
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   120
char *runSeed = NULL;
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   121
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   122
//! Execution key that user supplied via command options
5797
4936c840d128 Fixing execution key generation based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5796
diff changeset
   123
Uint64 userExecKey = 0;
5780
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   124
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   125
//! How man time a test will be invocated
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   126
int testInvocationCount = 1;
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   127
5787
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   128
//! Stores the basename for log files
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   129
char log_basename[NAME_BUFFER_SIZE];
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   130
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   131
//! Stores directory name for placing the logs
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   132
char log_directory[NAME_BUFFER_SIZE];
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   133
5786
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   134
// \todo add comments
5780
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   135
int totalTestFailureCount = 0, totalTestPassCount = 0, totalTestSkipCount = 0;
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   136
int testFailureCount = 0, testPassCount = 0, testSkipCount = 0;
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   137
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   138
5689
f1ab815aa4af Initial version of "scan tests/ for test suites" functionality.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5687
diff changeset
   139
/*!
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   140
 * 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
   141
 * 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
   142
 */
f1ab815aa4af Initial version of "scan tests/ for test suites" functionality.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5687
diff changeset
   143
typedef struct TestSuiteReference {
5692
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   144
	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
   145
	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
   146
	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
   147
5689
f1ab815aa4af Initial version of "scan tests/ for test suites" functionality.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5687
diff changeset
   148
	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
   149
} TestSuiteReference;
f1ab815aa4af Initial version of "scan tests/ for test suites" functionality.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5687
diff changeset
   150
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   151
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   152
/*!
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   153
 * 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
   154
 *
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   155
 * Implemented as linked list.
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   156
 */
5692
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   157
typedef struct TestCaseItem {
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   158
	char *testName;
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   159
	char *suiteName;
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   160
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   161
	char *description;
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   162
	long requirements;
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   163
	long timeout;
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5700
diff changeset
   164
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   165
	InitTestInvironmentFp initTestEnvironment;
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   166
	TestCaseSetUpFp testSetUp;
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   167
	TestCaseFp testCase;
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   168
	TestCaseTearDownFp testTearDown;
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   169
 	QuitTestInvironmentFp quitTestEnvironment;
5692
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   170
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   171
 	CountFailedAssertsFp countFailedAsserts;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   172
5692
249e54c47b90 Creating pipeline for test case selection. Work in progress.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5691
diff changeset
   173
	struct TestCaseItem *next;
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   174
} TestCase;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   175
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   176
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   177
/*! 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
   178
TestCaseFp LoadTestCaseFunction(void *suite, char *testName);
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   179
InitTestInvironmentFp LoadInitTestInvironmentFunction(void *suite);
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   180
QuitTestInvironmentFp LoadQuitTestInvironmentFunction(void *suite);
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   181
TestCaseReference **QueryTestCaseReferences(void *library);
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   182
TestCaseSetUpFp LoadTestSetUpFunction(void *suite);
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   183
TestCaseTearDownFp LoadTestTearDownFunction(void *suite);
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   184
CountFailedAssertsFp LoadCountFailedAssertsFunction(void *suite);
5769
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   185
void KillHungTestInChildProcess(int signum);
5796
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   186
void UnloadTestSuites(TestSuiteReference *suites);
5809
adc13772de72 Fixed a bunch of compiler warnings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5808
diff changeset
   187
int FilterTestCase(TestCaseReference *testReference);
adc13772de72 Fixed a bunch of compiler warnings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5808
diff changeset
   188
int HandleChildProcessReturnValue(int stat_lock);
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   189
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   190
5746
b7a0b33b08f4 Fixed the interface between tests suites and logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
   191
/*! Pointers to selected logger implementation */
b7a0b33b08f4 Fixed the interface between tests suites and logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
   192
RunStartedFp RunStarted = NULL;
b7a0b33b08f4 Fixed the interface between tests suites and logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
   193
RunEndedFp RunEnded = NULL;
b7a0b33b08f4 Fixed the interface between tests suites and logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
   194
SuiteStartedFp SuiteStarted = NULL;
b7a0b33b08f4 Fixed the interface between tests suites and logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
   195
SuiteEndedFp SuiteEnded = NULL;
b7a0b33b08f4 Fixed the interface between tests suites and logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
   196
TestStartedFp TestStarted = NULL;
b7a0b33b08f4 Fixed the interface between tests suites and logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
   197
TestEndedFp TestEnded = NULL;
b7a0b33b08f4 Fixed the interface between tests suites and logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
   198
AssertFp Assert = NULL;
b7a0b33b08f4 Fixed the interface between tests suites and logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
   199
AssertWithValuesFp AssertWithValues = NULL;
b7a0b33b08f4 Fixed the interface between tests suites and logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
   200
AssertSummaryFp AssertSummary = NULL;
b7a0b33b08f4 Fixed the interface between tests suites and logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
   201
LogFp Log = NULL;
b7a0b33b08f4 Fixed the interface between tests suites and logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
   202
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   203
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   204
/*!
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   205
 * 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
   206
 * 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
   207
 *
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   208
 * 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
   209
 * 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
   210
 *
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   211
 * 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
   212
 * test will be loaded.
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   213
 *
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   214
 * \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
   215
 * \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
   216
 *
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   217
 * \return Pointer to TestSuiteReference which holds all the info about suites
5796
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   218
 * 		   or NULL on failure
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   219
 */
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   220
TestSuiteReference *
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   221
ScanForTestSuites(char *directoryName, char *extension)
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   222
{
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   223
	typedef struct dirent Entry;
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   224
	TestSuiteReference *suites = NULL;
5796
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   225
	TestSuiteReference *reference = NULL;
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   226
	Entry *entry = NULL;
5796
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   227
	DIR *directory = NULL;
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   228
5796
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   229
	if(directoryName == NULL || extension == NULL ||
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   230
		SDL_strlen(directoryName) == 0 || SDL_strlen(extension) == 0) {
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   231
		return NULL;
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   232
	}
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   233
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   234
	directory = opendir(directoryName);
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   235
	if(!directory) {
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   236
		fprintf(stderr, "Failed to open test suite directory: %s\n", directoryName);
5804
d82711e39c05 Reorganizing the project.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5797
diff changeset
   237
		perror("Error message");
5792
ec908de81ba5 Fixed problem in ScanForTestSuites concerning hidden
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5791
diff changeset
   238
		exit(2);
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   239
	}
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   240
5809
adc13772de72 Fixed a bunch of compiler warnings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5808
diff changeset
   241
	while( (entry = readdir(directory)) ) {
5808
34114b48f322 Fixed 'make distclean'
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5805
diff changeset
   242
		 // discards . and .. and hidden files starting with dot and directories etc.
5805
df2097bab7ee Runner is automatically installed to .
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5804
diff changeset
   243
		if(strlen(entry->d_name) > 2 && entry->d_name[0] != '.' && entry->d_type == DT_REG) {
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   244
			const char *delimiters = ".";
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   245
			char *name = strtok(entry->d_name, delimiters);
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   246
			char *ext = strtok(NULL, delimiters);
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   247
5796
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   248
			if(name == NULL || ext == NULL) {
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   249
				goto error;
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   250
			}
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   251
5827
ef0942587b80 Added --include-dummy option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5826
diff changeset
   252
ef0942587b80 Added --include-dummy option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5826
diff changeset
   253
			int ok = 1; // on default, we want to include all tests
ef0942587b80 Added --include-dummy option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5826
diff changeset
   254
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   255
			// 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
   256
			if(only_selected_suite) {
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   257
				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
   258
			}
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   259
5827
ef0942587b80 Added --include-dummy option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5826
diff changeset
   260
			if(SDL_strncmp(name, DUMMY_TEST_NAME, NAME_BUFFER_SIZE) == 0) {
ef0942587b80 Added --include-dummy option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5826
diff changeset
   261
				if(include_dummy_suite) {
ef0942587b80 Added --include-dummy option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5826
diff changeset
   262
					ok =  1;
ef0942587b80 Added --include-dummy option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5826
diff changeset
   263
				} else {
ef0942587b80 Added --include-dummy option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5826
diff changeset
   264
					ok = 0;
ef0942587b80 Added --include-dummy option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5826
diff changeset
   265
				}
ef0942587b80 Added --include-dummy option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5826
diff changeset
   266
			}
ef0942587b80 Added --include-dummy option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5826
diff changeset
   267
5792
ec908de81ba5 Fixed problem in ScanForTestSuites concerning hidden
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5791
diff changeset
   268
			if(ok && SDL_strncmp(ext, extension, SDL_strlen(extension))  == 0) {
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   269
				// create test suite reference
5796
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   270
				reference = (TestSuiteReference *) SDL_malloc(sizeof(TestSuiteReference));
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   271
				if(reference == NULL) {
5796
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   272
					goto error;
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   273
				}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   274
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   275
				memset(reference, 0, sizeof(TestSuiteReference));
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   276
5796
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   277
				const Uint32 dirSize = SDL_strlen(directoryName);
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   278
				const Uint32 extSize = SDL_strlen(ext);
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   279
				const Uint32 nameSize = SDL_strlen(name) + 1;
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   280
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   281
				// copy the name
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   282
				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
   283
				if(reference->name == NULL) {
5796
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   284
					goto error;
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   285
				}
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   286
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   287
				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
   288
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   289
				// copy the directory path
5795
134c0f7ae826 Changed SetUpLogger based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5794
diff changeset
   290
				const Uint32 dpSize = dirSize + nameSize + 1 + extSize + 1;
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   291
				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
   292
				if(reference->directoryPath == NULL) {
5796
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   293
					goto error;
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   294
				}
5791
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   295
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   296
				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
   297
						directoryName, name, ext);
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   298
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   299
				reference->next = suites;
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   300
				suites = reference;
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   301
			}
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   302
		}
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   303
	}
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   304
5796
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   305
	goto finished;
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   306
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   307
	error:
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   308
	if(reference) {
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   309
		SDL_free(reference->name);
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   310
		SDL_free(reference->directoryPath);
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   311
		SDL_free(reference);
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   312
	}
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   313
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   314
	// Unload all the suites that are loaded thus far
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   315
	UnloadTestSuites(suites);
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   316
	suites = NULL;
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   317
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   318
	finished:
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   319
	if(directory) {
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   320
		closedir(directory);
610df1cc7b4a Fixed ScanForTestSuites function based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5795
diff changeset
   321
	}
5729
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
	return suites;
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   324
}
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
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   327
/*!
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   328
 * 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
   329
 *
5733
9c9eeded847a Fixed doxygen markup error.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   330
 * \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
   331
 *
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   332
 * \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
   333
 */
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   334
void *
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   335
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
   336
{
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   337
	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
   338
	if(library == NULL) {
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   339
		fprintf(stderr, "Loading %s failed\n", suite->name);
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   340
		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
   341
	}
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   342
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   343
	return library;
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   344
}
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   345
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   346
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   347
/*!
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   348
 * Goes through all the given TestSuiteReferences
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   349
 * 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
   350
 * parameter on-the-fly and returns it.
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   351
 *
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   352
 * \param suites Suites that will be loaded
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   353
 *
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   354
 * \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
   355
 */
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   356
TestSuiteReference *
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   357
LoadTestSuites(TestSuiteReference *suites)
5694
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 *reference = NULL;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   360
	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
   361
		reference->library = LoadTestSuite(reference);
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   362
	}
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   363
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   364
	return suites;
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
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
 * Unloads the given TestSuiteReferences. Frees all
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   370
 * the allocated resources including the dynamic libraries.
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
 * \param suites TestSuiteReferences for deallocation process
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   373
 */
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   374
void
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   375
UnloadTestSuites(TestSuiteReference *suites)
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
	TestSuiteReference *ref = suites;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   378
	while(ref) {
5805
df2097bab7ee Runner is automatically installed to .
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5804
diff changeset
   379
		if(ref->name)
df2097bab7ee Runner is automatically installed to .
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5804
diff changeset
   380
			SDL_free(ref->name);
df2097bab7ee Runner is automatically installed to .
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5804
diff changeset
   381
df2097bab7ee Runner is automatically installed to .
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5804
diff changeset
   382
		if(ref->directoryPath)
df2097bab7ee Runner is automatically installed to .
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5804
diff changeset
   383
			SDL_free(ref->directoryPath);
df2097bab7ee Runner is automatically installed to .
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5804
diff changeset
   384
df2097bab7ee Runner is automatically installed to .
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5804
diff changeset
   385
		if(ref->library)
df2097bab7ee Runner is automatically installed to .
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5804
diff changeset
   386
			SDL_UnloadObject(ref->library);
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   387
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   388
		TestSuiteReference *temp = ref->next;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   389
		SDL_free(ref);
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   390
		ref = temp;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   391
	}
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
	suites = NULL;
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
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   396
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   397
/*!
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   398
 * Goes through the previously loaded test suites and
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   399
 * loads test cases from them. Test cases are filtered
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   400
 * during the process. Function will only return the
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   401
 * test cases which aren't filtered out.
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   402
 *
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   403
 * \param suites previously loaded test suites
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   404
 *
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   405
 * \return Test cases that survived filtering process.
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   406
 */
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   407
TestCase *
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   408
LoadTestCases(TestSuiteReference *suites)
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   409
{
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   410
	TestCase *testCases = NULL;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   411
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   412
	TestSuiteReference *suiteReference = NULL;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   413
	for(suiteReference = suites; suiteReference; suiteReference = suiteReference->next) {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   414
		TestCaseReference **tests = QueryTestCaseReferences(suiteReference->library);
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   415
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   416
		TestCaseReference *testReference = NULL;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   417
		int counter = 0;
5792
ec908de81ba5 Fixed problem in ScanForTestSuites concerning hidden
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5791
diff changeset
   418
 		for(testReference = tests[counter]; testReference; testReference = tests[++counter]) {
ec908de81ba5 Fixed problem in ScanForTestSuites concerning hidden
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5791
diff changeset
   419
			//void *suite = suiteReference->library;
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   420
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   421
			// Load test case functions
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   422
			InitTestInvironmentFp initTestEnvironment = LoadInitTestInvironmentFunction(suiteReference->library);
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   423
			QuitTestInvironmentFp quitTestEnvironment = LoadQuitTestInvironmentFunction(suiteReference->library);
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   424
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   425
			TestCaseSetUpFp testSetUp = LoadTestSetUpFunction(suiteReference->library);
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   426
			TestCaseTearDownFp testTearDown = LoadTestTearDownFunction(suiteReference->library);
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   427
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   428
			TestCaseFp testCase = LoadTestCaseFunction(suiteReference->library, testReference->name);
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   429
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   430
			CountFailedAssertsFp countFailedAsserts = LoadCountFailedAssertsFunction(suiteReference->library);
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   431
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   432
			// Do the filtering
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   433
			if(FilterTestCase(testReference)) {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   434
				TestCase *item = SDL_malloc(sizeof(TestCase));
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   435
				memset(item, 0, sizeof(TestCase));
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   436
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   437
				item->initTestEnvironment = initTestEnvironment;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   438
				item->quitTestEnvironment = quitTestEnvironment;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   439
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   440
				item->testSetUp = testSetUp;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   441
				item->testTearDown = testTearDown;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   442
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   443
				item->testCase = testCase;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   444
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   445
				item->countFailedAsserts = countFailedAsserts;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   446
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   447
				// copy suite name
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   448
				int length = SDL_strlen(suiteReference->name) + 1;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   449
				item->suiteName = SDL_malloc(length);
5791
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   450
				if(item->suiteName == NULL) {
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   451
					SDL_free(item);
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   452
					return NULL;
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   453
				}
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   454
				strncpy(item->suiteName, suiteReference->name, length);
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   455
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   456
				// copy test name
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   457
				length = SDL_strlen(testReference->name) + 1;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   458
				item->testName = SDL_malloc(length);
5791
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   459
				if(item->testName == NULL) {
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   460
						SDL_free(item->suiteName);
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   461
						SDL_free(item);
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   462
						return NULL;
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   463
				}
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   464
				strncpy(item->testName, testReference->name, length);
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   465
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   466
				// copy test description
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   467
				length = SDL_strlen(testReference->description) + 1;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   468
				item->description = SDL_malloc(length);
5791
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   469
				if(item->description == NULL) {
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   470
						SDL_free(item->description);
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   471
						SDL_free(item->suiteName);
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   472
						SDL_free(item);
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   473
						return NULL;
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   474
				}
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   475
				strncpy(item->description, testReference->description, length);
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   476
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   477
				item->requirements = testReference->requirements;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   478
				item->timeout = testReference->timeout;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   479
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   480
				// prepend the list
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   481
				item->next = testCases;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   482
				testCases = item;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   483
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   484
				//printf("Added test: %s\n", testReference->name);
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   485
			}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   486
		}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   487
	}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   488
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   489
	return testCases;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   490
}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   491
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   492
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   493
/*!
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   494
 * Unloads the given TestCases. Frees all the resources
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   495
 * allocated for test cases.
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   496
 *
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   497
 * \param testCases Test cases to be deallocated
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   498
 */
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   499
void
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   500
UnloadTestCases(TestCase *testCases)
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   501
{
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   502
	TestCase *ref = testCases;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   503
	while(ref) {
5805
df2097bab7ee Runner is automatically installed to .
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5804
diff changeset
   504
		if(ref->testName)
df2097bab7ee Runner is automatically installed to .
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5804
diff changeset
   505
			SDL_free(ref->testName);
df2097bab7ee Runner is automatically installed to .
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5804
diff changeset
   506
df2097bab7ee Runner is automatically installed to .
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5804
diff changeset
   507
		if(ref->suiteName)
df2097bab7ee Runner is automatically installed to .
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5804
diff changeset
   508
			SDL_free(ref->suiteName);
df2097bab7ee Runner is automatically installed to .
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5804
diff changeset
   509
df2097bab7ee Runner is automatically installed to .
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5804
diff changeset
   510
		if(ref->description)
df2097bab7ee Runner is automatically installed to .
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5804
diff changeset
   511
			SDL_free(ref->description);
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   512
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   513
		TestCase *temp = ref->next;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   514
		SDL_free(ref);
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   515
		ref = temp;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   516
	}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   517
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   518
	testCases = NULL;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   519
}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   520
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   521
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   522
/*!
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   523
 * Filters a test case based on its properties in TestCaseReference and user
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   524
 * preference.
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   525
 *
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   526
 * \return Non-zero means test will be added to execution list, zero means opposite
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   527
 */
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   528
int
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   529
FilterTestCase(TestCaseReference *testReference)
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   530
{
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   531
	int retVal = 1;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   532
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   533
	if(testReference->enabled == TEST_DISABLED) {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   534
		retVal = 0;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   535
	}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   536
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   537
	if(only_selected_test) {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   538
		if(SDL_strncmp(testReference->name, selected_test_name, NAME_BUFFER_SIZE) == 0) {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   539
			retVal = 1;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   540
		} else {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   541
			retVal = 0;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   542
		}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   543
	}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   544
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   545
	if(only_tests_with_string) {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   546
		if(strstr(testReference->name, testcase_name_substring) != NULL) {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   547
			retVal = 1;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   548
		} else {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   549
			retVal = 0;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   550
		}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   551
	}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   552
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   553
	return retVal;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   554
}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   555
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   556
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   557
/*!
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   558
 * 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
   559
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   560
 * \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
   561
 * \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
   562
 */
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   563
TestCaseReference **
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   564
QueryTestCaseReferences(void *library)
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   565
{
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   566
	TestCaseReference **(*suite)(void);
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   567
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   568
	suite = (TestCaseReference **(*)(void)) SDL_LoadFunction(library, "QueryTestSuite");
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   569
	if(suite == NULL) {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   570
		fprintf(stderr, "Loading QueryTestCaseReferences() failed.\n");
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   571
		fprintf(stderr, "%s\n", SDL_GetError());
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   572
	}
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   573
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   574
	TestCaseReference **tests = suite();
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   575
	if(tests == NULL) {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   576
		fprintf(stderr, "Failed to load test references.\n");
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   577
		fprintf(stderr, "%s\n", SDL_GetError());
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   578
	}
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   579
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   580
	return tests;
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   581
}
5662
57fc58008d76 Tiny changes to runner
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5659
diff changeset
   582
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   583
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   584
/*!
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   585
 * Loads test case from a test suite
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   586
 *
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   587
 * \param suite a test suite
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   588
 * \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
   589
 *
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   590
 * \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
   591
 */
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   592
TestCaseFp
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   593
LoadTestCaseFunction(void *suite, char *testName)
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   594
{
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   595
	TestCaseFp test = (TestCaseFp) SDL_LoadFunction(suite, testName);
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   596
	if(test == NULL) {
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   597
		fprintf(stderr, "Loading test failed, tests == NULL\n");
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   598
		fprintf(stderr, "%s\n", SDL_GetError());
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   599
	}
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   600
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   601
	return test;
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   602
}
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   603
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   604
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   605
/*!
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   606
 * Loads function that sets up a fixture for a test case. Note: if there's
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   607
 * no SetUp function present in the suite the function will return NULL.
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   608
 *
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   609
 * \param suite Used test suite
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   610
 *
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   611
 * \return Function pointer to test case's set up function
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   612
 */
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   613
TestCaseSetUpFp
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   614
LoadTestSetUpFunction(void *suite) {
5764
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   615
	return (TestCaseSetUpFp) SDL_LoadFunction(suite, "SetUp");
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   616
}
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   617
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   618
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   619
/*!
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   620
 * Loads function that tears down a fixture for a test case. Note: if there's
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   621
 * no TearDown function present in the suite the function will return NULL.
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   622
 *
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   623
 * \param suite Used test suite
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   624
 *
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   625
 * \return Function pointer to test case's tear down function
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   626
 */
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   627
TestCaseTearDownFp
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   628
LoadTestTearDownFunction(void *suite) {
5764
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   629
	return (TestCaseTearDownFp) SDL_LoadFunction(suite, "TearDown");
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   630
}
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   631
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   632
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   633
/*!
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   634
 * Loads function that initialises the test environment for
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   635
 * a test case in the given suite.
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   636
 *
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   637
 * \param suite Used test suite
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   638
 *
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   639
 * \return Function pointer (InitTestInvironmentFp) which points to loaded init function. NULL if function fails.
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   640
 */
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   641
InitTestInvironmentFp
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   642
LoadInitTestInvironmentFunction(void *suite) {
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   643
	InitTestInvironmentFp testEnvInit = (InitTestInvironmentFp) SDL_LoadFunction(suite, "_InitTestEnvironment");
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   644
	if(testEnvInit == NULL) {
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   645
		fprintf(stderr, "Loading _InitTestInvironment function failed, testEnvInit == NULL\n");
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   646
		fprintf(stderr, "%s\n", SDL_GetError());
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   647
	}
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   648
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   649
	return testEnvInit;
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   650
}
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   651
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   652
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   653
/*!
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   654
 * Loads function that deinitialises the test environment (and returns
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   655
 * the test case's result) created for the test case in the given suite.
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   656
 *
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   657
 * \param suite Used test suite
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   658
 *
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   659
 * \return Function pointer (QuitTestInvironmentFp) which points to loaded init function. NULL if function fails.
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   660
 */
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   661
QuitTestInvironmentFp
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   662
LoadQuitTestInvironmentFunction(void *suite) {
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   663
	QuitTestInvironmentFp testEnvQuit = (QuitTestInvironmentFp) SDL_LoadFunction(suite, "_QuitTestEnvironment");
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   664
	if(testEnvQuit == NULL) {
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   665
		fprintf(stderr, "Loading _QuitTestEnvironment function failed, testEnvQuit == NULL\n");
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   666
		fprintf(stderr, "%s\n", SDL_GetError());
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   667
	}
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   668
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   669
	return testEnvQuit;
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   670
}
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   671
5770
795a59de1ad5 Fixes to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5769
diff changeset
   672
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   673
/*!
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   674
 * Loads function that returns failed assert count in the current
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   675
 * test environment
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   676
 *
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   677
 * \param suite Used test suite
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   678
 *
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   679
 * \return Function pointer to _CountFailedAsserts function
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   680
 */
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   681
CountFailedAssertsFp
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   682
LoadCountFailedAssertsFunction(void *suite) {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   683
	CountFailedAssertsFp countFailedAssert = (CountFailedAssertsFp) SDL_LoadFunction(suite, "_CountFailedAsserts");
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   684
	if(countFailedAssert == NULL) {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   685
		fprintf(stderr, "Loading _CountFailedAsserts function failed, countFailedAssert == NULL\n");
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   686
		fprintf(stderr, "%s\n", SDL_GetError());
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   687
	}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   688
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   689
	return countFailedAssert;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   690
}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   691
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   692
5764
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   693
/*!
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   694
 * Set timeout for test.
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   695
 *
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   696
 * \param timeout Timeout interval in seconds!
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   697
 * \param callback Function that will be called after timeout has elapsed
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   698
 */
5775
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   699
void
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   700
SetTestTimeout(int timeout, void (*callback)(int))
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   701
{
5769
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   702
	if(callback == NULL) {
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   703
		fprintf(stderr, "Error: timeout callback can't be NULL");
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   704
	}
5775
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   705
5769
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   706
	if(timeout < 0) {
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   707
		fprintf(stderr, "Error: timeout value must be bigger than zero.");
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   708
	}
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   709
5775
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   710
	int tm = (timeout > universal_timeout ? timeout : universal_timeout);
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   711
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   712
#if 1
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   713
	/* Init SDL timer if not initialized before */
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   714
	if(SDL_WasInit(SDL_INIT_TIMER) == 0) {
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   715
		if(SDL_InitSubSystem(SDL_INIT_TIMER)) {
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   716
			fprintf(stderr, "Error: Failed to init timer subsystem");
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   717
			fprintf(stderr, "%s\n", SDL_GetError());
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   718
		}
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   719
	}
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   720
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   721
	/* Note:
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   722
	 * SDL_Init(SDL_INIT_TIMER) should be successfully called before using this
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   723
	 */
5775
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   724
	int timeoutInMilliseconds = tm * 1000;
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   725
5809
adc13772de72 Fixed a bunch of compiler warnings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5808
diff changeset
   726
	SDL_TimerID timerID = SDL_AddTimer(timeoutInMilliseconds, (SDL_TimerCallback) callback, 0x0);
adc13772de72 Fixed a bunch of compiler warnings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5808
diff changeset
   727
	if(timerID == 0) {
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   728
		fprintf(stderr, "Error: Creation of SDL timer failed.\n");
5775
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   729
		fprintf(stderr, "Error: %s\n", SDL_GetError());
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   730
	}
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   731
#else
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   732
	signal(SIGALRM, callback);
5769
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   733
	alarm((unsigned int) tm);
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   734
#endif
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   735
}
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   736
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   737
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   738
/*!
5764
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   739
 * Kills test that hungs. Test hungs when its execution
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   740
 * takes longer than timeout specified for it.
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   741
 *
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   742
 * When test will be killed SIG_ALRM will be triggered and
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   743
 * it'll call this function which kills the test process.
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   744
 *
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   745
 * Note: if runner is executed with --in-proc then hung tests
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   746
 * can't be killed
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   747
 *
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   748
 * \param signum
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   749
 */
5769
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   750
void
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   751
KillHungTestInChildProcess(int signum)
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   752
{
5809
adc13772de72 Fixed a bunch of compiler warnings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5808
diff changeset
   753
	(void)signum; // keeps the compiler silent about unused variable
adc13772de72 Fixed a bunch of compiler warnings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5808
diff changeset
   754
5764
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   755
	exit(TEST_RESULT_KILLED);
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   756
}
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   757
5773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   758
/*!
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   759
 * Checks if given test case can be executed on the current platform.
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   760
 *
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   761
 * \param testCase Test to be checked
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   762
 * \returns 1 if test is runnable, otherwise 0. On error returns -1
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   763
 */
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   764
int
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   765
CheckTestRequirements(TestCase *testCase)
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   766
{
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   767
	int retVal = 1;
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   768
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   769
	if(testCase == NULL) {
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   770
		fprintf(stderr, "TestCase parameter can't be NULL");
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   771
		return -1;
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   772
	}
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   774
	if(testCase->requirements & TEST_REQUIRES_AUDIO) {
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   775
		retVal = PlatformSupportsAudio();
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   776
	}
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   777
5821
717e4cb840dd Ported rwops test suite.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5811
diff changeset
   778
	if(testCase->requirements & TEST_REQUIRES_STDIO) {
717e4cb840dd Ported rwops test suite.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5811
diff changeset
   779
		retVal = PlatformSupportsStdio();
717e4cb840dd Ported rwops test suite.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5811
diff changeset
   780
	}
717e4cb840dd Ported rwops test suite.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5811
diff changeset
   781
717e4cb840dd Ported rwops test suite.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5811
diff changeset
   782
5773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   783
	return retVal;
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   784
}
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   785
5764
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   786
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   787
/*
5759
59615ddece72 Fixed AssertEquals.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5758
diff changeset
   788
 * Execute a test. Loads the test, executes it and
59615ddece72 Fixed AssertEquals.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5758
diff changeset
   789
 * returns the tests return value to the caller.
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   790
 *
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   791
 * \param testItem Test to be executed
5759
59615ddece72 Fixed AssertEquals.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5758
diff changeset
   792
 * \param test result
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   793
 */
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   794
int
5797
4936c840d128 Fixing execution key generation based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5796
diff changeset
   795
RunTest(TestCase *testCase, Uint64 execKey)
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   796
{
5780
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   797
	if(!testCase) {
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   798
		return -1;
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   799
	}
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   800
5773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   801
	int runnable = CheckTestRequirements(testCase);
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   802
	if(runnable != 1) {
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   803
		return TEST_RESULT_SKIPPED;
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   804
	}
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   805
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   806
	if(testCase->timeout > 0 || universal_timeout > 0) {
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   807
		if(execute_inproc) {
5770
795a59de1ad5 Fixes to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5769
diff changeset
   808
			Log(time(0), "Test asked for timeout which is not supported.");
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   809
		}
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   810
		else {
5773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   811
			SetTestTimeout(testCase->timeout, KillHungTestInChildProcess);
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   812
		}
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   813
	}
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   814
5797
4936c840d128 Fixing execution key generation based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5796
diff changeset
   815
	testCase->initTestEnvironment(execKey);
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   816
5773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   817
	if(testCase->testSetUp) {
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   818
		testCase->testSetUp(0x0);
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   819
	}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   820
5773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   821
	int cntFailedAsserts = testCase->countFailedAsserts();
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   822
	if(cntFailedAsserts != 0) {
5758
e497802a71b4 Harness kills hung tests (won't work with --in-proc option).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5755
diff changeset
   823
		return TEST_RESULT_SETUP_FAILURE;
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   824
	}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   825
5773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   826
	testCase->testCase(0x0);
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   827
5773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   828
	if(testCase->testTearDown) {
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   829
		testCase->testTearDown(0x0);
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   830
	}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   831
5773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   832
	return testCase->quitTestEnvironment();
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   833
}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   834
5758
e497802a71b4 Harness kills hung tests (won't work with --in-proc option).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5755
diff changeset
   835
e497802a71b4 Harness kills hung tests (won't work with --in-proc option).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5755
diff changeset
   836
/*!
5759
59615ddece72 Fixed AssertEquals.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5758
diff changeset
   837
 * Sets up a test case. Decideds wheter the test will
59615ddece72 Fixed AssertEquals.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5758
diff changeset
   838
 * be executed in-proc or out-of-proc.
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   839
 *
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   840
 * \param testItem The test case that will be executed
5826
ac41301850c1 Fixed the doxygen markup.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5821
diff changeset
   841
 * \param execKey Execution key for the test case
ac41301850c1 Fixed the doxygen markup.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5821
diff changeset
   842
 *
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   843
 * \return The return value of the test. Zero means success, non-zero failure.
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   844
 */
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   845
int
5797
4936c840d128 Fixing execution key generation based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5796
diff changeset
   846
ExecuteTest(TestCase *testItem, Uint64 execKey) {
5758
e497802a71b4 Harness kills hung tests (won't work with --in-proc option).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5755
diff changeset
   847
	int retVal = -1;
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   848
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   849
	if(execute_inproc) {
5780
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   850
		retVal = RunTest(testItem, execKey);
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   851
	} else {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   852
		int childpid = fork();
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   853
		if(childpid == 0) {
5780
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   854
			exit(RunTest(testItem, execKey));
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   855
		} else {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   856
			int stat_lock = -1;
5809
adc13772de72 Fixed a bunch of compiler warnings.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5808
diff changeset
   857
			wait(&stat_lock);
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   858
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   859
			retVal = HandleChildProcessReturnValue(stat_lock);
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   860
		}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   861
	}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   862
5780
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   863
	if(retVal == TEST_RESULT_SKIPPED) {
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   864
		testSkipCount++;
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   865
		totalTestSkipCount++;
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   866
	}
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   867
	else if(retVal) {
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   868
		totalTestFailureCount++;
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   869
		testFailureCount++;
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   870
	}
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   871
	else {
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   872
		totalTestPassCount++;
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   873
		testPassCount++;
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   874
	}
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   875
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   876
	// return the value for logger
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   877
	return retVal;
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   878
}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   879
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   880
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   881
/*!
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   882
 * 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
   883
 * 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
   884
 * 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
   885
 * if child was aborted by a signela.
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   886
 *
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   887
 * \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
   888
 *
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   889
 * \return 0 if test case succeeded, 1 otherwise
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   890
 */
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   891
int
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   892
HandleChildProcessReturnValue(int stat_lock)
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   893
{
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   894
	int returnValue = -1;
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   895
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   896
	if(WIFEXITED(stat_lock)) {
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   897
		returnValue = WEXITSTATUS(stat_lock);
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   898
	} else if(WIFSIGNALED(stat_lock)) {
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   899
		int signal = WTERMSIG(stat_lock);
5751
cbb921210496 Bunch of little fixes.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5746
diff changeset
   900
		// \todo add this to logger (add signal number)
5770
795a59de1ad5 Fixes to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5769
diff changeset
   901
		Log(time(0), "FAILURE: test was aborted due to  %d\n", signal);
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   902
		returnValue = 1;
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   903
	}
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   904
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   905
	return returnValue;
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   906
}
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   907
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   908
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   909
/*!
5794
e39e9c62c671 Fixed harness seed generation based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5793
diff changeset
   910
 * Generates a random run seed for the harness. Seed
e39e9c62c671 Fixed harness seed generation based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5793
diff changeset
   911
 * can contain characters 0-9A-Z
5786
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   912
 *
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   913
 * \param length The length of the generated seed
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   914
 *
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   915
 * \returns The generated seed
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   916
 */
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   917
char *
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   918
GenerateRunSeed(const int length)
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   919
{
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   920
	if(length <= 0) {
5787
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   921
		fprintf(stderr, "Error: length of the harness seed can't be less than zero\n");
5786
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   922
		return NULL;
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   923
	}
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   924
5794
e39e9c62c671 Fixed harness seed generation based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5793
diff changeset
   925
	char *seed = SDL_malloc((length + 1) * sizeof(char));
5786
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   926
	if(seed == NULL) {
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   927
		fprintf(stderr, "Error: malloc for run seed failed\n");
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   928
		return NULL;
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   929
	}
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   930
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   931
	RND_CTX randomContext;
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   932
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   933
	utl_randomInitTime(&randomContext);
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   934
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   935
	int counter = 0;
5794
e39e9c62c671 Fixed harness seed generation based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5793
diff changeset
   936
	for( ; counter < length - 1; ++counter) {
5786
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   937
		int number = abs(utl_random(&randomContext));
5794
e39e9c62c671 Fixed harness seed generation based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5793
diff changeset
   938
		char ch = (char) (number % (91 - 48)) + 48;
5788
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   939
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   940
		if(ch >= 58 && ch <= 64) {
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   941
			ch = 65;
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   942
		}
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   943
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   944
		seed[counter] = ch;
5786
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   945
	}
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   946
5788
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   947
	seed[counter] = '\0';
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   948
5786
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   949
	return seed;
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   950
}
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   951
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   952
/*!
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   953
 * Sets up the logger.
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   954
 *
5785
7fc252ce5d1d Added simple logging levels to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5784
diff changeset
   955
 * \return Logger data structure (that needs be deallocated)
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   956
 */
5794
e39e9c62c671 Fixed harness seed generation based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5793
diff changeset
   957
LoggerData *
5795
134c0f7ae826 Changed SetUpLogger based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5794
diff changeset
   958
SetUpLogger(const int log_stdout_enabled, const int xml_enabled, const int xsl_enabled,
134c0f7ae826 Changed SetUpLogger based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5794
diff changeset
   959
			const int custom_xsl_enabled, const char *defaultXslSheet)
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   960
{
5794
e39e9c62c671 Fixed harness seed generation based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5793
diff changeset
   961
	LoggerData *loggerData = SDL_malloc(sizeof(LoggerData));
5785
7fc252ce5d1d Added simple logging levels to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5784
diff changeset
   962
	if(loggerData == NULL) {
7fc252ce5d1d Added simple logging levels to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5784
diff changeset
   963
		fprintf(stderr, "Error: Logger data structure not allocated.");
7fc252ce5d1d Added simple logging levels to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5784
diff changeset
   964
		return NULL;
7fc252ce5d1d Added simple logging levels to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5784
diff changeset
   965
	}
5788
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   966
	memset(loggerData, 0, sizeof(LoggerData));
5785
7fc252ce5d1d Added simple logging levels to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5784
diff changeset
   967
5795
134c0f7ae826 Changed SetUpLogger based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5794
diff changeset
   968
	loggerData->level = (enable_verbose_logger ? LOGGER_VERBOSE : LOGGER_TERSE);
5785
7fc252ce5d1d Added simple logging levels to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5784
diff changeset
   969
5788
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   970
	if(log_stdout_enabled == 1) {
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   971
		loggerData->stdoutEnabled = 1;
5787
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   972
		loggerData->filename = NULL;
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   973
	} else {
5794
e39e9c62c671 Fixed harness seed generation based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5793
diff changeset
   974
		loggerData->stdoutEnabled = 0;
e39e9c62c671 Fixed harness seed generation based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5793
diff changeset
   975
e39e9c62c671 Fixed harness seed generation based on CR.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5793
diff changeset
   976
		const char *extension = (xml_enabled ? "xml" : "log");
5787
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   977
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   978
		// create directory (if it doesn't exist yet)
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   979
		unsigned int mode = S_IRWXU | S_IRGRP | S_ISUID;
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   980
		mkdir(log_directory, mode);
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset