2011-05-20 13:50:52 +03:00
|
|
|
/*
|
|
|
|
Copyright (C) 2011 Markus Kauppila <markus.kauppila@gmail.com>
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
2011-05-23 17:49:06 +03:00
|
|
|
#include "SDL/SDL.h"
|
2011-05-20 13:50:52 +03:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2011-06-05 16:10:10 +03:00
|
|
|
#include <string.h>
|
2011-06-07 21:11:11 +03:00
|
|
|
#include <dirent.h>
|
2011-06-05 16:10:10 +03:00
|
|
|
|
2011-05-20 13:50:52 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2011-05-30 21:57:04 +03:00
|
|
|
#include "SDL_test.h"
|
2011-06-26 23:04:37 +03:00
|
|
|
#include "logger.h"
|
2011-06-09 18:07:50 +03:00
|
|
|
|
2011-05-30 12:55:40 +03:00
|
|
|
//!< Function pointer to a test case function
|
2011-06-09 18:07:50 +03:00
|
|
|
typedef void (*TestCaseFp)(void *arg);
|
2011-06-04 17:50:23 +03:00
|
|
|
//!< Function pointer to a test case init function
|
2011-06-26 23:04:37 +03:00
|
|
|
typedef void (*TestCaseInitFp)(const int);
|
2011-06-04 17:50:23 +03:00
|
|
|
//!< Function pointer to a test case quit function
|
2011-06-09 18:07:50 +03:00
|
|
|
typedef int (*TestCaseQuitFp)(void);
|
|
|
|
|
2011-05-30 12:55:40 +03:00
|
|
|
|
2011-06-01 12:29:19 +03:00
|
|
|
//!< Flag for executing tests in-process
|
|
|
|
static int execute_inproc = 0;
|
2011-06-13 15:38:40 +03:00
|
|
|
//!< Flag for only printing out the test names
|
|
|
|
static int only_print_tests = 0;
|
2011-06-05 16:10:10 +03:00
|
|
|
//!< Flag for executing only test with selected name
|
|
|
|
static int only_selected_test = 0;
|
|
|
|
//!< Flag for executing only the selected test suite
|
|
|
|
static int only_selected_suite = 0;
|
2011-06-09 17:13:33 +03:00
|
|
|
//!< Flag for executing only tests that contain certain string in their name
|
|
|
|
static int only_tests_with_string = 0;
|
2011-06-26 23:04:37 +03:00
|
|
|
//!< Flag for enabling XML logging
|
|
|
|
static int xml_enabled = 0;
|
2011-06-30 17:11:39 +03:00
|
|
|
//! Flag for enabling user-supplied style sheet for XML test report
|
|
|
|
static int custom_xsl_enabled = 0;
|
2011-07-01 12:36:57 +03:00
|
|
|
//! Flag for disabling xsl-style from xml report
|
|
|
|
static int xsl_enabled = 0;
|
2011-06-09 17:13:33 +03:00
|
|
|
|
2011-06-05 16:10:10 +03:00
|
|
|
|
2011-06-08 19:41:12 +03:00
|
|
|
//!< Size of the test and suite name buffers
|
2011-06-07 21:11:11 +03:00
|
|
|
#define NAME_BUFFER_SIZE 1024
|
2011-06-05 16:10:10 +03:00
|
|
|
//!< Name of the selected test
|
|
|
|
char selected_test_name[NAME_BUFFER_SIZE];
|
|
|
|
//!< Name of the selected suite
|
|
|
|
char selected_suite_name[NAME_BUFFER_SIZE];
|
2011-06-04 18:50:41 +03:00
|
|
|
|
2011-06-09 17:13:33 +03:00
|
|
|
//!< substring of test case name
|
|
|
|
char testcase_name_substring[NAME_BUFFER_SIZE];
|
|
|
|
|
2011-06-30 17:11:39 +03:00
|
|
|
//! Name for user-supplied XSL style sheet name
|
|
|
|
char xsl_stylesheet_name[NAME_BUFFER_SIZE];
|
|
|
|
|
2011-06-08 19:41:12 +03:00
|
|
|
//! Default directory of the test suites
|
|
|
|
#define DEFAULT_TEST_DIRECTORY "tests/"
|
|
|
|
|
2011-06-09 18:07:50 +03:00
|
|
|
|
2011-06-07 21:11:11 +03:00
|
|
|
/*!
|
2011-06-09 18:07:50 +03:00
|
|
|
* Holds information about test suite such as it's name
|
|
|
|
* and pointer to dynamic library. Implemented as linked list.
|
2011-06-07 21:11:11 +03:00
|
|
|
*/
|
|
|
|
typedef struct TestSuiteReference {
|
2011-06-09 16:37:51 +03:00
|
|
|
char *name; //!< test suite name
|
2011-07-01 11:12:35 +03:00
|
|
|
char *directoryPath; //!< test suites path (eg. tests/libtestsuite)
|
2011-06-09 18:07:50 +03:00
|
|
|
void *library; //!< pointer to shared/dynamic library implementing the suite
|
2011-06-09 16:37:51 +03:00
|
|
|
|
2011-06-07 21:11:11 +03:00
|
|
|
struct TestSuiteReference *next; //!< Pointer to next item in the list
|
|
|
|
} TestSuiteReference;
|
|
|
|
|
2011-06-09 18:07:50 +03:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Holds information about the tests that will be executed.
|
|
|
|
*
|
|
|
|
* Implemented as linked list.
|
|
|
|
*/
|
2011-06-09 16:37:51 +03:00
|
|
|
typedef struct TestCaseItem {
|
|
|
|
char *testName;
|
|
|
|
char *suiteName;
|
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
char *description;
|
|
|
|
long requirements;
|
|
|
|
long timeout;
|
|
|
|
|
2011-06-09 18:07:50 +03:00
|
|
|
TestCaseInitFp testCaseInit;
|
|
|
|
TestCaseFp testCase;
|
|
|
|
TestCaseQuitFp testCaseQuit;
|
2011-06-09 16:37:51 +03:00
|
|
|
|
|
|
|
struct TestCaseItem *next;
|
2011-06-09 18:07:50 +03:00
|
|
|
} TestCase;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! Some function prototypes. Add the rest of functions and move to runner.h */
|
|
|
|
TestCaseFp LoadTestCaseFunction(void *suite, char *testName);
|
|
|
|
TestCaseInitFp LoadTestCaseInitFunction(void *suite);
|
|
|
|
TestCaseQuitFp LoadTestCaseQuitFunction(void *suite);
|
|
|
|
TestCaseReference **QueryTestCaseReferences(void *library);
|
|
|
|
|
2011-06-04 18:50:41 +03:00
|
|
|
|
2011-06-09 18:07:50 +03:00
|
|
|
/*!
|
|
|
|
* Goes through the previously loaded test suites and
|
|
|
|
* loads test cases from them. Test cases are filtered
|
|
|
|
* during the process. Function will only return the
|
|
|
|
* test cases which aren't filtered out.
|
|
|
|
*
|
2011-06-09 18:30:06 +03:00
|
|
|
* \param suites previously loaded test suites
|
2011-06-09 18:07:50 +03:00
|
|
|
*
|
|
|
|
* \return Test cases that survived filtering process.
|
|
|
|
*/
|
|
|
|
TestCase *
|
|
|
|
LoadTestCases(TestSuiteReference *suites)
|
|
|
|
{
|
|
|
|
TestCase *testCases = NULL;
|
|
|
|
|
|
|
|
TestSuiteReference *suiteReference = NULL;
|
|
|
|
for(suiteReference = suites; suiteReference; suiteReference = suiteReference->next) {
|
|
|
|
TestCaseReference **tests = QueryTestCaseReferences(suiteReference->library);
|
|
|
|
|
|
|
|
TestCaseReference *testReference = NULL;
|
|
|
|
int counter = 0;
|
|
|
|
for(testReference = tests[counter]; testReference; testReference = tests[++counter]) {
|
|
|
|
|
|
|
|
void *suite = suiteReference->library;
|
|
|
|
|
|
|
|
// Load test case functions
|
|
|
|
TestCaseInitFp testCaseInit = LoadTestCaseInitFunction(suiteReference->library);
|
|
|
|
TestCaseQuitFp testCaseQuit = LoadTestCaseQuitFunction(suiteReference->library);
|
|
|
|
TestCaseFp testCase = (TestCaseFp) LoadTestCaseFunction(suiteReference->library, testReference->name);
|
|
|
|
|
|
|
|
// Do the filtering
|
|
|
|
if(FilterTestCase(testReference)) {
|
|
|
|
TestCase *item = SDL_malloc(sizeof(TestCase));
|
|
|
|
memset(item, 0, sizeof(TestCase));
|
|
|
|
|
|
|
|
item->testCaseInit = testCaseInit;
|
|
|
|
item->testCase = testCase;
|
|
|
|
item->testCaseQuit = testCaseQuit;
|
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
// copy suite name
|
2011-06-27 16:41:45 +03:00
|
|
|
int length = SDL_strlen(suiteReference->name) + 1;
|
2011-06-09 18:07:50 +03:00
|
|
|
item->suiteName = SDL_malloc(length);
|
2011-06-27 16:41:45 +03:00
|
|
|
strncpy(item->suiteName, suiteReference->name, length);
|
2011-06-09 18:07:50 +03:00
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
// copy test name
|
2011-06-27 16:41:45 +03:00
|
|
|
length = SDL_strlen(testReference->name) + 1;
|
2011-06-09 18:07:50 +03:00
|
|
|
item->testName = SDL_malloc(length);
|
2011-06-27 16:41:45 +03:00
|
|
|
strncpy(item->testName, testReference->name, length);
|
2011-06-09 18:07:50 +03:00
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
// copy test description
|
2011-06-27 16:41:45 +03:00
|
|
|
length = SDL_strlen(testReference->description) + 1;
|
2011-06-26 23:04:37 +03:00
|
|
|
item->description = SDL_malloc(length);
|
2011-06-27 16:41:45 +03:00
|
|
|
strncpy(item->description, testReference->description, length);
|
2011-06-26 23:04:37 +03:00
|
|
|
|
|
|
|
item->requirements = testReference->requirements;
|
|
|
|
item->timeout = testReference->timeout;
|
|
|
|
|
2011-06-09 18:07:50 +03:00
|
|
|
// prepend the list
|
|
|
|
item->next = testCases;
|
|
|
|
testCases = item;
|
|
|
|
|
|
|
|
//printf("Added test: %s\n", testReference->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return testCases;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Unloads the given TestCases. Frees all the resources
|
|
|
|
* allocated for test cases.
|
|
|
|
*
|
|
|
|
* \param testCases Test cases to be deallocated
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
UnloadTestCases(TestCase *testCases)
|
|
|
|
{
|
|
|
|
TestCase *ref = testCases;
|
|
|
|
while(ref) {
|
|
|
|
SDL_free(ref->testName);
|
|
|
|
SDL_free(ref->suiteName);
|
2011-06-26 23:04:37 +03:00
|
|
|
SDL_free(ref->description);
|
2011-06-09 18:07:50 +03:00
|
|
|
|
|
|
|
TestCase *temp = ref->next;
|
|
|
|
SDL_free(ref);
|
|
|
|
ref = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Filters a test case based on its properties in TestCaseReference and user
|
|
|
|
* preference.
|
|
|
|
*
|
|
|
|
* \return Non-zero means test will be added to execution list, zero means opposite
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
FilterTestCase(TestCaseReference *testReference)
|
|
|
|
{
|
|
|
|
int retVal = 1;
|
|
|
|
|
|
|
|
if(testReference->enabled == TEST_DISABLED) {
|
|
|
|
retVal = 0;
|
|
|
|
}
|
|
|
|
|
2011-06-09 18:13:46 +03:00
|
|
|
if(only_selected_test) {
|
|
|
|
if(SDL_strncmp(testReference->name, selected_test_name, NAME_BUFFER_SIZE) == 0) {
|
|
|
|
retVal = 1;
|
|
|
|
} else {
|
|
|
|
retVal = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-09 18:07:50 +03:00
|
|
|
if(only_tests_with_string) {
|
|
|
|
if(strstr(testReference->name, testcase_name_substring) != NULL) {
|
|
|
|
retVal = 1;
|
|
|
|
} else {
|
|
|
|
retVal = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-30 18:11:48 +03:00
|
|
|
/*!
|
|
|
|
* Scans the tests/ directory and returns the names
|
|
|
|
* of the dynamic libraries implementing the test suites.
|
|
|
|
*
|
|
|
|
* Note: currently function assumes that test suites names
|
|
|
|
* are in following format: libtestsuite.dylib or libtestsuite.so.
|
|
|
|
*
|
|
|
|
* Note: if only_selected_suite flags is non-zero, only the selected
|
|
|
|
* test will be loaded.
|
|
|
|
*
|
|
|
|
* \param directoryName Name of the directory which will be scanned
|
|
|
|
* \param extension What file extension is used with dynamic objects
|
|
|
|
*
|
|
|
|
* \return Pointer to TestSuiteReference which holds all the info about suites
|
|
|
|
*/
|
|
|
|
TestSuiteReference *
|
|
|
|
ScanForTestSuites(char *directoryName, char *extension)
|
|
|
|
{
|
|
|
|
typedef struct dirent Entry;
|
|
|
|
DIR *directory = opendir(directoryName);
|
|
|
|
|
|
|
|
TestSuiteReference *suites = NULL;
|
|
|
|
|
|
|
|
Entry *entry = NULL;
|
|
|
|
if(!directory) {
|
|
|
|
perror("Couldn't open test suite directory!");
|
|
|
|
}
|
|
|
|
|
|
|
|
while(entry = readdir(directory)) {
|
|
|
|
if(strlen(entry->d_name) > 2) { // discards . and ..
|
|
|
|
const char *delimiters = ".";
|
|
|
|
char *name = strtok(entry->d_name, delimiters);
|
|
|
|
char *ext = strtok(NULL, delimiters);
|
|
|
|
|
|
|
|
// filter out all other suites but the selected test suite
|
|
|
|
int ok = 1;
|
|
|
|
if(only_selected_suite) {
|
|
|
|
ok = SDL_strncmp(selected_suite_name, name, NAME_BUFFER_SIZE) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ok && SDL_strcmp(ext, extension) == 0) {
|
|
|
|
// create test suite reference
|
|
|
|
TestSuiteReference *reference = (TestSuiteReference *) SDL_malloc(sizeof(TestSuiteReference));
|
|
|
|
memset(reference, 0, sizeof(TestSuiteReference));
|
|
|
|
|
|
|
|
|
2011-07-01 11:12:35 +03:00
|
|
|
const int dirSize = SDL_strlen(directoryName);
|
|
|
|
const int extSize = SDL_strlen(ext);
|
|
|
|
const int nameSize = SDL_strlen(name) + 1;
|
|
|
|
|
|
|
|
// copy the name
|
|
|
|
reference->name = SDL_malloc(nameSize * sizeof(char));
|
|
|
|
if(reference->name == NULL) {
|
|
|
|
SDL_free(reference);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_snprintf(reference->name, nameSize, "%s", name);
|
|
|
|
|
|
|
|
// copy the directory path
|
|
|
|
const int dpSize = dirSize + nameSize + 1 + extSize + 1;
|
|
|
|
reference->directoryPath = SDL_malloc(dpSize * sizeof(char));
|
|
|
|
if(reference->directoryPath == NULL) {
|
|
|
|
SDL_free(reference->name);
|
|
|
|
SDL_free(reference);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
SDL_snprintf(reference->directoryPath, dpSize, "%s%s.%s",
|
|
|
|
directoryName, name, ext);
|
2011-06-30 18:11:48 +03:00
|
|
|
|
|
|
|
reference->next = suites;
|
|
|
|
suites = reference;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir(directory);
|
|
|
|
|
|
|
|
return suites;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-01 12:29:19 +03:00
|
|
|
/*!
|
|
|
|
* Loads test suite which is implemented as dynamic library.
|
|
|
|
*
|
2011-07-01 13:29:19 +03:00
|
|
|
* \param suite Reference to test suite that'll be loaded
|
2011-06-01 12:29:19 +03:00
|
|
|
*
|
|
|
|
* \return Pointer to loaded test suite, or NULL if library could not be loaded
|
|
|
|
*/
|
|
|
|
void *
|
2011-07-01 11:12:35 +03:00
|
|
|
LoadTestSuite(const TestSuiteReference *suite)
|
2011-06-01 12:29:19 +03:00
|
|
|
{
|
2011-07-01 11:12:35 +03:00
|
|
|
void *library = SDL_LoadObject(suite->directoryPath);
|
2011-05-20 13:50:52 +03:00
|
|
|
if(library == NULL) {
|
2011-07-01 11:12:35 +03:00
|
|
|
fprintf(stderr, "Loading %s failed\n", suite->name);
|
2011-05-31 14:40:28 +03:00
|
|
|
fprintf(stderr, "%s\n", SDL_GetError());
|
2011-05-20 13:50:52 +03:00
|
|
|
}
|
|
|
|
|
2011-05-26 18:38:56 +03:00
|
|
|
return library;
|
|
|
|
}
|
|
|
|
|
2011-06-05 16:10:10 +03:00
|
|
|
|
2011-06-09 18:07:50 +03:00
|
|
|
/*!
|
|
|
|
* Goes through all the given TestSuiteReferences
|
|
|
|
* and loads the dynamic libraries. Updates the suites
|
|
|
|
* parameter on-the-fly and returns it.
|
|
|
|
*
|
|
|
|
* \param suites Suites that will be loaded
|
|
|
|
*
|
|
|
|
* \return Updated TestSuiteReferences with pointer to loaded libraries
|
|
|
|
*/
|
|
|
|
TestSuiteReference *
|
2011-07-01 11:12:35 +03:00
|
|
|
LoadTestSuites(TestSuiteReference *suites)
|
2011-06-09 18:07:50 +03:00
|
|
|
{
|
|
|
|
TestSuiteReference *reference = NULL;
|
|
|
|
for(reference = suites; reference; reference = reference->next) {
|
2011-07-01 11:12:35 +03:00
|
|
|
reference->library = LoadTestSuite(reference);
|
2011-06-09 18:07:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return suites;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Unloads the given TestSuiteReferences. Frees all
|
|
|
|
* the allocated resources including the dynamic libraries.
|
|
|
|
*
|
|
|
|
* \param suites TestSuiteReferences for deallocation process
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
UnloadTestSuites(TestSuiteReference *suites)
|
|
|
|
{
|
|
|
|
TestSuiteReference *ref = suites;
|
|
|
|
while(ref) {
|
|
|
|
SDL_free(ref->name);
|
2011-07-01 11:12:35 +03:00
|
|
|
SDL_free(ref->directoryPath);
|
2011-06-09 18:07:50 +03:00
|
|
|
SDL_UnloadObject(ref->library);
|
|
|
|
|
|
|
|
TestSuiteReference *temp = ref->next;
|
|
|
|
SDL_free(ref);
|
|
|
|
ref = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
suites = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-30 11:53:59 +03:00
|
|
|
/*!
|
|
|
|
* Loads the test case references from the given test suite.
|
|
|
|
|
|
|
|
* \param library Previously loaded dynamic library AKA test suite
|
2011-05-31 14:40:28 +03:00
|
|
|
* \return Pointer to array of TestCaseReferences or NULL if function failed
|
2011-05-30 11:53:59 +03:00
|
|
|
*/
|
2011-05-30 18:58:20 +03:00
|
|
|
TestCaseReference **
|
2011-06-09 18:07:50 +03:00
|
|
|
QueryTestCaseReferences(void *library)
|
2011-05-30 18:58:20 +03:00
|
|
|
{
|
2011-06-09 18:07:50 +03:00
|
|
|
TestCaseReference **(*suite)(void);
|
2011-05-26 18:38:56 +03:00
|
|
|
|
2011-06-09 18:07:50 +03:00
|
|
|
suite = (TestCaseReference **(*)(void)) SDL_LoadFunction(library, "QueryTestSuite");
|
|
|
|
if(suite == NULL) {
|
|
|
|
fprintf(stderr, "Loading QueryTestCaseReferences() failed.\n");
|
|
|
|
fprintf(stderr, "%s\n", SDL_GetError());
|
|
|
|
}
|
2011-05-26 18:38:56 +03:00
|
|
|
|
2011-06-09 18:07:50 +03:00
|
|
|
TestCaseReference **tests = suite();
|
|
|
|
if(tests == NULL) {
|
|
|
|
fprintf(stderr, "Failed to load test references.\n");
|
|
|
|
fprintf(stderr, "%s\n", SDL_GetError());
|
|
|
|
}
|
2011-05-26 18:38:56 +03:00
|
|
|
|
2011-06-09 18:07:50 +03:00
|
|
|
return tests;
|
2011-05-26 18:38:56 +03:00
|
|
|
}
|
|
|
|
|
2011-06-04 17:50:23 +03:00
|
|
|
|
2011-05-30 12:55:40 +03:00
|
|
|
/*!
|
|
|
|
* Loads test case from a test suite
|
|
|
|
*
|
2011-05-30 18:58:20 +03:00
|
|
|
* \param suite a test suite
|
|
|
|
* \param testName Name of the test that is going to be loaded
|
2011-05-30 11:53:59 +03:00
|
|
|
*
|
2011-05-31 14:40:28 +03:00
|
|
|
* \return Function Pointer (TestCase) to loaded test case, NULL if function failed
|
2011-05-30 11:53:59 +03:00
|
|
|
*/
|
2011-06-09 18:07:50 +03:00
|
|
|
TestCaseFp
|
|
|
|
LoadTestCaseFunction(void *suite, char *testName)
|
2011-05-30 18:58:20 +03:00
|
|
|
{
|
2011-06-09 18:07:50 +03:00
|
|
|
TestCaseFp test = (TestCaseFp) SDL_LoadFunction(suite, testName);
|
2011-05-30 12:55:40 +03:00
|
|
|
if(test == NULL) {
|
2011-05-31 14:40:28 +03:00
|
|
|
fprintf(stderr, "Loading test failed, tests == NULL\n");
|
|
|
|
fprintf(stderr, "%s\n", SDL_GetError());
|
2011-05-30 12:55:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return test;
|
|
|
|
}
|
|
|
|
|
2011-06-05 16:10:10 +03:00
|
|
|
|
2011-06-04 17:50:23 +03:00
|
|
|
/*!
|
|
|
|
* Loads function that initialises the test case from the
|
|
|
|
* given test suite.
|
|
|
|
*
|
|
|
|
* \param suite Used test suite
|
|
|
|
*
|
|
|
|
* \return Function pointer (TestCaseInit) which points to loaded init function. NULL if function fails.
|
|
|
|
*/
|
2011-06-09 18:07:50 +03:00
|
|
|
TestCaseInitFp
|
|
|
|
LoadTestCaseInitFunction(void *suite) {
|
|
|
|
TestCaseInitFp testCaseInit = (TestCaseInitFp) SDL_LoadFunction(suite, "_TestCaseInit");
|
2011-06-04 17:50:23 +03:00
|
|
|
if(testCaseInit == NULL) {
|
|
|
|
fprintf(stderr, "Loading TestCaseInit function failed, testCaseInit == NULL\n");
|
|
|
|
fprintf(stderr, "%s\n", SDL_GetError());
|
|
|
|
}
|
|
|
|
|
|
|
|
return testCaseInit;
|
|
|
|
}
|
|
|
|
|
2011-06-05 16:10:10 +03:00
|
|
|
|
2011-06-04 17:50:23 +03:00
|
|
|
/*!
|
|
|
|
* Loads function that deinitialises the executed test case from the
|
|
|
|
* given test suite.
|
|
|
|
*
|
|
|
|
* \param suite Used test suite
|
|
|
|
*
|
|
|
|
* \return Function pointer (TestCaseInit) which points to loaded init function. NULL if function fails.
|
|
|
|
*/
|
2011-06-09 18:07:50 +03:00
|
|
|
TestCaseQuitFp
|
|
|
|
LoadTestCaseQuitFunction(void *suite) {
|
|
|
|
TestCaseQuitFp testCaseQuit = (TestCaseQuitFp) SDL_LoadFunction(suite, "_TestCaseQuit");
|
2011-06-04 17:50:23 +03:00
|
|
|
if(testCaseQuit == NULL) {
|
|
|
|
fprintf(stderr, "Loading TestCaseQuit function failed, testCaseQuit == NULL\n");
|
|
|
|
fprintf(stderr, "%s\n", SDL_GetError());
|
|
|
|
}
|
|
|
|
|
|
|
|
return testCaseQuit;
|
|
|
|
}
|
2011-05-30 12:55:40 +03:00
|
|
|
|
2011-06-05 16:10:10 +03:00
|
|
|
|
2011-05-30 11:53:59 +03:00
|
|
|
/*!
|
2011-05-30 12:55:40 +03:00
|
|
|
* If using out-of-proc execution of tests. This function
|
|
|
|
* will handle the return value of the child process
|
|
|
|
* and interprets it to the runner. Also prints warnings
|
|
|
|
* if child was aborted by a signela.
|
2011-05-30 11:53:59 +03:00
|
|
|
*
|
2011-05-30 12:55:40 +03:00
|
|
|
* \param stat_lock information about the exited child process
|
2011-05-30 11:53:59 +03:00
|
|
|
*
|
2011-05-30 12:55:40 +03:00
|
|
|
* \return 0 if test case succeeded, 1 otherwise
|
2011-05-30 11:53:59 +03:00
|
|
|
*/
|
2011-05-30 18:58:20 +03:00
|
|
|
int
|
2011-06-09 18:07:50 +03:00
|
|
|
HandleChildProcessReturnValue(int stat_lock)
|
2011-05-30 18:58:20 +03:00
|
|
|
{
|
2011-05-30 12:55:40 +03:00
|
|
|
int returnValue = -1;
|
2011-05-26 18:38:56 +03:00
|
|
|
|
2011-05-30 12:55:40 +03:00
|
|
|
if(WIFEXITED(stat_lock)) {
|
|
|
|
returnValue = WEXITSTATUS(stat_lock);
|
2011-05-26 18:38:56 +03:00
|
|
|
} else if(WIFSIGNALED(stat_lock)) {
|
|
|
|
int signal = WTERMSIG(stat_lock);
|
2011-05-31 14:40:28 +03:00
|
|
|
fprintf(stderr, "FAILURE: test was aborted due to signal no %d\n", signal);
|
2011-05-30 12:55:40 +03:00
|
|
|
returnValue = 1;
|
2011-05-26 18:38:56 +03:00
|
|
|
}
|
|
|
|
|
2011-05-30 12:55:40 +03:00
|
|
|
return returnValue;
|
2011-05-26 18:38:56 +03:00
|
|
|
}
|
|
|
|
|
2011-06-05 16:10:10 +03:00
|
|
|
|
2011-06-04 18:50:41 +03:00
|
|
|
/*!
|
|
|
|
* Executes a test case. Loads the test, executes it and
|
|
|
|
* returns the tests return value to the caller.
|
|
|
|
*
|
2011-06-09 18:30:06 +03:00
|
|
|
* \param testItem The test case that will be executed
|
2011-06-04 18:50:41 +03:00
|
|
|
* \return The return value of the test. Zero means success, non-zero failure.
|
|
|
|
*/
|
|
|
|
int
|
2011-06-09 18:07:50 +03:00
|
|
|
ExecuteTest(TestCase *testItem) {
|
2011-06-04 18:50:41 +03:00
|
|
|
int retVal = 1;
|
|
|
|
if(execute_inproc) {
|
2011-06-26 23:04:37 +03:00
|
|
|
testItem->testCaseInit(xml_enabled);
|
2011-06-04 18:50:41 +03:00
|
|
|
|
2011-06-09 16:37:51 +03:00
|
|
|
testItem->testCase(0x0);
|
2011-06-04 18:50:41 +03:00
|
|
|
|
2011-06-09 16:37:51 +03:00
|
|
|
retVal = testItem->testCaseQuit();
|
2011-06-04 18:50:41 +03:00
|
|
|
} else {
|
|
|
|
int childpid = fork();
|
|
|
|
if(childpid == 0) {
|
2011-06-26 23:04:37 +03:00
|
|
|
testItem->testCaseInit(xml_enabled);
|
2011-06-04 18:50:41 +03:00
|
|
|
|
2011-06-09 16:37:51 +03:00
|
|
|
testItem->testCase(0x0);
|
2011-06-04 18:50:41 +03:00
|
|
|
|
2011-06-09 16:37:51 +03:00
|
|
|
exit(testItem->testCaseQuit());
|
2011-06-04 18:50:41 +03:00
|
|
|
} else {
|
|
|
|
int stat_lock = -1;
|
|
|
|
int child = wait(&stat_lock);
|
|
|
|
|
2011-06-09 18:07:50 +03:00
|
|
|
retVal = HandleChildProcessReturnValue(stat_lock);
|
2011-06-04 18:50:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-04 17:50:23 +03:00
|
|
|
/*!
|
|
|
|
* Prints usage information
|
|
|
|
*/
|
2011-06-06 18:37:53 +03:00
|
|
|
void
|
|
|
|
printUsage() {
|
2011-06-09 18:30:06 +03:00
|
|
|
printf("Usage: ./runner [--in-proc] [--suite SUITE] [--test TEST]\n");
|
2011-06-30 18:11:48 +03:00
|
|
|
printf(" [--name-contains SUBSTR] [--show-tests\n");
|
2011-07-01 12:36:57 +03:00
|
|
|
printf(" [--xml] [--xsl] [--xsl STYLESHEET] [--help]\n");
|
2011-06-04 17:50:23 +03:00
|
|
|
printf("Options:\n");
|
2011-06-09 18:30:06 +03:00
|
|
|
printf(" --in-proc Executes tests in-process\n");
|
2011-06-13 15:38:40 +03:00
|
|
|
printf(" --show-tests Prints out all the executable tests\n");
|
2011-07-01 12:36:57 +03:00
|
|
|
printf(" --xml Enables XML logger\n");
|
|
|
|
printf(" --xsl Adds default XSL stylesheet to XML test reports\n");
|
|
|
|
printf(" --xsl STYLESHEET Use the given file as XSL style sheet for XML\n");
|
2011-06-09 18:30:06 +03:00
|
|
|
printf(" -t --test TEST Executes only tests with given name\n");
|
|
|
|
printf(" -ts --name-contains SUBSTR Executes only tests that have given\n");
|
|
|
|
printf(" substring in test name\n");
|
|
|
|
printf(" -s --suite SUITE Executes only the given test suite\n");
|
2011-06-05 17:34:04 +03:00
|
|
|
|
2011-06-09 18:30:06 +03:00
|
|
|
printf(" -h --help Print this help\n");
|
2011-06-04 17:50:23 +03:00
|
|
|
}
|
|
|
|
|
2011-06-05 16:10:10 +03:00
|
|
|
|
2011-05-30 12:55:40 +03:00
|
|
|
/*!
|
|
|
|
* Parse command line arguments
|
2011-06-01 12:29:19 +03:00
|
|
|
*
|
|
|
|
* \param argc Count of command line arguments
|
|
|
|
* \param argv Array of commond lines arguments
|
2011-05-30 12:55:40 +03:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
ParseOptions(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 1; i < argc; ++i) {
|
|
|
|
const char *arg = argv[i];
|
2011-06-01 12:29:19 +03:00
|
|
|
if(SDL_strcmp(arg, "--in-proc") == 0) {
|
2011-05-30 12:55:40 +03:00
|
|
|
execute_inproc = 1;
|
|
|
|
}
|
2011-06-13 15:38:40 +03:00
|
|
|
else if(SDL_strcmp(arg, "--show-tests") == 0) {
|
|
|
|
only_print_tests = 1;
|
2011-06-05 16:10:10 +03:00
|
|
|
}
|
2011-06-26 23:04:37 +03:00
|
|
|
else if(SDL_strcmp(arg, "--xml") == 0) {
|
|
|
|
xml_enabled = 1;
|
|
|
|
}
|
2011-06-05 16:10:10 +03:00
|
|
|
else if(SDL_strcmp(arg, "--test") == 0 || SDL_strcmp(arg, "-t") == 0) {
|
|
|
|
only_selected_test = 1;
|
2011-06-05 17:34:04 +03:00
|
|
|
char *testName = NULL;
|
|
|
|
|
|
|
|
if( (i + 1) < argc) {
|
|
|
|
testName = argv[++i];
|
|
|
|
} else {
|
|
|
|
printf("runner: test name is missing\n");
|
|
|
|
printUsage();
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-06-05 16:10:10 +03:00
|
|
|
|
2011-06-05 17:34:04 +03:00
|
|
|
memset(selected_test_name, 0, NAME_BUFFER_SIZE);
|
2011-06-05 16:10:10 +03:00
|
|
|
strcpy(selected_test_name, testName);
|
|
|
|
}
|
2011-06-30 17:11:39 +03:00
|
|
|
else if(SDL_strcmp(arg, "--xsl") == 0) {
|
2011-07-01 12:36:57 +03:00
|
|
|
xsl_enabled = 1;
|
2011-06-30 17:11:39 +03:00
|
|
|
|
|
|
|
if( (i + 1) < argc) {
|
2011-07-01 12:36:57 +03:00
|
|
|
char *stylesheet = argv[++i];
|
|
|
|
if(stylesheet[0] != '-') {
|
|
|
|
custom_xsl_enabled = 1;
|
2011-06-30 17:11:39 +03:00
|
|
|
|
2011-07-01 12:36:57 +03:00
|
|
|
memset(xsl_stylesheet_name, 0, NAME_BUFFER_SIZE);
|
|
|
|
strncpy(xsl_stylesheet_name, stylesheet, NAME_BUFFER_SIZE);
|
|
|
|
}
|
|
|
|
}
|
2011-06-30 17:11:39 +03:00
|
|
|
}
|
2011-06-09 18:30:06 +03:00
|
|
|
else if(SDL_strcmp(arg, "--name-contains") == 0 || SDL_strcmp(arg, "-ts") == 0) {
|
2011-06-09 17:13:33 +03:00
|
|
|
only_tests_with_string = 1;
|
|
|
|
char *substring = NULL;
|
|
|
|
|
|
|
|
if( (i + 1) < argc) {
|
|
|
|
substring = argv[++i];
|
|
|
|
} else {
|
|
|
|
printf("runner: substring of test name is missing\n");
|
|
|
|
printUsage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(testcase_name_substring, 0, NAME_BUFFER_SIZE);
|
|
|
|
strcpy(testcase_name_substring, substring);
|
|
|
|
}
|
2011-06-05 16:10:10 +03:00
|
|
|
else if(SDL_strcmp(arg, "--suite") == 0 || SDL_strcmp(arg, "-s") == 0) {
|
|
|
|
only_selected_suite = 1;
|
|
|
|
|
2011-06-05 17:34:04 +03:00
|
|
|
char *suiteName = NULL;
|
|
|
|
if( (i + 1) < argc) {
|
|
|
|
suiteName = argv[++i];
|
|
|
|
} else {
|
|
|
|
printf("runner: suite name is missing\n");
|
|
|
|
printUsage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(selected_suite_name, 0, NAME_BUFFER_SIZE);
|
2011-06-05 16:10:10 +03:00
|
|
|
strcpy(selected_suite_name, suiteName);
|
|
|
|
}
|
2011-06-13 15:38:40 +03:00
|
|
|
else if(SDL_strcmp(arg, "--help") == 0 || SDL_strcmp(arg, "-h") == 0) {
|
|
|
|
printUsage();
|
|
|
|
exit(0);
|
|
|
|
}
|
2011-06-05 16:10:10 +03:00
|
|
|
else {
|
2011-06-04 17:50:23 +03:00
|
|
|
printf("runner: unknown command '%s'\n", arg);
|
|
|
|
printUsage();
|
2011-06-01 12:29:19 +03:00
|
|
|
exit(0);
|
|
|
|
}
|
2011-05-30 12:55:40 +03:00
|
|
|
}
|
|
|
|
}
|
2011-05-26 18:38:56 +03:00
|
|
|
|
2011-06-05 16:10:10 +03:00
|
|
|
|
2011-05-31 14:40:28 +03:00
|
|
|
/*!
|
|
|
|
* Entry point for test runner
|
|
|
|
*
|
|
|
|
* \param argc Count of command line arguments
|
|
|
|
* \param argv Array of commond lines arguments
|
|
|
|
*/
|
2011-05-30 12:55:40 +03:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
ParseOptions(argc, argv);
|
2011-05-26 18:38:56 +03:00
|
|
|
|
2011-05-30 18:58:20 +03:00
|
|
|
// print: Testing against SDL version fuu (rev: bar) if verbose == true
|
2011-05-26 18:38:56 +03:00
|
|
|
|
2011-06-27 16:41:45 +03:00
|
|
|
int totalTestfailureCount = 0, totalTestPassCount = 0;
|
|
|
|
int testFailureCount = 0, testPassCount = 0, testSkipCount = 0;
|
2011-06-06 18:37:53 +03:00
|
|
|
char *testSuiteName = NULL;
|
|
|
|
int suiteCounter = 0;
|
2011-05-26 18:38:56 +03:00
|
|
|
|
2011-06-08 19:41:12 +03:00
|
|
|
#if defined(linux) || defined( __linux)
|
|
|
|
char *extension = "so";
|
|
|
|
#else
|
|
|
|
char *extension = "dylib";
|
|
|
|
#endif
|
2011-06-30 18:11:48 +03:00
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
if(xml_enabled) {
|
|
|
|
SetupXMLLogger();
|
2011-06-30 17:11:39 +03:00
|
|
|
|
2011-07-01 12:36:57 +03:00
|
|
|
char *sheet = NULL;
|
|
|
|
if(xsl_enabled) {
|
|
|
|
sheet = "style.xsl"; // default style sheet;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(custom_xsl_enabled) {
|
|
|
|
sheet = xsl_stylesheet_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
RunStarted(argc, argv, time(0), sheet);
|
2011-06-26 23:04:37 +03:00
|
|
|
} else {
|
|
|
|
SetupPlainLogger();
|
2011-06-30 17:11:39 +03:00
|
|
|
|
|
|
|
RunStarted(argc, argv, time(0), NULL);
|
2011-06-26 23:04:37 +03:00
|
|
|
}
|
2011-06-08 19:41:12 +03:00
|
|
|
|
2011-05-26 18:38:56 +03:00
|
|
|
const Uint32 startTicks = SDL_GetTicks();
|
2011-06-09 16:37:51 +03:00
|
|
|
|
2011-06-08 19:41:12 +03:00
|
|
|
TestSuiteReference *suites = ScanForTestSuites(DEFAULT_TEST_DIRECTORY, extension);
|
2011-07-01 11:12:35 +03:00
|
|
|
suites = LoadTestSuites(suites);
|
2011-06-08 19:41:12 +03:00
|
|
|
|
2011-06-09 18:07:50 +03:00
|
|
|
TestCase *testCases = LoadTestCases(suites);
|
2011-06-05 16:10:10 +03:00
|
|
|
|
2011-06-13 15:38:40 +03:00
|
|
|
// if --show-tests option is given, only print tests and exit
|
|
|
|
if(only_print_tests) {
|
|
|
|
TestCase *testItem = NULL;
|
|
|
|
for(testItem = testCases; testItem; testItem = testItem->next) {
|
|
|
|
printf("%s (in %s)\n", testItem->testName, testItem->suiteName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
char *currentSuiteName = NULL;
|
|
|
|
|
2011-06-27 21:41:34 +03:00
|
|
|
int suiteStartTime = SDL_GetTicks();
|
|
|
|
|
2011-06-09 18:07:50 +03:00
|
|
|
TestCase *testItem = NULL;
|
2011-06-09 16:37:51 +03:00
|
|
|
for(testItem = testCases; testItem; testItem = testItem->next) {
|
2011-06-26 23:04:37 +03:00
|
|
|
if(currentSuiteName == NULL) {
|
|
|
|
currentSuiteName = testItem->suiteName;
|
2011-06-27 21:41:34 +03:00
|
|
|
SuiteStarted(currentSuiteName, time(0));
|
2011-06-27 16:41:45 +03:00
|
|
|
|
|
|
|
testFailureCount = testPassCount = 0;
|
|
|
|
|
|
|
|
suiteCounter++;
|
|
|
|
}
|
|
|
|
else if(strncmp(currentSuiteName, testItem->suiteName, NAME_BUFFER_SIZE) != 0) {
|
2011-06-27 21:41:34 +03:00
|
|
|
const double suiteRuntime = (SDL_GetTicks() - suiteStartTime) / 1000.0f;
|
|
|
|
|
|
|
|
SuiteEnded(testPassCount, testFailureCount, testSkipCount, time(0),
|
|
|
|
suiteRuntime);
|
2011-06-27 16:41:45 +03:00
|
|
|
|
2011-06-29 19:05:56 +03:00
|
|
|
suiteStartTime = SDL_GetTicks();
|
|
|
|
|
2011-06-27 16:41:45 +03:00
|
|
|
currentSuiteName = testItem->suiteName;
|
2011-06-27 22:39:38 +03:00
|
|
|
SuiteStarted(currentSuiteName, time(0));
|
2011-06-27 16:41:45 +03:00
|
|
|
|
|
|
|
testFailureCount = testPassCount = 0;
|
|
|
|
|
|
|
|
suiteCounter++;
|
2011-06-26 23:04:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
TestStarted(testItem->testName, testItem->suiteName,
|
2011-06-27 21:41:34 +03:00
|
|
|
testItem->description, time(0));
|
|
|
|
|
|
|
|
const Uint32 testTimeStart = SDL_GetTicks();
|
2011-06-26 23:04:37 +03:00
|
|
|
|
2011-06-09 16:37:51 +03:00
|
|
|
int retVal = ExecuteTest(testItem);
|
|
|
|
if(retVal) {
|
2011-06-27 16:41:45 +03:00
|
|
|
totalTestfailureCount++;
|
|
|
|
testFailureCount++;
|
2011-06-09 16:37:51 +03:00
|
|
|
} else {
|
2011-06-27 16:41:45 +03:00
|
|
|
totalTestPassCount++;
|
|
|
|
testPassCount++;
|
2011-05-20 13:50:52 +03:00
|
|
|
}
|
2011-06-08 19:41:12 +03:00
|
|
|
|
2011-06-27 21:41:34 +03:00
|
|
|
const double testTotalRuntime = (SDL_GetTicks() - testTimeStart) / 1000.0f;
|
|
|
|
|
|
|
|
TestEnded(testItem->testName, testItem->suiteName, retVal, time(0), testTotalRuntime);
|
2011-05-20 13:50:52 +03:00
|
|
|
}
|
2011-05-23 17:49:06 +03:00
|
|
|
|
2011-06-27 16:41:45 +03:00
|
|
|
if(currentSuiteName) {
|
2011-06-27 21:41:34 +03:00
|
|
|
SuiteEnded(testPassCount, testFailureCount, testSkipCount, time(0),
|
|
|
|
(SDL_GetTicks() - suiteStartTime) / 1000.0f);
|
2011-06-27 16:41:45 +03:00
|
|
|
}
|
2011-06-27 11:53:14 +03:00
|
|
|
|
2011-06-09 16:37:51 +03:00
|
|
|
UnloadTestCases(testCases);
|
|
|
|
UnloadTestSuites(suites);
|
|
|
|
|
2011-05-23 17:49:06 +03:00
|
|
|
const Uint32 endTicks = SDL_GetTicks();
|
2011-06-27 21:41:34 +03:00
|
|
|
const double totalRunTime = (endTicks - startTicks) / 1000.0f;
|
2011-05-23 17:49:06 +03:00
|
|
|
|
2011-06-27 16:41:45 +03:00
|
|
|
RunEnded(totalTestPassCount + totalTestfailureCount, suiteCounter,
|
2011-06-27 21:41:34 +03:00
|
|
|
totalTestPassCount, totalTestfailureCount, time(0), totalRunTime);
|
2011-05-23 17:49:06 +03:00
|
|
|
|
2011-06-30 16:08:37 +03:00
|
|
|
return (totalTestfailureCount ? 1 : 0);
|
2011-05-20 13:50:52 +03:00
|
|
|
}
|