Esempio n. 1
0
gint main(gint argc, gchar **argv)
#endif
{
	gint i, j, c, iterations = 1;
	StringArray *tests_to_run = NULL;
	gdouble time_start;
	gboolean report_time = FALSE;
	gboolean quiet = FALSE;
	gboolean global_failure = FALSE;
	gboolean no_final_time_labels = FALSE;
	gboolean debug = FALSE;

#if HAVE_GETOPT_H
	static struct option long_options [] = {
		{"help",       no_argument,       0, 'h'},
		{"time",       no_argument,       0, 't'},
		{"quiet",      no_argument,       0, 'q'},
		{"iterations", required_argument, 0, 'i'},
		{"debug",      no_argument,       0, 'd'},
		{"no-labels",  no_argument,       0, 'n'},
		{0, 0, 0, 0}
	};

	while((c = getopt_long(argc, argv, "dhtqni:", long_options, NULL)) != -1) {			switch(c) {
			case 'h':
				print_help(argv[0]);
				return 1;
			case 't':
				report_time = TRUE;
				break;
			case 'i':
				iterations = atoi(optarg);
				break;
			case 'q':
				quiet = TRUE;
				break;
			case 'n':
				no_final_time_labels = TRUE;
				break;
			case 'd':
				debug = TRUE;
				break;
		}
	}

	for (i = optind; i < argc; i++) {
		if (argv[i][0] == '-') {
			continue;
		}

		tests_to_run = string_array_append(tests_to_run, argv[i]);
	}
#endif

	time_start = get_timestamp();

	for (j = 0; test_groups[j].name != NULL; j++) {
		gboolean run = TRUE;
		gchar *tests = NULL;
		gchar *group = NULL;

		if (tests_to_run != NULL) {
			gint k;
			run = FALSE;

			for (k = 0; k < tests_to_run->length; k++) {
				gchar *user = tests_to_run->strings[k];
				const gchar *table = test_groups[j].name;
				size_t user_len = strlen(user);
				size_t table_len = strlen(table);

				if (strncmp(user, table, table_len) == 0) {
					if (user_len > table_len && user[table_len] != ':') {
						break;
					}

					run = TRUE;
					group = tests_to_run->strings[k];
					break;
				}
			}
		}

		if (run) {
			gboolean passed;
			gchar **split = NULL;

			if (debug && test_groups[j].handler != fake_tests_init) {
				printf("Skipping %s, in driver debug mode\n",
					test_groups[j].name);
				continue;
			} else if (!debug && test_groups[j].handler == fake_tests_init) {
				continue;
			}

			if (group != NULL) {
				split = eg_strsplit(group, ":", -1);
				if (split != NULL) {
					gint m;
					for (m = 0; split[m] != NULL; m++) {
						if (m == 1) {
							tests = strdup(split[m]);
							break;
						}
					}
					eg_strfreev(split);
				}
			}

			passed = run_group(&(test_groups[j]),
				iterations, quiet, report_time, tests);

			if (tests != NULL) {
				g_free(tests);
			}

			if (!passed && !global_failure) {
				global_failure = TRUE;
			}
		}
	}

	if (!quiet) {
		gdouble pass_percentage = ((gdouble)global_passed / (gdouble)global_tests) * 100.0;
		printf("=============================\n");
		printf("Overall result: %s : %d / %d (%g%%)\n", global_failure ? "FAILED" : "OK", global_passed, global_tests, pass_percentage);
	}

	if (report_time) {
		gdouble duration = get_timestamp() - time_start;
		if (no_final_time_labels) {
			printf("%g\n", duration);
		} else {
			printf("%s Total Time: %g\n", DRIVER_NAME, duration);
		}
	}

	if (tests_to_run != NULL) {
		string_array_free(tests_to_run);
	}

	return global_tests - global_passed;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
	char c;
	int did_explicit_auth = 0;
	char *tickets = NULL;
	struct fuse_args fa;
	fa.argc = 0;
	fa.argv = string_array_new();
	fa.allocated = 1;

	debug_config(argv[0]);

	while((c = getopt(argc, argv, "a:b:d:Dfhi:m:o:t:v")) != -1) {
		switch (c) {
		case 'd':
			debug_flags_set(optarg);
			break;
		case 'D':
			enable_small_file_optimizations = 0;
			break;
		case 'b':
			chirp_reli_blocksize_set(atoi(optarg));
			break;
		case 'i':
			tickets = xxstrdup(optarg);
			break;
		case 'm':
			fa.argc += 1;
			fa.argv = string_array_append(fa.argv, optarg);
			break;
		case 'o':
			debug_config_file(optarg);
			break;
		case 'a':
			auth_register_byname(optarg);
			did_explicit_auth = 1;
			break;
		case 't':
			chirp_fuse_timeout = string_time_parse(optarg);
			break;
		case 'f':
			run_in_foreground = 1;
			break;
		case 'v':
			cctools_version_print(stdout, argv[0]);
			return 0;
			break;
		case 'h':
		default:
			show_help(argv[0]);
			return 1;
			break;
		}
	}

	cctools_version_debug(D_DEBUG, argv[0]);

	if((argc - optind) != 1) {
		show_help(argv[0]);
		return 1;
	}

	fuse_mountpoint = argv[optind];

	if(!did_explicit_auth)
		auth_register_all();
	if(tickets) {
		auth_ticket_load(tickets);
		free(tickets);
	} else if(getenv(CHIRP_CLIENT_TICKETS)) {
		auth_ticket_load(getenv(CHIRP_CLIENT_TICKETS));
	} else {
		auth_ticket_load(NULL);
	}

	file_table = itable_create(0);

	signal(SIGHUP, exit_handler);
	signal(SIGINT, exit_handler);
	signal(SIGTERM, exit_handler);

	fuse_chan = fuse_mount(fuse_mountpoint, &fa);
	if(!fuse_chan) {
		fprintf(stderr, "chirp_fuse: couldn't access %s\n", fuse_mountpoint);
		return 1;
	}

	fuse_instance = fuse_new(fuse_chan, &fa, &chirp_fuse_operations, sizeof(chirp_fuse_operations), 0);
	if(!fuse_instance) {
		fuse_unmount(fuse_mountpoint, fuse_chan);
		fprintf(stderr, "chirp_fuse: couldn't access %s\n", fuse_mountpoint);
		return 1;
	}

	printf("chirp_fuse: mounted chirp on %s\n", fuse_mountpoint);
#ifdef CCTOOLS_OPSYS_DARWIN
	printf("chirp_fuse: to unmount: umount %s\n", fuse_mountpoint);
#else
	printf("chirp_fuse: to unmount: fusermount -u %s\n", fuse_mountpoint);
#endif

	fflush(0);

	if(!run_in_foreground)
		daemon(0, 0);

	fuse_loop(fuse_instance);

	fuse_unmount(fuse_mountpoint, fuse_chan);
	fuse_destroy(fuse_instance);

	free(fa.argv);

	return 0;
}