test/test-automation/runner.c
author Markus Kauppila <markus.kauppila@gmail.com>
Fri, 29 Jul 2011 19:52:16 +0300
changeset 5793 e4b84f743a7e
parent 5792 ec908de81ba5
child 5794 e39e9c62c671
permissions -rw-r--r--
Fixed type from usage info.
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");
5792
ec908de81ba5 Fixed problem in ScanForTestSuites concerning hidden
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5791
diff changeset
   222
		exit(2);
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)) {
5792
ec908de81ba5 Fixed problem in ScanForTestSuites concerning hidden
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5791
diff changeset
   226
		 // discards . and .. and hidden files starting with .
ec908de81ba5 Fixed problem in ScanForTestSuites concerning hidden
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5791
diff changeset
   227
		if(strlen(entry->d_name) > 2 && entry->d_name[0] != '.') {
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   228
			const char *delimiters = ".";
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   229
			char *name = strtok(entry->d_name, delimiters);
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   230
			char *ext = strtok(NULL, delimiters);
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   231
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   232
			// 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
   233
			int ok = 1;
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   234
			if(only_selected_suite) {
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   235
				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
   236
			}
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   237
5792
ec908de81ba5 Fixed problem in ScanForTestSuites concerning hidden
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5791
diff changeset
   238
			if(ok && SDL_strncmp(ext, extension, SDL_strlen(extension))  == 0) {
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   239
				// create test suite reference
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   240
				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
   241
				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
   242
					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
   243
				}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   244
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   245
				memset(reference, 0, sizeof(TestSuiteReference));
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   246
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   247
				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
   248
				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
   249
				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
   250
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   251
				// copy the name
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   252
				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
   253
				if(reference->name == NULL) {
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   254
					SDL_free(reference);
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   255
					return NULL;
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   256
				}
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   257
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   258
				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
   259
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   260
				// copy the directory path
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   261
				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
   262
				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
   263
				if(reference->directoryPath == NULL) {
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   264
					SDL_free(reference->name);
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   265
					SDL_free(reference);
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   266
					return NULL;
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   267
				}
5791
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   268
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   269
				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
   270
						directoryName, name, ext);
5729
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   271
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   272
				reference->next = suites;
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   273
				suites = reference;
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
	}
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
	closedir(directory);
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
	return suites;
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
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   283
27be98c43bbc Removed directory from test suite names.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5728
diff changeset
   284
/*!
5676
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   285
 * 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
   286
 *
5733
9c9eeded847a Fixed doxygen markup error.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5731
diff changeset
   287
 * \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
   288
 *
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   289
 * \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
   290
 */
02a0f7889834 Refactoring runner.c. Added --help/-h command line option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5675
diff changeset
   291
void *
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   292
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
   293
{
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   294
	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
   295
	if(library == NULL) {
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   296
		fprintf(stderr, "Loading %s failed\n", suite->name);
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   297
		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
   298
	}
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   299
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   300
	return library;
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   301
}
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   302
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   303
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   304
/*!
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   305
 * Goes through all the given TestSuiteReferences
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   306
 * 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
   307
 * parameter on-the-fly and returns it.
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
 * \param suites Suites that will be loaded
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
 * \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
   312
 */
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   313
TestSuiteReference *
5730
5c094958a62f Separated test suite name from its directory path. Fixes
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5729
diff changeset
   314
LoadTestSuites(TestSuiteReference *suites)
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   315
{
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   316
	TestSuiteReference *reference = NULL;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   317
	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
   318
		reference->library = LoadTestSuite(reference);
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   319
	}
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
	return suites;
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
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   325
/*!
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   326
 * Unloads the given TestSuiteReferences. Frees all
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   327
 * the allocated resources including the dynamic libraries.
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
 * \param suites TestSuiteReferences for deallocation process
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   330
 */
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   331
void
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   332
UnloadTestSuites(TestSuiteReference *suites)
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   333
{
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   334
	TestSuiteReference *ref = suites;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   335
	while(ref) {
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   336
		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
   337
		SDL_free(ref->directoryPath);
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   338
		SDL_UnloadObject(ref->library);
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   339
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   340
		TestSuiteReference *temp = ref->next;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   341
		SDL_free(ref);
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   342
		ref = temp;
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   343
	}
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
	suites = NULL;
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
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   348
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   349
/*!
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   350
 * 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
   351
 * 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
   352
 * 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
   353
 * 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
   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
 * \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
   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
 * \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
   358
 */
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   359
TestCase *
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   360
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
   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
	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
   363
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   364
	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
   365
	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
   366
		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
   367
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   368
		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
   369
		int counter = 0;
5792
ec908de81ba5 Fixed problem in ScanForTestSuites concerning hidden
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5791
diff changeset
   370
 		for(testReference = tests[counter]; testReference; testReference = tests[++counter]) {
ec908de81ba5 Fixed problem in ScanForTestSuites concerning hidden
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5791
diff changeset
   371
			//void *suite = suiteReference->library;
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   372
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   373
			// 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
   374
			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
   375
			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
   376
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   377
			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
   378
			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
   379
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   380
			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
   381
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   382
			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
   383
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   384
			// 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
   385
			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
   386
				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
   387
				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
   388
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->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
   390
				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
   391
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->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
   393
				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
   394
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   395
				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
   396
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   397
				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
   398
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   399
				// 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
   400
				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
   401
				item->suiteName = SDL_malloc(length);
5791
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   402
				if(item->suiteName == NULL) {
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   403
					SDL_free(item);
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   404
					return NULL;
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   405
				}
5755
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->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
   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 name
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->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
   410
				item->testName = SDL_malloc(length);
5791
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   411
				if(item->testName == NULL) {
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   412
						SDL_free(item->suiteName);
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   413
						SDL_free(item);
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   414
						return NULL;
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   415
				}
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   416
				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
   417
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   418
				// 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
   419
				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
   420
				item->description = SDL_malloc(length);
5791
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   421
				if(item->description == NULL) {
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   422
						SDL_free(item->description);
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   423
						SDL_free(item->suiteName);
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   424
						SDL_free(item);
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   425
						return NULL;
a4e354dfcbfa Fixed potential memory leak from test case loading.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5790
diff changeset
   426
				}
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   427
				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
   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
				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
   430
				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
   431
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   432
				// 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
   433
				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
   434
				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
   435
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   436
				//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
   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
		}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   439
	}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   440
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   441
	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
   442
}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   443
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   444
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   445
/*!
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   446
 * 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
   447
 * 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
   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
 * \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
   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
void
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   452
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
   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
	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
   455
	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
   456
		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
   457
		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
   458
		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
   459
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   460
		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
   461
		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
   462
		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
   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
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   465
	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
   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
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   469
/*!
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   470
 * 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
   471
 * preference.
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   472
 *
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   473
 * \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
   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
int
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   476
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
   477
{
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   478
	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
   479
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   480
	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
   481
		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
   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
	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
   485
		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
   486
			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
   487
		} else {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   488
			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
   489
		}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   490
	}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   491
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   492
	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
   493
		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
   494
			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
   495
		} else {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   496
			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
   497
		}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   498
	}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   499
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   500
	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
   501
}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   502
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   503
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   504
/*!
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   505
 * 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
   506
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   507
 * \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
   508
 * \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
   509
 */
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   510
TestCaseReference **
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   511
QueryTestCaseReferences(void *library)
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   512
{
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   513
	TestCaseReference **(*suite)(void);
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   514
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   515
	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
   516
	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
   517
		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
   518
		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
   519
	}
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   520
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   521
	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
   522
	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
   523
		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
   524
		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
   525
	}
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   526
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   527
	return tests;
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   528
}
5662
57fc58008d76 Tiny changes to runner
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5659
diff changeset
   529
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   530
5672
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
 * Loads test case from a test suite
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   533
 *
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   534
 * \param suite a test suite
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   535
 * \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
   536
 *
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   537
 * \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
   538
 */
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   539
TestCaseFp
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   540
LoadTestCaseFunction(void *suite, char *testName)
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   541
{
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   542
	TestCaseFp test = (TestCaseFp) SDL_LoadFunction(suite, testName);
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   543
	if(test == NULL) {
5675
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   544
		fprintf(stderr, "Loading test failed, tests == NULL\n");
8513baf78c95 Fixes to doxygen comments.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5674
diff changeset
   545
		fprintf(stderr, "%s\n", SDL_GetError());
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   546
	}
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   547
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   548
	return test;
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   549
}
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   550
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   551
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   552
/*!
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   553
 * 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
   554
 * 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
   555
 *
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   556
 * \param suite Used test suite
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   557
 *
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   558
 * \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
   559
 */
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   560
TestCaseSetUpFp
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   561
LoadTestSetUpFunction(void *suite) {
5764
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   562
	return (TestCaseSetUpFp) SDL_LoadFunction(suite, "SetUp");
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   563
}
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   564
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   565
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   566
/*!
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   567
 * 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
   568
 * 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
   569
 *
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   570
 * \param suite Used test suite
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   571
 *
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   572
 * \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
   573
 */
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   574
TestCaseTearDownFp
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   575
LoadTestTearDownFunction(void *suite) {
5764
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   576
	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
   577
}
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   578
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   579
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   580
/*!
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   581
 * 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
   582
 * 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
   583
 *
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   584
 * \param suite Used test suite
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   585
 *
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   586
 * \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
   587
 */
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   588
InitTestInvironmentFp
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   589
LoadInitTestInvironmentFunction(void *suite) {
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   590
	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
   591
	if(testEnvInit == NULL) {
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   592
		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
   593
		fprintf(stderr, "%s\n", SDL_GetError());
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   594
	}
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   595
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   596
	return testEnvInit;
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   597
}
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
/*!
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   601
 * 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
   602
 * 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
   603
 *
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   604
 * \param suite Used test suite
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   605
 *
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   606
 * \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
   607
 */
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   608
QuitTestInvironmentFp
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   609
LoadQuitTestInvironmentFunction(void *suite) {
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   610
	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
   611
	if(testEnvQuit == NULL) {
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   612
		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
   613
		fprintf(stderr, "%s\n", SDL_GetError());
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   614
	}
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   615
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   616
	return testEnvQuit;
5678
50401a6c3c95 Refactoring the TestCaseInit and TestCaseQuit functions
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5677
diff changeset
   617
}
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   618
5770
795a59de1ad5 Fixes to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5769
diff changeset
   619
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   620
/*!
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   621
 * 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
   622
 * 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
   623
 *
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   624
 * \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
   625
 *
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   626
 * \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
   627
 */
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   628
CountFailedAssertsFp
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   629
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
   630
	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
   631
	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
   632
		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
   633
		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
   634
	}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   635
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   636
	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
   637
}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   638
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   639
5764
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   640
/*!
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   641
 * Set timeout for test.
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   642
 *
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   643
 * \param timeout Timeout interval in seconds!
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   644
 * \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
   645
 */
5775
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   646
void
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   647
SetTestTimeout(int timeout, void (*callback)(int))
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   648
{
5769
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   649
	if(callback == NULL) {
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   650
		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
   651
	}
5775
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   652
5769
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   653
	if(timeout < 0) {
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   654
		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
   655
	}
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   656
5775
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   657
	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
   658
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   659
#if 1
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   660
	/* 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
   661
	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
   662
		if(SDL_InitSubSystem(SDL_INIT_TIMER)) {
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   663
			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
   664
			fprintf(stderr, "%s\n", SDL_GetError());
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   665
		}
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   666
	}
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   667
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   668
	/* Note:
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   669
	 * 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
   670
	 */
5775
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   671
	int timeoutInMilliseconds = tm * 1000;
61b87cd64b4d Using SDL timer to kill hung tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5773
diff changeset
   672
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   673
	SDL_TimerID timerID = SDL_AddTimer(timeoutInMilliseconds, callback, 0x0);
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   674
	if(timerID == NULL) {
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   675
		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
   676
		fprintf(stderr, "Error: %s\n", SDL_GetError());
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   677
	}
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   678
#else
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   679
	signal(SIGALRM, callback);
5769
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   680
	alarm((unsigned int) tm);
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   681
#endif
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   682
}
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   683
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   684
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   685
/*!
5764
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   686
 * 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
   687
 * 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
   688
 *
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   689
 * 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
   690
 * 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
   691
 *
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   692
 * 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
   693
 * can't be killed
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   694
 *
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   695
 * \param signum
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   696
 */
5769
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   697
void
8f51d6a55006 Added --timeout VALUE command option.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5768
diff changeset
   698
KillHungTestInChildProcess(int signum)
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   699
{
5764
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   700
	exit(TEST_RESULT_KILLED);
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   701
}
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   702
5773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   703
/*!
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   704
 * 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
   705
 *
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   706
 * \param testCase Test to be checked
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   707
 * \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
   708
 */
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   709
int
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   710
CheckTestRequirements(TestCase *testCase)
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   711
{
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   712
	int retVal = 1;
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   713
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   714
	if(testCase == NULL) {
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   715
		fprintf(stderr, "TestCase parameter can't be NULL");
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   716
		return -1;
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   717
	}
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   718
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   719
	if(testCase->requirements & TEST_REQUIRES_AUDIO) {
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   720
		retVal = PlatformSupportsAudio();
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   721
	}
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   722
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   723
	return retVal;
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   724
}
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   725
5764
5cf913feab69 Fixed logging noise coming from unimplemented optional test
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5759
diff changeset
   726
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   727
/*
5759
59615ddece72 Fixed AssertEquals.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5758
diff changeset
   728
 * Execute a test. Loads the test, executes it and
59615ddece72 Fixed AssertEquals.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5758
diff changeset
   729
 * 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
   730
 *
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   731
 * \param testItem Test to be executed
5759
59615ddece72 Fixed AssertEquals.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5758
diff changeset
   732
 * \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
   733
 */
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   734
int
5789
d2123992108f Fixed an issue with fuzzing seeds.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5788
diff changeset
   735
RunTest(TestCase *testCase, int execKey)
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   736
{
5780
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   737
	if(!testCase) {
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   738
		return -1;
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   739
	}
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   740
5773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   741
	int runnable = CheckTestRequirements(testCase);
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   742
	if(runnable != 1) {
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   743
		return TEST_RESULT_SKIPPED;
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   744
	}
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   745
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   746
	if(testCase->timeout > 0 || universal_timeout > 0) {
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   747
		if(execute_inproc) {
5770
795a59de1ad5 Fixes to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5769
diff changeset
   748
			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
   749
		}
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   750
		else {
5773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   751
			SetTestTimeout(testCase->timeout, KillHungTestInChildProcess);
5768
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   752
		}
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   753
	}
40d331dc9c9e Refactored a bit.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5767
diff changeset
   754
5773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   755
	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
   756
5773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   757
	if(testCase->testSetUp) {
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   758
		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
   759
	}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   760
5773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   761
	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
   762
	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
   763
		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
   764
	}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   765
5773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   766
	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
   767
5773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   768
	if(testCase->testTearDown) {
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   769
		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
   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
5773
a610795fd8fe Refined test skipping.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5772
diff changeset
   772
	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
   773
}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   774
5758
e497802a71b4 Harness kills hung tests (won't work with --in-proc option).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5755
diff changeset
   775
e497802a71b4 Harness kills hung tests (won't work with --in-proc option).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5755
diff changeset
   776
/*!
5759
59615ddece72 Fixed AssertEquals.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5758
diff changeset
   777
 * Sets up a test case. Decideds wheter the test will
59615ddece72 Fixed AssertEquals.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5758
diff changeset
   778
 * 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
   779
 *
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   780
 * \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
   781
 * \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
   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
int
5789
d2123992108f Fixed an issue with fuzzing seeds.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5788
diff changeset
   784
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
   785
	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
   786
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   787
	if(execute_inproc) {
5780
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   788
		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
   789
	} else {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   790
		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
   791
		if(childpid == 0) {
5780
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   792
			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
   793
		} else {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   794
			int 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
   795
			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
   796
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   797
			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
   798
		}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   799
	}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   800
5780
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   801
	if(retVal == TEST_RESULT_SKIPPED) {
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   802
		testSkipCount++;
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   803
		totalTestSkipCount++;
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   804
	}
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   805
	else if(retVal) {
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   806
		totalTestFailureCount++;
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   807
		testFailureCount++;
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   808
	}
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   809
	else {
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   810
		totalTestPassCount++;
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   811
		testPassCount++;
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   812
	}
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   813
6d294a397a27 Adding elementary support for fuzzing.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5775
diff changeset
   814
	// 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
   815
	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
   816
}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   817
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   818
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   819
/*!
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   820
 * 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
   821
 * 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
   822
 * 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
   823
 * if child was aborted by a signela.
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   824
 *
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   825
 * \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
   826
 *
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   827
 * \return 0 if test case succeeded, 1 otherwise
5671
5b0e288921eb Added doxygen-compatible comments
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5670
diff changeset
   828
 */
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   829
int
5694
2fc30d9b1002 Added comments and did some cleaning.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5693
diff changeset
   830
HandleChildProcessReturnValue(int stat_lock)
5673
07b920bcff70 Fixed doxygen warnings
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5672
diff changeset
   831
{
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   832
	int returnValue = -1;
5659
37e7b3b4b5e3 Bootstrapping build process using proof-of-concept test runner.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   833
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   834
	if(WIFEXITED(stat_lock)) {
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   835
		returnValue = WEXITSTATUS(stat_lock);
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   836
	} else if(WIFSIGNALED(stat_lock)) {
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   837
		int signal = WTERMSIG(stat_lock);
5751
cbb921210496 Bunch of little fixes.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5746
diff changeset
   838
		// \todo add this to logger (add signal number)
5770
795a59de1ad5 Fixes to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5769
diff changeset
   839
		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
   840
		returnValue = 1;
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   841
	}
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   842
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   843
	return returnValue;
5667
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   844
}
4c0d0d32414c Refactoring the massive main() to smaller functions.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5666
diff changeset
   845
5682
a04cb565aed2 Possible to execute only selected tests or suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5681
diff changeset
   846
5672
d2df9dbce0ea Refactoring the code (runner.c).
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5671
diff changeset
   847
/*!
5786
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   848
 * Generates a random run seed for the harness.
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   849
 *
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   850
 * \param length The length of the generated seed
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
 * \returns The generated seed
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
char *
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   855
GenerateRunSeed(const int length)
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   856
{
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   857
	if(length <= 0) {
5787
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   858
		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
   859
		return NULL;
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   860
	}
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   861
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   862
	char *seed = SDL_malloc(length * sizeof(8));
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   863
	if(seed == NULL) {
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   864
		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
   865
		return NULL;
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   866
	}
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   867
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   868
	RND_CTX randomContext;
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   869
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   870
	utl_randomInitTime(&randomContext);
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   871
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   872
	int counter = 0;
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   873
	for( ; counter < length; ++counter) {
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   874
		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
   875
		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
   876
5792
ec908de81ba5 Fixed problem in ScanForTestSuites concerning hidden
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5791
diff changeset
   877
		// Skip all the special characters so the run seed
5788
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   878
		// 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
   879
		// 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
   880
		if(ch >= 58 && ch <= 64) {
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   881
			ch = 65;
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   882
		}
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   883
		if(ch >= 91 && ch <= 96) {
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   884
			ch = 97;
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   885
		}
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   886
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   887
		seed[counter] = ch;
5786
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   888
	}
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   889
5788
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   890
	seed[counter] = '\0';
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   891
5786
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   892
	return seed;
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   893
}
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   894
b6df0fc13504 Added randomly generated harness seed.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5785
diff changeset
   895
/*!
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   896
 * Sets up the logger.
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   897
 *
5785
7fc252ce5d1d Added simple logging levels to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5784
diff changeset
   898
 * \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
   899
 */
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   900
void *
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   901
SetUpLogger()
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   902
{
5785
7fc252ce5d1d Added simple logging levels to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5784
diff changeset
   903
	LoggerData *loggerData = SDL_malloc(sizeof(loggerData));
7fc252ce5d1d Added simple logging levels to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5784
diff changeset
   904
	if(loggerData == NULL) {
7fc252ce5d1d Added simple logging levels to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5784
diff changeset
   905
		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
   906
		return NULL;
7fc252ce5d1d Added simple logging levels to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5784
diff changeset
   907
	}
5788
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   908
	memset(loggerData, 0, sizeof(LoggerData));
5785
7fc252ce5d1d Added simple logging levels to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5784
diff changeset
   909
7fc252ce5d1d Added simple logging levels to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5784
diff changeset
   910
	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
   911
5788
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   912
	if(log_stdout_enabled == 1) {
eeb5431a8cbf Made run seed more file name friendly.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5787
diff changeset
   913
		loggerData->stdoutEnabled = 1;
5787
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   914
		loggerData->filename = NULL;
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   915
	} else {
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   916
		const char *extension = (xml_enabled ? "xml": "log");
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   917
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   918
		/* Combine and create directory for log file */
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   919
		// log_directory + log_basename + seed + . + type
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   920
		const int directoryLength = SDL_strlen(log_directory);
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   921
		const int basenameLength = SDL_strlen(log_basename);
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   922
		const int seedLength = SDL_strlen(runSeed);
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   923
		const int extensionLength = SDL_strlen(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
		// 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
   926
		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
   927
		mkdir(log_directory, mode);
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   928
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   929
		// 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
   930
		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
   931
		char *filename = SDL_malloc(length);
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   932
		if(filename == NULL) {
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   933
			SDL_free(loggerData);
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   934
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   935
			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
   936
			return NULL;
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   937
		}
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   938
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   939
		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
   940
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   941
		loggerData->filename = filename;
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   942
	}
46cddba50600 Logger logs to file on default.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5786
diff changeset
   943
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   944
	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
   945
		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
   946
		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
   947
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   948
		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
   949
		SuiteEnded = XMLSuiteEnded;
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   950
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   951
		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
   952
		TestEnded = XMLTestEnded;
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   953
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
		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
   955
		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
   956
		AssertSummary = XMLAssertSummary;
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
		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
   959
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   960
		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
   961
		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
   962
			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
   963
		}
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   964
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   965
		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
   966
			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
   967
		}
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   968
5785
7fc252ce5d1d Added simple logging levels to logging system.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5784
diff changeset
   969
		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
   970
	} else {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   971
		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
   972
		RunEnded = PlainRunEnded;
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   973
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   974
		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
   975
		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
   976
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   977
		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
   978
		TestEnded = PlainTestEnded;
5754
2eead798346a Added SetUp/TearDown functions for test suites.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   979
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   980
		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
   981
		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
   982
		AssertSummary = PlainAssertSummary;
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   983
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5754
diff changeset
   984
		Log = PlainLog;
5681
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5680
diff changeset
   985
	}
7abfcc71aa7d Runner can execute multiple test suites consecutively.
Markus K