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