X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Fmem_functions.c;h=4c1b56b5327816e1da01b1e64c9968c0ed5fd2f1;hb=ec35c1ba09b8eb49505d32d23a2b679be3c45add;hp=fa1ecbd8f18f516cc3c0f796539025ae50657fc1;hpb=d753fca27268b2d3ab6bce64411c65287acbe25d;p=m6w6%2Flibmemcached diff --git a/tests/mem_functions.c b/tests/mem_functions.c index fa1ecbd8..4c1b56b5 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); @@ -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); @@ -3615,8 +3623,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 +3635,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 +3657,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 +3677,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 +3817,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 +4110,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 +4905,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; } @@ -5965,6 +5994,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 },