Ejemplo n.º 1
0
bool torture_run_tcase_restricted(struct torture_context *context,
                                  struct torture_tcase *tcase, const char **restricted)
{
    bool ret = true;
    struct torture_test *test;
    bool setup_succeeded = true;
    const char * setup_reason = "Setup failed";

    context->active_tcase = tcase;
    if (context->results->ui_ops->tcase_start)
        context->results->ui_ops->tcase_start(context, tcase);

    if (tcase->fixture_persistent && tcase->setup) {
        setup_succeeded = tcase->setup(context, &tcase->data);
    }

    if (!setup_succeeded) {
        /* Uh-oh. The setup failed, so we can't run any of the tests
         * in this testcase. The subunit format doesn't specify what
         * to do here, so we keep the failure reason, and manually
         * use it to fail every test.
         */
        if (context->last_reason != NULL) {
            setup_reason = talloc_asprintf(context,
                                           "Setup failed: %s", context->last_reason);
        }
    }

    for (test = tcase->tests; test; test = test->next) {
        if (setup_succeeded) {
            ret &= internal_torture_run_test(context, tcase, test,
                                             tcase->fixture_persistent, restricted);
        } else {
            context->active_tcase = tcase;
            context->active_test = test;
            torture_ui_test_start(context, tcase, test);
            torture_ui_test_result(context, TORTURE_FAIL, setup_reason);
        }
    }

    if (setup_succeeded && tcase->fixture_persistent && tcase->teardown &&
            !tcase->teardown(context, tcase->data)) {
        ret = false;
    }

    context->active_tcase = NULL;
    context->active_test = NULL;

    if (context->results->ui_ops->tcase_finish)
        context->results->ui_ops->tcase_finish(context, tcase);

    return (!setup_succeeded) ? false : ret;
}
Ejemplo n.º 2
0
static bool internal_torture_run_test(struct torture_context *context, 
					  struct torture_tcase *tcase,
					  struct torture_test *test,
					  bool already_setup)
{
	bool success;
	char *old_testname = NULL;

	if (tcase == NULL || strcmp(test->name, tcase->name) != 0) { 
		old_testname = context->active_testname;
		context->active_testname = talloc_asprintf(context, "%s-%s", old_testname, test->name);
	}

	context->active_tcase = tcase;
	context->active_test = test;

	torture_ui_test_start(context, tcase, test);

	context->last_reason = NULL;
	context->last_result = TORTURE_OK;

	if (!already_setup && tcase->setup && 
		!tcase->setup(context, &(tcase->data))) {
	    	if (context->last_reason == NULL)
			context->last_reason = talloc_strdup(context, "Setup failure");
		context->last_result = TORTURE_ERROR;
		success = false;
	} else if (test->dangerous && 
	    !torture_setting_bool(context, "dangerous", false)) {
	    context->last_result = TORTURE_SKIP;
	    context->last_reason = talloc_asprintf(context, 
	    	"disabled %s - enable dangerous tests to use", test->name);
	    success = true;
	} else {
	    success = test->run(context, tcase, test);

	    if (!success && context->last_result == TORTURE_OK) {
		    if (context->last_reason == NULL)
			    context->last_reason = talloc_strdup(context, "Unknown error/failure");
		    context->last_result = TORTURE_ERROR;
	    }
	}

	if (!already_setup && tcase->teardown && !tcase->teardown(context, tcase->data)) {
    		if (context->last_reason == NULL)
		    context->last_reason = talloc_strdup(context, "Setup failure");
	    	context->last_result = TORTURE_ERROR;
		success = false;
	}

	torture_ui_test_result(context, context->last_result, 
			       context->last_reason);
	
	talloc_free(context->last_reason);

	if (tcase == NULL || strcmp(test->name, tcase->name) != 0) { 
		talloc_free(context->active_testname);
		context->active_testname = old_testname;
	}
	context->active_test = NULL;
	context->active_tcase = NULL;

	return success;
}