-#include <stdio.h>
#include <string.h>
+#include <getopt.h>
+#include <stdlib.h>
+#include <test-harness.h>
#include "tct-dali-core.h"
-int main(int argc, const char *argv[])
+int main(int argc, char * const argv[])
{
- int result = -1;
- int i;
+ int result = TestHarness::EXIT_STATUS_BAD_ARGUMENT;
- if (argc != 2) {
- printf("Usage: %s <testcase name>\n", argv[0]);
- return 2;
- }
-
- for (i = 0; tc_array[i].name; i++) {
- if (!strcmp(argv[1], tc_array[i].name)) {
- if (tc_array[i].startup)
- tc_array[i].startup();
-
- result = tc_array[i].function();
+ const char* optString = "rs";
+ bool optRerunFailed(true);
+ bool optRunSerially(false);
- if (tc_array[i].cleanup)
- tc_array[i].cleanup();
-
- return result;
- }
+ int nextOpt = 0;
+ do
+ {
+ nextOpt = getopt( argc, argv, optString );
+ switch(nextOpt)
+ {
+ case 'r':
+ optRerunFailed = true;
+ break;
+ case 's':
+ optRunSerially = true;
+ break;
+ case '?':
+ TestHarness::Usage(argv[0]);
+ exit(TestHarness::EXIT_STATUS_BAD_ARGUMENT);
+ break;
}
+ } while( nextOpt != -1 );
- printf("Unknown testcase name: \"%s\"\n", argv[1]);
- return 2;
+ if( optind == argc ) // no testcase name in argument list
+ {
+ if( optRunSerially )
+ {
+ result = TestHarness::RunAll( argv[0], tc_array );
+ }
+ else
+ {
+ result = TestHarness::RunAllInParallel( argv[0], tc_array, optRerunFailed );
+ }
+ }
+ else
+ {
+ // optind is index of next argument - interpret as testcase name
+ result = TestHarness::FindAndRunTestCase(tc_array, argv[optind]);
+ }
+ return result;
}