99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek/*
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek Copyright (C) 2015 Red Hat
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek This program is free software; you can redistribute it and/or modify
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek it under the terms of the GNU General Public License as published by
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek (at your option) any later version.
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek This program is distributed in the hope that it will be useful,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek GNU General Public License for more details.
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek You should have received a copy of the GNU General Public License
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek*/
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek#include <talloc.h>
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek#include <tevent.h>
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek#include <errno.h>
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek#include <popt.h>
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek#include <time.h>
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
cc2d77d5218c188119fa954c856e858cbde76947Pavel Březina#include "providers/backend.h"
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek#include "tests/cmocka/common_mock.h"
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek#include "tests/cmocka/common_mock_be.h"
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek#include "tests/common.h"
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek#define TESTS_PATH "tests_dp_be"
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek#define TEST_CONF_DB "test_dp_be_conf.ldb"
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek#define TEST_DOM_NAME "dp_be_test"
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek#define TEST_ID_PROVIDER "ldap"
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek#define OFFLINE_TIMEOUT 2
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek#define AS_STR(param) (#param)
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekstatic TALLOC_CTX *global_mock_context = NULL;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekstatic bool global_timer_added;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekstruct tevent_timer *__real__tevent_add_timer(struct tevent_context *ev,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek TALLOC_CTX *mem_ctx,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct timeval next_event,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek tevent_timer_handler_t handler,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek void *private_data,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek const char *handler_name,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek const char *location);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekstruct tevent_timer *__wrap__tevent_add_timer(struct tevent_context *ev,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek TALLOC_CTX *mem_ctx,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct timeval next_event,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek tevent_timer_handler_t handler,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek void *private_data,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek const char *handler_name,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek const char *location)
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek{
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek global_timer_added = true;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek return __real__tevent_add_timer(ev, mem_ctx, next_event,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek handler, private_data, handler_name,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek location);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek}
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekstruct test_ctx {
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct sss_test_ctx *tctx;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct be_ctx *be_ctx;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek};
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekstatic int test_setup(void **state)
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek{
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct test_ctx *test_ctx = NULL;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct sss_test_conf_param params[] = {
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek { "offline_timeout", AS_STR(OFFLINE_TIMEOUT) },
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek { NULL, NULL }, /* Sentinel */
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek };
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_true(leak_check_setup());
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek global_mock_context = talloc_new(global_talloc_context);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_non_null(global_mock_context);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_ctx = talloc_zero(global_talloc_context, struct test_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_non_null(test_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek TEST_CONF_DB, TEST_DOM_NAME,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek TEST_ID_PROVIDER, params);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_non_null(test_ctx->tctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_ctx->be_ctx = mock_be_ctx(test_ctx, test_ctx->tctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_non_null(test_ctx->be_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_ctx->be_ctx->domain->subdomains = named_domain(test_ctx,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek "subdomains",
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_ctx->be_ctx->domain);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_non_null(test_ctx->be_ctx->domain->subdomains);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek *state = test_ctx;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek return 0;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek}
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekstatic int test_teardown(void **state)
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek{
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek talloc_zfree(*state);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_true(leak_check_teardown());
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek return 0;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek}
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekstatic void assert_domain_state(struct sss_domain_info *dom,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek enum sss_domain_state expected_state)
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek{
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek enum sss_domain_state dom_state;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek dom_state = sss_domain_get_state(dom);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_int_equal(dom_state, expected_state);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek}
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekstatic void test_mark_subdom_offline_check(struct tevent_context *ev,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct tevent_timer *te,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct timeval current_time,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek void *pvt)
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek{
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct test_ctx *test_ctx = talloc_get_type(pvt, struct test_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_domain_state(test_ctx->be_ctx->domain->subdomains,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek DOM_ACTIVE);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_ctx->tctx->done = true;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_ctx->tctx->error = EOK;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek}
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekstatic void test_mark_dom_offline(void **state)
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek{
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_domain_state(test_ctx->be_ctx->domain, DOM_ACTIVE);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_false(be_is_offline(test_ctx->be_ctx));
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek be_mark_dom_offline(test_ctx->be_ctx->domain, test_ctx->be_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_true(be_is_offline(test_ctx->be_ctx));
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_domain_state(test_ctx->be_ctx->domain, DOM_ACTIVE);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek}
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekstatic void test_mark_subdom_offline(void **state)
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek{
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct timeval tv;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct tevent_timer *check_ev = NULL;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek errno_t ret;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_domain_state(test_ctx->be_ctx->domain->subdomains,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek DOM_ACTIVE);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_false(be_is_offline(test_ctx->be_ctx));
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek global_timer_added = false;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek be_mark_dom_offline(test_ctx->be_ctx->domain->subdomains, test_ctx->be_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_domain_state(test_ctx->be_ctx->domain->subdomains,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek DOM_INACTIVE);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek /* A timer must be added that resets the state back */
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_true(global_timer_added);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek /* Global offline state must not change */
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_false(be_is_offline(test_ctx->be_ctx));
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek /* Make sure we don't add a second timer */
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek global_timer_added = false;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek be_mark_dom_offline(test_ctx->be_ctx->domain->subdomains, test_ctx->be_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_domain_state(test_ctx->be_ctx->domain->subdomains,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek DOM_INACTIVE);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_false(global_timer_added);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek /* Wait for the internal timer to reset our subdomain back */
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek tv = tevent_timeval_current_ofs(OFFLINE_TIMEOUT + 1, 0);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek check_ev = tevent_add_timer(test_ctx->tctx->ev, test_ctx, tv,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_mark_subdom_offline_check,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek if (check_ev == NULL) {
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Cannot create timer\n");
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek return;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek }
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek ret = test_ev_loop(test_ctx->tctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_int_equal(ret, EOK);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek}
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekstatic void test_mark_subdom_offline_disabled(void **state)
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek{
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek sss_domain_set_state(test_ctx->be_ctx->domain->subdomains, DOM_DISABLED);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_domain_state(test_ctx->be_ctx->domain->subdomains,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek DOM_DISABLED);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek be_mark_dom_offline(test_ctx->be_ctx->domain->subdomains, test_ctx->be_ctx);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek assert_domain_state(test_ctx->be_ctx->domain->subdomains,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek DOM_DISABLED);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek}
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozekint main(int argc, const char *argv[])
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek{
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek poptContext pc;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek int opt;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek int rv;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek int no_cleanup = 0;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek struct poptOption long_options[] = {
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek POPT_AUTOHELP
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek SSSD_DEBUG_OPTS
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek _("Do not delete the test database after a test run"), NULL },
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek POPT_TABLEEND
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek };
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek const struct CMUnitTest tests[] = {
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek cmocka_unit_test_setup_teardown(test_mark_dom_offline,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_setup,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_teardown),
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek cmocka_unit_test_setup_teardown(test_mark_subdom_offline,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_setup,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_teardown),
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek cmocka_unit_test_setup_teardown(test_mark_subdom_offline_disabled,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_setup,
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_teardown),
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek };
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek debug_level = SSSDBG_INVALID;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek while((opt = poptGetNextOpt(pc)) != -1) {
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek switch(opt) {
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek default:
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek fprintf(stderr, "\nInvalid option %s: %s\n\n",
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek poptBadOption(pc, 0), poptStrerror(opt));
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek poptPrintUsage(pc, stderr, 0);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek return 1;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek }
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek }
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek poptFreeContext(pc);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek DEBUG_CLI_INIT(debug_level);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek /* Even though normally the tests should clean up after themselves
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz * they might not after a failed run. Remove the old DB to be sure */
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek tests_set_cwd();
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_dom_suite_setup(TESTS_PATH);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek rv = cmocka_run_group_tests(tests, NULL, NULL);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek if (rv == 0 && !no_cleanup) {
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek }
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek return rv;
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek return cmocka_run_group_tests(tests, NULL, NULL);
99c5f2f6ba0af6ce52be0d82ec2794bacc215742Jakub Hrozek}