From b90c798532ec8d4d4e2f5c1eea1ec18354dd2070 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Wed, 20 Jul 2011 22:26:25 -0700 Subject: [PATCH] Fix it so socket is built just on main tests. --- libtest/framework.cc | 1 + libtest/framework.h | 6 ++++ libtest/server.h | 13 +++++++++ tests/atomsmasher.cc | 56 +++++++++++++++++++++----------------- tests/debug.cc | 8 ++++++ tests/debug.h | 2 ++ tests/include.am | 6 ++-- tests/libmemcached_world.h | 11 +++++--- tests/mem_functions.cc | 2 ++ 9 files changed, 74 insertions(+), 31 deletions(-) diff --git a/libtest/framework.cc b/libtest/framework.cc index baff4b8a..deb9045d 100644 --- a/libtest/framework.cc +++ b/libtest/framework.cc @@ -57,6 +57,7 @@ Framework::Framework() : collection_shutdown(_default_callback), _on_error(NULL), _runner(NULL), + _socket(false), _creators_ptr(NULL) { } diff --git a/libtest/framework.h b/libtest/framework.h index b504c5c1..087268cc 100644 --- a/libtest/framework.h +++ b/libtest/framework.h @@ -153,6 +153,11 @@ public: test_return_t on_error(const enum test_return_t, void *); + void set_socket() + { + _servers.set_socket(); + } + /** Runner represents the callers for the tests. If not implemented we will use a set of default implementations. @@ -176,5 +181,6 @@ public: private: Framework& operator=(const Framework&); libtest::server_startup_st _servers; + bool _socket; void *_creators_ptr; }; diff --git a/libtest/server.h b/libtest/server.h index c09469ec..d987a0b7 100644 --- a/libtest/server.h +++ b/libtest/server.h @@ -171,6 +171,7 @@ class server_startup_st { private: std::string server_list; + bool _socket; public: @@ -178,6 +179,7 @@ public: std::vector servers; server_startup_st() : + _socket(false), udp(0) { } @@ -194,6 +196,17 @@ public: bool is_helgrind() const; bool is_valgrind() const; + bool socket() + { + return _socket; + } + + void set_socket() + { + _socket= true; + } + + void shutdown(bool remove= false); void push_server(Server *); Server *pop_server(); diff --git a/tests/atomsmasher.cc b/tests/atomsmasher.cc index 60f201eb..573e7f53 100644 --- a/tests/atomsmasher.cc +++ b/tests/atomsmasher.cc @@ -33,6 +33,8 @@ #include +#include + using namespace libtest; /* Number of items generated for tests */ @@ -46,17 +48,15 @@ static pairs_st *global_pairs; static char *global_keys[GLOBAL_COUNT]; static size_t global_keys_length[GLOBAL_COUNT]; -static test_return_t cleanup_pairs(memcached_st *memc) +static test_return_t cleanup_pairs(memcached_st *) { - (void)memc; pairs_free(global_pairs); return TEST_SUCCESS; } -static test_return_t generate_pairs(memcached_st *memc) +static test_return_t generate_pairs(memcached_st *) { - (void)memc; global_pairs= pairs_generate(GLOBAL_COUNT, 400); global_count= GLOBAL_COUNT; @@ -71,14 +71,14 @@ static test_return_t generate_pairs(memcached_st *memc) static test_return_t drizzle(memcached_st *memc) { - memcached_return_t rc; - char *return_value; - size_t return_value_length; - uint32_t flags; - infinite: for (size_t x= 0; x < TEST_COUNTER; x++) { + memcached_return_t rc; + char *return_value; + size_t return_value_length; + uint32_t flags; + uint32_t test_bit; uint8_t which; @@ -119,7 +119,9 @@ infinite: } if (getenv("MEMCACHED_ATOM_BURIN_IN")) + { goto infinite; + } return TEST_SUCCESS; } @@ -137,13 +139,10 @@ static test_return_t pre_nonblock(memcached_st *memc) */ static test_return_t add_test(memcached_st *memc) { - 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); + memcached_return_t rc; rc= memcached_set(memc, key, strlen(key), value, strlen(value), (time_t)0, (uint32_t)0); @@ -153,8 +152,13 @@ static test_return_t add_test(memcached_st *memc) value, strlen(value), (time_t)0, (uint32_t)0); + if (rc == MEMCACHED_CONNECTION_FAILURE) + { + print_servers(memc); + } + /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */ - if (setting_value) + if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK)) { test_true(rc == MEMCACHED_NOTSTORED or rc == MEMCACHED_STORED); } @@ -172,18 +176,19 @@ static test_return_t add_test(memcached_st *memc) */ static test_return_t many_adds(memcached_st *memc) { + test_true(memc); for (size_t x= 0; x < TEST_COUNTER; x++) { - add_test(memc); + test_compare_got(TEST_SUCCESS, add_test(memc), x); } return TEST_SUCCESS; } test_st smash_tests[] ={ - {"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 }, + {"generate_pairs", true, (test_callback_fn*)generate_pairs }, + {"drizzle", true, (test_callback_fn*)drizzle }, + {"cleanup", true, (test_callback_fn*)cleanup_pairs }, + {"many_adds", true, (test_callback_fn*)many_adds }, {0, 0, 0} }; @@ -197,9 +202,8 @@ struct benchmark_state_st memcached_st *clone; } benchmark_state; -static test_return_t memcached_create_benchmark(memcached_st *memc) +static test_return_t memcached_create_benchmark(memcached_st *) { - (void)memc; benchmark_state.create_init= true; for (size_t x= 0; x < BENCHMARK_TEST_LOOP; x++) @@ -228,9 +232,8 @@ static test_return_t memcached_clone_benchmark(memcached_st *memc) return TEST_SUCCESS; } -static test_return_t pre_allocate(memcached_st *memc) +static test_return_t pre_allocate(memcached_st *) { - (void)memc; memset(&benchmark_state, 0, sizeof(benchmark_state)); benchmark_state.create= (memcached_st *)calloc(BENCHMARK_TEST_LOOP, sizeof(memcached_st)); @@ -241,16 +244,19 @@ static test_return_t pre_allocate(memcached_st *memc) return TEST_SUCCESS; } -static test_return_t post_allocate(memcached_st *memc) +static test_return_t post_allocate(memcached_st *) { - (void)memc; for (size_t x= 0; x < BENCHMARK_TEST_LOOP; x++) { if (benchmark_state.create_init) + { memcached_free(&benchmark_state.create[x]); + } if (benchmark_state.clone_init) + { memcached_free(&benchmark_state.clone[x]); + } } free(benchmark_state.create); diff --git a/tests/debug.cc b/tests/debug.cc index 4ba46eae..0b091a8d 100644 --- a/tests/debug.cc +++ b/tests/debug.cc @@ -44,6 +44,7 @@ using namespace libtest; #include #include +#include /* Dump each server's keys */ static memcached_return_t print_keys_callback(const memcached_st *, @@ -179,3 +180,10 @@ size_t confirm_key_count(memcached_st *memc) memcached_free(clone); return count; } + +void print_servers(memcached_st *memc) +{ + memcached_server_fn callbacks[1]; + callbacks[0]= server_print_callback; + memcached_server_cursor(memc, callbacks, NULL, 1); +} diff --git a/tests/debug.h b/tests/debug.h index 3d5a2288..ad20b562 100644 --- a/tests/debug.h +++ b/tests/debug.h @@ -44,3 +44,5 @@ test_return_t confirm_keys_dont_exist(memcached_st *memc, const char * const *ke test_return_t print_keys_by_server(memcached_st *memc); size_t confirm_key_count(memcached_st *memc); + +void print_servers(memcached_st *); diff --git a/tests/include.am b/tests/include.am index ac0dd92b..b8b2cb80 100644 --- a/tests/include.am +++ b/tests/include.am @@ -96,6 +96,8 @@ check_PROGRAMS+= tests/testplus tests_atomsmasher_SOURCES= \ tests/atomsmasher.cc \ + tests/debug.cc \ + tests/print.cc \ clients/generator.cc \ clients/execute.cc tests_atomsmasher_DEPENDENCIES= $(TESTS_LDADDS) @@ -326,7 +328,7 @@ valgrind-hashplus: tests/hashplus $(VALGRIND_COMMAND) $(HASHPLUS_COMMAND) PHONY += valgrind -valgrind: valgrind-cycle valgrind-mem valgrind-atom valgrind-udp valgrind-plus valgrind-hash valgrind-hashplus +valgrind: valgrind-cycle valgrind-mem valgrind-udp valgrind-plus valgrind-hash valgrind-hashplus helgrind-cycle: tests/cycle $(HELGRIND_COMMAND) $(CYCLE_COMMAND) @@ -350,7 +352,7 @@ helgrind-hashplus: tests/hashplus $(HELGRIND_COMMAND) $(HASHPLUS_COMMAND) .PHONY += helgrind -helgrind: helgrind-cycle helgrind-mem helgrind-atom helgrind-udp helgrind-plus helgrind-hash helgrind-hashplus +helgrind: helgrind-cycle helgrind-mem helgrind-udp helgrind-plus helgrind-hash helgrind-hashplus PHONY += cachegrind CLEANFILES += tests/cachegrind.out diff --git a/tests/libmemcached_world.h b/tests/libmemcached_world.h index c6eebea7..968c235e 100644 --- a/tests/libmemcached_world.h +++ b/tests/libmemcached_world.h @@ -59,11 +59,14 @@ static void *world_create(server_startup_st& servers, test_return_t& error) } } - const char *argv[1]= { "memcached" }; - if (not servers.start_socket_server("memcached", max_port +1, 1, argv)) + if (servers.socket()) { - error= TEST_FAILURE; - return NULL; + const char *argv[1]= { "memcached" }; + if (not servers.start_socket_server("memcached", max_port +1, 1, argv)) + { + error= TEST_FAILURE; + return NULL; + } } diff --git a/tests/mem_functions.cc b/tests/mem_functions.cc index f0a14e61..bf2f3ee0 100644 --- a/tests/mem_functions.cc +++ b/tests/mem_functions.cc @@ -6540,4 +6540,6 @@ void get_world(Framework *world) world->collection_shutdown= (test_callback_fn*)world_container_shutdown; world->set_runner(&defualt_libmemcached_runner); + + world->set_socket(); } -- 2.30.2