From: Ondřej Surý Date: Wed, 29 Nov 2023 11:42:38 +0000 (+0100) Subject: Add isc_mem_overmem unit test X-Git-Tag: v9.19.19~22^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0b865c781aa766349cbd78e4f01dc793fd79ecd6;p=thirdparty%2Fbind9.git Add isc_mem_overmem unit test The new unit isc_mem_overmem unit test sets hi and lo water marks and then does allocations to go over: 0. x < lo_water 1. lo_water < x < hi_water 2. x > hi_water 3. lo_water < x < hi_water 4. < lo_water --- diff --git a/tests/isc/mem_test.c b/tests/isc/mem_test.c index 4a05efb1d92..22f6be9893a 100644 --- a/tests/isc/mem_test.c +++ b/tests/isc/mem_test.c @@ -291,6 +291,40 @@ ISC_RUN_TEST_IMPL(isc_mem_reallocate) { isc_mem_free(mctx, data); } +ISC_RUN_TEST_IMPL(isc_mem_overmem) { + isc_mem_t *omctx = NULL; + isc_mem_create(&omctx); + assert_non_null(omctx); + + isc_mem_setwater(omctx, 1024, 512); + + /* inuse < lo_water */ + void *data1 = isc_mem_allocate(omctx, 256); + assert_false(isc_mem_isovermem(omctx)); + + /* lo_water < inuse < hi_water */ + void *data2 = isc_mem_allocate(omctx, 512); + assert_false(isc_mem_isovermem(omctx)); + + /* hi_water < inuse */ + void *data3 = isc_mem_allocate(omctx, 512); + assert_true(isc_mem_isovermem(omctx)); + + /* lo_water < inuse < hi_water */ + isc_mem_free(omctx, data2); + assert_true(isc_mem_isovermem(omctx)); + + /* inuse < lo_water */ + isc_mem_free(omctx, data3); + assert_false(isc_mem_isovermem(omctx)); + + /* inuse == 0 */ + isc_mem_free(omctx, data1); + assert_false(isc_mem_isovermem(omctx)); + + isc_mem_destroy(&omctx); +} + #if ISC_MEM_TRACKLINES /* test mem with no flags */ @@ -486,6 +520,7 @@ ISC_TEST_ENTRY(isc_mem_inuse) ISC_TEST_ENTRY(isc_mem_zeroget) ISC_TEST_ENTRY(isc_mem_reget) ISC_TEST_ENTRY(isc_mem_reallocate) +ISC_TEST_ENTRY(isc_mem_overmem) #if ISC_MEM_TRACKLINES ISC_TEST_ENTRY(isc_mem_noflags)