X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Fatomsmasher.c;h=3e759767c9b74c16e6c5bd5352feebec82e69869;hb=69e37123baed3e7d5970be3c576fb61f91713736;hp=6ff68ca96a4851b8f40f1126190570243e9dd5d1;hpb=8af90ac15d8ba8ec464e5ad402ed2d27b95f81e3;p=m6w6%2Flibmemcached diff --git a/tests/atomsmasher.c b/tests/atomsmasher.c index 6ff68ca9..3e759767 100644 --- a/tests/atomsmasher.c +++ b/tests/atomsmasher.c @@ -1,8 +1,20 @@ +/* LibMemcached + * Copyright (C) 2006-2009 Brian Aker + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + * + * Summary: + * + */ + /* Sample test application. */ +#include "libmemcached/common.h" + #include -#include #include #include #include @@ -12,7 +24,6 @@ #include #include #include "server.h" -#include "../libmemcached/common.h" #include "../clients/generator.h" #include "../clients/execute.h" @@ -37,14 +48,14 @@ static pairs_st *global_pairs; static char *global_keys[GLOBAL_COUNT]; static size_t global_keys_length[GLOBAL_COUNT]; -uint8_t cleanup_pairs(memcached_st *memc) +static test_return_t cleanup_pairs(memcached_st *memc __attribute__((unused))) { pairs_free(global_pairs); return 0; } -uint8_t generate_pairs(memcached_st *memc) +static test_return_t generate_pairs(memcached_st *memc __attribute__((unused))) { unsigned long long x; global_pairs= pairs_generate(GLOBAL_COUNT, 400); @@ -59,10 +70,10 @@ uint8_t generate_pairs(memcached_st *memc) return 0; } -uint8_t drizzle(memcached_st *memc) +static test_return_t drizzle(memcached_st *memc) { unsigned int x; - memcached_return rc; + memcached_return_t rc; char *return_value; size_t return_value_length; uint32_t flags; @@ -73,8 +84,8 @@ infinite: uint32_t test_bit; uint8_t which; - test_bit= random() % GLOBAL_COUNT; - which= random() % 2; + test_bit= (uint32_t)(random() % GLOBAL_COUNT); + which= (uint8_t)(random() % 2); if (which == 0) { @@ -111,38 +122,38 @@ infinite: return 0; } -memcached_return pre_nonblock(memcached_st *memc) +static memcached_return_t pre_nonblock(memcached_st *memc) { memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 0); return MEMCACHED_SUCCESS; } -memcached_return pre_md5(memcached_st *memc) +static memcached_return_t pre_md5(memcached_st *memc) { memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_MD5); return MEMCACHED_SUCCESS; } -memcached_return pre_hsieh(memcached_st *memc) +static memcached_return_t pre_hsieh(memcached_st *memc) { memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_HSIEH); return MEMCACHED_SUCCESS; } -memcached_return enable_consistent(memcached_st *memc) +static memcached_return_t enable_consistent(memcached_st *memc) { - memcached_server_distribution value= MEMCACHED_DISTRIBUTION_CONSISTENT; - memcached_hash hash; + memcached_server_distribution_t value= MEMCACHED_DISTRIBUTION_CONSISTENT; + memcached_hash_t hash; memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, value); pre_hsieh(memc); - value= (memcached_server_distribution)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION); + value= (memcached_server_distribution_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION); assert(value == MEMCACHED_DISTRIBUTION_CONSISTENT); - hash= (memcached_hash)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH); + hash= (memcached_hash_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH); assert(hash == MEMCACHED_HASH_HSIEH); @@ -153,11 +164,11 @@ memcached_return enable_consistent(memcached_st *memc) Set the value, then quit to make sure it is flushed. Come back in and test that add fails. */ -uint8_t add_test(memcached_st *memc) +static test_return_t add_test(memcached_st *memc) { - memcached_return rc; - char *key= "foo"; - char *value= "when we sanitize"; + memcached_return_t rc; + const char *key= "foo"; + const char *value= "when we sanitize"; unsigned long long setting_value; setting_value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK); @@ -165,7 +176,7 @@ uint8_t add_test(memcached_st *memc) rc= memcached_set(memc, key, strlen(key), value, strlen(value), (time_t)0, (uint32_t)0); - assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + test_truth(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); memcached_quit(memc); rc= memcached_add(memc, key, strlen(key), value, strlen(value), @@ -173,9 +184,13 @@ uint8_t add_test(memcached_st *memc) /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */ if (setting_value) - assert(rc == MEMCACHED_NOTSTORED || MEMCACHED_STORED); + { + test_truth(rc == MEMCACHED_NOTSTORED || rc == MEMCACHED_STORED); + } else - assert(rc == MEMCACHED_NOTSTORED); + { + test_truth(rc == MEMCACHED_NOTSTORED); + } return 0; } @@ -184,61 +199,51 @@ uint8_t add_test(memcached_st *memc) * repeating add_tests many times * may show a problem in timing */ -uint8_t many_adds(memcached_st *memc) +static test_return_t many_adds(memcached_st *memc) { unsigned int i; - for (i = 0; i < TEST_COUNTER; i++){ + for (i = 0; i < TEST_COUNTER; i++) + { add_test(memc); } return 0; } test_st smash_tests[] ={ - {"generate_pairs", 1, generate_pairs }, - {"drizzle", 1, drizzle }, - {"cleanup", 1, cleanup_pairs }, - {"many_adds", 1, many_adds }, + {"generate_pairs", 1, (test_callback_fn)generate_pairs }, + {"drizzle", 1, (test_callback_fn)drizzle }, + {"cleanup", 1, (test_callback_fn)cleanup_pairs }, + {"many_adds", 1, (test_callback_fn)many_adds }, {0, 0, 0} }; collection_st collection[] ={ {"smash", 0, 0, smash_tests}, - {"smash_hsieh", pre_hsieh, 0, smash_tests}, - {"smash_hsieh_consistent", enable_consistent, 0, smash_tests}, - {"smash_md5", pre_md5, 0, smash_tests}, - {"smash_nonblock", pre_nonblock, 0, smash_tests}, + {"smash_hsieh", (test_callback_fn)pre_hsieh, 0, smash_tests}, + {"smash_hsieh_consistent", (test_callback_fn)enable_consistent, 0, smash_tests}, + {"smash_md5", (test_callback_fn)pre_md5, 0, smash_tests}, + {"smash_nonblock", (test_callback_fn)pre_nonblock, 0, smash_tests}, {0, 0, 0, 0} }; -#define SERVERS_TO_CREATE 5 - -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->count= SERVERS_TO_CREATE; - construct->udp= 0; - server_startup(construct); - return construct; -} - -void world_destroy(void *p) -{ - server_startup_st *construct= (server_startup_st *)p; - memcached_server_st *servers= (memcached_server_st *)construct->servers; - memcached_server_list_free(servers); +#define SERVERS_TO_CREATE 5 - server_shutdown(construct); - free(construct); -} +#include "libmemcached_world.h" void get_world(world_st *world) { world->collections= collection; - world->create= world_create; - world->destroy= world_destroy; + + world->create= (test_callback_create_fn)world_create; + world->destroy= (test_callback_fn)world_destroy; + + world->test.startup= (test_callback_fn)world_test_startup; + world->test.flush= (test_callback_fn)world_flush; + world->test.pre_run= (test_callback_fn)world_pre_run; + world->test.post_run= (test_callback_fn)world_post_run; + world->test.on_error= (test_callback_error_fn)world_on_error; + + world->runner= &defualt_libmemcached_runner; }