diff options
52 files changed, 792 insertions, 545 deletions
@@ -89,6 +89,7 @@ libmemcached/memcached_configure.h libtest/.hg/ libtest/.hgignore libtest/abort +libtest/backtrace libtest/core-count libtest/skiptest libtest/unittest @@ -142,6 +143,7 @@ tests/memdump tests/memerror tests/memexist tests/memflush +tests/memping tests/memplus tests/memrm tests/memslap @@ -1,6 +1,9 @@ 1.1.0 * Enable MEMCACHED_BEHAVIOR_VERIFY_KEY by default +1.0.18 +* + 1.0.17 Tue Apr 2 14:02:01 HST 2013 * Remove c++ namespace that was being exposed (the API should be plug compatible).. * Fix cases where --servers wasn't behaving the same in all clients. diff --git a/Makefile.am b/Makefile.am index 24483736..62b88708 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,7 @@ # vim:ft=automake -ACLOCAL_AMFLAGS = -I m4 -I libtest/m4 +ACLOCAL_AMFLAGS= -I m4 -I libtest/m4 +AM_YFLAGS= -d # includes append to these: SUFFIXES = @@ -18,6 +19,7 @@ noinst_PROGRAMS = include_HEADERS = nobase_include_HEADERS = check_PROGRAMS = +check_LTLIBRARIES= EXTRA_HEADERS = BUILT_SOURCES= EXTRA_DIST= @@ -125,6 +127,7 @@ maintainer-clean-local: -rm -f build-aux/install-sh -rm -f build-aux/ltmain.sh -rm -f build-aux/missing + -rm -f build-aux/ylwrap -rm -f mem_config.in -rm -f config.log -rm -f config.status diff --git a/bootstrap.sh b/bootstrap.sh index 1c2beff2..105822cf 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -188,9 +188,15 @@ function set_VENDOR_DISTRIBUTION () function set_VENDOR_RELEASE () { local release=`echo "$1" | tr '[A-Z]' '[a-z]'` - case "$VENDOR_DISTRIBUTION" in + + if $DEBUG; then + echo "VENDOR_DISTRIBUTION:$VENDOR_DISTRIBUTION" + echo "VENDOR_RELEASE:$release" + fi + + case $VENDOR_DISTRIBUTION in darwin) - case "$VENDOR_DISTRIBUTION" in + case $release in 10.6*) VENDOR_RELEASE='snow_leopard' ;; @@ -200,10 +206,12 @@ function set_VENDOR_RELEASE () mountain) VENDOR_RELEASE='mountain' ;; - 10.8*) + 10.8.*) + echo "mountain_lion" VENDOR_RELEASE='mountain_lion' ;; *) + echo $VENDOR_RELEASE VENDOR_RELEASE='unknown' ;; esac @@ -226,6 +234,8 @@ function set_VENDOR_RELEASE () VENDOR_RELEASE="precise" elif [[ "x$VENDOR_RELEASE" == 'x12.10' ]]; then VENDOR_RELEASE="quantal" + elif [[ "x$VENDOR_RELEASE" == 'x13.04' ]]; then + VENDOR_RELEASE="raring" fi ;; opensuse) @@ -375,11 +385,16 @@ function run_configure () local BUILD_CONFIGURE_ARG= # If ENV DEBUG is set we enable both debug and asssert, otherwise we see if this is a VCS checkout and if so enable assert - # Set ENV ASSERT in order to enable assert - if $DEBUG; then - BUILD_CONFIGURE_ARG+=' --enable-debug --enable-assert' - elif [[ -n "$VCS_CHECKOUT" ]]; then - BUILD_CONFIGURE_ARG+=' --enable-assert' + # Set ENV ASSERT in order to enable assert. + # If we are doing a valgrind run, we always compile with assert disabled + if $valgrind_run; then + BUILD_CONFIGURE_ARG+= '--enable-assert=no' + else + if $DEBUG; then + BUILD_CONFIGURE_ARG+=' --enable-debug --enable-assert' + elif [[ -n "$VCS_CHECKOUT" ]]; then + BUILD_CONFIGURE_ARG+=' --enable-assert' + fi fi if [[ -n "$CONFIGURE_ARG" ]]; then @@ -431,7 +446,7 @@ function setup_gdb_command () { function setup_valgrind_command () { VALGRIND_PROGRAM=`type -p valgrind` if [[ -n "$VALGRIND_PROGRAM" ]]; then - VALGRIND_COMMAND="$VALGRIND_PROGRAM --error-exitcode=1 --leak-check=yes --show-reachable=yes --track-fds=yes --malloc-fill=A5 --free-fill=DE" + VALGRIND_COMMAND="$VALGRIND_PROGRAM --error-exitcode=1 --leak-check=yes --malloc-fill=A5 --free-fill=DE --xml=yes --xml-file=\"valgrind-%p.xml\"" fi } @@ -531,11 +546,6 @@ function safe_popd () function make_valgrind () { - if [[ "$VENDOR_DISTRIBUTION" == 'darwin' ]]; then - make_darwin_malloc - return - fi - # If the env VALGRIND_COMMAND is set then we assume it is valid local valgrind_was_set=false if [[ -z "$VALGRIND_COMMAND" ]]; then @@ -555,20 +565,35 @@ function make_valgrind () save_BUILD + valgrind_run=true + # If we are required to run configure, do so now - run_configure_if_required + run_configure # If we don't have a configure, then most likely we will be missing libtool assert_file 'configure' - if [[ -f 'libtool' ]]; then + if [[ -x 'libtool' ]]; then TESTS_ENVIRONMENT="./libtool --mode=execute $VALGRIND_COMMAND" else TESTS_ENVIRONMENT="$VALGRIND_COMMAND" fi - make_target 'check' || return 1 + make_target 'all' + make_target 'check' + ret=$? + + # If we aren't going to error, we will clean up our environment + if [ "$ret" -eq 0 ]; then + make 'distclean' + fi + + valgrind_run=false restore_BUILD + + if [ "$ret" -ne 0 ]; then + return 1 + fi } function make_install_system () @@ -619,32 +644,21 @@ function make_darwin_malloc () MallocScribble=$old_MallocScribble } -function snapshot_check () -{ - if [ ! -f "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then - make_for_snapshot - fi - - if [ -n "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then - assert_file "$BOOTSTRAP_SNAPSHOT_CHECK" 'snapshot check failed' - fi -} - # This will reset our environment, and make sure built files are available. function make_for_snapshot () { - # Make sure it is clean - make_maintainer_clean + # Lets make sure we have a clean environment + assert_no_file 'Makefile' + assert_no_file 'configure' + assert_no_directory 'autom4te.cache' run_configure - make_target 'dist' + make_target 'all' make_target 'distclean' # We should have a configure, but no Makefile at the end of this exercise assert_no_file 'Makefile' assert_exec_file 'configure' - - snapshot_check } function check_mingw () @@ -813,7 +827,7 @@ function make_for_clang_analyzer () function check_for_jenkins () { if ! $jenkins_build_environment; then - echo "Not inside of jenkins" + echo "Not inside of jenkins, simulating environment" if [ -f 'configure' ]; then make_maintainer_clean @@ -842,6 +856,13 @@ function make_universe () make_install_system } +function check_snapshot () +{ + if [ -n "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then + assert_file "$BOOTSTRAP_SNAPSHOT_CHECK" 'snapshot check failed' + fi +} + function make_for_continuus_integration () { # Setup the environment if we are local @@ -853,7 +874,11 @@ function make_for_continuus_integration () # Platforms which require bootstrap should have some setup done before we hit this stage. # If we are building locally, skip this step, unless we are just testing locally. if $BOOTSTRAP_SNAPSHOT; then - snapshot_check + if $BOOTSTRAP_SNAPSHOT; then + assert_file 'configure' + fi + + check_snapshot else # If we didn't require a snapshot, then we should not have a configure assert_no_file 'configure' @@ -864,48 +889,6 @@ function make_for_continuus_integration () assert_no_file 'Makefile' 'Programmer error, Makefile existed where build state should have been clean' case $HOST_OS in - *-fedora-*) - run_configure - - assert_exec_file 'configure' - assert_file 'Makefile' - - make_target 'all' - - # make rpm includes "make distcheck" - if [[ -f rpm.am ]]; then - make_rpm - elif [[ -d rpm ]]; then - make_rpm - else - make_distcheck - fi - - assert_exec_file 'configure' - assert_file 'Makefile' - - make_install_system - ;; - *-precise-*) - run_configure - - assert_exec_file 'configure' - assert_file 'Makefile' - - make_target 'all' - - make_distcheck - - assert_exec_file 'configure' - assert_file 'Makefile' - - make_valgrind - - assert_exec_file 'configure' - assert_file 'Makefile' - - make_install_system - ;; *) make_jenkins_default ;; @@ -1102,7 +1085,7 @@ function run_autoreconf () run $BOOTSTRAP_LIBTOOLIZE '--copy' '--install' '--force' || die "Cannot execute $BOOTSTRAP_LIBTOOLIZE" fi - run $AUTORECONF || die "Cannot execute $AUTORECONF" + run $AUTORECONF $AUTORECONF_ARGS || die "Cannot execute $AUTORECONF" eval 'bash -n configure' || die "autoreconf generated a malformed configure" } @@ -1283,12 +1266,16 @@ function autoreconf_setup () fi fi fi + if $VERBOSE; then LIBTOOLIZE_OPTIONS="--verbose $BOOTSTRAP_LIBTOOLIZE_OPTIONS" fi + if $DEBUG; then LIBTOOLIZE_OPTIONS="--debug $BOOTSTRAP_LIBTOOLIZE_OPTIONS" fi + + # Here we set LIBTOOLIZE to true since we are going to invoke it via BOOTSTRAP_LIBTOOLIZE LIBTOOLIZE=true fi @@ -1326,7 +1313,7 @@ function autoreconf_setup () fi if [[ -n "$GNU_BUILD_FLAGS" ]]; then - AUTORECONF="$AUTORECONF $GNU_BUILD_FLAGS" + AUTORECONF_ARGS="$GNU_BUILD_FLAGS" fi fi @@ -1553,6 +1540,7 @@ function bootstrap () fi local snapshot_run=false + local valgrind_run=false case $target in 'self') @@ -1612,11 +1600,16 @@ function bootstrap () 'snapshot') make_for_snapshot snapshot_run=true + check_snapshot ;; 'rpm') make_rpm ;; + 'darwin_malloc') + make_darwin_malloc + ;; 'valgrind') + make_maintainer_clean make_valgrind ;; 'universe') @@ -1711,6 +1704,12 @@ function main () MAKE_TARGET="$label" fi fi + if [[ -n "$LABEL" ]]; then + check_make_target $LABEL + if [ $? -eq 0 ]; then + MAKE_TARGET="$LABEL" + fi + fi if [ -z "$MAKE_TARGET" ]; then MAKE_TARGET='jenkins' diff --git a/clients/memcapable.cc b/clients/memcapable.cc index 5566ea91..d520c778 100644 --- a/clients/memcapable.cc +++ b/clients/memcapable.cc @@ -110,9 +110,13 @@ static struct addrinfo *lookuphost(const char *hostname, const char *port) if (error != 0) { if (error != EAI_SYSTEM) + { fprintf(stderr, "getaddrinfo(): %s\n", gai_strerror(error)); + } else + { perror("getaddrinfo()"); + } } return ai; @@ -182,8 +186,9 @@ static memcached_socket_t connect_server(const char *hostname, const char *port) } } else - fprintf(stderr, "Failed to create socket: %s\n", - strerror(get_socket_errno())); + { + fprintf(stderr, "Failed to create socket: %s\n", strerror(get_socket_errno())); + } freeaddrinfo(ai); } @@ -249,7 +254,7 @@ static enum test_return ensure(bool val, const char *expression, const char *fil { if (verbose) { - fprintf(stderr, "\n%s:%d: %s", file, line, expression); + fprintf(stdout, "\n%s:%d: %s", file, line, expression); } if (do_core) @@ -334,7 +339,7 @@ static enum test_return retry_read(void *buf, size_t len) ssize_t nr= timeout_io_op(sock, POLLIN, ((char*) buf) + offset, len - offset); switch (nr) { case -1 : - fprintf(stderr, "Errno: %d %s\n", get_socket_errno(), strerror(errno)); + fprintf(stderr, "Errno: %d %s\n", get_socket_errno(), strerror(errno)); verify(get_socket_errno() == EINTR || get_socket_errno() == EAGAIN); break; @@ -2074,8 +2079,8 @@ int main(int argc, char **argv) struct test_type_st tests= { true, true }; int total= 0; int failed= 0; - const char *hostname= "localhost"; - const char *port= "11211"; + const char *hostname= NULL; + const char *port= MEMCACHED_DEFAULT_PORT_STRING; int cmd; bool prompt= false; const char *testname= NULL; @@ -2143,6 +2148,12 @@ int main(int argc, char **argv) } } + if (hostname) + { + fprintf(stderr, "No hostname was provided.\n"); + return EXIT_FAILURE; + } + initialize_sockets(); sock= connect_server(hostname, port); if (sock == INVALID_SOCKET) @@ -2197,12 +2208,24 @@ int main(int argc, char **argv) reconnect= true; ++failed; if (verbose) + { fprintf(stderr, "\n"); + } } else if (ret == TEST_PASS_RECONNECT) + { reconnect= true; + } + + if (ret == TEST_FAIL) + { + fprintf(stderr, "%s\n", status_msg[ret]); + } + else + { + fprintf(stdout, "%s\n", status_msg[ret]); + } - fprintf(stderr, "%s\n", status_msg[ret]); if (reconnect) { closesocket(sock); diff --git a/clients/memcp.cc b/clients/memcp.cc index fb899e56..ca245163 100644 --- a/clients/memcp.cc +++ b/clients/memcp.cc @@ -85,6 +85,13 @@ int main(int argc, char *argv[]) { options_parse(argc, argv); + + if (optind >= argc) + { + fprintf(stderr, "Expected argument after options\n"); + exit(EXIT_FAILURE); + } + initialize_sockets(); memcached_st *memc= memcached_create(NULL); @@ -129,10 +136,12 @@ int main(int argc, char *argv[]) { opt_servers= strdup(temp); } +#if 0 else if (argc >= 1 and argv[--argc]) { - opt_servers= strdup(argv[--argc]); + opt_servers= strdup(argv[argc]); } +#endif if (opt_servers == NULL) { @@ -185,7 +194,13 @@ int main(int argc, char *argv[]) } struct stat sbuf; - (void)fstat(fd, &sbuf); + if (fstat(fd, &sbuf) == -1) + { + std::cerr << "memcp " << argv[optind] << " " << strerror(errno) << std::endl; + optind++; + exit_code= EXIT_FAILURE; + continue; + } char *ptr= rindex(argv[optind], '/'); if (ptr) @@ -206,27 +221,33 @@ int main(int argc, char *argv[]) ptr, opt_flags, (unsigned long)opt_expires); } - char *file_buffer_ptr; - if ((file_buffer_ptr= (char *)malloc(sizeof(char) * (size_t)sbuf.st_size)) == NULL) + // The file may be empty + char *file_buffer_ptr= NULL; + if (sbuf.st_size > 0) { - std::cerr << "Error allocating file buffer(" << strerror(errno) << ")" << std::endl; - close(fd); - exit(EXIT_FAILURE); - } + if ((file_buffer_ptr= (char *)malloc(sizeof(char) * (size_t)sbuf.st_size)) == NULL) + { + std::cerr << "Error allocating file buffer(" << strerror(errno) << ")" << std::endl; + close(fd); + exit(EXIT_FAILURE); + } - ssize_t read_length; - if ((read_length= ::read(fd, file_buffer_ptr, (size_t)sbuf.st_size)) == -1) - { - std::cerr << "Error while reading file " << file_buffer_ptr << " (" << strerror(errno) << ")" << std::endl; - close(fd); - exit(EXIT_FAILURE); - } + ssize_t read_length; + if ((read_length= ::read(fd, file_buffer_ptr, (size_t)sbuf.st_size)) == -1) + { + std::cerr << "Error while reading file " << file_buffer_ptr << " (" << strerror(errno) << ")" << std::endl; + close(fd); + free(file_buffer_ptr); + exit(EXIT_FAILURE); + } - if (read_length != sbuf.st_size) - { - std::cerr << "Failure while reading file. Read length was not equal to stat() length" << std::endl; - close(fd); - exit(EXIT_FAILURE); + if (read_length != sbuf.st_size) + { + std::cerr << "Failure while reading file. Read length was not equal to stat() length" << std::endl; + close(fd); + free(file_buffer_ptr); + exit(EXIT_FAILURE); + } } memcached_return_t rc; @@ -252,7 +273,6 @@ int main(int argc, char *argv[]) if (memcached_failed(rc)) { std::cerr << "Error occrrured during memcached_set(): " << memcached_last_error_message(memc) << std::endl; - ::close(fd); exit_code= EXIT_FAILURE; } diff --git a/clients/memdump.cc b/clients/memdump.cc index ca1c0430..38b7f020 100644 --- a/clients/memdump.cc +++ b/clients/memdump.cc @@ -72,7 +72,7 @@ int main(int argc, char *argv[]) } else if (argc >= 1 and argv[--argc]) { - opt_servers= strdup(argv[--argc]); + opt_servers= strdup(argv[argc]); } if (opt_servers == NULL) diff --git a/configure.ac b/configure.ac index eadc533f..fa5f33cb 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,8 @@ # Use and distribution licensed under the BSD license. See # the COPYING file in this directory for full text. -AC_INIT([libmemcached],[1.1.0],[http://libmemcached.org/]) +m4_include([version.m4]) +AC_INIT([libmemcached],VERSION_NUMBER,[http://libmemcached.org/]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) @@ -50,6 +51,9 @@ LT_INIT LT_LANG([C++]) LT_LIB_M +AC_PROG_CC_C99 +AS_IF([test "x${ac_cv_prog_cc_c99}" == "xno"],[AC_MSG_ERROR([No c99 compatible compiler found])]) + AX_ASSERT AX_PLATFORM @@ -100,13 +104,20 @@ PROTOCOL_BINARY_TEST ENABLE_DEPRECATED # Checks for programs. +AC_CHECK_PROGS([DPKG_GENSYMBOLS],[dpkg-gensymbols]) +AC_CHECK_PROGS([LEX],['flex'],[:]) +AC_CHECK_PROGS([PERL],[perl]) +AC_CHECK_PROGS([VALGRIND],['valgrind']) +AC_CHECK_PROGS([WINE],['wine']) +AC_CHECK_PROGS([YACC],['bison --warnings=all'],[:]) AC_PROG_AWK -AC_PROG_SED AC_PROG_MKDIR_P -AC_CHECK_PROGS([LEX],['flex'],[:]) -AC_CHECK_PROGS([YACC],['bison'],[:]) -AX_PROG_SPHINX_BUILD +AC_PROG_SED AX_PROG_MEMCACHED +AX_PROG_SPHINX_BUILD(,[AC_MSG_WARN([sphinx-build version 1.0 or greater is required to build man pages])]) +AX_WITH_PROG([LCOV],[lcov]) +AX_WITH_PROG([LCOV_GENHTML],[genhtml]) +AC_DEFINE([HAVE_MEMCACHED_SASL_BINARY],[0],[If Memcached binary with sasl support is available]) # Checks for libraries. AC_SEARCH_LIBS([getopt_long],[gnugetopt]) diff --git a/docs/include.am b/docs/include.am index b302681d..f28079f8 100644 --- a/docs/include.am +++ b/docs/include.am @@ -19,7 +19,6 @@ clean-docs-check: -rm -rf docs/_build docs/doctrees man/.doctrees/ .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest -if HAVE_SPHINX sphinx-help: @echo "Please use \`make <target>' where <target> is one of" @@ -86,15 +85,9 @@ latexpdf: latex text: docs/conf.py @PYTHONPATH=${top_srcdir}/docs $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(SPHINX_BUILDDIR)/text -if HAVE_RECENT_SPHINX man: @PYTHONPATH=$(SPHINX_BUILDDIR)/docs $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) ${top_builddir}/man -else - -man: - -endif changes: docs/conf.py @PYTHONPATH=${top_srcdir}/docs $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(SPHINX_BUILDDIR)/changes @@ -106,9 +99,3 @@ doctest: docs/conf.py PYTHONPATH=${top_srcdir}/docs $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(SPHINX_BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(SPHINX_BUILDDIR)/doctest/output.txt." - -else - -man: - -endif diff --git a/libhashkit/aes.cc b/libhashkit/aes.cc index c7083a6e..12adcae3 100644 --- a/libhashkit/aes.cc +++ b/libhashkit/aes.cc @@ -62,7 +62,7 @@ struct aes_key_t { aes_key_t* aes_create_key(const char *key, const size_t key_length) { - aes_key_t* _aes_key= (aes_key_t*)calloc(1, sizeof(aes_key_t)); + aes_key_t* _aes_key= (aes_key_t*)(calloc(1, sizeof(aes_key_t))); if (_aes_key) { uint8_t rkey[AES_KEY_LENGTH/8]; @@ -79,7 +79,7 @@ aes_key_t* aes_create_key(const char *key, const size_t key_length) { ptr= rkey; /* Just loop over tmp_key until we used all key */ } - *ptr^= (uint8_t) *sptr; + *ptr^= (uint8_t)(*sptr); } _aes_key->decode_key.nr= rijndaelKeySetupDec(_aes_key->decode_key.rk, rkey, AES_KEY_LENGTH); @@ -96,7 +96,7 @@ aes_key_t* aes_clone_key(aes_key_t *_aes_key) return NULL; } - aes_key_t* _aes_clone_key= (aes_key_t*)calloc(1, sizeof(aes_key_t)); + aes_key_t* _aes_clone_key= (aes_key_t*)(calloc(1, sizeof(aes_key_t))); if (_aes_clone_key) { memcpy(_aes_clone_key, _aes_key, sizeof(aes_key_t)); @@ -122,8 +122,8 @@ hashkit_string_st* aes_encrypt(aes_key_t *_aes_key, for (size_t x= num_blocks; x > 0; x--) /* Encode complete blocks */ { - rijndaelEncrypt(_aes_key->encode_key.rk, _aes_key->encode_key.nr, (const uint8_t*) source, - (uint8_t*) dest); + rijndaelEncrypt(_aes_key->encode_key.rk, _aes_key->encode_key.nr, (const uint8_t*)(source), + (uint8_t*) (dest)); source+= AES_BLOCK_SIZE; dest+= AES_BLOCK_SIZE; } @@ -132,7 +132,7 @@ hashkit_string_st* aes_encrypt(aes_key_t *_aes_key, char pad_len= AES_BLOCK_SIZE - (source_length - AES_BLOCK_SIZE*num_blocks); memcpy(block, source, 16 -pad_len); memset(block + AES_BLOCK_SIZE -pad_len, pad_len, pad_len); - rijndaelEncrypt(_aes_key->encode_key.rk, _aes_key->encode_key.nr, block, (uint8_t*) dest); + rijndaelEncrypt(_aes_key->encode_key.rk, _aes_key->encode_key.nr, block, (uint8_t*) (dest)); hashkit_string_set_length(destination, AES_BLOCK_SIZE*(num_blocks + 1)); } @@ -160,15 +160,15 @@ hashkit_string_st* aes_decrypt(aes_key_t *_aes_key, for (size_t x = num_blocks-1; x > 0; x--) { - rijndaelDecrypt(_aes_key->decode_key.rk, _aes_key->decode_key.nr, (const uint8_t*) source, (uint8_t*) dest); + rijndaelDecrypt(_aes_key->decode_key.rk, _aes_key->decode_key.nr, (const uint8_t*) (source), (uint8_t*)(dest)); source+= AES_BLOCK_SIZE; dest+= AES_BLOCK_SIZE; } uint8_t block[AES_BLOCK_SIZE]; - rijndaelDecrypt(_aes_key->decode_key.rk, _aes_key->decode_key.nr, (const uint8_t*) source, block); + rijndaelDecrypt(_aes_key->decode_key.rk, _aes_key->decode_key.nr, (const uint8_t*)(source), block); /* Use last char in the block as size */ - unsigned int pad_len= (unsigned int) (unsigned char) block[AES_BLOCK_SIZE-1]; + unsigned int pad_len= (unsigned int) (unsigned char)(block[AES_BLOCK_SIZE-1]); if (pad_len > AES_BLOCK_SIZE) { hashkit_string_free(destination); diff --git a/libmemcached-1.2/defaults.h b/libmemcached-1.2/defaults.h index 38c29ba3..177e18cf 100644 --- a/libmemcached-1.2/defaults.h +++ b/libmemcached-1.2/defaults.h @@ -40,6 +40,7 @@ /* Public defines */ #define MEMCACHED_DEFAULT_PORT 11211 +#define MEMCACHED_DEFAULT_PORT_STRING "11211" #define MEMCACHED_POINTS_PER_SERVER 100 #define MEMCACHED_POINTS_PER_SERVER_KETAMA 160 #define MEMCACHED_CONTINUUM_SIZE MEMCACHED_POINTS_PER_SERVER*100 /* This would then set max hosts to 100 */ diff --git a/libmemcached/connect.cc b/libmemcached/connect.cc index 659d3407..b19ba716 100644 --- a/libmemcached/connect.cc +++ b/libmemcached/connect.cc @@ -760,7 +760,7 @@ static memcached_return_t _memcached_connect(memcached_instance_st* server, cons case MEMCACHED_CONNECTION_TCP: rc= network_connect(server); -#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT +#if defined(LIBMEMCACHED_WITH_SASL_SUPPORT) if (LIBMEMCACHED_WITH_SASL_SUPPORT) { if (server->fd != INVALID_SOCKET and server->root->sasl.callbacks) diff --git a/libmemcached/hosts.cc b/libmemcached/hosts.cc index 121e8f7c..75bfbee6 100644 --- a/libmemcached/hosts.cc +++ b/libmemcached/hosts.cc @@ -591,7 +591,7 @@ memcached_return_t memcached_server_add_parsed(memcached_st *ptr, in_port_t port, uint32_t weight) { - char buffer[MEMCACHED_NI_MAXHOST]; + char buffer[MEMCACHED_NI_MAXHOST]= { 0 }; memcpy(buffer, hostname, hostname_length); buffer[hostname_length]= 0; diff --git a/libtest/cmdline.cc b/libtest/cmdline.cc index fd9e510d..94c41814 100644 --- a/libtest/cmdline.cc +++ b/libtest/cmdline.cc @@ -59,6 +59,7 @@ using namespace libtest; #include <unistd.h> #include <algorithm> +#include <stdexcept> #ifndef __USE_GNU static char **environ= NULL; @@ -408,7 +409,7 @@ bool Application::slurp() Application::error_t Application::join() { - pid_t waited_pid= waitpid(_pid, &_status, 0); + pid_t waited_pid= waitpid(_pid, &_status, WUNTRACED); slurp(); if (waited_pid == _pid and WIFEXITED(_status) == false) { diff --git a/libtest/collection.cc b/libtest/collection.cc index 86e7f864..2f1cba31 100644 --- a/libtest/collection.cc +++ b/libtest/collection.cc @@ -51,6 +51,9 @@ static test_return_t runner_code(libtest::Framework* frame, try { _timer.reset(); + assert(frame); + assert(frame->runner()); + assert(run->test_fn); return_code= frame->runner()->main(run->test_fn, frame->creators_ptr()); } // Special case where check for the testing of the exception diff --git a/libtest/dns.cc b/libtest/dns.cc index 0becfc99..75a5bbfb 100644 --- a/libtest/dns.cc +++ b/libtest/dns.cc @@ -46,10 +46,14 @@ namespace libtest { bool lookup(const char* host) { bool success= false; - if (host) + assert(host and host[0]); + if (host and host[0]) { - assert(host); struct addrinfo *addrinfo= NULL; + struct addrinfo hints; + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype= SOCK_STREAM; + hints.ai_protocol= IPPROTO_TCP; int limit= 5; while (--limit and success == false) @@ -61,7 +65,7 @@ bool lookup(const char* host) } int ret; - if ((ret= getaddrinfo(host, NULL, NULL, &addrinfo)) == 0) + if ((ret= getaddrinfo(host, "echo", &hints, &addrinfo)) == 0) { success= true; break; @@ -92,6 +96,11 @@ bool lookup(const char* host) bool check_dns() { + if (valgrind_is_caller()) + { + return false; + } + if (lookup("exist.gearman.info") == false) { return false; diff --git a/libtest/exception.cc b/libtest/exception.cc new file mode 100644 index 00000000..0b18f777 --- /dev/null +++ b/libtest/exception.cc @@ -0,0 +1,108 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Data Differential YATL (i.e. libtest) library + * + * 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 + * 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 "libtest/yatlcon.h" +#include <libtest/common.h> +#include <cstdarg> + +namespace libtest { + +exception::exception(const char *file_arg, int line_arg, const char *func_arg): + std::exception(), + _line(line_arg), + _file(file_arg), + _func(func_arg), + _error_message(NULL), + _error_message_size(0) +{ +} + +#ifndef __INTEL_COMPILER +# pragma GCC diagnostic ignored "-Wformat-nonliteral" +#endif +void exception::init(va_list args_) +{ + const char *format= va_arg(args_, const char *); + int error_message_length= vasprintf(&_error_message, format, args_); + assert(error_message_length != -1); + if (error_message_length > 0) + { + _error_message_size= error_message_length +1; + } +} + +exception::~exception() throw() +{ + if (_error_message) + { + free(_error_message); + } +} + +void exception::what(size_t length_, const char* message_) +{ + if (length_ > 0 and message_) + { + char *ptr= (char*) realloc(_error_message, length_ +1); + if (ptr) + { + _error_message= ptr; + memcpy(_error_message, message_, length_); + _error_message[length_]= 0; + } + } +} + +exception::exception(const exception& other) : + std::exception(), + _line(other._line), + _file(other._file), + _func(other._func), + _error_message_size(0) +{ + if (other.length() > 0) + { + _error_message= (char*) malloc(other.length() +1); + if (_error_message) + { + memcpy(_error_message, other._error_message, other.length()); + _error_message_size= other.length(); + } + } +} + +} // namespace libtest + diff --git a/libtest/failed.h b/libtest/exception.hpp index bc459660..3d20e8ba 100644 --- a/libtest/failed.h +++ b/libtest/exception.hpp @@ -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 @@ -36,16 +36,59 @@ #pragma once -#ifdef __cplusplus -extern "C" { -#endif +namespace libtest { -LIBTEST_INTERNAL_API - void push_failed_test(const char *collection, const char *test); +class exception : public std::exception +{ +public: + exception(const char *file, int line, const char *func); -LIBTEST_INTERNAL_API - void print_failed_test(void); + exception( const exception& ); + + virtual ~exception() throw(); + + virtual const char* what() const throw() + { + if (_error_message) + { + return _error_message; + } + + return ""; + } + + void what(size_t, const char*); + + size_t length() const + { + return _error_message_size; + } + + int line() const + { + return _line; + } + + const char* file() const + { + return _file; + } + + const char* func() const + { + return _func; + } + +protected: + void init(va_list); + +private: + int _line; + const char* _file; + const char* _func; + char* _error_message; + size_t _error_message_size; +}; + +} // namespace libtest -#ifdef __cplusplus -} -#endif diff --git a/libtest/fatal.hpp b/libtest/exception/disconnected.hpp index c679f9b0..fb3a2adb 100644 --- a/libtest/fatal.hpp +++ b/libtest/exception/disconnected.hpp @@ -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 @@ -36,20 +36,15 @@ #pragma once -#include <stdexcept> +#include "libtest/exception.hpp" namespace libtest { -class disconnected : public std::runtime_error +class disconnected : public libtest::exception { public: disconnected(const char *file, int line, const char *func, const std::string&, const in_port_t port, ...); - const char* what() const throw() - { - return _error_message; - } - disconnected(const disconnected&); // The following are just for unittesting the exception class @@ -59,28 +54,9 @@ public: static uint32_t disabled_counter(); static void increment_disabled_counter(); - int line() const - { - return _line; - } - - const char* file() const - { - return _file; - } - - const char* func() const - { - return _func; - } - private: - char _error_message[BUFSIZ]; in_port_t _port; char _instance[BUFSIZ]; - int _line; - const char* _file; - const char* _func; }; } // namespace libtest diff --git a/libtest/fatal.cc b/libtest/exception/fatal.cc index 0ed06c2c..21a8ca79 100644 --- a/libtest/fatal.cc +++ b/libtest/exception/fatal.cc @@ -36,6 +36,7 @@ #include "libtest/yatlcon.h" #include <libtest/common.h> +#include "libtest/exception.hpp" #include <cstdarg> namespace libtest { @@ -43,7 +44,7 @@ namespace libtest { #pragma GCC diagnostic ignored "-Wformat-nonliteral" fatal::fatal(const char *file_arg, int line_arg, const char *func_arg, ...) : - __test_result(file_arg, line_arg, func_arg) + libtest::exception(file_arg, line_arg, func_arg) { va_list args; va_start(args, func_arg); @@ -52,7 +53,7 @@ fatal::fatal(const char *file_arg, int line_arg, const char *func_arg, ...) : } fatal::fatal( const fatal& other ) : - __test_result(other) + libtest::exception(other) { } @@ -89,11 +90,8 @@ void fatal::increment_disabled_counter() throw() #pragma GCC diagnostic ignored "-Wformat-nonliteral" disconnected::disconnected(const char *file_arg, int line_arg, const char *func_arg, const std::string& instance, const in_port_t port, ...) : - std::runtime_error(func_arg), - _port(port), - _line(line_arg), - _file(file_arg), - _func(func_arg) + libtest::exception(file_arg, line_arg, func_arg), + _port(port) { va_list args; va_start(args, port); @@ -102,17 +100,19 @@ disconnected::disconnected(const char *file_arg, int line_arg, const char *func_ (void)vsnprintf(last_error, sizeof(last_error), format, args); va_end(args); - snprintf(_error_message, sizeof(_error_message), "%s:%u %s", instance.c_str(), uint32_t(port), last_error); + char buffer_error[BUFSIZ]; + int error_length= snprintf(buffer_error, sizeof(buffer_error), "%s:%u %s", instance.c_str(), uint32_t(port), last_error); + + if (error_length > 0) + { + what(size_t(error_length), buffer_error); + } } disconnected::disconnected(const disconnected& other): - std::runtime_error(other._func), - _port(other._port), - _line(other._line), - _file(other._file), - _func(other._func) + libtest::exception(other), + _port(other._port) { - strncpy(_error_message, other._error_message, BUFSIZ); strncpy(_instance, other._instance, BUFSIZ); } diff --git a/libtest/result/fatal.hpp b/libtest/exception/fatal.hpp index 8e6d1346..5ee1aac5 100644 --- a/libtest/result/fatal.hpp +++ b/libtest/exception/fatal.hpp @@ -38,7 +38,7 @@ namespace libtest { -class fatal : public __test_result +class fatal : public libtest::exception { public: fatal(const char *file, int line, const char *func, ...); @@ -52,7 +52,36 @@ public: static uint32_t disabled_counter() throw(); static void increment_disabled_counter() throw(); + test_return_t return_code() const + { + return TEST_SKIPPED; + } + private: }; } // namespace libtest + +#define FATAL(...) \ +do \ +{ \ + throw libtest::fatal(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \ +} while (0) + +#define FATAL_IF(__expression, ...) \ +do \ +{ \ + if ((__expression)) { \ + throw libtest::fatal(LIBYATL_DEFAULT_PARAM, (#__expression)); \ + } \ +} while (0) + +#define FATAL_IF_(__expression, ...) \ +do \ +{ \ + if ((__expression)) { \ + throw libtest::fatal(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \ + } \ +} while (0) + +#define fatal_assert(__assert) if((__assert)) {} else { throw libtest::fatal(LIBYATL_DEFAULT_PARAM, #__assert); } diff --git a/libtest/framework.cc b/libtest/framework.cc index 92aacfee..2c9ba74b 100644 --- a/libtest/framework.cc +++ b/libtest/framework.cc @@ -107,47 +107,50 @@ void Framework::exec() iter != _collection.end() and (_signal.is_shutdown() == false); ++iter) { - if (_only_run.empty() == false and - fnmatch(_only_run.c_str(), (*iter)->name(), 0)) + if (*iter) { - continue; - } - - _total++; + if (_only_run.empty() == false and + fnmatch(_only_run.c_str(), (*iter)->name(), 0)) + { + continue; + } - try { - switch ((*iter)->exec()) + _total++; + + try { + switch ((*iter)->exec()) + { + case TEST_FAILURE: + _failed++; + break; + + case TEST_SKIPPED: + _skipped++; + break; + + // exec() can return SUCCESS, but that doesn't mean that some tests did + // not fail or get skipped. + case TEST_SUCCESS: + _success++; + break; + } + } + catch (const libtest::fatal& e) { - case TEST_FAILURE: _failed++; - break; - - case TEST_SKIPPED: - _skipped++; - break; - - // exec() can return SUCCESS, but that doesn't mean that some tests did - // not fail or get skipped. - case TEST_SUCCESS: - _success++; - break; + stream::cerr(e.file(), e.line(), e.func()) << e.what(); + } + catch (const libtest::disconnected& e) + { + _failed++; + Error << "Unhandled disconnection occurred:" << e.what(); + throw; + } + catch (...) + { + _failed++; + throw; } - } - catch (const libtest::fatal& e) - { - _failed++; - stream::cerr(e.file(), e.line(), e.func()) << e.what(); - } - catch (const libtest::disconnected& e) - { - _failed++; - Error << "Unhandled disconnection occurred:" << e.what(); - throw; - } - catch (...) - { - _failed++; - throw; } } diff --git a/libtest/has.cc b/libtest/has.cc index a7a09cb4..2d9abf6b 100644 --- a/libtest/has.cc +++ b/libtest/has.cc @@ -43,6 +43,11 @@ namespace libtest { +bool has_libmemcached_sasl(void) +{ + return false; +} + bool has_libmemcached(void) { #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED @@ -85,7 +90,7 @@ bool has_postgres_support(void) bool has_gearmand() { -#if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY +#if defined(GEARMAND_BINARY) && defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY if (HAVE_GEARMAND_BINARY) { std::stringstream arg_buffer; @@ -111,7 +116,7 @@ bool has_gearmand() bool has_drizzled() { -#if defined(HAVE_DRIZZLED_BINARY) && HAVE_DRIZZLED_BINARY +#if defined(DRIZZLED_BINARY) && defined(HAVE_DRIZZLED_BINARY) && HAVE_DRIZZLED_BINARY if (HAVE_DRIZZLED_BINARY) { if (access(DRIZZLED_BINARY, X_OK) == 0) @@ -126,7 +131,7 @@ bool has_drizzled() bool has_mysqld() { -#if defined(HAVE_MYSQLD_BUILD) && HAVE_MYSQLD_BUILD +#if defined(MYSQLD_BINARY) && defined(HAVE_MYSQLD_BUILD) && HAVE_MYSQLD_BUILD if (HAVE_MYSQLD_BUILD) { if (access(MYSQLD_BINARY, X_OK) == 0) @@ -141,11 +146,11 @@ bool has_mysqld() static char memcached_binary_path[FILENAME_MAX]; -static void initialize_curl_startup() +static void initialize_memcached_binary_path() { - memcached_binary_path[0]= NULL; + memcached_binary_path[0]= 0; -#if defined(HAVE_MEMCACHED_BINARY) && HAVE_MEMCACHED_BINARY +#if defined(MEMCACHED_BINARY) && defined(HAVE_MEMCACHED_BINARY) && HAVE_MEMCACHED_BINARY if (HAVE_MEMCACHED_BINARY) { std::stringstream arg_buffer; @@ -170,7 +175,7 @@ static pthread_once_t memcached_binary_once= PTHREAD_ONCE_INIT; static void initialize_memcached_binary(void) { int ret; - if ((ret= pthread_once(&memcached_binary_once, initialize_curl_startup)) != 0) + if ((ret= pthread_once(&memcached_binary_once, initialize_memcached_binary_path)) != 0) { FATAL(strerror(ret)); } @@ -180,7 +185,7 @@ bool has_memcached() { initialize_memcached_binary(); - if (memcached_binary_path[0]) + if (memcached_binary_path[0] and (strlen(memcached_binary_path) > 0)) { return true; } @@ -200,29 +205,22 @@ const char* memcached_binary() return NULL; } -bool has_memcached_sasl() -{ -#if defined(HAVE_MEMCACHED_SASL_BINARY) && HAVE_MEMCACHED_SASL_BINARY - if (HAVE_MEMCACHED_SASL_BINARY) - { - if (access(MEMCACHED_SASL_BINARY, X_OK) == 0) - { - return true; - } - } -#endif - - return false; -} - const char *gearmand_binary() { +#if defined(GEARMAND_BINARY) return GEARMAND_BINARY; +#else + return NULL; +#endif } const char *drizzled_binary() { +#if defined(DRIZZLED_BINARY) return DRIZZLED_BINARY; +#else + return NULL; +#endif } } // namespace libtest diff --git a/libtest/has.hpp b/libtest/has.hpp index f38306d5..59ee88f9 100644 --- a/libtest/has.hpp +++ b/libtest/has.hpp @@ -39,6 +39,9 @@ namespace libtest { LIBTEST_API +bool has_libmemcached_sasl(void); + +LIBTEST_API bool has_libmemcached(); LIBTEST_API diff --git a/libtest/http.cc b/libtest/http.cc index 621c714c..29873dc6 100644 --- a/libtest/http.cc +++ b/libtest/http.cc @@ -97,14 +97,14 @@ static void init(CURL *curl, const std::string& url) (void)http_get_result_callback; (void)curl; (void)url; +#if defined(HAVE_LIBCURL) && HAVE_LIBCURL if (HAVE_LIBCURL) { -#if defined(HAVE_LIBCURL) && HAVE_LIBCURL assert(curl); curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_USERAGENT, YATL_USERAGENT); -#endif } +#endif } HTTP::HTTP(const std::string& url_arg) : @@ -118,9 +118,9 @@ bool GET::execute() { (void)init; +#if defined(HAVE_LIBCURL) && HAVE_LIBCURL if (HAVE_LIBCURL) { -#if defined(HAVE_LIBCURL) && HAVE_LIBCURL CURL *curl= curl_easy_init(); init(curl, url()); @@ -134,17 +134,17 @@ bool GET::execute() curl_easy_cleanup(curl); return bool(retref == CURLE_OK); -#endif } +#endif return false; } bool POST::execute() { +#if defined(HAVE_LIBCURL) && HAVE_LIBCURL if (HAVE_LIBCURL) { -#if defined(HAVE_LIBCURL) && HAVE_LIBCURL CURL *curl= curl_easy_init();; init(curl, url()); @@ -158,17 +158,17 @@ bool POST::execute() curl_easy_cleanup(curl); return bool(retref == CURLE_OK); -#endif } +#endif return false; } bool TRACE::execute() { +#if defined(HAVE_LIBCURL) && HAVE_LIBCURL if (HAVE_LIBCURL) { -#if defined(HAVE_LIBCURL) && HAVE_LIBCURL CURL *curl= curl_easy_init();; init(curl, url()); @@ -183,18 +183,18 @@ bool TRACE::execute() curl_easy_cleanup(curl); return retref == CURLE_OK; -#endif } +#endif return false; } bool HEAD::execute() { +#if defined(HAVE_LIBCURL) && HAVE_LIBCURL if (HAVE_LIBCURL) { -#if defined(HAVE_LIBCURL) && HAVE_LIBCURL - CURL *curl= curl_easy_init();; + CURL *curl= curl_easy_init(); init(curl, url()); @@ -207,8 +207,8 @@ bool HEAD::execute() curl_easy_cleanup(curl); return retref == CURLE_OK; -#endif } +#endif return false; } diff --git a/libtest/include.am b/libtest/include.am index c9368c4f..4d1d8428 100644 --- a/libtest/include.am +++ b/libtest/include.am @@ -9,7 +9,7 @@ VALGRIND_EXEC_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=memcheck --error-exitc SGCHECK_EXEC_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=exp-sgcheck --error-exitcode=1 VALGRIND_COMMAND= TESTS_ENVIRONMENT="valgrind" $(VALGRIND_EXEC_COMMAND) HELGRIND_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=helgrind --read-var-info=yes --error-exitcode=1 --read-var-info=yes -DRD_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=drd --error-exitcode=1 +DRD_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=drd --free-is-write=yes --error-exitcode=1 SGCHECK_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=exp-sgcheck --error-exitcode=1 MASSIF_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=massif GDB_COMMAND= $(LIBTOOL_COMMAND) gdb -f -x libtest/run.gdb @@ -67,8 +67,9 @@ noinst_HEADERS+= libtest/comparison.hpp noinst_HEADERS+= libtest/core.h noinst_HEADERS+= libtest/dream.h noinst_HEADERS+= libtest/error.h -noinst_HEADERS+= libtest/failed.h -noinst_HEADERS+= libtest/fatal.hpp +noinst_HEADERS+= libtest/exception.hpp +noinst_HEADERS+= libtest/exception/disconnected.hpp +noinst_HEADERS+= libtest/exception/fatal.hpp noinst_HEADERS+= libtest/framework.h noinst_HEADERS+= libtest/gearmand.h noinst_HEADERS+= libtest/drizzled.h @@ -86,7 +87,6 @@ noinst_HEADERS+= libtest/port.h noinst_HEADERS+= libtest/result.hpp noinst_HEADERS+= libtest/result/base.hpp noinst_HEADERS+= libtest/result/fail.hpp -noinst_HEADERS+= libtest/result/fatal.hpp noinst_HEADERS+= libtest/result/skip.hpp noinst_HEADERS+= libtest/result/success.hpp noinst_HEADERS+= libtest/runner.h @@ -109,18 +109,12 @@ noinst_HEADERS+= libtest/visibility.h noinst_HEADERS+= libtest/wait.h noinst_HEADERS+= libtest/yatl.h -noinst_LTLIBRARIES+= libtest/libtest.la +check_LTLIBRARIES+= libtest/libtest.la libtest_libtest_la_CXXFLAGS= EXTRA_libtest_libtest_la_DEPENDENCIES= libtest_libtest_la_LIBADD= libtest_libtest_la_SOURCES= -if BUILDING_LIBMEMCACHED -libtest_libtest_la_LIBADD+= libmemcached/libmemcached.la -else -libtest_libtest_la_CXXFLAGS+= @LIBMEMCACHED_CFLAGS@ -libtest_libtest_la_LIBADD+= @LIBMEMCACHED_LIB@ -endif libtest_libtest_la_SOURCES+= libtest/alarm.cc libtest_libtest_la_SOURCES+= libtest/binaries.cc @@ -132,7 +126,8 @@ libtest_libtest_la_SOURCES+= libtest/cpu.cc libtest_libtest_la_SOURCES+= libtest/dns.cc libtest_libtest_la_SOURCES+= libtest/dream.cc libtest_libtest_la_SOURCES+= libtest/drizzled.cc -libtest_libtest_la_SOURCES+= libtest/fatal.cc +libtest_libtest_la_SOURCES+= libtest/exception.cc +libtest_libtest_la_SOURCES+= libtest/exception/fatal.cc libtest_libtest_la_SOURCES+= libtest/formatter.cc libtest_libtest_la_SOURCES+= libtest/client.cc libtest_libtest_la_SOURCES+= libtest/framework.cc @@ -220,6 +215,18 @@ libtest_skiptest_SOURCES= libtest/skiptest.cc check_PROGRAMS+= libtest/skiptest noinst_PROGRAMS+= libtest/skiptest +test-skiptest: libtest/skiptest + @libtest/skiptest + +valgrind-skiptest: libtest/skiptest + @$(VALGRIND_COMMAND) libtest/skiptest + +helgrind-skiptest: libtest/skiptest + @$(HELGRIND_COMMAND) libtest/skiptest + +drd-skiptest: libtest/skiptest + @$(DRD_COMMAND) libtest/skiptest + libtest_wait_SOURCES= libtest_wait_SOURCES+= libtest/wait.cc libtest_wait_SOURCES+= libtest/dream.cc diff --git a/libtest/lite.h b/libtest/lite.h index 342be97d..36f873e8 100644 --- a/libtest/lite.h +++ b/libtest/lite.h @@ -140,6 +140,34 @@ do \ } \ } while (0) +#define SKIP_UNLESS(__expression) \ +do \ +{ \ + if (! (__expression)) { \ + if (YATL_FULL) { \ + SKIP(#__expression); \ + } \ + fprintf(stdout, "\n%s:%d: %s SKIP '(%s)'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression); \ + exit(EXIT_SKIP); \ + } \ +} while (0) + +#define SKIP_UNLESS_(__expression, ...) \ +do \ +{ \ + if (! (__expression)) { \ + size_t ask= snprintf(0, 0, __VA_ARGS__); \ + ask++; \ + char *buffer= (char*)alloca(sizeof(char) * ask); \ + snprintf(buffer, ask, __VA_ARGS__); \ + if (YATL_FULL) { \ + SKIP(#__expression, buffer); \ + } \ + fprintf(stdout, "\n%s:%d: %s SKIP '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \ + exit(EXIT_SKIP); \ + } \ +} while (0) + #define ASSERT_TRUE(__expression) \ do \ { \ diff --git a/libtest/main.cc b/libtest/main.cc index 2ceeac92..46429241 100644 --- a/libtest/main.cc +++ b/libtest/main.cc @@ -297,7 +297,6 @@ int main(int argc, char *argv[]) std::auto_ptr<libtest::Framework> frame(new libtest::Framework(signal, binary_name, collection_to_run, wildcard)); // Run create(), bail on error. - try { switch (frame->create()) { @@ -305,17 +304,14 @@ int main(int argc, char *argv[]) break; case TEST_SKIPPED: - return EXIT_SKIP; + SKIP("SKIP was returned from framework create()"); + break; case TEST_FAILURE: std::cerr << "Could not call frame->create()" << std::endl; return EXIT_FAILURE; } } - catch (const libtest::__skipped& e) - { - return EXIT_SKIP; - } frame->exec(); diff --git a/libtest/result.cc b/libtest/result.cc index a102b4f7..3e4523d3 100644 --- a/libtest/result.cc +++ b/libtest/result.cc @@ -41,53 +41,9 @@ namespace libtest { __test_result::__test_result(const char *file_arg, int line_arg, const char *func_arg): - _line(line_arg), - _file(file_arg), - _func(func_arg), - _error_message(NULL), - _error_message_size(0) -{ -} - -#ifndef __INTEL_COMPILER -# pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif -void __test_result::init(va_list args_) -{ - const char *format= va_arg(args_, const char *); - _error_message_size= vasprintf(&_error_message, format, args_); - assert(_error_message_size != -1); - if (_error_message_size > 0) + libtest::exception(file_arg, line_arg, func_arg) { - _error_message_size++; } -} - -__test_result::~__test_result() throw() -{ - free(_error_message); -} - -__test_result::__test_result(const __test_result& other) : - std::exception(), - _line(other._line), - _file(other._file), - _func(other._func), - _error_message_size(other._error_message_size) -{ - if (_error_message_size > 0) - { - _error_message= (char*) malloc(_error_message_size); - if (_error_message) - { - memcpy(_error_message, other._error_message, _error_message_size); - } - else - { - _error_message_size= -1; - } - } -} __success::__success(const char *file_arg, int line_arg, const char *func_arg): __test_result(file_arg, line_arg, func_arg) diff --git a/libtest/result.hpp b/libtest/result.hpp index 0c78b998..79acbb40 100644 --- a/libtest/result.hpp +++ b/libtest/result.hpp @@ -36,10 +36,8 @@ #pragma once -#include <libtest/fatal.hpp> #include <libtest/result/base.hpp> #include <libtest/result/fail.hpp> -#include <libtest/result/fatal.hpp> #include <libtest/result/skip.hpp> #include <libtest/result/success.hpp> @@ -56,27 +54,3 @@ do \ { \ throw libtest::__failure(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \ } while (0) - -#define FATAL(...) \ -do \ -{ \ - throw libtest::fatal(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \ -} while (0) - -#define FATAL_IF(__expression, ...) \ -do \ -{ \ - if ((__expression)) { \ - throw libtest::fatal(LIBYATL_DEFAULT_PARAM, (#__expression)); \ - } \ -} while (0) - -#define FATAL_IF_(__expression, ...) \ -do \ -{ \ - if ((__expression)) { \ - throw libtest::fatal(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \ - } \ -} while (0) - -#define fatal_assert(__assert) if((__assert)) {} else { throw libtest::fatal(LIBYATL_DEFAULT_PARAM, #__assert); } diff --git a/libtest/result/base.hpp b/libtest/result/base.hpp index 51ee995d..5f093f83 100644 --- a/libtest/result/base.hpp +++ b/libtest/result/base.hpp @@ -36,51 +36,19 @@ #pragma once +#include "libtest/exception.hpp" +#include "libtest/error.h" + namespace libtest { -class __test_result : public std::exception +class __test_result : public libtest::exception { public: __test_result(const char *file, int line, const char *func); - __test_result( const __test_result& ); - - virtual ~__test_result() throw(); - - virtual const char* what() const throw() - { - if (_error_message) - { - return _error_message; - } - - return ""; - } - - int line() const - { - return _line; - } - - const char* file() const - { - return _file; - } - - const char* func() const - { - return _func; - } - -protected: - void init(va_list); + virtual test_return_t return_code() const= 0; private: - int _line; - const char* _file; - const char* _func; - char* _error_message; - int _error_message_size; }; } // namespace libtest diff --git a/libtest/result/fail.hpp b/libtest/result/fail.hpp index fd8766a9..3aec9c1e 100644 --- a/libtest/result/fail.hpp +++ b/libtest/result/fail.hpp @@ -45,6 +45,11 @@ public: __failure(const __failure&); + test_return_t return_code() const + { + return TEST_FAILURE; + } + private: }; diff --git a/libtest/result/skip.hpp b/libtest/result/skip.hpp index d0226e9f..7409d718 100644 --- a/libtest/result/skip.hpp +++ b/libtest/result/skip.hpp @@ -44,6 +44,11 @@ public: __skipped(const char *file, int line, const char *func, ...); __skipped(const __skipped&); + + test_return_t return_code() const + { + return TEST_SKIPPED; + } }; } // namespace libtest diff --git a/libtest/result/success.hpp b/libtest/result/success.hpp index 2931f2d0..a34e677e 100644 --- a/libtest/result/success.hpp +++ b/libtest/result/success.hpp @@ -48,6 +48,11 @@ public: return "SUCCESS"; } + test_return_t return_code() const + { + return TEST_SUCCESS; + } + private: }; diff --git a/libtest/run.gdb b/libtest/run.gdb index 25dcdd53..c35ab767 100644 --- a/libtest/run.gdb +++ b/libtest/run.gdb @@ -2,5 +2,6 @@ set logging on set logging overwrite on set environment LIBTEST_IN_GDB=1 #set ASAN_OPTIONS=abort_on_error=1 +handle SIGVTALRM stop run thread apply all bt diff --git a/libtest/test.hpp b/libtest/test.hpp index 7c18d6bc..d9040700 100644 --- a/libtest/test.hpp +++ b/libtest/test.hpp @@ -65,7 +65,10 @@ #include <libtest/version.h> #include <libtest/vchar.hpp> -#include <libtest/fatal.hpp> +#include <libtest/error.h> +#include <libtest/exception.hpp> +#include <libtest/exception/disconnected.hpp> +#include <libtest/exception/fatal.hpp> #include <libtest/result.hpp> #include <libtest/has.hpp> diff --git a/libtest/tmpfile.cc b/libtest/tmpfile.cc index a88c0ede..425a21e7 100644 --- a/libtest/tmpfile.cc +++ b/libtest/tmpfile.cc @@ -40,7 +40,7 @@ namespace libtest { -std::string create_tmpfile(const std::string& name) +std::string create_tmpfile(const std::string& name, int& fd) { libtest::vchar_t file_buffer; file_buffer.resize(FILENAME_MAX); @@ -49,15 +49,22 @@ std::string create_tmpfile(const std::string& name) int length= snprintf(&file_buffer[0], file_buffer.size(), "var/tmp/%s.XXXXXX", name.c_str()); fatal_assert(length > 0); - int fd; if ((fd= mkstemp(&file_buffer[0])) == -1) { throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "mkstemp() failed on %s with %s", &file_buffer[0], strerror(errno)); } - close(fd); - unlink(&file_buffer[0]); return &file_buffer[0]; } +std::string create_tmpfile(const std::string& name) +{ + int fd; + std::string ret_file= create_tmpfile(name, fd); + close(fd); + unlink(ret_file.c_str()); + + return ret_file.c_str(); +} + } // namespace libtest diff --git a/libtest/tmpfile.hpp b/libtest/tmpfile.hpp index 0eb8dca2..9283b84a 100644 --- a/libtest/tmpfile.hpp +++ b/libtest/tmpfile.hpp @@ -40,6 +40,7 @@ namespace libtest { +std::string create_tmpfile(const std::string&, int&); std::string create_tmpfile(const std::string&); } // namespace libtest diff --git a/libtest/unittest.cc b/libtest/unittest.cc index 1663e59a..bbb56c66 100644 --- a/libtest/unittest.cc +++ b/libtest/unittest.cc @@ -142,6 +142,25 @@ static test_return_t test_throw_skip_macro_TEST(void *) return TEST_FAILURE; } +static test_return_t test_throw_skip_unless_macro_TEST(void *) +{ + try { + SKIP_UNLESS(false); + } + catch (const libtest::__skipped&) + { + return TEST_SUCCESS; + } + catch (...) + { + FAIL("SLIP_UNLESS() failed to throw libtest::_skipped"); + } + + FAIL("SLIP_UNLESS() failed to throw"); + + return TEST_FAILURE; +} + static test_return_t test_throw_skip_TEST(void *) { try { @@ -941,6 +960,12 @@ static test_return_t default_port_TEST(void *) return TEST_SUCCESS; } +static test_return_t check_for_VALGRIND(void *) +{ + test_skip_valgrind(); + return TEST_SUCCESS; +} + static test_return_t check_for_gearman(void *) { test_skip(true, HAVE_LIBGEARMAN); @@ -1043,6 +1068,7 @@ test_st tests_log[] ={ {"SUCCESS", false, test_throw_success_TEST }, {"libtest::__skipped", false, test_throw_skip_TEST }, {"SKIP_IF", false, test_throw_skip_macro_TEST }, + {"SKIP_UNLESS", false, test_throw_skip_unless_macro_TEST }, {"FAIL", false, test_throw_fail_TEST }, {"ASSERT_FALSE_", false, ASSERT_FALSE__TEST }, {"ASSERT_FALSE", false, ASSERT_FALSE_TEST }, @@ -1186,7 +1212,7 @@ collection_st collection[] ={ {"fatal", disable_fatal_exception, enable_fatal_exception, fatal_message_TESTS }, {"number_of_cpus()", 0, 0, number_of_cpus_TESTS }, {"create_tmpfile()", 0, 0, create_tmpfile_TESTS }, - {"dns", 0, 0, dns_TESTS }, + {"dns", check_for_VALGRIND, 0, dns_TESTS }, {"libtest::Timer", 0, 0, timer_TESTS }, {0, 0, 0, 0} }; diff --git a/libtest/yatl.m4 b/libtest/yatl.m4 index 61d1a2f0..0e88425d 100644 --- a/libtest/yatl.m4 +++ b/libtest/yatl.m4 @@ -7,7 +7,6 @@ AC_SUBST([LIBTEST_VERSION],[1.0]) AC_CONFIG_FILES([libtest/version.h]) m4_include([libtest/m4/mysql.m4]) -AC_DEFINE([HAVE_MEMCACHED_SASL_BINARY],[0],[If Memcached binary with sasl support is available]) YATL_MYSQL diff --git a/m4/ax_append_to_file.m4 b/m4/ax_append_to_file.m4 index c88affb4..f9f54e08 100644 --- a/m4/ax_append_to_file.m4 +++ b/m4/ax_append_to_file.m4 @@ -19,9 +19,9 @@ # and this notice are preserved. This file is offered as-is, without any # warranty. -#serial 7 +#serial 8 AC_DEFUN([AX_APPEND_TO_FILE],[ AC_REQUIRE([AX_FILE_ESCAPES]) -printf "$2" >> "$1" +printf "$2\n" >> "$1" ]) diff --git a/m4/ax_harden_compiler_flags.m4 b/m4/ax_harden_compiler_flags.m4 index b3b93921..d4fccad6 100644 --- a/m4/ax_harden_compiler_flags.m4 +++ b/m4/ax_harden_compiler_flags.m4 @@ -15,7 +15,7 @@ # # LICENSE # -# Copyright (C) 2012 Brian Aker +# Copyright (C) 2012-2013 Brian Aker # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -45,15 +45,15 @@ # 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. +# +# Notes: +# We do not test for c99 or c++11, that is out of scope. # The Following flags are not checked for # -Wdeclaration-after-statement is counter to C99 -# _APPEND_COMPILE_FLAGS_ERROR([-std=c++11]) -- Not ready yet -# _APPEND_COMPILE_FLAGS_ERROR([-pedantic]) -- -# ? _APPEND_COMPILE_FLAGS_ERROR([-Wlong-long]) -- Don't turn on for -# compatibility issues memcached_stat_st +# _APPEND_COMPILE_FLAGS_ERROR([-pedantic]) -#serial 9 +#serial 10 AC_DEFUN([_WARNINGS_AS_ERRORS], [AC_CACHE_CHECK([if all warnings into errors],[ac_cv_warnings_as_errors], @@ -76,13 +76,12 @@ AC_DEFUN([_APPEND_COMPILE_FLAGS_ERROR], # Everything above this does the heavy lifting, while what follows does the specifics. AC_DEFUN([_HARDEN_LINKER_FLAGS], - [ - AS_IF([test "$CC" != "clang"], - [_APPEND_LINK_FLAGS_ERROR([-z relro -z now]) -#_APPEND_LINK_FLAGS_ERROR([-pie]) - AS_IF([test "x$ac_cv_warnings_as_errors" = xyes], - [AX_APPEND_LINK_FLAGS([-Werror])])]) - ]) + [AS_IF([test "$CC" != "clang"], + [_APPEND_LINK_FLAGS_ERROR([-z relro -z now]) + AS_IF([test "x$ac_cv_warnings_as_errors" = xyes],[AX_APPEND_LINK_FLAGS([-Werror])]) + AS_IF([test "x$ac_cv_vcs_checkout" = xyes],[_APPEND_LINK_FLAGS_ERROR([-rdynamic])]) + ]) + ]) AC_DEFUN([_HARDEN_CC_COMPILER_FLAGS], [AC_LANG_PUSH([C])dnl @@ -106,13 +105,12 @@ AC_DEFUN([_HARDEN_CC_COMPILER_FLAGS], [_APPEND_COMPILE_FLAGS_ERROR([-Wno-unknown-pragmas]) _APPEND_COMPILE_FLAGS_ERROR([-Wno-pragmas])]) - AS_IF([test "$CC" = "clang"], - [_APPEND_COMPILE_FLAGS_ERROR([-Qunused-arguments])]) + AS_IF([test "$CC" = "clang"],[_APPEND_COMPILE_FLAGS_ERROR([-Qunused-arguments])]) _APPEND_COMPILE_FLAGS_ERROR([-Wall]) _APPEND_COMPILE_FLAGS_ERROR([-Wextra]) + _APPEND_COMPILE_FLAGS_ERROR([-Weverything]) _APPEND_COMPILE_FLAGS_ERROR([-Wthis-test-should-fail]) - _APPEND_COMPILE_FLAGS_ERROR([-std=c99]) # Anything below this comment please keep sorted. # _APPEND_COMPILE_FLAGS_ERROR([-Wmissing-format-attribute]) _APPEND_COMPILE_FLAGS_ERROR([-Wunsuffixed-float-constants]) @@ -147,7 +145,6 @@ AC_DEFUN([_HARDEN_CC_COMPILER_FLAGS], _APPEND_COMPILE_FLAGS_ERROR([-Wno-suggest-attribute=pure]) _APPEND_COMPILE_FLAGS_ERROR([-Wno-redundant-decls])], [_APPEND_COMPILE_FLAGS_ERROR([-Wredundant-decls])]) - _APPEND_COMPILE_FLAGS_ERROR([-Wshadow]) _APPEND_COMPILE_FLAGS_ERROR([-Wshorten-64-to-32]) _APPEND_COMPILE_FLAGS_ERROR([-Wsign-compare]) @@ -158,30 +155,32 @@ AC_DEFUN([_HARDEN_CC_COMPILER_FLAGS], _APPEND_COMPILE_FLAGS_ERROR([-Wundef]) _APPEND_COMPILE_FLAGS_ERROR([-Wunsafe-loop-optimizations]) _APPEND_COMPILE_FLAGS_ERROR([-funsafe-loop-optimizations]) - AS_IF([test "x$ac_cv_vcs_checkout" = xyes],[ - _APPEND_COMPILE_FLAGS_ERROR([-fno-omit-frame-pointer]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=address]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=integer]) - AS_IF([test "x$enable_shared" = "xyes"],[ + AS_IF([test "x$MINGW" != xyes],[ + AS_IF([test "x$ac_cv_vcs_checkout" = xyes],[ + AS_IF([test "x$enable_shared" = "xyes"],[ + _APPEND_COMPILE_FLAGS_ERROR([-fno-omit-frame-pointer]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=address]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=integer]) _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=thread]) - ]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=memory]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=alignment]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=bool]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=bounds]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=enum]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=float-cast-overflow]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=float-divide-by-zero]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=integer-divide-by-zero]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=null]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=object-size]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=return]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=shift]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=signed-integer-overflow]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=unreachable]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=unsigned-integer-overflow]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=vla-bound]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=vptr]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=memory]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=alignment]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=bool]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=bounds]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=enum]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=float-cast-overflow]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=float-divide-by-zero]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=integer-divide-by-zero]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=null]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=object-size]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=return]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=shift]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=signed-integer-overflow]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=unreachable]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=unsigned-integer-overflow]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=vla-bound]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=vptr]) + ]) + ]) ]) _APPEND_COMPILE_FLAGS_ERROR([-Wclobbered]) _APPEND_COMPILE_FLAGS_ERROR([-Wunused]) @@ -194,7 +193,11 @@ AC_DEFUN([_HARDEN_CC_COMPILER_FLAGS], _APPEND_COMPILE_FLAGS_ERROR([-fwrapv]) _APPEND_COMPILE_FLAGS_ERROR([-fmudflapt]) _APPEND_COMPILE_FLAGS_ERROR([-pipe]) + _APPEND_COMPILE_FLAGS_ERROR([-fPIE -pie]) _APPEND_COMPILE_FLAGS_ERROR([-Wsizeof-pointer-memaccess]) + _APPEND_COMPILE_FLAGS_ERROR([-Wpacked]) +# _APPEND_COMPILE_FLAGS_ERROR([-Wlong-long]) + _APPEND_COMPILE_FLAGS_ERROR([-Wunreachable-code]) AS_IF([test "x$ax_enable_debug" = xno], [AS_IF([test "x$ac_cv_vcs_checkout" = xyes], @@ -202,8 +205,7 @@ AC_DEFUN([_HARDEN_CC_COMPILER_FLAGS], [AS_IF([test "x$ac_c_gcc_recent" = xyes], [_APPEND_COMPILE_FLAGS_ERROR([-D_FORTIFY_SOURCE=2]) #_APPEND_COMPILE_FLAGS_ERROR([-Wstack-protector]) - #_APPEND_COMPILE_FLAGS_ERROR([-fstack-protector]) - #_APPEND_COMPILE_FLAGS_ERROR([--param=ssp-buffer-size=1]) + #_APPEND_COMPILE_FLAGS_ERROR([-fstack-protector --param=ssp-buffer-size=4]) _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector-all]) ])])])]) @@ -236,11 +238,11 @@ AC_DEFUN([_HARDEN_CXX_COMPILER_FLAGS], [_APPEND_COMPILE_FLAGS_ERROR([-Wno-unknown-pragmas]) _APPEND_COMPILE_FLAGS_ERROR([-Wno-pragmas])]) - AS_IF([test "$CXX" = "clang++"], - [_APPEND_COMPILE_FLAGS_ERROR([-Qunused-arguments])]) + AS_IF([test "$CXX" = "clang++"],[_APPEND_COMPILE_FLAGS_ERROR([-Qunused-arguments])]) _APPEND_COMPILE_FLAGS_ERROR([-Wall]) _APPEND_COMPILE_FLAGS_ERROR([-Wextra]) + _APPEND_COMPILE_FLAGS_ERROR([-Weverything]) _APPEND_COMPILE_FLAGS_ERROR([-Wthis-test-should-fail]) # Anything below this comment please keep sorted. # _APPEND_COMPILE_FLAGS_ERROR([-Wmissing-format-attribute]) @@ -280,30 +282,32 @@ AC_DEFUN([_HARDEN_CXX_COMPILER_FLAGS], _APPEND_COMPILE_FLAGS_ERROR([-funsafe-loop-optimizations]) _APPEND_COMPILE_FLAGS_ERROR([-Wc++11-compat]) # _APPEND_COMPILE_FLAGS_ERROR([-Weffc++]) - AS_IF([test "x$ac_cv_vcs_checkout" = xyes],[ - _APPEND_COMPILE_FLAGS_ERROR([-fno-omit-frame-pointer]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=address]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=integer]) - AS_IF([test "x$enable_shared" = "xyes"],[ + AS_IF([test "x$MINGW" != xyes],[ + AS_IF([test "x$ac_cv_vcs_checkout" = xyes],[ + AS_IF([test "x$enable_shared" = "xyes"],[ + _APPEND_COMPILE_FLAGS_ERROR([-fno-omit-frame-pointer]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=address]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=integer]) _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=thread]) - ]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=memory]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=alignment]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=bool]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=bounds]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=enum]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=float-cast-overflow]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=float-divide-by-zero]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=integer-divide-by-zero]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=null]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=object-size]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=return]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=shift]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=signed-integer-overflow]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=unreachable]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=unsigned-integer-overflow]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=vla-bound]) - _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=vptr]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=memory]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=alignment]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=bool]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=bounds]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=enum]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=float-cast-overflow]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=float-divide-by-zero]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=integer-divide-by-zero]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=null]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=object-size]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=return]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=shift]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=signed-integer-overflow]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=unreachable]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=unsigned-integer-overflow]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=vla-bound]) + _APPEND_COMPILE_FLAGS_ERROR([-fsanitize=vptr]) + ]) + ]) ]) # _APPEND_COMPILE_FLAGS_ERROR([-Wold-style-cast]) _APPEND_COMPILE_FLAGS_ERROR([-Wclobbered]) @@ -318,7 +322,11 @@ AC_DEFUN([_HARDEN_CXX_COMPILER_FLAGS], _APPEND_COMPILE_FLAGS_ERROR([-fwrapv]) _APPEND_COMPILE_FLAGS_ERROR([-fmudflapt]) _APPEND_COMPILE_FLAGS_ERROR([-pipe]) + _APPEND_COMPILE_FLAGS_ERROR([-fPIE -pie]) _APPEND_COMPILE_FLAGS_ERROR([-Wsizeof-pointer-memaccess]) + _APPEND_COMPILE_FLAGS_ERROR([-Wpacked]) +# _APPEND_COMPILE_FLAGS_ERROR([-Wlong-long]) + _APPEND_COMPILE_FLAGS_ERROR([-Wunreachable-code]) AS_IF([test "x$ax_enable_debug" = xno], [AS_IF([test "x$ac_cv_vcs_checkout" = xyes], @@ -326,8 +334,7 @@ AC_DEFUN([_HARDEN_CXX_COMPILER_FLAGS], [AS_IF([test "x$ac_c_gcc_recent" = xyes], [_APPEND_COMPILE_FLAGS_ERROR([-D_FORTIFY_SOURCE=2]) #_APPEND_COMPILE_FLAGS_ERROR([-Wstack-protector]) - #_APPEND_COMPILE_FLAGS_ERROR([-fstack-protector]) - #_APPEND_COMPILE_FLAGS_ERROR([--param=ssp-buffer-size=1]) + #_APPEND_COMPILE_FLAGS_ERROR([-fstack-protector --param=ssp-buffer-size=4]) _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector-all]) ])])])]) diff --git a/m4/ax_memcached.m4 b/m4/ax_memcached.m4 index 21067c68..160cfe32 100644 --- a/m4/ax_memcached.m4 +++ b/m4/ax_memcached.m4 @@ -44,15 +44,26 @@ # (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 3 +#serial 4 AC_DEFUN([AX_PROG_MEMCACHED], - [AX_WITH_PROG([MEMCACHED_BINARY],[memcached]) - AS_IF([test -f "$ac_cv_path_MEMCACHED_BINARY"], - [AC_DEFINE([HAVE_MEMCACHED_BINARY], [1], [If Memcached binary is available]) - AC_DEFINE_UNQUOTED([MEMCACHED_BINARY],"$ac_cv_path_MEMCACHED_BINARY",[Name of the memcached binary used in make test]) - ax_memcached_version=`$MEMCACHED_BINARY -h | sed 1q | awk '{print \$ 2 }' | sed 's|[\-a-z0-9]*$||' | awk -F. '{printf "%d.%d.%d", $[]1, $[]2, $[]3}'` - AC_MSG_RESULT([memcached version "$ax_memcached_version"]) - AC_DEFINE_UNQUOTED([MEMCACHED_VERSION],"$ax_memcached_version",[Memcached binary version]) - ]) - ]) + [AX_WITH_PROG([MEMCACHED_BINARY],[memcached],[unknown]) + ax_memcached_success= + AS_IF([test x"$MEMCACHED_BINARY" != xunknown], + [AS_IF([test -x "$MEMCACHED_BINARY"], + [ax_memcached_version=`$MEMCACHED_BINARY -h | sed 1q | awk '{print \$ 2 }' | sed 's|[\-a-z0-9]*$||' | awk -F. '{printf "%d.%d.%d", $[]1, $[]2, $[]3}'` + AS_IF([test -n "$ax_memcached_version"], + [ax_memcached_success='ok' + AC_MSG_RESULT([memcached version "$ax_memcached_version"]) + AC_DEFINE_UNQUOTED([MEMCACHED_VERSION],"$ax_memcached_version",[Memcached binary version])]) + ]) + ]) + + AS_IF([test -n "$ax_memcached_success"], + [AC_DEFINE([HAVE_MEMCACHED_BINARY], [1], [If Memcached binary is available]) + AC_DEFINE_UNQUOTED([MEMCACHED_BINARY],"$MEMCACHED_BINARY",[Name of the memcached binary used in make test]) + ], + [AC_DEFINE([HAVE_MEMCACHED_BINARY], [0], [If Memcached binary is available]) + MEMCACHED_BINARY= + ]) + ]) diff --git a/m4/ax_prog_sphinx_build.m4 b/m4/ax_prog_sphinx_build.m4 index cbbf1723..3a89a331 100644 --- a/m4/ax_prog_sphinx_build.m4 +++ b/m4/ax_prog_sphinx_build.m4 @@ -4,42 +4,41 @@ # # SYNOPSIS # -# AX_PROG_SPHINX_BUILD() +# AX_PROG_SPHINX_BUILD([ACTION-IF-FOUND], [ACTION-IF-NOT_FOUND]) # # DESCRIPTION # -# Look for sphinx-build +# Look for sphinx-build and make sure it is a recent version of it. # # LICENSE # -# Copyright (c) 2012 Brian Aker <brian@tangent.org> +# Copyright (c) 2012-2013 Brian Aker <brian@tangent.org> # # Copying and distribution of this file, with or without modification, are # permitted in any medium without royalty provided the copyright notice # and this notice are preserved. This file is offered as-is, without any # warranty. -#serial 2 +#serial 3 AC_DEFUN([AX_PROG_SPHINX_BUILD], - [AC_PREREQ([2.63])dnl - AC_CHECK_PROGS([PERL], [perl]) - AC_CHECK_PROGS([DPKG_GENSYMBOLS], [dpkg-gensymbols], [:]) - AC_CHECK_PROGS([LCOV], [lcov], [echo lcov not found]) - AC_CHECK_PROGS([LCOV_GENHTML], [genhtml], [echo genhtml not found]) - - AC_CHECK_PROGS([SPHINXBUILD], [sphinx-build], [:]) - AS_IF([test "x${SPHINXBUILD}" != "x:"],[ - AC_CACHE_CHECK([if sphinx is new enough],[ac_cv_recent_sphinx],[ - - ${SPHINXBUILD} -Q -C -b man -d conftest.d . . >/dev/null 2>&1 - AS_IF([test $? -eq 0],[ac_cv_recent_sphinx=yes], - [ac_cv_recent_sphinx=no]) + [AX_WITH_PROG([SPHINXBUILD],[sphinx-build],[:]) + AS_IF([test x"SPHINXBUILD" = x":"], + [SPHINXBUILD=], + [AS_IF([test -x "$SPHINXBUILD"], + [AC_MSG_CHECKING([Checking to see if $SPHINXBUILD is recent]) + junk=`$SPHINXBUILD &> version_file` + ax_sphinx_build_version=`head -1 version_file` + rm version_file + AC_MSG_RESULT([$SPHINXBUILD is version "$ax_sphinx_build_version"]) + $SPHINXBUILD -Q -C -b man -d conftest.d . . >/dev/null 2>&1 + AS_IF([test $? -eq 0], ,[SPHINXBUILD=]) rm -rf conftest.d ]) ]) - AM_CONDITIONAL([HAVE_DPKG_GENSYMBOLS],[test "x${DPKG_GENSYMBOLS}" != "x:"]) - AM_CONDITIONAL([HAVE_SPHINX],[test "x${SPHINXBUILD}" != "x:"]) - AM_CONDITIONAL([HAVE_RECENT_SPHINX],[test "x${ac_cv_recent_sphinx}" = "xyes"]) -]) + AS_IF([test -n "${SPHINXBUILD}"], + [AC_SUBST([SPHINXBUILD]) + ifelse([$1], , :, [$1])], + [ifelse([$2], , :, [$2])]) + ]) diff --git a/m4/ax_uuid.m4 b/m4/ax_uuid.m4 index 93c5f89f..293fdfc5 100644 --- a/m4/ax_uuid.m4 +++ b/m4/ax_uuid.m4 @@ -6,22 +6,23 @@ # SYNOPSIS # # AX_UUID() +# AX_UUID_GENERATE_TIME() # AX_UUID_GENERATE_TIME_SAFE() # # DESCRIPTION # -# Check for uuid, and uuid_generate_time_safe support. +# Check for uuid, uuid_generate_time, and uuid_generate_time_safe support. # # LICENSE # -# Copyright (c) 2012 Brian Aker <brian@tangent.org> +# Copyright (c) 2012-2013 Brian Aker <brian@tangent.org> # # Copying and distribution of this file, with or without modification, are # permitted in any medium without royalty provided the copyright notice # and this notice are preserved. This file is offered as-is, without any # warranty. -#serial 6 +#serial 7 AC_DEFUN([AX_UUID], [AC_PREREQ([2.63])dnl @@ -72,6 +73,31 @@ AC_DEFUN([AX_UUID], AM_CONDITIONAL([HAVE_LIBUUID],[test "x$ax_libuuid" = xyes]) ]) + AC_DEFUN([AX_UUID_GENERATE_TIME], + [AC_PREREQ([2.63])dnl + AC_REQUIRE([AX_UUID])dnl + AC_CACHE_CHECK([for uuid_generate_time], + [ax_cv_uuid_generate_time], + [AX_SAVE_FLAGS + LIBS="$LIBUUID_LIB $LIBS" + AC_LANG_PUSH([C]) + AC_RUN_IFELSE([ + AC_LANG_PROGRAM([#include <uuid/uuid.h>],[ + uuid_t out; + uuid_generate_time(out); + ])], + [ax_cv_uuid_generate_time=yes], + [ax_cv_uuid_generate_time=no], + [AC_MSG_WARN([test program execution failed])]) + AC_LANG_POP + AX_RESTORE_FLAGS + ]) + + AS_IF([test "$ax_cv_uuid_generate_time" = yes], + [AC_DEFINE([HAVE_UUID_GENERATE_TIME],[1],[Define if uuid_generate_time is present in uuid/uuid.h.])], + [AC_DEFINE([HAVE_UUID_GENERATE_TIME],[0],[Define if uuid_generate_time is present in uuid/uuid.h.])]) + ]) + AC_DEFUN([AX_UUID_GENERATE_TIME_SAFE], [AC_PREREQ([2.63])dnl AC_REQUIRE([AX_UUID])dnl diff --git a/man/include.am b/man/include.am index 3b68557a..602cfa96 100644 --- a/man/include.am +++ b/man/include.am @@ -2,18 +2,11 @@ # included from Top Level Makefile.am # All paths should be given relative to the root -if HAVE_RECENT_SPHINX -if IS_VCS_CHECKOUT - -dist-hook: man - # Build rule for documentation -$(dist_man_MANS): man - -BUILT_SOURCES+= $(dist_man_MANS) +$(dist_man_MANS): $(top_srcdir)/configure.ac + $(MAKE) $(AM_MAKEFLAGS) man -endif -endif +.NOTPARALLEL: $(dist_man_MANS) dist_man_MANS+= man/memaslap.1 dist_man_MANS+= man/memcapable.1 diff --git a/tests/cli.am b/tests/cli.am index 573be2af..df206e5c 100644 --- a/tests/cli.am +++ b/tests/cli.am @@ -99,6 +99,12 @@ tests_memdump_LDADD= libtest/libtest.la $(TESTS_LDADDS) check_PROGRAMS+= tests/memdump noinst_PROGRAMS+= tests/memdump +test-memcp: tests/memcp + tests/memcp + +gdb-memcp: tests/memcp + @$(GDB_COMMAND) tests/memcp + test-memstat: tests/memstat tests/memstat diff --git a/tests/include.am b/tests/include.am index 44fdbfa3..414b143b 100644 --- a/tests/include.am +++ b/tests/include.am @@ -98,6 +98,9 @@ valgrind-memcapable: tests/memcapable pahole-mem: tests/testapp @$(PAHOLE_COMMAND) tests/testapp +pahole-hash: tests/testhashkit + @$(PAHOLE_COMMAND) tests/testhashkit + gdb-mem: tests/libmemcached-1.0/testapp @$(GDB_COMMAND) tests/libmemcached-1.0/testapp @@ -148,3 +151,9 @@ helgrind-hash: tests/testhashkit helgrind-hashplus: tests/hash_plus @$(HELGRIND_COMMAND) tests/hash_plus + +drd-mem: tests/libmemcached-1.0/testapp + @$(DRD_COMMAND) tests/libmemcached-1.0/testapp + +drd-cycle: tests/cycle + @$(DRD_COMMAND) tests/cycle diff --git a/tests/libmemcached_world.h b/tests/libmemcached_world.h index 3dda2d8a..6bed25a9 100644 --- a/tests/libmemcached_world.h +++ b/tests/libmemcached_world.h @@ -43,26 +43,12 @@ static void *world_create(libtest::server_startup_st& servers, test_return_t& error) { - if (libtest::has_memcached() == false) - { - error= TEST_SKIPPED; - return NULL; - } + SKIP_UNLESS(libtest::has_libmemcached()); if (servers.sasl()) { - if (LIBMEMCACHED_WITH_SASL_SUPPORT == 0) - { - error= TEST_SKIPPED; - return NULL; - } + SKIP_UNLESS(libtest::has_libmemcached_sasl()); - if (HAVE_MEMCACHED_SASL_BINARY == 0) - { - error= TEST_SKIPPED; - return NULL; - } - // Assume we are running under valgrind, and bail if (getenv("TESTS_ENVIRONMENT")) { diff --git a/tests/memcapable.cc b/tests/memcapable.cc index 054342c3..f43c1acb 100644 --- a/tests/memcapable.cc +++ b/tests/memcapable.cc @@ -47,14 +47,16 @@ using namespace libtest; #ifndef __INTEL_COMPILER -#pragma GCC diagnostic ignored "-Wstrict-aliasing" +# pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif static std::string executable; static test_return_t quiet_test(void *) { - const char *args[]= { "-q", 0 }; + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "%d", int(get_free_port())); + const char *args[]= { "-p", buffer, "-q", 0 }; test_compare(EXIT_FAILURE, exec_cmdline(executable, args, true)); @@ -74,7 +76,7 @@ static test_return_t ascii_test(void *) { char buffer[1024]; snprintf(buffer, sizeof(buffer), "%d", int(default_port())); - const char *args[]= { "-p", buffer, " -a ", 0 }; + const char *args[]= { "-p", buffer, "-a", 0 }; test_true(exec_cmdline(executable, args, true) <= EXIT_FAILURE); @@ -85,7 +87,7 @@ static test_return_t binary_test(void *) { char buffer[1024]; snprintf(buffer, sizeof(buffer), "%d", int(default_port())); - const char *args[]= { "-p", buffer, " -b ", 0 }; + const char *args[]= { "-p", buffer, "-b", 0 }; test_true(exec_cmdline(executable, args, true) <= EXIT_FAILURE); @@ -105,18 +107,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_SKIPPED; - } + SKIP_UNLESS(libtest::has_memcached()); + + SKIP_UNLESS(server_startup(servers, "memcached", libtest::default_port(), NULL)); return &servers; } diff --git a/tests/memcp.cc b/tests/memcp.cc index 9c9f4d62..4139437b 100644 --- a/tests/memcp.cc +++ b/tests/memcp.cc @@ -44,6 +44,8 @@ #include <libtest/test.hpp> #include <libmemcached-1.2/memcached.h> +#include <sys/stat.h> + using namespace libtest; #ifndef __INTEL_COMPILER @@ -63,11 +65,20 @@ static test_return_t help_test(void *) static test_return_t server_test(void *) { + int fd; + std::string tmp_file= create_tmpfile("memcp", fd); + ASSERT_TRUE(tmp_file.c_str()); + struct stat buf; + ASSERT_EQ(fstat(fd, &buf), 0); + ASSERT_EQ(buf.st_size, 0); + char buffer[1024]; snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); - const char *args[]= { buffer, 0 }; + const char *args[]= { buffer, tmp_file.c_str(), 0 }; test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true)); + close(fd); + unlink(tmp_file.c_str()); return TEST_SUCCESS; } diff --git a/version.m4 b/version.m4 new file mode 100644 index 00000000..b50ce773 --- /dev/null +++ b/version.m4 @@ -0,0 +1 @@ +m4_define([VERSION_NUMBER], [1.1.0]) |