From 7b7b8c93445a962375b17f1b22d1fb1b1f693484 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Tue, 2 Aug 2011 10:15:15 -0700 Subject: [PATCH] Merge in all updates for autoconf --- .bzrignore | 18 +- Makefile.am | 20 +- clients/include.am | 1 + configure.ac | 45 +++++ example/byteorder.cc | 89 +++++++++ example/byteorder.h | 49 +++++ example/include.am | 2 +- example/interface_v0.c | 26 +-- example/interface_v1.c | 2 +- example/memcached_light.c | 2 +- libhashkit/include.am | 9 + libmemcached/byteorder.cc | 7 +- libmemcached/common.h | 11 +- libmemcached/continuum.hpp | 46 +++++ libmemcached/fetch.cc | 2 + libmemcached/include.am | 34 +--- libmemcached/server_instance.h | 48 +++++ libmemcached/string.cc | 4 +- libmemcached/string.h | 4 - libmemcached/util/include.am | 6 +- libmemcached/visibility.h | 44 ++-- libmemcachedinternal/include.am | 25 +++ libmemcachedinternal/util/include.am | 25 +++ libtest/include.am | 23 ++- m4/pandora_enable_dtrace.m4 | 6 +- tests/include.am | 38 ++-- tests/internals.cc | 67 +++++++ tests/ketama.cc | 289 +++++++++++++++++++++++++++ tests/ketama.h | 42 ++++ tests/ketama_test_cases.h | 5 +- tests/ketama_test_cases_spy.h | 4 +- tests/mem_functions.cc | 277 +------------------------ tests/parser.cc | 1 - tests/string.cc | 114 ++++++----- tests/string.h | 14 +- 35 files changed, 949 insertions(+), 450 deletions(-) create mode 100644 example/byteorder.cc create mode 100644 example/byteorder.h create mode 100644 libmemcached/continuum.hpp create mode 100644 libmemcached/server_instance.h create mode 100644 libmemcachedinternal/include.am create mode 100644 libmemcachedinternal/util/include.am create mode 100644 tests/internals.cc create mode 100644 tests/ketama.cc create mode 100644 tests/ketama.h diff --git a/.bzrignore b/.bzrignore index 42903be0..8e38d30d 100644 --- a/.bzrignore +++ b/.bzrignore @@ -2,11 +2,14 @@ *.OTHER *.THIS *.exe +*.gz *.lo *.orig *.output *.pop +*.rej *.rpm +*.tar */*.l[oa] */*/*.l[oa] */*/.deps @@ -29,6 +32,7 @@ Makefile.in TAGS aclocal.m4 autom4te.cache +autoscan.log clients/memaslap clients/memcapable clients/memcat @@ -55,6 +59,7 @@ config/pandora_vc_revinfo config/plugin.ac config/top.h configure +configure.scan docs/*.[13] docs/*.html docs/changes @@ -67,13 +72,6 @@ docs/man/* docs/text example/memcached_light libhashkit/configure.h -libmemcached-*.tar.gz -libmemcached-0.30-1.src.rpm -libmemcached-0.30-1.x86_64.rpm -libmemcached-0.31-1.src.rpm -libmemcached-0.31-1.x86_64.rpm -libmemcached-0.37-1.src.rpm -libmemcached-0.37-1.x86_64.rpm libmemcached-?.??/ libmemcached/configure.h libmemcached/dtrace_probes.h @@ -89,6 +87,11 @@ ltoptions.m4 ltsugar.m4 ltversion.m4 lt~obsolete.m4 +m4/libtool.m4 +m4/ltoptions.m4 +m4/ltsugar.m4 +m4/ltversion.m4 +m4/lt~obsolete.m4 out patch patch2 @@ -104,6 +107,7 @@ tests/c_test tests/cycle tests/hash_plus tests/hashplus +tests/internals tests/memcapable tests/memplus tests/memslap diff --git a/Makefile.am b/Makefile.am index b47dfc82..5b600d5a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -33,19 +33,23 @@ EXTRA_DIST= \ m4/po.m4 \ m4/progtest.m4 -include libtest/include.am -include libmemcached/include.am -include libmemcached/protocol/include.am -include libmemcached/util/include.am +libmemcached_libmemcached_la_LDFLAGS= + include clients/include.am -include libhashkit/include.am -include tests/include.am +include docs/include.am include example/include.am -include support/include.am +include libhashkit/include.am +include libmemcached/include.am +include libmemcached/util/include.am +include libmemcached/protocol/include.am +include libmemcachedinternal/include.am +include libmemcachedinternal/util/include.am +include libtest/include.am include poll/include.am +include support/include.am +include tests/include.am include util/include.am include win32/include.am -include docs/include.am docs: html man diff --git a/clients/include.am b/clients/include.am index 281aa0b9..98511366 100644 --- a/clients/include.am +++ b/clients/include.am @@ -74,6 +74,7 @@ clients_memerror_LDADD= $(CLIENTS_LDADDS) clients_memslap_SOURCES = clients/memslap.cc clients_memslap_SOURCES+= clients/generator.cc clients/execute.cc +clients_memslap_CXXFLAGS = ${PTHREAD_CFLAGS} clients_memslap_LDADD = $(PTHREAD_LIBS) $(CLIENTS_LDADDS) clients_memaslap_SOURCES= \ diff --git a/configure.ac b/configure.ac index ca51592e..3fc5871f 100644 --- a/configure.ac +++ b/configure.ac @@ -130,6 +130,51 @@ PANDORA_PRINT_CALLSTACK PANDORA_HAVE_SASL WITH_LIBGEARMAN +AC_CHECK_FUNCS([alarm]) +AC_CHECK_FUNCS([dup2]) +AC_CHECK_FUNCS([gettimeofday]) +AC_CHECK_FUNCS([memchr]) +AC_CHECK_FUNCS([memmove]) +AC_CHECK_FUNCS([memset]) +AC_CHECK_FUNCS([select]) +AC_CHECK_FUNCS([setenv]) +AC_CHECK_FUNCS([socket]) +AC_CHECK_FUNCS([sqrt]) +AC_CHECK_FUNCS([strcasecmp]) +AC_CHECK_FUNCS([strchr]) +AC_CHECK_FUNCS([strdup]) +AC_CHECK_FUNCS([strerror]) +AC_CHECK_FUNCS([strtol]) +AC_CHECK_FUNCS([strtoul]) +AC_CHECK_FUNCS([strtoull]) +AC_CHECK_HEADERS([arpa/inet.h]) +AC_CHECK_HEADERS([fcntl.h]) +AC_CHECK_HEADERS([libintl.h]) +AC_CHECK_HEADERS([limits.h]) +AC_CHECK_HEADERS([malloc.h]) +AC_CHECK_HEADERS([netdb.h]) +AC_CHECK_HEADERS([netinet/in.h]) +AC_CHECK_HEADERS([stddef.h]) +AC_CHECK_HEADERS([sys/time.h]) +AC_FUNC_ALLOCA +AC_FUNC_ERROR_AT_LINE +AC_FUNC_FORK +AC_FUNC_MALLOC +AC_FUNC_REALLOC +AC_FUNC_STRERROR_R +AC_HEADER_STDBOOL +AC_TYPE_INT16_T +AC_TYPE_INT32_T +AC_TYPE_INT64_T +AC_TYPE_INT8_T +AC_TYPE_OFF_T +AC_TYPE_PID_T +AC_TYPE_SSIZE_T +AC_TYPE_UINT16_T +AC_TYPE_UINT32_T +AC_TYPE_UINT64_T +AC_TYPE_UINT8_T + dnl The sasl functions should only be visible if we build with sasl support AS_IF([test "x$ac_cv_sasl" = "xyes"], [LIBMEMCACHED_WITH_SASL_SUPPORT="#define LIBMEMCACHED_WITH_SASL_SUPPORT 1"]) diff --git a/example/byteorder.cc b/example/byteorder.cc new file mode 100644 index 00000000..5b25624a --- /dev/null +++ b/example/byteorder.cc @@ -0,0 +1,89 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2009 Brian Aker All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + +#include + +#include + +/* Byte swap a 64-bit number. */ +#ifndef swap64 +static inline uint64_t swap64(uint64_t in) +{ +#ifndef WORDS_BIGENDIAN + /* Little endian, flip the bytes around until someone makes a faster/better + * way to do this. */ + uint64_t rv= 0; + for (uint8_t x= 0; x < 8; x++) + { + rv= (rv << 8) | (in & 0xff); + in >>= 8; + } + return rv; +#else + /* big-endian machines don't need byte swapping */ + return in; +#endif // WORDS_BIGENDIAN +} +#endif + +#ifdef HAVE_HTONLL + +uint64_t example_ntohll(uint64_t value) +{ + return ntohll(value); +} + +uint64_t example_htonll(uint64_t value) +{ + return htonll(value); +} + +#else // HAVE_HTONLL + +uint64_t example_ntohll(uint64_t value) +{ + return swap64(value); +} + +uint64_t example_htonll(uint64_t value) +{ + return swap64(value); +} + +#endif // HAVE_HTONLL diff --git a/example/byteorder.h b/example/byteorder.h new file mode 100644 index 00000000..1e319a3e --- /dev/null +++ b/example/byteorder.h @@ -0,0 +1,49 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Byteorder for example + * + * Copyright (C) 2011 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 + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +uint64_t example_ntohll(uint64_t); + +uint64_t example_htonll(uint64_t); + +#ifdef __cplusplus +} +#endif diff --git a/example/include.am b/example/include.am index 561eebc8..5a4dad14 100644 --- a/example/include.am +++ b/example/include.am @@ -10,7 +10,7 @@ example_memcached_light_SOURCES= \ example/interface_v0.c \ example/interface_v1.c \ example/memcached_light.c \ - libmemcached/byteorder.cc \ + example/byteorder.cc \ example/memcached_light.h \ example/storage.h diff --git a/example/interface_v0.c b/example/interface_v0.c index a5462734..625b4dd9 100644 --- a/example/interface_v0.c +++ b/example/interface_v0.c @@ -15,7 +15,7 @@ #include #include -#include +#include #include "storage.h" #include "memcached_light.h" @@ -78,7 +78,7 @@ static protocol_binary_response_status get_command_handler(const void *cookie, msg.response.message.body.flags= htonl(item->flags); char *ptr= (char*)(msg.response.bytes + sizeof(*header) + 4); uint32_t bodysize= 4; - msg.response.message.header.response.cas= memcached_htonll(item->cas); + msg.response.message.header.response.cas= example_htonll(item->cas); if (opcode == PROTOCOL_BINARY_CMD_GETK || opcode == PROTOCOL_BINARY_CMD_GETKQ) { memcpy(ptr, item->key, item->nkey); @@ -172,8 +172,8 @@ static protocol_binary_response_status arithmetic_command_handler(const void *co }; uint16_t keylen= ntohs(header->request.keylen); - uint64_t initial= memcached_ntohll(req->message.body.initial); - uint64_t delta= memcached_ntohll(req->message.body.delta); + uint64_t initial= example_ntohll(req->message.body.initial); + uint64_t delta= example_ntohll(req->message.body.delta); uint32_t expiration= ntohl(req->message.body.expiration); uint32_t flags= 0; void *key= req->bytes + sizeof(req->bytes); @@ -222,8 +222,8 @@ static protocol_binary_response_status arithmetic_command_handler(const void *co if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS) { response.message.header.response.bodylen= ntohl(8); - response.message.body.value= memcached_ntohll((*(uint64_t*)item->data)); - response.message.header.response.cas= memcached_ntohll(item->cas); + response.message.body.value= example_ntohll((*(uint64_t*)item->data)); + response.message.header.response.cas= example_ntohll(item->cas); release_item(item); if (header->request.opcode == PROTOCOL_BINARY_CMD_INCREMENTQ || @@ -266,7 +266,7 @@ static protocol_binary_response_status concat_command_handler(const void *cookie { protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS; uint16_t keylen= ntohs(header->request.keylen); - uint64_t cas= memcached_ntohll(header->request.cas); + uint64_t cas= example_ntohll(header->request.cas); void *key= header + 1; uint32_t vallen= ntohl(header->request.bodylen) - keylen; void *val= (char*)key + keylen; @@ -317,7 +317,7 @@ static protocol_binary_response_status concat_command_handler(const void *cookie .opcode= header->request.opcode, .status= htons(rval), .opaque= header->request.opaque, - .cas= memcached_htonll(cas), + .cas= example_htonll(cas), } } }; @@ -357,7 +357,7 @@ static protocol_binary_response_status set_command_handler(const void *cookie, struct item* item= get_item(key, keylen); if (item != NULL) { - if (item->cas != memcached_ntohll(header->request.cas)) + if (item->cas != example_ntohll(header->request.cas)) { release_item(item); response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS); @@ -379,7 +379,7 @@ static protocol_binary_response_status set_command_handler(const void *cookie, /* SETQ shouldn't return a message */ if (header->request.opcode == PROTOCOL_BINARY_CMD_SET) { - response.message.header.response.cas= memcached_htonll(item->cas); + response.message.header.response.cas= example_htonll(item->cas); release_item(item); return response_handler(cookie, header, (void*)&response); } @@ -426,7 +426,7 @@ static protocol_binary_response_status add_command_handler(const void *cookie, /* ADDQ shouldn't return a message */ if (header->request.opcode == PROTOCOL_BINARY_CMD_ADD) { - response.message.header.response.cas= memcached_htonll(item->cas); + response.message.header.response.cas= example_htonll(item->cas); release_item(item); return response_handler(cookie, header, (void*)&response); } @@ -471,7 +471,7 @@ static protocol_binary_response_status replace_command_handler(const void *cooki { response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_ENOENT); } - else if (header->request.cas == 0 || memcached_ntohll(header->request.cas) == item->cas) + else if (header->request.cas == 0 || example_ntohll(header->request.cas) == item->cas) { release_item(item); delete_item(key, keylen); @@ -487,7 +487,7 @@ static protocol_binary_response_status replace_command_handler(const void *cooki /* REPLACEQ shouldn't return a message */ if (header->request.opcode == PROTOCOL_BINARY_CMD_REPLACE) { - response.message.header.response.cas= memcached_htonll(item->cas); + response.message.header.response.cas= example_htonll(item->cas); release_item(item); return response_handler(cookie, header, (void*)&response); } diff --git a/example/interface_v1.c b/example/interface_v1.c index 36c0468b..4fbfed5c 100644 --- a/example/interface_v1.c +++ b/example/interface_v1.c @@ -19,7 +19,7 @@ #include #include -#include +#include #include "storage.h" static protocol_binary_response_status add_handler(const void *cookie, diff --git a/example/memcached_light.c b/example/memcached_light.c index 6a87ff19..0249ac6c 100644 --- a/example/memcached_light.c +++ b/example/memcached_light.c @@ -35,7 +35,7 @@ #include #include -#include +#include #include "storage.h" #include "memcached_light.h" diff --git a/libhashkit/include.am b/libhashkit/include.am index 43300585..cb424e1d 100644 --- a/libhashkit/include.am +++ b/libhashkit/include.am @@ -54,6 +54,14 @@ if INCLUDE_MURMUR_SRC libhashkit_libhashkit_la_SOURCES+= libhashkit/murmur.cc endif +libhashkit_libhashkit_la_CPPFLAGS= \ + ${AM_CPPFLAGS} \ + -DBUILDING_HASHKIT + +libhashkit_libhashkit_la_CFLAGS= \ + ${AM_CFLAGS} \ + -DBUILDING_HASHKIT + libhashkit_libhashkit_la_CXXFLAGS= \ ${AM_CXXFLAGS} \ -DBUILDING_HASHKIT @@ -62,6 +70,7 @@ libhashkit_libhashkit_la_LDFLAGS= \ $(LIBM) \ -version-info $(HASHKIT_LIBRARY_VERSION) +# library used for testing noinst_LTLIBRARIES+= libhashkit/libhashkitinc.la libhashkit_libhashkitinc_la_SOURCES= ${libhashkit_libhashkit_la_SOURCES} diff --git a/libmemcached/byteorder.cc b/libmemcached/byteorder.cc index 80ea0210..7e141756 100644 --- a/libmemcached/byteorder.cc +++ b/libmemcached/byteorder.cc @@ -35,12 +35,7 @@ * */ -#include - -#include - -#include -#include +#include /* Byte swap a 64-bit number. */ #ifndef swap64 diff --git a/libmemcached/common.h b/libmemcached/common.h index 49d309c8..469ef3e2 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -68,12 +68,12 @@ #include #include +#include + #ifdef __cplusplus extern "C" { #endif -typedef struct memcached_server_st * memcached_server_write_instance_st; - typedef memcached_return_t (*memcached_server_execute_fn)(memcached_st *ptr, memcached_server_write_instance_st server, void *context); LIBMEMCACHED_LOCAL @@ -111,12 +111,7 @@ memcached_return_t memcached_server_execute(memcached_st *ptr, #include #endif -/* string value */ -struct memcached_continuum_item_st -{ - uint32_t index; - uint32_t value; -}; +#include #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96) diff --git a/libmemcached/continuum.hpp b/libmemcached/continuum.hpp new file mode 100644 index 00000000..e39fcdc3 --- /dev/null +++ b/libmemcached/continuum.hpp @@ -0,0 +1,46 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * LibMemcached + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2009 Brian Aker + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +/* string value */ +struct memcached_continuum_item_st +{ + uint32_t index; + uint32_t value; +}; diff --git a/libmemcached/fetch.cc b/libmemcached/fetch.cc index d5730105..8867d53d 100644 --- a/libmemcached/fetch.cc +++ b/libmemcached/fetch.cc @@ -86,7 +86,9 @@ char *memcached_fetch(memcached_st *ptr, char *key, size_t *key_length, } if (value_length) + { *value_length= memcached_string_length(&result_buffer->value); + } if (key) { diff --git a/libmemcached/include.am b/libmemcached/include.am index 3a0a0ac4..4950f3ca 100644 --- a/libmemcached/include.am +++ b/libmemcached/include.am @@ -16,6 +16,7 @@ noinst_HEADERS+= \ libmemcached/backtrace.hpp \ libmemcached/byteorder.h \ libmemcached/common.h \ + libmemcached/continuum.hpp \ libmemcached/do.hpp \ libmemcached/error.hpp \ libmemcached/initialize_query.h \ @@ -30,6 +31,7 @@ noinst_HEADERS+= \ libmemcached/protocol/binary_handler.h \ libmemcached/protocol/common.h \ libmemcached/response.h \ + libmemcached/server_instance.h \ libmemcached/string.hpp \ libmemcached/virtual_bucket.h @@ -79,25 +81,6 @@ nobase_include_HEADERS+= \ libmemcached/visibility.h \ libmemcached/watchpoint.h -# This noinst lib contains things we want to be ABI private but still want to -# either use in client programs or be able to test in test cases -# These symbols will not be exposed in the shipped .so -noinst_LTLIBRARIES+= libmemcached/libmemcachedinternal.la -libmemcached_libmemcachedinternal_la_SOURCES= \ - libmemcached/array.c \ - libmemcached/backtrace.cc \ - libmemcached/error.cc \ - libmemcached/string.cc -libmemcached_libmemcachedinternal_la_CFLAGS= \ - ${AM_CFLAGS} \ - ${NO_CONVERSION} \ - -DBUILDING_LIBMEMCACHED - -libmemcached_libmemcachedinternal_la_CXXFLAGS= \ - ${AM_CXXFLAGS} \ - ${NO_CONVERSION} \ - -DBUILDING_LIBMEMCACHED - lib_LTLIBRARIES+= libmemcached/libmemcached.la libmemcached_libmemcached_la_CFLAGS= \ ${AM_CFLAGS} \ @@ -156,7 +139,7 @@ libmemcached/options.cc: libmemcached/csl/parser.h libmemcached_libmemcached_la_DEPENDENCIES= libmemcached_libmemcached_la_LIBADD= $(LIBM) -libmemcached_libmemcached_la_LDFLAGS= ${AM_LDFLAGS} -version-info ${MEMCACHED_LIBRARY_VERSION} +libmemcached_libmemcached_la_LDFLAGS+= ${AM_LDFLAGS} -version-info ${MEMCACHED_LIBRARY_VERSION} if HAVE_SASL libmemcached_libmemcached_la_LDFLAGS+= $(LTLIBSASL) $(LTLIBSASL2) @@ -166,22 +149,19 @@ endif if HAVE_DTRACE BUILT_SOURCES+= libmemcached/dtrace_probes.h CLEANFILES+= libmemcached/dtrace_probes.h -endif +CLEANFILES+= libmemcached/libmemcached_probes.o -if DTRACE_NEEDS_OBJECTS -libmemcached_libmemcached_la_SOURCES += libmemcached/libmemcached_probes.d libmemcached_libmemcached_la_DEPENDENCIES += libmemcached/libmemcached_probes.o libmemcached_libmemcached_la_LIBADD += libmemcached/libmemcached_probes.o -CLEANFILES+= libmemcached/libmemcached_probes.o +libmemcached_libmemcached_la_SOURCES += libmemcached/libmemcached_probes.d endif SUFFIXES+= .d libmemcached/dtrace_probes.h: libmemcached/libmemcached_probes.d - $(DTRACE) $(DTRACEFLAGS) -h -o libmemcached/dtrace_probes.h -s ${top_srcdir}/libmemcached/libmemcached_probes.d + $(DTRACE) $(DTRACEFLAGS) -h -o ${top_srcdir}/libmemcached/dtrace_probes.h -s ${top_srcdir}/libmemcached/libmemcached_probes.d libmemcached/libmemcached_probes.o: libmemcached/libmemcached_probes.d ${libmemcached_libmemcached_la_OBJECTS} config.h .d.o: - $(DTRACE) $(DTRACEFLAGS) -o $@ -G -s $< `grep '^pic_object' ${top_builddir}/libmemcached/*.lo | cut -f 2 -d\' | sed "s/^/${top_builddir}\/libmemcached\//"` - + $(DTRACE) $(DTRACEFLAGS) -o $@ -G -s libmemcached/libmemcached_probes.d diff --git a/libmemcached/server_instance.h b/libmemcached/server_instance.h new file mode 100644 index 00000000..8c439920 --- /dev/null +++ b/libmemcached/server_instance.h @@ -0,0 +1,48 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * LibMemcached + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct memcached_server_st * memcached_server_write_instance_st; + +#ifdef __cplusplus +} +#endif diff --git a/libmemcached/string.cc b/libmemcached/string.cc index 7bc7fec0..d482d4cd 100644 --- a/libmemcached/string.cc +++ b/libmemcached/string.cc @@ -191,7 +191,9 @@ memcached_return_t memcached_string_reset(memcached_string_st *string) void memcached_string_free(memcached_string_st *ptr) { if (not ptr) + { return; + } if (ptr->string) { @@ -215,7 +217,7 @@ memcached_return_t memcached_string_check(memcached_string_st *string, size_t ne size_t memcached_string_length(const memcached_string_st *self) { - return (size_t)(self->end - self->string); + return size_t(self->end -self->string); } size_t memcached_string_size(const memcached_string_st *self) diff --git a/libmemcached/string.h b/libmemcached/string.h index 360d9008..01097a65 100644 --- a/libmemcached/string.h +++ b/libmemcached/string.h @@ -60,8 +60,6 @@ struct memcached_string_st { } options; }; -#ifdef BUILDING_LIBMEMCACHED - #ifdef __cplusplus extern "C" { #endif @@ -109,5 +107,3 @@ void memcached_string_set_length(memcached_string_st *self, size_t length); #ifdef __cplusplus } #endif - -#endif diff --git a/libmemcached/util/include.am b/libmemcached/util/include.am index 9ac9c8c4..2f446517 100644 --- a/libmemcached/util/include.am +++ b/libmemcached/util/include.am @@ -2,7 +2,6 @@ # included from Top Level Makefile.am # All paths should be given relative to the root -if BUILD_LIBMEMCACHEDUTIL nobase_include_HEADERS+= \ libmemcached/memcached_util.h \ libmemcached/util.h \ @@ -12,7 +11,6 @@ nobase_include_HEADERS+= \ libmemcached/util/pool.h \ libmemcached/util/version.h lib_LTLIBRARIES+= libmemcached/libmemcachedutil.la -endif libmemcached_libmemcachedutil_la_SOURCES= \ libmemcached/backtrace.cc \ @@ -31,7 +29,7 @@ libmemcached_libmemcachedutil_la_CXXFLAGS= \ ${NO_CONVERSION} \ ${PTHREAD_CFLAGS} \ -DBUILDING_LIBMEMCACHED -libmemcached_libmemcachedutil_la_LIBADD= libmemcached/libmemcached.la -libmemcached_libmemcachedutil_la_LDFLAGS= ${AM_LDFLAGS} ${PTHREAD_LIBS} -version-info ${MEMCACHED_UTIL_LIBRARY_VERSION} +libmemcached_libmemcachedutil_la_LIBADD= libmemcached/libmemcached.la ${PTHREAD_LIBS} +libmemcached_libmemcachedutil_la_LDFLAGS= ${AM_LDFLAGS} -version-info ${MEMCACHED_UTIL_LIBRARY_VERSION} libmemcached_libmemcachedutil_la_DEPENDENCIES= libmemcached/libmemcached.la diff --git a/libmemcached/visibility.h b/libmemcached/visibility.h index 646806ac..d4e4eea0 100644 --- a/libmemcached/visibility.h +++ b/libmemcached/visibility.h @@ -26,26 +26,42 @@ * LIBMEMCACHED_LOCAL is used for non-api symbols. */ -#if defined(BUILDING_LIBMEMCACHED) +#if defined(BUILDING_LIBMEMCACHEDINTERNAL) # if defined(HAVE_VISIBILITY) && HAVE_VISIBILITY # define LIBMEMCACHED_API __attribute__ ((visibility("default"))) -# define LIBMEMCACHED_LOCAL __attribute__ ((visibility("hidden"))) +# define LIBMEMCACHED_LOCAL __attribute__ ((visibility("default"))) # elif defined (__SUNPRO_C) && (__SUNPRO_C >= 0x550) # define LIBMEMCACHED_API __global -# define LIBMEMCACHED_LOCAL __hidden +# define LIBMEMCACHED_LOCAL __global # elif defined(_MSC_VER) # define LIBMEMCACHED_API extern __declspec(dllexport) -# define LIBMEMCACHED_LOCAL -# else -# define LIBMEMCACHED_API -# define LIBMEMCACHED_LOCAL -# endif /* defined(HAVE_VISIBILITY) */ -#else /* defined(BUILDING_LIBMEMCACHED) */ -# if defined(_MSC_VER) -# define LIBMEMCACHED_API extern __declspec(dllimport) -# define LIBMEMCACHED_LOCAL +# define LIBMEMCACHED_LOCAL extern __declspec(dllexport) # else # define LIBMEMCACHED_API # define LIBMEMCACHED_LOCAL -# endif /* defined(_MSC_VER) */ -#endif /* defined(BUILDING_LIBMEMCACHED) */ +# endif +#else +# if defined(BUILDING_LIBMEMCACHED) +# if defined(HAVE_VISIBILITY) && HAVE_VISIBILITY +# define LIBMEMCACHED_API __attribute__ ((visibility("default"))) +# define LIBMEMCACHED_LOCAL __attribute__ ((visibility("hidden"))) +# elif defined (__SUNPRO_C) && (__SUNPRO_C >= 0x550) +# define LIBMEMCACHED_API __global +# define LIBMEMCACHED_LOCAL __hidden +# elif defined(_MSC_VER) +# define LIBMEMCACHED_API extern __declspec(dllexport) +# define LIBMEMCACHED_LOCAL +# else +# define LIBMEMCACHED_API +# define LIBMEMCACHED_LOCAL +# endif /* defined(HAVE_VISIBILITY) */ +# else /* defined(BUILDING_LIBMEMCACHED) */ +# if defined(_MSC_VER) +# define LIBMEMCACHED_API extern __declspec(dllimport) +# define LIBMEMCACHED_LOCAL +# else +# define LIBMEMCACHED_API +# define LIBMEMCACHED_LOCAL +# endif /* defined(_MSC_VER) */ +# endif /* defined(BUILDING_LIBMEMCACHED) */ +#endif /* defined(BUILDING_LIBMEMCACHEDINTERNAL) */ diff --git a/libmemcachedinternal/include.am b/libmemcachedinternal/include.am new file mode 100644 index 00000000..a6153cd5 --- /dev/null +++ b/libmemcachedinternal/include.am @@ -0,0 +1,25 @@ +# vim:ft=automake +# included from Top Level Makefile.am +# All paths should be given relative to the root + +# This noinst lib contains things we want to be ABI private but still want to +# either use in client programs or be able to test in test cases These symbols +# will not be exposed in the shipped .so +noinst_LTLIBRARIES+= libmemcachedinternal/libmemcachedinternal.la + +libmemcachedinternal_libmemcachedinternal_la_SOURCES= $(libmemcached_libmemcached_la_SOURCES) +libmemcachedinternal_libmemcachedinternal_la_CFLAGS= \ + ${AM_CFLAGS} \ + ${NO_CONVERSION} \ + -DBUILDING_LIBMEMCACHEDINTERNAL +libmemcachedinternal_libmemcachedinternal_la_CPPFLAGS= \ + ${AM_CPPFLAGS} \ + ${NO_CONVERSION} \ + -DBUILDING_LIBMEMCACHEDINTERNAL +libmemcachedinternal_libmemcachedinternal_la_CXXFLAGS= \ + ${AM_CXXFLAGS} \ + ${NO_CONVERSION} \ + -DBUILDING_LIBMEMCACHEDINTERNAL +libmemcachedinternal_libmemcachedinternal_la_LDFLAGS= ${AM_LDFLAGS} +libmemcachedinternal_libmemcachedinternal_la_LIBADD= $(libmemcached_libmemcached_la_LIBADD) +libmemcachedinternal_libmemcachedinternal_la_DEPENDENCIES= $(libmemcached_libmemcached_la_DEPENDENCIES) diff --git a/libmemcachedinternal/util/include.am b/libmemcachedinternal/util/include.am new file mode 100644 index 00000000..64589255 --- /dev/null +++ b/libmemcachedinternal/util/include.am @@ -0,0 +1,25 @@ +# vim:ft=automake +# included from Top Level Makefile.am +# All paths should be given relative to the root + +# This noinst lib contains things we want to be ABI private but still want to +# either use in client programs or be able to test in test cases These symbols +# will not be exposed in the shipped .so +noinst_LTLIBRARIES+= libmemcachedinternal/libmemcachedutilinternal.la + +libmemcachedinternal_libmemcachedutilinternal_la_SOURCES= $(libmemcached_libmemcachedutil_la_SOURCES) +libmemcachedinternal_libmemcachedutilinternal_la_CFLAGS= \ + ${AM_CFLAGS} \ + ${NO_CONVERSION} \ + ${PTHREAD_CFLAGS} \ + -DBUILDING_LIBMEMCACHEDINTERNAL +libmemcachedinternal_libmemcachedutilinternal_la_CXXFLAGS= \ + ${AM_CXXFLAGS} \ + ${NO_CONVERSION} \ + ${PTHREAD_CFLAGS} \ + -DBUILDING_LIBMEMCACHEDINTERNAL +libmemcachedinternal_libmemcachedutilinternal_la_LIBADD= libmemcachedinternal/libmemcachedinternal.la ${PTHREAD_LIBS} +libmemcachedinternal_libmemcachedutilinternal_la_LDFLAGS= ${AM_LDFLAGS} -version-info ${MEMCACHED_UTIL_LIBRARY_VERSION} +libmemcachedinternal_libmemcachedutilinternal_la_DEPENDENCIES= libmemcached/libmemcached.la + + diff --git a/libtest/include.am b/libtest/include.am index 71b5821f..2ed437c2 100644 --- a/libtest/include.am +++ b/libtest/include.am @@ -78,19 +78,26 @@ libtest_libtest_la_SOURCES= \ libtest/signal.cc \ libtest/test.cc -libtest_libtest_la_CFLAGS= ${AM_CFLAGS} ${NO_CONVERSION} -DBUILDING_LIBTEST -libtest_libtest_la_CXXFLAGS= ${AM_CXXFLAGS} ${NO_CONVERSION} -DBUILDING_LIBTEST +libtest_libtest_la_CFLAGS= ${AM_CFLAGS} +libtest_libtest_la_CFLAGS+= ${NO_CONVERSION} +libtest_libtest_la_CFLAGS+= $(PTHREAD_CFLAGS) +libtest_libtest_la_CFLAGS+= -DBUILDING_LIBTEST +libtest_libtest_la_CPPFLAGS= ${AM_CPPFLAGS} +libtest_libtest_la_CPPFLAGS+= ${NO_CONVERSION} +libtest_libtest_la_CPPFLAGS+= $(PTHREAD_LIBS) +libtest_libtest_la_CPPFLAGS+= -DBUILDING_LIBTEST +libtest_libtest_la_CXXFLAGS= ${AM_CXXFLAGS} +libtest_libtest_la_CXXFLAGS+= ${NO_CONVERSION} +libtest_libtest_la_CXXFLAGS+= -DBUILDING_LIBTEST +libtest_libtest_la_CXXFLAGS+= $(PTHREAD_CFLAGS) libtest_libtest_la_LIBADD= +libtest_libtest_la_LIBADD+= $(PTHREAD_LIBS) LIBTEST_LDADD= libtest/libtest.la if HAVE_LIBMEMCACHED -if BUILD_LIBMEMCACHEDUTIL -LIBTEST_LDADD+= libmemcached/libmemcached.la -LIBTEST_LDADD+= libmemcached/libmemcachedutil.la -else -LIBTEST_LDADD+= $(libmemcached_LIBS) -endif +libtest_libtest_la_LIBADD+= libmemcached/libmemcached.la +libtest_libtest_la_LIBADD+= libmemcached/libmemcachedutil.la libtest_libtest_la_SOURCES+= libtest/memcached.cc endif diff --git a/m4/pandora_enable_dtrace.m4 b/m4/pandora_enable_dtrace.m4 index 390efc57..4edf46f2 100644 --- a/m4/pandora_enable_dtrace.m4 +++ b/m4/pandora_enable_dtrace.m4 @@ -8,10 +8,10 @@ dnl Macro: PANDORA_ENABLE_DTRACE dnl --------------------------------------------------------------------------- AC_DEFUN([PANDORA_ENABLE_DTRACE],[ AC_ARG_ENABLE([dtrace], - [AS_HELP_STRING([--disable-dtrace], - [Build with support for the DTRACE. @<:@default=on@:>@])], + [AS_HELP_STRING([--enable-dtrace], + [Build with support for the DTRACE. @<:@default=no@:>@])], [ac_cv_enable_dtrace="$enableval"], - [ac_cv_enable_dtrace="yes"]) + [ac_cv_enable_dtrace="no"]) AS_IF([test "$ac_cv_enable_dtrace" = "yes"],[ AC_CHECK_PROGS([DTRACE], [dtrace]) diff --git a/tests/include.am b/tests/include.am index ebeeb620..316da33c 100644 --- a/tests/include.am +++ b/tests/include.am @@ -10,16 +10,13 @@ TESTS_LDADDS= \ libmemcached/libmemcached.la \ + libmemcached/libmemcachedutil.la \ libtest/libtest.la DEBUG_COMMAND= $(LIBTOOL) --mode=execute gdb PAHOLE_COMMAND= $(LIBTOOL) --mode=execute pahole -if BUILD_LIBMEMCACHEDUTIL -TESTS_LDADDS+= libmemcached/libmemcachedutil.la -endif - EXTRA_DIST+= \ tests/cpp_example.cc \ tests/output_plus.res @@ -43,40 +40,55 @@ noinst_HEADERS+= \ # Cycle should always run first tests_cycle_CFLAGS= $(AM_CFLAGS) $(NO_CONVERSION) $(NO_STRICT_ALIASING) +tests_cycle_CXXFLAGS = $(AM_CXXFLAGS) ${PTHREAD_CFLAGS} tests_cycle_SOURCES= tests/cycle.cc tests_cycle_DEPENDENCIES= $(TESTS_LDADDS) tests_cycle_LDADD= $(tests_cycle_DEPENDENCIES) +tests_cycle_LDADD+= ${PTHREAD_LIBS} check_PROGRAMS+= tests/cycle noinst_PROGRAMS+= tests/cycle +# Test internals +tests_internals_SOURCES= tests/internals.cc +tests_internals_SOURCES+= tests/string.cc +tests_internals_CXXFLAGS = $(AM_CXXFLAGS) ${PTHREAD_CFLAGS} +tests_internals_DEPENDENCIES= libmemcachedinternal/libmemcachedinternal.la libtest/libtest.la libmemcachedinternal/libmemcachedutilinternal.la +tests_internals_LDADD= libmemcachedinternal/libmemcachedinternal.la +tests_internals_LDADD+= ${PTHREAD_LIBS} +tests_internals_LDADD+= libmemcachedinternal/libmemcachedutilinternal.la +tests_internals_LDADD+= libtest/libtest.la +check_PROGRAMS+= tests/internals +noinst_PROGRAMS+= tests/internals + +tests_testapp_CXXFLAGS = $(AM_CXXFLAGS) ${PTHREAD_CFLAGS} tests_testapp_CFLAGS= $(AM_CFLAGS) $(NO_CONVERSION) $(NO_STRICT_ALIASING) tests_testapp_SOURCES= \ tests/basic.cc \ tests/debug.cc \ tests/deprecated.cc \ tests/error_conditions.cc \ + tests/ketama.cc \ tests/mem_functions.cc \ tests/namespace.cc \ tests/parser.cc \ tests/pool.cc \ tests/print.cc \ tests/replication.cc \ - tests/string.cc \ tests/virtual_buckets.cc tests_testapp_SOURCES+= clients/generator.cc clients/execute.cc - tests_testapp_DEPENDENCIES= \ - $(BUILT_SOURCES) \ - $(TESTS_LDADDS) \ + libmemcached/libmemcached.la \ + libtest/libtest.la libhashkit/libhashkit.la \ - libmemcached/libmemcachedinternal.la - + libmemcached/libmemcachedutil.la tests_testapp_LDADD= \ $(LIBSASL) \ - $(TESTS_LDADDS) \ - libhashkit/libhashkit.la \ - libmemcached/libmemcachedinternal.la + ${PTHREAD_LIBS} \ + libmemcached/libmemcached.la \ + libmemcached/libmemcachedutil.la \ + libtest/libtest.la \ + libhashkit/libhashkit.la check_PROGRAMS+= tests/testapp noinst_PROGRAMS+= tests/testapp diff --git a/tests/internals.cc b/tests/internals.cc new file mode 100644 index 00000000..8c28d315 --- /dev/null +++ b/tests/internals.cc @@ -0,0 +1,67 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached internals test + * + * Copyright (C) 2011 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 + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include + +using namespace libtest; + +#include "tests/string.h" + +/* + Test cases +*/ +test_st string_tests[] ={ + {"string static with null", false, string_static_null }, + {"string alloc with null", false, string_alloc_null }, + {"string alloc with 1K", false, string_alloc_with_size }, + {"string alloc with malloc failure", false, string_alloc_with_size_toobig }, + {"string append", false, string_alloc_append }, + {"string append failure (too big)", false, string_alloc_append_toobig }, + {"string_alloc_append_multiple", false, string_alloc_append_multiple }, + {0, 0, 0} +}; + + +collection_st collection[] ={ + {"string", 0, 0, string_tests}, + {0, 0, 0, 0} +}; + +void get_world(Framework *frame) +{ + frame->collections= collection; +} diff --git a/tests/ketama.cc b/tests/ketama.cc new file mode 100644 index 00000000..82237343 --- /dev/null +++ b/tests/ketama.cc @@ -0,0 +1,289 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 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 + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include + +#include +#include +#include + +#include +#include + +test_return_t ketama_compatibility_libmemcached(memcached_st *) +{ + memcached_st *memc= memcached_create(NULL); + test_true(memc); + + test_compare(MEMCACHED_SUCCESS, + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, 1)); + + test_compare(uint64_t(1), memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED)); + + test_compare(MEMCACHED_SUCCESS, memcached_behavior_set_distribution(memc, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA)); + test_compare(MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA, memcached_behavior_get_distribution(memc)); + + memcached_server_st *server_pool= memcached_servers_parse("10.0.1.1:11211 600,10.0.1.2:11211 300,10.0.1.3:11211 200,10.0.1.4:11211 350,10.0.1.5:11211 1000,10.0.1.6:11211 800,10.0.1.7:11211 950,10.0.1.8:11211 100"); + memcached_server_push(memc, server_pool); + + /* verify that the server list was parsed okay. */ + test_compare(8U, memcached_server_count(memc)); + test_strcmp(server_pool[0].hostname, "10.0.1.1"); + test_compare(in_port_t(11211), server_pool[0].port); + test_compare(600U, server_pool[0].weight); + test_strcmp(server_pool[2].hostname, "10.0.1.3"); + test_compare(in_port_t(11211), server_pool[2].port); + test_compare(200U, server_pool[2].weight); + test_strcmp(server_pool[7].hostname, "10.0.1.8"); + test_compare(in_port_t(11211), server_pool[7].port); + test_compare(100U, server_pool[7].weight); + + /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets + * us test the boundary wraparound. + */ + test_true(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->ketama.continuum[0].index); + + /* verify the standard ketama set. */ + for (uint32_t x= 0; x < 99; x++) + { + uint32_t server_idx = memcached_generate_hash(memc, ketama_test_cases[x].key, strlen(ketama_test_cases[x].key)); + memcached_server_instance_st instance= + memcached_server_instance_by_position(memc, server_idx); + const char *hostname = memcached_server_name(instance); + + test_strcmp(hostname, ketama_test_cases[x].server); + } + + memcached_server_list_free(server_pool); + memcached_free(memc); + + return TEST_SUCCESS; +} + +test_return_t user_supplied_bug18(memcached_st *trash) +{ + memcached_return_t rc; + uint64_t value; + int x; + memcached_st *memc; + + (void)trash; + + memc= memcached_create(NULL); + test_true(memc); + + rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, 1); + test_compare(MEMCACHED_SUCCESS, rc); + + value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED); + test_true(value == 1); + + rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, MEMCACHED_HASH_MD5); + test_compare(MEMCACHED_SUCCESS, rc); + + value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_HASH); + test_true(value == MEMCACHED_HASH_MD5); + + memcached_server_st *server_pool= memcached_servers_parse("10.0.1.1:11211 600,10.0.1.2:11211 300,10.0.1.3:11211 200,10.0.1.4:11211 350,10.0.1.5:11211 1000,10.0.1.6:11211 800,10.0.1.7:11211 950,10.0.1.8:11211 100"); + memcached_server_push(memc, server_pool); + + /* verify that the server list was parsed okay. */ + test_true(memcached_server_count(memc) == 8); + test_strcmp(server_pool[0].hostname, "10.0.1.1"); + test_true(server_pool[0].port == 11211); + test_true(server_pool[0].weight == 600); + test_strcmp(server_pool[2].hostname, "10.0.1.3"); + test_true(server_pool[2].port == 11211); + test_true(server_pool[2].weight == 200); + test_strcmp(server_pool[7].hostname, "10.0.1.8"); + test_true(server_pool[7].port == 11211); + test_true(server_pool[7].weight == 100); + + /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets + * us test the boundary wraparound. + */ + test_true(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->ketama.continuum[0].index); + + /* verify the standard ketama set. */ + for (x= 0; x < 99; x++) + { + uint32_t server_idx = memcached_generate_hash(memc, ketama_test_cases[x].key, strlen(ketama_test_cases[x].key)); + + memcached_server_instance_st instance= + memcached_server_instance_by_position(memc, server_idx); + + const char *hostname = memcached_server_name(instance); + test_strcmp(hostname, ketama_test_cases[x].server); + } + + memcached_server_list_free(server_pool); + memcached_free(memc); + + return TEST_SUCCESS; +} + +test_return_t auto_eject_hosts(memcached_st *trash) +{ + (void) trash; + memcached_server_instance_st instance; + + memcached_return_t rc; + memcached_st *memc= memcached_create(NULL); + test_true(memc); + + rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, 1); + test_compare(MEMCACHED_SUCCESS, rc); + + uint64_t value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED); + test_true(value == 1); + + rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, MEMCACHED_HASH_MD5); + test_compare(MEMCACHED_SUCCESS, rc); + + value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_HASH); + test_true(value == MEMCACHED_HASH_MD5); + + /* server should be removed when in delay */ + rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS, 1); + test_compare(MEMCACHED_SUCCESS, rc); + + value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS); + test_true(value == 1); + + memcached_server_st *server_pool; + server_pool = memcached_servers_parse("10.0.1.1:11211 600,10.0.1.2:11211 300,10.0.1.3:11211 200,10.0.1.4:11211 350,10.0.1.5:11211 1000,10.0.1.6:11211 800,10.0.1.7:11211 950,10.0.1.8:11211 100"); + memcached_server_push(memc, server_pool); + + /* verify that the server list was parsed okay. */ + test_true(memcached_server_count(memc) == 8); + test_strcmp(server_pool[0].hostname, "10.0.1.1"); + test_true(server_pool[0].port == 11211); + test_true(server_pool[0].weight == 600); + test_strcmp(server_pool[2].hostname, "10.0.1.3"); + test_true(server_pool[2].port == 11211); + test_true(server_pool[2].weight == 200); + test_strcmp(server_pool[7].hostname, "10.0.1.8"); + test_true(server_pool[7].port == 11211); + test_true(server_pool[7].weight == 100); + + instance= memcached_server_instance_by_position(memc, 2); + ((memcached_server_write_instance_st)instance)->next_retry = time(NULL) + 15; + memc->ketama.next_distribution_rebuild= time(NULL) - 1; + + /* + This would not work if there were only two hosts. + */ + for (size_t x= 0; x < 99; x++) + { + memcached_autoeject(memc); + uint32_t server_idx= memcached_generate_hash(memc, ketama_test_cases[x].key, strlen(ketama_test_cases[x].key)); + test_true(server_idx != 2); + } + + /* and re-added when it's back. */ + ((memcached_server_write_instance_st)instance)->next_retry = time(NULL) - 1; + memc->ketama.next_distribution_rebuild= time(NULL) - 1; + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, + memc->distribution); + for (size_t x= 0; x < 99; x++) + { + uint32_t server_idx = memcached_generate_hash(memc, ketama_test_cases[x].key, strlen(ketama_test_cases[x].key)); + // We re-use instance from above. + instance= + memcached_server_instance_by_position(memc, server_idx); + const char *hostname = memcached_server_name(instance); + test_strcmp(hostname, ketama_test_cases[x].server); + } + + memcached_server_list_free(server_pool); + memcached_free(memc); + + return TEST_SUCCESS; +} + +test_return_t ketama_compatibility_spymemcached(memcached_st *) +{ + memcached_st *memc= memcached_create(NULL); + test_true(memc); + + test_compare(MEMCACHED_SUCCESS, + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, 1)); + + test_compare(UINT64_C(1), memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED)); + + test_compare(MEMCACHED_SUCCESS, memcached_behavior_set_distribution(memc, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY)); + test_compare(MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY, memcached_behavior_get_distribution(memc)); + + memcached_server_st *server_pool= memcached_servers_parse("10.0.1.1:11211 600,10.0.1.2:11211 300,10.0.1.3:11211 200,10.0.1.4:11211 350,10.0.1.5:11211 1000,10.0.1.6:11211 800,10.0.1.7:11211 950,10.0.1.8:11211 100"); + test_true(server_pool); + memcached_server_push(memc, server_pool); + + /* verify that the server list was parsed okay. */ + test_compare(8U, memcached_server_count(memc)); + test_strcmp(server_pool[0].hostname, "10.0.1.1"); + test_compare(in_port_t(11211), server_pool[0].port); + test_compare(600U, server_pool[0].weight); + test_strcmp(server_pool[2].hostname, "10.0.1.3"); + test_compare(in_port_t(11211), server_pool[2].port); + test_compare(200U, server_pool[2].weight); + test_strcmp(server_pool[7].hostname, "10.0.1.8"); + test_compare(in_port_t(11211), server_pool[7].port); + test_compare(100U, server_pool[7].weight); + + /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets + * us test the boundary wraparound. + */ + test_true(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->ketama.continuum[0].index); + + /* verify the standard ketama set. */ + for (uint32_t x= 0; x < 99; x++) + { + uint32_t server_idx= memcached_generate_hash(memc, ketama_test_cases_spy[x].key, strlen(ketama_test_cases_spy[x].key)); + + memcached_server_instance_st instance= + memcached_server_instance_by_position(memc, server_idx); + + const char *hostname= memcached_server_name(instance); + + test_strcmp(hostname, ketama_test_cases_spy[x].server); + } + + memcached_server_list_free(server_pool); + memcached_free(memc); + + return TEST_SUCCESS; +} diff --git a/tests/ketama.h b/tests/ketama.h new file mode 100644 index 00000000..2d9cbb9b --- /dev/null +++ b/tests/ketama.h @@ -0,0 +1,42 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 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 + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +test_return_t auto_eject_hosts(memcached_st *); +test_return_t ketama_compatibility_libmemcached(memcached_st *); +test_return_t ketama_compatibility_spymemcached(memcached_st *); +test_return_t user_supplied_bug18(memcached_st *); diff --git a/tests/ketama_test_cases.h b/tests/ketama_test_cases.h index b01d1ab2..49d1eaa5 100644 --- a/tests/ketama_test_cases.h +++ b/tests/ketama_test_cases.h @@ -6,8 +6,7 @@ * the COPYING file in the parent directory for full text. */ -#ifndef TESTS_KETAMA_TEST_CASES_H -#define TESTS_KETAMA_TEST_CASES_H +#pragma once static struct { const char *key; @@ -117,5 +116,3 @@ static struct { }; #include "ketama_test_cases_spy.h" - -#endif diff --git a/tests/ketama_test_cases_spy.h b/tests/ketama_test_cases_spy.h index b9c0a96e..b587031f 100644 --- a/tests/ketama_test_cases_spy.h +++ b/tests/ketama_test_cases_spy.h @@ -6,8 +6,7 @@ * the COPYING file in the parent directory for full text. */ -#ifndef TESTS_KETAMA_TEST_CASES_SPY_H -#define TESTS_KETAMA_TEST_CASES_SPY_H +#pragma once static struct { const char *key; @@ -115,4 +114,3 @@ static struct { { "\\MQ_XNT7L-", 1259349383UL, 1259509450UL, "10.0.1.5" }, { "VD6D0]ba_\\", 3842502950UL, 3842588691UL, "10.0.1.7" }, }; -#endif diff --git a/tests/mem_functions.cc b/tests/mem_functions.cc index 835fc0c7..7418cc21 100644 --- a/tests/mem_functions.cc +++ b/tests/mem_functions.cc @@ -42,12 +42,16 @@ Test cases */ -#define BUILDING_LIBMEMCACHED -// !NEVER use common.h, always use memcached.h in your own apps -#include +#include +#include +#include + +#include #include +#include #include +#include #include #include #include @@ -66,9 +70,9 @@ #include #include "tests/deprecated.h" #include "tests/parser.h" +#include "tests/ketama.h" #include "tests/pool.h" #include "tests/namespace.h" -#include "tests/string.h" #include "tests/replication.h" #include "tests/debug.h" #include "tests/basic.h" @@ -78,10 +82,7 @@ using namespace libtest; -#ifdef HAVE_LIBMEMCACHEDUTIL -#include -#include "libmemcached/memcached_util.h" -#endif +#include #include "hash_results.h" @@ -2931,69 +2932,6 @@ static test_return_t user_supplied_bug20(memcached_st *memc) return TEST_SUCCESS; } -#include "ketama_test_cases.h" -static test_return_t user_supplied_bug18(memcached_st *trash) -{ - memcached_return_t rc; - uint64_t value; - int x; - memcached_st *memc; - - (void)trash; - - memc= memcached_create(NULL); - test_true(memc); - - rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, 1); - test_compare(MEMCACHED_SUCCESS, rc); - - value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED); - test_true(value == 1); - - rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, MEMCACHED_HASH_MD5); - test_compare(MEMCACHED_SUCCESS, rc); - - value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_HASH); - test_true(value == MEMCACHED_HASH_MD5); - - memcached_server_st *server_pool= memcached_servers_parse("10.0.1.1:11211 600,10.0.1.2:11211 300,10.0.1.3:11211 200,10.0.1.4:11211 350,10.0.1.5:11211 1000,10.0.1.6:11211 800,10.0.1.7:11211 950,10.0.1.8:11211 100"); - memcached_server_push(memc, server_pool); - - /* verify that the server list was parsed okay. */ - test_true(memcached_server_count(memc) == 8); - test_strcmp(server_pool[0].hostname, "10.0.1.1"); - test_true(server_pool[0].port == 11211); - test_true(server_pool[0].weight == 600); - test_strcmp(server_pool[2].hostname, "10.0.1.3"); - test_true(server_pool[2].port == 11211); - test_true(server_pool[2].weight == 200); - test_strcmp(server_pool[7].hostname, "10.0.1.8"); - test_true(server_pool[7].port == 11211); - test_true(server_pool[7].weight == 100); - - /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets - * us test the boundary wraparound. - */ - test_true(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->ketama.continuum[0].index); - - /* verify the standard ketama set. */ - for (x= 0; x < 99; x++) - { - uint32_t server_idx = memcached_generate_hash(memc, ketama_test_cases[x].key, strlen(ketama_test_cases[x].key)); - - memcached_server_instance_st instance= - memcached_server_instance_by_position(memc, server_idx); - - const char *hostname = memcached_server_name(instance); - test_strcmp(hostname, ketama_test_cases[x].server); - } - - memcached_server_list_free(server_pool); - memcached_free(memc); - - return TEST_SUCCESS; -} - /* Large mget() of missing keys with binary proto * * If many binary quiet commands (such as getq's in an mget) fill the output @@ -3098,85 +3036,6 @@ static test_return_t user_supplied_bug21(memcached_st *memc) return TEST_SUCCESS; } -static test_return_t auto_eject_hosts(memcached_st *trash) -{ - (void) trash; - memcached_server_instance_st instance; - - memcached_return_t rc; - memcached_st *memc= memcached_create(NULL); - test_true(memc); - - rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, 1); - test_compare(MEMCACHED_SUCCESS, rc); - - uint64_t value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED); - test_true(value == 1); - - rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, MEMCACHED_HASH_MD5); - test_compare(MEMCACHED_SUCCESS, rc); - - value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_HASH); - test_true(value == MEMCACHED_HASH_MD5); - - /* server should be removed when in delay */ - rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS, 1); - test_compare(MEMCACHED_SUCCESS, rc); - - value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS); - test_true(value == 1); - - memcached_server_st *server_pool; - server_pool = memcached_servers_parse("10.0.1.1:11211 600,10.0.1.2:11211 300,10.0.1.3:11211 200,10.0.1.4:11211 350,10.0.1.5:11211 1000,10.0.1.6:11211 800,10.0.1.7:11211 950,10.0.1.8:11211 100"); - memcached_server_push(memc, server_pool); - - /* verify that the server list was parsed okay. */ - test_true(memcached_server_count(memc) == 8); - test_strcmp(server_pool[0].hostname, "10.0.1.1"); - test_true(server_pool[0].port == 11211); - test_true(server_pool[0].weight == 600); - test_strcmp(server_pool[2].hostname, "10.0.1.3"); - test_true(server_pool[2].port == 11211); - test_true(server_pool[2].weight == 200); - test_strcmp(server_pool[7].hostname, "10.0.1.8"); - test_true(server_pool[7].port == 11211); - test_true(server_pool[7].weight == 100); - - instance= memcached_server_instance_by_position(memc, 2); - ((memcached_server_write_instance_st)instance)->next_retry = time(NULL) + 15; - memc->ketama.next_distribution_rebuild= time(NULL) - 1; - - /* - This would not work if there were only two hosts. - */ - for (size_t x= 0; x < 99; x++) - { - memcached_autoeject(memc); - uint32_t server_idx= memcached_generate_hash(memc, ketama_test_cases[x].key, strlen(ketama_test_cases[x].key)); - test_true(server_idx != 2); - } - - /* and re-added when it's back. */ - ((memcached_server_write_instance_st)instance)->next_retry = time(NULL) - 1; - memc->ketama.next_distribution_rebuild= time(NULL) - 1; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, - memc->distribution); - for (size_t x= 0; x < 99; x++) - { - uint32_t server_idx = memcached_generate_hash(memc, ketama_test_cases[x].key, strlen(ketama_test_cases[x].key)); - // We re-use instance from above. - instance= - memcached_server_instance_by_position(memc, server_idx); - const char *hostname = memcached_server_name(instance); - test_strcmp(hostname, ketama_test_cases[x].server); - } - - memcached_server_list_free(server_pool); - memcached_free(memc); - - return TEST_SUCCESS; -} - static test_return_t output_ketama_weighted_keys(memcached_st *trash) { (void) trash; @@ -4951,110 +4810,6 @@ static test_return_t memcached_get_by_key_MEMCACHED_NOTFOUND(memcached_st *memc) return TEST_SUCCESS; } - -static test_return_t ketama_compatibility_libmemcached(memcached_st *) -{ - memcached_st *memc= memcached_create(NULL); - test_true(memc); - - test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, 1)); - - test_compare(uint64_t(1), memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED)); - - test_compare(MEMCACHED_SUCCESS, memcached_behavior_set_distribution(memc, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA)); - test_compare(MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA, memcached_behavior_get_distribution(memc)); - - memcached_server_st *server_pool= memcached_servers_parse("10.0.1.1:11211 600,10.0.1.2:11211 300,10.0.1.3:11211 200,10.0.1.4:11211 350,10.0.1.5:11211 1000,10.0.1.6:11211 800,10.0.1.7:11211 950,10.0.1.8:11211 100"); - memcached_server_push(memc, server_pool); - - /* verify that the server list was parsed okay. */ - test_compare(8U, memcached_server_count(memc)); - test_strcmp(server_pool[0].hostname, "10.0.1.1"); - test_compare(in_port_t(11211), server_pool[0].port); - test_compare(600U, server_pool[0].weight); - test_strcmp(server_pool[2].hostname, "10.0.1.3"); - test_compare(in_port_t(11211), server_pool[2].port); - test_compare(200U, server_pool[2].weight); - test_strcmp(server_pool[7].hostname, "10.0.1.8"); - test_compare(in_port_t(11211), server_pool[7].port); - test_compare(100U, server_pool[7].weight); - - /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets - * us test the boundary wraparound. - */ - test_true(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->ketama.continuum[0].index); - - /* verify the standard ketama set. */ - for (uint32_t x= 0; x < 99; x++) - { - uint32_t server_idx = memcached_generate_hash(memc, ketama_test_cases[x].key, strlen(ketama_test_cases[x].key)); - memcached_server_instance_st instance= - memcached_server_instance_by_position(memc, server_idx); - const char *hostname = memcached_server_name(instance); - - test_strcmp(hostname, ketama_test_cases[x].server); - } - - memcached_server_list_free(server_pool); - memcached_free(memc); - - return TEST_SUCCESS; -} - -static test_return_t ketama_compatibility_spymemcached(memcached_st *) -{ - memcached_st *memc= memcached_create(NULL); - test_true(memc); - - test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, 1)); - - test_compare(UINT64_C(1), memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED)); - - test_compare(MEMCACHED_SUCCESS, memcached_behavior_set_distribution(memc, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY)); - test_compare(MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY, memcached_behavior_get_distribution(memc)); - - memcached_server_st *server_pool= memcached_servers_parse("10.0.1.1:11211 600,10.0.1.2:11211 300,10.0.1.3:11211 200,10.0.1.4:11211 350,10.0.1.5:11211 1000,10.0.1.6:11211 800,10.0.1.7:11211 950,10.0.1.8:11211 100"); - test_true(server_pool); - memcached_server_push(memc, server_pool); - - /* verify that the server list was parsed okay. */ - test_compare(8U, memcached_server_count(memc)); - test_strcmp(server_pool[0].hostname, "10.0.1.1"); - test_compare(in_port_t(11211), server_pool[0].port); - test_compare(600U, server_pool[0].weight); - test_strcmp(server_pool[2].hostname, "10.0.1.3"); - test_compare(in_port_t(11211), server_pool[2].port); - test_compare(200U, server_pool[2].weight); - test_strcmp(server_pool[7].hostname, "10.0.1.8"); - test_compare(in_port_t(11211), server_pool[7].port); - test_compare(100U, server_pool[7].weight); - - /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets - * us test the boundary wraparound. - */ - test_true(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->ketama.continuum[0].index); - - /* verify the standard ketama set. */ - for (uint32_t x= 0; x < 99; x++) - { - uint32_t server_idx= memcached_generate_hash(memc, ketama_test_cases_spy[x].key, strlen(ketama_test_cases_spy[x].key)); - - memcached_server_instance_st instance= - memcached_server_instance_by_position(memc, server_idx); - - const char *hostname= memcached_server_name(instance); - - test_strcmp(hostname, ketama_test_cases_spy[x].server); - } - - memcached_server_list_free(server_pool); - memcached_free(memc); - - return TEST_SUCCESS; -} - static test_return_t regression_bug_434484(memcached_st *memc) { test_return_t test_rc; @@ -5979,7 +5734,7 @@ static void memcached_die(memcached_st* mc, memcached_return error, const char* { fprintf(stderr, "Iteration #%u: ", it); - if(error == MEMCACHED_ERRNO) + if (error == MEMCACHED_ERRNO) { fprintf(stderr, "system error %d from %s: %s\n", errno, what, strerror(errno)); @@ -6220,17 +5975,6 @@ test_st async_tests[] ={ {0, 0, 0} }; -test_st string_tests[] ={ - {"string static with null", false, (test_callback_fn*)string_static_null }, - {"string alloc with null", false, (test_callback_fn*)string_alloc_null }, - {"string alloc with 1K", false, (test_callback_fn*)string_alloc_with_size }, - {"string alloc with malloc failure", false, (test_callback_fn*)string_alloc_with_size_toobig }, - {"string append", false, (test_callback_fn*)string_alloc_append }, - {"string append failure (too big)", false, (test_callback_fn*)string_alloc_append_toobig }, - {"string_alloc_append_multiple", false, (test_callback_fn*)string_alloc_append_multiple }, - {0, 0, (test_callback_fn*)0} -}; - test_st memcached_server_get_last_disconnect_tests[] ={ {"memcached_server_get_last_disconnect()", false, (test_callback_fn*)test_multiple_get_last_disconnect}, {0, 0, (test_callback_fn*)0} @@ -6496,7 +6240,6 @@ collection_st collection[] ={ {"sasl_auth", (test_callback_fn*)pre_sasl, 0, sasl_auth_tests }, {"sasl", (test_callback_fn*)pre_sasl, 0, tests }, {"version_1_2_3", (test_callback_fn*)check_for_1_2_3, 0, version_1_2_3}, - {"string", 0, 0, string_tests}, {"result", 0, 0, result_tests}, {"async", (test_callback_fn*)pre_nonblock, 0, async_tests}, {"async(BINARY)", (test_callback_fn*)pre_nonblock_binary, 0, async_tests}, diff --git a/tests/parser.cc b/tests/parser.cc index b29a6fdc..2becbd92 100644 --- a/tests/parser.cc +++ b/tests/parser.cc @@ -343,7 +343,6 @@ test_return_t memcached_create_with_options_with_filename(memcached_st*) memcached_st *memc_ptr; memc_ptr= memcached(test_literal_param("--CONFIGURE-FILE=\"support/example.cnf\"")); test_true_got(memc_ptr, "memcached() failed"); - test_strcmp(SUPPORT_EXAMPLE_CNF, memcached_array_string(memc_ptr->configure.filename)); memcached_free(memc_ptr); return TEST_SUCCESS; diff --git a/tests/string.cc b/tests/string.cc index 6ffe6a3f..041390ee 100644 --- a/tests/string.cc +++ b/tests/string.cc @@ -38,103 +38,113 @@ // We let libmemcached/common.h define config since we are looking at // library internals. -#define BUILDING_LIBMEMCACHED +#include -#include +#include +#include #include -#include #include -test_return_t string_static_null(memcached_st *memc) +test_return_t string_static_null(void*) { + memcached_st *memc= memcached_create(NULL); memcached_string_st string; - memcached_string_st *string_ptr; - string_ptr= memcached_string_create(memc, &string, 0); - test_true(string.options.is_initialized == true); + memcached_string_st *string_ptr= memcached_string_create(memc, &string, 0); + test_true(string.options.is_initialized); test_true(string_ptr); /* The following two better be the same! */ - test_true(memcached_is_allocated(string_ptr) == false); - test_true(memcached_is_allocated(&string) == false); + test_false(memcached_is_allocated(string_ptr)); + test_false(memcached_is_allocated(&string)); test_true(&string == string_ptr); - test_true(string.options.is_initialized == true); - test_true(memcached_is_initialized(&string) == true); + test_true(string.options.is_initialized); + test_true(memcached_is_initialized(&string)); memcached_string_free(&string); - test_true(memcached_is_initialized(&string) == false); + test_false(memcached_is_initialized(&string)); + + memcached_free(memc); return TEST_SUCCESS; } -test_return_t string_alloc_null(memcached_st *memc) +test_return_t string_alloc_null(void*) { - memcached_string_st *string; + memcached_st *memc= memcached_create(NULL); - string= memcached_string_create(memc, NULL, 0); + memcached_string_st *string= memcached_string_create(memc, NULL, 0); test_true(string); - test_true(memcached_is_allocated(string) == true); - test_true(memcached_is_initialized(string) == true); + test_true(memcached_is_allocated(string)); + test_true(memcached_is_initialized(string)); memcached_string_free(string); + memcached_free(memc); + return TEST_SUCCESS; } -test_return_t string_alloc_with_size(memcached_st *memc) +test_return_t string_alloc_with_size(void*) { - memcached_string_st *string; - - string= memcached_string_create(memc, NULL, 1024); + memcached_st *memc= memcached_create(NULL); + memcached_string_st *string= memcached_string_create(memc, NULL, 1024); test_true(string); - test_true(memcached_is_allocated(string) == true); - test_true(memcached_is_initialized(string) == true); + test_true(memcached_is_allocated(string)); + test_true(memcached_is_initialized(string)); memcached_string_free(string); + memcached_free(memc); + return TEST_SUCCESS; } -test_return_t string_alloc_with_size_toobig(memcached_st *memc) +test_return_t string_alloc_with_size_toobig(void*) { - memcached_string_st *string; - - string= memcached_string_create(memc, NULL, SIZE_MAX); - test_true(string == NULL); + memcached_st *memc= memcached_create(NULL); + memcached_string_st *string= memcached_string_create(memc, NULL, SIZE_MAX); + test_zero(string); + memcached_free(memc); return TEST_SUCCESS; } -test_return_t string_alloc_append(memcached_st *memc) +test_return_t string_alloc_append(void*) { - unsigned int x; - char buffer[SMALL_STRING_LEN]; + memcached_st *memc= memcached_create(NULL); + + char buffer[BUFSIZ]; memcached_string_st *string; /* Ring the bell! */ - memset(buffer, 6, SMALL_STRING_LEN); + memset(buffer, 6, BUFSIZ); string= memcached_string_create(memc, NULL, 100); test_true(string); - test_true(memcached_is_allocated(string) == true); - test_true(memcached_is_initialized(string) == true); + test_true(memcached_is_allocated(string)); + test_true(memcached_is_initialized(string)); - for (x= 0; x < 1024; x++) + for (unsigned int x= 0; x < 1024; x++) { memcached_return_t rc; - rc= memcached_string_append(string, buffer, SMALL_STRING_LEN); + rc= memcached_string_append(string, buffer, BUFSIZ); test_true(rc == MEMCACHED_SUCCESS); } - test_true(memcached_is_allocated(string) == true); + test_true(memcached_is_allocated(string)); memcached_string_free(string); + memcached_free(memc); + return TEST_SUCCESS; } -test_return_t string_alloc_append_toobig(memcached_st *memc) +test_return_t string_alloc_append_toobig(void*) { + memcached_st *memc= memcached_create(NULL); + memcached_return_t rc; - char buffer[SMALL_STRING_LEN]; + char buffer[BUFSIZ]; memcached_string_st *string; /* Ring the bell! */ @@ -142,33 +152,39 @@ test_return_t string_alloc_append_toobig(memcached_st *memc) string= memcached_string_create(memc, NULL, 100); test_true(string); - test_true(memcached_is_allocated(string) == true); - test_true(memcached_is_initialized(string) == true); + test_true(memcached_is_allocated(string)); + test_true(memcached_is_initialized(string)); for (unsigned int x= 0; x < 1024; x++) { - rc= memcached_string_append(string, buffer, SMALL_STRING_LEN); + rc= memcached_string_append(string, buffer, BUFSIZ); test_true(rc == MEMCACHED_SUCCESS); } rc= memcached_string_append(string, buffer, SIZE_MAX); test_true(rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE); - test_true(memcached_is_allocated(string) == true); + test_true(memcached_is_allocated(string)); memcached_string_free(string); + memcached_free(memc); + return TEST_SUCCESS; } -test_return_t string_alloc_append_multiple(memcached_st *memc) +test_return_t string_alloc_append_multiple(void*) { + memcached_st *memc= memcached_create(NULL); + memcached_string_st *error_string= memcached_string_create(memc, NULL, 1024); - memcached_string_append(error_string, memcached_literal_param("Error occured while parsing: ")); - memcached_string_append(error_string, memcached_string_make_from_cstr("jog the strlen() method")); - memcached_string_append(error_string, memcached_literal_param(" (")); + memcached_string_append(error_string, test_literal_param("Error occured while parsing: ")); + memcached_string_append(error_string, test_string_make_from_cstr("jog the strlen() method")); + memcached_string_append(error_string, test_literal_param(" (")); - memcached_string_append(error_string, memcached_string_make_from_cstr(memcached_strerror(NULL, MEMCACHED_SUCCESS))); - memcached_string_append(error_string, memcached_literal_param(")")); + memcached_string_append(error_string, test_string_make_from_cstr(memcached_strerror(NULL, MEMCACHED_SUCCESS))); + memcached_string_append(error_string, test_literal_param(")")); memcached_string_free(error_string); + memcached_free(memc); + return TEST_SUCCESS; } diff --git a/tests/string.h b/tests/string.h index ca1679cd..e8848fb9 100644 --- a/tests/string.h +++ b/tests/string.h @@ -42,25 +42,25 @@ extern "C" { #endif LIBTEST_INTERNAL_API -test_return_t string_static_null(memcached_st *memc); +test_return_t string_static_null(void *); LIBTEST_INTERNAL_API -test_return_t string_alloc_null(memcached_st *memc); +test_return_t string_alloc_null(void *); LIBTEST_INTERNAL_API -test_return_t string_alloc_with_size(memcached_st *memc); +test_return_t string_alloc_with_size(void *); LIBTEST_INTERNAL_API -test_return_t string_alloc_with_size_toobig(memcached_st *memc); +test_return_t string_alloc_with_size_toobig(void *); LIBTEST_INTERNAL_API -test_return_t string_alloc_append(memcached_st *memc); +test_return_t string_alloc_append(void *); LIBTEST_INTERNAL_API -test_return_t string_alloc_append_toobig(memcached_st *memc); +test_return_t string_alloc_append_toobig(void *); LIBTEST_INTERNAL_API -test_return_t string_alloc_append_multiple(memcached_st *memc); +test_return_t string_alloc_append_multiple(void *); #ifdef __cplusplus } -- 2.30.2