]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Refactor the way we use memory context from isctest.c
authorOndřej Surý <ondrej@sury.org>
Sat, 9 Nov 2019 13:01:08 +0000 (14:01 +0100)
committerOndřej Surý <ondrej@sury.org>
Wed, 13 Nov 2019 13:47:47 +0000 (14:47 +0100)
This commit renames isctest {mctx,lctx} to test_{mctx,lctx} and cleans
up their usage in the individual unit tests.  This allows embedding
library .c files directly into the unit tests.

17 files changed:
lib/isc/tests/Makefile.in
lib/isc/tests/buffer_test.c
lib/isc/tests/counter_test.c
lib/isc/tests/heap_test.c
lib/isc/tests/ht_test.c
lib/isc/tests/isctest.c
lib/isc/tests/isctest.h
lib/isc/tests/lex_test.c
lib/isc/tests/mem_test.c
lib/isc/tests/pool_test.c
lib/isc/tests/radix_test.c
lib/isc/tests/random_test.c
lib/isc/tests/socket_test.c
lib/isc/tests/symtab_test.c
lib/isc/tests/task_test.c
lib/isc/tests/taskpool_test.c
lib/isc/tests/timer_test.c

index 046b8dcff3fab5980c7956927014b899e93df7aa..d743821a9e5556a586f4eb51c43cf93d75d2add1 100644 (file)
@@ -89,9 +89,9 @@ hash_test@EXEEXT@: hash_test.@O@ ${ISCDEPLIBS}
                ${LDFLAGS} -o $@ hash_test.@O@ \
                ${ISCLIBS} ${LIBS}
 
-heap_test@EXEEXT@: heap_test.@O@ ${ISCDEPLIBS}
+heap_test@EXEEXT@: heap_test.@O@ isctest.@O@ ${ISCDEPLIBS}
        ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
-               ${LDFLAGS} -o $@ heap_test.@O@ \
+               ${LDFLAGS} -o $@ heap_test.@O@ isctest.@O@ \
                ${ISCLIBS} ${LIBS}
 
 hmac_test@EXEEXT@: hmac_test.@O@ ${ISCDEPLIBS}
@@ -99,14 +99,14 @@ hmac_test@EXEEXT@: hmac_test.@O@ ${ISCDEPLIBS}
                ${LDFLAGS} -o $@ hmac_test.@O@ \
                ${ISCLIBS} ${LIBS}
 
-ht_test@EXEEXT@: ht_test.@O@ ${ISCDEPLIBS}
+ht_test@EXEEXT@: ht_test.@O@ isctest.@O@ ${ISCDEPLIBS}
        ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
-               ${LDFLAGS} -o $@ ht_test.@O@ \
+               ${LDFLAGS} -o $@ ht_test.@O@ isctest.@O@ \
                ${ISCLIBS} ${LIBS}
 
-lex_test@EXEEXT@: lex_test.@O@ ${ISCDEPLIBS}
+lex_test@EXEEXT@: lex_test.@O@ isctest.@O@ ${ISCDEPLIBS}
        ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
-               ${LDFLAGS} -o $@ lex_test.@O@ \
+               ${LDFLAGS} -o $@ lex_test.@O@ isctest.@O@ \
                ${ISCLIBS} ${LIBS}
 
 md_test@EXEEXT@: md_test.@O@ ${ISCDEPLIBS}
index 80d01e04e437a870040b07e7eb5bb358f3d11e51..71b9aa2110242a2cd123992fff7cdb5e43aa242f 100644 (file)
@@ -65,7 +65,7 @@ isc_buffer_reserve_test(void **state) {
        UNUSED(state);
 
        b = NULL;
-       result = isc_buffer_allocate(mctx, &b, 1024);
+       result = isc_buffer_allocate(test_mctx, &b, 1024);
        assert_int_equal(result, ISC_R_SUCCESS);
        assert_int_equal(b->length, 1024);
 
@@ -135,7 +135,7 @@ isc_buffer_dynamic_test(void **state) {
        UNUSED(state);
 
        b = NULL;
-       result = isc_buffer_allocate(mctx, &b, last_length);
+       result = isc_buffer_allocate(test_mctx, &b, last_length);
        assert_int_equal(result, ISC_R_SUCCESS);
        assert_non_null(b);
        assert_int_equal(b->length, last_length);
@@ -194,7 +194,7 @@ isc_buffer_copyregion_test(void **state) {
 
        UNUSED(state);
 
-       result = isc_buffer_allocate(mctx, &b, sizeof(data));
+       result = isc_buffer_allocate(test_mctx, &b, sizeof(data));
        assert_int_equal(result, ISC_R_SUCCESS);
 
        /*
@@ -234,7 +234,7 @@ isc_buffer_printf_test(void **state) {
         * Prepare a buffer with auto-reallocation enabled.
         */
        b = NULL;
-       result = isc_buffer_allocate(mctx, &b, 0);
+       result = isc_buffer_allocate(test_mctx, &b, 0);
        assert_int_equal(result, ISC_R_SUCCESS);
        isc_buffer_setautorealloc(b, true);
 
index 6770dd24536f429069d5f28753d9da9b8c3e9b67..55ef9916857ddb8af6874c5fe7528080a0c310aa 100644 (file)
@@ -58,7 +58,7 @@ isc_counter_test(void **state) {
 
        UNUSED(state);
 
-       result = isc_counter_create(mctx, 0, &counter);
+       result = isc_counter_create(test_mctx, 0, &counter);
        assert_int_equal(result, ISC_R_SUCCESS);
 
        for (i = 0; i < 10; i++) {
index b0b8e644815ef821f775f525280bfa8b2145e257..4a6d55c665660b7eafa0d2bb165ea558972da3bb 100644 (file)
 #include <isc/mem.h>
 #include <isc/util.h>
 
+#include "isctest.h"
+
+static int
+_setup(void **state) {
+       isc_result_t result;
+
+       UNUSED(state);
+
+       result = isc_test_begin(NULL, true, 0);
+       assert_int_equal(result, ISC_R_SUCCESS);
+
+       return (0);
+}
+
+static int
+_teardown(void **state) {
+       UNUSED(state);
+
+       isc_test_end();
+
+       return (0);
+}
+
 struct e {
        unsigned int value;
        unsigned int index;
@@ -51,16 +74,13 @@ idx(void *p, unsigned int i) {
 /* test isc_heap_delete() */
 static void
 isc_heap_delete_test(void **state) {
-       isc_mem_t *mctx = NULL;
        isc_heap_t *heap = NULL;
        isc_result_t result;
        struct e e1 = { 100, 0 };
 
        UNUSED(state);
 
-       isc_mem_create(&mctx);
-
-       result = isc_heap_create(mctx, compare, idx, 0, &heap);
+       result = isc_heap_create(test_mctx, compare, idx, 0, &heap);
        assert_int_equal(result, ISC_R_SUCCESS);
        assert_non_null(heap);
 
@@ -73,9 +93,6 @@ isc_heap_delete_test(void **state) {
 
        isc_heap_destroy(&heap);
        assert_int_equal(heap, NULL);
-
-       isc_mem_detach(&mctx);
-       assert_int_equal(mctx, NULL);
 }
 
 int
@@ -84,7 +101,7 @@ main(void) {
                cmocka_unit_test(isc_heap_delete_test),
        };
 
-       return (cmocka_run_group_tests(tests, NULL, NULL));
+       return (cmocka_run_group_tests(tests, _setup, _teardown));
 }
 
 #else /* HAVE_CMOCKA */
index 40bfccbc75f7def1384849bffd62f1412574c081..c18661454931410e22a819e9825a3289c6fc6c6c 100644 (file)
 #include <isc/string.h>
 #include <isc/util.h>
 
+#include "isctest.h"
+
+static int
+_setup(void **state) {
+       isc_result_t result;
+
+       UNUSED(state);
+
+       result = isc_test_begin(NULL, true, 0);
+       assert_int_equal(result, ISC_R_SUCCESS);
+
+       return (0);
+}
+
+static int
+_teardown(void **state) {
+       UNUSED(state);
+
+       isc_test_end();
+
+       return (0);
+}
+
+
 static void
 test_ht_full(int bits, uintptr_t count) {
        isc_ht_t *ht = NULL;
        isc_result_t result;
-       isc_mem_t *mctx = NULL;
        uintptr_t i;
 
-       isc_mem_create(&mctx);
-
-       result = isc_ht_init(&ht, mctx, bits);
+       result = isc_ht_init(&ht, test_mctx, bits);
        assert_int_equal(result, ISC_R_SUCCESS);
        assert_non_null(ht);
 
@@ -174,15 +195,12 @@ test_ht_full(int bits, uintptr_t count) {
 
        isc_ht_destroy(&ht);
        assert_null(ht);
-
-       isc_mem_detach(&mctx);
 }
 
 static void
 test_ht_iterator() {
        isc_ht_t *ht = NULL;
        isc_result_t result;
-       isc_mem_t *mctx = NULL;
        isc_ht_iter_t * iter = NULL;
        uintptr_t i;
        uintptr_t count = 10000;
@@ -190,9 +208,7 @@ test_ht_iterator() {
        unsigned char key[16];
        size_t tksize;
 
-       isc_mem_create(&mctx);
-
-       result = isc_ht_init(&ht, mctx, 16);
+       result = isc_ht_init(&ht, test_mctx, 16);
        assert_int_equal(result, ISC_R_SUCCESS);
        assert_non_null(ht);
        for (i = 1; i <= count; i++) {
@@ -293,8 +309,6 @@ test_ht_iterator() {
 
        isc_ht_destroy(&ht);
        assert_null(ht);
-
-       isc_mem_detach(&mctx);
 }
 
 /* 20 bit, 200K elements test */
@@ -335,7 +349,7 @@ main(void) {
                cmocka_unit_test(isc_ht_iterator_test),
        };
 
-       return (cmocka_run_group_tests(tests, NULL, NULL));
+       return (cmocka_run_group_tests(tests, _setup, _teardown));
 }
 
 #else /* HAVE_CMOCKA */
index 08ced36b303cbbce5210ef39076d3ad07fd4fcd0..5e7827a8e2f690d5e61f48e2d206d17c898ffcac 100644 (file)
@@ -28,8 +28,8 @@
 
 #include "isctest.h"
 
-isc_mem_t *mctx = NULL;
-isc_log_t *lctx = NULL;
+isc_mem_t *test_mctx = NULL;
+isc_log_t *test_lctx = NULL;
 isc_taskmgr_t *taskmgr = NULL;
 isc_timermgr_t *timermgr = NULL;
 isc_socketmgr_t *socketmgr = NULL;
@@ -88,13 +88,13 @@ create_managers(unsigned int workers) {
                workers = atoi(p);
        }
 
-       CHECK(isc_taskmgr_create(mctx, workers, 0, NULL, &taskmgr));
+       CHECK(isc_taskmgr_create(test_mctx, workers, 0, NULL, &taskmgr));
        CHECK(isc_task_create(taskmgr, 0, &maintask));
        isc_taskmgr_setexcltask(taskmgr, maintask);
 
-       CHECK(isc_timermgr_create(mctx, &timermgr));
-       CHECK(isc_socketmgr_create(mctx, &socketmgr));
-       netmgr = isc_nm_start(mctx, 3);
+       CHECK(isc_timermgr_create(test_mctx, &timermgr));
+       CHECK(isc_socketmgr_create(test_mctx, &socketmgr));
+       netmgr = isc_nm_start(test_mctx, 3);
        return (ISC_R_SUCCESS);
 
  cleanup:
@@ -113,18 +113,18 @@ isc_test_begin(FILE *logfile, bool start_managers,
 
        isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
 
-       INSIST(mctx == NULL);
-       isc_mem_create(&mctx);
+       INSIST(test_mctx == NULL);
+       isc_mem_create(&test_mctx);
 
        if (logfile != NULL) {
                isc_logdestination_t destination;
                isc_logconfig_t *logconfig = NULL;
 
-               INSIST(lctx == NULL);
-               CHECK(isc_log_create(mctx, &lctx, &logconfig));
+               INSIST(test_lctx == NULL);
+               CHECK(isc_log_create(test_mctx, &test_lctx, &logconfig));
 
-               isc_log_registercategories(lctx, categories);
-               isc_log_setcontext(lctx);
+               isc_log_registercategories(test_lctx, categories);
+               isc_log_setcontext(test_lctx);
 
                destination.file.stream = logfile;
                destination.file.name = NULL;
@@ -161,11 +161,11 @@ isc_test_end(void) {
 
        cleanup_managers();
 
-       if (lctx != NULL) {
-               isc_log_destroy(&lctx);
+       if (test_lctx != NULL) {
+               isc_log_destroy(&test_lctx);
        }
-       if (mctx != NULL) {
-               isc_mem_destroy(&mctx);
+       if (test_mctx != NULL) {
+               isc_mem_destroy(&test_mctx);
        }
 
        test_running = false;
index c89996721a5ac3087ac77ca8f9f53cf08a46001c..17b0342d23d9c97c2f613f592f435903f588bfe3 100644 (file)
@@ -33,8 +33,8 @@
                        goto cleanup; \
        } while (0)
 
-extern isc_mem_t *mctx;
-extern isc_log_t *lctx;
+extern isc_mem_t *test_mctx;
+extern isc_log_t *test_lctx;
 extern isc_taskmgr_t *taskmgr;
 extern isc_timermgr_t *timermgr;
 extern isc_socketmgr_t *socketmgr;
index 462375ae93d10949f4098224bb24417ea39541d5..709574e0e347eaa67192a49672b6f5e456cee894 100644 (file)
 #include <isc/mem.h>
 #include <isc/util.h>
 
+#include "isctest.h"
+
+static int
+_setup(void **state) {
+       isc_result_t result;
+
+       UNUSED(state);
+
+       result = isc_test_begin(NULL, true, 0);
+       assert_int_equal(result, ISC_R_SUCCESS);
+
+       return (0);
+}
+
+static int
+_teardown(void **state) {
+       UNUSED(state);
+
+       isc_test_end();
+
+       return (0);
+}
+
 /* check handling of 0xff */
 static void
 lex_0xff(void **state) {
-       isc_mem_t *mctx = NULL;
        isc_result_t result;
        isc_lex_t *lex = NULL;
        isc_buffer_t death_buf;
@@ -41,9 +63,7 @@ lex_0xff(void **state) {
 
        UNUSED(state);
 
-       isc_mem_create(&mctx);
-
-       result = isc_lex_create(mctx, 1024, &lex);
+       result = isc_lex_create(test_mctx, 1024, &lex);
        assert_int_equal(result, ISC_R_SUCCESS);
 
        isc_buffer_init(&death_buf, &death[0], sizeof(death));
@@ -56,14 +76,11 @@ lex_0xff(void **state) {
        assert_int_equal(result, ISC_R_SUCCESS);
 
        isc_lex_destroy(&lex);
-
-       isc_mem_destroy(&mctx);
 }
 
 /* check setting of source line */
 static void
 lex_setline(void **state) {
-       isc_mem_t *mctx = NULL;
        isc_result_t result;
        isc_lex_t *lex = NULL;
        unsigned char text[] = "text\nto\nbe\nprocessed\nby\nlexer";
@@ -74,9 +91,7 @@ lex_setline(void **state) {
 
        UNUSED(state);
 
-       isc_mem_create(&mctx);
-
-       result = isc_lex_create(mctx, 1024, &lex);
+       result = isc_lex_create(test_mctx, 1024, &lex);
        assert_int_equal(result, ISC_R_SUCCESS);
 
        isc_buffer_init(&buf, &text[0], sizeof(text));
@@ -103,8 +118,6 @@ lex_setline(void **state) {
        assert_int_equal(line, 105U);
 
        isc_lex_destroy(&lex);
-
-       isc_mem_destroy(&mctx);
 }
 
 int
@@ -114,7 +127,7 @@ main(void) {
                cmocka_unit_test(lex_setline),
        };
 
-       return (cmocka_run_group_tests(tests, NULL, NULL));
+       return (cmocka_run_group_tests(tests, _setup, _teardown));
 }
 
 #else /* HAVE_CMOCKA */
index 0f783422e67980a16b5cc4d6cd3cd19f60aeddd6..c1c63be6109484c19d18228308ba1fb7ed83e345 100644 (file)
@@ -73,19 +73,16 @@ isc_mem_test(void **state) {
        void *items1[50];
        void *items2[50];
        void *tmp;
-       isc_mem_t *localmctx = NULL;
        isc_mempool_t *mp1 = NULL, *mp2 = NULL;
        unsigned int i, j;
        int rval;
 
        UNUSED(state);
 
-       isc_mem_create(&localmctx);
-
-       result = isc_mempool_create(localmctx, 24, &mp1);
+       result = isc_mempool_create(test_mctx, 24, &mp1);
        assert_int_equal(result, ISC_R_SUCCESS);
 
-       result = isc_mempool_create(localmctx, 31, &mp2);
+       result = isc_mempool_create(test_mctx, 31, &mp2);
        assert_int_equal(result, ISC_R_SUCCESS);
 
        isc_mempool_setfreemax(mp1, MP1_FREEMAX);
@@ -151,11 +148,7 @@ isc_mem_test(void **state) {
        isc_mempool_destroy(&mp1);
        isc_mempool_destroy(&mp2);
 
-       isc_mem_destroy(&localmctx);
-
-       isc_mem_create(&localmctx);
-
-       result = isc_mempool_create(localmctx, 2, &mp1);
+       result = isc_mempool_create(test_mctx, 2, &mp1);
        assert_int_equal(result, ISC_R_SUCCESS);
 
        tmp = isc_mempool_get(mp1);
@@ -164,9 +157,6 @@ isc_mem_test(void **state) {
        isc_mempool_put(mp1, tmp);
 
        isc_mempool_destroy(&mp1);
-
-       isc_mem_destroy(&localmctx);
-
 }
 
 /* test TotalUse calculation */
@@ -200,16 +190,16 @@ isc_mem_total_test(void **state) {
 
        /* ISC_MEMFLAG_INTERNAL */
 
-       before = isc_mem_total(mctx);
+       before = isc_mem_total(test_mctx);
 
        for (i = 0; i < 100000; i++) {
                void *ptr;
 
-               ptr = isc_mem_allocate(mctx, 2048);
-               isc_mem_free(mctx, ptr);
+               ptr = isc_mem_allocate(test_mctx, 2048);
+               isc_mem_free(test_mctx, ptr);
        }
 
-       after = isc_mem_total(mctx);
+       after = isc_mem_total(test_mctx);
        diff = after - before;
 
        /* 2048 +8 bytes extra for size_info */
@@ -397,10 +387,10 @@ mem_thread(void *arg) {
 
        for (int i = 0; i < ITERS; i++) {
                for (int j = 0; j < NUM_ITEMS; j++) {
-                       items[j] = isc_mem_get(mctx, size);
+                       items[j] = isc_mem_get(test_mctx, size);
                }
                for (int j = 0; j < NUM_ITEMS; j++) {
-                       isc_mem_put(mctx, items[j], size);
+                       isc_mem_put(test_mctx, items[j], size);
                }
        }
 
@@ -470,7 +460,7 @@ isc_mempool_benchmark(void **state) {
 
        isc_mutex_init(&mplock);
 
-       result = isc_mempool_create(mctx, ITEM_SIZE, &mp);
+       result = isc_mempool_create(test_mctx, ITEM_SIZE, &mp);
        assert_int_equal(result, ISC_R_SUCCESS);
 
        isc_mempool_associatelock(mp, &mplock);
index b902869b86511f0923fee81137bbef87d03b67f2..5f803632f80656237cbb3dfb6603ae7eb87d151e 100644 (file)
@@ -79,7 +79,7 @@ create_pool(void **state) {
 
        UNUSED(state);
 
-       result = isc_pool_create(mctx, 8, poolfree, poolinit, taskmgr, &pool);
+       result = isc_pool_create(test_mctx, 8, poolfree, poolinit, taskmgr, &pool);
        assert_int_equal(result, ISC_R_SUCCESS);
        assert_int_equal(isc_pool_count(pool), 8);
 
@@ -95,7 +95,7 @@ expand_pool(void **state) {
 
        UNUSED(state);
 
-       result = isc_pool_create(mctx, 10, poolfree, poolinit, taskmgr, &pool1);
+       result = isc_pool_create(test_mctx, 10, poolfree, poolinit, taskmgr, &pool1);
        assert_int_equal(result, ISC_R_SUCCESS);
        assert_int_equal(isc_pool_count(pool1), 10);
 
@@ -141,7 +141,7 @@ get_objects(void **state) {
 
        UNUSED(state);
 
-       result = isc_pool_create(mctx, 2, poolfree, poolinit, taskmgr, &pool);
+       result = isc_pool_create(test_mctx, 2, poolfree, poolinit, taskmgr, &pool);
        assert_int_equal(result, ISC_R_SUCCESS);
        assert_int_equal(isc_pool_count(pool), 2);
 
index 5f49ac08fd24a854bae915c07e49cc8776270922..26fd006fffb2baca150640a28ace21c4bb4dee61 100644 (file)
@@ -63,7 +63,7 @@ isc_radix_search_test(void **state) {
 
        UNUSED(state);
 
-       result = isc_radix_create(mctx, &radix, 32);
+       result = isc_radix_create(test_mctx, &radix, 32);
        assert_int_equal(result, ISC_R_SUCCESS);
 
        in_addr.s_addr = inet_addr("3.3.3.0");
index 556acffa4b795bb998249c13347256b8f7905def..1dbdf0068a8f2fc0b2b7aeaceeef82bf578ee6ac 100644 (file)
@@ -39,6 +39,8 @@
 #include <isc/result.h>
 #include <isc/util.h>
 
+#include "isctest.h"
+
 #define REPS 25000
 
 typedef double (pvalue_func_t)(isc_mem_t *mctx,
@@ -74,6 +76,27 @@ typedef enum {
        ISC_NONCE_BYTES
 } isc_random_func;
 
+static int
+_setup(void **state) {
+       isc_result_t result;
+
+       UNUSED(state);
+
+       result = isc_test_begin(NULL, true, 0);
+       assert_int_equal(result, ISC_R_SUCCESS);
+
+       return (0);
+}
+
+static int
+_teardown(void **state) {
+       UNUSED(state);
+
+       isc_test_end();
+
+       return (0);
+}
+
 static double
 igamc(double a, double x) {
        double ans, ax, c, yc, r, t, y, z;
@@ -272,7 +295,6 @@ matrix_binaryrank(uint32_t *bits, size_t rows, size_t cols) {
 
 static void
 random_test(pvalue_func_t *func, isc_random_func test_func) {
-       isc_mem_t *mctx = NULL;
        uint32_t m;
        uint32_t j;
        uint32_t histogram[11] = { 0 };
@@ -286,8 +308,6 @@ random_test(pvalue_func_t *func, isc_random_func test_func) {
 
        tables_init();
 
-       isc_mem_create(&mctx);
-
        m = 1000;
        passed = 0;
 
@@ -334,7 +354,7 @@ random_test(pvalue_func_t *func, isc_random_func test_func) {
                        break;
                }
 
-               p_value = (*func)(mctx, (uint16_t *)values, REPS * 2);
+               p_value = (*func)(test_mctx, (uint16_t *)values, REPS * 2);
                if (p_value >= 0.01) {
                        passed++;
                }
@@ -841,7 +861,7 @@ main(int argc, char **argv) {
                }
        }
 
-       return (cmocka_run_group_tests(tests, NULL, NULL));
+       return (cmocka_run_group_tests(tests, _setup, _teardown));
 }
 
 #else /* HAVE_CMOCKA */
index 20cf26b22d3325f0e6cf3e837d927b568ab1f16a..77c2475f8741e5736899c4af6f21fd060e9982e8 100644 (file)
@@ -358,7 +358,7 @@ udp_dscp_v4_test(void **state) {
 
        completion_init(&completion);
 
-       socketevent = isc_socket_socketevent(mctx, s1, ISC_SOCKEVENT_SENDDONE,
+       socketevent = isc_socket_socketevent(test_mctx, s1, ISC_SOCKEVENT_SENDDONE,
                                             event_done, &completion);
        assert_non_null(socketevent);
 
@@ -452,7 +452,7 @@ udp_dscp_v6_test(void **state) {
 
        completion_init(&completion);
 
-       socketevent = isc_socket_socketevent(mctx, s1, ISC_SOCKEVENT_SENDDONE,
+       socketevent = isc_socket_socketevent(test_mctx, s1, ISC_SOCKEVENT_SENDDONE,
                                             event_done, &completion);
        assert_non_null(socketevent);
 
@@ -769,7 +769,7 @@ udp_trunc_test(void **state) {
 
        completion_init(&completion);
 
-       socketevent = isc_socket_socketevent(mctx, s1, ISC_SOCKEVENT_SENDDONE,
+       socketevent = isc_socket_socketevent(test_mctx, s1, ISC_SOCKEVENT_SENDDONE,
                                             event_done, &completion);
        assert_non_null(socketevent);
 
@@ -801,7 +801,7 @@ udp_trunc_test(void **state) {
 
        completion_init(&completion);
 
-       socketevent = isc_socket_socketevent(mctx, s1, ISC_SOCKEVENT_SENDDONE,
+       socketevent = isc_socket_socketevent(test_mctx, s1, ISC_SOCKEVENT_SENDDONE,
                                             event_done, &completion);
        assert_non_null(socketevent);
 
index fea0cda6995761cf9dcefc1b2ae9ccbe1b431ff7..28bb05383134cffa6208f7a782996b0784712db9 100644 (file)
@@ -55,8 +55,8 @@ undefine(char *key, unsigned int type, isc_symvalue_t value, void *arg) {
        UNUSED(arg);
 
        assert_int_equal(type, 1);
-       isc_mem_free(mctx, key);
-       isc_mem_free(mctx, value.as_pointer);
+       isc_mem_free(test_mctx, key);
+       isc_mem_free(test_mctx, value.as_pointer);
 }
 
 /* test symbol table growth */
@@ -70,7 +70,7 @@ symtab_grow(void **state) {
 
        UNUSED(state);
 
-       result = isc_symtab_create(mctx, 3, undefine, NULL, false, &st);
+       result = isc_symtab_create(test_mctx, 3, undefine, NULL, false, &st);
        assert_int_equal(result, ISC_R_SUCCESS);
        assert_non_null(st);
 
@@ -84,9 +84,9 @@ symtab_grow(void **state) {
                char str[16], *key;
 
                snprintf(str, sizeof(str), "%04x", i);
-               key = isc_mem_strdup(mctx, str);
+               key = isc_mem_strdup(test_mctx, str);
                assert_non_null(key);
-               value.as_pointer = isc_mem_strdup(mctx, str);
+               value.as_pointer = isc_mem_strdup(test_mctx, str);
                assert_non_null(value.as_pointer);
                result = isc_symtab_define(st, key, 1, value, policy);
                assert_int_equal(result, ISC_R_SUCCESS);
@@ -101,9 +101,9 @@ symtab_grow(void **state) {
                char str[16], *key;
 
                snprintf(str, sizeof(str), "%04x", i);
-               key = isc_mem_strdup(mctx, str);
+               key = isc_mem_strdup(test_mctx, str);
                assert_non_null(key);
-               value.as_pointer = isc_mem_strdup(mctx, str);
+               value.as_pointer = isc_mem_strdup(test_mctx, str);
                assert_non_null(value.as_pointer);
                result = isc_symtab_define(st, key, 1, value, policy);
                assert_int_equal(result, ISC_R_EXISTS);
index 9b15897a94d6efa007a59aade23f36148527b549..d44aee5898b4c7c07bb51b4f87d19492e2f865da 100644 (file)
@@ -167,14 +167,14 @@ all_events(void **state) {
        assert_int_equal(result, ISC_R_SUCCESS);
 
        /* First event */
-       event = isc_event_allocate(mctx, task, ISC_TASKEVENT_TEST,
+       event = isc_event_allocate(test_mctx, task, ISC_TASKEVENT_TEST,
                                   set, &a, sizeof (isc_event_t));
        assert_non_null(event);
 
        assert_int_equal(atomic_load(&a), 0);
        isc_task_send(task, &event);
 
-       event = isc_event_allocate(mctx, task, ISC_TASKEVENT_TEST,
+       event = isc_event_allocate(test_mctx, task, ISC_TASKEVENT_TEST,
                                   set, &b, sizeof (isc_event_t));
        assert_non_null(event);
 
@@ -229,7 +229,7 @@ privileged_events(void **state) {
        assert_false(isc_task_privilege(task2));
 
        /* First event: privileged */
-       event = isc_event_allocate(mctx, task1, ISC_TASKEVENT_TEST,
+       event = isc_event_allocate(test_mctx, task1, ISC_TASKEVENT_TEST,
                                   set, &a, sizeof (isc_event_t));
        assert_non_null(event);
 
@@ -237,7 +237,7 @@ privileged_events(void **state) {
        isc_task_send(task1, &event);
 
        /* Second event: not privileged */
-       event = isc_event_allocate(mctx, task2, ISC_TASKEVENT_TEST,
+       event = isc_event_allocate(test_mctx, task2, ISC_TASKEVENT_TEST,
                                   set, &b, sizeof (isc_event_t));
        assert_non_null(event);
 
@@ -245,7 +245,7 @@ privileged_events(void **state) {
        isc_task_send(task2, &event);
 
        /* Third event: privileged */
-       event = isc_event_allocate(mctx, task1, ISC_TASKEVENT_TEST,
+       event = isc_event_allocate(test_mctx, task1, ISC_TASKEVENT_TEST,
                                   set, &c, sizeof (isc_event_t));
        assert_non_null(event);
 
@@ -253,7 +253,7 @@ privileged_events(void **state) {
        isc_task_send(task1, &event);
 
        /* Fourth event: privileged */
-       event = isc_event_allocate(mctx, task1, ISC_TASKEVENT_TEST,
+       event = isc_event_allocate(test_mctx, task1, ISC_TASKEVENT_TEST,
                                   set, &d, sizeof (isc_event_t));
        assert_non_null(event);
 
@@ -261,7 +261,7 @@ privileged_events(void **state) {
        isc_task_send(task1, &event);
 
        /* Fifth event: not privileged */
-       event = isc_event_allocate(mctx, task2, ISC_TASKEVENT_TEST,
+       event = isc_event_allocate(test_mctx, task2, ISC_TASKEVENT_TEST,
                                   set, &e, sizeof (isc_event_t));
        assert_non_null(event);
 
@@ -350,7 +350,7 @@ privilege_drop(void **state) {
        assert_false(isc_task_privilege(task2));
 
        /* First event: privileged */
-       event = isc_event_allocate(mctx, task1, ISC_TASKEVENT_TEST,
+       event = isc_event_allocate(test_mctx, task1, ISC_TASKEVENT_TEST,
                                   set_and_drop, &a, sizeof (isc_event_t));
        assert_non_null(event);
 
@@ -358,7 +358,7 @@ privilege_drop(void **state) {
        isc_task_send(task1, &event);
 
        /* Second event: not privileged */
-       event = isc_event_allocate(mctx, task2, ISC_TASKEVENT_TEST,
+       event = isc_event_allocate(test_mctx, task2, ISC_TASKEVENT_TEST,
                                   set_and_drop, &b, sizeof (isc_event_t));
        assert_non_null(event);
 
@@ -366,7 +366,7 @@ privilege_drop(void **state) {
        isc_task_send(task2, &event);
 
        /* Third event: privileged */
-       event = isc_event_allocate(mctx, task1, ISC_TASKEVENT_TEST,
+       event = isc_event_allocate(test_mctx, task1, ISC_TASKEVENT_TEST,
                                   set_and_drop, &c, sizeof (isc_event_t));
        assert_non_null(event);
 
@@ -374,7 +374,7 @@ privilege_drop(void **state) {
        isc_task_send(task1, &event);
 
        /* Fourth event: privileged */
-       event = isc_event_allocate(mctx, task1, ISC_TASKEVENT_TEST,
+       event = isc_event_allocate(test_mctx, task1, ISC_TASKEVENT_TEST,
                                   set_and_drop, &d, sizeof (isc_event_t));
        assert_non_null(event);
 
@@ -382,7 +382,7 @@ privilege_drop(void **state) {
        isc_task_send(task1, &event);
 
        /* Fifth event: not privileged */
-       event = isc_event_allocate(mctx, task2, ISC_TASKEVENT_TEST,
+       event = isc_event_allocate(test_mctx, task2, ISC_TASKEVENT_TEST,
                                   set_and_drop, &e, sizeof (isc_event_t));
        assert_non_null(event);
 
@@ -551,7 +551,7 @@ basic(void **state) {
                 * structure (socket, timer, task, etc) but this is just a
                 * test program.
                 */
-               event = isc_event_allocate(mctx, (void *)1, 1, basic_cb,
+               event = isc_event_allocate(test_mctx, (void *)1, 1, basic_cb,
                                           testarray[i], sizeof(*event));
                assert_non_null(event);
                isc_task_send(task1, &event);
@@ -653,12 +653,12 @@ task_exclusive(void **state) {
                        isc_taskmgr_setexcltask(taskmgr, tasks[6]);
                }
 
-               v = isc_mem_get(mctx, sizeof *v);
+               v = isc_mem_get(test_mctx, sizeof *v);
                assert_non_null(v);
 
                *v = i;
 
-               event = isc_event_allocate(mctx, NULL, 1, exclusive_cb,
+               event = isc_event_allocate(test_mctx, NULL, 1, exclusive_cb,
                                           v, sizeof(*event));
                assert_non_null(event);
 
@@ -718,6 +718,7 @@ maxtask_cb(isc_task_t *task, isc_event_t *event) {
 
 static void
 manytasks(void **state) {
+       isc_mem_t *mctx = NULL;
        isc_result_t result;
        isc_event_t *event = NULL;
        uintptr_t ntasks = 10000;
@@ -851,7 +852,7 @@ shutdown(void **state) {
        /*
         * This event causes the task to wait on cv.
         */
-       event = isc_event_allocate(mctx, &senders[1], event_type, sd_event1,
+       event = isc_event_allocate(test_mctx, &senders[1], event_type, sd_event1,
                                   NULL, sizeof(*event));
        assert_non_null(event);
        isc_task_send(task, &event);
@@ -860,7 +861,7 @@ shutdown(void **state) {
         * Now we fill up the task's event queue with some events.
         */
        for (i = 0; i < 256; ++i) {
-               event = isc_event_allocate(mctx, &senders[1], event_type,
+               event = isc_event_allocate(test_mctx, &senders[1], event_type,
                                           sd_event2, NULL, sizeof(*event));
                assert_non_null(event);
                isc_task_send(task, &event);
@@ -942,7 +943,7 @@ post_shutdown(void **state) {
        /*
         * This event causes the task to wait on cv.
         */
-       event = isc_event_allocate(mctx, &senders[1], event_type, psd_event1,
+       event = isc_event_allocate(test_mctx, &senders[1], event_type, psd_event1,
                                   NULL, sizeof(*event));
        assert_non_null(event);
        isc_task_send(task, &event);
@@ -1083,7 +1084,7 @@ test_purge(int sender, int type, int tag, int exp_purged) {
        /*
         * Block the task on cv.
         */
-       event = isc_event_allocate(mctx, (void *)1, 9999,
+       event = isc_event_allocate(test_mctx, (void *)1, 9999,
                                   pg_event1, NULL, sizeof(*event));
 
        assert_non_null(event);
@@ -1098,7 +1099,7 @@ test_purge(int sender, int type, int tag, int exp_purged) {
                for (type_cnt = 0; type_cnt < TYPECNT; ++type_cnt) {
                        for (tag_cnt = 0; tag_cnt < TAGCNT; ++tag_cnt) {
                                eventtab[event_cnt] =
-                                       isc_event_allocate(mctx,
+                                       isc_event_allocate(test_mctx,
                                            &senders[sender + sender_cnt],
                                            (isc_eventtype_t)(type + type_cnt),
                                            pg_event2, NULL, sizeof(*event));
@@ -1382,12 +1383,12 @@ try_purgeevent(bool purgeable) {
        /*
         * Block the task on cv.
         */
-       event1 = isc_event_allocate(mctx, (void *)1, (isc_eventtype_t)1,
+       event1 = isc_event_allocate(test_mctx, (void *)1, (isc_eventtype_t)1,
                                    pge_event1, NULL, sizeof(*event1));
        assert_non_null(event1);
        isc_task_send(task, &event1);
 
-       event2 = isc_event_allocate(mctx, (void *)1, (isc_eventtype_t)1,
+       event2 = isc_event_allocate(test_mctx, (void *)1, (isc_eventtype_t)1,
                                    pge_event2, NULL, sizeof(*event2));
        assert_non_null(event2);
 
index 0dfdc0b93e5454859cd633c85ed8164f6fc173d6..9621690bb53fd4f4bfa8cfeec8f01791ac68b357 100644 (file)
@@ -58,7 +58,7 @@ create_pool(void **state) {
 
        UNUSED(state);
 
-       result = isc_taskpool_create(taskmgr, mctx, 8, 2, &pool);
+       result = isc_taskpool_create(taskmgr, test_mctx, 8, 2, &pool);
        assert_int_equal(result, ISC_R_SUCCESS);
        assert_int_equal(isc_taskpool_size(pool), 8);
 
@@ -74,7 +74,7 @@ expand_pool(void **state) {
 
        UNUSED(state);
 
-       result = isc_taskpool_create(taskmgr, mctx, 10, 2, &pool1);
+       result = isc_taskpool_create(taskmgr, test_mctx, 10, 2, &pool1);
        assert_int_equal(result, ISC_R_SUCCESS);
        assert_int_equal(isc_taskpool_size(pool1), 10);
 
@@ -119,7 +119,7 @@ get_tasks(void **state) {
 
        UNUSED(state);
 
-       result = isc_taskpool_create(taskmgr, mctx, 2, 2, &pool);
+       result = isc_taskpool_create(taskmgr, test_mctx, 2, 2, &pool);
        assert_int_equal(result, ISC_R_SUCCESS);
        assert_int_equal(isc_taskpool_size(pool), 2);
 
@@ -150,7 +150,7 @@ set_privilege(void **state) {
 
        UNUSED(state);
 
-       result = isc_taskpool_create(taskmgr, mctx, 2, 2, &pool);
+       result = isc_taskpool_create(taskmgr, test_mctx, 2, 2, &pool);
        assert_int_equal(result, ISC_R_SUCCESS);
        assert_int_equal(isc_taskpool_size(pool), 2);
 
index 829019986b5cdf95dae39d33c13f37e23fa51d66..e6da158fcfc9f180390109a51e0690a68700520c 100644 (file)
@@ -518,7 +518,7 @@ purge(void **state) {
 
        LOCK(&mx);
 
-       event = isc_event_allocate(mctx, (void *)1 , (isc_eventtype_t)1,
+       event = isc_event_allocate(test_mctx, (void *)1 , (isc_eventtype_t)1,
                                   start_event, NULL, sizeof(*event));
        assert_non_null(event);
        isc_task_send(task1, &event);