From b6d82a481a45360852be7c3792c33abebf723c3c Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Thu, 10 Mar 2016 17:51:39 +0300 Subject: [PATCH] Ht: regressions: validate serial: check that our hash function was actually called. Of course, assumes that there won't be an overflow caueing it to be exactly 0 in the end... The test fails. --- regressions/ck_ht/validate/serial.c | 31 +++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/regressions/ck_ht/validate/serial.c b/regressions/ck_ht/validate/serial.c index fa3f874..9a85c2f 100644 --- a/regressions/ck_ht/validate/serial.c +++ b/regressions/ck_ht/validate/serial.c @@ -33,6 +33,9 @@ #include #include #include "../../common.h" +#include "../../../src/ck_ht_hash.h" + +static size_t hash_times_called = 0; static void * ht_malloc(size_t r) @@ -51,6 +54,18 @@ ht_free(void *p, size_t b, bool r) return; } +static void +ht_hash_wrapper(struct ck_ht_hash *h, + const void *key, + size_t length, + uint64_t seed) +{ + hash_times_called++; + + h->value = (unsigned long)MurmurHash64A(key, length, seed); + return; +} + static struct ck_malloc my_allocator = { .malloc = ht_malloc, .free = ht_free @@ -82,7 +97,7 @@ main(void) mode |= CK_HT_WORKLOAD_DELETE; #endif - if (ck_ht_init(&ht, mode, NULL, &my_allocator, 2, 6602834) == false) { + if (ck_ht_init(&ht, mode, ht_hash_wrapper, &my_allocator, 2, 6602834) == false) { perror("ck_ht_init"); exit(EXIT_FAILURE); } @@ -247,7 +262,14 @@ main(void) } ck_ht_destroy(&ht); - if (ck_ht_init(&ht, CK_HT_MODE_DIRECT, NULL, &my_allocator, 8, 6602834) == false) { + + if (hash_times_called == 0) { + ck_error("ERROR: Our hash function was not called!\n"); + } + + hash_times_called = 0; + + if (ck_ht_init(&ht, CK_HT_MODE_DIRECT, ht_hash_wrapper, &my_allocator, 8, 6602834) == false) { perror("ck_ht_init"); exit(EXIT_FAILURE); } @@ -278,5 +300,10 @@ main(void) } ck_ht_destroy(&ht); + + if (hash_times_called == 0) { + ck_error("ERROR: Our hash function was not called!\n"); + } + return 0; }