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

Commit

Permalink
Initial version of "scan tests/ for test suites" functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkauppila committed Jun 7, 2011
1 parent cb587e7 commit 8564619
Showing 1 changed file with 68 additions and 19 deletions.
87 changes: 68 additions & 19 deletions test/test-automation/runner.c
Expand Up @@ -24,6 +24,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <dirent.h>

#include <sys/types.h>

Expand All @@ -45,33 +46,78 @@ static int only_selected_test = 0;
static int only_selected_suite = 0;

//<! Size of the test and suite name buffers
#define NAME_BUFFER_SIZE 256
#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];

//!< Temporary array to hold test suite names
#if defined(linux) || defined( __linux)
char *testSuites[] = { "tests/libtestdummy.so", "tests/libtestrect.so", NULL};
#else
char *testSuites[] = { "tests/libtestdummy.dylib", "tests/libtestrect.dylib", NULL};
#endif

/*!
* Holds information about test suite. Implemented as
* linked list. \todo write better doc
*/
typedef struct TestSuiteReference {
char *name; //<! test suite name
struct TestSuiteReference *next; //!< Pointer to next item in the list
} TestSuiteReference;

static TestSuiteReference *suites = NULL;

/*!
* Returns the name for the dynamic library
* which implements the test suite.
* 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.
*
* (in the future: scans the test/ directory and
* returns the names of the dynamic libraries
* implementing the test suites)
*
* \return Array of test suite names
* \return Pointer to TestSuiteReference which holds all the info about suites
*/
char **
ScanForTestSuites() {
return testSuites;
TestSuiteReference *
ScanForTestSuites(/*char *directoryName*/) {
typedef struct dirent Entry;
DIR *directory = opendir("tests/");

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 *name = strtok(entry->d_name, ".");
char *extension = strtok(NULL, ".");
if(strcmp(extension, "dylib") == 0 || strcmp(extension, "so") == 0) {
strcat(buffer, name);
strcat(buffer, ".");
strcat(buffer, extension);

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)
}
}
}

closedir(directory);
} else {
perror("Couldn't open directory: tests/");
}

return suites;
}


Expand Down Expand Up @@ -381,9 +427,12 @@ main(int argc, char *argv[])
int suiteCounter = 0;

const Uint32 startTicks = SDL_GetTicks();
char **testSuiteNames = ScanForTestSuites();
TestSuiteReference *suites = ScanForTestSuites();

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

for(testSuiteName = testSuiteNames[suiteCounter]; testSuiteName; testSuiteName = testSuiteNames[++suiteCounter]) {
// if the current suite isn't selected, go to next suite
if(SuiteIsSelected(testSuiteName)) {
void *suite = LoadTestSuite(testSuiteName);
Expand Down

0 comments on commit 8564619

Please sign in to comment.