bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek/*
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek SSSD
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek Fail over tests.
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek Authors:
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek Martin Nagy <mnagy@redhat.com>
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek Copyright (C) Red Hat, Inc 2009
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek This program is free software; you can redistribute it and/or modify
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek it under the terms of the GNU General Public License as published by
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek the Free Software Foundation; either version 3 of the License, or
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek (at your option) any later version.
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek This program is distributed in the hope that it will be useful,
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek GNU General Public License for more details.
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek You should have received a copy of the GNU General Public License
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek*/
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek#include <arpa/inet.h>
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek#include <check.h>
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek#include <popt.h>
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek#include <stdlib.h>
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek#include <stdio.h>
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek#include <talloc.h>
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek#include <tevent.h>
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek#include "resolv/async_resolv.h"
00f3fbb66e882213a78a7ad0a4f9190d0838c830Justin Stephenson#include "tests/common_check.h"
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek#include "util/util.h"
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek/* Interface under test */
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek#include "providers/fail_over.h"
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozekint use_net_test;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozekstruct test_ctx {
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek struct tevent_context *ev;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek struct resolv_ctx *resolv;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek struct fo_ctx *fo_ctx;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek int tasks;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek};
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozekstruct task {
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek struct test_ctx *test_ctx;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek const char *location;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek struct fo_service *service;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek int recv;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek int port;
2b84054e2f9fa7301af4dbef4dcbf1cba066ecb3Lukas Slebodnik int new_server_status;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek int new_port_status;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek};
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
2b84054e2f9fa7301af4dbef4dcbf1cba066ecb3Lukas Slebodnikstatic struct test_ctx *
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozeksetup_test(void)
2b84054e2f9fa7301af4dbef4dcbf1cba066ecb3Lukas Slebodnik{
2b84054e2f9fa7301af4dbef4dcbf1cba066ecb3Lukas Slebodnik struct test_ctx *ctx;
2b84054e2f9fa7301af4dbef4dcbf1cba066ecb3Lukas Slebodnik struct fo_options fopts;
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz int ret;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
2b84054e2f9fa7301af4dbef4dcbf1cba066ecb3Lukas Slebodnik ctx = talloc_zero(global_talloc_context, struct test_ctx);
2b84054e2f9fa7301af4dbef4dcbf1cba066ecb3Lukas Slebodnik fail_if(ctx == NULL, "Could not allocate memory for test context");
2b84054e2f9fa7301af4dbef4dcbf1cba066ecb3Lukas Slebodnik
2b84054e2f9fa7301af4dbef4dcbf1cba066ecb3Lukas Slebodnik ctx->ev = tevent_context_init(ctx);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek if (ctx->ev == NULL) {
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek talloc_free(ctx);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail("Could not init tevent context");
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek }
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek ret = resolv_init(ctx, ctx->ev, 5, &ctx->resolv);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek if (ret != EOK) {
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek talloc_free(ctx);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail("Could not init resolv context");
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek }
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek memset(&fopts, 0, sizeof(fopts));
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fopts.retry_timeout = 30;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fopts.family_order = IPV4_FIRST;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek ctx->fo_ctx = fo_context_init(ctx, &fopts);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek if (ctx->fo_ctx == NULL) {
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek talloc_free(ctx);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail("Could not init fail over context");
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek }
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek return ctx;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek}
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozekstatic void
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozektest_loop(struct test_ctx *data)
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek{
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek while (data->tasks != 0)
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek tevent_loop_once(data->ev);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek}
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub HrozekSTART_TEST(test_fo_new_service)
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek{
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek int i;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek int ret;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek struct test_ctx *ctx;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek struct fo_service *service;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek struct fo_service *services[10];
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek ctx = setup_test();
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek ck_leaks_push(ctx);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek for (i = 0; i < 10; i++) {
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek char buf[16];
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek sprintf(buf, "service_%d", i);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek ck_leaks_push(ctx);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek ret = fo_new_service(ctx->fo_ctx, buf, NULL, &services[i]);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(ret != EOK);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek }
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek ret = fo_new_service(ctx->fo_ctx, "service_3", NULL, &service);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(ret != EEXIST);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek for (i = 9; i >= 0; i--) {
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek char buf[16];
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek sprintf(buf, "service_%d", i);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek ret = fo_get_service(ctx->fo_ctx, buf, &service);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(ret != EOK);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(service != services[i]);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek talloc_free(service);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek ck_leaks_pop(ctx);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek ret = fo_get_service(ctx->fo_ctx, buf, &service);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(ret != ENOENT);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek }
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek ck_leaks_pop(ctx);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek talloc_free(ctx);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek}
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub HrozekEND_TEST
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozekstatic void
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozektest_resolve_service_callback(struct tevent_req *req)
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek{
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek uint64_t recv_status;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek int port;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek struct task *task;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek struct fo_server *server = NULL;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek struct fo_server *active_server = NULL;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek struct resolv_hostent *he;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek int i;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek task = tevent_req_callback_data(req, struct task);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek task->test_ctx->tasks--;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek recv_status = fo_resolve_service_recv(req, req, &server);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek talloc_free(req);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(recv_status != task->recv, "%s: Expected return of %d, got %d",
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek task->location, task->recv, recv_status);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek if (recv_status != EOK)
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek return;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(server == NULL);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek port = fo_get_server_port(server);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(port != task->port, "%s: Expected port %d, got %d", task->location,
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek task->port, port);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek if (task->new_port_status >= 0)
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fo_set_port_status(server, task->new_port_status);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek if (task->new_server_status >= 0)
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fo_set_server_status(server, task->new_server_status);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek if (fo_get_server_name(server) != NULL) {
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek he = fo_get_server_hostent(server);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(he == NULL, "fo_get_server_hostent() returned NULL");
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek for (i = 0; he->addr_list[i]; i++) {
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek char buf[256];
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek inet_ntop(he->family, he->addr_list[i]->ipaddr, buf, sizeof(buf));
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(strcmp(buf, "127.0.0.1") != 0 && strcmp(buf, "::1") != 0);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek }
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek }
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek if (task->new_port_status == PORT_WORKING
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek && task->new_server_status == SERVER_WORKING) {
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek active_server = fo_get_active_server(task->service);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(active_server == NULL, "Missing active server");
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(server != active_server, "Current server is not active server");
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek }
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek}
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek#define get_request(a, b, c, d, e, f) \
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek _get_request(a, b, c, d, e, f, __location__)
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozekstatic void
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek_get_request(struct test_ctx *test_ctx, struct fo_service *service,
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek int expected_recv, int expected_port, int new_port_status,
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek int new_server_status, const char *location)
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek{
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek struct tevent_req *req;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek struct task *task;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek task = talloc(test_ctx, struct task);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(task == NULL);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek task->test_ctx = test_ctx;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek task->recv = expected_recv;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek task->port = expected_port;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek task->new_port_status = new_port_status;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek task->new_server_status = new_server_status;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek task->location = location;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek task->service = service;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek test_ctx->tasks++;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek req = fo_resolve_service_send(test_ctx, test_ctx->ev,
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek test_ctx->resolv,
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek test_ctx->fo_ctx, service);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(req == NULL, "%s: fo_resolve_service_send() failed", location);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek tevent_req_set_callback(req, test_resolve_service_callback, task);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek test_loop(test_ctx);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek}
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub HrozekSTART_TEST(test_fo_resolve_service)
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek{
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek struct test_ctx *ctx;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek struct fo_service *service[3];
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek ctx = setup_test();
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(ctx == NULL);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek /* Add service. */
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(fo_new_service(ctx->fo_ctx, "http", NULL, &service[0]) != EOK);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(fo_new_service(ctx->fo_ctx, "ldap", NULL, &service[1]) != EOK);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(fo_new_service(ctx->fo_ctx, "ntp", NULL, &service[2]) != EOK);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek /* Add servers. */
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(fo_add_server(service[0], "localhost", 20, NULL, true) != EOK);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(fo_add_server(service[0], "127.0.0.1", 80, NULL, false) != EOK);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(fo_add_server(service[1], "localhost", 30, NULL, false) != EOK);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek fail_if(fo_add_server(service[1], "127.0.0.1", 389, NULL, true) != EOK);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(fo_add_server(service[1], "127.0.0.1", 389, NULL, true) != EEXIST);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(fo_add_server(service[1], "127.0.0.1", 389, NULL, false) != EEXIST);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(fo_add_server(service[2], NULL, 123, NULL, true) != EOK);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek /* Make requests. */
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek get_request(ctx, service[0], EOK, 20, PORT_WORKING, -1);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek get_request(ctx, service[0], EOK, 20, PORT_WORKING, SERVER_WORKING);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek get_request(ctx, service[0], EOK, 20, -1, SERVER_NOT_WORKING);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek get_request(ctx, service[0], EOK, 80, PORT_WORKING, -1);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek get_request(ctx, service[0], EOK, 80, PORT_NOT_WORKING, -1);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek get_request(ctx, service[0], ENOENT, 0, -1, -1);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek get_request(ctx, service[1], EOK, 389, PORT_WORKING, -1);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek get_request(ctx, service[1], EOK, 389, -1, SERVER_NOT_WORKING);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek get_request(ctx, service[1], ENOENT, 0, -1, -1);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek get_request(ctx, service[2], EOK, 123, -1, -1);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek talloc_free(ctx);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek}
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub HrozekEND_TEST
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub HrozekSuite *
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozekcreate_suite(void)
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek{
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek Suite *s = suite_create("fail_over");
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek TCase *tc = tcase_create("FAIL_OVER Tests");
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek tcase_add_checked_fixture(tc, ck_leak_check_setup, ck_leak_check_teardown);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek /* Do some testing */
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek tcase_add_test(tc, test_fo_new_service);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek tcase_add_test(tc, test_fo_resolve_service);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek if (use_net_test) {
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek }
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek /* Add all test cases to the test suite */
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek suite_add_tcase(s, tc);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek return s;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek}
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozekint
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozekmain(int argc, const char *argv[])
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek{
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek int opt;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek poptContext pc;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek int failure_count;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek Suite *suite;
eca74a9559ce1b0f123c14906ad8394fc303f468Jakub Hrozek SRunner *sr;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek struct poptOption long_options[] = {
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek POPT_AUTOHELP
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek { "debug-level", 'd', POPT_ARG_INT, &debug_level, 0, "Set debug level", NULL },
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek { "use-net-test", 'n', POPT_ARG_NONE, 0, 'n', "Run tests that need an active internet connection", NULL },
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek POPT_TABLEEND
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek };
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek /* Set debug level to invalid value so we can decide if -d 0 was used. */
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek debug_level = SSSDBG_INVALID;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek while((opt = poptGetNextOpt(pc)) != -1) {
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek switch(opt) {
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek case 'n':
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek use_net_test = 1;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek break;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek default:
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fprintf(stderr, "\nInvalid option %s: %s\n\n",
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek poptBadOption(pc, 0), poptStrerror(opt));
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek poptPrintUsage(pc, stderr, 0);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek return 1;
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek }
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek }
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek poptFreeContext(pc);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek DEBUG_CLI_INIT(debug_level);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek tests_set_cwd();
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek suite = create_suite();
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek sr = srunner_create(suite);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek srunner_run_all(sr, CK_ENV);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek failure_count = srunner_ntests_failed(sr);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek srunner_free(sr);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek return (failure_count == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek}
00f3fbb66e882213a78a7ad0a4f9190d0838c830Justin Stephenson