From: Brian Aker Date: Tue, 8 Jan 2013 01:03:28 +0000 (-0500) Subject: Update yatl. X-Git-Tag: 1.0.16~16^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=17690735658d7b44f91579df91e31da9ae185158;p=awesomized%2Flibmemcached Update yatl. --- diff --git a/clients/generator.cc b/clients/generator.cc index b2ba67ca..df805153 100644 --- a/clients/generator.cc +++ b/clients/generator.cc @@ -20,7 +20,7 @@ #include #include -#include "generator.h" +#include "clients/generator.h" /* Use this for string generation */ static const char ALPHANUMERICS[]= @@ -33,12 +33,14 @@ static size_t get_alpha_num(void) return (size_t)random() % ALPHANUMERICS_SIZE; } -static void get_random_string(char *buffer, size_t size) +void get_random_string(char *buffer, size_t size) { char *buffer_ptr= buffer; while (--size) + { *buffer_ptr++= ALPHANUMERICS[get_alpha_num()]; + } *buffer_ptr++= ALPHANUMERICS[get_alpha_num()]; } diff --git a/clients/memslap.cc b/clients/memslap.cc index 295ea0db..d32b1c04 100644 --- a/clients/memslap.cc +++ b/clients/memslap.cc @@ -224,7 +224,15 @@ int main(int argc, char *argv[]) pthread_mutex_init(&sleeper_mutex, NULL); pthread_cond_init(&sleep_threshhold, NULL); - scheduler(servers, &conclusion); + int error_code= EXIT_SUCCESS; + try { + scheduler(servers, &conclusion); + } + catch(std::exception& e) + { + std::cerr << "Died with exception: " << e.what() << std::endl; + error_code= EXIT_FAILURE; + } free(opt_servers); @@ -233,7 +241,7 @@ int main(int argc, char *argv[]) conclusions_print(&conclusion); memcached_server_list_free(servers); - return EXIT_SUCCESS; + return error_code; } void scheduler(memcached_server_st *servers, conclusions_st *conclusion) @@ -305,7 +313,7 @@ void scheduler(memcached_server_st *servers, conclusions_st *conclusion) pthread_t *threads= new (std::nothrow) pthread_t[opt_concurrency]; - if (not threads) + if (threads == NULL) { exit(EXIT_FAILURE); } diff --git a/configure.ac b/configure.ac index b66c05fa..de966c80 100644 --- a/configure.ac +++ b/configure.ac @@ -189,6 +189,7 @@ AM_CONDITIONAL([BUILD_CACHE],[test "x$build_cache" = "xyes"]) AX_COMPILER_VENDOR +AC_CHECK_TYPES([in_port_t]) AC_CHECK_TYPES([ptrdiff_t]) AC_HEADER_STDBOOL AC_TYPE_INT16_T @@ -218,6 +219,7 @@ AC_CHECK_LIB([rt],[clock_gettime], AC_DEFINE([HAVE_CLOCK_GETTIME],[1],[Have clock_gettime])], [AC_DEFINE([HAVE_CLOCK_GETTIME],[0],[Have clock_gettime])]) + # Check for the ability to call dlopen (used in libhostile) AX_DLOPEN diff --git a/libmemcached/assert.hpp b/libmemcached/assert.hpp index 28948c3c..f2fc158d 100644 --- a/libmemcached/assert.hpp +++ b/libmemcached/assert.hpp @@ -37,8 +37,17 @@ #pragma once +#ifdef _WIN32 +# include +#else +# include +#endif + +#include + #ifdef NDEBUG #define assert_msg(__expr, __mesg) (void)(__expr); (void)(__mesg); +#define assert_vmsg(__expr, __mesg, ...) (void)(__expr); (void)(__mesg); #else #define assert_msg(__expr, __mesg) \ @@ -52,4 +61,19 @@ do \ } \ } while (0) +#define assert_vmsg(__expr, __mesg, ...) \ +do \ +{ \ + if (not (__expr)) \ + { \ + size_t ask= snprintf(0, 0, (__mesg), __VA_ARGS__); \ + ask++; \ + char *_error_message= (char*)alloca(sizeof(char) * ask); \ + size_t _error_message_size= snprintf(_error_message, ask, (__mesg), __VA_ARGS__); \ + fprintf(stderr, "\n%s:%d Assertion '%s' failed for function '%s' [ %.*s ]\n", __FILE__, __LINE__, #__expr, __func__, int(_error_message_size), _error_message);\ + custom_backtrace(); \ + abort(); \ + } \ +} while (0) + #endif diff --git a/libmemcached/connect.cc b/libmemcached/connect.cc index b59c0ecb..d6dca966 100644 --- a/libmemcached/connect.cc +++ b/libmemcached/connect.cc @@ -206,12 +206,6 @@ static memcached_return_t set_hostinfo(org::libmemcached::Instance* server) break; case EAI_AGAIN: - if (server->address_info) - { - freeaddrinfo(server->address_info); - server->address_info= NULL; - server->address_info_next= NULL; - } return memcached_set_error(*server, MEMCACHED_TIMEOUT, MEMCACHED_AT, memcached_string_make_from_cstr(gai_strerror(errcode))); case EAI_SYSTEM: diff --git a/libmemcached/hosts.cc b/libmemcached/hosts.cc index 73fb66af..80ba0339 100644 --- a/libmemcached/hosts.cc +++ b/libmemcached/hosts.cc @@ -346,52 +346,52 @@ static memcached_return_t update_continuum(memcached_st *ptr) return MEMCACHED_SUCCESS; } -static memcached_return_t server_add(memcached_st *ptr, +static memcached_return_t server_add(memcached_st *memc, const memcached_string_t& hostname, in_port_t port, uint32_t weight, memcached_connection_t type) { - assert_msg(ptr, "Programmer mistake, somehow server_add() was passed a NULL memcached_st"); + assert_msg(memc, "Programmer mistake, somehow server_add() was passed a NULL memcached_st"); - if (ptr->number_of_hosts) + if (memc->number_of_hosts) { - assert(memcached_instance_list(ptr)); + assert(memcached_instance_list(memc)); } - if (memcached_instance_list(ptr)) + if (memcached_instance_list(memc)) { - assert(ptr->number_of_hosts); + assert(memc->number_of_hosts); } - uint32_t host_list_size= ptr->number_of_hosts +1; - org::libmemcached::Instance* new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), host_list_size, org::libmemcached::Instance); + uint32_t host_list_size= memc->number_of_hosts +1; + org::libmemcached::Instance* new_host_list= libmemcached_xrealloc(memc, memcached_instance_list(memc), host_list_size, org::libmemcached::Instance); if (new_host_list == NULL) { - return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); + return memcached_set_error(*memc, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); } - memcached_instance_set(ptr, new_host_list, host_list_size); - assert(ptr->number_of_hosts == host_list_size); + memcached_instance_set(memc, new_host_list, host_list_size); + assert(memc->number_of_hosts == host_list_size); /* TODO: Check return type */ - org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, memcached_server_count(ptr) -1); + org::libmemcached::Instance* instance= memcached_instance_fetch(memc, memcached_server_count(memc) -1); - if (__instance_create_with(ptr, instance, hostname, port, weight, type) == NULL) + if (__instance_create_with(memc, instance, hostname, port, weight, type) == NULL) { - return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); + return memcached_set_error(*memc, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); } if (weight > 1) { - if (memcached_is_consistent_distribution(ptr)) + if (memcached_is_consistent_distribution(memc)) { - memcached_set_weighted_ketama(ptr, true); + memcached_set_weighted_ketama(memc, true); } } - return run_distribution(ptr); + return run_distribution(memc); } diff --git a/libmemcached/include.am b/libmemcached/include.am index 74da20f0..4c826ba1 100644 --- a/libmemcached/include.am +++ b/libmemcached/include.am @@ -115,12 +115,10 @@ libmemcached_libmemcached_la_LDFLAGS+= -version-info ${MEMCACHED_LIBRARY_VERSION libmemcached_libmemcached_la_LIBADD+= @DL_LIB@ if HAVE_SASL -if HAVE_LIBSASL libmemcached_libmemcached_la_CXXFLAGS+= @PTHREAD_CFLAGS@ libmemcached_libmemcached_la_LIBADD+= @PTHREAD_LIBS@ libmemcached_libmemcached_la_LIBADD+= @LIBSASL_LIB@ endif -endif if HAVE_DTRACE BUILT_SOURCES+= libmemcached/dtrace_probes.h diff --git a/libmemcached/memcached.cc b/libmemcached/memcached.cc index d430d116..bd23f1f1 100644 --- a/libmemcached/memcached.cc +++ b/libmemcached/memcached.cc @@ -279,12 +279,13 @@ void memcached_servers_reset(memcached_st *self) { if (self) { - memcached_instance_list_free(memcached_instance_list(self), self->number_of_hosts); + libmemcached_free(self, self->ketama.continuum); + self->ketama.continuum= NULL; + memcached_instance_list_free(memcached_instance_list(self), self->number_of_hosts); memcached_instance_set(self, NULL, 0); - self->number_of_hosts= 0; - memcached_instance_free((org::libmemcached::Instance*)self->last_disconnected_server); - self->last_disconnected_server= NULL; + + memcached_reset_last_disconnected_server(self); } } diff --git a/libmemcached/server_list.cc b/libmemcached/server_list.cc index 5ead6fe9..b42a9095 100644 --- a/libmemcached/server_list.cc +++ b/libmemcached/server_list.cc @@ -129,6 +129,7 @@ uint32_t memcached_instance_list_count(const memcached_st* self) void memcached_instance_set(memcached_st* memc, org::libmemcached::Instance* list, const uint32_t host_list_size) { + assert(memc); memc->servers= list; memc->number_of_hosts= host_list_size; } diff --git a/libmemcachedutil/common.h b/libmemcachedutil/common.h index 6afd7968..5e39354f 100644 --- a/libmemcachedutil/common.h +++ b/libmemcachedutil/common.h @@ -44,6 +44,6 @@ #include #include -#include -#include -#include +#include "libmemcachedutil-1.0/util.h" +#include "libmemcached/assert.hpp" +#include "libmemcached/backtrace.hpp" diff --git a/libmemcachedutil/pool.cc b/libmemcachedutil/pool.cc index a3f79ecf..8d760246 100644 --- a/libmemcachedutil/pool.cc +++ b/libmemcachedutil/pool.cc @@ -86,11 +86,20 @@ struct memcached_pool_st for (int x= 0; x <= firstfree; ++x) { memcached_free(server_pool[x]); - server_pool[x] = NULL; + server_pool[x]= NULL; + } + + int error; + if ((error= pthread_mutex_destroy(&mutex)) != 0) + { + assert_vmsg(error != 0, "pthread_mutex_destroy() %s(%d)", strerror(error), error); + } + + if ((error= pthread_cond_destroy(&cond)) != 0) + { + assert_vmsg(error != 0, "pthread_cond_destroy() %s", strerror(error)); } - pthread_mutex_destroy(&mutex); - pthread_cond_destroy(&cond); delete [] server_pool; if (_owns_master) { @@ -139,8 +148,10 @@ static bool grow_pool(memcached_pool_st* pool) bool memcached_pool_st::init(uint32_t initial) { server_pool= new (std::nothrow) memcached_st *[size]; - if (not server_pool) + if (server_pool == NULL) + { return false; + } /* Try to create the initial size of the pool. An allocation failure at @@ -275,6 +286,7 @@ memcached_st* memcached_pool_st::fetch(const struct timespec& relative_time, mem int unlock_error; if ((unlock_error= pthread_mutex_unlock(&mutex)) != 0) { + assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error)); } if (thread_ret == ETIMEDOUT) @@ -295,6 +307,7 @@ memcached_st* memcached_pool_st::fetch(const struct timespec& relative_time, mem int unlock_error; if ((unlock_error= pthread_mutex_unlock(&mutex)) != 0) { + assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error)); } return NULL; @@ -303,6 +316,7 @@ memcached_st* memcached_pool_st::fetch(const struct timespec& relative_time, mem if ((error= pthread_mutex_unlock(&mutex)) != 0) { + assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error)); } return ret; @@ -344,6 +358,7 @@ bool memcached_pool_st::release(memcached_st *released, memcached_return_t& rc) /* we might have people waiting for a connection.. wake them up :-) */ if ((error= pthread_cond_broadcast(&cond)) != 0) { + assert_vmsg(error != 0, "pthread_cond_broadcast() %s", strerror(error)); } } @@ -444,6 +459,7 @@ memcached_return_t memcached_pool_behavior_set(memcached_pool_st *pool, { if ((error= pthread_mutex_unlock(&pool->mutex)) != 0) { + assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error)); } return rc; } @@ -475,6 +491,7 @@ memcached_return_t memcached_pool_behavior_set(memcached_pool_st *pool, if ((error= pthread_mutex_unlock(&pool->mutex)) != 0) { + assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error)); } return rc; @@ -499,6 +516,7 @@ memcached_return_t memcached_pool_behavior_get(memcached_pool_st *pool, if ((error= pthread_mutex_unlock(&pool->mutex)) != 0) { + assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error)); } return MEMCACHED_SUCCESS; diff --git a/libtest/blobslap_worker.cc b/libtest/blobslap_worker.cc index da43f619..612847e5 100644 --- a/libtest/blobslap_worker.cc +++ b/libtest/blobslap_worker.cc @@ -51,8 +51,6 @@ #include #include -#include - #ifndef __INTEL_COMPILER #pragma GCC diagnostic ignored "-Wold-style-cast" #endif @@ -160,6 +158,11 @@ bool BlobslapWorker::build(size_t argc, const char *argv[]) for (size_t x= 0 ; x < argc ; x++) { + if (argv[x] == NULL) + { + break; + } + add_option(argv[x]); } diff --git a/libtest/client.hpp b/libtest/client.hpp index a6439869..979a532a 100644 --- a/libtest/client.hpp +++ b/libtest/client.hpp @@ -58,7 +58,7 @@ public: bool is_error() const { - return _error.size(); + return _error.size() ? true : false; } private: // Methods diff --git a/libtest/cmdline.cc b/libtest/cmdline.cc index 60d2b1a4..5e723350 100644 --- a/libtest/cmdline.cc +++ b/libtest/cmdline.cc @@ -766,11 +766,13 @@ std::string Application::arguments() { std::stringstream arg_buffer; - for (size_t x= _use_libtool ? 2 : 0; - x < _argc and built_argv[x]; - ++x) + // Skip printing out the libtool reference + for (size_t x= _use_libtool ? 2 : 0; x < _argc; ++x) { - arg_buffer << built_argv[x] << " "; + if (built_argv[x]) + { + arg_buffer << built_argv[x] << " "; + } } return arg_buffer.str(); diff --git a/libtest/collection.cc b/libtest/collection.cc index b3bdbdee..1b4915e1 100644 --- a/libtest/collection.cc +++ b/libtest/collection.cc @@ -38,6 +38,7 @@ #include +// @todo possibly have this code fork off so if it fails nothing goes bad static test_return_t runner_code(libtest::Framework* frame, test_st* run, libtest::Timer& _timer) @@ -50,7 +51,7 @@ static test_return_t runner_code(libtest::Framework* frame, try { _timer.reset(); - return_code= frame->runner()->run(run->test_fn, frame->creators_ptr()); + return_code= frame->runner()->main(run->test_fn, frame->creators_ptr()); } // Special case where check for the testing of the exception // system. @@ -92,7 +93,7 @@ Collection::Collection(Framework* frame_arg, test_return_t Collection::exec() { - if (test_success(_frame->runner()->pre(_pre, _frame->creators_ptr()))) + if (test_success(_frame->runner()->setup(_pre, _frame->creators_ptr()))) { for (test_st *run= _tests; run->name; run++) { @@ -165,7 +166,7 @@ test_return_t Collection::exec() #endif } - (void) _frame->runner()->post(_post, _frame->creators_ptr()); + (void) _frame->runner()->teardown(_post, _frame->creators_ptr()); } if (_failed == 0 and _skipped == 0 and _success) diff --git a/libtest/drizzled.cc b/libtest/drizzled.cc index 8f5d3f58..16933c4b 100644 --- a/libtest/drizzled.cc +++ b/libtest/drizzled.cc @@ -206,6 +206,11 @@ bool Drizzle::build(size_t argc, const char *argv[]) for (size_t x= 0 ; x < argc ; x++) { + if (argv[x] == NULL) + { + break; + } + add_option(argv[x]); } diff --git a/libtest/gearmand.cc b/libtest/gearmand.cc index 337fb725..d9dcf192 100644 --- a/libtest/gearmand.cc +++ b/libtest/gearmand.cc @@ -143,6 +143,11 @@ bool Gearmand::build(size_t argc, const char *argv[]) for (size_t x= 0 ; x < argc ; x++) { + if (argv[x] == NULL) + { + break; + } + add_option(argv[x]); } diff --git a/libtest/lite.h b/libtest/lite.h index aad47cf3..52e96380 100644 --- a/libtest/lite.h +++ b/libtest/lite.h @@ -37,19 +37,25 @@ #pragma once #ifdef __cplusplus +# include # include +# include # include # include -#include #else +# include +# include # include +# include # include -# include # include -# include #endif -#include +#ifdef _WIN32 +# include +#else +# include +#endif #ifndef __PRETTY_FUNCTION__ # define __PRETTY_FUNCTION__ __func__ @@ -64,11 +70,11 @@ #endif #ifndef FAIL -# define FAIL(__message_format, ...) +# define FAIL(__message_format, ...) #endif #ifndef SKIP -# define SKIP(__message_format, ...) +# define SKIP(__message_format, ...) #endif static inline bool valgrind_is_caller(void) @@ -126,6 +132,22 @@ do \ } \ } while (0) +#define SKIP_IF_(__expression, ...) \ +do \ +{ \ + if ((__expression)) { \ + size_t ask= snprintf(0, 0, __VA_ARGS__); \ + ask++; \ + char *buffer= (char*)alloca(sizeof(char) * ask); \ + snprintf(buffer, ask, __VA_ARGS__); \ + if (YATL_FULL) { \ + SKIP(#__expression, buffer); \ + } \ + fprintf(stdout, "\n%s:%d: %s SKIP '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \ + exit(EXIT_SKIP); \ + } \ +} while (0) + #define ASSERT_TRUE(__expression) \ do \ { \ @@ -158,6 +180,9 @@ do \ ask++; \ char *buffer= (char*)alloca(sizeof(char) * ask); \ snprintf(buffer, ask, __VA_ARGS__); \ + if (YATL_FULL) { \ + FAIL("Assertion '%s' != NULL [ %s ]", #__expression, buffer);\ + } \ fprintf(stderr, "\n%s:%d: %s Assertion '%s' != NULL [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer);\ exit(EXIT_FAILURE); \ } \ @@ -167,6 +192,9 @@ do \ do \ { \ if ((__expression) == NULL) { \ + if (YATL_FULL) { \ + FAIL("Assertion '%s' == NULL", #__expression,);\ + } \ fprintf(stderr, "\n%s:%d: %s Assertion '%s' == NULL\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression,);\ exit(EXIT_FAILURE); \ } \ @@ -176,28 +204,15 @@ do \ do \ { \ if ((__expression) == NULL) { \ - size_t ask= snprintf(0, 0, __VA_ARGS__); \ - ask++; \ - char *buffer= (char*)alloca(sizeof(char) * ask); \ - snprintf(buffer, ask, __VA_ARGS__); \ - fprintf(stderr, "\n%s:%d: %s Assertion '%s' == NULL [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer);\ - exit(EXIT_FAILURE); \ - } \ -} while (0) - -#define SKIP_IF_(__expression, ...) \ -do \ -{ \ - if ((__expression)) { \ size_t ask= snprintf(0, 0, __VA_ARGS__); \ ask++; \ char *buffer= (char*)alloca(sizeof(char) * ask); \ snprintf(buffer, ask, __VA_ARGS__); \ if (YATL_FULL) { \ - SKIP(#__expression, buffer); \ + FAIL("Assertion '%s' == NULL [ %s ]", #__expression, buffer);\ } \ - fprintf(stdout, "\n%s:%d: %s SKIP '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \ - exit(EXIT_SKIP); \ + fprintf(stderr, "\n%s:%d: %s Assertion '%s' == NULL [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer);\ + exit(EXIT_FAILURE); \ } \ } while (0) @@ -209,6 +224,9 @@ do \ ask++; \ char *buffer= (char*)alloca(sizeof(char) * ask); \ snprintf(buffer, ask, __VA_ARGS__); \ + if (YATL_FULL) { \ + FAIL("Assertion '%s' [ %s ]", #__expression, buffer); \ + } \ fprintf(stderr, "\n%s:%d: %s Assertion '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \ exit(EXIT_FAILURE); \ } \ @@ -218,6 +236,9 @@ do \ do \ { \ if ((__expected) != (__actual)) { \ + if (YATL_FULL) { \ + FAIL("Assertion '%s' != '%s'", #__expected, #__actual); \ + } \ fprintf(stderr, "\n%s:%d: %s Assertion '%s' != '%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual); \ exit(EXIT_FAILURE); \ } \ @@ -231,6 +252,9 @@ do \ ask++; \ char *buffer= (char*)alloca(sizeof(char) * ask); \ snprintf(buffer, ask, __VA_ARGS__); \ + if (YATL_FULL) { \ + FAIL("Assertion '%s' != '%s' [ %s ]", #__expected, #__actual, buffer); \ + } \ fprintf(stderr, "\n%s:%d: %s Assertion '%s' != '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual, buffer); \ exit(EXIT_FAILURE); \ } \ @@ -243,6 +267,11 @@ do \ size_t __actual_length; \ int ret= yatl_strcmp(__expected_str, __actual_str, &__expected_length, &__actual_length); \ if (ret) { \ + if (YATL_FULL) { \ + FAIL("Assertion '%.*s' != '%.*s'\n", \ + (int)(__expected_length), (__expected_str), \ + (int)__actual_length, (__actual_str)) ; \ + } \ fprintf(stderr, "\n%s:%d: %s Assertion '%.*s' != '%.*s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, \ (int)(__expected_length), (__expected_str), \ (int)__actual_length, (__actual_str)) ; \ @@ -261,6 +290,12 @@ do \ ask++; \ char *buffer= (char*)alloca(sizeof(char) * ask); \ ask= snprintf(buffer, ask, __VA_ARGS__); \ + if (YATL_FULL) { \ + FAIL("Assertion '%.*s' != '%.*s' [ %.*s ]", \ + (int)(__expected_length), (__expected_str), \ + (int)(__actual_length), (__actual_str), \ + (int)(ask), buffer); \ + } \ fprintf(stderr, "\n%s:%d: %s Assertion '%.*s' != '%.*s' [ %.*s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, \ (int)(__expected_length), (__expected_str), \ (int)(__actual_length), (__actual_str), \ @@ -276,6 +311,11 @@ do \ size_t __actual_length; \ int ret= yatl_strcmp(__expected_str, __actual_str, &__expected_length, &__actual_length); \ if (ret == 0) { \ + if (YATL_FULL) { \ + FAIL("Assertion '%.*s' == '%.*s'", \ + (int)(__expected_length), (__expected_str), \ + (int)__actual_length, (__actual_str)) ; \ + } \ fprintf(stderr, "\n%s:%d: %s Assertion '%.*s' == '%.*s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, \ (int)(__expected_length), (__expected_str), \ (int)__actual_length, (__actual_str)) ; \ @@ -294,6 +334,12 @@ do \ ask++; \ char *buffer= (char*)alloca(sizeof(char) * ask); \ ask= snprintf(buffer, ask, __VA_ARGS__); \ + if (YATL_FULL) { \ + FAIL("Assertion '%.*s' == '%.*s' [ %.*s ]", \ + (int)(__expected_length), (__expected_str), \ + (int)(__actual_length), (__actual_str), \ + (int)(ask), buffer); \ + } \ fprintf(stderr, "\n%s:%d: %s Assertion '%.*s' == '%.*s' [ %.*s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, \ (int)(__expected_length), (__expected_str), \ (int)(__actual_length), (__actual_str), \ @@ -306,6 +352,9 @@ do \ do \ { \ if ((__expected) == (__actual)) { \ + if (YATL_FULL) { \ + FAIL("Assertion '%s' == '%s'", #__expected, #__actual); \ + } \ fprintf(stderr, "\n%s:%d: %s Assertion '%s' == '%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual); \ exit(EXIT_FAILURE); \ } \ @@ -319,6 +368,9 @@ do \ ask++; \ char *buffer= (char*)alloca(sizeof(char) * ask); \ snprintf(buffer, ask, __VA_ARGS__); \ + if (YATL_FULL) { \ + FAIL("Assertion '%s' == '%s' [ %s ]", #__expected, #__actual, buffer); \ + } \ fprintf(stderr, "\n%s:%d: %s Assertion '%s' == '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual, buffer); \ exit(EXIT_FAILURE); \ } \ @@ -333,7 +385,7 @@ do \ char *buffer= (char*)alloca(sizeof(char) * ask); \ snprintf(buffer, ask, __VA_ARGS__); \ if (YATL_FULL) { \ - throw libtest::__failure(__FILE__, __LINE__, __PRETTY_FUNCTION__, "Assertion '!%s' [ %s ]", #__expression, buffer); \ + FAIL("Assertion '!%s' [ %s ]", #__expression, buffer); \ } \ fprintf(stderr, "\n%s:%d: %s Assertion '!%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \ exit(EXIT_FAILURE); \ diff --git a/libtest/memcached.cc b/libtest/memcached.cc index ff246b5a..2c150f90 100644 --- a/libtest/memcached.cc +++ b/libtest/memcached.cc @@ -214,6 +214,11 @@ bool Memcached::build(size_t argc, const char *argv[]) for (size_t x= 0 ; x < argc ; x++) { + if (argv[x] == NULL) + { + break; + } + add_option(argv[x]); } diff --git a/libtest/runner.cc b/libtest/runner.cc index 059e9843..fdabb7c6 100644 --- a/libtest/runner.cc +++ b/libtest/runner.cc @@ -44,6 +44,117 @@ Runner::Runner() : { } +test_return_t Runner::main(test_callback_fn* func, void *object) +{ + test_return_t ret; + try { + ret= run(func, object); + } + catch (libtest::__skipped e) + { + ret= TEST_SKIPPED; + } + catch (libtest::__failure e) + { + libtest::stream::make_cerr(e.file(), e.line(), e.func()) << e.what(); + ret= TEST_FAILURE; + } + catch (libtest::__success) + { + ret= TEST_SUCCESS; + } + catch (libtest::fatal& e) + { + throw; + } + catch (std::exception& e) + { + libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what(); + throw; + } + catch (...) + { + libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << "Unknown exception thrown"; + throw; + } + + return ret; +} + +test_return_t Runner::setup(test_callback_fn* func, void *object) +{ + test_return_t ret; + try { + ret= pre(func, object); + } + catch (libtest::__skipped e) + { + ret= TEST_SKIPPED; + } + catch (libtest::__failure e) + { + libtest::stream::make_cout(e.file(), e.line(), e.func()) << e.what(); + ret= TEST_FAILURE; + } + catch (libtest::__success) + { + ret= TEST_SUCCESS; + } + catch (libtest::fatal& e) + { + throw; + } + catch (std::exception& e) + { + libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what(); + throw; + } + catch (...) + { + libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << "Unknown exception thrown"; + throw; + } + + return ret; +} + +test_return_t Runner::teardown(test_callback_fn* func, void *object) +{ + test_return_t ret; + try { + ret= post(func, object); + } + catch (libtest::__skipped e) + { + ret= TEST_SKIPPED; + } + catch (libtest::__failure e) + { + libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what(); + ret= TEST_FAILURE; + } + catch (libtest::__success) + { + ret= TEST_SUCCESS; + } + catch (libtest::fatal& e) + { + throw; + } + catch (std::exception& e) + { + libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what(); + throw; + } + catch (...) + { + libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << "Unknown exception thrown"; + throw; + } + + return ret; +} + test_return_t Runner::flush(void*) { return TEST_SUCCESS; @@ -53,22 +164,7 @@ test_return_t Runner::run(test_callback_fn* func, void *object) { if (func) { - try { - return func(object); - } - catch (libtest::__skipped e) - { - return TEST_SKIPPED; - } - catch (libtest::__failure e) - { - libtest::stream::make_cerr(e.file(), e.line(), e.func()) << e.what(); - return TEST_FAILURE; - } - catch (libtest::__success) - { - return TEST_SUCCESS; - } + return func(object); } return TEST_SUCCESS; @@ -78,22 +174,7 @@ test_return_t Runner::pre(test_callback_fn* func, void *object) { if (func) { - try { - return func(object); - } - catch (libtest::__skipped e) - { - return TEST_SKIPPED; - } - catch (libtest::__failure e) - { - libtest::stream::make_cout(e.file(), e.line(), e.func()) << e.what(); - return TEST_FAILURE; - } - catch (libtest::__success) - { - return TEST_SUCCESS; - } + return func(object); } return TEST_SUCCESS; @@ -103,25 +184,20 @@ test_return_t Runner::post(test_callback_fn* func, void *object) { if (func) { - try { - return func(object); - } - catch (libtest::__skipped e) - { - return TEST_SKIPPED; - } - catch (libtest::__failure e) - { - libtest::stream::make_cerr(e.file(), e.line(), e.func()) << e.what(); - return TEST_FAILURE; - } - catch (libtest::__success) - { - return TEST_SUCCESS; - } + return func(object); } return TEST_SUCCESS; } +void Runner::set_servers(libtest::server_startup_st& arg) +{ + _servers= &arg; +} + +bool Runner::check() +{ + return _servers ? _servers->check() : true; +} + } // namespace libtest diff --git a/libtest/runner.h b/libtest/runner.h index 71b18d9f..d90b70e4 100644 --- a/libtest/runner.h +++ b/libtest/runner.h @@ -45,25 +45,23 @@ namespace libtest { */ class Runner { public: - virtual test_return_t flush(void*); - virtual test_return_t run(test_callback_fn* func, void *object); - virtual test_return_t pre(test_callback_fn* func, void *object); - virtual test_return_t post(test_callback_fn* func, void *object); + test_return_t main(test_callback_fn* func, void *object); + test_return_t setup(test_callback_fn* func, void *object); + test_return_t teardown(test_callback_fn* func, void *object); Runner(); - void set_servers(libtest::server_startup_st& arg) - { - _servers= &arg; - } + void set_servers(libtest::server_startup_st& arg); - bool check() - { - return _servers ? _servers->check() : true; - } + bool check(); virtual ~Runner() { } + virtual test_return_t flush(void*); + virtual test_return_t run(test_callback_fn* func, void *object); + virtual test_return_t pre(test_callback_fn* func, void *object); + virtual test_return_t post(test_callback_fn* func, void *object); + private: libtest::server_startup_st* _servers; }; diff --git a/libtest/server.cc b/libtest/server.cc index 044772f5..33b20ad8 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -295,7 +295,9 @@ bool Server::start() if (pinged == false) { - Error << "ping(" << _app.pid() << ") wait: " << this_wait << " " << hostname() << ":" << port() << " run:" << _running << " " << error(); +#if 0 + Error << "Failed to ping(" << _app.pid() << ") wait: " << this_wait << " " << hostname() << ":" << port() << " run:" << _running << " " << error(); +#endif // If we happen to have a pid file, lets try to kill it if ((pid_file().empty() == false) and (access(pid_file().c_str(), R_OK) == 0)) @@ -480,13 +482,16 @@ bool Server::args(Application& app) for (Options::const_iterator iter= _options.begin(); iter != _options.end(); ++iter) { - if ((*iter).second.empty() == false) - { - app.add_option((*iter).first, (*iter).second); - } - else + if ((*iter).first.empty() == false) { - app.add_option((*iter).first); + if ((*iter).second.empty() == false) + { + app.add_option((*iter).first, (*iter).second); + } + else + { + app.add_option((*iter).first); + } } } diff --git a/libtest/signal.cc b/libtest/signal.cc index 1c4ecb73..165915f5 100644 --- a/libtest/signal.cc +++ b/libtest/signal.cc @@ -91,6 +91,7 @@ void SignalThread::test() assert(magic_memory == MAGIC_MEMORY); if (bool(getenv("LIBTEST_IN_GDB")) == false) { + assert(sigismember(&set, SIGALRM)); assert(sigismember(&set, SIGABRT)); assert(sigismember(&set, SIGQUIT)); assert(sigismember(&set, SIGINT)); @@ -151,6 +152,14 @@ static void *sig_thread(void *arg) switch (sig) { + case SIGALRM: + Error << "SIGALRM"; + if (gdb_is_caller()) + { + abort(); + } + exit(EXIT_SKIP); + case SIGVTALRM: Error << "SIGVTALRM was called"; context->unblock(); @@ -194,11 +203,17 @@ SignalThread::SignalThread() : sigemptyset(&set); if (bool(getenv("LIBTEST_IN_GDB")) == false) { + sigaddset(&set, SIGALRM); sigaddset(&set, SIGABRT); sigaddset(&set, SIGQUIT); sigaddset(&set, SIGINT); sigaddset(&set, SIGVTALRM); } + else + { + Out << "Inside of GDB, disabling signal handlers"; + } + sigaddset(&set, SIGPIPE); sigaddset(&set, SIGUSR2); diff --git a/libtest/thread.hpp b/libtest/thread.hpp index 05f7fad4..25fc0993 100644 --- a/libtest/thread.hpp +++ b/libtest/thread.hpp @@ -165,7 +165,7 @@ private: class Barrier { public: - Barrier(uint32_t count): + explicit Barrier(uint32_t count): _threshold(count), _count(count), _generation(0) diff --git a/libtest/unittest.cc b/libtest/unittest.cc index b3e90c79..6b11c3b0 100644 --- a/libtest/unittest.cc +++ b/libtest/unittest.cc @@ -618,6 +618,17 @@ static test_return_t vchar_t_TEST(void *) return TEST_SUCCESS; } +static test_return_t vchar_t_make_append_TEST(void *) +{ + libtest::vchar_t hostname; + libtest::vchar::make(hostname, 23); + libtest::vchar::append(hostname, ".com"); + ASSERT_EQ(28, hostname.size()); + ASSERT_EQ(0, hostname[27]); + + return TEST_SUCCESS; +} + static test_return_t vchar_t_compare_neg_TEST(void *) { libtest::vchar_t response; @@ -1086,6 +1097,7 @@ test_st dns_TESTS[] ={ test_st application_tests[] ={ {"vchar_t", 0, vchar_t_TEST }, + {"vchar_t make() append()", 0, vchar_t_make_append_TEST }, {"vchar_t compare()", 0, vchar_t_compare_neg_TEST }, {"true", 0, application_true_BINARY }, {"gbd true --fubar", 0, application_gdb_true_BINARY }, diff --git a/libtest/vchar.cc b/libtest/vchar.cc index 68646083..c899b515 100644 --- a/libtest/vchar.cc +++ b/libtest/vchar.cc @@ -37,6 +37,17 @@ #include "libtest/yatlcon.h" #include +/* Use this for string generation */ +static const char ALPHANUMERICS[]= + "0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz"; + +#define ALPHANUMERICS_SIZE (sizeof(ALPHANUMERICS)-1) + +static size_t get_alpha_num(void) +{ + return (size_t)random() % ALPHANUMERICS_SIZE; +} + namespace libtest { static std::string printer(const char *str, size_t length) @@ -82,9 +93,24 @@ void make(libtest::vchar_t& arg) void make(libtest::vchar_t& arg, size_t length) { arg.reserve(length); - for (uint32_t x= 0; x < length; x++) + for (uint32_t x= 0; x < length; ++x) + { + arg.push_back(ALPHANUMERICS[get_alpha_num()]); + } +} + +void chomp(libtest::vchar_t& arg) +{ + while(arg.size()) { - arg.push_back(char(x % 127)); + if (arg.back() == 0) + { + arg.pop_back(); + } + else + { + break; + } } } @@ -97,10 +123,28 @@ void append(libtest::vchar_ptr_t& arg, const char* ptr) { fatal_message("UNABLE to allocate %s(%p)", ptr, ptr); } + arg.push_back(new_ptr); } } +void append(libtest::vchar_t& arg, const char* ptr) +{ + if (ptr) + { + size_t length= strlen(ptr); + ASSERT_TRUE(length); + arg.reserve(length); + do + { + arg.push_back(*ptr); + ++ptr; + } while (*ptr); + + arg.push_back(0); + } +} + } // namespace vchar void make_vector(libtest::vchar_t& arg, const char *str, size_t length) diff --git a/libtest/vchar.hpp b/libtest/vchar.hpp index 737b6df1..1cc45b44 100644 --- a/libtest/vchar.hpp +++ b/libtest/vchar.hpp @@ -52,9 +52,11 @@ void make_vector(libtest::vchar_t& arg, const char *str, size_t length); namespace vchar { int compare(libtest::vchar_t& arg, const char *str, size_t length); +void chomp(libtest::vchar_t& arg); void make(libtest::vchar_t& arg); void make(libtest::vchar_t& arg, size_t length); void append(libtest::vchar_ptr_t& arg, const char*); +void append(libtest::vchar_t& arg, const char*); } // namespace vchar diff --git a/m4/ax_check_library.m4 b/m4/ax_check_library.m4 index f8d7962f..dd27ff41 100644 --- a/m4/ax_check_library.m4 +++ b/m4/ax_check_library.m4 @@ -61,7 +61,7 @@ # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. -#serial 6 +#serial 7 AC_DEFUN([AX_CHECK_LIBRARY], [AC_ARG_VAR($1[_CPPFLAGS],[C preprocessor flags for ]$1[ headers]) @@ -92,5 +92,4 @@ AC_DEFUN([AX_CHECK_LIBRARY], AC_SUBST($1[_LIB],[-l]$3) ifelse([$4], , :, [$4])], [ifelse([$5], , :, [$5])]) - AM_CONDITIONAL([HAVE_]$1,[test "$]AS_TR_SH([ax_cv_have_]$1)[" = "yes"]) ]) diff --git a/m4/ax_debug.m4 b/m4/ax_debug.m4 index e066bf6e..4c72f276 100644 --- a/m4/ax_debug.m4 +++ b/m4/ax_debug.m4 @@ -43,7 +43,7 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#serial 4 +#serial 5 AC_DEFUN([AX_DEBUG], [AC_PREREQ([2.63])dnl @@ -51,10 +51,12 @@ AC_DEFUN([AX_DEBUG], [AS_HELP_STRING([--enable-debug], [Add debug code/turns off optimizations (yes|no) @<:@default=no@:>@])], [ax_enable_debug=yes - AC_DEFINE(DEBUG,[1],[Define to 1 to enable debugging code.])], + AC_DEFINE([DEBUG],[1],[Define to 1 to enable debugging code.]) + AX_CHECK_LIBRARY([MCHECK],[mcheck.h],[mcheck],[AX_APPEND_LINK_FLAGS([-lmcheck])])], [ax_enable_debug=no - AC_DEFINE(DEBUG, [ 0 ], [Define to 1 to enable debugging code.])]) + AC_SUBST([MCHECK]) + AC_DEFINE([DEBUG],[0],[Define to 1 to enable debugging code.])]) AC_MSG_CHECKING([for debug]) AC_MSG_RESULT([$ax_enable_debug]) - ]) + AM_CONDITIONAL([DEBUG],[test "x${ax_enable_debug}" = "xyes"])]) diff --git a/m4/ax_dlopen.m4 b/m4/ax_dlopen.m4 index 89d97088..514c578a 100644 --- a/m4/ax_dlopen.m4 +++ b/m4/ax_dlopen.m4 @@ -1,11 +1,10 @@ -#serial 1 +#serial 2 AC_DEFUN([AX_DLOPEN], - [AS_IF([test "x$enable_shared" = xyes], - [AX_CHECK_LIBRARY([DL],[dlfcn.h],[dl], - [AC_DEFINE([HAVE_LIBDL],[1],[Have dlopen]) - AC_CHECK_LIB([dl],[dlopen],[AC_DEFINE([HAVE_DLOPEN],[1],[Have dlopen])]) - AC_CHECK_LIB([dl],[dladdr],[AC_DEFINE([HAVE_DLADDR],[1],[Have dladdr])])])], - [AM_CONDITIONAL([HAVE_DL],false)]) - ]) + [AS_IF([test "x$enable_shared" = xyes], + [AX_CHECK_LIBRARY([DL],[dlfcn.h],[dl], + [AC_DEFINE([HAVE_LIBDL],[1],[Have dlopen]) + AC_CHECK_LIB([dl],[dlopen],[AC_DEFINE([HAVE_DLOPEN],[1],[Have dlopen])]) + AC_CHECK_LIB([dl],[dladdr],[AC_DEFINE([HAVE_DLADDR],[1],[Have dladdr])])])]) + ]) diff --git a/m4/ax_harden_compiler_flags.m4 b/m4/ax_harden_compiler_flags.m4 index 91d58b39..66de89d3 100644 --- a/m4/ax_harden_compiler_flags.m4 +++ b/m4/ax_harden_compiler_flags.m4 @@ -83,11 +83,13 @@ AC_DEFUN([_HARDEN_LINKER_FLAGS], AC_DEFUN([_HARDEN_CC_COMPILER_FLAGS], [AC_LANG_PUSH([C])dnl - _APPEND_COMPILE_FLAGS_ERROR([-g]) AS_IF([test "x$ax_enable_debug" = xyes], - [_APPEND_COMPILE_FLAGS_ERROR([-ggdb]) - _APPEND_COMPILE_FLAGS_ERROR([-O0])], - [_APPEND_COMPILE_FLAGS_ERROR([-O2])]) + [CFLAGS='' + _APPEND_COMPILE_FLAGS_ERROR([-ggdb]) + _APPEND_COMPILE_FLAGS_ERROR([-g]) + _APPEND_COMPILE_FLAGS_ERROR([-O0])], + [_APPEND_COMPILE_FLAGS_ERROR([-g]) + _APPEND_COMPILE_FLAGS_ERROR([-O2])]) _APPEND_COMPILE_FLAGS_ERROR([-Wno-pragmas]) _APPEND_COMPILE_FLAGS_ERROR([-Wall]) @@ -142,15 +144,16 @@ AC_DEFUN([_HARDEN_CC_COMPILER_FLAGS], _APPEND_COMPILE_FLAGS_ERROR([-floop-parallelize-all]) _APPEND_COMPILE_FLAGS_ERROR([-fwrapv]) _APPEND_COMPILE_FLAGS_ERROR([-fmudflapt]) + _APPEND_COMPILE_FLAGS_ERROR([-pipe]) AS_IF([test "x$ax_enable_debug" = xno], [AS_IF([test "x$ac_cv_vcs_checkout" = xyes], [_APPEND_COMPILE_FLAGS_ERROR([-fstack-check]) AS_IF([test "x$ac_c_gcc_recent" = xyes], [_APPEND_COMPILE_FLAGS_ERROR([-D_FORTIFY_SOURCE=2]) - _APPEND_COMPILE_FLAGS_ERROR([-Wstack-protector]) +# _APPEND_COMPILE_FLAGS_ERROR([-Wstack-protector]) _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector]) - _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector-all]) +# _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector-all]) ])])]) AS_IF([test "x$ac_cv_vcs_checkout" = xyes], @@ -167,87 +170,82 @@ AC_DEFUN([_HARDEN_CXX_COMPILER_FLAGS], [AC_LANG_PUSH([C++]) AC_REQUIRE([_APPEND_COMPILE_FLAGS_ERROR]) - _APPEND_COMPILE_FLAGS_ERROR([-g]) - AS_IF([test "x$ax_enable_debug" = xyes], - [_APPEND_COMPILE_FLAGS_ERROR([-O0]) - _APPEND_COMPILE_FLAGS_ERROR([-ggdb])], - [_APPEND_COMPILE_FLAGS_ERROR([-O2])]) + AS_IF([test "x$ax_enable_debug" = xyes], + [CXXFLAGS='' + _APPEND_COMPILE_FLAGS_ERROR([-ggdb]) + _APPEND_COMPILE_FLAGS_ERROR([-g]) + _APPEND_COMPILE_FLAGS_ERROR([-O0])], + [_APPEND_COMPILE_FLAGS_ERROR([-g]) + _APPEND_COMPILE_FLAGS_ERROR([-O2])]) - AS_IF([test "x$ac_cv_vcs_checkout" = xyes], - [_APPEND_COMPILE_FLAGS_ERROR([-fstack-check])], - [_APPEND_COMPILE_FLAGS_ERROR([-Wno-pragmas])]) + AS_IF([test "x$ac_cv_vcs_checkout" = xyes], + [_APPEND_COMPILE_FLAGS_ERROR([-fstack-check])], + [_APPEND_COMPILE_FLAGS_ERROR([-Wno-pragmas])]) - _APPEND_COMPILE_FLAGS_ERROR([-Wall]) - _APPEND_COMPILE_FLAGS_ERROR([-Wextra]) - _APPEND_COMPILE_FLAGS_ERROR([-Wunknown-pragmas]) - _APPEND_COMPILE_FLAGS_ERROR([-Wthis-test-should-fail]) + _APPEND_COMPILE_FLAGS_ERROR([-Wall]) + _APPEND_COMPILE_FLAGS_ERROR([-Wextra]) + _APPEND_COMPILE_FLAGS_ERROR([-Wunknown-pragmas]) + _APPEND_COMPILE_FLAGS_ERROR([-Wthis-test-should-fail]) # Anything below this comment please keep sorted. - _APPEND_COMPILE_FLAGS_ERROR([--param=ssp-buffer-size=1]) + _APPEND_COMPILE_FLAGS_ERROR([--param=ssp-buffer-size=1]) # _APPEND_COMPILE_FLAGS_ERROR([-Wmissing-format-attribute]) - _APPEND_COMPILE_FLAGS_ERROR([-Wno-attributes]) - _APPEND_COMPILE_FLAGS_ERROR([-Waddress]) - _APPEND_COMPILE_FLAGS_ERROR([-Warray-bounds]) - _APPEND_COMPILE_FLAGS_ERROR([-Wchar-subscripts]) - _APPEND_COMPILE_FLAGS_ERROR([-Wcomment]) - _APPEND_COMPILE_FLAGS_ERROR([-Wctor-dtor-privacy]) - _APPEND_COMPILE_FLAGS_ERROR([-Wfloat-equal]) - _APPEND_COMPILE_FLAGS_ERROR([-Wformat=2]) - _APPEND_COMPILE_FLAGS_ERROR([-Wmaybe-uninitialized]) - _APPEND_COMPILE_FLAGS_ERROR([-Wmissing-field-initializers]) - _APPEND_COMPILE_FLAGS_ERROR([-Wlogical-op]) - _APPEND_COMPILE_FLAGS_ERROR([-Wnon-virtual-dtor]) - _APPEND_COMPILE_FLAGS_ERROR([-Wnormalized=id]) - _APPEND_COMPILE_FLAGS_ERROR([-Woverloaded-virtual]) - _APPEND_COMPILE_FLAGS_ERROR([-Wpointer-arith]) - AS_IF([test "x$MINGW" = xyes], - [_APPEND_COMPILE_FLAGS_ERROR([-Wno-suggest-attribute=const]) - _APPEND_COMPILE_FLAGS_ERROR([-Wno-missing-noreturn]) - _APPEND_COMPILE_FLAGS_ERROR([-Wmissing-noreturn]) - _APPEND_COMPILE_FLAGS_ERROR([-Wno-suggest-attribute=noreturn]) - _APPEND_COMPILE_FLAGS_ERROR([-Wno-error=suggest-attribute=noreturn]) - _APPEND_COMPILE_FLAGS_ERROR([-Wno-redundant-decls])], - [_APPEND_COMPILE_FLAGS_ERROR([-Wredundant-decls])]) - _APPEND_COMPILE_FLAGS_ERROR([-Wshadow]) - _APPEND_COMPILE_FLAGS_ERROR([-Wshorten-64-to-32]) - _APPEND_COMPILE_FLAGS_ERROR([-Wsign-compare]) - _APPEND_COMPILE_FLAGS_ERROR([-Wstrict-overflow=1]) - _APPEND_COMPILE_FLAGS_ERROR([-Wswitch-enum]) - _APPEND_COMPILE_FLAGS_ERROR([-Wundef]) - _APPEND_COMPILE_FLAGS_ERROR([-Wc++11-compat]) - _APPEND_COMPILE_FLAGS_ERROR([-Wunused]) - _APPEND_COMPILE_FLAGS_ERROR([-Wunused-result]) - _APPEND_COMPILE_FLAGS_ERROR([-Wunused-variable]) - _APPEND_COMPILE_FLAGS_ERROR([-Wwrite-strings]) - _APPEND_COMPILE_FLAGS_ERROR([-Wformat-security]) - _APPEND_COMPILE_FLAGS_ERROR([-floop-parallelize-all]) - _APPEND_COMPILE_FLAGS_ERROR([-fwrapv]) - _APPEND_COMPILE_FLAGS_ERROR([-fmudflapt]) + _APPEND_COMPILE_FLAGS_ERROR([-Wno-attributes]) + _APPEND_COMPILE_FLAGS_ERROR([-Waddress]) + _APPEND_COMPILE_FLAGS_ERROR([-Warray-bounds]) + _APPEND_COMPILE_FLAGS_ERROR([-Wchar-subscripts]) + _APPEND_COMPILE_FLAGS_ERROR([-Wcomment]) + _APPEND_COMPILE_FLAGS_ERROR([-Wctor-dtor-privacy]) + _APPEND_COMPILE_FLAGS_ERROR([-Wfloat-equal]) + _APPEND_COMPILE_FLAGS_ERROR([-Wformat=2]) + _APPEND_COMPILE_FLAGS_ERROR([-Wmaybe-uninitialized]) + _APPEND_COMPILE_FLAGS_ERROR([-Wmissing-field-initializers]) + _APPEND_COMPILE_FLAGS_ERROR([-Wlogical-op]) + _APPEND_COMPILE_FLAGS_ERROR([-Wnon-virtual-dtor]) + _APPEND_COMPILE_FLAGS_ERROR([-Wnormalized=id]) + _APPEND_COMPILE_FLAGS_ERROR([-Woverloaded-virtual]) + _APPEND_COMPILE_FLAGS_ERROR([-Wpointer-arith]) + AS_IF([test "x$MINGW" = xyes], + [_APPEND_COMPILE_FLAGS_ERROR([-Wno-suggest-attribute=const]) + _APPEND_COMPILE_FLAGS_ERROR([-Wno-missing-noreturn]) + _APPEND_COMPILE_FLAGS_ERROR([-Wmissing-noreturn]) + _APPEND_COMPILE_FLAGS_ERROR([-Wno-suggest-attribute=noreturn]) + _APPEND_COMPILE_FLAGS_ERROR([-Wno-error=suggest-attribute=noreturn]) + _APPEND_COMPILE_FLAGS_ERROR([-Wno-redundant-decls])], + [_APPEND_COMPILE_FLAGS_ERROR([-Wredundant-decls])]) + _APPEND_COMPILE_FLAGS_ERROR([-Wshadow]) + _APPEND_COMPILE_FLAGS_ERROR([-Wshorten-64-to-32]) + _APPEND_COMPILE_FLAGS_ERROR([-Wsign-compare]) + _APPEND_COMPILE_FLAGS_ERROR([-Wstrict-overflow=1]) + _APPEND_COMPILE_FLAGS_ERROR([-Wswitch-enum]) + _APPEND_COMPILE_FLAGS_ERROR([-Wundef]) + _APPEND_COMPILE_FLAGS_ERROR([-Wc++11-compat]) + _APPEND_COMPILE_FLAGS_ERROR([-Wunused]) + _APPEND_COMPILE_FLAGS_ERROR([-Wunused-result]) + _APPEND_COMPILE_FLAGS_ERROR([-Wunused-variable]) + _APPEND_COMPILE_FLAGS_ERROR([-Wwrite-strings]) + _APPEND_COMPILE_FLAGS_ERROR([-Wformat-security]) + _APPEND_COMPILE_FLAGS_ERROR([-floop-parallelize-all]) + _APPEND_COMPILE_FLAGS_ERROR([-fwrapv]) + _APPEND_COMPILE_FLAGS_ERROR([-fmudflapt]) + _APPEND_COMPILE_FLAGS_ERROR([-pipe]) - AS_IF([test "x$ax_enable_debug" = xno], - [AS_IF([test "x$ac_cv_vcs_checkout" = xyes], - [_APPEND_COMPILE_FLAGS_ERROR([-fstack-check]) - AS_IF([test "x$ac_c_gcc_recent" = xyes], - [_APPEND_COMPILE_FLAGS_ERROR([-D_FORTIFY_SOURCE=2]) - _APPEND_COMPILE_FLAGS_ERROR([-Wstack-protector]) - _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector]) - _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector-all]) - ])])]) + AS_IF([test "x$ax_enable_debug" = xno], + [AS_IF([test "x$ac_cv_vcs_checkout" = xyes], + [_APPEND_COMPILE_FLAGS_ERROR([-fstack-check]) + AS_IF([test "x$ac_c_gcc_recent" = xyes], + [_APPEND_COMPILE_FLAGS_ERROR([-D_FORTIFY_SOURCE=2]) +# _APPEND_COMPILE_FLAGS_ERROR([-Wstack-protector]) + _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector]) +# _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector-all]) + ])])]) - AS_IF([test "x$ac_cv_warnings_as_errors" = xyes], - [AX_APPEND_FLAG([-Werror])]) - AC_LANG_POP([C++]) + AS_IF([test "x$ac_cv_warnings_as_errors" = xyes], + [AX_APPEND_FLAG([-Werror])]) + AC_LANG_POP([C++]) ]) - AC_DEFUN([_CC_OTHER_FLAGS], - [AC_REQUIRE([_APPEND_COMPILE_FLAGS_ERROR]) - - AC_LANG_PUSH([C]) - _APPEND_COMPILE_FLAGS_ERROR([-pipe]) - AC_LANG_POP([C]) - ]) - # All of the heavy lifting happens in _HARDEN_LINKER_FLAGS, -# _HARDEN_CC_COMPILER_FLAGS, _HARDEN_CXX_COMPILER_FLAGS, _CC_OTHER_FLAGS +# _HARDEN_CC_COMPILER_FLAGS, _HARDEN_CXX_COMPILER_FLAGS AC_DEFUN([AX_HARDEN_COMPILER_FLAGS], [AC_PREREQ([2.63])dnl AC_REQUIRE([_WARNINGS_AS_ERRORS]) @@ -262,5 +260,4 @@ AC_DEFUN([_HARDEN_CXX_COMPILER_FLAGS], AC_REQUIRE([_HARDEN_LINKER_FLAGS]) AC_REQUIRE([_HARDEN_CC_COMPILER_FLAGS]) AC_REQUIRE([_HARDEN_CXX_COMPILER_FLAGS]) - AC_REQUIRE([_CC_OTHER_FLAGS]) ]) diff --git a/tests/cli.am b/tests/cli.am index 2847de90..bc0d9a06 100644 --- a/tests/cli.am +++ b/tests/cli.am @@ -79,6 +79,12 @@ tests_memslap_LDADD= libtest/libtest.la $(TESTS_LDADDS) check_PROGRAMS+= tests/memslap noinst_PROGRAMS+= tests/memslap +test-memslap: tests/memslap + @tests/memslap + +gdb-memslap: tests/memslap + @$(GDB_COMMAND) tests/memslap + tests_memdump_SOURCES= tests/memdump.cc tests_memdump_CXXFLAGS= $(AM_CXXFLAGS) $(NO_EFF_CXX) EXTRA_tests_memdump_DEPENDENCIES= clients/memdump diff --git a/tests/libmemcached-1.0/all_tests.h b/tests/libmemcached-1.0/all_tests.h index 18a55f97..fe28e733 100644 --- a/tests/libmemcached-1.0/all_tests.h +++ b/tests/libmemcached-1.0/all_tests.h @@ -403,9 +403,11 @@ test_st virtual_bucket_tests[] ={ {0, 0, (test_callback_fn*)0} }; -test_st memcached_server_add_tests[] ={ +test_st memcached_server_add_TESTS[] ={ {"memcached_server_add(\"\")", false, (test_callback_fn*)memcached_server_add_empty_test }, {"memcached_server_add(NULL)", false, (test_callback_fn*)memcached_server_add_null_test }, + {"memcached_server_add(many)", false, (test_callback_fn*)memcached_server_many_TEST }, + {"memcached_server_add(many weighted)", false, (test_callback_fn*)memcached_server_many_weighted_TEST }, {0, 0, (test_callback_fn*)0} }; @@ -444,7 +446,9 @@ collection_st collection[] ={ {"basic", 0, 0, basic_tests}, {"hsieh_availability", 0, 0, hsieh_availability}, {"murmur_availability", 0, 0, murmur_availability}, - {"memcached_server_add", 0, 0, memcached_server_add_tests}, + {"memcached_server_add", (test_callback_fn*)memcached_servers_reset_SETUP, 0, memcached_server_add_TESTS}, + {"memcached_server_add(MEMCACHED_DISTRIBUTION_CONSISTENT)", (test_callback_fn*)memcached_servers_reset_MEMCACHED_DISTRIBUTION_CONSISTENT_SETUP, 0, memcached_server_add_TESTS}, + {"memcached_server_add(MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED)", (test_callback_fn*)memcached_servers_reset_MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED_SETUP, 0, memcached_server_add_TESTS}, {"block", 0, 0, tests}, {"binary", (test_callback_fn*)pre_binary, 0, tests}, {"nonblock", (test_callback_fn*)pre_nonblock, 0, tests}, diff --git a/tests/libmemcached-1.0/sasl.cc b/tests/libmemcached-1.0/sasl.cc index b85d3277..9b398528 100644 --- a/tests/libmemcached-1.0/sasl.cc +++ b/tests/libmemcached-1.0/sasl.cc @@ -47,10 +47,11 @@ using namespace libtest; static test_return_t pre_sasl(memcached_st *) { - if (LIBMEMCACHED_WITH_SASL_SUPPORT == 0) - { - return TEST_SKIPPED; - } + SKIP_IF(true); +#if 0 + SKIP_IF_(true, "currently we are not testing sasl support"); +#endif + SKIP_IF(LIBMEMCACHED_WITH_SASL_SUPPORT == 0); return TEST_SUCCESS; } diff --git a/tests/libmemcached-1.0/server_add.cc b/tests/libmemcached-1.0/server_add.cc index 6539df06..495a7717 100644 --- a/tests/libmemcached-1.0/server_add.cc +++ b/tests/libmemcached-1.0/server_add.cc @@ -36,7 +36,9 @@ */ #include -#include +#include + +#include using namespace libtest; @@ -44,24 +46,60 @@ using namespace libtest; #include -test_return_t memcached_server_add_null_test(memcached_st*) +static std::string random_hostname() { - memcached_st *memc= memcached_create(NULL); + libtest::vchar_t hostname; + libtest::vchar::make(hostname, 23); + libtest::vchar::append(hostname, ".com"); - test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, NULL, 0)); + return std::string(&hostname[0]); +} - memcached_free(memc); +test_return_t memcached_server_add_null_test(memcached_st* memc) +{ + ASSERT_EQ(0, memcached_server_count(memc)); + + test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, NULL, 0)); return TEST_SUCCESS; } -test_return_t memcached_server_add_empty_test(memcached_st*) +test_return_t memcached_server_add_empty_test(memcached_st* memc) { - memcached_st *memc= memcached_create(NULL); + ASSERT_EQ(0, memcached_server_count(memc)); test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, "", 0)); - memcached_free(memc); + return TEST_SUCCESS; +} + +test_return_t memcached_server_many_TEST(memcached_st* memc) +{ + ASSERT_EQ(0, memcached_server_count(memc)); + + in_port_t base_port= 5555; + for (in_port_t x= 0; x < 100; ++x) + { + std::string hostname(random_hostname()); + ASSERT_TRUE(hostname.size()); + test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, hostname.c_str(), base_port +x)); + } + + return TEST_SUCCESS; +} + +test_return_t memcached_server_many_weighted_TEST(memcached_st* memc) +{ + SKIP_IF(true); + ASSERT_EQ(0, memcached_server_count(memc)); + + in_port_t base_port= 5555; + for (in_port_t x= 0; x < 100; ++x) + { + std::string hostname(random_hostname()); + ASSERT_TRUE(hostname.size()); + test_compare(MEMCACHED_SUCCESS, memcached_server_add_with_weight(memc, hostname.c_str(), base_port +x, random() % 10)); + } return TEST_SUCCESS; } diff --git a/tests/libmemcached-1.0/setup_and_teardowns.cc b/tests/libmemcached-1.0/setup_and_teardowns.cc index 6655cb57..4191c384 100644 --- a/tests/libmemcached-1.0/setup_and_teardowns.cc +++ b/tests/libmemcached-1.0/setup_and_teardowns.cc @@ -170,6 +170,34 @@ test_return_t pre_hash_fnv1a_32(memcached_st *memc) return TEST_SUCCESS; } +test_return_t memcached_servers_reset_SETUP(memcached_st *memc) +{ + memcached_servers_reset(memc); + test_compare(0U, memcached_server_count(memc)); + return TEST_SUCCESS; +} + +test_return_t memcached_servers_reset_MEMCACHED_DISTRIBUTION_CONSISTENT_SETUP(memcached_st *memc) +{ + test_compare(TEST_SUCCESS, memcached_servers_reset_SETUP(memc)); + + test_compare(MEMCACHED_SUCCESS, memcached_behavior_set_distribution(memc, MEMCACHED_DISTRIBUTION_CONSISTENT)); + test_compare(memcached_behavior_get_distribution(memc), MEMCACHED_DISTRIBUTION_CONSISTENT); + + return TEST_SUCCESS; +} + +test_return_t memcached_servers_reset_MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED_SETUP(memcached_st *memc) +{ + test_compare(TEST_SUCCESS, memcached_servers_reset_SETUP(memc)); + ASSERT_EQ(0U, memcached_server_count(0)); + + test_compare(MEMCACHED_SUCCESS, memcached_behavior_set_distribution(memc, MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED)); + test_compare(memcached_behavior_get_distribution(memc), MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED); + + return TEST_SUCCESS; +} + test_return_t pre_behavior_ketama(memcached_st *memc) { test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA, 1)); diff --git a/tests/libmemcached-1.0/setup_and_teardowns.h b/tests/libmemcached-1.0/setup_and_teardowns.h index 655cab44..7610c5a6 100644 --- a/tests/libmemcached-1.0/setup_and_teardowns.h +++ b/tests/libmemcached-1.0/setup_and_teardowns.h @@ -61,3 +61,6 @@ test_return_t pre_replication_noblock(memcached_st*); test_return_t pre_settimer(memcached_st*); test_return_t pre_unix_socket(memcached_st*); test_return_t pre_buffer(memcached_st*); +test_return_t memcached_servers_reset_MEMCACHED_DISTRIBUTION_CONSISTENT_SETUP(memcached_st *memc); +test_return_t memcached_servers_reset_MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED_SETUP(memcached_st *memc); +test_return_t memcached_servers_reset_SETUP(memcached_st *memc); diff --git a/tests/libmemcached-1.0/stat.cc b/tests/libmemcached-1.0/stat.cc index 60318790..f92c88e5 100644 --- a/tests/libmemcached-1.0/stat.cc +++ b/tests/libmemcached-1.0/stat.cc @@ -57,10 +57,7 @@ static memcached_return_t item_counter(memcached_server_instance_st , { uint64_t* counter= (uint64_t*)context; unsigned long number_value= strtoul(value, (char **)NULL, 10); - if (number_value == ULONG_MAX) - { - return MEMCACHED_FAILURE; - } + ASSERT_NEQ(number_value, ULONG_MAX); *counter= *counter +number_value; } @@ -85,10 +82,9 @@ test_return_t memcached_stat_TEST2(memcached_st *memc) for (uint32_t x= 0; x < memcached_dump_TEST2_COUNT; x++) { char key[1024]; - int length= snprintf(key, sizeof(key), "%s%u", __func__, x); - test_true(length > 0); + ASSERT_TRUE(length > 0); test_compare(MEMCACHED_SUCCESS, memcached_set(memc, key, length, @@ -98,9 +94,9 @@ test_return_t memcached_stat_TEST2(memcached_st *memc) memcached_quit(memc); uint64_t counter= 0; - test_compare(MEMCACHED_SUCCESS, - memcached_stat_execute(memc, NULL, item_counter, &counter)); - test_true(counter); + ASSERT_EQ(MEMCACHED_SUCCESS, + memcached_stat_execute(memc, NULL, item_counter, &counter)); + ASSERT_TRUE(counter); return TEST_SUCCESS; } diff --git a/tests/runner.h b/tests/runner.h index 9ec65c06..17bf55a6 100644 --- a/tests/runner.h +++ b/tests/runner.h @@ -86,14 +86,7 @@ private: if (func) { test_true(container); - try { - ret= func(&memc); - } - catch (std::exception& e) - { - libtest::Error << e.what(); - ret= TEST_FAILURE; - } + ret= func(&memc); } return ret; diff --git a/tests/server_add.h b/tests/server_add.h index 53ced524..06d58356 100644 --- a/tests/server_add.h +++ b/tests/server_add.h @@ -39,3 +39,5 @@ test_return_t memcached_server_add_null_test(memcached_st*); test_return_t memcached_server_add_empty_test(memcached_st*); +test_return_t memcached_server_many_TEST(memcached_st*); +test_return_t memcached_server_many_weighted_TEST(memcached_st*);