Removed directory from test suite names.
authorMarkus Kauppila
Thu, 30 Jun 2011 18:11:48 +0300
changeset 572927be98c43bbc
parent 5728 7cf47cdaf4ab
child 5730 5c094958a62f
Removed directory from test suite names.
test/test-automation/runner.c
     1.1 --- a/test/test-automation/runner.c	Thu Jun 30 17:11:39 2011 +0300
     1.2 +++ b/test/test-automation/runner.c	Thu Jun 30 18:11:48 2011 +0300
     1.3 @@ -114,78 +114,6 @@
     1.4  
     1.5  
     1.6  /*!
     1.7 - * Scans the tests/ directory and returns the names
     1.8 - * of the dynamic libraries implementing the test suites.
     1.9 - *
    1.10 - * Note: currently function assumes that test suites names
    1.11 - * are in following format: libtestsuite.dylib or libtestsuite.so.
    1.12 - *
    1.13 - * Note: if only_selected_suite flags is non-zero, only the selected
    1.14 - * test will be loaded.
    1.15 - *
    1.16 - * \param directoryName Name of the directory which will be scanned
    1.17 - * \param extension What file extension is used with dynamic objects
    1.18 - *
    1.19 - * \return Pointer to TestSuiteReference which holds all the info about suites
    1.20 - */
    1.21 -TestSuiteReference *
    1.22 -ScanForTestSuites(char *directoryName, char *extension)
    1.23 -{
    1.24 -	typedef struct dirent Entry;
    1.25 -	DIR *directory = opendir(directoryName);
    1.26 -
    1.27 -	TestSuiteReference *suites = NULL;
    1.28 -
    1.29 -	Entry *entry = NULL;
    1.30 -	if(!directory) {
    1.31 -		perror("Couldn't open test suite directory!");
    1.32 -	}
    1.33 -
    1.34 -	while(entry = readdir(directory)) {
    1.35 -		if(strlen(entry->d_name) > 2) { // discards . and ..
    1.36 -			const char *delimiters = ".";
    1.37 -			char *name = strtok(entry->d_name, delimiters);
    1.38 -			char *ext = strtok(NULL, delimiters);
    1.39 -
    1.40 -			// filter out all other suites but the selected test suite
    1.41 -			int ok = 1;
    1.42 -			if(only_selected_suite) {
    1.43 -				ok = SDL_strncmp(selected_suite_name, name, NAME_BUFFER_SIZE) == 0;
    1.44 -			}
    1.45 -
    1.46 -			if(ok && SDL_strcmp(ext, extension)  == 0) {
    1.47 -				char buffer[NAME_BUFFER_SIZE];
    1.48 -				memset(buffer, 0, NAME_BUFFER_SIZE);
    1.49 -
    1.50 -				strcat(buffer, directoryName);
    1.51 -				strcat(buffer, name);
    1.52 -				strcat(buffer, ".");
    1.53 -				strcat(buffer, ext);
    1.54 -
    1.55 -				// create test suite reference
    1.56 -				TestSuiteReference *reference = (TestSuiteReference *) SDL_malloc(sizeof(TestSuiteReference));
    1.57 -				memset(reference, 0, sizeof(TestSuiteReference));
    1.58 -
    1.59 -				int length = strlen(buffer) + 1; // + 1 for '\0'?
    1.60 -				reference->name = SDL_malloc(length * sizeof(char));
    1.61 -
    1.62 -				strcpy(reference->name, buffer);
    1.63 -
    1.64 -				reference->next = suites;
    1.65 -				suites = reference;
    1.66 -
    1.67 -				//printf("Reference added to: %s\n", buffer);
    1.68 -			}
    1.69 -		}
    1.70 -	}
    1.71 -
    1.72 -	closedir(directory);
    1.73 -
    1.74 -	return suites;
    1.75 -}
    1.76 -
    1.77 -
    1.78 -/*!
    1.79   * Goes through the previously loaded test suites and
    1.80   * loads test cases from them. Test cases are filtered
    1.81   * during the process. Function will only return the
    1.82 @@ -315,6 +243,79 @@
    1.83  
    1.84  
    1.85  /*!
    1.86 + * Scans the tests/ directory and returns the names
    1.87 + * of the dynamic libraries implementing the test suites.
    1.88 + *
    1.89 + * Note: currently function assumes that test suites names
    1.90 + * are in following format: libtestsuite.dylib or libtestsuite.so.
    1.91 + *
    1.92 + * Note: if only_selected_suite flags is non-zero, only the selected
    1.93 + * test will be loaded.
    1.94 + *
    1.95 + * \param directoryName Name of the directory which will be scanned
    1.96 + * \param extension What file extension is used with dynamic objects
    1.97 + *
    1.98 + * \return Pointer to TestSuiteReference which holds all the info about suites
    1.99 + */
   1.100 +TestSuiteReference *
   1.101 +ScanForTestSuites(char *directoryName, char *extension)
   1.102 +{
   1.103 +	typedef struct dirent Entry;
   1.104 +	DIR *directory = opendir(directoryName);
   1.105 +
   1.106 +	TestSuiteReference *suites = NULL;
   1.107 +
   1.108 +	Entry *entry = NULL;
   1.109 +	if(!directory) {
   1.110 +		perror("Couldn't open test suite directory!");
   1.111 +	}
   1.112 +
   1.113 +	while(entry = readdir(directory)) {
   1.114 +		if(strlen(entry->d_name) > 2) { // discards . and ..
   1.115 +			const char *delimiters = ".";
   1.116 +			char *name = strtok(entry->d_name, delimiters);
   1.117 +			char *ext = strtok(NULL, delimiters);
   1.118 +
   1.119 +			// filter out all other suites but the selected test suite
   1.120 +			int ok = 1;
   1.121 +			if(only_selected_suite) {
   1.122 +				ok = SDL_strncmp(selected_suite_name, name, NAME_BUFFER_SIZE) == 0;
   1.123 +			}
   1.124 +
   1.125 +			if(ok && SDL_strcmp(ext, extension)  == 0) {
   1.126 +				char buffer[NAME_BUFFER_SIZE];
   1.127 +				memset(buffer, 0, NAME_BUFFER_SIZE);
   1.128 +
   1.129 +				//! \todo change strcat's to strncats
   1.130 +				//strcat(buffer, directoryName);
   1.131 +				strcat(buffer, name);
   1.132 +				strcat(buffer, ".");
   1.133 +				strcat(buffer, ext);
   1.134 +
   1.135 +				// create test suite reference
   1.136 +				TestSuiteReference *reference = (TestSuiteReference *) SDL_malloc(sizeof(TestSuiteReference));
   1.137 +				memset(reference, 0, sizeof(TestSuiteReference));
   1.138 +
   1.139 +				int length = strlen(buffer) + 1; // + 1 for '\0'?
   1.140 +				reference->name = SDL_malloc(length * sizeof(char));
   1.141 +
   1.142 +				strcpy(reference->name, buffer);
   1.143 +
   1.144 +				reference->next = suites;
   1.145 +				suites = reference;
   1.146 +
   1.147 +				//printf("Reference added to: %s\n", buffer);
   1.148 +			}
   1.149 +		}
   1.150 +	}
   1.151 +
   1.152 +	closedir(directory);
   1.153 +
   1.154 +	return suites;
   1.155 +}
   1.156 +
   1.157 +
   1.158 +/*!
   1.159   * Loads test suite which is implemented as dynamic library.
   1.160   *
   1.161   * \param testSuiteName Name of the test suite which will be loaded
   1.162 @@ -322,9 +323,16 @@
   1.163   * \return Pointer to loaded test suite, or NULL if library could not be loaded
   1.164   */
   1.165  void *
   1.166 -LoadTestSuite(char *testSuiteName)
   1.167 +LoadTestSuite(const char *directory, const char *testSuiteName)
   1.168  {
   1.169 -	void *library = SDL_LoadObject(testSuiteName);
   1.170 +	const int nameSize = SDL_strlen(testSuiteName);
   1.171 +	const int dirSize = SDL_strlen(directory);
   1.172 +	const int size = nameSize + dirSize+ 1;
   1.173 +
   1.174 +	char *directoryPath = SDL_malloc(size);
   1.175 +	snprintf(directoryPath, size, "%s%s", directory, testSuiteName);
   1.176 +
   1.177 +	void *library = SDL_LoadObject(directoryPath);
   1.178  	if(library == NULL) {
   1.179  		fprintf(stderr, "Loading %s failed\n", testSuiteName);
   1.180  		fprintf(stderr, "%s\n", SDL_GetError());
   1.181 @@ -344,11 +352,11 @@
   1.182   * \return Updated TestSuiteReferences with pointer to loaded libraries
   1.183   */
   1.184  TestSuiteReference *
   1.185 -LoadTestSuites(TestSuiteReference *suites)
   1.186 +LoadTestSuites(const char *directory, TestSuiteReference *suites)
   1.187  {
   1.188  	TestSuiteReference *reference = NULL;
   1.189  	for(reference = suites; reference; reference = reference->next) {
   1.190 -		reference->library = LoadTestSuite(reference->name);
   1.191 +		reference->library = LoadTestSuite(directory, reference->name);
   1.192  	}
   1.193  
   1.194  	return suites;
   1.195 @@ -535,12 +543,13 @@
   1.196  void
   1.197  printUsage() {
   1.198  	  printf("Usage: ./runner [--in-proc] [--suite SUITE] [--test TEST]\n");
   1.199 -	  printf("                [--name-contains SUBSTR] [--help]\n");
   1.200 +	  printf("                [--name-contains SUBSTR] [--show-tests\n");
   1.201 +	  printf("                [--xml] [--xsl STYLESHEET] [--help]\n");
   1.202  	  printf("Options:\n");
   1.203  	  printf("     --in-proc                Executes tests in-process\n");
   1.204  	  printf("     --show-tests             Prints out all the executable tests\n");
   1.205  	  printf("     --xml             		Enables XML logger\n");
   1.206 -	  printf("     --xsl FILENAME     		Use the given file as XSL style sheet for XML\n"); // \todo add to wiki
   1.207 +	  printf("     --xsl STYLESHEET    		Use the given file as XSL style sheet for XML\n");
   1.208  	  printf(" -t  --test TEST              Executes only tests with given name\n");
   1.209  	  printf(" -ts --name-contains SUBSTR   Executes only tests that have given\n");
   1.210  	  printf("                              substring in test name\n");
   1.211 @@ -668,6 +677,7 @@
   1.212  #else
   1.213  	char *extension = "dylib";
   1.214  #endif
   1.215 +
   1.216  	if(xml_enabled) {
   1.217  		SetupXMLLogger();
   1.218  
   1.219 @@ -681,7 +691,7 @@
   1.220  	const Uint32 startTicks = SDL_GetTicks();
   1.221  
   1.222  	TestSuiteReference *suites = ScanForTestSuites(DEFAULT_TEST_DIRECTORY, extension);
   1.223 -	suites = LoadTestSuites(suites);
   1.224 +	suites = LoadTestSuites(DEFAULT_TEST_DIRECTORY, suites);
   1.225  
   1.226  	TestCase *testCases = LoadTestCases(suites);
   1.227  
   1.228 @@ -689,7 +699,6 @@
   1.229  	if(only_print_tests) {
   1.230  		TestCase *testItem = NULL;
   1.231  		for(testItem = testCases; testItem; testItem = testItem->next) {
   1.232 -			//! \todo This should be handled by the logging system?
   1.233  			printf("%s (in %s)\n", testItem->testName, testItem->suiteName);
   1.234  		}
   1.235