X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Fmem_functions.c;h=cf48940bbeca39573c0d9428fe70bd1f7a6c980c;hb=d590ead1014a271bd96bebd5790f1bf8818e5cab;hp=fa1ecbd8f18f516cc3c0f796539025ae50657fc1;hpb=d753fca27268b2d3ab6bce64411c65287acbe25d;p=awesomized%2Flibmemcached diff --git a/tests/mem_functions.c b/tests/mem_functions.c index fa1ecbd8..cf48940b 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -82,7 +82,8 @@ static test_return_t server_list_null_test(memcached_st *ptr __attribute__((unus #define TEST_PORT_COUNT 7 in_port_t test_ports[TEST_PORT_COUNT]; -static memcached_return_t server_display_function(memcached_st *ptr __attribute__((unused)), memcached_server_st *server, void *context) +static memcached_return_t server_display_function(const memcached_st *ptr __attribute__((unused)), + memcached_server_st *server, void *context) { /* Do Nothing */ size_t bigger= *((size_t *)(context)); @@ -158,7 +159,7 @@ static test_return_t server_sort2_test(memcached_st *ptr __attribute__((unused)) return TEST_SUCCESS; } -static memcached_return_t server_display_unsort_function(memcached_st *ptr __attribute__((unused)), memcached_server_st *server, void *context) +static memcached_return_t server_display_unsort_function(const memcached_st *ptr __attribute__((unused)), memcached_server_st *server, void *context) { /* Do Nothing */ uint32_t x= *((uint32_t *)(context)); @@ -229,10 +230,13 @@ static test_return_t clone_test(memcached_st *memc) memc_clone= memcached_clone(NULL, memc); test_true(memc_clone); - test_true(memc_clone->call_free == memc->call_free); - test_true(memc_clone->call_malloc == memc->call_malloc); - test_true(memc_clone->call_realloc == memc->call_realloc); - test_true(memc_clone->call_calloc == memc->call_calloc); + { // Test allocators + test_true(memc_clone->allocators.free == memc->allocators.free); + test_true(memc_clone->allocators.malloc == memc->allocators.malloc); + test_true(memc_clone->allocators.realloc == memc->allocators.realloc); + test_true(memc_clone->allocators.calloc == memc->allocators.calloc); + } + test_true(memc_clone->connect_timeout == memc->connect_timeout); test_true(memc_clone->delete_trigger == memc->delete_trigger); test_true(memc_clone->distribution == memc->distribution); @@ -254,8 +258,8 @@ static test_return_t clone_test(memcached_st *memc) test_true(memc_clone->flags.randomize_replica_read == memc->flags.randomize_replica_read); } test_true(memc_clone->get_key_failure == memc->get_key_failure); - test_true(memc_clone->hash == memc->hash); - test_true(memc_clone->distribution_hash == memc->distribution_hash); + test_true(hashkit_compare(&memc_clone->hashkit, &memc->hashkit)); + test_true(hashkit_compare(&memc_clone->distribution_hashkit, &memc->distribution_hashkit)); test_true(memc_clone->io_bytes_watermark == memc->io_bytes_watermark); test_true(memc_clone->io_msg_watermark == memc->io_msg_watermark); test_true(memc_clone->io_key_prefetch == memc->io_key_prefetch); @@ -328,16 +332,21 @@ static test_return_t error_test(memcached_st *memc) 4269430871U, 610793021U, 527273862U, 1437122909U, 2300930706U, 2943759320U, 674306647U, 2400528935U, 54481931U, 4186304426U, 1741088401U, 2979625118U, - 4159057246U, 3425930182U, 2593724503U}; + 4159057246U, 3425930182U, 2593724503U, 1868899624U}; // You have updated the memcache_error messages but not updated docs/tests. - test_true(MEMCACHED_MAXIMUM_RETURN == 39); + test_true(MEMCACHED_MAXIMUM_RETURN == 40); for (rc= MEMCACHED_SUCCESS; rc < MEMCACHED_MAXIMUM_RETURN; rc++) { uint32_t hash_val; const char *msg= memcached_strerror(memc, rc); hash_val= memcached_generate_hash_value(msg, strlen(msg), MEMCACHED_HASH_JENKINS); + if (values[rc] != hash_val) + { + fprintf(stderr, "\n\nYou have updated memcached_return_t without updating the error_test\n"); + fprintf(stderr, "%u, %s, (%u)\n\n", (uint32_t)rc, memcached_strerror(memc, rc), hash_val); + } test_true(values[rc] == hash_val); } @@ -469,7 +478,7 @@ static test_return_t cas2_test(memcached_st *memc) results= memcached_fetch_result(memc, &results_obj, &rc); test_true(results); - test_true(results->cas); + test_true(results->item_cas); test_true(rc == MEMCACHED_SUCCESS); test_true(memcached_result_cas(results)); @@ -685,7 +694,7 @@ static test_return_t flush_test(memcached_st *memc) return TEST_SUCCESS; } -static memcached_return_t server_function(memcached_st *ptr __attribute__((unused)), +static memcached_return_t server_function(const memcached_st *ptr __attribute__((unused)), memcached_server_st *server __attribute__((unused)), void *context __attribute__((unused))) { @@ -1497,7 +1506,7 @@ static test_return_t mget_result_alloc_test(memcached_st *memc) } /* Count the results */ -static memcached_return_t callback_counter(memcached_st *ptr __attribute__((unused)), +static memcached_return_t callback_counter(const memcached_st *ptr __attribute__((unused)), memcached_result_st *result __attribute__((unused)), void *context) { @@ -1692,7 +1701,6 @@ static test_return_t version_string_test(memcached_st *memc __attribute__((unuse static test_return_t get_stats(memcached_st *memc) { - unsigned int x; char **stat_list; char **ptr; memcached_return_t rc; @@ -1704,7 +1712,7 @@ static test_return_t get_stats(memcached_st *memc) test_true(rc == MEMCACHED_SUCCESS); test_true(memc_stat); - for (x= 0; x < memcached_server_count(memc); x++) + for (uint32_t x= 0; x < memcached_server_count(memc); x++) { stat_list= memcached_stat_get_keys(memc, memc_stat+x, &rc); test_true(rc == MEMCACHED_SUCCESS); @@ -3396,8 +3404,13 @@ static test_return_t pre_cork(memcached_st *memc) { memcached_return_t rc; bool set= true; + rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_CORK, set); +#ifdef __APPLE__ + return TEST_SKIPPED; +#endif + if (rc == MEMCACHED_SUCCESS) return TEST_SUCCESS; @@ -3410,6 +3423,10 @@ static test_return_t pre_cork_and_nonblock(memcached_st *memc) rc= pre_cork(memc); +#ifdef __APPLE__ + return TEST_SKIPPED; +#endif + if (rc != TEST_SUCCESS) return rc; @@ -3615,8 +3632,9 @@ static test_return_t pre_replication_noblock(memcached_st *memc) } -static void my_free(memcached_st *ptr __attribute__((unused)), void *mem) +static void my_free(const memcached_st *ptr __attribute__((unused)), void *mem, void *context) { + (void) context; #ifdef HARD_MALLOC_TESTS void *real_ptr= (mem == NULL) ? mem : (void*)((caddr_t)mem - 8); free(real_ptr); @@ -3626,8 +3644,9 @@ static void my_free(memcached_st *ptr __attribute__((unused)), void *mem) } -static void *my_malloc(memcached_st *ptr __attribute__((unused)), const size_t size) +static void *my_malloc(const memcached_st *ptr __attribute__((unused)), const size_t size, void *context) { + (void)context; #ifdef HARD_MALLOC_TESTS void *ret= malloc(size + 8); if (ret != NULL) @@ -3647,8 +3666,9 @@ static void *my_malloc(memcached_st *ptr __attribute__((unused)), const size_t s } -static void *my_realloc(memcached_st *ptr __attribute__((unused)), void *mem, const size_t size) +static void *my_realloc(const memcached_st *ptr __attribute__((unused)), void *mem, const size_t size, void *context) { + (void)context; #ifdef HARD_MALLOC_TESTS void *real_ptr= (mem == NULL) ? NULL : (void*)((caddr_t)mem - 8); void *nmem= realloc(real_ptr, size + 8); @@ -3666,8 +3686,9 @@ static void *my_realloc(memcached_st *ptr __attribute__((unused)), void *mem, co } -static void *my_calloc(memcached_st *ptr __attribute__((unused)), size_t nelem, const size_t size) +static void *my_calloc(const memcached_st *ptr __attribute__((unused)), size_t nelem, const size_t size, void *context) { + (void)context; #ifdef HARD_MALLOC_TESTS void *mem= my_malloc(ptr, nelem * size); if (mem) @@ -3805,11 +3826,11 @@ static test_return_t set_memory_alloc(memcached_st *memc) { memcached_return_t rc; rc= memcached_set_memory_allocators(memc, NULL, my_free, - my_realloc, my_calloc); + my_realloc, my_calloc, NULL); test_true(rc == MEMCACHED_FAILURE); rc= memcached_set_memory_allocators(memc, my_malloc, my_free, - my_realloc, my_calloc); + my_realloc, my_calloc, NULL); memcached_malloc_fn mem_malloc; memcached_free_fn mem_free; @@ -4098,10 +4119,10 @@ static test_return_t analyzer_test(memcached_st *memc) } /* Count the objects */ -static memcached_return_t callback_dump_counter(memcached_st *ptr __attribute__((unused)), - const char *key __attribute__((unused)), - size_t key_length __attribute__((unused)), - void *context) +static memcached_return_t callback_dump_counter(const memcached_st *ptr __attribute__((unused)), + const char *key __attribute__((unused)), + size_t key_length __attribute__((unused)), + void *context) { size_t *counter= (size_t *)context; @@ -4893,8 +4914,25 @@ static test_return_t hsieh_avaibility_test (memcached_st *memc) expected_rc= MEMCACHED_SUCCESS; #endif memcached_return_t rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, - (uint64_t)MEMCACHED_HASH_HSIEH); + (uint64_t)MEMCACHED_HASH_HSIEH); test_true(rc == expected_rc); + + return TEST_SUCCESS; +} + +static test_return_t one_at_a_time_run (memcached_st *memc __attribute__((unused))) +{ + 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_DEFAULT); + test_true(one_at_a_time_values[x] == hash_val); + } + return TEST_SUCCESS; } @@ -5048,6 +5086,81 @@ static test_return_t jenkins_run (memcached_st *memc __attribute__((unused))) return TEST_SUCCESS; } +static uint32_t hash_md5_test_function(const char *string, size_t string_length, void *context) +{ + (void)context; + return libhashkit_md5(string, string_length); +} + +static uint32_t hash_crc_test_function(const char *string, size_t string_length, void *context) +{ + (void)context; + return libhashkit_crc32(string, string_length); +} + +static test_return_t memcached_get_hashkit_test (memcached_st *memc) +{ + uint32_t x; + const char **ptr; + hashkit_st *kit; + hashkit_return_t hash_rc; + + uint32_t md5_hosts[]= {4U, 1U, 0U, 1U, 4U, 2U, 0U, 3U, 0U, 0U, 3U, 1U, 0U, 0U, 1U, 3U, 0U, 0U, 0U, 3U, 1U, 0U, 4U, 4U, 3U}; + uint32_t crc_hosts[]= {2U, 4U, 1U, 0U, 2U, 4U, 4U, 4U, 1U, 2U, 3U, 4U, 3U, 4U, 1U, 3U, 3U, 2U, 0U, 0U, 0U, 1U, 2U, 4U, 0U}; + + kit= memcached_get_hashkit(memc); + + hash_rc= hashkit_set_custom_function(kit, hash_md5_test_function, NULL); + test_true(hash_rc == HASHKIT_SUCCESS); + + /* + Verify Setting the hash. + */ + for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) + { + uint32_t hash_val; + + hash_val= hashkit_digest(kit, *ptr, strlen(*ptr)); + test_true(md5_values[x] == hash_val); + } + + + /* + Now check memcached_st. + */ + for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) + { + uint32_t hash_val; + + hash_val= memcached_generate_hash(memc, *ptr, strlen(*ptr)); + test_true(md5_hosts[x] == hash_val); + } + + hash_rc= hashkit_set_custom_function(kit, hash_crc_test_function, NULL); + test_true(hash_rc == HASHKIT_SUCCESS); + + /* + Verify Setting the hash. + */ + for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) + { + uint32_t hash_val; + + hash_val= hashkit_digest(kit, *ptr, strlen(*ptr)); + test_true(crc_values[x] == hash_val); + } + + for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) + { + uint32_t hash_val; + + hash_val= memcached_generate_hash(memc, *ptr, strlen(*ptr)); + test_true(crc_hosts[x] == hash_val); + } + + return TEST_SUCCESS; +} + static test_return_t ketama_compatibility_libmemcached(memcached_st *trash) { @@ -5965,6 +6078,7 @@ test_st ketama_auto_eject_hosts[] ={ }; test_st hash_tests[] ={ + {"one_at_a_time_run", 0, (test_callback_fn)one_at_a_time_run }, {"md5", 0, (test_callback_fn)md5_run }, {"crc", 0, (test_callback_fn)crc_run }, {"fnv1_64", 0, (test_callback_fn)fnv1_64_run }, @@ -5974,6 +6088,7 @@ test_st hash_tests[] ={ {"hsieh", 0, (test_callback_fn)hsieh_run }, {"murmur", 0, (test_callback_fn)murmur_run }, {"jenkis", 0, (test_callback_fn)jenkins_run }, + {"memcached_get_hashkit", 0, (test_callback_fn)memcached_get_hashkit_test }, {0, 0, (test_callback_fn)0} };