-int main(int argc, char** argv) {
- int retval;
- int thread_index;
- struct timeval timer;
- pthread_t* threads;
- int thread_retval;
- void* thread_retval_ptr = &thread_retval;
- char test_path[MAXPATHLEN];
-
- retval = parse_args(argc, argv, &args);
- if(retval) {
- print_usage(argv);
- return -1;
- }
-
- retval = find_test(args.test_name, test_path);
- if(retval) {
- printf("Unable to find test %s\n", args.test_name);
- return -1;
- }
-
- load_test(test_path, &test);
- if(retval) {
- printf("Unable to load test %s\n", args.test_name);
- return -1;
- }
-
- pthread_cond_init(&threads_ready_cvar, NULL);
- pthread_cond_init(&start_cvar, NULL);
- pthread_mutex_init(&ready_thread_count_lock, NULL);
- ready_thread_count = 0;
-
- if(test.setup) {
- retval = test.setup(args.num_threads, args.length, 0, NULL);
- if(retval == PERFINDEX_FAILURE) {
- fprintf(stderr, "Test setup failed: %s\n", *test.error_str_ptr);
- return -1;
- }
- }
-
- threads = (pthread_t*)malloc(sizeof(pthread_t)*args.num_threads);
- for(thread_index = 0; thread_index < args.num_threads; thread_index++) {
- retval = pthread_create(&threads[thread_index], NULL, thread_setup, (void*)(long)thread_index);
- assert(retval == 0);
- }
-
- pthread_mutex_lock(&ready_thread_count_lock);
- if(ready_thread_count != args.num_threads) {
- pthread_cond_wait(&threads_ready_cvar, &ready_thread_count_lock);
- }
- pthread_mutex_unlock(&ready_thread_count_lock);
-
- start_timer(&timer);
- pthread_cond_broadcast(&start_cvar);
- for(thread_index = 0; thread_index < args.num_threads; thread_index++) {
- pthread_join(threads[thread_index], &thread_retval_ptr);
- if(**test.error_str_ptr) {
- printf("Test failed: %s\n", *test.error_str_ptr);
- }
- }
- end_timer(&timer);
-
- if(test.cleanup)
- retval = test.cleanup(args.num_threads, args.length);
- if(retval == PERFINDEX_FAILURE) {
- fprintf(stderr, "Test cleanup failed: %s\n", *test.error_str_ptr);
- free(threads);
- return -1;
- }
-
- print_timer(&timer);
-
- free(threads);
-
- return 0;
+int
+main(int argc, char** argv)
+{
+ int retval;
+ int thread_index;
+ struct timeval timer;
+ pthread_t* threads;
+ int thread_retval;
+ void* thread_retval_ptr = &thread_retval;
+ char test_path[MAXPATHLEN];
+
+ retval = parse_args(argc, argv, &args);
+ if (retval) {
+ print_usage(argv);
+ return -1;
+ }
+
+ retval = find_test(args.test_name, test_path);
+ if (retval) {
+ printf("Unable to find test %s\n", args.test_name);
+ return -1;
+ }
+
+ load_test(test_path, &test);
+ if (retval) {
+ printf("Unable to load test %s\n", args.test_name);
+ return -1;
+ }
+
+ pthread_cond_init(&threads_ready_cvar, NULL);
+ pthread_cond_init(&start_cvar, NULL);
+ pthread_mutex_init(&ready_thread_count_lock, NULL);
+ ready_thread_count = 0;
+
+ if (test.setup) {
+ retval = test.setup(args.num_threads, args.length, 0, NULL);
+ if (retval == PERFINDEX_FAILURE) {
+ fprintf(stderr, "Test setup failed: %s\n", *test.error_str_ptr);
+ return -1;
+ }
+ }
+
+ threads = (pthread_t*)malloc(sizeof(pthread_t) * args.num_threads);
+ for (thread_index = 0; thread_index < args.num_threads; thread_index++) {
+ retval = pthread_create(&threads[thread_index], NULL, thread_setup, (void*)(long)thread_index);
+ assert(retval == 0);
+ }
+
+ pthread_mutex_lock(&ready_thread_count_lock);
+ if (ready_thread_count != args.num_threads) {
+ pthread_cond_wait(&threads_ready_cvar, &ready_thread_count_lock);
+ }
+ pthread_mutex_unlock(&ready_thread_count_lock);
+
+ start_timer(&timer);
+ pthread_cond_broadcast(&start_cvar);
+ for (thread_index = 0; thread_index < args.num_threads; thread_index++) {
+ pthread_join(threads[thread_index], &thread_retval_ptr);
+ if (**test.error_str_ptr) {
+ printf("Test failed: %s\n", *test.error_str_ptr);
+ }
+ }
+ end_timer(&timer);
+
+ if (test.cleanup) {
+ retval = test.cleanup(args.num_threads, args.length);
+ }
+ if (retval == PERFINDEX_FAILURE) {
+ fprintf(stderr, "Test cleanup failed: %s\n", *test.error_str_ptr);
+ free(threads);
+ return -1;
+ }
+
+ print_timer(&timer);
+
+ free(threads);
+
+ return 0;