-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 03/04/2010 06:27 PM, Jakub Hrozek wrote: > The attached patch also moves the localhost test into the networked > tests so we can safely build on systems that lack the localhost > definition in /etc/hosts. > > Also prints a warning when running in non-networked mode. >
One more patch - rebase against current master and add a test to resolve "127.0.0.1" which does nothing except calling the specified callback, so this codepath can be tested even in environments with no network. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iEYEARECAAYFAkuP8+QACgkQHsardTLnvCUfbACg0y2SmVqUDmnyS1UeJLVs2/8r lYoAn0Q4KDReb6Ph8KpeED4JtQy+dIEz =GS9G -----END PGP SIGNATURE-----
From 6c34a21156e3d33c44000adb1956b35b0990d6cb Mon Sep 17 00:00:00 2001 From: Jakub Hrozek <jhro...@redhat.com> Date: Wed, 3 Mar 2010 14:40:12 +0100 Subject: [PATCH] Do not run negative resolv test with no network One of our resolv tests tries to resolve a nonexistent hostname. Do not run this test unless we are explicitly told that a network connection is available (-n). Also do not automatically resolving localhost. --- src/tests/resolv-tests.c | 76 ++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 73 insertions(+), 3 deletions(-) diff --git a/src/tests/resolv-tests.c b/src/tests/resolv-tests.c index eced5b2..7f38192 100644 --- a/src/tests/resolv-tests.c +++ b/src/tests/resolv-tests.c @@ -130,6 +130,72 @@ START_TEST(test_copy_hostent) } END_TEST +static void test_ip_addr(struct tevent_req *req) +{ + int recv_status; + int status; + struct hostent *hostent; + int i; + struct resolv_test_ctx *test_ctx = tevent_req_callback_data(req, + struct resolv_test_ctx); + + test_ctx->done = true; + + recv_status = resolv_gethostbyname_recv(req, test_ctx, + &status, NULL, &hostent); + talloc_zfree(req); + if (recv_status != EOK) { + DEBUG(2, ("resolv_gethostbyname_recv failed: %d\n", recv_status)); + test_ctx->error = recv_status; + return; + } + DEBUG(7, ("resolv_gethostbyname_recv status: %d\n", status)); + + test_ctx->error = ENOENT; + for (i = 0; hostent->h_addr_list[i]; i++) { + char addr_buf[256]; + inet_ntop(hostent->h_addrtype, hostent->h_addr_list[i], addr_buf, sizeof(addr_buf)); + + if (strcmp(addr_buf, "127.0.0.1") == 0) { + test_ctx->error = EOK; + } + } + talloc_free(hostent); +} + +START_TEST(test_resolv_ip_addr) +{ + struct resolv_test_ctx *test_ctx; + int ret = EOK; + struct tevent_req *req; + const char *hostname = "127.0.0.1"; + + ret = setup_resolv_test(&test_ctx); + if (ret != EOK) { + fail("Could not set up test"); + return; + } + + check_leaks_push(test_ctx); + req = resolv_gethostbyname_send(test_ctx, test_ctx->ev, + test_ctx->resolv, hostname, IPV4_ONLY); + DEBUG(7, ("Sent resolv_gethostbyname\n")); + if (req == NULL) { + ret = ENOMEM; + } + + if (ret == EOK) { + tevent_req_set_callback(req, test_ip_addr, test_ctx); + ret = test_loop(test_ctx); + } + + check_leaks_pop(test_ctx); + fail_unless(ret == EOK); + + talloc_zfree(test_ctx); +} +END_TEST + static void test_localhost(struct tevent_req *req) { int recv_status; @@ -535,10 +601,11 @@ Suite *create_resolv_suite(void) tcase_add_checked_fixture(tc_resolv, leak_check_setup, leak_check_teardown); /* Do some testing */ tcase_add_test(tc_resolv, test_copy_hostent); - tcase_add_test(tc_resolv, test_resolv_localhost); - tcase_add_test(tc_resolv, test_resolv_negative); + tcase_add_test(tc_resolv, test_resolv_ip_addr); if (use_net_test) { tcase_add_test(tc_resolv, test_resolv_internet); + tcase_add_test(tc_resolv, test_resolv_negative); + tcase_add_test(tc_resolv, test_resolv_localhost); if (txt_host != NULL) { tcase_add_test(tc_resolv, test_resolv_internet_txt); } @@ -595,7 +662,10 @@ int main(int argc, const char *argv[]) poptFreeContext(pc); debug_level = debug; - tests_set_cwd(); + if (!use_net_test) { + printf("Network tests disabled. Rerun with the \"-n\" " + "option to run the full suite of tests\n"); + } resolv_suite = create_resolv_suite(); sr = srunner_create(resolv_suite); -- 1.6.6.1
0001-Do-not-run-negative-resolv-test-with-no-network.patch.sig
Description: PGP signature
_______________________________________________ sssd-devel mailing list sssd-devel@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/sssd-devel