]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Make deleg cleanuptests memory assertions 32-bit-safe 12061/head
authorMichal Nowak <mnowak@isc.org>
Wed, 20 May 2026 08:59:49 +0000 (08:59 +0000)
committerMichal Nowak <mnowak@isc.org>
Wed, 20 May 2026 13:29:22 +0000 (13:29 +0000)
Each address entry stored by dns_delegset_addaddr() is an
isc_netaddrlink_t, whose size depends on sizeof(void *) via the
ISC_LINK macro (24 bytes of address + two prev/next pointers): 40
bytes on 64-bit, 32 bytes on 32-bit. The hardcoded 4 MB / 8 MB
ranges only held on 64-bit, so dns_deleg_cleanuptests failed on
armv7l with isc_mem_inuse() returning ~3.2 MB.

Express the expected ranges in terms of sizeof(isc_netaddrlink_t)
so they scale with pointer width, and pull the 99999 entry count
out into a NENTRIES macro.

Assisted-by: Claude:claude-opus-4-7
tests/dns/deleg_test.c

index d3af6aba966210f5515fa903435c17447727114d..9497caf2753d21206d818e273896b18bc83a40e0 100644 (file)
@@ -52,6 +52,15 @@ isc_stdtime_now(void) {
 
 #include <tests/isc.h>
 
+/*
+ * cleanuptests adds NENTRIES address entries to a delegset; each is an
+ * isc_netaddrlink_t whose size depends on sizeof(void *) via ISC_LINK.
+ * Express memory expectations in terms of that struct so the test works
+ * on both 32-bit and 64-bit targets.
+ */
+#define NENTRIES       99999
+#define ENTRIES_MEM(n) ((size_t)(n) * sizeof(isc_netaddrlink_t))
+
 static void
 shutdownloop(ISC_ATTR_UNUSED void *arg) {
        isc_loopmgr_shutdown();
@@ -587,7 +596,8 @@ cleanuptests_phase3(void *arg) {
        dns_delegset_t *delegset = NULL;
        isc_result_t result;
 
-       assert_int_in_range(isc_mem_inuse(db->mctx), 8000000, 8100000);
+       assert_int_in_range(isc_mem_inuse(db->mctx), ENTRIES_MEM(2 * NENTRIES),
+                           ENTRIES_MEM(2 * NENTRIES) + 100000);
 
        /*
         * baz. is there, but bar. is gone, as it has been
@@ -612,7 +622,8 @@ cleanuptests_phase2(void *arg) {
        dns_delegset_t *delegset = NULL;
        isc_result_t result;
 
-       assert_int_in_range(isc_mem_inuse(db->mctx), 4000000, 4100000);
+       assert_int_in_range(isc_mem_inuse(db->mctx), ENTRIES_MEM(NENTRIES),
+                           ENTRIES_MEM(NENTRIES) + 100000);
 
        /*
         * bar. is there
@@ -629,10 +640,11 @@ cleanuptests_phase2(void *arg) {
        dns_delegset_allocdeleg(delegset, DNS_DELEGTYPE_DELEG_ADDRESSES,
                                &deleg);
 
-       for (size_t i = 0; i < 99999; i++) {
+       for (size_t i = 0; i < NENTRIES; i++) {
                addipdeleg(AF_INET6, "1111::2222", delegset, deleg);
        }
-       assert_int_in_range(isc_mem_inuse(db->mctx), 8000000, 8100000);
+       assert_int_in_range(isc_mem_inuse(db->mctx), ENTRIES_MEM(2 * NENTRIES),
+                           ENTRIES_MEM(2 * NENTRIES) + 100000);
        writedb(db, "baz.", 30, &delegset, true);
        deleg = NULL;
 
@@ -677,11 +689,12 @@ cleanuptests(ISC_ATTR_UNUSED void *arg) {
 
        assert_int_in_range(isc_mem_inuse(db->mctx), 500, 2000);
 
-       for (size_t i = 0; i < 99999; i++) {
+       for (size_t i = 0; i < NENTRIES; i++) {
                addipdeleg(AF_INET6, "1111::2222", delegset, deleg);
        }
 
-       assert_int_in_range(isc_mem_inuse(db->mctx), 4000000, 4100000);
+       assert_int_in_range(isc_mem_inuse(db->mctx), ENTRIES_MEM(NENTRIES),
+                           ENTRIES_MEM(NENTRIES) + 100000);
 
        writedb(db, "stuff.", 10, &delegset, true);
        deleg = NULL;
@@ -694,7 +707,7 @@ cleanuptests(ISC_ATTR_UNUSED void *arg) {
        dns_delegset_allocdeleg(delegset, DNS_DELEGTYPE_DELEG_ADDRESSES,
                                &deleg);
 
-       for (size_t i = 0; i < 99999; i++) {
+       for (size_t i = 0; i < NENTRIES; i++) {
                addipdeleg(AF_INET6, "1111::2222", delegset, deleg);
        }
 
@@ -703,7 +716,8 @@ cleanuptests(ISC_ATTR_UNUSED void *arg) {
         * with DB mem context) overmem conditions will be detected, and the
         * expired node will be removed
         */
-       assert_int_in_range(isc_mem_inuse(db->mctx), 8000000, 8100000);
+       assert_int_in_range(isc_mem_inuse(db->mctx), ENTRIES_MEM(2 * NENTRIES),
+                           ENTRIES_MEM(2 * NENTRIES) + 100000);
        writedb(db, "bar.", 30, &delegset, true);
        deleg = NULL;