Exemplo n.º 1
0
/** If the user has not defined any specific groups for testrun then this function executes all of the tests.*/
bool run_all_tests()
{
    bool result = true;
    for(auto t = g_tests->begin(); t != g_tests->end(); ++t) run_group(*t);
    return result;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
int server_start(server_t *s)
{
	if (!getuid())
	{
		uid_t uid = 0;
		gid_t gid = 0;

		run_user(s, &uid, &gid);
		run_group(s, &gid);

		// runtime data directory
		if (run_mkdir(JOURNAL_RUNDIR) < 0)
		{
			log_error("Failed to create '%s' directory: %m", JOURNAL_RUNDIR);
			return -1;
		}

		if (chown(JOURNAL_RUNDIR, uid, gid) < 0)
		{
			log_error("Unable to change owner “%s” directory to %s(%s): %m", JOURNAL_RUNDIR, s->runuser, s->rungroup);
			return -1;
		}

		syslog_run(s);

		// variable data directory
		if (run_mkdir(JOURNAL_LOGDIR) < 0)
			log_warning("Failed to create '%s' directory: %m", JOURNAL_LOGDIR);
		else
		{
			if (errno != EEXIST && chown(JOURNAL_LOGDIR, uid, gid) < 0)
				log_warning("Unable to change owner “%s” directory to %s(%s): %m", JOURNAL_LOGDIR, s->runuser, s->rungroup);
		}

		// change user and group of process
		if (gid > 0 && run_chgroup(gid) < 0)
		{
			log_error("Unable change group to “%s”: %m", s->rungroup);
			return -1;
		}

		if (uid > 0 && run_chuser(uid) < 0)
		{
			log_error("Unable change user to “%s”: %m", s->runuser);
			return -1;
		}
	}

	if (epollfd_create(&s->epoll) < 0)
	{
		log_error("Failed to create event loop: %m");
		return -1;
	}

	s->msg = msg_new(LINE_MAX);
	if (!s->msg)
		return -1;

	seqnum_load(JOURNAL_RUNDIR "/kernel-seqnum", &s->kseqnum);

	if (hostname_open(s) < 0)
		return -1;

	boot_get_id(&s->boot_id);

	return 0;
}