Added torture test for bug #8910. Test remove_duplicate_addrs2().
authorJeremy Allison <jra@samba.org>
Mon, 21 May 2012 21:29:11 +0000 (14:29 -0700)
committerJeremy Allison <jra@samba.org>
Mon, 21 May 2012 23:31:17 +0000 (01:31 +0200)
Autobuild-User: Jeremy Allison <jra@samba.org>
Autobuild-Date: Tue May 22 01:31:17 CEST 2012 on sn-devel-104

source3/include/proto.h
source3/libsmb/namequery.c
source3/selftest/tests.py
source3/torture/torture.c

index f9306b88419df09203484e08c2f4ab5ceccec33a..31c709dd9b78a3561f80f09c50863b439dd41af2 100644 (file)
@@ -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,
index 662d8d6a09b7bb8efc9ca365fd35177f59147486..8934d8524371d8a97a9c17eff04532d666bea6de 100644 (file)
@@ -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;
 
index bcd9ae8524a1c195defbc540206cbd51ad2a1e17..fa1f5e50e9f7a09dfbdf0ae677986b3d0fe7edd1 100755 (executable)
@@ -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"])
index 962d0e7967383fcd253295149eca656865ed5e9f..83b06667bd939cb1a43fc21d153b394dc8920e09 100644 (file)
@@ -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}};