From fa223b690b444856b1dbe3c0c5a25b43cc1062d2 Mon Sep 17 00:00:00 2001 From: Markus Kauppila Date: Sun, 5 Jun 2011 16:10:10 +0300 Subject: [PATCH] Possible to execute only selected tests or suites. --- test/test-automation/runner.c | 64 ++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/test/test-automation/runner.c b/test/test-automation/runner.c index 655512950..524d0a907 100644 --- a/test/test-automation/runner.c +++ b/test/test-automation/runner.c @@ -23,6 +23,8 @@ #include #include #include +#include + #include #include "SDL_test.h" @@ -37,6 +39,17 @@ typedef int (*TestCaseQuit)(void); //!< Flag for executing tests in-process static int execute_inproc = 0; +//!< 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; + +//name; - TestCaseInit testCaseInit = LoadTestCaseInit(suite); TestCaseQuit testCaseQuit = LoadTestCaseQuit(suite); - TestCase test = (TestCase) LoadTestCase(suite, testname); + TestCase test = (TestCase) LoadTestCase(suite, testReference->name); int retVal = 1; if(execute_inproc) { @@ -246,6 +262,7 @@ void printUsage() { printf(" --help Print this help\n"); } + /*! * Parse command line arguments * @@ -265,7 +282,22 @@ ParseOptions(int argc, char *argv[]) else if(SDL_strcmp(arg, "--help") == 0 || SDL_strcmp(arg, "-h") == 0) { printUsage(); exit(0); - } else { + } + else if(SDL_strcmp(arg, "--test") == 0 || SDL_strcmp(arg, "-t") == 0) { + only_selected_test = 1; + char *testName = argv[++i]; //!< \todo fixme what if i == argc? segfault? + + memset(selected_test_name, 0, NAME_BUFFER_SIZE); // unnecessary? + strcpy(selected_test_name, testName); + } + else if(SDL_strcmp(arg, "--suite") == 0 || SDL_strcmp(arg, "-s") == 0) { + only_selected_suite = 1; + char *suiteName = argv[++i]; //!< \todo fixme what if i == argc? segfault? + + memset(selected_suite_name, 0, NAME_BUFFER_SIZE); // unnecessary? + strcpy(selected_suite_name, suiteName); + } + else { printf("runner: unknown command '%s'\n", arg); printUsage(); exit(0); @@ -273,6 +305,7 @@ ParseOptions(int argc, char *argv[]) } } + /*! * Entry point for test runner * @@ -295,13 +328,34 @@ main(int argc, char *argv[]) char *testSuiteName = NULL; int suiteCounter = 0; for(testSuiteName = testSuiteNames[suiteCounter]; testSuiteName; testSuiteName = testSuiteNames[++suiteCounter]) { + + if(only_selected_suite) { + // extract the suite name. Rips the tests/ and file suffix from the suite name + char buffer[32]; + int len = strlen(testSuiteName); + int copy = len - 6 - 6; + memcpy(buffer, testSuiteName + 6, copy); + //printf("%s\n", buffer); + //char *name = strndup(testSuiteName[5], 32); + + if(SDL_strncmp(selected_suite_name, buffer, 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) { + if(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 {