Refactoring runner.c. Added --help/-h command line option.
This commit is contained in:
parent
de0a31c8fc
commit
75691b7b9f
1 changed files with 45 additions and 18 deletions
|
@ -30,23 +30,43 @@
|
||||||
//!< Function pointer to a test case function
|
//!< Function pointer to a test case function
|
||||||
typedef int (*TestCase)(void *arg);
|
typedef int (*TestCase)(void *arg);
|
||||||
|
|
||||||
|
//!< Flag for executing tests in-process
|
||||||
|
static int execute_inproc = 0;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Loads test suite which is implemented as dynamic library.
|
* Returns the name for the dynamic library
|
||||||
|
* which implements the test suite.
|
||||||
*
|
*
|
||||||
* \return Pointer to loaded test suite, or NULL if library could not be loaded
|
* (in the future: scans the test/ directory and
|
||||||
|
* returns the names of the dynamic libraries
|
||||||
|
* implementing the test suites)
|
||||||
|
*
|
||||||
|
* \return Name of the dummy test suite
|
||||||
*/
|
*/
|
||||||
void *
|
char *
|
||||||
LoadTestSuite()
|
ScanForTestSuites() {
|
||||||
{
|
|
||||||
#if defined(linux) || defined( __linux)
|
#if defined(linux) || defined( __linux)
|
||||||
char *libName = "tests/libtest.so";
|
char *libName = "tests/libtest.so";
|
||||||
#else
|
#else
|
||||||
char *libName = "tests/libtest.dylib";
|
char *libName = "tests/libtest.dylib";
|
||||||
#endif
|
#endif
|
||||||
|
return libName;
|
||||||
|
}
|
||||||
|
|
||||||
void *library = SDL_LoadObject(libName);
|
|
||||||
|
/*!
|
||||||
|
* Loads test suite which is implemented as dynamic library.
|
||||||
|
*
|
||||||
|
* \param test0,330
|
||||||
|
*
|
||||||
|
* \return Pointer to loaded test suite, or NULL if library could not be loaded
|
||||||
|
*/
|
||||||
|
void *
|
||||||
|
LoadTestSuite(char *testSuiteName)
|
||||||
|
{
|
||||||
|
void *library = SDL_LoadObject(testSuiteName);
|
||||||
if(library == NULL) {
|
if(library == NULL) {
|
||||||
fprintf(stderr, "Loading %s failed\n", libName);
|
fprintf(stderr, "Loading %s failed\n", testSuiteName);
|
||||||
fprintf(stderr, "%s\n", SDL_GetError());
|
fprintf(stderr, "%s\n", SDL_GetError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,11 +147,11 @@ HandleTestReturnValue(int stat_lock)
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//!< Flag for executing tests in-process
|
|
||||||
static int execute_inproc = 0;
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Parse command line arguments
|
* Parse command line arguments
|
||||||
|
*
|
||||||
|
* \param argc Count of command line arguments
|
||||||
|
* \param argv Array of commond lines arguments
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
ParseOptions(int argc, char *argv[])
|
ParseOptions(int argc, char *argv[])
|
||||||
|
@ -140,9 +160,17 @@ ParseOptions(int argc, char *argv[])
|
||||||
|
|
||||||
for (i = 1; i < argc; ++i) {
|
for (i = 1; i < argc; ++i) {
|
||||||
const char *arg = argv[i];
|
const char *arg = argv[i];
|
||||||
if (SDL_strcmp(arg, "--in-proc") == 0) {
|
if(SDL_strcmp(arg, "--in-proc") == 0) {
|
||||||
execute_inproc = 1;
|
execute_inproc = 1;
|
||||||
}
|
}
|
||||||
|
else if(SDL_strcmp(arg, "--help") == 0 || SDL_strcmp(arg, "-h") == 0) {
|
||||||
|
printf("Usage: ./runner [--in-proc] [--help]\n");
|
||||||
|
printf("Options:\n");
|
||||||
|
printf(" --in-proc Executes tests in-process\n");
|
||||||
|
printf(" --help Print this help.:\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
// \todo print error for unknown option
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,11 +189,10 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
int failureCount = 0, passCount = 0;
|
int failureCount = 0, passCount = 0;
|
||||||
|
|
||||||
char *libName = "libtest";
|
|
||||||
|
|
||||||
const Uint32 startTicks = SDL_GetTicks();
|
const Uint32 startTicks = SDL_GetTicks();
|
||||||
|
|
||||||
void *suite = LoadTestSuite();
|
char *testSuiteName = ScanForTestSuites();
|
||||||
|
void *suite = LoadTestSuite(testSuiteName);
|
||||||
TestCaseReference **tests = QueryTestCases(suite);
|
TestCaseReference **tests = QueryTestCases(suite);
|
||||||
|
|
||||||
TestCaseReference *reference = NULL;
|
TestCaseReference *reference = NULL;
|
||||||
|
@ -173,11 +200,11 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
for(reference = tests[counter]; reference; reference = tests[++counter]) {
|
for(reference = tests[counter]; reference; reference = tests[++counter]) {
|
||||||
if(reference->enabled == TEST_DISABLED) {
|
if(reference->enabled == TEST_DISABLED) {
|
||||||
printf("Test %s (in %s) disabled. Omitting...\n", reference->name, libName);
|
printf("Test %s (in %s) disabled. Omitting...\n", reference->name, testSuiteName);
|
||||||
} else {
|
} else {
|
||||||
char *testname = reference->name;
|
char *testname = reference->name;
|
||||||
|
|
||||||
printf("Running %s (in %s):\n", testname, libName);
|
printf("Running %s (in %s):\n", testname, testSuiteName);
|
||||||
|
|
||||||
int retVal = 1;
|
int retVal = 1;
|
||||||
if(execute_inproc) {
|
if(execute_inproc) {
|
||||||
|
@ -198,10 +225,10 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
if(retVal) {
|
if(retVal) {
|
||||||
failureCount++;
|
failureCount++;
|
||||||
printf("%s (in %s): FAILED\n", testname, libName);
|
printf("%s (in %s): FAILED\n", testname, testSuiteName);
|
||||||
} else {
|
} else {
|
||||||
passCount++;
|
passCount++;
|
||||||
printf("%s (in %s): ok\n", testname, libName);
|
printf("%s (in %s): ok\n", testname, testSuiteName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue