mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
Update the isc_ht unit test to also tesh rehashing
As incremental rehashing has been added to isc_ht implementation, we need to test whether the rehashing works. Update the isc_ht unit test to test: * preinitialized hash table large enough to hold all the elements * smallest hash table that fully grows to hold all the elements * partially preinitialized hash table that grows * iterating while rehashing is in progress
This commit is contained in:
@@ -34,6 +34,10 @@
|
|||||||
|
|
||||||
#include "isctest.h"
|
#include "isctest.h"
|
||||||
|
|
||||||
|
/* INCLUDE LAST */
|
||||||
|
|
||||||
|
#include "../ht.c"
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_setup(void **state) {
|
_setup(void **state) {
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
@@ -56,12 +60,12 @@ _teardown(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_ht_full(int bits, uintptr_t count) {
|
test_ht_full(uint8_t init_bits, uint8_t finish_bits, uintptr_t count) {
|
||||||
isc_ht_t *ht = NULL;
|
isc_ht_t *ht = NULL;
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
uintptr_t i;
|
uintptr_t i;
|
||||||
|
|
||||||
isc_ht_init(&ht, test_mctx, bits);
|
isc_ht_init(&ht, test_mctx, init_bits);
|
||||||
assert_non_null(ht);
|
assert_non_null(ht);
|
||||||
|
|
||||||
for (i = 1; i < count; i++) {
|
for (i = 1; i < count; i++) {
|
||||||
@@ -191,6 +195,8 @@ test_ht_full(int bits, uintptr_t count) {
|
|||||||
assert_null(f);
|
assert_null(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert_int_equal(ht->hashbits[ht->hindex], finish_bits);
|
||||||
|
|
||||||
isc_ht_destroy(&ht);
|
isc_ht_destroy(&ht);
|
||||||
assert_null(ht);
|
assert_null(ht);
|
||||||
}
|
}
|
||||||
@@ -201,12 +207,12 @@ test_ht_iterator(void) {
|
|||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
isc_ht_iter_t *iter = NULL;
|
isc_ht_iter_t *iter = NULL;
|
||||||
uintptr_t i;
|
uintptr_t i;
|
||||||
uintptr_t count = 10000;
|
uintptr_t count = 6300;
|
||||||
uint32_t walked;
|
uint32_t walked;
|
||||||
unsigned char key[16];
|
unsigned char key[16];
|
||||||
size_t tksize;
|
size_t tksize;
|
||||||
|
|
||||||
isc_ht_init(&ht, test_mctx, 16);
|
isc_ht_init(&ht, test_mctx, HT_MIN_BITS);
|
||||||
assert_non_null(ht);
|
assert_non_null(ht);
|
||||||
for (i = 1; i <= count; i++) {
|
for (i = 1; i <= count; i++) {
|
||||||
/*
|
/*
|
||||||
@@ -219,6 +225,9 @@ test_ht_iterator(void) {
|
|||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* We want to iterate while rehashing is in progress */
|
||||||
|
assert_true(rehashing_in_progress(ht));
|
||||||
|
|
||||||
walked = 0;
|
walked = 0;
|
||||||
isc_ht_iter_create(ht, &iter);
|
isc_ht_iter_create(ht, &iter);
|
||||||
|
|
||||||
@@ -298,6 +307,9 @@ test_ht_iterator(void) {
|
|||||||
assert_int_equal(result, ISC_R_NOMORE);
|
assert_int_equal(result, ISC_R_NOMORE);
|
||||||
assert_int_equal(walked, 0);
|
assert_int_equal(walked, 0);
|
||||||
|
|
||||||
|
/* Iterator doesn't progress rehashing */
|
||||||
|
assert_true(rehashing_in_progress(ht));
|
||||||
|
|
||||||
isc_ht_iter_destroy(&iter);
|
isc_ht_iter_destroy(&iter);
|
||||||
assert_null(iter);
|
assert_null(iter);
|
||||||
|
|
||||||
@@ -305,25 +317,25 @@ test_ht_iterator(void) {
|
|||||||
assert_null(ht);
|
assert_null(ht);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 20 bit, 200K elements test */
|
/* 24 bit, 200K elements test, no rehashing */
|
||||||
static void
|
static void
|
||||||
isc_ht_20(void **state) {
|
isc_ht_24(void **state) {
|
||||||
UNUSED(state);
|
UNUSED(state);
|
||||||
test_ht_full(20, 200000);
|
test_ht_full(24, 24, 200000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 8 bit, 20000 elements crowded test */
|
/* 15 bit, 45K elements test, full rehashing */
|
||||||
|
static void
|
||||||
|
isc_ht_15(void **state) {
|
||||||
|
UNUSED(state);
|
||||||
|
test_ht_full(1, 15, 48000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 8 bit, 20k elements test, partial rehashing */
|
||||||
static void
|
static void
|
||||||
isc_ht_8(void **state) {
|
isc_ht_8(void **state) {
|
||||||
UNUSED(state);
|
UNUSED(state);
|
||||||
test_ht_full(8, 20000);
|
test_ht_full(8, 14, 20000);
|
||||||
}
|
|
||||||
|
|
||||||
/* 8 bit, 100 elements corner case test */
|
|
||||||
static void
|
|
||||||
isc_ht_1(void **state) {
|
|
||||||
UNUSED(state);
|
|
||||||
test_ht_full(1, 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* test hashtable iterator */
|
/* test hashtable iterator */
|
||||||
@@ -336,9 +348,9 @@ isc_ht_iterator_test(void **state) {
|
|||||||
int
|
int
|
||||||
main(void) {
|
main(void) {
|
||||||
const struct CMUnitTest tests[] = {
|
const struct CMUnitTest tests[] = {
|
||||||
cmocka_unit_test(isc_ht_20),
|
cmocka_unit_test(isc_ht_24),
|
||||||
|
cmocka_unit_test(isc_ht_15),
|
||||||
cmocka_unit_test(isc_ht_8),
|
cmocka_unit_test(isc_ht_8),
|
||||||
cmocka_unit_test(isc_ht_1),
|
|
||||||
cmocka_unit_test(isc_ht_iterator_test),
|
cmocka_unit_test(isc_ht_iterator_test),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user