5 // Copyright (c) 2011 Apple Inc.
\r
17 #include "TestList.h"
\r
18 #include "LinearMath/btScalar.h"
\r
20 #if defined (BT_USE_NEON) || defined (BT_USE_SSE_IN_API)
\r
23 #define strcasecmp _stricmp
\r
24 #define basename(A) A
\r
27 #define EXIT_NO_ERROR INT_MIN
\r
29 //int gReportNanoseconds = 0; // in Utils.c
\r
31 int gReportAverageTimes = 0;
\r
32 int gExitOnError = 0;
\r
33 char *gFullPath = NULL;
\r
34 const char *gAppName = NULL;
\r
38 typedef struct TestNode
\r
40 struct TestNode *next;
\r
44 TestNode *gNodeList = NULL;
\r
46 static int ParseArgs( int argc, const char *argv[] );
\r
47 static void PrintUsage( void );
\r
48 static int Init( void );
\r
49 static void ListTests(void );
\r
51 const char *gArch =
\r
54 #elif defined __x86_64__
\r
56 #elif defined __arm__
\r
58 #elif defined _WIN64
\r
60 #elif defined _WIN32
\r
72 int main (int argc, const char * argv[])
\r
75 // Enable just one test programatically (instead of command-line param)
\r
76 // TestNode *node = (TestNode*) malloc( sizeof( TestNode ) );
\r
77 // node->name = "btDbvt";
\r
79 // gNodeList = node;
\r
83 int numPassedTests=0;
\r
84 int numFailedTests= 0;
\r
88 // Parse arguments. Build gNodeList.
\r
89 if( (err = ParseArgs( argc, argv ) ) )
\r
91 if( EXIT_NO_ERROR == err )
\r
98 printf("Arch: %s\n", gArch );
\r
100 if( gReportAverageTimes )
\r
101 printf( "Reporting average times.\n" );
\r
103 printf( "Reporting best times.\n" );
\r
105 // Set a few things up
\r
106 if( (err = Init() ))
\r
108 printf( "Init failed.\n" );
\r
112 if( NULL == gNodeList )
\r
113 { // test everything
\r
114 printf( "No function list found. Testing everything...\n" );
\r
116 for( i = 0; NULL != gTestList[i].test_func; i++ )
\r
118 printf( "\n----------------------------------------------\n" );
\r
119 printf( "Testing %s:\n", gTestList[i].name );
\r
120 printf( "----------------------------------------------\n" );
\r
121 uint64_t startTime = ReadTicks();
\r
122 int local_error = gTestList[i].test_func();
\r
123 uint64_t currentTime = ReadTicks() - startTime;
\r
127 printf( "*** %s test failed with error: %d\n", gTestList[i].name, local_error );
\r
129 return local_error;
\r
136 printf("%s Passed.\t\t\t(%2.2gs)\n", gTestList[i].name, TicksToSeconds(currentTime));
\r
141 { // test just the list
\r
142 while( NULL != gNodeList )
\r
144 TestNode *currentNode = gNodeList;
\r
145 gNodeList = gNodeList->next;
\r
147 // Find the test with that name
\r
149 for( i = 0; NULL != gTestList[i].test_func; i++ )
\r
150 if( 0 == strcasecmp( currentNode->name, gTestList[i].name ) )
\r
153 if( NULL != gTestList[i].test_func )
\r
155 printf( "\n----------------------------------------------\n" );
\r
156 printf( "Testing %s:\n", gTestList[i].name );
\r
157 printf( "----------------------------------------------\n" );
\r
158 uint64_t startTime = ReadTicks();
\r
159 int local_error = gTestList[i].test_func();
\r
160 uint64_t currentTime = ReadTicks() - startTime;
\r
164 printf( "*** %s test failed with error: %d\n", gTestList[i].name, local_error );
\r
166 return local_error;
\r
173 printf("%s Passed.\t\t\t(%2.2gs)\n", gTestList[i].name, TicksToSeconds(currentTime));
\r
178 printf( "\n***Error: Test name \"%s\" not found! Skipping.\n", currentNode->name );
\r
184 free( currentNode );
\r
187 printf( "\n----------------------------------------------\n" );
\r
188 printf("numPassedTests = %d, numFailedTests = %d\n",numPassedTests,numFailedTests);
\r
194 static int Init( void )
\r
202 static int ParseArgs( int argc, const char *argv[] )
\r
205 TestNode *list = NULL;
\r
209 gFullPath = (char*)malloc( strlen(argv[0]) + 1);
\r
210 strcpy(gFullPath, argv[0]);
\r
211 gAppName = basename( gFullPath );
\r
212 if( NULL == gAppName )
\r
213 gAppName = "<unknown app name>";
\r
215 printf( "%s ", gAppName );
\r
216 int skipremaining=0;
\r
219 for( i = 1; i < argc; i++ )
\r
221 const char *arg = argv[i];
\r
222 printf( "\t%s", arg );
\r
223 if( arg[0] == '-' )
\r
226 while( arg[0] != '\0' )
\r
232 gReportAverageTimes ^= 1;
\r
239 return EXIT_NO_ERROR;
\r
242 return EXIT_NO_ERROR;
\r
244 gReportNanoseconds ^= 1;
\r
249 case 'N'://ignore the -NSDocumentRevisionsDebugMode argument from XCode 4.3.2
\r
254 printf( "\nError: Unknown flag \'%c\'\n", arg[0] );
\r
263 { // add function name to the list
\r
264 TestNode *node = (TestNode*) malloc( sizeof( TestNode ) );
\r
273 // reverse the list of test names, and stick on gNodeList
\r
276 TestNode *node = list;
\r
277 TestNode *next = node->next;
\r
278 node->next = gNodeList;
\r
291 static void PrintUsage( void )
\r
293 printf("\nUsage:\n" );
\r
294 printf("%s: <-aehls> <test names>", gAppName);
\r
295 printf("Options:\n");
\r
296 printf("\t-a\tToggle report average times vs. best times. (Default: best times)\n");
\r
297 printf("\t-e\tToggle exit immediately on error behavior. (Default: off)\n");
\r
298 printf("\t-h\tPrint this message.\n");
\r
299 printf("\t-l\tToggle list available test names. (Default: off)\n");
\r
300 printf("\t-s\tToggle report times in cycles or nanoseconds. (Default: cycles)\n\n");
\r
301 printf("\tOptions may be followed by one or more test names. If no test names \n" );
\r
302 printf("\tare provided, then all tests are run.\n\n");
\r
305 static void ListTests(void )
\r
309 printf("\nTests:\n");
\r
310 for( i = 0; NULL != gTestList[i].test_func; i++ )
\r
312 printf( "%19s", gTestList[i].name );
\r
313 if( NULL != gTestList[i].test_func )
\r
321 int main(int argc, char* argv[])
\r
323 printf("error: no SIMD enabled through BT_USE_NEON or BT_USE_SSE_IN_API \n(enable in LinearMath/btScalar.h or through build system)\n");
\r