From: Brian Aker Date: Wed, 21 Sep 2011 17:19:46 +0000 (-0700) Subject: Make 64bit fnv optional. X-Git-Tag: 0.53~7 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=b446f6c049da5f9c2516a19024c97a9951168c6a;p=awesomized%2Flibmemcached Make 64bit fnv optional. --- diff --git a/configure.ac b/configure.ac index 5b71b302..fc349ae0 100644 --- a/configure.ac +++ b/configure.ac @@ -92,6 +92,7 @@ ENABLE_UTILLIB SETSOCKOPT_SANITY ENABLE_HSIEH_HASH ENABLE_MURMUR_HASH +ENABLE_FNV64_HASH ENABLE_MEMASLAP PROTOCOL_BINARY_TEST ENABLE_DEPRECATED diff --git a/libhashkit/algorithm.cc b/libhashkit/algorithm.cc index de00081d..37d1cb43 100644 --- a/libhashkit/algorithm.cc +++ b/libhashkit/algorithm.cc @@ -38,19 +38,15 @@ uint32_t libhashkit_crc32(const char *key, size_t key_length) return hashkit_crc32(key, key_length, NULL); } -#ifdef HAVE_HSIEH_HASH uint32_t libhashkit_hsieh(const char *key, size_t key_length) { return hashkit_hsieh(key, key_length, NULL); } -#endif -#ifdef HAVE_MURMUR_HASH uint32_t libhashkit_murmur(const char *key, size_t key_length) { return hashkit_murmur(key, key_length, NULL); } -#endif uint32_t libhashkit_jenkins(const char *key, size_t key_length) { diff --git a/libhashkit/algorithm.h b/libhashkit/algorithm.h index 58b40bc3..fa5f3ae5 100644 --- a/libhashkit/algorithm.h +++ b/libhashkit/algorithm.h @@ -35,15 +35,11 @@ uint32_t libhashkit_fnv1a_32(const char *key, size_t key_length); HASHKIT_API uint32_t libhashkit_crc32(const char *key, size_t key_length); -#ifdef HAVE_HSIEH_HASH HASHKIT_API uint32_t libhashkit_hsieh(const char *key, size_t key_length); -#endif -#ifdef HAVE_MURMUR_HASH HASHKIT_API uint32_t libhashkit_murmur(const char *key, size_t key_length); -#endif HASHKIT_API uint32_t libhashkit_jenkins(const char *key, size_t key_length); @@ -69,15 +65,11 @@ uint32_t hashkit_fnv1a_32(const char *key, size_t key_length, void *context); HASHKIT_LOCAL uint32_t hashkit_crc32(const char *key, size_t key_length, void *context); -#ifdef HAVE_HSIEH_HASH HASHKIT_LOCAL uint32_t hashkit_hsieh(const char *key, size_t key_length, void *context); -#endif -#ifdef HAVE_MURMUR_HASH HASHKIT_LOCAL uint32_t hashkit_murmur(const char *key, size_t key_length, void *context); -#endif HASHKIT_LOCAL uint32_t hashkit_jenkins(const char *key, size_t key_length, void *context); diff --git a/libhashkit/fnv_64.cc b/libhashkit/fnv_64.cc index 0cfce633..302215a0 100644 --- a/libhashkit/fnv_64.cc +++ b/libhashkit/fnv_64.cc @@ -38,6 +38,8 @@ #include +#if __WORDSIZE == 64 && defined(HAVE_FNV64_HASH) + /* FNV hash'es lifted from Dustin Sallings work */ static uint64_t FNV_64_INIT= 0xcbf29ce484222325; static uint64_t FNV_64_PRIME= 0x100000001b3; @@ -69,3 +71,15 @@ uint32_t hashkit_fnv1a_64(const char *key, size_t key_length, void *) return hash; } + +#else +uint32_t hashkit_fnv1_64(const char *, size_t, void *) +{ + return 0; +} + +uint32_t hashkit_fnv1a_64(const char *, size_t, void *) +{ + return 0; +} +#endif diff --git a/libhashkit/function.cc b/libhashkit/function.cc index 7ac91007..044ca07d 100644 --- a/libhashkit/function.cc +++ b/libhashkit/function.cc @@ -10,50 +10,74 @@ static hashkit_return_t _set_function(struct hashkit_st::hashkit_function_st *self, hashkit_hash_algorithm_t hash_algorithm) { + if (self == NULL) + { + return HASHKIT_INVALID_ARGUMENT; + } + switch (hash_algorithm) { - case HASHKIT_HASH_DEFAULT: - self->function= hashkit_one_at_a_time; - break; case HASHKIT_HASH_MD5: self->function= hashkit_md5; break; + case HASHKIT_HASH_CRC: self->function= hashkit_crc32; break; + case HASHKIT_HASH_FNV1_64: - self->function= hashkit_fnv1_64; - break; + if (libhashkit_has_algorithm(HASHKIT_HASH_FNV1_64)) + { + self->function= hashkit_fnv1_64; + break; + } + return HASHKIT_INVALID_ARGUMENT; + case HASHKIT_HASH_FNV1A_64: - self->function= hashkit_fnv1a_64; - break; + if (libhashkit_has_algorithm(HASHKIT_HASH_FNV1_64)) + { + self->function= hashkit_fnv1a_64; + break; + } + return HASHKIT_INVALID_ARGUMENT; + case HASHKIT_HASH_FNV1_32: self->function= hashkit_fnv1_32; break; + case HASHKIT_HASH_FNV1A_32: self->function= hashkit_fnv1a_32; break; + case HASHKIT_HASH_HSIEH: -#ifdef HAVE_HSIEH_HASH - self->function= hashkit_hsieh; - break; -#else - return HASHKIT_FAILURE; -#endif + if (libhashkit_has_algorithm(HASHKIT_HASH_HSIEH)) + { + self->function= hashkit_hsieh; + break; + } + return HASHKIT_INVALID_ARGUMENT; + case HASHKIT_HASH_MURMUR: -#ifdef HAVE_MURMUR_HASH - self->function= hashkit_murmur; - break; -#else - return HASHKIT_FAILURE; -#endif + if (libhashkit_has_algorithm(HASHKIT_HASH_MURMUR)) + { + self->function= hashkit_murmur; + break; + } + return HASHKIT_INVALID_ARGUMENT; + case HASHKIT_HASH_JENKINS: self->function= hashkit_jenkins; break; + case HASHKIT_HASH_CUSTOM: return HASHKIT_INVALID_ARGUMENT; + + case HASHKIT_HASH_DEFAULT: + self->function= hashkit_one_at_a_time; + break; + case HASHKIT_HASH_MAX: - default: + self->function= hashkit_one_at_a_time; return HASHKIT_INVALID_HASH; } @@ -74,6 +98,11 @@ hashkit_return_t hashkit_set_distribution_function(hashkit_st *self, hashkit_has static hashkit_return_t _set_custom_function(struct hashkit_st::hashkit_function_st *self, hashkit_hash_fn function, void *context) { + if (self == NULL) + { + return HASHKIT_INVALID_ARGUMENT; + } + if (function) { self->function= function; @@ -87,11 +116,22 @@ static hashkit_return_t _set_custom_function(struct hashkit_st::hashkit_function hashkit_return_t hashkit_set_custom_function(hashkit_st *self, hashkit_hash_fn function, void *context) { + if (self == NULL) + { + return HASHKIT_INVALID_ARGUMENT; + } + + return _set_custom_function(&self->base_hash, function, context); } hashkit_return_t hashkit_set_custom_distribution_function(hashkit_st *self, hashkit_hash_fn function, void *context) { + if (self == NULL) + { + return HASHKIT_INVALID_ARGUMENT; + } + return _set_custom_function(&self->distribution_hash, function, context); } @@ -125,18 +165,14 @@ static hashkit_hash_algorithm_t get_function_type(const hashkit_hash_fn function { return HASHKIT_HASH_FNV1A_32; } -#ifdef HAVE_HSIEH_HASH else if (function == hashkit_hsieh) { return HASHKIT_HASH_HSIEH; } -#endif -#ifdef HAVE_MURMUR_HASH else if (function == hashkit_murmur) { return HASHKIT_HASH_MURMUR; } -#endif else if (function == hashkit_jenkins) { return HASHKIT_HASH_JENKINS; @@ -147,10 +183,20 @@ static hashkit_hash_algorithm_t get_function_type(const hashkit_hash_fn function hashkit_hash_algorithm_t hashkit_get_function(const hashkit_st *self) { + if (self == NULL) + { + return HASHKIT_HASH_DEFAULT; + } + return get_function_type(self->base_hash.function); } hashkit_hash_algorithm_t hashkit_get_distribution_function(const hashkit_st *self) { + if (self == NULL) + { + return HASHKIT_HASH_DEFAULT; + } + return get_function_type(self->distribution_hash.function); } diff --git a/libhashkit/has.cc b/libhashkit/has.cc new file mode 100644 index 00000000..111e7153 --- /dev/null +++ b/libhashkit/has.cc @@ -0,0 +1,79 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + +bool libhashkit_has_algorithm(const hashkit_hash_algorithm_t algo) +{ + switch (algo) + { + case HASHKIT_HASH_FNV1_64: + case HASHKIT_HASH_FNV1A_64: +#if __WORDSIZE == 64 && defined(HAVE_FNV64_HASH) + return true; +#else + return false; +#endif + + case HASHKIT_HASH_HSIEH: +#ifdef HAVE_HSIEH_HASH + return true; +#else + return false; +#endif + + case HASHKIT_HASH_MURMUR: +#ifdef HAVE_MURMUR_HASH + return true; +#else + return false; +#endif + + case HASHKIT_HASH_FNV1_32: + case HASHKIT_HASH_FNV1A_32: + case HASHKIT_HASH_DEFAULT: + case HASHKIT_HASH_MD5: + case HASHKIT_HASH_CRC: + case HASHKIT_HASH_JENKINS: + case HASHKIT_HASH_CUSTOM: + return true; + + case HASHKIT_HASH_MAX: + break; + } + + return false; +} diff --git a/libhashkit/has.h b/libhashkit/has.h new file mode 100644 index 00000000..8975c7a8 --- /dev/null +++ b/libhashkit/has.h @@ -0,0 +1,48 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +HASHKIT_API +bool libhashkit_has_algorithm(const hashkit_hash_algorithm_t); + +#ifdef __cplusplus +} +#endif diff --git a/libhashkit/hashkit.h b/libhashkit/hashkit.h index 9b8761f1..ad13ec51 100644 --- a/libhashkit/hashkit.h +++ b/libhashkit/hashkit.h @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include diff --git a/libhashkit/hsieh.cc b/libhashkit/hsieh.cc index 35a2e209..f7067909 100644 --- a/libhashkit/hsieh.cc +++ b/libhashkit/hsieh.cc @@ -17,7 +17,8 @@ +(uint32_t)(((const uint8_t *)(d))[0]) ) #endif -uint32_t hashkit_hsieh(const char *key, size_t key_length, void *context __attribute__((unused))) +#ifdef HAVE_HSIEH_HASH +uint32_t hashkit_hsieh(const char *key, size_t key_length, void *) { uint32_t hash = 0, tmp; int rem; @@ -67,4 +68,9 @@ uint32_t hashkit_hsieh(const char *key, size_t key_length, void *context __attri return hash; } - +#else +uint32_t hashkit_hsieh(const char *, size_t , void *) +{ + return 0; +} +#endif diff --git a/libhashkit/include.am b/libhashkit/include.am index 90d623a1..9a556e35 100644 --- a/libhashkit/include.am +++ b/libhashkit/include.am @@ -21,6 +21,7 @@ nobase_include_HEADERS+= \ libhashkit/configure.h \ libhashkit/digest.h \ libhashkit/function.h \ + libhashkit/has.h \ libhashkit/hashkit.h \ libhashkit/hashkit.hpp \ libhashkit/strerror.h \ @@ -39,21 +40,18 @@ libhashkit_libhashkit_la_SOURCES= \ libhashkit/fnv_32.cc \ libhashkit/fnv_64.cc \ libhashkit/function.cc \ + libhashkit/has.cc \ libhashkit/hashkit.cc \ + libhashkit/hsieh.cc \ libhashkit/jenkins.cc \ libhashkit/ketama.cc \ libhashkit/md5.cc \ + libhashkit/murmur.cc \ libhashkit/one_at_a_time.cc \ libhashkit/str_algorithm.cc \ libhashkit/strerror.cc -if INCLUDE_HSIEH_SRC -libhashkit_libhashkit_la_SOURCES+= libhashkit/hsieh.cc -endif -if INCLUDE_MURMUR_SRC -libhashkit_libhashkit_la_SOURCES+= libhashkit/murmur.cc -endif libhashkit_libhashkit_la_CPPFLAGS= -DBUILDING_HASHKIT diff --git a/libhashkit/murmur.cc b/libhashkit/murmur.cc index a40b11b7..d30e850d 100644 --- a/libhashkit/murmur.cc +++ b/libhashkit/murmur.cc @@ -17,6 +17,8 @@ #include +#ifdef HAVE_MURMUR_HASH + uint32_t hashkit_murmur(const char *key, size_t length, void *context) { /* @@ -75,3 +77,10 @@ uint32_t hashkit_murmur(const char *key, size_t length, void *context) return h; } + +#else +uint32_t hashkit_murmur(const char *, size_t , void *) +{ + return 0; +} +#endif diff --git a/libhashkit/types.h b/libhashkit/types.h index 66e4cd9c..e0f1f138 100644 --- a/libhashkit/types.h +++ b/libhashkit/types.h @@ -47,8 +47,15 @@ typedef enum { HASHKIT_MAXIMUM_RETURN /* Always add new error code before */ } hashkit_return_t; -#define hashkit_success(X) ((X) == HASHKIT_SUCCESS) -#define hashkit_failed(X) ((X) != HASHKIT_SUCCESS) +static inline bool hashkit_success(const hashkit_return_t rc) +{ + return (rc == HASHKIT_SUCCESS); +} + +static inline bool hashkit_failed(const hashkit_return_t rc) +{ + return (rc != HASHKIT_SUCCESS); +} typedef enum { HASHKIT_HASH_DEFAULT= 0, // hashkit_one_at_a_time() diff --git a/libmemcached/behavior.cc b/libmemcached/behavior.cc index 6036aebd..2b3b389c 100644 --- a/libmemcached/behavior.cc +++ b/libmemcached/behavior.cc @@ -493,7 +493,9 @@ memcached_server_distribution_t memcached_behavior_get_distribution(memcached_st memcached_return_t memcached_behavior_set_key_hash(memcached_st *ptr, memcached_hash_t type) { if (hashkit_success(hashkit_set_function(&ptr->hashkit, (hashkit_hash_algorithm_t)type))) + { return MEMCACHED_SUCCESS; + } return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid memcached_hash_t()")); diff --git a/m4/fnv.m4 b/m4/fnv.m4 new file mode 100644 index 00000000..00455857 --- /dev/null +++ b/m4/fnv.m4 @@ -0,0 +1,16 @@ +dnl --------------------------------------------------------------------------- +dnl Macro: ENABLE_FNV64_HASH +dnl --------------------------------------------------------------------------- +AC_DEFUN([ENABLE_FNV64_HASH], + [AC_ARG_ENABLE([fnv64_hash], + [AS_HELP_STRING([--disable-fnv64_hash], + [build with support for fnv64 hashing. @<:@default=on@:>@])], + [ac_cv_enable_fnv64_hash=no], + [ac_cv_enable_fnv64_hash=yes]) + + AS_IF([test "$ac_cv_enable_fnv64_hash" = "yes"], + [AC_DEFINE([HAVE_FNV64_HASH], [1], [Enables fnv64 hashing support])]) +]) +dnl --------------------------------------------------------------------------- +dnl End Macro: ENABLE_FNV64_HASH +dnl --------------------------------------------------------------------------- diff --git a/support/libmemcached.spec.in b/support/libmemcached.spec.in index 02f2c436..c031b7b3 100644 --- a/support/libmemcached.spec.in +++ b/support/libmemcached.spec.in @@ -114,6 +114,7 @@ you will need to install %{name}-devel. %{_includedir}/libhashkit/configure.h %{_includedir}/libhashkit/digest.h %{_includedir}/libhashkit/function.h +%{_includedir}/libhashkit/has.h %{_includedir}/libhashkit/hashkit.h %{_includedir}/libhashkit/hashkit.hpp %{_includedir}/libhashkit/str_algorithm.h diff --git a/tests/hash_plus.cc b/tests/hash_plus.cc index b355fe57..3d2545ab 100644 --- a/tests/hash_plus.cc +++ b/tests/hash_plus.cc @@ -16,19 +16,17 @@ using namespace libtest; #include "hash_results.h" -static test_return_t exists_test(void *obj) +static test_return_t exists_test(void *) { Hashkit hashk; - (void)obj; (void)hashk; return TEST_SUCCESS; } -static test_return_t new_test(void *obj) +static test_return_t new_test(void *) { Hashkit *hashk= new Hashkit; - (void)obj; (void)hashk; @@ -37,11 +35,10 @@ static test_return_t new_test(void *obj) return TEST_SUCCESS; } -static test_return_t copy_test(void *obj) +static test_return_t copy_test(void *) { Hashkit *hashk= new Hashkit; Hashkit *copy(hashk); - (void)obj; (void)copy; @@ -50,11 +47,10 @@ static test_return_t copy_test(void *obj) return TEST_SUCCESS; } -static test_return_t assign_test(void *obj) +static test_return_t assign_test(void *) { Hashkit hashk; Hashkit copy; - (void)obj; copy= hashk; @@ -92,6 +88,11 @@ static test_return_t set_function_test(void *) { hashkit_return_t rc= hashk.set_function(*algo); + if (rc == HASHKIT_INVALID_ARGUMENT) + { + continue; + } + test_compare(HASHKIT_SUCCESS, rc); uint32_t *list; @@ -126,18 +127,12 @@ static test_return_t set_function_test(void *) break; case HASHKIT_HASH_HSIEH: -#ifndef HAVE_HSIEH_HASH - continue; -#endif list= hsieh_values; break; case HASHKIT_HASH_MURMUR: #ifdef WORDS_BIGENDIAN continue; -#endif -#ifndef HAVE_MURMUR_HASH - continue; #endif list= murmur_values; break; @@ -170,25 +165,23 @@ static test_return_t set_function_test(void *) return TEST_SUCCESS; } -static test_return_t set_distribution_function_test(void *obj) +static test_return_t set_distribution_function_test(void *) { Hashkit hashk; hashkit_return_t rc; - (void)obj; rc= hashk.set_distribution_function(HASHKIT_HASH_CUSTOM); test_true_got(rc == HASHKIT_FAILURE or rc == HASHKIT_INVALID_ARGUMENT, hashkit_strerror(NULL, rc)); - rc= hashk.set_distribution_function(HASHKIT_HASH_JENKINS); - test_true(rc == HASHKIT_SUCCESS); + test_compare(HASHKIT_SUCCESS, + hashk.set_distribution_function(HASHKIT_HASH_JENKINS)); return TEST_SUCCESS; } -static test_return_t compare_function_test(void *obj) +static test_return_t compare_function_test(void *) { Hashkit a, b; - (void)obj; b= a; diff --git a/tests/hashkit_functions.cc b/tests/hashkit_functions.cc index 12cd3988..2d664e7c 100644 --- a/tests/hashkit_functions.cc +++ b/tests/hashkit_functions.cc @@ -61,30 +61,28 @@ struct hash_test_st bool _unused; }; -static test_return_t init_test(void *not_used) +static test_return_t init_test(void *) { hashkit_st hashk; hashkit_st *hashk_ptr; - (void)not_used; hashk_ptr= hashkit_create(&hashk); test_true(hashk_ptr); test_true(hashk_ptr == &hashk); - test_true(hashkit_is_allocated(hashk_ptr) == false); + test_false(hashkit_is_allocated(hashk_ptr)); hashkit_free(hashk_ptr); return TEST_SUCCESS; } -static test_return_t allocation_test(void *not_used) +static test_return_t allocation_test(void *) { hashkit_st *hashk_ptr; - (void)not_used; hashk_ptr= hashkit_create(NULL); test_true(hashk_ptr); - test_true(hashkit_is_allocated(hashk_ptr) == true); + test_true(hashkit_is_allocated(hashk_ptr)); hashkit_free(hashk_ptr); return TEST_SUCCESS; @@ -93,7 +91,7 @@ static test_return_t allocation_test(void *not_used) static test_return_t clone_test(hashkit_st *hashk) { // First we make sure that the testing system is giving us what we expect. - assert(&global_hashk == hashk); + test_true(&global_hashk == hashk); // Second we test if hashk is even valid @@ -147,149 +145,126 @@ static test_return_t clone_test(hashkit_st *hashk) return TEST_SUCCESS; } -static test_return_t one_at_a_time_run (hashkit_st *hashk) +static test_return_t one_at_a_time_run (hashkit_st *) { uint32_t x; const char **ptr; - (void)hashk; for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= libhashkit_one_at_a_time(*ptr, strlen(*ptr)); - test_true(one_at_a_time_values[x] == hash_val); + test_compare(one_at_a_time_values[x], + libhashkit_one_at_a_time(*ptr, strlen(*ptr))); } return TEST_SUCCESS; } -static test_return_t md5_run (hashkit_st *hashk) +static test_return_t md5_run (hashkit_st *) { uint32_t x; const char **ptr; - (void)hashk; for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= libhashkit_md5(*ptr, strlen(*ptr)); - test_true(md5_values[x] == hash_val); + test_compare(md5_values[x], + libhashkit_md5(*ptr, strlen(*ptr))); } return TEST_SUCCESS; } -static test_return_t crc_run (hashkit_st *hashk) +static test_return_t crc_run (hashkit_st *) { uint32_t x; const char **ptr; - (void)hashk; for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= libhashkit_crc32(*ptr, strlen(*ptr)); - test_compare(crc_values[x], hash_val); + test_compare(crc_values[x], + libhashkit_crc32(*ptr, strlen(*ptr))); } return TEST_SUCCESS; } -static test_return_t fnv1_64_run (hashkit_st *hashk) +static test_return_t fnv1_64_run (hashkit_st *) { + test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_FNV1_64)); + uint32_t x; const char **ptr; - (void)hashk; for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= libhashkit_fnv1_64(*ptr, strlen(*ptr)); - test_compare(fnv1_64_values[x], hash_val); + test_compare(fnv1_64_values[x], + libhashkit_fnv1_64(*ptr, strlen(*ptr))); } return TEST_SUCCESS; } -static test_return_t fnv1a_64_run (hashkit_st *hashk) +static test_return_t fnv1a_64_run (hashkit_st *) { + test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_FNV1A_64)); uint32_t x; const char **ptr; - (void)hashk; for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= libhashkit_fnv1a_64(*ptr, strlen(*ptr)); - test_compare(fnv1a_64_values[x], hash_val); + test_compare(fnv1a_64_values[x], + libhashkit_fnv1a_64(*ptr, strlen(*ptr))); } return TEST_SUCCESS; } -static test_return_t fnv1_32_run (hashkit_st *hashk) +static test_return_t fnv1_32_run (hashkit_st *) { uint32_t x; const char **ptr; - (void)hashk; for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= libhashkit_fnv1_32(*ptr, strlen(*ptr)); - test_compare(fnv1_32_values[x], hash_val); + test_compare(fnv1_32_values[x], + libhashkit_fnv1_32(*ptr, strlen(*ptr))); } return TEST_SUCCESS; } -static test_return_t fnv1a_32_run (hashkit_st *hashk) +static test_return_t fnv1a_32_run (hashkit_st *) { uint32_t x; const char **ptr; - (void)hashk; for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= libhashkit_fnv1a_32(*ptr, strlen(*ptr)); - test_compare(fnv1a_32_values[x], hash_val); + test_compare(fnv1a_32_values[x], + libhashkit_fnv1a_32(*ptr, strlen(*ptr))); } return TEST_SUCCESS; } -static test_return_t hsieh_run (hashkit_st *hashk) +static test_return_t hsieh_run (hashkit_st *) { + test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_HSIEH)); + uint32_t x; const char **ptr; - (void)hashk; for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - -#ifdef HAVE_HSIEH_HASH - hash_val= libhashkit_hsieh(*ptr, strlen(*ptr)); -#else - hash_val= 1; -#endif - test_compare(hsieh_values[x], hash_val); + test_compare(hsieh_values[x], + libhashkit_hsieh(*ptr, strlen(*ptr))); } return TEST_SUCCESS; } -static test_return_t murmur_run (hashkit_st *hashk) +static test_return_t murmur_run (hashkit_st *) { - (void)hashk; + test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_MURMUR)); #ifdef WORDS_BIGENDIAN (void)murmur_values; @@ -300,32 +275,23 @@ static test_return_t murmur_run (hashkit_st *hashk) for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - -#ifdef HAVE_MURMUR_HASH - hash_val= libhashkit_murmur(*ptr, strlen(*ptr)); -#else - hash_val= 1; -#endif - test_compare(murmur_values[x], hash_val); + test_compare(murmur_values[x], + libhashkit_murmur(*ptr, strlen(*ptr))); } return TEST_SUCCESS; #endif } -static test_return_t jenkins_run (hashkit_st *hashk) +static test_return_t jenkins_run (hashkit_st *) { uint32_t x; const char **ptr; - (void)hashk; for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= libhashkit_jenkins(*ptr, strlen(*ptr)); - test_compare(jenkins_values[x], hash_val); + test_compare(jenkins_values[x], + libhashkit_jenkins(*ptr, strlen(*ptr))); } return TEST_SUCCESS; @@ -360,56 +326,54 @@ static test_return_t hashkit_set_function_test(hashkit_st *hashk) const char **ptr; uint32_t *list; - hashkit_return_t rc= hashkit_set_function(hashk, static_cast(algo)); + test_skip(true, libhashkit_has_algorithm(static_cast(algo))); - /* Hsieh is disabled most of the time for patent issues */ -#ifndef HAVE_HSIEH_HASH - if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_HSIEH) - continue; -#endif - -#ifndef HAVE_MURMUR_HASH - if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_MURMUR) - continue; -#endif - - if (rc == HASHKIT_INVALID_ARGUMENT && algo == HASHKIT_HASH_CUSTOM) - continue; + hashkit_return_t rc= hashkit_set_function(hashk, static_cast(algo)); - test_true_got(rc == HASHKIT_SUCCESS, hashkit_strerror(NULL, rc)); + test_compare_got(HASHKIT_SUCCESS, rc, hashkit_strerror(NULL, rc)); switch (algo) { case HASHKIT_HASH_DEFAULT: list= one_at_a_time_values; break; + case HASHKIT_HASH_MD5: list= md5_values; break; + case HASHKIT_HASH_CRC: list= crc_values; break; + case HASHKIT_HASH_FNV1_64: list= fnv1_64_values; break; + case HASHKIT_HASH_FNV1A_64: list= fnv1a_64_values; break; + case HASHKIT_HASH_FNV1_32: list= fnv1_32_values; break; + case HASHKIT_HASH_FNV1A_32: list= fnv1a_32_values; break; + case HASHKIT_HASH_HSIEH: list= hsieh_values; break; + case HASHKIT_HASH_MURMUR: list= murmur_values; break; + case HASHKIT_HASH_JENKINS: list= jenkins_values; break; + case HASHKIT_HASH_CUSTOM: case HASHKIT_HASH_MAX: default: @@ -422,10 +386,8 @@ static test_return_t hashkit_set_function_test(hashkit_st *hashk) { for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= hashkit_digest(hashk, *ptr, strlen(*ptr)); - test_true(list[x] == hash_val); + test_compare(list[x], + hashkit_digest(hashk, *ptr, strlen(*ptr))); } } else @@ -437,28 +399,24 @@ static test_return_t hashkit_set_function_test(hashkit_st *hashk) return TEST_SUCCESS; } -static uint32_t hash_test_function(const char *string, size_t string_length, void *context) +static uint32_t hash_test_function(const char *string, size_t string_length, void *) { - (void)context; return libhashkit_md5(string, string_length); } static test_return_t hashkit_set_custom_function_test(hashkit_st *hashk) { - hashkit_return_t rc; uint32_t x; const char **ptr; - rc= hashkit_set_custom_function(hashk, hash_test_function, NULL); - test_true(rc == HASHKIT_SUCCESS); + test_compare(HASHKIT_SUCCESS, + hashkit_set_custom_function(hashk, hash_test_function, NULL)); for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= hashkit_digest(hashk, *ptr, strlen(*ptr)); - test_true(md5_values[x] == hash_val); + test_compare(md5_values[x], + hashkit_digest(hashk, *ptr, strlen(*ptr))); } return TEST_SUCCESS; @@ -471,13 +429,10 @@ static test_return_t hashkit_set_distribution_function_test(hashkit_st *hashk) hashkit_return_t rc= hashkit_set_distribution_function(hashk, static_cast(algo)); /* Hsieh is disabled most of the time for patent issues */ - if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_HSIEH) - continue; - - if (rc == HASHKIT_INVALID_ARGUMENT && algo == HASHKIT_HASH_CUSTOM) + if (rc == HASHKIT_INVALID_ARGUMENT) continue; - test_true(rc == HASHKIT_SUCCESS); + test_compare(HASHKIT_SUCCESS, rc); } return TEST_SUCCESS; @@ -485,8 +440,8 @@ static test_return_t hashkit_set_distribution_function_test(hashkit_st *hashk) static test_return_t hashkit_set_custom_distribution_function_test(hashkit_st *hashk) { - hashkit_return_t rc= hashkit_set_custom_distribution_function(hashk, hash_test_function, NULL); - test_true(rc == HASHKIT_SUCCESS); + test_compare(HASHKIT_SUCCESS, + hashkit_set_custom_distribution_function(hashk, hash_test_function, NULL)); return TEST_SUCCESS; } @@ -497,13 +452,16 @@ static test_return_t hashkit_get_function_test(hashkit_st *hashk) for (int algo= int(HASHKIT_HASH_DEFAULT); algo < int(HASHKIT_HASH_MAX); algo++) { - if (HASHKIT_HASH_CUSTOM or HASHKIT_HASH_HSIEH) + if (HASHKIT_HASH_CUSTOM) + { continue; + } + test_skip(true, libhashkit_has_algorithm(static_cast(algo))); - hashkit_return_t rc= hashkit_set_function(hashk, static_cast(algo)); - test_true(rc == HASHKIT_SUCCESS); + test_compare(HASHKIT_SUCCESS, + hashkit_set_function(hashk, static_cast(algo))); - test_true(hashkit_get_function(hashk) == algo); + test_compare(hashkit_get_function(hashk), algo); } return TEST_SUCCESS; } @@ -529,13 +487,9 @@ test_st hashkit_st_functions[] ={ {0, 0, 0} }; -static test_return_t libhashkit_digest_test(hashkit_st *hashk) +static test_return_t libhashkit_digest_test(hashkit_st *) { - - (void)hashk; - - uint32_t value= libhashkit_digest("a", sizeof("a"), HASHKIT_HASH_DEFAULT); - test_true(value); + test_true(libhashkit_digest("a", sizeof("a"), HASHKIT_HASH_DEFAULT)); return TEST_SUCCESS; } diff --git a/tests/mem_functions.cc b/tests/mem_functions.cc index c0dde998..bc54b671 100644 --- a/tests/mem_functions.cc +++ b/tests/mem_functions.cc @@ -3525,13 +3525,8 @@ static test_return_t pre_nonblock_binary(memcached_st *memc) static test_return_t pre_murmur(memcached_st *memc) { -#ifdef HAVE_MURMUR_HASH - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_MURMUR); + test_skip(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_MURMUR)); return TEST_SUCCESS; -#else - (void) memc; - return TEST_SKIPPED; -#endif } static test_return_t pre_jenkins(memcached_st *memc) @@ -3558,25 +3553,20 @@ static test_return_t pre_crc(memcached_st *memc) static test_return_t pre_hsieh(memcached_st *memc) { -#ifdef HAVE_HSIEH_HASH - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_HSIEH); + test_skip(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_HSIEH)); return TEST_SUCCESS; -#else - (void) memc; - return TEST_SKIPPED; -#endif } static test_return_t pre_hash_fnv1_64(memcached_st *memc) { - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_MURMUR); + test_skip(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_MURMUR)); return TEST_SUCCESS; } static test_return_t pre_hash_fnv1a_64(memcached_st *memc) { - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_FNV1A_64); + test_skip(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_FNV1A_64)); return TEST_SUCCESS; } @@ -4436,26 +4426,30 @@ static test_return_t hash_sanity_test (memcached_st *memc) static test_return_t hsieh_avaibility_test (memcached_st *memc) { + test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_HSIEH)); + memcached_return_t expected_rc= MEMCACHED_INVALID_ARGUMENTS; #ifdef HAVE_HSIEH_HASH expected_rc= MEMCACHED_SUCCESS; #endif memcached_return_t rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_HSIEH); - test_true(rc == expected_rc); + test_compare(expected_rc, rc); return TEST_SUCCESS; } static test_return_t murmur_avaibility_test (memcached_st *memc) { + test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_MURMUR)); + memcached_return_t expected_rc= MEMCACHED_INVALID_ARGUMENTS; #ifdef HAVE_MURMUR_HASH expected_rc= MEMCACHED_SUCCESS; #endif memcached_return_t rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_MURMUR); - test_true(rc == expected_rc); + test_compare(expected_rc, rc); return TEST_SUCCESS; } @@ -4467,10 +4461,8 @@ static test_return_t one_at_a_time_run (memcached_st *) for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_DEFAULT); - test_true(one_at_a_time_values[x] == hash_val); + test_compare(one_at_a_time_values[x], + memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_DEFAULT)); } return TEST_SUCCESS; @@ -4483,10 +4475,8 @@ static test_return_t md5_run (memcached_st *) for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_MD5); - test_true(md5_values[x] == hash_val); + test_compare(md5_values[x], + memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_MD5)); } return TEST_SUCCESS; @@ -4499,10 +4489,8 @@ static test_return_t crc_run (memcached_st *) for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_CRC); - test_true(crc_values[x] == hash_val); + test_compare(crc_values[x], + memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_CRC)); } return TEST_SUCCESS; @@ -4510,15 +4498,15 @@ static test_return_t crc_run (memcached_st *) static test_return_t fnv1_64_run (memcached_st *) { + test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_FNV1_64)); + uint32_t x; const char **ptr; for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1_64); - test_true(fnv1_64_values[x] == hash_val); + test_compare(fnv1_64_values[x], + memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1_64)); } return TEST_SUCCESS; @@ -4526,15 +4514,15 @@ static test_return_t fnv1_64_run (memcached_st *) static test_return_t fnv1a_64_run (memcached_st *) { + test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_FNV1A_64)); + uint32_t x; const char **ptr; for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1A_64); - test_true(fnv1a_64_values[x] == hash_val); + test_compare(fnv1a_64_values[x], + memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1A_64)); } return TEST_SUCCESS; @@ -4547,10 +4535,8 @@ static test_return_t fnv1_32_run (memcached_st *) for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1_32); - test_true(fnv1_32_values[x] == hash_val); + test_compare(fnv1_32_values[x], + memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1_32)); } return TEST_SUCCESS; @@ -4563,10 +4549,8 @@ static test_return_t fnv1a_32_run (memcached_st *) for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1A_32); - test_true(fnv1a_32_values[x] == hash_val); + test_compare(fnv1a_32_values[x], + memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1A_32)); } return TEST_SUCCESS; @@ -4574,15 +4558,15 @@ static test_return_t fnv1a_32_run (memcached_st *) static test_return_t hsieh_run (memcached_st *) { + test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_HSIEH)); + uint32_t x; const char **ptr; for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_HSIEH); - test_true(hsieh_values[x] == hash_val); + test_compare(hsieh_values[x], + memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_HSIEH)); } return TEST_SUCCESS; @@ -4590,6 +4574,8 @@ static test_return_t hsieh_run (memcached_st *) static test_return_t murmur_run (memcached_st *) { + test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_MURMUR)); + #ifdef WORDS_BIGENDIAN (void)murmur_values; return TEST_SKIPPED; @@ -4599,10 +4585,8 @@ static test_return_t murmur_run (memcached_st *) for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_MURMUR); - test_true(murmur_values[x] == hash_val); + test_compare(murmur_values[x], + memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_MURMUR)); } return TEST_SUCCESS; @@ -4616,24 +4600,20 @@ static test_return_t jenkins_run (memcached_st *) for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) { - uint32_t hash_val; - - hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_JENKINS); - test_true(jenkins_values[x] == hash_val); + test_compare(jenkins_values[x], + memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_JENKINS)); } return TEST_SUCCESS; } -static uint32_t hash_md5_test_function(const char *string, size_t string_length, void *context) +static uint32_t hash_md5_test_function(const char *string, size_t string_length, void *) { - (void)context; return libhashkit_md5(string, string_length); } -static uint32_t hash_crc_test_function(const char *string, size_t string_length, void *context) +static uint32_t hash_crc_test_function(const char *string, size_t string_length, void *) { - (void)context; return libhashkit_crc32(string, string_length); } diff --git a/tests/parser.cc b/tests/parser.cc index dd8062c2..898fdb54 100644 --- a/tests/parser.cc +++ b/tests/parser.cc @@ -221,12 +221,9 @@ scanner_variable_t distribution_strings[]= { scanner_variable_t hash_strings[]= { { ARRAY, make_scanner_string("--HASH=CRC"), scanner_string_null, NULL }, { ARRAY, make_scanner_string("--HASH=FNV1A_32"), scanner_string_null, NULL }, - { ARRAY, make_scanner_string("--HASH=FNV1A_64"), scanner_string_null, NULL }, { ARRAY, make_scanner_string("--HASH=FNV1_32"), scanner_string_null, NULL }, - { ARRAY, make_scanner_string("--HASH=FNV1_64"), scanner_string_null, NULL }, { ARRAY, make_scanner_string("--HASH=JENKINS"), scanner_string_null, NULL }, { ARRAY, make_scanner_string("--HASH=MD5"), scanner_string_null, NULL }, - { ARRAY, make_scanner_string("--HASH=MURMUR"), scanner_string_null, NULL }, { NIL, scanner_string_null, scanner_string_null, NULL} };