]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Prevent rare rbt_insert_and_remove unit test failures
authorMichał Kępień <michal@isc.org>
Tue, 14 Aug 2018 08:43:51 +0000 (10:43 +0200)
committerMichał Kępień <michal@isc.org>
Tue, 14 Aug 2018 08:44:59 +0000 (10:44 +0200)
When two or more absolute, two-label names are added to a completely
empty RBT, an extra, empty node for the root name will be created due to
node splitting.  check_tree() expects that, but the extra node will not
be created when just one name is added to a completely empty RBT.  This
problem could be handled inside check_tree(), but that would introduce
unnecessary complexity into it since adding a single name will result in
a different node count for a completely empty RBT (node count will be 1)
and an RBT containing only an empty node for the root name, created due
to prior node splitting (node count will be 2).  Thus, first explicitly
create a node for the root name to prevent rare check_tree() failures
caused by a single name being added in the first iteration of the
insert/remove loop.

(cherry picked from commit 13fe76379834b8d588abe5913a1a7676f4d6637e)

lib/dns/tests/rbt_test.c

index fdfb3328a1024d4ead04d71865b7ad61dabc1a27..81d97d4dedd0fe8f9377ce698dd2ba1be7217eca 100644 (file)
@@ -911,6 +911,7 @@ insert_nodes(dns_rbt_t *mytree, char **names,
                                node->data = n;
                                names[*names_count] = isc_mem_strdup(mctx,
                                                                     namebuf);
+                               ATF_REQUIRE(names[*names_count] != NULL);
                                *names_count += 1;
                                break;
                        }
@@ -998,6 +999,7 @@ ATF_TC_BODY(rbt_insert_and_remove, tc) {
         */
        isc_result_t result;
        dns_rbt_t *mytree = NULL;
+       size_t *n;
        /*
         * We use an array for storing names instead of a set
         * structure. It's slow, but works and is good enough for tests.
@@ -1016,6 +1018,11 @@ ATF_TC_BODY(rbt_insert_and_remove, tc) {
        result = dns_rbt_create(mctx, delete_data, NULL, &mytree);
        ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
 
+       n = isc_mem_get(mctx, sizeof(size_t));
+       ATF_REQUIRE(n != NULL);
+       result = dns_rbt_addname(mytree, dns_rootname, n);
+       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+
        memset(names, 0, sizeof(names));
        names_count = 0;
 
@@ -1056,6 +1063,12 @@ ATF_TC_BODY(rbt_insert_and_remove, tc) {
                }
        }
 
+       result = dns_rbt_deletename(mytree, dns_rootname, false);
+       ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
+                        "result: %s", isc_result_totext(result));
+       ATF_CHECK_EQ_MSG(dns_rbt_nodecount(mytree), 0,
+                        "%u != 0", dns_rbt_nodecount(mytree));
+
        dns_rbt_destroy(&mytree);
 
        dns_test_end();