Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Removed unnecessary function.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkauppila committed Jun 8, 2011
1 parent a40b66b commit 691c1e2
Showing 1 changed file with 64 additions and 78 deletions.
142 changes: 64 additions & 78 deletions test/test-automation/runner.c
Expand Up @@ -45,14 +45,17 @@ static int only_selected_test = 0;
//!< Flag for executing only the selected test suite
static int only_selected_suite = 0;

//<! Size of the test and suite name buffers
//!< Size of the test and suite name buffers
#define NAME_BUFFER_SIZE 1024
//!< Name of the selected test
char selected_test_name[NAME_BUFFER_SIZE];
//!< Name of the selected suite
char selected_suite_name[NAME_BUFFER_SIZE];


//! Default directory of the test suites
#define DEFAULT_TEST_DIRECTORY "tests/"

/*!
* Holds information about test suite. Implemented as
* linked list. \todo write better doc
Expand All @@ -62,52 +65,64 @@ typedef struct TestSuiteReference {
struct TestSuiteReference *next; //!< Pointer to next item in the list
} TestSuiteReference;

static TestSuiteReference *suites = NULL;

/*!
* 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
*
* \return Pointer to TestSuiteReference which holds all the info about suites
*/
TestSuiteReference *
ScanForTestSuites(/*char *directoryName*/) {
ScanForTestSuites(char *directoryName, char *extension) {
typedef struct dirent Entry;
DIR *directory = opendir("tests/");
DIR *directory = opendir(directoryName);

TestSuiteReference *suites = NULL;

Entry *entry = NULL;
if(directory) {
while(entry = readdir(directory)) {
if(entry->d_namlen > 2) { // discards . and ..
const int bufferSize = 1024;
char buffer[bufferSize];
memset(buffer, 0, bufferSize);

strcat(buffer, "tests/"); // \todo convert to define or something
char buffer[NAME_BUFFER_SIZE];
memset(buffer, 0, NAME_BUFFER_SIZE);

char *name = strtok(entry->d_name, ".");
char *extension = strtok(NULL, ".");
if(strcmp(extension, "dylib") == 0 || strcmp(extension, "so") == 0) {
char *ext = strtok(NULL, ".");

// 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) {
strcat(buffer, directoryName);
strcat(buffer, name);
strcat(buffer, ".");
strcat(buffer, extension);
strcat(buffer, ext);

// create tes suite reference
TestSuiteReference *reference = (TestSuiteReference *) SDL_malloc(sizeof(TestSuiteReference));
memset(reference, 0, sizeof(TestSuiteReference));

int length = strlen(buffer) + 1; // + 1 for '\0'?
reference->name = SDL_malloc(length * sizeof(char));

strcpy(reference->name, buffer);

reference->next = suites;

suites = reference;

// printf("Reference added to: %s\n", buffer)
printf("Reference added to: %s\n", buffer);
}
}
}
Expand Down Expand Up @@ -372,43 +387,6 @@ ParseOptions(int argc, char *argv[])
}


/*!
* Tests if the given test suite is selected for execution.
* If only_selected_suite flag is zero, then all the suites are
* automatically selected. If the flags is non-zero, only the suite
* which matches the selected suite is selected.
*
* \param testSuiteName Name of the test suite
*
* \return 1 if given suite is selected, otherwise 0
*/
int
SuiteIsSelected(char *testSuiteName) {
int retVal = 1;

if(only_selected_suite) {
// extract the suite name. Rips the tests/ and file extension from the suite name
char buffer[NAME_BUFFER_SIZE];
int len = strlen(testSuiteName);

const int dirNameLength = 6;
#if defined(linux) || defined( __linux)
const int fileExtLength = 3;
#else
const int fileExtLength = 6;
#endif
int length = len - dirNameLength - fileExtLength;

memset(buffer, 0, NAME_BUFFER_SIZE);
memcpy(buffer, testSuiteName + dirNameLength, length);

retVal = SDL_strncmp(selected_suite_name, buffer, NAME_BUFFER_SIZE) == 0;
}

return retVal;
}


/*!
* Entry point for test runner
*
Expand All @@ -426,50 +404,58 @@ main(int argc, char *argv[])
char *testSuiteName = NULL;
int suiteCounter = 0;

#if defined(linux) || defined( __linux)
char *extension = "so";
#else
char *extension = "dylib";
#endif

const Uint32 startTicks = SDL_GetTicks();
TestSuiteReference *suites = ScanForTestSuites();
TestSuiteReference *suites = ScanForTestSuites(DEFAULT_TEST_DIRECTORY, extension);

// load the suites
// load tests and filter them
// end result: list of tests to run

TestSuiteReference *suiteReference = NULL;
for(suiteReference = suites; suiteReference; suiteReference = suiteReference->next) {
char *testSuiteName = suiteReference->name;

// if the current suite isn't selected, go to next suite
if(SuiteIsSelected(testSuiteName)) {
void *suite = LoadTestSuite(testSuiteName);
TestCaseReference **tests = QueryTestCases(suite);

TestCaseReference *reference = NULL;
int counter = 0;
for(reference = tests[counter]; reference; reference = tests[++counter]) {
if(only_selected_test && SDL_strncmp(selected_test_name, reference->name, NAME_BUFFER_SIZE) != 0) {
continue;
}
void *suite = LoadTestSuite(testSuiteName);
TestCaseReference **tests = QueryTestCases(suite);

TestCaseReference *reference = NULL;
int counter = 0;
for(reference = tests[counter]; reference; reference = tests[++counter]) {
if(only_selected_test && SDL_strncmp(selected_test_name, reference->name, NAME_BUFFER_SIZE) != 0) {
continue;
}

if(reference->enabled == TEST_DISABLED) {
printf("Test %s (in %s) disabled. Omitting...\n", reference->name, testSuiteName);
} else {
printf("Executing %s (in %s):\n", reference->name, testSuiteName);
if(reference->enabled == TEST_DISABLED) {
printf("Test %s (in %s) disabled. Omitting...\n", reference->name, testSuiteName);
} else {
printf("Executing %s (in %s):\n", reference->name, testSuiteName);

int retVal = ExecuteTest(suite, reference);
int retVal = ExecuteTest(suite, reference);

if(retVal) {
failureCount++;
if(retVal == 2) {
printf("%s (in %s): FAILED -> No asserts\n", reference->name, testSuiteName);
} else {
printf("%s (in %s): FAILED\n", reference->name, testSuiteName);
}
if(retVal) {
failureCount++;
if(retVal == 2) {
printf("%s (in %s): FAILED -> No asserts\n", reference->name, testSuiteName);
} else {
passCount++;
printf("%s (in %s): ok\n", reference->name, testSuiteName);
printf("%s (in %s): FAILED\n", reference->name, testSuiteName);
}
} else {
passCount++;
printf("%s (in %s): ok\n", reference->name, testSuiteName);
}

printf("\n");
}

SDL_UnloadObject(suite);
printf("\n");
}

SDL_UnloadObject(suite);
}

const Uint32 endTicks = SDL_GetTicks();
Expand Down

0 comments on commit 691c1e2

Please sign in to comment.