X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Ffunction.c;h=cdea2d1edeb70178b987eebc189ca4fcbd9966a6;hb=dcd5061e6bc6e591ad9986e9360a4657f8dbf7f1;hp=b9e7d303efdbfa121fe44e357dc9b0f1b837a1e2;hpb=17e0b84e30fe82f6a2a995484a502179c73906ea;p=awesomized%2Flibmemcached diff --git a/tests/function.c b/tests/function.c index b9e7d303..cdea2d1e 100644 --- a/tests/function.c +++ b/tests/function.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include "server.h" @@ -287,10 +288,18 @@ static test_return connection_test(memcached_st *memc) static test_return error_test(memcached_st *memc) { memcached_return rc; + uint32_t values[] = { 851992627U, 2337886783U, 3196981036U, 4001849190U, 982370485U, 1263635348U, 4242906218U, 3829656100U, 1891735253U, + 334139633U, 2257084983U, 3088286104U, 13199785U, 2542027183U, 1097051614U, 199566778U, 2748246961U, 2465192557U, + 1664094137U, 2405439045U, 1842224848U, 692413798U, 3479807801U, 919913813U, 4269430871U, 610793021U, 527273862U, + 1437122909U, 2300930706U, 2943759320U, 674306647U, 2400528935U, 54481931U, 4186304426U, 1741088401U, 2979625118U, + 4159057246U }; + assert(MEMCACHED_MAXIMUM_RETURN == 37); // You have updated the memcache_error messages but not updated docs/tests. for (rc= MEMCACHED_SUCCESS; rc < MEMCACHED_MAXIMUM_RETURN; rc++) { - printf("Error %d -> %s\n", rc, memcached_strerror(memc, rc)); + uint32_t hash_val; + hash_val= memcached_generate_hash_value(memcached_strerror(memc, rc), strlen(memcached_strerror(memc, rc)), MEMCACHED_HASH_JENKINS); + assert(values[rc] == hash_val); } return 0; @@ -1685,9 +1694,8 @@ static test_return user_supplied_bug3(memcached_st *memc) getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE); #endif - keys= (char **)malloc(sizeof(char *) * KEY_COUNT); + keys= calloc(KEY_COUNT, sizeof(char *)); assert(keys); - memset(keys, 0, (sizeof(char *) * KEY_COUNT)); for (x= 0; x < KEY_COUNT; x++) { char buffer[30]; @@ -2304,6 +2312,7 @@ static test_return user_supplied_bug16(memcached_st *memc) return 0; } +#ifndef __sun /* Check the validity of chinese key*/ static test_return user_supplied_bug17(memcached_st *memc) { @@ -2330,6 +2339,7 @@ static test_return user_supplied_bug17(memcached_st *memc) return 0; } +#endif /* From Andrei on IRC @@ -2447,6 +2457,99 @@ static test_return user_supplied_bug18(memcached_st *trash) return 0; } +/* Large mget() of missing keys with binary proto + * See http://lists.tangent.org/pipermail/libmemcached/2009-August/000918.html + */ + +void fail(int); + +static test_return _user_supplied_bug21(memcached_st* memc, size_t key_count) +{ + memcached_return rc; + unsigned int x; + char **keys; + size_t* key_lengths; + void (*oldalarm)(int); + memcached_st *memc_clone; + + memc_clone= memcached_clone(NULL, memc); + assert(memc); + + /* only binproto uses getq for mget */ + memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1); + + /* empty the cache to ensure misses (hence non-responses) */ + rc= memcached_flush(memc_clone, 0); + assert(rc == MEMCACHED_SUCCESS); + + key_lengths= calloc(key_count, sizeof(size_t)); + keys= calloc(key_count, sizeof(char *)); + assert(keys); + for (x= 0; x < key_count; x++) + { + char buffer[30]; + + snprintf(buffer, 30, "%u", x); + keys[x]= strdup(buffer); + key_lengths[x]= strlen(keys[x]); + } + + oldalarm= signal(SIGALRM, fail); + alarm(5); + + rc= memcached_mget(memc_clone, (const char **)keys, key_lengths, key_count); + assert(rc == MEMCACHED_SUCCESS); + + alarm(0); + signal(SIGALRM, oldalarm); + + /* Turn this into a help function */ + { + char return_key[MEMCACHED_MAX_KEY]; + size_t return_key_length; + char *return_value; + size_t return_value_length; + uint32_t flags; + + while ((return_value= memcached_fetch(memc, return_key, &return_key_length, + &return_value_length, &flags, &rc))) + { + assert(return_value); + assert(rc == MEMCACHED_SUCCESS); + free(return_value); + } + } + + for (x= 0; x < key_count; x++) + free(keys[x]); + free(keys); + free(key_lengths); + + memcached_free(memc); + + return TEST_SUCCESS; +} + +static test_return user_supplied_bug21(memcached_st *memc) +{ + memcached_return rc; + + /* should work as of r580 */ + rc= _user_supplied_bug21(memc, 10); + assert(rc == TEST_SUCCESS); + + /* should fail as of r580 */ + rc= _user_supplied_bug21(memc, 1000); + assert(rc == TEST_SUCCESS); + + return TEST_SUCCESS; +} + +void fail(int unused __attribute__((unused))) +{ + assert(0); +} + static test_return auto_eject_hosts(memcached_st *trash) { (void) trash; @@ -3334,7 +3437,7 @@ static memcached_return poll_timeout(memcached_st *memc) memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, timeout); - timeout= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT); + timeout= (size_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT); assert(timeout == 100); @@ -3729,6 +3832,8 @@ static test_return replication_mget_test(memcached_st *memc) memcached_free(new_clone); } + memcached_free(memc_clone); + return TEST_SUCCESS; } @@ -4514,6 +4619,7 @@ test_st user_tests[] ={ {"user_supplied_bug18", 1, user_supplied_bug18 }, {"user_supplied_bug19", 1, user_supplied_bug19 }, {"user_supplied_bug20", 1, user_supplied_bug20 }, + {"user_supplied_bug21", 0, user_supplied_bug21 }, {0, 0, 0} }; @@ -4646,8 +4752,7 @@ void *world_create(void) { server_startup_st *construct; - construct= (server_startup_st *)malloc(sizeof(server_startup_st)); - memset(construct, 0, sizeof(server_startup_st)); + construct= calloc(sizeof(server_startup_st), 1); construct->count= SERVERS_TO_CREATE; construct->udp= 0; server_startup(construct);