From c531aac27c433e0eb068a8a4f0a6c90cad2e44fa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 21 May 2012 14:29:11 -0700 Subject: Added torture test for bug #8910. Test remove_duplicate_addrs2(). Autobuild-User: Jeremy Allison Autobuild-Date: Tue May 22 01:31:17 CEST 2012 on sn-devel-104 --- source3/include/proto.h | 1 + source3/libsmb/namequery.c | 2 +- source3/selftest/tests.py | 3 +- source3/torture/torture.c | 104 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 2 deletions(-) (limited to 'source3') diff --git a/source3/include/proto.h b/source3/include/proto.h index f9306b8841..31c709dd9b 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -911,6 +911,7 @@ bool name_status_find(const char *q_name, const struct sockaddr_storage *to_ss, fstring name); int ip_service_compare(struct ip_service *ss1, struct ip_service *ss2); +int remove_duplicate_addrs2(struct ip_service *iplist, int count ); struct tevent_req *name_query_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, const char *name, int name_type, diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c index 662d8d6a09..8934d85243 100644 --- a/source3/libsmb/namequery.c +++ b/source3/libsmb/namequery.c @@ -1102,7 +1102,7 @@ static void sort_service_list(struct ip_service *servlist, int count) Remove any duplicate address/port pairs in the list *********************************************************************/ -static int remove_duplicate_addrs2(struct ip_service *iplist, int count ) +int remove_duplicate_addrs2(struct ip_service *iplist, int count ) { int i, j; diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py index bcd9ae8524..fa1f5e50e9 100755 --- a/source3/selftest/tests.py +++ b/source3/selftest/tests.py @@ -107,7 +107,8 @@ local_tests=[ "LOCAL-CONV-AUTH-INFO", "LOCAL-IDMAP-TDB-COMMON", "LOCAL-hex_encode_buf", - "LOCAL-sprintf_append"] + "LOCAL-sprintf_append", + "LOCAL-remove_duplicate_addrs2"] for t in local_tests: plantestsuite("samba3.smbtorture_s3.%s" % t, "s3dc", [os.path.join(samba3srcdir, "script/tests/test_smbtorture_s3.sh"), t, '//$SERVER_IP/tmp', '$USERNAME', '$PASSWORD', binpath('smbtorture3'), "-e"]) diff --git a/source3/torture/torture.c b/source3/torture/torture.c index 962d0e7967..83b06667bd 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -8726,6 +8726,109 @@ static bool run_local_hex_encode_buf(int dummy) return true; } +static const char *remove_duplicate_addrs2_test_strings_vector[] = { + "0.0.0.0", + "::0", + "1.2.3.1", + "0.0.0.0", + "0.0.0.0", + "1.2.3.2", + "1.2.3.3", + "1.2.3.4", + "1.2.3.5", + "::0", + "1.2.3.6", + "1.2.3.7", + "::0", + "::0", + "::0", + "1.2.3.8", + "1.2.3.9", + "1.2.3.10", + "1.2.3.11", + "1.2.3.12", + "1.2.3.13", + "1001:1111:1111:1000:0:1111:1111:1111", + "1.2.3.1", + "1.2.3.2", + "1.2.3.3", + "1.2.3.12", + "::0", + "::0" +}; + +static const char *remove_duplicate_addrs2_test_strings_result[] = { + "1.2.3.1", + "1.2.3.2", + "1.2.3.3", + "1.2.3.4", + "1.2.3.5", + "1.2.3.6", + "1.2.3.7", + "1.2.3.8", + "1.2.3.9", + "1.2.3.10", + "1.2.3.11", + "1.2.3.12", + "1.2.3.13", + "1001:1111:1111:1000:0:1111:1111:1111" +}; + +static bool run_local_remove_duplicate_addrs2(int dummy) +{ + struct ip_service test_vector[28]; + int count, i; + + /* Construct the sockaddr_storage test vector. */ + for (i = 0; i < 28; i++) { + struct addrinfo hints; + struct addrinfo *res = NULL; + int ret; + + memset(&hints, '\0', sizeof(hints)); + hints.ai_flags = AI_NUMERICHOST; + ret = getaddrinfo(remove_duplicate_addrs2_test_strings_vector[i], + NULL, + &hints, + &res); + if (ret) { + fprintf(stderr, "getaddrinfo failed on [%s]\n", + remove_duplicate_addrs2_test_strings_vector[i]); + return false; + } + memset(&test_vector[i], '\0', sizeof(test_vector[i])); + memcpy(&test_vector[i].ss, + res->ai_addr, + res->ai_addrlen); + freeaddrinfo(res); + } + + count = remove_duplicate_addrs2(test_vector, i); + + if (count != 14) { + fprintf(stderr, "count wrong (%d) should be 14\n", + count); + return false; + } + + for (i = 0; i < count; i++) { + char addr[INET6_ADDRSTRLEN]; + + print_sockaddr(addr, sizeof(addr), &test_vector[i].ss); + + if (strcmp(addr, remove_duplicate_addrs2_test_strings_result[i]) != 0) { + fprintf(stderr, "mismatch on [%d] [%s] [%s]\n", + i, + addr, + remove_duplicate_addrs2_test_strings_result[i]); + return false; + } + } + + printf("run_local_remove_duplicate_addrs2: success\n"); + return true; +} + static double create_procs(bool (*fn)(int), bool *result) { int i, status; @@ -8936,6 +9039,7 @@ static struct { { "LOCAL-sprintf_append", run_local_sprintf_append, 0}, { "LOCAL-hex_encode_buf", run_local_hex_encode_buf, 0}, { "LOCAL-IDMAP-TDB-COMMON", run_idmap_tdb_common_test, 0}, + { "LOCAL-remove_duplicate_addrs2", run_local_remove_duplicate_addrs2, 0}, {NULL, NULL, 0}}; -- cgit