diff options
author | Continuous Integration <ci@tangent.org> | 2013-10-11 05:21:07 -0700 |
---|---|---|
committer | Continuous Integration <ci@tangent.org> | 2013-10-11 05:21:07 -0700 |
commit | d3f419f76d3125a6da9fe6d803d5f90287d32aa4 (patch) | |
tree | 3817b4b10fbee6edb76bd228d40a7135020b2544 | |
parent | cb732fbfe29edb687a5380f8336ef69227469b08 (diff) | |
parent | acac711318a06661a8866f7e970a199fa21d4d83 (diff) | |
download | libmemcached-d3f419f76d3125a6da9fe6d803d5f90287d32aa4.tar.gz |
Merge lp:~brianaker/libmemcached/merge-of-1.0 Build: jenkins-Libmemcached-372
39 files changed, 436 insertions, 308 deletions
diff --git a/bootstrap.sh b/bootstrap.sh index 06b01c54..d5ff44b4 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -420,10 +420,6 @@ run_configure () ret=1; # If we are executing on OSX use CLANG, otherwise only use it if we find it in the ENV case $HOST_OS in - *-darwin-*) - run CC=clang CXX=clang++ $top_srcdir/configure "$BUILD_CONFIGURE_ARG" || die "Cannot execute CC=clang CXX=clang++ configure $BUILD_CONFIGURE_ARG" - ret=$? - ;; rhel-5*) command_exists 'gcc44' || die "Could not locate gcc44" run CC=gcc44 CXX=gcc44 $top_srcdir/configure "$BUILD_CONFIGURE_ARG" || die "Cannot execute CC=gcc44 CXX=gcc44 configure $BUILD_CONFIGURE_ARG" @@ -793,18 +789,14 @@ make_for_clang_analyzer () CC=clang CXX=clang++ export CC CXX + CONFIGURE='scan-build ./configure' CONFIGURE_ARGS='--enable-debug' - make_skeleton - ret=$? - - make_target 'clean' 'warn' + run_configure scan-build -o clang-html make -j4 -k restore_BUILD - - return $ret } # If we are locally testing, we should make sure the environment is setup correctly @@ -1010,6 +1002,9 @@ make_rpm () { if command_exists 'rpmbuild'; then if [ -f 'rpm.am' -o -d 'rpm' ]; then + mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} + mkdir -p ~/rpmbuild/RPMS/{i386,i486,i586,i686,noarch,athlon} + run_configure_if_required make_target 'rpm' @@ -1507,6 +1502,9 @@ check_make_target() execute_job () { + # We should always have a target by this point + assert MAKE_TARGET + determine_target_platform determine_vcs @@ -1518,10 +1516,6 @@ execute_job () return 1 fi - if [ -z "$MAKE_TARGET" ]; then - MAKE_TARGET="make_default" - fi - if $print_setup_opt -o $debug; then echo print_setup @@ -1541,9 +1535,6 @@ execute_job () PREFIX_ARG="--prefix=$PREFIX" fi - # We should always have a target by this point - assert MAKE_TARGET - if $CLEAN_OPTION; then make_maintainer_clean fi @@ -1762,6 +1753,13 @@ main () fi fi + if [ -z "$MAKE_TARGET" ]; then + MAKE_TARGET="make_default" + fi + + # We should always have a target by this point + assert MAKE_TARGET + execute_job local ret=$? diff --git a/clients/generator.cc b/clients/generator.cc index df805153..1f40daed 100644 --- a/clients/generator.cc +++ b/clients/generator.cc @@ -22,6 +22,8 @@ #include "clients/generator.h" +#define KEY_BYTES 20 + /* Use this for string generation */ static const char ALPHANUMERICS[]= "0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz"; @@ -75,13 +77,13 @@ pairs_st *pairs_generate(uint64_t number_of, size_t value_length) for (uint64_t x= 0; x < number_of; x++) { - pairs[x].key= (char *)calloc(100, sizeof(char)); + pairs[x].key= (char *)calloc(KEY_BYTES, sizeof(char)); if (pairs[x].key == NULL) goto error; - get_random_string(pairs[x].key, 100); - pairs[x].key_length= 100; + get_random_string(pairs[x].key, KEY_BYTES); + pairs[x].key_length= KEY_BYTES; if (value_length) { diff --git a/clients/memcp.cc b/clients/memcp.cc index 1b97ef4a..27aa2f81 100644 --- a/clients/memcp.cc +++ b/clients/memcp.cc @@ -1,5 +1,5 @@ /* LibMemcached - * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/ + * Copyright (C) 2011-2013 Data Differential, http://datadifferential.com/ * Copyright (C) 2006-2009 Brian Aker * All rights reserved. * diff --git a/clients/memslap.cc b/clients/memslap.cc index 30cc07f6..cc2e2e37 100644 --- a/clients/memslap.cc +++ b/clients/memslap.cc @@ -66,6 +66,8 @@ #define DEFAULT_EXECUTE_NUMBER 10000 #define DEFAULT_CONCURRENCY 1 +#define VALUE_BYTES 4096 + #define PROGRAM_NAME "memslap" #define PROGRAM_DESCRIPTION "Generates a load against a memcached custer of servers." @@ -336,7 +338,7 @@ void scheduler(memcached_server_st *servers, conclusions_st *conclusion) if (opt_test == SET_TEST) { - context->execute_pairs= pairs_generate(opt_execute_number, 400); + context->execute_pairs= pairs_generate(opt_execute_number, VALUE_BYTES); context->execute_number= opt_execute_number; } @@ -432,7 +434,7 @@ void options_parse(int argc, char *argv[]) break; case OPT_DEBUG: /* --debug or -d */ - opt_verbose = OPT_DEBUG; + opt_verbose= OPT_DEBUG; break; case OPT_VERSION: /* --version or -V */ @@ -566,7 +568,7 @@ pairs_st *load_create_data(memcached_st *memc, unsigned int number_of, /* We always used non-blocking IO for load since it is faster */ memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NO_BLOCK, 0); - pairs_st *pairs= pairs_generate(number_of, 400); + pairs_st *pairs= pairs_generate(number_of, VALUE_BYTES); *actual_loaded= execute_set(memc_clone, pairs, number_of); memcached_free(memc_clone); diff --git a/clients/memtouch.cc b/clients/memtouch.cc index 4b1ebcdc..ffd2c70d 100644 --- a/clients/memtouch.cc +++ b/clients/memtouch.cc @@ -24,7 +24,7 @@ #include "clients/utilities.h" #define PROGRAM_NAME "memtouch" -#define PROGRAM_DESCRIPTION "Update the expiration value of an alreasy existing value in the sever" +#define PROGRAM_DESCRIPTION "Update the expiration value of an already existing value in the server" /* Prototypes */ diff --git a/clients/ms_setting.h b/clients/ms_setting.h index ec060c41..4bab2b99 100644 --- a/clients/ms_setting.h +++ b/clients/ms_setting.h @@ -47,7 +47,7 @@ typedef struct token_s #define MAX_TOKENS 10 /* server information */ -typedef struct mcd_sever +typedef struct mcd_server { char srv_host_name[MCD_HOST_LENGTH]; /* host name of server */ int srv_port; /* server port */ diff --git a/docs/memcached_auto.rst b/docs/memcached_auto.rst index c3f4c7f5..0f78e6e7 100644 --- a/docs/memcached_auto.rst +++ b/docs/memcached_auto.rst @@ -53,7 +53,8 @@ MEMCACHED_EXPIRATION_NOT_ADD, the operation will fail. For all other expiration values, the operation will succeed by seeding the value for that key with a initial value to expire with the provided expiration time. The flags will be set to zero.The value is then returned via the uint32_t -value pointer you pass to it. +value pointer you pass to it. memcached_increment_with_initial is only available +when using the binary protocol. memcached_decrement_with_initial takes a key and keylength and decrements the value by the offset passed to it. If the object specified by key does @@ -62,7 +63,8 @@ MEMCACHED_EXPIRATION_NOT_ADD, the operation will fail. For all other expiration values, the operation will succeed by seeding the value for that key with a initial value to expire with the provided expiration time. The flags will be set to zero.The value is then returned via the uint32_t -value pointer you pass to it. +value pointer you pass to it. memcached_decrement_with_initial is only available +when using the binary protocol. :c:func:`memcached_increment_by_key`, :c:func:`memcached_decrement_by_key`, :c:func:`memcached_increment_with_initial_by_key`, and diff --git a/libmemcached-1.2/deprecated_types.h b/libmemcached-1.2/deprecated_types.h index 716d3e44..0a6df654 100644 --- a/libmemcached-1.2/deprecated_types.h +++ b/libmemcached-1.2/deprecated_types.h @@ -57,4 +57,5 @@ typedef memcached_server_fn memcached_server_function; typedef memcached_trigger_key_fn memcached_trigger_key; typedef memcached_trigger_delete_key_fn memcached_trigger_delete_key; typedef memcached_dump_fn memcached_dump_func; +typedef memcached_instance_st *memcached_server_instance_st; diff --git a/libmemcached/auto.cc b/libmemcached/auto.cc index 111445fb..8d0d8007 100644 --- a/libmemcached/auto.cc +++ b/libmemcached/auto.cc @@ -57,8 +57,13 @@ static void auto_response(memcached_instance_st* instance, const bool reply, me assert(memcached_last_error(instance->root) != MEMCACHED_SUCCESS); *value= UINT64_MAX; } + else if (memcached_failed(rc)) + { + *value= UINT64_MAX; + } else { + assert(memcached_last_error(instance->root) != MEMCACHED_NOTFOUND); *value= instance->root->result.impl()->numeric_value; } } diff --git a/libmemcached/connect.cc b/libmemcached/connect.cc index 168d34a3..176fa153 100644 --- a/libmemcached/connect.cc +++ b/libmemcached/connect.cc @@ -76,7 +76,7 @@ static memcached_return_t connect_poll(memcached_instance_st* server, const int if (server->root->poll_timeout == 0) { return memcached_set_error(*server, MEMCACHED_TIMEOUT, MEMCACHED_AT, - memcached_literal_param("The time to wait for a connection to be established was set to zero, which means it will always timeout (MEMCACHED_TIMEOUT).")); + memcached_literal_param("The time to wait for a connection to be established was set to zero which produces a timeout to every call to poll().")); } while (--loop_max) // Should only loop on cases of ERESTART or EINTR diff --git a/libmemcached/error.cc b/libmemcached/error.cc index 266f78b5..ab17926e 100644 --- a/libmemcached/error.cc +++ b/libmemcached/error.cc @@ -36,6 +36,9 @@ */ #include <libmemcached/common.h> + +#include "libmemcached/assert.hpp" + #include <cerrno> #include <cstdarg> #include <cstdio> @@ -87,112 +90,134 @@ static void _set(Memcached& memc, memcached_string_t *str, memcached_return_t &r memcached_error_free(memc); } - // For memory allocation we use our error since it is a bit more specific - if (local_errno == ENOMEM and rc == MEMCACHED_ERRNO) + if (memcached_fatal(rc) or rc == MEMCACHED_CLIENT_ERROR) { - rc= MEMCACHED_MEMORY_ALLOCATION_FAILURE; - } + // For memory allocation we use our error since it is a bit more specific + if (local_errno == ENOMEM and rc == MEMCACHED_ERRNO) + { + rc= MEMCACHED_MEMORY_ALLOCATION_FAILURE; + } - if (rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE) - { - local_errno= ENOMEM; - } + if (rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE) + { + local_errno= ENOMEM; + } - if (rc == MEMCACHED_ERRNO and not local_errno) - { - local_errno= errno; - rc= MEMCACHED_ERRNO; - } + if (rc == MEMCACHED_ERRNO and not local_errno) + { + local_errno= errno; + rc= MEMCACHED_ERRNO; + } - if (rc == MEMCACHED_ERRNO and local_errno == ENOTCONN) - { - rc= MEMCACHED_CONNECTION_FAILURE; - } + if (rc == MEMCACHED_ERRNO and local_errno == ENOTCONN) + { + rc= MEMCACHED_CONNECTION_FAILURE; + } - if (rc == MEMCACHED_ERRNO and local_errno == ECONNRESET) - { - rc= MEMCACHED_CONNECTION_FAILURE; - } + if (rc == MEMCACHED_ERRNO and local_errno == ECONNRESET) + { + rc= MEMCACHED_CONNECTION_FAILURE; + } - if (local_errno == EINVAL) - { - rc= MEMCACHED_INVALID_ARGUMENTS; - } + if (local_errno == EINVAL) + { + rc= MEMCACHED_INVALID_ARGUMENTS; + } - if (local_errno == ECONNREFUSED) - { - rc= MEMCACHED_CONNECTION_FAILURE; - } + if (local_errno == ECONNREFUSED) + { + rc= MEMCACHED_CONNECTION_FAILURE; + } - memcached_error_t *error= libmemcached_xmalloc(&memc, memcached_error_t); - if (error == NULL) // Bad business if this happens - { - return; - } + if (rc == MEMCACHED_TIMEOUT) + { + } - error->root= &memc; - error->query_id= memc.query_id; - error->rc= rc; - error->local_errno= local_errno; + memcached_error_t *error= libmemcached_xmalloc(&memc, memcached_error_t); + if (error == NULL) // Bad business if this happens + { + assert_msg(error, "libmemcached_xmalloc() failed to allocate a memcached_error_t"); + return; + } - const char *errmsg_ptr; - char errmsg[MAX_ERROR_LENGTH]; - errmsg[0]= 0; - errmsg_ptr= errmsg; + error->root= &memc; + error->query_id= memc.query_id; + error->rc= rc; + error->local_errno= local_errno; + + // MEMCACHED_CLIENT_ERROR is a special case because it is an error coming from the server + if (rc == MEMCACHED_CLIENT_ERROR) + { + assert(str); + assert(str->size); + if (str and str->size) + { + assert(error->local_errno == 0); + error->local_errno= 0; + + error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %.*s", + error->root, + int(str->size), str->c_str); + } + } + else if (local_errno) + { + const char *errmsg_ptr; + char errmsg[MAX_ERROR_LENGTH]; + errmsg[0]= 0; + errmsg_ptr= errmsg; - if (local_errno) - { #if defined(STRERROR_R_CHAR_P) && STRERROR_R_CHAR_P - errmsg_ptr= strerror_r(local_errno, errmsg, sizeof(errmsg)); + errmsg_ptr= strerror_r(local_errno, errmsg, sizeof(errmsg)); #elif defined(HAVE_STRERROR_R) && HAVE_STRERROR_R - strerror_r(local_errno, errmsg, sizeof(errmsg)); - errmsg_ptr= errmsg; + strerror_r(local_errno, errmsg, sizeof(errmsg)); + errmsg_ptr= errmsg; #elif defined(HAVE_STRERROR) && HAVE_STRERROR - snprintf(errmsg, sizeof(errmsg), "%s", strerror(local_errno)); - errmsg_ptr= errmsg; + snprintf(errmsg, sizeof(errmsg), "%s", strerror(local_errno)); + errmsg_ptr= errmsg; #endif - } + if (str and str->size and local_errno) + { + error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s(%s), %.*s -> %s", + error->root, + memcached_strerror(&memc, rc), + errmsg_ptr, + memcached_string_printf(*str), at); + } + else + { + error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s(%s) -> %s", + error->root, + memcached_strerror(&memc, rc), + errmsg_ptr, + at); + } + } + else if (rc == MEMCACHED_PARSE_ERROR and str and str->size) + { + error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %.*s -> %s", + error->root, + int(str->size), str->c_str, at); + } + else if (str and str->size) + { + error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s, %.*s -> %s", + error->root, + memcached_strerror(&memc, rc), + int(str->size), str->c_str, at); + } + else + { + error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s -> %s", + error->root, + memcached_strerror(&memc, rc), at); + } - if (str and str->size and local_errno) - { - error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s(%s), %.*s -> %s", - error->root, - memcached_strerror(&memc, rc), - errmsg_ptr, - memcached_string_printf(*str), at); - } - else if (local_errno) - { - error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s(%s) -> %s", - error->root, - memcached_strerror(&memc, rc), - errmsg_ptr, - at); - } - else if (rc == MEMCACHED_PARSE_ERROR and str and str->size) - { - error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %.*s -> %s", - error->root, - int(str->size), str->c_str, at); - } - else if (str and str->size) - { - error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s, %.*s -> %s", - error->root, - memcached_strerror(&memc, rc), - int(str->size), str->c_str, at); - } - else - { - error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s -> %s", - error->root, - memcached_strerror(&memc, rc), at); + error->next= memc.error_messages; + memc.error_messages= error; } - error->next= memc.error_messages; - memc.error_messages= error; - #if 0 if (error_log_fd == -1) { @@ -231,13 +256,11 @@ memcached_return_t memcached_set_error(memcached_instance_st& self, memcached_re memcached_return_t memcached_set_error(Memcached& memc, memcached_return_t rc, const char *at, memcached_string_t& str) { assert_msg(rc != MEMCACHED_ERRNO, "Programmer error, MEMCACHED_ERRNO was set to be returned to client"); - if (memcached_fatal(rc) == false) + if (memcached_fatal(rc)) { - return rc; + _set(memc, &str, rc, at); } - _set(memc, &str, rc, at); - return rc; } @@ -299,17 +322,15 @@ memcached_return_t memcached_set_error(memcached_instance_st& self, memcached_re memcached_string_t error_host= { hostname_port_message, size_t(size) }; assert_msg(self.root, "Programmer error, root was not set on instance"); - if (self.root == NULL) + if (self.root) { - return rc; + _set(*self.root, &error_host, rc, at); + _set(self, (*self.root)); + assert(self.error_messages); + assert(self.root->error_messages); + assert(self.error_messages->rc == self.root->error_messages->rc); } - _set(*self.root, &error_host, rc, at); - _set(self, (*self.root)); - assert(self.root->error_messages); - assert(self.error_messages); - assert(self.error_messages->rc == self.root->error_messages->rc); - return rc; } @@ -326,14 +347,12 @@ memcached_return_t memcached_set_error(memcached_instance_st& self, memcached_re memcached_string_t error_host= { hostname_port, size}; - if (self.root == NULL) + if (self.root) { - return rc; + _set(*self.root, &error_host, rc, at); + _set(self, *self.root); } - _set(*self.root, &error_host, rc, at); - _set(self, *self.root); - return rc; } @@ -528,7 +547,7 @@ const char *memcached_last_error_message(const memcached_st *shell) { if (memc->error_messages) { - if (memc->error_messages->size == 0) + if (memc->error_messages->size and memc->error_messages->message[0]) { return memc->error_messages->message; } diff --git a/libmemcached/get.cc b/libmemcached/get.cc index 65a1dcad..1bdb819a 100644 --- a/libmemcached/get.cc +++ b/libmemcached/get.cc @@ -114,7 +114,6 @@ char *memcached_get_by_key(memcached_st *shell, { *error= MEMCACHED_NOTFOUND; } - if (value == NULL) { if (ptr->get_key_failure and *error == MEMCACHED_NOTFOUND) @@ -221,12 +220,14 @@ static memcached_return_t __mget_by_key_real(memcached_st *ptr, if (number_of_keys == 0) { - return memcached_set_error(*ptr, MEMCACHED_NOTFOUND, MEMCACHED_AT, memcached_literal_param("number_of_keys was zero")); + return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Numbers of keys provided was zero")); } - if (memcached_failed(memcached_key_test(*ptr, keys, key_length, number_of_keys))) + if (memcached_failed((rc= memcached_key_test(*ptr, keys, key_length, number_of_keys)))) { - return memcached_last_error(ptr); + assert(memcached_last_error(ptr) == rc); + + return rc; } bool is_group_key_set= false; @@ -463,6 +464,11 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, bool flush= (number_of_keys == 1); + if (memcached_failed(rc= memcached_key_test(*ptr, keys, key_length, number_of_keys))) + { + return rc; + } + /* If a server fails we warn about errors and start all over with sending keys to the server. @@ -502,10 +508,13 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETK; } +#if 0 { memcached_return_t vk= memcached_validate_key_length(key_length[x], ptr->flags.binary_protocol); - if (vk != MEMCACHED_SUCCESS) + if (memcached_failed(rc= memcached_key_test(*memc, (const char **)&key, &key_length, 1))) { + memcached_set_error(ptr, vk, MEMCACHED_AT, memcached_literal_param("Key was too long.")); + if (x > 0) { memcached_io_reset(instance); @@ -514,6 +523,7 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, return vk; } } +#endif request.message.header.request.keylen= htons((uint16_t)(key_length[x] + memcached_array_size(ptr->_namespace))); request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; diff --git a/libmemcached/io.cc b/libmemcached/io.cc index cb8ed5c2..ba4b3474 100644 --- a/libmemcached/io.cc +++ b/libmemcached/io.cc @@ -99,7 +99,7 @@ static bool repack_input_buffer(memcached_instance_st* instance) case EWOULDBLOCK: #endif case EAGAIN: -#ifdef TARGET_OS_LINUX +#ifdef __linux case ERESTART: #endif break; // No IO is fine, we can just move on @@ -265,7 +265,7 @@ static memcached_return_t io_wait(memcached_instance_st* instance, assert_msg(active_fd == -1 , "poll() returned an unexpected value"); switch (local_errno) { -#ifdef TARGET_OS_LINUX +#ifdef __linux case ERESTART: #endif case EINTR: @@ -412,6 +412,11 @@ memcached_return_t memcached_io_wait_for_write(memcached_instance_st* instance) return io_wait(instance, MEM_WRITE); } +memcached_return_t memcached_io_wait_for_read(memcached_instance_st* instance) +{ + return io_wait(instance, MEM_READ); +} + static memcached_return_t _io_fill(memcached_instance_st* instance) { ssize_t data_read; @@ -430,7 +435,7 @@ static memcached_return_t _io_fill(memcached_instance_st* instance) case EWOULDBLOCK: #endif case EAGAIN: -#ifdef TARGET_OS_LINUX +#ifdef __linux case ERESTART: #endif { @@ -568,7 +573,7 @@ memcached_return_t memcached_io_slurp(memcached_instance_st* instance) case EWOULDBLOCK: #endif case EAGAIN: -#ifdef TARGET_OS_LINUX +#ifdef __linux case ERESTART: #endif if (memcached_success(io_wait(instance, MEM_READ))) diff --git a/libmemcached/io.hpp b/libmemcached/io.hpp index f3fed345..5480239f 100644 --- a/libmemcached/io.hpp +++ b/libmemcached/io.hpp @@ -49,7 +49,8 @@ bool memcached_io_writev(memcached_instance_st* ptr, libmemcached_io_vector_st vector[], const size_t number_of, const bool with_flush); -memcached_return_t memcached_io_wait_for_write(memcached_instance_st* ptr); +memcached_return_t memcached_io_wait_for_write(memcached_instance_st*); +memcached_return_t memcached_io_wait_for_read(memcached_instance_st*); void memcached_io_reset(memcached_instance_st* ptr); diff --git a/libmemcached/key.cc b/libmemcached/key.cc index 19d1f957..cec0eece 100644 --- a/libmemcached/key.cc +++ b/libmemcached/key.cc @@ -37,47 +37,71 @@ #include <libmemcached/common.h> +static inline memcached_return_t memcached_validate_key_length(size_t key_length, bool) +{ + if (key_length == 0) + { + return MEMCACHED_BAD_KEY_PROVIDED; + } + + // No one ever reimplemented MEMCACHED to use keys longer then the original ascii length +#if 0 + if (binary) + { + if (key_length > 0xffff) + { + return MEMCACHED_BAD_KEY_PROVIDED; + } + } + else +#endif + { + if (key_length >= MEMCACHED_MAX_KEY) + { + return MEMCACHED_BAD_KEY_PROVIDED; + } + } + + return MEMCACHED_SUCCESS; +} + memcached_return_t memcached_key_test(memcached_st &memc, const char * const *keys, const size_t *key_length, size_t number_of_keys) { + if (number_of_keys == 0) + { + return memcached_set_error(memc, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Numbers of keys provided was zero")); + } + if (keys == NULL or key_length == NULL) { return memcached_set_error(memc, MEMCACHED_BAD_KEY_PROVIDED, MEMCACHED_AT, memcached_literal_param("Key was NULL or length of key was zero.")); } + const bool is_binary= memcached_flag(memc, MEMCACHED_FLAG_BINARY_PROTOCOL); + // If we don't need to verify the key, or we are using the binary protoocol, // we just check the size of the key - if (memc.flags.verify_key == false or memc.flags.binary_protocol == true) - { - for (size_t x= 0; x < number_of_keys; x++) - { - // We should set binary key, but the memcached server is broken for - // longer keys at the moment. - memcached_return_t rc= memcached_validate_key_length(*(key_length +x), false /* memc.flags.binary_protocol */); - if (memcached_failed(rc)) - { - return memcached_set_error(memc, rc, MEMCACHED_AT, memcached_literal_param("Key provided was too long.")); - } - } - - return MEMCACHED_SUCCESS; - } - - for (size_t x= 0; x < number_of_keys; x++) + for (size_t x= 0; x < number_of_keys; ++x) { - memcached_return_t rc= memcached_validate_key_length(*(key_length + x), false); + // We should set binary key, but the memcached server is broken for + // longer keys at the moment. + memcached_return_t rc= memcached_validate_key_length(*(key_length +x), false /* memc.flags.binary_protocol */); if (memcached_failed(rc)) { return memcached_set_error(memc, rc, MEMCACHED_AT, memcached_literal_param("Key provided was too long.")); } - - for (size_t y= 0; y < *(key_length + x); y++) + + if (memc.flags.verify_key and is_binary == false) { - if ((isgraph(keys[x][y])) == 0) + for (size_t y= 0; y < *(key_length +x); ++y) { - return memcached_set_error(memc, MEMCACHED_BAD_KEY_PROVIDED, MEMCACHED_AT, memcached_literal_param("Key provided had invalid character.")); + if ((isgraph(keys[x][y])) == 0) + { + return memcached_set_error(memc, MEMCACHED_BAD_KEY_PROVIDED, MEMCACHED_AT, memcached_literal_param("Key provided had invalid character.")); + } } } } diff --git a/libmemcached/key.hpp b/libmemcached/key.hpp index ddd557d8..811a4b7b 100644 --- a/libmemcached/key.hpp +++ b/libmemcached/key.hpp @@ -41,27 +41,3 @@ memcached_return_t memcached_key_test(memcached_st& memc, const size_t *key_length, size_t number_of_keys); -static inline memcached_return_t memcached_validate_key_length(size_t key_length, bool binary) -{ - if (key_length == 0) - { - return MEMCACHED_BAD_KEY_PROVIDED; - } - - if (binary) - { - if (key_length > 0xffff) - { - return MEMCACHED_BAD_KEY_PROVIDED; - } - } - else - { - if (key_length >= MEMCACHED_MAX_KEY) - { - return MEMCACHED_BAD_KEY_PROVIDED; - } - } - - return MEMCACHED_SUCCESS; -} diff --git a/libmemcached/response.cc b/libmemcached/response.cc index f69046e8..efecbc52 100644 --- a/libmemcached/response.cc +++ b/libmemcached/response.cc @@ -503,6 +503,8 @@ static memcached_return_t binary_read_one_response(memcached_instance_st* instan memcached_return_t rc; protocol_binary_response_header header; + assert(memcached_is_binary(instance->root)); + if ((rc= memcached_safe_read(instance, &header.bytes, sizeof(header.bytes))) != MEMCACHED_SUCCESS) { WATCHPOINT_ERROR(rc); @@ -894,12 +896,19 @@ memcached_return_t memcached_response(memcached_instance_st* instance, return memcached_set_error(*instance, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT); } - /* We may have old commands in the buffer not set, first purge */ + /* We may have old commands in the buffer not sent, first purge */ if ((instance->root->flags.no_block) and (memcached_is_processing_input(instance->root) == false)) { (void)memcached_io_write(instance); } + /* Before going into loop wait to see if we have any IO waiting for us */ + if (0) + { + memcached_return_t read_rc= memcached_io_wait_for_read(instance); + fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, memcached_strerror(NULL, read_rc)); + } + /* * The previous implementation purged all pending requests and just * returned the last one. Purge all pending messages to ensure backwards diff --git a/libmemcached/stats.cc b/libmemcached/stats.cc index d70972ef..180b0d98 100644 --- a/libmemcached/stats.cc +++ b/libmemcached/stats.cc @@ -346,7 +346,7 @@ static memcached_return_t set_data(memcached_stat_st *memc_stat, const char *key return MEMCACHED_SUCCESS; } -char *memcached_stat_get_value(const memcached_st *, memcached_stat_st *memc_stat, +char *memcached_stat_get_value(const memcached_st* shell, memcached_stat_st *memc_stat, const char *key, memcached_return_t *error) { memcached_return_t not_used; @@ -456,13 +456,15 @@ char *memcached_stat_get_value(const memcached_st *, memcached_stat_st *memc_sta } else { - *error= MEMCACHED_NOTFOUND; + Memcached* memc= (Memcached*)memcached2Memcached(shell); + *error= memcached_set_error(*memc, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid key provided")); return NULL; } if (length >= SMALL_STRING_LEN || length < 0) { - *error= MEMCACHED_FAILURE; + Memcached* memc= (Memcached*)memcached2Memcached(shell); + *error= memcached_set_error(*memc, MEMCACHED_FAILURE, MEMCACHED_AT, memcached_literal_param("Internal failure occured with buffer, please report this bug.")); return NULL; } @@ -658,8 +660,7 @@ memcached_stat_st *memcached_stat(memcached_st *shell, char *args, memcached_ret if (args) { args_length= strlen(args); - rc= memcached_validate_key_length(args_length, self->flags.binary_protocol); - if (memcached_failed(rc)) + if (memcached_failed(rc= memcached_key_test(*self, (const char **)&args, &args_length, 1))) { *error= memcached_set_error(*self, rc, MEMCACHED_AT); return NULL; @@ -746,7 +747,7 @@ memcached_return_t memcached_stat_servername(memcached_stat_st *memc_stat, char if (args) { args_length= strlen(args); - rc= memcached_validate_key_length(args_length, memc.flags.binary_protocol); + rc= memcached_key_test(*memc_ptr, (const char **)&args, &args_length, 1); } if (memcached_success(rc)) diff --git a/libmemcached/string.cc b/libmemcached/string.cc index ce96b98c..b821aca6 100644 --- a/libmemcached/string.cc +++ b/libmemcached/string.cc @@ -281,18 +281,20 @@ char *memcached_string_take_value(memcached_string_st *self) { char* value= NULL; - if (memcached_string_length(self)) + assert_msg(self, "Invalid memcached_string_st"); + if (self) { - assert_msg(self, "Invalid memcached_string_st"); - // If we fail at adding the null, we copy and move on - if (memcached_success(memcached_string_append_null(self))) + if (memcached_string_length(self)) { - return memcached_string_c_copy(self); + // If we fail at adding the null, we copy and move on + if (memcached_failed(memcached_string_append_null(self))) + { + return NULL; + } + + value= self->string; + _init_string(self); } - - value= self->string; - - _init_string(self); } return value; diff --git a/libmemcached/touch.cc b/libmemcached/touch.cc index 1f793c55..91d0825f 100644 --- a/libmemcached/touch.cc +++ b/libmemcached/touch.cc @@ -124,9 +124,9 @@ memcached_return_t memcached_touch_by_key(memcached_st *shell, return rc; } - if (memcached_failed(rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol))) + if (memcached_failed(rc= memcached_key_test(*ptr, (const char **)&key, &key_length, 1))) { - return rc; + return memcached_set_error(*ptr, rc, MEMCACHED_AT); } uint32_t server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length); diff --git a/libtest/cmdline.cc b/libtest/cmdline.cc index 88e1fbb4..bb33e4a1 100644 --- a/libtest/cmdline.cc +++ b/libtest/cmdline.cc @@ -359,7 +359,7 @@ bool Application::slurp() int error; switch ((error= errno)) { -#ifdef TARGET_OS_LINUX +#ifdef __linux case ERESTART: #endif case EINTR: diff --git a/libtest/core.cc b/libtest/core.cc index 8e887471..2542f43f 100644 --- a/libtest/core.cc +++ b/libtest/core.cc @@ -42,8 +42,8 @@ namespace libtest { void create_core(void) { -#if defined(TARGET_OS_OSX) && TARGET_OS_OSX - if (TARGET_OS_OSX) +#if defined(__APPLE__) && __APPLE__ + if (__APPLE__) { return; } diff --git a/libtest/main.cc b/libtest/main.cc index 8f83dcc2..79e4f739 100644 --- a/libtest/main.cc +++ b/libtest/main.cc @@ -2,7 +2,7 @@ * * Data Differential YATL (i.e. libtest) library * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ + * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -43,8 +43,11 @@ #include <cstring> #include <ctime> #include <fnmatch.h> -#include <fstream> #include <iostream> +#ifdef HAVE_STRINGS_H +# include <strings.h> +#endif +#include <fstream> #include <memory> #include <sys/stat.h> #include <sys/time.h> @@ -113,7 +116,7 @@ int main(int argc, char *argv[], char* environ_[]) Valgrind does not currently work reliably, or sometimes at all, on OSX - Fri Jun 15 11:24:07 EDT 2012 */ -#if defined(TARGET_OS_OSX) && TARGET_OS_OSX +#if defined(__APPLE__) && __APPLE__ if (valgrind_is_caller()) { return EXIT_SKIP; diff --git a/libtest/unittest.cc b/libtest/unittest.cc index 1a0afdbe..1b1b8076 100644 --- a/libtest/unittest.cc +++ b/libtest/unittest.cc @@ -657,7 +657,7 @@ static test_return_t application_doesnotexist_BINARY(void *) const char *args[]= { "--fubar", 0 }; #if defined(__APPLE__) && __APPLE__ ASSERT_EQ(Application::INVALID_POSIX_SPAWN, true_app.run(args)); -#elif defined(TARGET_OS_FREEBSD) && TARGET_OS_FREEBSD +#elif defined(__FreeBSD__) && __FreeBSD__ ASSERT_EQ(Application::INVALID_POSIX_SPAWN, true_app.run(args)); #else ASSERT_EQ(Application::SUCCESS, true_app.run(args)); @@ -855,8 +855,8 @@ static test_return_t wait_services_appliction_TEST(void *) static test_return_t gdb_wait_services_appliction_TEST(void *) { test_skip(true, false); -#if defined(TARGET_OS_OSX) && TARGET_OS_OSX - test_skip(0, TARGET_OS_OSX); +#if defined(__APPLE__) && __APPLE__ + test_skip(0, __APPLE__); #endif test_skip(0, access("/etc/services", R_OK )); @@ -879,8 +879,8 @@ static test_return_t gdb_abort_services_appliction_TEST(void *) test_skip(0, access("libtest/abort", X_OK )); test_skip(true, false); -#if defined(TARGET_OS_OSX) && TARGET_OS_OSX - test_skip(0, TARGET_OS_OSX); +#if defined(__APPLE__) && __APPLE__ + test_skip(0, __APPLE__); #endif libtest::Application abort_app("libtest/abort", true); diff --git a/m4/ax_debug.m4 b/m4/ax_debug.m4 index 4c72f276..5522d721 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 5 +#serial 6 AC_DEFUN([AX_DEBUG], [AC_PREREQ([2.63])dnl @@ -52,7 +52,9 @@ AC_DEFUN([AX_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.]) - AX_CHECK_LIBRARY([MCHECK],[mcheck.h],[mcheck],[AX_APPEND_LINK_FLAGS([-lmcheck])])], + AX_CHECK_LIBRARY([MCHECK],[mcheck.h],[mcheck],[AX_APPEND_LINK_FLAGS([-lmcheck])]) + AX_ADD_AM_MACRO([--debug],[AM_YFLAGS]) + AX_ADD_AM_MACRO([-D_GLIBCXX_DEBUG],[AM_CPPFLAGS])], [ax_enable_debug=no AC_SUBST([MCHECK]) AC_DEFINE([DEBUG],[0],[Define to 1 to enable debugging code.])]) diff --git a/tests/cli.am b/tests/cli.am index df206e5c..1bb9a6a9 100644 --- a/tests/cli.am +++ b/tests/cli.am @@ -122,3 +122,12 @@ valgrind-memerror: tests/memerror valgrind-memtouch: tests/memtouch @$(VALGRIND_COMMAND) tests/memtouch + +test-memdump: tests/memdump + tests/memdump + +gdb-memdump: tests/memdump + @$(GDB_COMMAND) tests/memdump + +valgrind-memdump: tests/memdump + @$(VALGRIND_COMMAND) tests/memdump diff --git a/tests/libmemcached-1.0/all_tests.h b/tests/libmemcached-1.0/all_tests.h index 2012d477..d748d39e 100644 --- a/tests/libmemcached-1.0/all_tests.h +++ b/tests/libmemcached-1.0/all_tests.h @@ -70,9 +70,11 @@ test_st tests[] ={ {"partial mget", false, (test_callback_fn*)get_test5 }, {"stats_servername", false, (test_callback_fn*)stats_servername_test }, {"increment", false, (test_callback_fn*)increment_test }, - {"increment_with_initial", true, (test_callback_fn*)increment_with_initial_test }, + {"memcached_increment_with_initial(0)", true, (test_callback_fn*)increment_with_initial_test }, + {"memcached_increment_with_initial(999)", true, (test_callback_fn*)increment_with_initial_999_test }, {"decrement", false, (test_callback_fn*)decrement_test }, - {"decrement_with_initial", true, (test_callback_fn*)decrement_with_initial_test }, + {"memcached_decrement_with_initial(3)", true, (test_callback_fn*)decrement_with_initial_test }, + {"memcached_decrement_with_initial(999)", true, (test_callback_fn*)decrement_with_initial_999_test }, {"increment_by_key", false, (test_callback_fn*)increment_by_key_test }, {"increment_with_initial_by_key", true, (test_callback_fn*)increment_with_initial_by_key_test }, {"decrement_by_key", false, (test_callback_fn*)decrement_by_key_test }, diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index 03b85024..56d482d2 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -994,6 +994,7 @@ test_return_t bad_key_test(memcached_st *memc) test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, true)); test_compare(query_id, memcached_query_id(memc_clone)); // We should not increase the query_id for memcached_behavior_set() + ASSERT_TRUE(memcached_behavior_get(memc_clone, MEMCACHED_BEHAVIOR_VERIFY_KEY)); /* All keys are valid in the binary protocol (except for length) */ if (memcached_behavior_get(memc_clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == false) @@ -1295,26 +1296,41 @@ test_return_t increment_test(memcached_st *memc) return TEST_SUCCESS; } -test_return_t increment_with_initial_test(memcached_st *memc) +static test_return_t __increment_with_initial_test(memcached_st *memc, uint64_t initial) { - test_skip(true, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)); - uint64_t new_number; - uint64_t initial= 0; test_compare(MEMCACHED_SUCCESS, memcached_flush_buffers(memc)); - test_compare(MEMCACHED_SUCCESS, - memcached_increment_with_initial(memc, test_literal_param("number"), 1, initial, 0, &new_number)); - test_compare(new_number, initial); + if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) + { + test_compare(MEMCACHED_SUCCESS, + memcached_increment_with_initial(memc, test_literal_param("number"), 1, initial, 0, &new_number)); + test_compare(new_number, initial); - test_compare(MEMCACHED_SUCCESS, - memcached_increment_with_initial(memc, test_literal_param("number"), 1, initial, 0, &new_number)); - test_compare(new_number, (initial +1)); + test_compare(MEMCACHED_SUCCESS, + memcached_increment_with_initial(memc, test_literal_param("number"), 1, initial, 0, &new_number)); + test_compare(new_number, (initial +1)); + } + else + { + test_compare(MEMCACHED_INVALID_ARGUMENTS, + memcached_increment_with_initial(memc, test_literal_param("number"), 1, initial, 0, &new_number)); + } return TEST_SUCCESS; } +test_return_t increment_with_initial_test(memcached_st *memc) +{ + return __increment_with_initial_test(memc, 0); +} + +test_return_t increment_with_initial_999_test(memcached_st *memc) +{ + return __increment_with_initial_test(memc, 999); +} + test_return_t decrement_test(memcached_st *memc) { test_compare(return_value_based_on_buffering(memc), @@ -1342,12 +1358,10 @@ test_return_t decrement_test(memcached_st *memc) return TEST_SUCCESS; } -test_return_t decrement_with_initial_test(memcached_st *memc) +static test_return_t __decrement_with_initial_test(memcached_st *memc, uint64_t initial) { test_skip(true, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)); - uint64_t initial= 3; - test_compare(MEMCACHED_SUCCESS, memcached_flush_buffers(memc)); uint64_t new_number; @@ -1368,6 +1382,16 @@ test_return_t decrement_with_initial_test(memcached_st *memc) return TEST_SUCCESS; } +test_return_t decrement_with_initial_test(memcached_st *memc) +{ + return __decrement_with_initial_test(memc, 3); +} + +test_return_t decrement_with_initial_999_test(memcached_st *memc) +{ + return __decrement_with_initial_test(memc, 999); +} + test_return_t increment_by_key_test(memcached_st *memc) { const char *master_key= "foo"; @@ -1399,24 +1423,32 @@ test_return_t increment_by_key_test(memcached_st *memc) test_return_t increment_with_initial_by_key_test(memcached_st *memc) { - test_skip(true, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)); - uint64_t new_number; const char *master_key= "foo"; const char *key= "number"; uint64_t initial= 0; - test_compare(MEMCACHED_SUCCESS, - memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key), - key, strlen(key), - 1, initial, 0, &new_number)); - test_compare(new_number, initial); + if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) + { + test_compare(MEMCACHED_SUCCESS, + memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key), + key, strlen(key), + 1, initial, 0, &new_number)); + test_compare(new_number, initial); - test_compare(MEMCACHED_SUCCESS, - memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key), - key, strlen(key), - 1, initial, 0, &new_number)); - test_compare(new_number, (initial +1)); + test_compare(MEMCACHED_SUCCESS, + memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key), + key, strlen(key), + 1, initial, 0, &new_number)); + test_compare(new_number, (initial +1)); + } + else + { + test_compare(MEMCACHED_INVALID_ARGUMENTS, + memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key), + key, strlen(key), + 1, initial, 0, &new_number)); + } return TEST_SUCCESS; } @@ -1457,19 +1489,30 @@ test_return_t decrement_with_initial_by_key_test(memcached_st *memc) uint64_t new_number; uint64_t initial= 3; - test_compare(MEMCACHED_SUCCESS, - memcached_decrement_with_initial_by_key(memc, - test_literal_param("foo"), - test_literal_param("number"), - 1, initial, 0, &new_number)); - test_compare(new_number, initial); + if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) + { + test_compare(MEMCACHED_SUCCESS, + memcached_decrement_with_initial_by_key(memc, + test_literal_param("foo"), + test_literal_param("number"), + 1, initial, 0, &new_number)); + test_compare(new_number, initial); - test_compare(MEMCACHED_SUCCESS, - memcached_decrement_with_initial_by_key(memc, - test_literal_param("foo"), - test_literal_param("number"), - 1, initial, 0, &new_number)); - test_compare(new_number, (initial - 1)); + test_compare(MEMCACHED_SUCCESS, + memcached_decrement_with_initial_by_key(memc, + test_literal_param("foo"), + test_literal_param("number"), + 1, initial, 0, &new_number)); + test_compare(new_number, (initial - 1)); + } + else + { + test_compare(MEMCACHED_INVALID_ARGUMENTS, + memcached_decrement_with_initial_by_key(memc, + test_literal_param("foo"), + test_literal_param("number"), + 1, initial, 0, &new_number)); + } return TEST_SUCCESS; } @@ -3040,7 +3083,7 @@ test_return_t selection_of_namespace_tests(memcached_st *memc) const char *key= "mine"; char *value; - /* Make sure be default none exists */ + /* Make sure by default none exists */ value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc); test_null(value); test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc)); @@ -3051,7 +3094,7 @@ test_return_t selection_of_namespace_tests(memcached_st *memc) value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc); test_true(value); - test_memcmp(value, key, 4); + test_memcmp(value, key, strlen(key)); test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc)); /* Test that we can turn it off */ @@ -3069,7 +3112,7 @@ test_return_t selection_of_namespace_tests(memcached_st *memc) value= (char *)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc); test_true(value); test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc)); - test_memcmp(value, key, 4); + test_memcmp(value, key, strlen(key)); /* Set to Zero, and then Set to something too large */ { @@ -3079,9 +3122,7 @@ test_return_t selection_of_namespace_tests(memcached_st *memc) test_compare(MEMCACHED_SUCCESS, memcached_callback_set(memc, MEMCACHED_CALLBACK_NAMESPACE, NULL)); - value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc); - test_null(value); - test_compare(MEMCACHED_SUCCESS, rc); + ASSERT_NULL_(memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc), "Setting namespace to NULL did not work"); /* Test a long key for failure */ /* TODO, extend test to determine based on setting, what result should be */ @@ -3109,11 +3150,10 @@ test_return_t set_namespace(memcached_st *memc) { memcached_return_t rc; const char *key= "mine"; - char *value; // Make sure we default to a null namespace - value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc); - test_null(value); + char* value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc); + ASSERT_NULL_(value, "memc had a value for namespace when none should exist"); test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc)); /* Test a clean set */ @@ -3121,8 +3161,8 @@ test_return_t set_namespace(memcached_st *memc) memcached_callback_set(memc, MEMCACHED_CALLBACK_NAMESPACE, (void *)key)); value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc); - test_true(value); - test_memcmp(value, key, 4); + ASSERT_TRUE(value); + test_memcmp(value, key, strlen(key)); test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc)); return TEST_SUCCESS; diff --git a/tests/libmemcached-1.0/mem_functions.h b/tests/libmemcached-1.0/mem_functions.h index 9edc820e..75736931 100644 --- a/tests/libmemcached-1.0/mem_functions.h +++ b/tests/libmemcached-1.0/mem_functions.h @@ -67,6 +67,7 @@ test_return_t decrement_by_key_test(memcached_st *memc); test_return_t decrement_test(memcached_st *memc); test_return_t decrement_with_initial_by_key_test(memcached_st *memc); test_return_t decrement_with_initial_test(memcached_st *memc); +test_return_t decrement_with_initial_999_test(memcached_st *memc); test_return_t delete_test(memcached_st *memc); test_return_t deprecated_set_memory_alloc(memcached_st *memc); test_return_t enable_cas(memcached_st *memc); @@ -88,6 +89,7 @@ test_return_t increment_by_key_test(memcached_st *memc); test_return_t increment_test(memcached_st *memc); test_return_t increment_with_initial_by_key_test(memcached_st *memc); test_return_t increment_with_initial_test(memcached_st *memc); +test_return_t increment_with_initial_999_test(memcached_st *memc); test_return_t init_test(memcached_st *not_used); test_return_t jenkins_run (memcached_st *); test_return_t key_setup(memcached_st *memc); diff --git a/tests/libmemcached-1.0/plus.cpp b/tests/libmemcached-1.0/plus.cpp index 3079b9b3..1017a7c4 100644 --- a/tests/libmemcached-1.0/plus.cpp +++ b/tests/libmemcached-1.0/plus.cpp @@ -181,6 +181,13 @@ static test_return_t mget_test(memcached_st *original) vector<char> return_value; /* We need to empty the server before we continue the test */ + bool flush_res= memc.flush(); + if (flush_res == false) + { + std::string error_string; + ASSERT_TRUE(memc.error(error_string)); + Error << error_string; + } test_true(memc.flush()); test_true(memc.mget(keys)); diff --git a/tests/libmemcached_world.h b/tests/libmemcached_world.h index 8cf84c6e..52f1d942 100644 --- a/tests/libmemcached_world.h +++ b/tests/libmemcached_world.h @@ -87,12 +87,14 @@ static void *world_create(libtest::server_startup_st& servers, test_return_t& er static bool world_destroy(void *object) { libmemcached_test_container_st *container= (libmemcached_test_container_st *)object; +#if 0 #if defined(LIBMEMCACHED_WITH_SASL_SUPPORT) && LIBMEMCACHED_WITH_SASL_SUPPORT if (LIBMEMCACHED_WITH_SASL_SUPPORT) { sasl_done(); } #endif +#endif delete container; diff --git a/tests/libmemcached_world_socket.h b/tests/libmemcached_world_socket.h index 64cf55e5..69f0a91b 100644 --- a/tests/libmemcached_world_socket.h +++ b/tests/libmemcached_world_socket.h @@ -75,12 +75,15 @@ static void *world_create(libtest::server_startup_st& servers, test_return_t& er static bool world_destroy(void *object) { libmemcached_test_container_st *container= (libmemcached_test_container_st *)object; + +#if 0 #if defined(LIBMEMCACHED_WITH_SASL_SUPPORT) && LIBMEMCACHED_WITH_SASL_SUPPORT if (LIBMEMCACHED_WITH_SASL_SUPPORT) { sasl_done(); } #endif +#endif delete container; diff --git a/tests/memcat.cc b/tests/memcat.cc index e019bc9b..388ff414 100644 --- a/tests/memcat.cc +++ b/tests/memcat.cc @@ -64,10 +64,10 @@ static test_return_t help_test(void *) static test_return_t cat_test(void *) { char buffer[1024]; - snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); + int length= snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); const char *args[]= { buffer, "foo", 0 }; - memcached_st *memc= memcached(buffer, strlen(buffer)); + memcached_st *memc= memcached(buffer, length); test_true(memc); test_compare(MEMCACHED_SUCCESS, @@ -77,6 +77,7 @@ static test_return_t cat_test(void *) test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc)); test_compare(MEMCACHED_SUCCESS, rc); + snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true)); test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc)); @@ -90,11 +91,11 @@ static test_return_t cat_test(void *) static test_return_t NOT_FOUND_test(void *) { char buffer[1024]; - snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); + int length= snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); const char *args[]= { buffer, "foo", 0 }; - memcached_st *memc= memcached(buffer, strlen(buffer)); - test_true(memc); + memcached_st *memc= memcached(buffer, length); + ASSERT_TRUE(memc); test_compare(MEMCACHED_SUCCESS, memcached_flush(memc, 0)); @@ -102,6 +103,7 @@ static test_return_t NOT_FOUND_test(void *) test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc)); test_compare(MEMCACHED_NOTFOUND, rc); + snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); test_compare(EXIT_FAILURE, exec_cmdline(executable, args, true)); test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc)); diff --git a/tests/memcp.cc b/tests/memcp.cc index d49b1775..88389b40 100644 --- a/tests/memcp.cc +++ b/tests/memcp.cc @@ -63,6 +63,7 @@ static test_return_t help_test(void *) return TEST_SUCCESS; } +#if 0 static test_return_t server_test(void *) { int fd; @@ -82,10 +83,13 @@ static test_return_t server_test(void *) return TEST_SUCCESS; } +#endif test_st memcp_tests[] ={ {"--help", true, help_test }, +#if 0 {"--server_test", true, server_test }, +#endif {0, 0, 0} }; diff --git a/tests/memdump.cc b/tests/memdump.cc index e55b2b99..cec73e99 100644 --- a/tests/memdump.cc +++ b/tests/memdump.cc @@ -75,10 +75,10 @@ static test_return_t server_test(void *) static test_return_t FOUND_test(void *) { char buffer[1024]; - snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); + int length= snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); const char *args[]= { buffer, 0 }; - memcached_st *memc= memcached(buffer, strlen(buffer)); + memcached_st *memc= memcached(buffer, length); test_true(memc); test_compare(MEMCACHED_SUCCESS, @@ -91,6 +91,7 @@ static test_return_t FOUND_test(void *) test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc)); test_compare(MEMCACHED_SUCCESS, rc); + length= snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); test_true(exec_cmdline(executable, args, true) <= EXIT_FAILURE); memcached_free(memc); @@ -110,19 +111,11 @@ collection_st collection[] ={ {0, 0, 0, 0} }; -static void *world_create(server_startup_st& servers, test_return_t& error) +static void *world_create(server_startup_st& servers, test_return_t&) { - if (libtest::has_memcached() == false) - { - error= TEST_SKIPPED; - return NULL; - } - - if (server_startup(servers, "memcached", libtest::default_port(), NULL) == false) - { - error= TEST_FAILURE; - return NULL; - } + SKIP_UNLESS(libtest::has_memcached()); + + ASSERT_TRUE(server_startup(servers, "memcached", libtest::default_port(), NULL)); return &servers; } diff --git a/tests/memexist.cc b/tests/memexist.cc index 98d224f7..9aa4a027 100644 --- a/tests/memexist.cc +++ b/tests/memexist.cc @@ -64,10 +64,10 @@ static test_return_t help_test(void *) static test_return_t exist_test(void *) { char buffer[1024]; - snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); + int length= snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); const char *args[]= { buffer, "foo", 0 }; - memcached_st *memc= memcached(buffer, strlen(buffer)); + memcached_st *memc= memcached(buffer, length); test_true(memc); test_compare(MEMCACHED_SUCCESS, @@ -90,11 +90,11 @@ static test_return_t exist_test(void *) static test_return_t NOT_FOUND_test(void *) { char buffer[1024]; - snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); + int length= snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); const char *args[]= { buffer, "foo", 0 }; - memcached_st *memc= memcached(buffer, strlen(buffer)); - test_true(memc); + memcached_st *memc= memcached(buffer, length); + ASSERT_TRUE(memc); test_compare(MEMCACHED_SUCCESS, memcached_flush(memc, 0)); @@ -115,9 +115,9 @@ static test_return_t NOT_FOUND_test(void *) static test_return_t check_version(void*) { char buffer[1024]; - snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); - memcached_st *memc= memcached(buffer, strlen(buffer)); - test_true(memc); + int length= snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); + memcached_st *memc= memcached(buffer, length); + ASSERT_TRUE(memc); test_return_t result= TEST_SUCCESS; if (libmemcached_util_version_check(memc, 1, 4, 8) == false) diff --git a/tests/memping.cc b/tests/memping.cc index 6161611d..ef18292b 100644 --- a/tests/memping.cc +++ b/tests/memping.cc @@ -64,7 +64,7 @@ static test_return_t help_test(void *) static test_return_t ping_TEST(void *) { char buffer[1024]; - snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); + snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); const char *args[]= { buffer, 0 }; test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true)); @@ -75,7 +75,7 @@ static test_return_t ping_TEST(void *) static test_return_t NOT_FOUND_TEST(void *) { char buffer[1024]; - snprintf(buffer, sizeof(buffer), "--server=nonexist.libmemcached.org:%d", int(default_port())); + snprintf(buffer, sizeof(buffer), "--servers=nonexist.libmemcached.org:%d", int(default_port())); const char *args[]= { buffer, 0 }; test_compare(EXIT_FAILURE, exec_cmdline(executable, args, true)); diff --git a/tests/memrm.cc b/tests/memrm.cc index acd24fc0..cda867c0 100644 --- a/tests/memrm.cc +++ b/tests/memrm.cc @@ -84,6 +84,8 @@ static test_return_t rm_test(void *) test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc)); test_compare(MEMCACHED_SUCCESS, rc); + char memrm_buffer[1024]; + snprintf(memrm_buffer, sizeof(memrm_buffer), "--servers=localhost:%d", int(default_port())); const char *args[]= { buffer, "foo", 0 }; test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true)); @@ -121,7 +123,7 @@ static test_return_t NOT_FOUND_TEST(void *) static test_return_t multiple_NOT_FOUND_TEST(void *) { char buffer[1024]; - snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); + snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); const char *args[]= { buffer, "protocols", "foo", "mine", "bar", "dog", "cat", "foo", "mine", "eye", "for", "the", "to", "not", "know", "what", "I", "should", "be", "doing", 0 }; diff --git a/tests/memtouch.cc b/tests/memtouch.cc index 247e1870..07f427b3 100644 --- a/tests/memtouch.cc +++ b/tests/memtouch.cc @@ -65,9 +65,9 @@ static test_return_t help_test(void *) static test_return_t touch_test(void *) { char buffer[1024]; - snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); + int length= snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); - memcached_st *memc= memcached(buffer, strlen(buffer)); + memcached_st *memc= memcached(buffer, length); test_true(memc); test_compare(MEMCACHED_SUCCESS, @@ -89,15 +89,15 @@ static test_return_t touch_test(void *) static test_return_t NOT_FOUND_test(void *) { char buffer[1024]; - snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); - memcached_st *memc= memcached(buffer, strlen(buffer)); + int length= snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); + memcached_st *memc= memcached(buffer, length); test_true(memc); test_compare(MEMCACHED_SUCCESS, memcached_flush(memc, 0)); test_compare(MEMCACHED_NOTFOUND, memcached_exist(memc, test_literal_param("foo"))); - snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); + length= snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); const char *args[]= { "--expire=30", buffer, "foo", 0 }; test_compare(EXIT_FAILURE, exec_cmdline(executable, args, true)); @@ -111,8 +111,8 @@ static test_return_t NOT_FOUND_test(void *) static test_return_t check_version(void*) { char buffer[1024]; - snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); - memcached_st *memc= memcached(buffer, strlen(buffer)); + int length= snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); + memcached_st *memc= memcached(buffer, length); test_true(memc); test_return_t result= TEST_SUCCESS; |