bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek Fail over tests.
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek Martin Nagy <mnagy@redhat.com>
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek Copyright (C) Red Hat, Inc 2009
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 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 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/* Interface under test */
2b84054e2f9fa7301af4dbef4dcbf1cba066ecb3Lukas Slebodnikstatic struct test_ctx *
2b84054e2f9fa7301af4dbef4dcbf1cba066ecb3Lukas Slebodnik ctx = talloc_zero(global_talloc_context, struct test_ctx);
2b84054e2f9fa7301af4dbef4dcbf1cba066ecb3Lukas Slebodnik fail_if(ctx == NULL, "Could not allocate memory for test context");
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek ret = resolv_init(ctx, ctx->ev, 5, &ctx->resolv);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek for (i = 0; i < 10; i++) {
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek ret = fo_new_service(ctx->fo_ctx, buf, NULL, &services[i]);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek ret = fo_new_service(ctx->fo_ctx, "service_3", NULL, &service);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek for (i = 9; i >= 0; i--) {
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek ret = fo_get_service(ctx->fo_ctx, buf, &service);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek ret = fo_get_service(ctx->fo_ctx, buf, &service);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozektest_resolve_service_callback(struct tevent_req *req)
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek task = tevent_req_callback_data(req, struct task);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek recv_status = fo_resolve_service_recv(req, req, &server);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(recv_status != task->recv, "%s: Expected return of %d, got %d",
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(port != task->port, "%s: Expected port %d, got %d", task->location,
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fo_set_port_status(server, task->new_port_status);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fo_set_server_status(server, task->new_server_status);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(he == NULL, "fo_get_server_hostent() returned NULL");
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 && 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_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 req = fo_resolve_service_send(test_ctx, test_ctx->ev,
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(req == NULL, "%s: fo_resolve_service_send() failed", location);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek tevent_req_set_callback(req, test_resolve_service_callback, task);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek /* Add service. */
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(fo_new_service(ctx->fo_ctx, "http", NULL, &service[0]) != EOK);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(fo_new_service(ctx->fo_ctx, "ldap", NULL, &service[1]) != EOK);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(fo_new_service(ctx->fo_ctx, "ntp", NULL, &service[2]) != EOK);
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 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);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek fail_if(fo_add_server(service[2], NULL, 123, NULL, true) != EOK);
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 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 get_request(ctx, service[2], EOK, 123, -1, -1);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek tcase_add_checked_fixture(tc, ck_leak_check_setup, ck_leak_check_teardown);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek /* Do some testing */
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek /* Add all test cases to the test suite */
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 /* Set debug level to invalid value so we can decide if -d 0 was used. */
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
bf54fbed126ec3d459af40ea370ffadacd31c76dJakub Hrozek /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */