From 69934819b816a8e60d232dcd2a8ae67c4c37b4dc Mon Sep 17 00:00:00 2001 From: Markus Kauppila Date: Thu, 9 Jun 2011 16:37:51 +0300 Subject: [PATCH] Creating pipeline for test case selection. Work in progress. --- test/test-automation/runner.c | 273 ++++++++++++++------- test/test-automation/testdummy/testdummy.c | 3 + 2 files changed, 187 insertions(+), 89 deletions(-) diff --git a/test/test-automation/runner.c b/test/test-automation/runner.c index f81dd3b05..24d1b1556 100644 --- a/test/test-automation/runner.c +++ b/test/test-automation/runner.c @@ -61,10 +61,22 @@ char selected_suite_name[NAME_BUFFER_SIZE]; * linked list. \todo write better doc */ typedef struct TestSuiteReference { - char *name; //d_namlen > 2) { // discards . and .. - char buffer[NAME_BUFFER_SIZE]; - memset(buffer, 0, NAME_BUFFER_SIZE); + if(!directory) { + perror("Couldn't open directory: tests/"); + } - char *name = strtok(entry->d_name, "."); - char *ext = strtok(NULL, "."); + while(entry = readdir(directory)) { + if(entry->d_namlen > 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; - } + // 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, ext); + if(ok && SDL_strcmp(ext, extension) == 0) { + char buffer[NAME_BUFFER_SIZE]; + memset(buffer, 0, NAME_BUFFER_SIZE); - // create tes suite reference - TestSuiteReference *reference = (TestSuiteReference *) SDL_malloc(sizeof(TestSuiteReference)); - memset(reference, 0, sizeof(TestSuiteReference)); + strcat(buffer, directoryName); + strcat(buffer, name); + strcat(buffer, "."); + strcat(buffer, ext); - int length = strlen(buffer) + 1; // + 1 for '\0'? - reference->name = SDL_malloc(length * sizeof(char)); + // create test suite reference + TestSuiteReference *reference = (TestSuiteReference *) SDL_malloc(sizeof(TestSuiteReference)); + memset(reference, 0, sizeof(TestSuiteReference)); - strcpy(reference->name, buffer); + int length = strlen(buffer) + 1; // + 1 for '\0'? + reference->name = SDL_malloc(length * sizeof(char)); - reference->next = suites; + strcpy(reference->name, buffer); - suites = reference; + reference->next = suites; + suites = reference; - printf("Reference added to: %s\n", buffer); - } + printf("Reference added to: %s\n", buffer); } } - - closedir(directory); - } else { - perror("Couldn't open directory: tests/"); } + closedir(directory); + return suites; } @@ -281,26 +293,22 @@ HandleTestReturnValue(int stat_lock) * \return The return value of the test. Zero means success, non-zero failure. */ int -ExecuteTest(void *suite, TestCaseReference *testReference) { - TestCaseInit testCaseInit = LoadTestCaseInit(suite); - TestCaseQuit testCaseQuit = LoadTestCaseQuit(suite); - TestCase test = (TestCase) LoadTestCase(suite, testReference->name); - +ExecuteTest(TestCaseItem *testItem) { int retVal = 1; if(execute_inproc) { - testCaseInit(); + testItem->testCaseInit(); - test(0x0); + testItem->testCase(0x0); - retVal = testCaseQuit(); + retVal = testItem->testCaseQuit(); } else { int childpid = fork(); if(childpid == 0) { - testCaseInit(); + testItem->testCaseInit(); - test(0x0); + testItem->testCase(0x0); - exit(testCaseQuit()); + exit(testItem->testCaseQuit()); } else { int stat_lock = -1; int child = wait(&stat_lock); @@ -387,6 +395,118 @@ ParseOptions(int argc, char *argv[]) } +/*! + * \todo add comment + */ +TestCaseItem * +LoadTestCases(TestSuiteReference *suites) { + TestCaseItem *testCases = NULL; + + TestSuiteReference *suiteReference = NULL; + for(suiteReference = suites; suiteReference; suiteReference = suiteReference->next) { + TestCaseReference **tests = QueryTestCases(suiteReference->library); + + TestCaseReference *testReference = NULL; + int counter = 0; + for(testReference = tests[counter]; testReference; testReference = tests[++counter]) { + + void *suite = suiteReference->library; + // Load test case functions + TestCaseInit testCaseInit = LoadTestCaseInit(suiteReference->library); + TestCaseQuit testCaseQuit = LoadTestCaseQuit(suiteReference->library); + TestCase testCase = (TestCase) LoadTestCase(suiteReference->library, testReference->name); + + // Do the filtering + if(FilterTestCase(testReference)) { + //!< \todo deallocate these + TestCaseItem *item = SDL_malloc(sizeof(TestCaseItem)); + memset(item, 0, sizeof(TestCaseItem)); + + item->testCaseInit = testCaseInit; + item->testCase = testCase; + item->testCaseQuit = testCaseQuit; + + // prepend the list + item->next = testCases; + testCases = item; + + printf("Added test: %s\n", testReference->name); + } + } + } + + return testCases; +} + +/*! + * \todo add comment + */ +void +UnloadTestCases(TestCaseItem *item) { + TestCaseItem *ref = item; + while(ref) { + TestCaseItem *temp = ref->next; + SDL_free(ref); + ref = temp; + } + + item = NULL; +} + +/*! + * \todo add comment + */ +int +FilterTestCase(TestCaseReference *testReference) { + //int retVal = 1; + + if(testReference->enabled == TEST_DISABLED) { + //retVal = 0; + return 0; + } + + if(1 && strstr(testReference->name, "rect") != NULL) { + //retVal = 1; + return 1; + } else { + return 0; + } + + return 1; +} + +/*! + * \todo add comment + */ +TestSuiteReference * +LoadTestSuites(TestSuiteReference *suites) { + TestSuiteReference *reference = NULL; + for(reference = suites; reference; reference = reference->next) { + reference->library = LoadTestSuite(reference->name); + } + + return suites; +} + + +/*! + * \todo add comment + */ +void UnloadTestSuites(TestSuiteReference *suites) { + TestSuiteReference *ref = suites; + while(ref) { + SDL_free(ref->name); + SDL_UnloadObject(ref->library); + + TestSuiteReference *temp = ref->next; + SDL_free(ref); + ref = temp; + } + + suites = NULL; +} + + /*! * Entry point for test runner * @@ -411,53 +531,37 @@ main(int argc, char *argv[]) #endif const Uint32 startTicks = SDL_GetTicks(); + TestSuiteReference *suites = ScanForTestSuites(DEFAULT_TEST_DIRECTORY, extension); + suites = LoadTestSuites(suites); - // 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 - 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; - } + TestCaseItem *testCases = LoadTestCases(suites); - if(reference->enabled == TEST_DISABLED) { - printf("Test %s (in %s) disabled. Omitting...\n", reference->name, testSuiteName); + // end result: list of tests to run + TestCaseItem *testItem = NULL; + for(testItem = testCases; testItem; testItem = testItem->next) { + int retVal = ExecuteTest(testItem); + + if(retVal) { + failureCount++; + if(retVal == 2) { + //printf("%s (in %s): FAILED -> No asserts\n", reference->name, testSuiteName); + printf("%s (in %s): FAILED -> No asserts\n", "", ""); } else { - printf("Executing %s (in %s):\n", reference->name, testSuiteName); - - 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); - } - } else { - passCount++; - printf("%s (in %s): ok\n", reference->name, testSuiteName); - } + printf("%s (in %s): FAILED\n", "", ""); } - - printf("\n"); + } else { + passCount++; + printf("%s (in %s): ok\n", "", ""); } - SDL_UnloadObject(suite); + printf("\n"); } + UnloadTestCases(testCases); + UnloadTestSuites(suites); + const Uint32 endTicks = SDL_GetTicks(); printf("Ran %d tests in %0.5f seconds.\n", (passCount + failureCount), (endTicks-startTicks)/1000.0f); @@ -465,15 +569,6 @@ main(int argc, char *argv[]) printf("%d tests passed\n", passCount); printf("%d tests failed\n", failureCount); - // Deallocate the memory used by test suites - TestSuiteReference *ref = suites; - while(ref) { - SDL_free(ref->name); - - TestSuiteReference *temp = ref->next; - SDL_free(ref); - ref = temp; - } return 0; } diff --git a/test/test-automation/testdummy/testdummy.c b/test/test-automation/testdummy/testdummy.c index 1a5558aa2..1d2b6553f 100644 --- a/test/test-automation/testdummy/testdummy.c +++ b/test/test-automation/testdummy/testdummy.c @@ -60,6 +60,7 @@ void dummycase1(void *arg) { const char *revision = SDL_GetRevision(); + printf("Dummycase 1\n"); printf("Revision is %s\n", revision); AssertEquals(3, 5, "fails"); @@ -69,11 +70,13 @@ void dummycase2(void *arg) { char *msg = "eello"; //msg[0] = 'H'; + printf("Dummycase 2\n"); AssertTrue(0, "fails"); } void dummycase3(void *arg) { + printf("Dummycase 3\n"); AssertTrue(1, "passes"); }