X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Fatomsmasher.c;h=6ff68ca96a4851b8f40f1126190570243e9dd5d1;hb=8af90ac15d8ba8ec464e5ad402ed2d27b95f81e3;hp=c267fcee546b24e3dc45b2467493b4c8a57eef55;hpb=7ab91f09b127b67e726c03a7f4384f0970096977;p=m6w6%2Flibmemcached diff --git a/tests/atomsmasher.c b/tests/atomsmasher.c index c267fcee..6ff68ca9 100644 --- a/tests/atomsmasher.c +++ b/tests/atomsmasher.c @@ -2,7 +2,7 @@ Sample test application. */ #include -#include +#include #include #include #include @@ -12,9 +12,9 @@ #include #include #include "server.h" -#include "../lib/common.h" -#include "../src/generator.h" -#include "../src/execute.h" +#include "../libmemcached/common.h" +#include "../clients/generator.h" +#include "../clients/execute.h" #ifndef INT64_MAX #define INT64_MAX LONG_MAX @@ -26,8 +26,11 @@ #include "test.h" +/* Number of items generated for tests */ #define GLOBAL_COUNT 100000 -#define TEST_COUNTER 100000 + +/* Number of times to run the test loop */ +#define TEST_COUNTER 500000 static uint32_t global_count; static pairs_st *global_pairs; @@ -60,67 +63,71 @@ uint8_t drizzle(memcached_st *memc) { unsigned int x; memcached_return rc; + char *return_value; + size_t return_value_length; + uint32_t flags; +infinite: + for (x= 0; x < TEST_COUNTER; x++) { - char *return_value; - size_t return_value_length; - uint32_t flags; - - for (x= 0; x < TEST_COUNTER; x++) - { - uint32_t test_bit; - uint8_t which; + uint32_t test_bit; + uint8_t which; - test_bit= random() % GLOBAL_COUNT; - which= random() % 2; + test_bit= random() % GLOBAL_COUNT; + which= random() % 2; - if (which == 0) - { - return_value= memcached_get(memc, global_keys[test_bit], global_keys_length[test_bit], - &return_value_length, &flags, &rc); - if (rc == MEMCACHED_SUCCESS && return_value) - free(return_value); - else - WATCHPOINT_ERROR(rc); - } + if (which == 0) + { + return_value= memcached_get(memc, global_keys[test_bit], global_keys_length[test_bit], + &return_value_length, &flags, &rc); + if (rc == MEMCACHED_SUCCESS && return_value) + free(return_value); + else if (rc == MEMCACHED_NOTFOUND) + continue; else { - rc= memcached_set(memc, global_pairs[test_bit].key, - global_pairs[test_bit].key_length, - global_pairs[test_bit].value, - global_pairs[test_bit].value_length, - 0, 0); - if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_BUFFERED) - { - WATCHPOINT_ERROR(rc); - WATCHPOINT_ASSERT(0); - } + WATCHPOINT_ERROR(rc); + WATCHPOINT_ASSERT(rc); + } + } + else + { + rc= memcached_set(memc, global_pairs[test_bit].key, + global_pairs[test_bit].key_length, + global_pairs[test_bit].value, + global_pairs[test_bit].value_length, + 0, 0); + if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_BUFFERED) + { + WATCHPOINT_ERROR(rc); + WATCHPOINT_ASSERT(0); } } } + if (getenv("MEMCACHED_ATOM_BURIN_IN")) + goto infinite; + return 0; } memcached_return pre_nonblock(memcached_st *memc) { - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 0); return MEMCACHED_SUCCESS; } memcached_return pre_md5(memcached_st *memc) { - memcached_hash value= MEMCACHED_HASH_MD5; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_MD5); return MEMCACHED_SUCCESS; } memcached_return pre_hsieh(memcached_st *memc) { - memcached_hash value= MEMCACHED_HASH_HSIEH; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_HSIEH); return MEMCACHED_SUCCESS; } @@ -129,7 +136,7 @@ memcached_return enable_consistent(memcached_st *memc) { memcached_server_distribution value= MEMCACHED_DISTRIBUTION_CONSISTENT; memcached_hash hash; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, &value); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, value); pre_hsieh(memc); value= (memcached_server_distribution)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION); @@ -142,19 +149,65 @@ memcached_return enable_consistent(memcached_st *memc) return MEMCACHED_SUCCESS; } -test_st generate_tests[] ={ +/* + 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) +{ + memcached_return rc; + char *key= "foo"; + char *value= "when we sanitize"; + unsigned long long setting_value; + + setting_value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK); + + rc= memcached_set(memc, key, strlen(key), + value, strlen(value), + (time_t)0, (uint32_t)0); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + memcached_quit(memc); + rc= memcached_add(memc, key, strlen(key), + value, strlen(value), + (time_t)0, (uint32_t)0); + + /* 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); + else + assert(rc == MEMCACHED_NOTSTORED); + + return 0; +} + +/* + * repeating add_tests many times + * may show a problem in timing + */ +uint8_t many_adds(memcached_st *memc) +{ + unsigned int 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 }, {0, 0, 0} }; collection_st collection[] ={ - {"generate", 0, 0, generate_tests}, - {"generate_hsieh", pre_hsieh, 0, generate_tests}, - {"generate_hsieh_consistent", enable_consistent, 0, generate_tests}, - {"generate_md5", pre_md5, 0, generate_tests}, - {"generate_nonblock", pre_nonblock, 0, generate_tests}, + {"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}, {0, 0, 0, 0} };