+ test_return_t return_code;
+ unsigned int x;
+ char *collection_to_run= NULL;
+ char *wildcard= NULL;
+ world_st world;
+ collection_st *collection;
+ collection_st *next;
+ void *world_ptr;
+
+ world_stats_st stats;
+
+ memset(&stats, 0, sizeof(stats));
+ memset(&world, 0, sizeof(world));
+ get_world(&world);
+
+ if (! world.runner)
+ {
+ world.runner= &defualt_runners;
+ }
+
+ collection= world.collections;
+
+ if (world.create)
+ world_ptr= world.create();
+ else
+ world_ptr= NULL;
+
+ if (argc > 1)
+ collection_to_run= argv[1];
+
+ if (argc == 3)
+ wildcard= argv[2];
+
+ for (next= collection; next->name; next++)
+ {
+ test_st *run;
+
+ run= next->tests;
+ if (collection_to_run && fnmatch(collection_to_run, next->name, 0))
+ continue;
+
+ fprintf(stderr, "\n%s\n\n", next->name);
+
+ for (x= 0; run->name; run++)
+ {
+ struct timeval start_time, end_time;
+ long int load_time= 0;
+
+ if (wildcard && fnmatch(wildcard, run->name, 0))
+ continue;
+
+ fprintf(stderr, "Testing %s", run->name);
+
+ if (world.collection_startup)
+ {
+ world.collection_startup(world_ptr);
+ }
+
+ if (run->requires_flush && world.flush)
+ {
+ world.flush(world_ptr);
+ }
+
+ if (world.pre_run)
+ {
+ world.pre_run(world_ptr);
+ }
+
+
+ if (next->pre)
+ {
+ return_code= world.runner->pre(next->pre, world_ptr);
+
+ if (return_code != TEST_SUCCESS)
+ {
+ goto error;
+ }
+ }
+
+ gettimeofday(&start_time, NULL);
+ return_code= world.runner->run(run->test_fn, world_ptr);
+ gettimeofday(&end_time, NULL);
+ load_time= timedif(end_time, start_time);
+
+ if (next->post)
+ {
+ (void) world.runner->pre(next->pre, world_ptr);
+ }
+
+ if (world.post_run)
+ {
+ world.post_run(world_ptr);
+ }
+
+error:
+ stats.total++;
+
+ fprintf(stderr, "\t\t\t\t\t");
+
+ switch (return_code)
+ {
+ case TEST_SUCCESS:
+ fprintf(stderr, "%ld.%03ld ", load_time / 1000, load_time % 1000);
+ stats.success++;
+ break;
+ case TEST_FAILURE:
+ stats.failed++;
+ break;
+ case TEST_SKIPPED:
+ stats.skipped++;
+ break;
+ case TEST_MEMORY_ALLOCATION_FAILURE:
+ case TEST_MAXIMUM_RETURN:
+ default:
+ break;
+ }
+
+ fprintf(stderr, "[ %s ]\n", test_strerror(return_code));
+
+ if (world.on_error)
+ {
+ test_return_t rc;
+ rc= world.on_error(return_code, world_ptr);
+
+ if (rc != TEST_SUCCESS)
+ break;
+ }
+ }
+ }
+
+ fprintf(stderr, "All tests completed successfully\n\n");
+
+ if (world.destroy)
+ world.destroy(world_ptr);
+
+ world_stats_print(&stats);
+
+ return stats.failed == 0 ? 0 : 1;