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

Commit

Permalink
Made run seed more file name friendly.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkauppila committed Jul 28, 2011
1 parent da41916 commit 8ed21cd
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 19 deletions.
2 changes: 2 additions & 0 deletions test/test-automation/build-scripts/install-tests.sh
Expand Up @@ -21,4 +21,6 @@ do
cp -f "$suite/.libs/lib$suite.$EXT" $DIRECTORY
done

sudo cp .libs/libtest.0.dylib /usr/local/lib/libtest.0.dylib

echo "Test suites installed."
19 changes: 16 additions & 3 deletions test/test-automation/plain_logger.c
Expand Up @@ -27,12 +27,17 @@ static FILE *logFile;
int
Output(const int currentIndentLevel, const char *message, ...)
{
if(logFile == NULL) {
fprintf(stderr, "logfile is NULL\n");
exit(3);
}

int indent = 0;
for( ; indent < currentIndentLevel; ++indent) {
fprintf(logFile, " "); // \todo make configurable?
}

char buffer[1024];
char buffer[1024];
memset(buffer, 0, 1024);

va_list list;
Expand All @@ -41,17 +46,22 @@ Output(const int currentIndentLevel, const char *message, ...)
SDL_vsnprintf(buffer, 1024, message, list);

va_end(list);

fprintf(logFile, "%s\n", buffer);
fflush(logFile);
}


void
PlainRunStarted(int parameterCount, char *runnerParameters[], char *runSeed,
time_t eventTime, LoggerData *data)
{
if(data == NULL) {
fprintf(stderr, "Logger data is NULL\n");
exit(3);
}

// Set up the logging destination
if(data->stdoutEnabled) {
if(data->stdoutEnabled == 1) {
logFile = stdout;
} else {
logFile = fopen(data->filename, "w");
Expand All @@ -61,6 +71,7 @@ PlainRunStarted(int parameterCount, char *runnerParameters[], char *runSeed,
}
}


level = data->level;
//printf("Debug: %d == %d\n", level, data->level);

Expand All @@ -87,6 +98,8 @@ PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCoun
Output(indentLevel, "%d tests passed", testPassCount);
Output(indentLevel, "%d tests failed", testFailCount);
Output(indentLevel, "%d tests skipped", testSkippedCount);

fclose(logFile);
}

void
Expand Down
48 changes: 32 additions & 16 deletions test/test-automation/runner.c
Expand Up @@ -77,7 +77,8 @@ static int universal_timeout_enabled = 0;
static int enable_verbose_logger = 0;
//! Flag for using user supplied run seed
static int userRunSeed = 0;

//! Whether or not logger should log to stdout instead of file
static int log_stdout_enabled = 0;

//!< Size of the test and suite name buffers
#define NAME_BUFFER_SIZE 1024
Expand Down Expand Up @@ -119,10 +120,6 @@ char *userExecKey = NULL;
//! How man time a test will be invocated
int testInvocationCount = 1;

//! Whether or not logger should log to stdout instead of file
static int log_stdout_enabled = 0;


//! Stores the basename for log files
char log_basename[NAME_BUFFER_SIZE];

Expand Down Expand Up @@ -859,9 +856,23 @@ GenerateRunSeed(const int length)
int counter = 0;
for( ; counter < length; ++counter) {
int number = abs(utl_random(&randomContext));
seed[counter] = (char) (number % (127 - 34)) + 34;
char ch = (char) (number % (122 - 48)) + 48;

// Remove all the special characters so the run seed
// can be used to form a valid filename.
// A lot more characters are skipped than necessary.
if(ch >= 58 && ch <= 64) {
ch = 65;
}
if(ch >= 91 && ch <= 96) {
ch = 97;
}

seed[counter] = ch;
}

seed[counter] = '\0';

return seed;
}

Expand All @@ -878,11 +889,12 @@ SetUpLogger()
fprintf(stderr, "Error: Logger data structure not allocated.");
return NULL;
}
memset(loggerData, 0, sizeof(LoggerData));

loggerData->level = (enable_verbose_logger ? VERBOSE : STANDARD);

if(log_stdout_enabled) {
loggerData->stdoutEnabled = SDL_TRUE;
if(log_stdout_enabled == 1) {
loggerData->stdoutEnabled = 1;
loggerData->filename = NULL;
} else {
const char *extension = (xml_enabled ? "xml": "log");
Expand Down Expand Up @@ -1037,6 +1049,7 @@ ParseOptions(int argc, char *argv[])
exit(1);
}

memset(log_directory, 0, NAME_BUFFER_SIZE);
memcpy(log_directory, dirString, SDL_strlen(dirString));
}
else if(SDL_strcmp(arg, "--logfile") == 0) {
Expand All @@ -1050,6 +1063,7 @@ ParseOptions(int argc, char *argv[])
exit(1);
}

memset(log_basename, 0, NAME_BUFFER_SIZE);
memcpy(log_basename, fileString, SDL_strlen(fileString));
}
else if(SDL_strcmp(arg, "--log-stdout") == 0) {
Expand Down Expand Up @@ -1241,23 +1255,24 @@ main(int argc, char *argv[])

RunStarted(argc, argv, runSeed, time(0), loggerData);

// logger data is no longer used
SDL_free(loggerData->filename);
SDL_free(loggerData);

/*
// validate the parsed command options
if(execute_inproc && universal_timeout_enabled) {
Log(time(0), "Test timeout is not supported with in-proc execution.");
Log(time(0), "Timeout will be disabled...");
universal_timeout_enabled = 0;
universal_timeout = -1;
}/*
}*/ /*
if(userExecKey && testInvocationCount > 1 || userRunSeed) {
printf("The given combination of command line options doesn't make sense\n");
printf("--exec-key should only be used to rerun failed fuzz tests\n");
}*/

// logger data is no longer used
SDL_free(loggerData->filename);
SDL_free(loggerData);

char *currentSuiteName = NULL;
int suiteStartTime = SDL_GetTicks();

Expand Down Expand Up @@ -1293,9 +1308,8 @@ main(int argc, char *argv[])
if(userExecKey != NULL) {
globalExecKey = userExecKey;
} else {
char *execKey = GenerateExecKey(runSeed, testItem->suiteName,
globalExecKey = GenerateExecKey(runSeed, testItem->suiteName,
testItem->testName, currentIteration);
globalExecKey = execKey;
}

TestStarted(testItem->testName, testItem->suiteName,
Expand All @@ -1311,10 +1325,12 @@ main(int argc, char *argv[])

currentIteration--;

/*
if(userExecKey != NULL) {
SDL_free(globalExecKey);
}
globalExecKey = NULL;
*/

}
}
Expand All @@ -1325,7 +1341,7 @@ main(int argc, char *argv[])
}

UnloadTestCases(testCases);
UnloadTestSuites(suites);
UnloadTestSuites(suites); // crashes here with -ts case1

const Uint32 endTicks = SDL_GetTicks();
const double totalRunTime = (endTicks - startTicks) / 1000.0f;
Expand Down
3 changes: 3 additions & 0 deletions test/test-automation/xml_logger.c
Expand Up @@ -257,6 +257,9 @@ XMLRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,

output = XMLCloseDocument(documentRoot);
XMLOutputter(--indentLevel, YES, output);

// close the log file
fclose(logFile);
}

void
Expand Down

0 comments on commit 8ed21cd

Please sign in to comment.