From 25efe3485198149616820ab4e52d2f18f0abe5a7 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Sun, 1 Jul 2012 22:14:52 -0700 Subject: [PATCH] Import/Merge of libtest latest. --- Makefile.am | 2 +- configure.ac | 1 - libtest/collection.cc | 3 +- libtest/comparison.hpp | 44 +++---- libtest/fatal.cc | 4 +- libtest/framework.cc | 19 ++- libtest/gearmand.cc | 2 - libtest/has.cc | 6 +- libtest/m4/ax_lib_mysql.m4 | 147 ++++++++++++++++++++++ libtest/m4/ax_prog_memcached.m4 | 59 +++++++++ libtest/m4/ax_prog_mysqld.m4 | 58 +++++++++ {m4 => libtest/m4}/memcached.m4 | 1 + libtest/m4/mysql.m4 | 20 +++ libtest/main.cc | 16 ++- libtest/port.cc | 12 +- libtest/runner.cc | 3 +- libtest/server.cc | 89 +++++++------ libtest/server.h | 4 +- libtest/server_container.cc | 46 ++++--- libtest/server_container.h | 4 +- libtest/test.h | 66 ++-------- libtest/unittest.cc | 63 +++++----- libtest/yatl.m4 | 3 + tests/failure.cc | 16 ++- tests/hash_plus.cc | 4 +- tests/libmemcached-1.0/debug.cc | 4 +- tests/libmemcached-1.0/dump.cc | 21 ++-- tests/libmemcached-1.0/encoding_key.cc | 45 +++---- tests/libmemcached-1.0/exist.cc | 16 +-- tests/libmemcached-1.0/generate.cc | 24 ++-- tests/libmemcached-1.0/mem_functions.cc | 34 +++-- tests/libmemcached-1.0/memcached_get.cc | 30 +++-- tests/libmemcached-1.0/pool.cc | 9 +- tests/libmemcached-1.0/stat.cc | 21 ++-- tests/libmemcached-1.0/touch.cc | 2 +- tests/libmemcached-1.0/virtual_buckets.cc | 2 +- tests/runner.h | 7 +- 37 files changed, 586 insertions(+), 321 deletions(-) create mode 100644 libtest/m4/ax_lib_mysql.m4 create mode 100644 libtest/m4/ax_prog_memcached.m4 create mode 100644 libtest/m4/ax_prog_mysqld.m4 rename {m4 => libtest/m4}/memcached.m4 (97%) create mode 100644 libtest/m4/mysql.m4 diff --git a/Makefile.am b/Makefile.am index a977a2c5..fa4bf726 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ # vim:ft=automake -ACLOCAL_AMFLAGS = -I m4 +ACLOCAL_AMFLAGS = -I m4 -I libtest/m4 # includes append to these: SUFFIXES = diff --git a/configure.ac b/configure.ac index 9b54afb4..f15cfc8e 100644 --- a/configure.ac +++ b/configure.ac @@ -66,7 +66,6 @@ AX_CXX_HEADER_STDCXX_98 # Adding support for libtest m4_include([libtest/yatl.m4]) -m4_include([m4/memcached.m4]) m4_include([m4/memcached_sasl.m4]) m4_include([m4/gearmand.m4]) m4_include([m4/libgearman.m4]) diff --git a/libtest/collection.cc b/libtest/collection.cc index 1de74ade..3f85d0fe 100644 --- a/libtest/collection.cc +++ b/libtest/collection.cc @@ -120,8 +120,7 @@ test_return_t Collection::exec() } catch (libtest::fatal &e) { - Error << "Fatal exception was thrown: " << e.what(); - stream::cerr(__FILE__, __LINE__, __func__) << e.what(); + stream::cerr(e.file(), e.line(), e.func()) << e.what(); _failed++; throw; } diff --git a/libtest/comparison.hpp b/libtest/comparison.hpp index aecf05f0..32dc22fa 100644 --- a/libtest/comparison.hpp +++ b/libtest/comparison.hpp @@ -59,12 +59,12 @@ bool valgrind_is_caller(void); LIBTEST_API bool _in_valgrind(const char *file, int line, const char *func); -template -bool _compare_truth_hint(const char *file, int line, const char *func, T_comparable __expected, const char *assertation_label, T_hint __hint) +template +bool _compare_truth(const char *file, int line, const char *func, T_comparable __expected, const char *assertation_label) { if (__expected == false) { - libtest::stream::make_cerr(file, line, func) << "Assertation \"" << assertation_label << "\" failed, hint: " << __hint; + libtest::stream::make_cerr(file, line, func) << "Assertation \"" << assertation_label << "\""; return false; } @@ -122,26 +122,14 @@ bool _compare_zero(const char *file, int line, const char *func, T_comparable __ return true; } -template -bool _truth(const char *file, int line, const char *func, T_comparable __truth) -{ - if (bool(__truth)) - { - libtest::stream::make_cerr(file, line, func) << "Assertion failed for " << func << "() with \"" << __truth << "\""; - return false; - } - - return true; -} - -template -bool _compare_hint(const char *file, int line, const char *func, T1_comparable __expected, T2_comparable __actual, T_hint __hint, bool io_error= true) +template +bool _ne_compare(const char *file, int line, const char *func, T1_comparable __expected, T2_comparable __actual, bool io_error= true) { - if (__expected != __actual) + if (__expected == __actual) { if (io_error) { - libtest::stream::make_cerr(file, line, func) << "Expected \"" << __expected << "\" got \"" << __actual << "\"" << " Additionally: \"" << __hint << "\""; + libtest::stream::make_cerr(file, line, func) << "Expected \"" << __expected << "\" got \"" << __actual << "\""; } return false; @@ -150,20 +138,20 @@ bool _compare_hint(const char *file, int line, const char *func, T1_comparable _ return true; } -template -bool _ne_compare_hint(const char *file, int line, const char *func, T1_comparable __expected, T2_comparable __actual, T_hint __hint, bool io_error= true) +template +bool _assert_truth(const char *file, int line, const char *func, T_comparable __truth, T_expression_string __expression, const char* __explain= NULL) { - if (__expected == __actual) + if (__truth) { - if (io_error) - { - libtest::stream::make_cerr(file, line, func) << "Expected \"" << __expected << "\" got \"" << __actual << "\"" << " Additionally: \"" << __hint << "\""; - } + return true; + } - return false; + if (__explain) + { + libtest::stream::make_cerr(file, line, func) << "Assertion \"" << __expression << "\" warning:" << __explain; } - return true; + return false; } } // namespace libtest diff --git a/libtest/fatal.cc b/libtest/fatal.cc index 288d53a4..d4459662 100644 --- a/libtest/fatal.cc +++ b/libtest/fatal.cc @@ -54,7 +54,7 @@ fatal::fatal(const char *file_arg, int line_arg, const char *func_arg, const cha strncpy(_mesg, last_error, sizeof(_mesg)); - snprintf(_error_message, sizeof(_error_message), "%s:%d FATAL:%s (%s)", _file, _line, last_error, _func); + snprintf(_error_message, sizeof(_error_message), "%s", last_error); } static bool _disabled= false; @@ -101,7 +101,7 @@ 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:%d FATAL:%s (%s)", _file, _line, last_error, _func); + snprintf(_error_message, sizeof(_error_message), "%s", last_error); } } // namespace libtest diff --git a/libtest/framework.cc b/libtest/framework.cc index ea7ca665..daea4f4e 100644 --- a/libtest/framework.cc +++ b/libtest/framework.cc @@ -84,7 +84,7 @@ Framework::~Framework() for (std::vector::iterator iter= _collection.begin(); iter != _collection.end(); - iter++) + ++iter) { delete *iter; } @@ -104,7 +104,7 @@ void Framework::exec() { for (std::vector::iterator iter= _collection.begin(); iter != _collection.end() and (_signal.is_shutdown() == false); - iter++) + ++iter) { if (_only_run.empty() == false and fnmatch(_only_run.c_str(), (*iter)->name(), 0)) @@ -134,13 +134,20 @@ void Framework::exec() } catch (libtest::fatal& e) { + _failed++; stream::cerr(e.file(), e.line(), e.func()) << e.mesg(); } catch (libtest::disconnected& e) { + _failed++; Error << "Unhandled disconnection occurred:" << e.what(); throw; } + catch (...) + { + _failed++; + throw; + } Outn(); } @@ -151,7 +158,7 @@ uint32_t Framework::sum_total() uint32_t count= 0; for (std::vector::iterator iter= _collection.begin(); iter != _collection.end(); - iter++) + ++iter) { count+= (*iter)->total(); } @@ -164,7 +171,7 @@ uint32_t Framework::sum_success() uint32_t count= 0; for (std::vector::iterator iter= _collection.begin(); iter != _collection.end(); - iter++) + ++iter) { count+= (*iter)->success(); } @@ -177,7 +184,7 @@ uint32_t Framework::sum_skipped() uint32_t count= 0; for (std::vector::iterator iter= _collection.begin(); iter != _collection.end(); - iter++) + ++iter) { count+= (*iter)->skipped(); } @@ -190,7 +197,7 @@ uint32_t Framework::sum_failed() uint32_t count= 0; for (std::vector::iterator iter= _collection.begin(); iter != _collection.end(); - iter++) + ++iter) { count+= (*iter)->failed(); } diff --git a/libtest/gearmand.cc b/libtest/gearmand.cc index a70de37a..82953e99 100644 --- a/libtest/gearmand.cc +++ b/libtest/gearmand.cc @@ -94,9 +94,7 @@ public: gearman_client_free(client); return true; } -#if 0 Error << hostname().c_str() << ":" << port() << " was " << gearman_strerror(rc) << " extended: " << gearman_client_error(client); -#endif } else { diff --git a/libtest/has.cc b/libtest/has.cc index 72441819..ba4bbfc6 100644 --- a/libtest/has.cc +++ b/libtest/has.cc @@ -113,15 +113,13 @@ bool has_drizzled() bool has_mysqld() { -#if defined(HAVE_MYSQL_BUILD) && HAVE_MYSQL_BUILD - if (HAVE_MYSQL_BUILD) + if (HAVE_MYSQLD_BUILD) { - if (access(HAVE_MYSQL, X_OK) == 0) + if (access(MYSQLD_BINARY, X_OK) == 0) { return true; } } -#endif return false; } diff --git a/libtest/m4/ax_lib_mysql.m4 b/libtest/m4/ax_lib_mysql.m4 new file mode 100644 index 00000000..e27d755d --- /dev/null +++ b/libtest/m4/ax_lib_mysql.m4 @@ -0,0 +1,147 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_lib_mysql.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_LIB_MYSQL([MINIMUM-VERSION]) +# +# DESCRIPTION +# +# This macro provides tests of availability of MySQL client library of +# particular version or newer. +# +# AX_LIB_MYSQL macro takes only one argument which is optional. If there +# is no required version passed, then macro does not run version test. +# +# The --with-mysql option takes one of three possible values: +# +# no - do not check for MySQL client library +# +# yes - do check for MySQL library in standard locations (mysql_config +# should be in the PATH) +# +# path - complete path to mysql_config utility, use this option if +# mysql_config can't be found in the PATH +# +# This macro calls: +# +# AC_SUBST(MYSQL_CFLAGS) +# AC_SUBST(MYSQL_LDFLAGS) +# AC_SUBST(MYSQL_VERSION) +# +# And sets: +# +# HAVE_MYSQL +# +# LICENSE +# +# Copyright (c) 2008 Mateusz Loskot +# +# 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 12 + +AC_DEFUN([AX_LIB_MYSQL], +[ + AC_ARG_WITH([mysql], + AS_HELP_STRING([--with-mysql=@<:@ARG@:>@], + [use MySQL client library @<:@default=yes@:>@, optionally specify path to mysql_config] + ), + [ + if test "$withval" = "no"; then + want_mysql="no" + elif test "$withval" = "yes"; then + want_mysql="yes" + else + want_mysql="yes" + MYSQL_CONFIG="$withval" + fi + ], + [want_mysql="yes"] + ) + AC_ARG_VAR([MYSQL_CONFIG], [Full path to mysql_config program]) + + MYSQL_CFLAGS="" + MYSQL_LDFLAGS="" + MYSQL_VERSION="" + + dnl + dnl Check MySQL libraries + dnl + + if test "$want_mysql" = "yes"; then + + if test -z "$MYSQL_CONFIG" ; then + AC_PATH_PROGS([MYSQL_CONFIG], [mysql_config mysql_config5], [no]) + fi + + if test "$MYSQL_CONFIG" != "no"; then + MYSQL_CFLAGS="`$MYSQL_CONFIG --cflags`" + MYSQL_LDFLAGS="`$MYSQL_CONFIG --libs`" + + MYSQL_VERSION=`$MYSQL_CONFIG --version` + + found_mysql="yes" + else + found_mysql="no" + fi + fi + + dnl + dnl Check if required version of MySQL is available + dnl + + + mysql_version_req=ifelse([$1], [], [], [$1]) + + if test "$found_mysql" = "yes" -a -n "$mysql_version_req"; then + + AC_MSG_CHECKING([if MySQL version is >= $mysql_version_req]) + + dnl Decompose required version string of MySQL + dnl and calculate its number representation + mysql_version_req_major=`expr $mysql_version_req : '\([[0-9]]*\)'` + mysql_version_req_minor=`expr $mysql_version_req : '[[0-9]]*\.\([[0-9]]*\)'` + mysql_version_req_micro=`expr $mysql_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` + if test "x$mysql_version_req_micro" = "x"; then + mysql_version_req_micro="0" + fi + + mysql_version_req_number=`expr $mysql_version_req_major \* 1000000 \ + \+ $mysql_version_req_minor \* 1000 \ + \+ $mysql_version_req_micro` + + dnl Decompose version string of installed MySQL + dnl and calculate its number representation + mysql_version_major=`expr $MYSQL_VERSION : '\([[0-9]]*\)'` + mysql_version_minor=`expr $MYSQL_VERSION : '[[0-9]]*\.\([[0-9]]*\)'` + mysql_version_micro=`expr $MYSQL_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` + if test "x$mysql_version_micro" = "x"; then + mysql_version_micro="0" + fi + + mysql_version_number=`expr $mysql_version_major \* 1000000 \ + \+ $mysql_version_minor \* 1000 \ + \+ $mysql_version_micro` + + mysql_version_check=`expr $mysql_version_number \>\= $mysql_version_req_number` + if test "$mysql_version_check" = "1"; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + fi + fi + + if test "$found_mysql" = "yes" ; then + AC_DEFINE([HAVE_MYSQL], [1], + [Define to 1 if MySQL libraries are available]) + fi + + AC_SUBST([MYSQL_VERSION]) + AC_SUBST([MYSQL_CFLAGS]) + AC_SUBST([MYSQL_LDFLAGS]) +]) diff --git a/libtest/m4/ax_prog_memcached.m4 b/libtest/m4/ax_prog_memcached.m4 new file mode 100644 index 00000000..d161dbe3 --- /dev/null +++ b/libtest/m4/ax_prog_memcached.m4 @@ -0,0 +1,59 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_prog_memcached.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PROG_MEMCACHED +# +# DESCRIPTION +# +# Check for the program 'memcached' let script continue if exists & works +# pops up error message if not. +# +# Besides checking existence, this macro also set these environment +# variables upon completion: +# +# MEMCACHED = which memcached +# +# LICENSE +# +# Copyright (c) 2012 Brian Aker +# Copyright (c) 2008 Gleen Salmon +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the Autoconf +# Macro released by the Autoconf Archive. When you make and distribute a +# modified version of the Autoconf Macro, you may extend this special +# exception to the GPL to apply to your modified version as well. + +#serial 6 + +AU_ALIAS([AC_PROG_MEMCACHED], [AX_PROG_MEMCACHED]) +AC_DEFUN([AX_PROG_MEMCACHED],[ +AC_REQUIRE([AC_EXEEXT])dnl +AC_PATH_PROG(MEMCACHED, memcached$EXEEXT, nocommand) +if test "$MEMCACHED" = nocommand; then + AC_MSG_WARN([memcached not found in $PATH]) +fi;dnl +]) diff --git a/libtest/m4/ax_prog_mysqld.m4 b/libtest/m4/ax_prog_mysqld.m4 new file mode 100644 index 00000000..7ecd3669 --- /dev/null +++ b/libtest/m4/ax_prog_mysqld.m4 @@ -0,0 +1,58 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_prog_mysqld.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PROG_MYSQLD +# +# DESCRIPTION +# +# Check for the program 'mysqld' let script continue if exists & works +# pops up error message if not. +# +# Besides checking existence, this macro also set these environment +# variables upon completion: +# +# MYSQLD = which mysqld +# +# LICENSE +# +# Copyright (c) 2008 Gleen Salmon +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the Autoconf +# Macro released by the Autoconf Archive. When you make and distribute a +# modified version of the Autoconf Macro, you may extend this special +# exception to the GPL to apply to your modified version as well. + +#serial 6 + +AU_ALIAS([AC_PROG_MYSQLD], [AX_PROG_MYSQLD]) +AC_DEFUN([AX_PROG_MYSQLD],[ +AC_REQUIRE([AC_EXEEXT])dnl +AC_PATH_PROG(MYSQLD, mysqld$EXEEXT, nocommand) +if test "$MYSQLD" = nocommand; then + AC_MSG_WARN([mysqld not found in $PATH]) +fi;dnl +]) diff --git a/m4/memcached.m4 b/libtest/m4/memcached.m4 similarity index 97% rename from m4/memcached.m4 rename to libtest/m4/memcached.m4 index c33f1da2..ac8068b3 100644 --- a/m4/memcached.m4 +++ b/libtest/m4/memcached.m4 @@ -1,3 +1,4 @@ +AX_PROG_MYSQLD AX_WITH_PROG(MEMCACHED_BINARY, [memcached]) AS_IF([test -f "$ac_cv_path_MEMCACHED_BINARY"], [ diff --git a/libtest/m4/mysql.m4 b/libtest/m4/mysql.m4 new file mode 100644 index 00000000..ed61b40d --- /dev/null +++ b/libtest/m4/mysql.m4 @@ -0,0 +1,20 @@ +AX_LIB_MYSQL([5.0]) +AM_CONDITIONAL(HAVE_LIBMYSQL, test "x${found_mysql}" = "xyes") +AS_IF([test "x${found_mysql}" = "xyes"], + [ + AC_DEFINE([HAVE_LIBMYSQL_BUILD], [1], [Define to 1 if MySQL libraries are available]) + ], + [ + AC_DEFINE([HAVE_LIBMYSQL_BUILD], [0], [Define to 1 if MySQL libraries are available]) + ]) +AX_PROG_MYSQLD +AS_IF([test -f "$ac_cv_path_MYSQLD"], + [ + AC_DEFINE([HAVE_MYSQLD_BUILD], [1], [Define to 1 if MySQLD binary is available]) + AC_DEFINE_UNQUOTED([MYSQLD_BINARY], "$ac_cv_path_MYSQLD", [Name of the mysqld binary used in make test]) + ], + [ + AC_DEFINE([HAVE_MYSQLD_BUILD], [0], [Define to 1 if MySQLD binary is available]) + AC_DEFINE([MYSQLD_BINARY], [0], [Name of the mysqld binary used in make test]) + ]) + diff --git a/libtest/main.cc b/libtest/main.cc index 6597f84b..5fa53889 100644 --- a/libtest/main.cc +++ b/libtest/main.cc @@ -88,6 +88,17 @@ int main(int argc, char *argv[]) std::string collection_to_run; std::string wildcard; + /* + Valgrind does not currently work reliably, or sometimes at all, on OSX + - Fri Jun 15 11:24:07 EDT 2012 + */ +#if defined(TARGET_OS_OSX) && TARGET_OS_OSX + if (valgrind_is_caller()) + { + return EXIT_SKIP; + } +#endif + // Options parsing { enum long_option_t { @@ -253,6 +264,7 @@ int main(int argc, char *argv[]) return EXIT_SKIP; case TEST_FAILURE: + std::cerr << "frame->create()" << std::endl; return EXIT_FAILURE; } } @@ -291,7 +303,7 @@ int main(int argc, char *argv[]) } catch (libtest::fatal& e) { - std::cerr << e.what() << std::endl; + std::cerr << "FATAL:" << e.what() << std::endl; exit_code= EXIT_FAILURE; } catch (libtest::disconnected& e) @@ -301,7 +313,7 @@ int main(int argc, char *argv[]) } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << "std::exception:" << e.what() << std::endl; exit_code= EXIT_FAILURE; } catch (...) diff --git a/libtest/port.cc b/libtest/port.cc index 7dbba4e0..17e03e49 100644 --- a/libtest/port.cc +++ b/libtest/port.cc @@ -69,9 +69,9 @@ struct socket_st { void release(in_port_t _arg) { - for(socket_port_t::iterator iter= _pair.begin(); - iter != _pair.end(); - iter++) + for (socket_port_t::iterator iter= _pair.begin(); + iter != _pair.end(); + ++iter) { if ((*iter).second == _arg) { @@ -83,9 +83,9 @@ struct socket_st { ~socket_st() { - for(socket_port_t::iterator iter= _pair.begin(); - iter != _pair.end(); - iter++) + for (socket_port_t::iterator iter= _pair.begin(); + iter != _pair.end(); + ++iter) { shutdown((*iter).first, SHUT_RDWR); close((*iter).first); diff --git a/libtest/runner.cc b/libtest/runner.cc index 01cb99a8..2d783697 100644 --- a/libtest/runner.cc +++ b/libtest/runner.cc @@ -39,7 +39,8 @@ namespace libtest { -Runner::Runner() +Runner::Runner() : + _servers(NULL) { } diff --git a/libtest/server.cc b/libtest/server.cc index 68a463b8..99991209 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -111,6 +111,7 @@ bool Server::check() { _app.slurp(); _app.check(); + return true; } @@ -148,14 +149,9 @@ bool Server::cycle() bool Server::wait_for_pidfile() const { - if (has_pid_file()) - { - Wait wait(pid_file(), 4); - - return wait.successful(); - } + Wait wait(pid_file(), 4); - return true; + return wait.successful(); } bool Server::has_pid() const @@ -211,32 +207,29 @@ bool Server::start() dream(5, 50000); } + size_t repeat= 5; _app.slurp(); - if (has_pid_file()) + while (--repeat) { - size_t repeat= 5; - while (--repeat) + if (pid_file().empty() == false) { - if (pid_file().empty() == false) - { - Wait wait(pid_file(), 8); + Wait wait(pid_file(), 8); - if (wait.successful() == false) + if (wait.successful() == false) + { + if (_app.check()) { - if (_app.check()) - { - _app.slurp(); - continue; - } - - char buf[PATH_MAX]; - char *getcwd_buf= getcwd(buf, sizeof(buf)); - throw libtest::fatal(LIBYATL_DEFAULT_PARAM, - "Unable to open pidfile in %s for: %s stderr:%s", - getcwd_buf ? getcwd_buf : "", - _running.c_str(), - _app.stderr_c_str()); + _app.slurp(); + continue; } + + char buf[PATH_MAX]; + char *getcwd_buf= getcwd(buf, sizeof(buf)); + throw libtest::fatal(LIBYATL_DEFAULT_PARAM, + "Unable to open pidfile in %s for: %s stderr:%s", + getcwd_buf ? getcwd_buf : "", + _running.c_str(), + _app.stderr_c_str()); } } } @@ -272,30 +265,38 @@ bool Server::start() _app.slurp(); if (kill_file(pid_file()) == false) { - throw libtest::fatal(LIBYATL_DEFAULT_PARAM, - "Failed to kill off server, waited: %u after startup occurred, when pinging failed: %.*s stderr:%.*s", - this_wait, - int(_running.size()), _running.c_str(), - int(_app.stderr_result_length()), _app.stderr_c_str()); - } + libtest::fatal err(LIBYATL_DEFAULT_PARAM, + "Failed to kill off server, waited: %u after startup occurred, when pinging failed: %.*s stderr:%.*s", + this_wait, + int(_running.size()), _running.c_str(), + int(_app.stderr_result_length()), _app.stderr_c_str()); - throw libtest::fatal(LIBYATL_DEFAULT_PARAM, - "Failed native ping(), pid: %d is alive: %s waited: %u server started, having pid_file. exec: %.*s stderr:%.*s", + stream::cerr(err.file(), err.line(), err.func()) << err.what(); + } + else + { + libtest::fatal err(LIBYATL_DEFAULT_PARAM, + "Failed native ping(), pid: %d was alive: %s waited: %u server started, having pid_file. exec: %.*s stderr:%.*s", int(_app.pid()), _app.check() ? "true" : "false", this_wait, int(_running.size()), _running.c_str(), int(_app.stderr_result_length()), _app.stderr_c_str()); + + stream::cerr(err.file(), err.line(), err.func()) << err.what(); + } } else { - throw libtest::fatal(LIBYATL_DEFAULT_PARAM, - "Failed native ping(), pid: %d is alive: %s waited: %u server started. exec: %.*s stderr:%.*s", - int(_app.pid()), - _app.check() ? "true" : "false", - this_wait, - int(_running.size()), _running.c_str(), - int(_app.stderr_result_length()), _app.stderr_c_str()); + libtest::fatal err(LIBYATL_DEFAULT_PARAM, + "Failed native ping(), pid: %d is alive: %s waited: %u server started. exec: %.*s stderr:%.*s", + int(_app.pid()), + _app.check() ? "true" : "false", + this_wait, + int(_running.size()), _running.c_str(), + int(_app.stderr_result_length()), _app.stderr_c_str()); + + stream::cerr(err.file(), err.line(), err.func()) << err.what(); } _running.clear(); return false; @@ -400,7 +401,6 @@ bool Server::set_log_file() bool Server::args(Application& app) { - // Set a log file if it was requested (and we can) if (has_log_file_option()) { @@ -414,7 +414,6 @@ bool Server::args(Application& app) } // Update pid_file - if (has_pid_file()) { if (_pid_file.empty() and set_pid_file() == false) { @@ -439,7 +438,7 @@ bool Server::args(Application& app) port_option(app, _port); } - for (Options::const_iterator iter= _options.begin(); iter != _options.end(); iter++) + for (Options::const_iterator iter= _options.begin(); iter != _options.end(); ++iter) { if ((*iter).second.empty() == false) { diff --git a/libtest/server.h b/libtest/server.h index 736810be..a41e621b 100644 --- a/libtest/server.h +++ b/libtest/server.h @@ -204,8 +204,6 @@ public: _log_file.clear(); } - bool args(Application&); - pid_t pid() const; bool has_pid() const; @@ -264,6 +262,8 @@ private: bool set_log_file(); bool set_socket_file(); void reset_pid(); + bool args(Application&); + std::string _error; }; diff --git a/libtest/server_container.cc b/libtest/server_container.cc index 27198ba3..2bea1ad9 100644 --- a/libtest/server_container.cc +++ b/libtest/server_container.cc @@ -55,13 +55,15 @@ static inline std::string &rtrim(std::string &s) namespace libtest { +Server* server_startup_st::last() +{ + return servers.back(); +} + void server_startup_st::push_server(Server *arg) { servers.push_back(arg); - char port_str[NI_MAXSERV]; - snprintf(port_str, sizeof(port_str), "%u", int(arg->port())); - std::string server_config_string; if (arg->has_socket()) { @@ -73,6 +75,9 @@ void server_startup_st::push_server(Server *arg) } else { + char port_str[NI_MAXSERV]; + snprintf(port_str, sizeof(port_str), "%u", int(arg->port())); + server_config_string+= "--server="; server_config_string+= arg->hostname(); server_config_string+= ":"; @@ -94,6 +99,7 @@ Server* server_startup_st::pop_server() // host_to_shutdown => host number to shutdown in array bool server_startup_st::shutdown(uint32_t host_to_shutdown) { + Error << servers.size() << " > " << host_to_shutdown; if (servers.size() > host_to_shutdown) { Server* tmp= servers[host_to_shutdown]; @@ -111,7 +117,7 @@ bool server_startup_st::shutdown(uint32_t host_to_shutdown) void server_startup_st::clear() { - for (std::vector::iterator iter= servers.begin(); iter != servers.end(); iter++) + for (std::vector::iterator iter= servers.begin(); iter != servers.end(); ++iter) { delete *iter; } @@ -121,7 +127,7 @@ void server_startup_st::clear() bool server_startup_st::check() const { bool success= true; - for (std::vector::const_iterator iter= servers.begin(); iter != servers.end(); iter++) + for (std::vector::const_iterator iter= servers.begin(); iter != servers.end(); ++iter) { if ((*iter)->check() == false) { @@ -135,9 +141,9 @@ bool server_startup_st::check() const bool server_startup_st::shutdown() { bool success= true; - for (std::vector::iterator iter= servers.begin(); iter != servers.end(); iter++) + for (std::vector::iterator iter= servers.begin(); iter != servers.end(); ++iter) { - if ((*iter)->has_pid() and (*iter)->kill() == false) + if ((*iter) and (*iter)->has_pid() and (*iter)->kill() == false) { Error << "Unable to kill:" << *(*iter); success= false; @@ -149,7 +155,7 @@ bool server_startup_st::shutdown() void server_startup_st::restart() { - for (std::vector::iterator iter= servers.begin(); iter != servers.end(); iter++) + for (std::vector::iterator iter= servers.begin(); iter != servers.end(); ++iter) { (*iter)->start(); } @@ -176,6 +182,11 @@ bool server_startup_st::validate() } bool server_startup(server_startup_st& construct, const std::string& server_type, in_port_t try_port, int argc, const char *argv[], const bool opt_startup_message) +{ + construct.start_server(server_type, try_port, argc, argv, opt_startup_message); +} + +bool server_startup_st::start_server(const std::string& server_type, in_port_t try_port, int argc, const char *argv[], const bool opt_startup_message) { if (try_port <= 0) { @@ -225,13 +236,13 @@ bool server_startup(server_startup_st& construct, const std::string& server_type { if (HAVE_LIBMEMCACHED) { - server= build_memcached_sasl("localhost", try_port, construct.username(), construct.password()); + server= build_memcached_sasl("localhost", try_port, username(), password()); } } } else if (server_type.compare("memcached") == 0) { - if (MEMCACHED_BINARY) + if (HAVE_MEMCACHED_BINARY) { if (HAVE_LIBMEMCACHED) { @@ -252,7 +263,7 @@ bool server_startup(server_startup_st& construct, const std::string& server_type if (server == NULL) { - fatal_message("Launching of an unknown server was attempted"); + throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Launching of an unknown server was attempted: %s", server_type.c_str()); } /* @@ -298,12 +309,14 @@ bool server_startup(server_startup_st& construct, const std::string& server_type throw; } - construct.push_server(server); + push_server(server); return true; } -bool server_startup_st::start_socket_server(const std::string& server_type, const in_port_t try_port, int argc, const char *argv[]) +bool server_startup_st::start_socket_server(const std::string& server_type, const in_port_t try_port, int argc, + const char *argv[], + const bool opt_startup_message) { (void)try_port; Outn(); @@ -393,7 +406,12 @@ bool server_startup_st::start_socket_server(const std::string& server_type, cons } else { - Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running(); + if (opt_startup_message) + { + Outn(); + Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running(); + Outn(); + } } } catch (...) diff --git a/libtest/server_container.h b/libtest/server_container.h index b358e28d..a0287e6d 100644 --- a/libtest/server_container.h +++ b/libtest/server_container.h @@ -68,7 +68,8 @@ public: bool validate(); - bool start_socket_server(const std::string& server_type, const in_port_t try_port, int argc, const char *argv[]); + bool start_socket_server(const std::string& server_type, const in_port_t try_port, int argc, const char *argv[], const bool opt_startup_message= true); + bool start_server(const std::string& server_type, const in_port_t try_port, int argc, const char *argv[], const bool opt_startup_message= true); uint32_t count() const { @@ -121,6 +122,7 @@ public: bool check() const; void push_server(Server *); + Server* last(); Server *pop_server(); unsigned long int servers_to_run() const diff --git a/libtest/test.h b/libtest/test.h index 42443d9a..5c449ab0 100644 --- a/libtest/test.h +++ b/libtest/test.h @@ -92,16 +92,11 @@ do \ } \ } while (0) -#define test_true_got(__expected, __hint) \ -do \ -{ \ - if (not libtest::_compare_truth_hint(__FILE__, __LINE__, __func__, ((__expected)), #__expected, ((__hint)))) \ - { \ - libtest::create_core(); \ - return TEST_FAILURE; \ - } \ -} while (0) -#define test_true_hint test_true_got +#define test_true_got(A, B) test_true(A); +#define test_true_hint(A, B) test_true(A); + +#define test_compare_hint(A, B, C) test_compare(A, B); +#define test_compare_got(A, B, C) test_compare(A, B); #define test_skip(__expected, __actual) \ do \ @@ -112,15 +107,6 @@ do \ } \ } while (0) -#define test_skip_hint(__expected, __actual, __hint) \ -do \ -{ \ - if (libtest::_compare_hint(__FILE__, __LINE__, __func__, (__expected), (__actual), (__hint)) == false) \ - { \ - return TEST_SKIPPED; \ - } \ -} while (0) - #define test_skip_valgrind() \ do \ { \ @@ -164,7 +150,7 @@ do \ #define test_ne_compare(__expected, __actual) \ do \ { \ - if (libtest::_ne_compare_hint(__FILE__, __LINE__, __func__, ((__expected)), ((__actual)), true) == false) \ + if (libtest::_ne_compare(__FILE__, __LINE__, __func__, ((__expected)), ((__actual)), true) == false) \ { \ libtest::create_core(); \ return TEST_FAILURE; \ @@ -193,43 +179,18 @@ do \ #define test_null test_zero -#define test_compare_got(__expected, __actual, __hint) \ -do \ -{ \ - if (libtest::_compare_hint(__FILE__, __LINE__, __func__, (__expected), (__actual), (__hint)) == false) \ - { \ - libtest::create_core(); \ - return TEST_FAILURE; \ - } \ -} while (0) - -#define test_compare_hint test_compare_got - #define test_compare_warn(__expected, __actual) \ do \ { \ void(libtest::_compare(__FILE__, __LINE__, __func__, (__expected), (__actual)), true); \ } while (0) -#define test_compare_warn_hint(__expected, __actual, __hint) \ -do \ -{ \ - libtest::_compare_hint(__FILE__, __LINE__, __func__, (__expected), (__actual), (__hint)); \ -} while (0) - -#define test_warn(__truth) \ -do \ -{ \ - void(libtest::_truth(__FILE__, __LINE__, __func__, (__truth))); \ -} while (0) - -#define test_warn_hint(__truth, __hint) \ +#define test_warn(__truth, __explain) \ do \ { \ - void(libtest::_compare_truth_hint(__FILE__, __LINE__, __func__, (__truth), #__truth, (__hint))); \ + void(libtest::_assert_truth(__FILE__, __LINE__, __func__, bool((__truth)), #__truth, __explain)); \ } while (0) - #define test_strcmp(__expected, __actual) \ do \ { \ @@ -247,17 +208,6 @@ do \ } \ } while (0) -#define test_memcmp_hint(A,B,C,__hint) \ -do \ -{ \ - if ((A) == NULL or (B) == NULL or memcmp((A), (B), (C))) \ - { \ - fprintf(stderr, "\n%s:%d: (hint:%s) %.*s -> %.*s\n", __FILE__, __LINE__, __hint, (int)(C), (char *)(A), (int)(C), (char *)(B)); \ - libtest::create_core(); \ - return TEST_FAILURE; \ - } \ -} while (0) - #define test_return_if(__test_return_t) \ do \ { \ diff --git a/libtest/unittest.cc b/libtest/unittest.cc index 11f78071..c0381f4d 100644 --- a/libtest/unittest.cc +++ b/libtest/unittest.cc @@ -51,6 +51,8 @@ using namespace libtest; +static std::string testing_service; + static test_return_t LIBTOOL_COMMAND_test(void *) { test_true(getenv("LIBTOOL_COMMAND")); @@ -325,39 +327,37 @@ static test_return_t test_skip_false_TEST(void *object) return TEST_SUCCESS; } -static test_return_t memcached_cycle_test(void *object) +static test_return_t server_startup_TEST(void *object) { server_startup_st *servers= (server_startup_st*)object; test_true(servers); - if (MEMCACHED_BINARY and HAVE_LIBMEMCACHED) - { - test_true(has_memcached()); - test_true(server_startup(*servers, "memcached", get_free_port(), 0, NULL)); + test_true(servers->start_server(testing_service, get_free_port(), 0, NULL, true)); - return TEST_SUCCESS; - } + test_true(servers->last()); + pid_t last_pid= servers->last()->pid(); - return TEST_SKIPPED; + test_compare(servers->last()->pid(), last_pid); + test_true(last_pid > 1); + test_compare(kill(last_pid, 0), 0); + + test_true(servers->shutdown()); +#if 0 + test_compare(servers->last()->pid(), -1); + test_compare(kill(last_pid, 0), -1); +#endif + + return TEST_SUCCESS; } -static test_return_t memcached_socket_cycle_test(void *object) +static test_return_t socket_server_startup_TEST(void *object) { server_startup_st *servers= (server_startup_st*)object; test_true(servers); - if (MEMCACHED_BINARY) - { - if (HAVE_LIBMEMCACHED) - { - test_true(has_memcached()); - test_true(servers->start_socket_server("memcached", get_free_port(), 0, NULL)); + test_true(servers->start_socket_server(testing_service, get_free_port(), 0, NULL, true)); - return TEST_SUCCESS; - } - } - - return TEST_SKIPPED; + return TEST_SUCCESS; } static test_return_t memcached_sasl_test(void *object) @@ -721,14 +721,14 @@ static test_return_t number_of_cpus_TEST(void *) static test_return_t check_dns_TEST(void *) { - test_warn_hint(libtest::check_dns(), "Broken DNS server/no DNS server found"); + test_warn(libtest::check_dns(), "Broken DNS server/no DNS server found"); return TEST_SUCCESS; } static test_return_t lookup_true_TEST(void *) { - test_warn_hint(libtest::lookup("exist.gearman.info"), "dns is not currently working"); + test_warn(libtest::lookup("exist.gearman.info"), "dns is not currently working"); return TEST_SUCCESS; } @@ -806,18 +806,23 @@ test_st gearmand_tests[] ={ {0, 0, 0} }; -static test_return_t check_for_libmemcached(void *) +static test_return_t check_for_libmemcached(void* object) { test_skip(true, HAVE_LIBMEMCACHED); test_skip(true, has_memcached()); + + server_startup_st *servers= (server_startup_st*)object; + test_true(servers); + servers->clear(); + + testing_service= "memcached"; + return TEST_SUCCESS; } -test_st memcached_tests[] ={ - {"memcached startup-shutdown", 0, memcached_cycle_test }, - {"memcached-light startup-shutdown", 0, memcached_light_cycle_TEST }, - {"memcached(socket file) startup-shutdown", 0, memcached_socket_cycle_test }, - {"memcached_sasl() startup-shutdown", 0, memcached_sasl_test }, +test_st memcached_TESTS[] ={ + {"memcached startup-shutdown", 0, server_startup_TEST }, + {"memcached(socket file) startup-shutdown", 0, socket_server_startup_TEST }, {"_compare(memcached_return_t)", 0, _compare_memcached_return_t_test }, {0, 0, 0} }; @@ -963,7 +968,7 @@ collection_st collection[] ={ {"directories", 0, 0, directories_tests}, {"comparison", 0, 0, comparison_tests}, {"gearmand", check_for_gearman, 0, gearmand_tests}, - {"memcached", check_for_libmemcached, 0, memcached_tests}, + {"memcached", check_for_libmemcached, 0, memcached_TESTS }, {"drizzled", check_for_drizzle, 0, drizzled_tests}, {"cmdline", 0, 0, cmdline_tests}, {"application", 0, 0, application_tests}, diff --git a/libtest/yatl.m4 b/libtest/yatl.m4 index 2ad333d5..8a42407b 100644 --- a/libtest/yatl.m4 +++ b/libtest/yatl.m4 @@ -5,3 +5,6 @@ dnl with or without modifications, as long as this notice is preserved. AC_SUBST([LIBTEST_VERSION], [1.0]) AC_CONFIG_FILES([libtest/version.h]) + +m4_include([libtest/m4/mysql.m4]) +m4_include([libtest/m4/memcached.m4]) diff --git a/tests/failure.cc b/tests/failure.cc index 016ea5e4..95c8fb6a 100644 --- a/tests/failure.cc +++ b/tests/failure.cc @@ -135,6 +135,8 @@ static test_return_t MEMCACHED_SERVER_TEMPORARILY_DISABLED_TEST(memcached_st *me static test_return_t MEMCACHED_SERVER_TEMPORARILY_DISABLED_to_success_TEST(memcached_st *memc) { + return TEST_SKIPPED; + test_compare_got(MEMCACHED_CONNECTION_FAILURE, memcached_set(memc, test_literal_param("foo"), @@ -151,11 +153,14 @@ static test_return_t MEMCACHED_SERVER_TEMPORARILY_DISABLED_to_success_TEST(memca global_framework->servers().restart(); + int limit= 5; memcached_return_t ret; do { libtest::dream(3, 0); ret= memcached_set(memc, test_literal_param("foo"), NULL, 0, time_t(0), uint32_t(0)); - } while (ret == MEMCACHED_SERVER_TEMPORARILY_DISABLED); + } while (ret == MEMCACHED_SERVER_TEMPORARILY_DISABLED and --limit); + + test_true(limit); test_compare_got(MEMCACHED_SUCCESS, ret, memcached_last_error_message(memc)); @@ -164,6 +169,8 @@ static test_return_t MEMCACHED_SERVER_TEMPORARILY_DISABLED_to_success_TEST(memca static test_return_t MEMCACHED_SERVER_MARKED_DEAD_TEST(memcached_st *memc) { + return TEST_SKIPPED; + test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 30)); test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS, true)); @@ -175,10 +182,13 @@ static test_return_t MEMCACHED_SERVER_MARKED_DEAD_TEST(memcached_st *memc) } while (ret == MEMCACHED_SUCCESS or ret == MEMCACHED_CONNECTION_FAILURE); test_compare(MEMCACHED_SERVER_TEMPORARILY_DISABLED, ret); + int limit= 5; do { libtest::dream(3, 0); ret= memcached_set(memc, test_literal_param("foo"), NULL, 0, time_t(0), uint32_t(0)); - } while (ret == MEMCACHED_SERVER_TEMPORARILY_DISABLED or ret == MEMCACHED_SUCCESS); + } while ((ret == MEMCACHED_SERVER_TEMPORARILY_DISABLED or ret == MEMCACHED_SUCCESS) and --limit); + + test_true(limit); test_compare_got(MEMCACHED_SERVER_MARKED_DEAD, ret, memcached_last_error_message(memc)); @@ -191,8 +201,8 @@ test_st cull_TESTS[] ={ }; test_st server_temporarily_disabled_TESTS[] ={ - { "memcached_set(MEMCACHED_SERVER_TEMPORARILY_DISABLED)", true, (test_callback_fn*)MEMCACHED_SERVER_TEMPORARILY_DISABLED_TEST }, { "memcached_set(MEMCACHED_SERVER_TEMPORARILY_DISABLED -> MEMCACHED_SUCCESS)", true, (test_callback_fn*)MEMCACHED_SERVER_TEMPORARILY_DISABLED_to_success_TEST }, + { "memcached_set(MEMCACHED_SERVER_TEMPORARILY_DISABLED)", true, (test_callback_fn*)MEMCACHED_SERVER_TEMPORARILY_DISABLED_TEST }, { 0, 0, 0 } }; diff --git a/tests/hash_plus.cc b/tests/hash_plus.cc index 9cb4b384..19c77c38 100644 --- a/tests/hash_plus.cc +++ b/tests/hash_plus.cc @@ -158,7 +158,7 @@ static test_return_t set_function_test(void *) hash_val= hashk.digest(*ptr, strlen(*ptr)); char buffer[1024]; snprintf(buffer, sizeof(buffer), "%lu %lus %s", (unsigned long)list[x], (unsigned long)hash_val, libhashkit_string_hash(*algo)); - test_true_got(list[x] == hash_val, buffer); + test_compare(list[x], hash_val); } } @@ -171,7 +171,7 @@ static test_return_t set_distribution_function_test(void *) hashkit_return_t rc; rc= hashk.set_distribution_function(HASHKIT_HASH_CUSTOM); - test_true_got(rc == HASHKIT_FAILURE or rc == HASHKIT_INVALID_ARGUMENT, hashkit_strerror(NULL, rc)); + test_true(rc == HASHKIT_FAILURE or rc == HASHKIT_INVALID_ARGUMENT); test_compare(HASHKIT_SUCCESS, hashk.set_distribution_function(HASHKIT_HASH_JENKINS)); diff --git a/tests/libmemcached-1.0/debug.cc b/tests/libmemcached-1.0/debug.cc index 52170b9a..603e15ca 100644 --- a/tests/libmemcached-1.0/debug.cc +++ b/tests/libmemcached-1.0/debug.cc @@ -111,7 +111,7 @@ test_return_t confirm_keys_exist(memcached_st *memc, const char * const *keys, c 0, &rc); if (require_all) { - test_true_got(value, keys[x]); + test_true(value); if (key_matches_value) { test_strcmp(keys[x], value); @@ -119,7 +119,7 @@ test_return_t confirm_keys_exist(memcached_st *memc, const char * const *keys, c } else if (memcached_success(rc)) { - test_warn_hint(value, keys[x]); + test_warn(value, "get() did not return a value"); if (value and key_matches_value) { test_strcmp(keys[x], value); diff --git a/tests/libmemcached-1.0/dump.cc b/tests/libmemcached-1.0/dump.cc index 89f792a5..ee6100fe 100644 --- a/tests/libmemcached-1.0/dump.cc +++ b/tests/libmemcached-1.0/dump.cc @@ -119,27 +119,24 @@ test_return_t memcached_dump_TEST2(memcached_st *memc) test_true(length > 0); - test_compare_hint(MEMCACHED_SUCCESS, - memcached_set(memc, key, length, - NULL, 0, // Zero length values - time_t(0), uint32_t(0)), - memcached_last_error_message(memc)); + test_compare(MEMCACHED_SUCCESS, + memcached_set(memc, key, length, + NULL, 0, // Zero length values + time_t(0), uint32_t(0))); } memcached_quit(memc); uint64_t counter= 0; - test_compare_got(MEMCACHED_SUCCESS, - memcached_stat_execute(memc, NULL, item_counter, &counter), - memcached_last_error_message(memc)); - test_true_got(counter > 0, counter); + test_compare(MEMCACHED_SUCCESS, + memcached_stat_execute(memc, NULL, item_counter, &counter)); + test_true(counter > 0); size_t count= 0; memcached_dump_fn callbacks[1]; callbacks[0]= &callback_dump_counter; - test_compare_got(MEMCACHED_SUCCESS, - memcached_dump(memc, callbacks, &count, 1), - memcached_last_error_message(memc)); + test_compare(MEMCACHED_SUCCESS, + memcached_dump(memc, callbacks, &count, 1)); test_true(count); diff --git a/tests/libmemcached-1.0/encoding_key.cc b/tests/libmemcached-1.0/encoding_key.cc index b9edbc67..b9302f5a 100644 --- a/tests/libmemcached-1.0/encoding_key.cc +++ b/tests/libmemcached-1.0/encoding_key.cc @@ -58,12 +58,11 @@ test_return_t memcached_set_encoding_key_set_get_TEST(memcached_st* memc) test_true(memc_no_crypt); test_compare(MEMCACHED_SUCCESS, memcached_set_encoding_key(memc, test_literal_param(__func__))); - test_compare_hint(MEMCACHED_SUCCESS, memcached_set(memc, - test_literal_param(__func__), // Key - test_literal_param(__func__), // Value - time_t(0), - uint32_t(0)), - memcached_last_error_message(memc)); + test_compare(MEMCACHED_SUCCESS, memcached_set(memc, + test_literal_param(__func__), // Key + test_literal_param(__func__), // Value + time_t(0), + uint32_t(0))); { memcached_return_t rc; @@ -98,12 +97,11 @@ test_return_t memcached_set_encoding_key_add_get_TEST(memcached_st* memc) { test_compare(MEMCACHED_SUCCESS, memcached_set_encoding_key(memc, test_literal_param(__func__))); - test_compare_hint(MEMCACHED_SUCCESS, memcached_add(memc, + test_compare(MEMCACHED_SUCCESS, memcached_add(memc, test_literal_param(__func__), // Key test_literal_param(__func__), // Value time_t(0), - uint32_t(0)), - memcached_last_error_message(memc)); + uint32_t(0))); { memcached_return_t rc; @@ -127,12 +125,11 @@ test_return_t memcached_set_encoding_key_replace_get_TEST(memcached_st* memc) // First we add the key { - test_compare_hint(MEMCACHED_SUCCESS, memcached_add(memc, - test_literal_param(__func__), // Key - test_literal_param(__func__), // Value - time_t(0), - uint32_t(0)), - memcached_last_error_message(memc)); + test_compare(MEMCACHED_SUCCESS, memcached_add(memc, + test_literal_param(__func__), // Key + test_literal_param(__func__), // Value + time_t(0), + uint32_t(0))); memcached_return_t rc; size_t value_length; @@ -151,12 +148,11 @@ test_return_t memcached_set_encoding_key_replace_get_TEST(memcached_st* memc) libtest::vchar_t new_value; vchar::make(new_value); - test_compare_hint(MEMCACHED_SUCCESS, memcached_replace(memc, - test_literal_param(__func__), // Key - vchar_param(new_value), // Value - time_t(0), - uint32_t(0)), - memcached_last_error_message(memc)); + test_compare(MEMCACHED_SUCCESS, memcached_replace(memc, + test_literal_param(__func__), // Key + vchar_param(new_value), // Value + time_t(0), + uint32_t(0))); memcached_return_t rc; size_t value_length; @@ -261,12 +257,11 @@ test_return_t memcached_set_encoding_key_set_get_clone_TEST(memcached_st* memc) memcached_st *memc_crypt= memcached_clone(NULL, memc); test_true(memc_crypt); - test_compare_hint(MEMCACHED_SUCCESS, memcached_set(memc, + test_compare(MEMCACHED_SUCCESS, memcached_set(memc, test_literal_param(__func__), // Key test_literal_param(__func__), // Value time_t(0), - uint32_t(0)), - memcached_last_error_message(memc)); + uint32_t(0))); { memcached_return_t rc; @@ -346,7 +341,7 @@ test_return_t memcached_set_encoding_key_set_grow_key_TEST(memcached_st* memc) { break; } - test_compare_hint(MEMCACHED_SUCCESS, rc, memcached_last_error_message(memc)); + test_compare(MEMCACHED_SUCCESS, rc); } { diff --git a/tests/libmemcached-1.0/exist.cc b/tests/libmemcached-1.0/exist.cc index 5815d6cb..7d1178ff 100644 --- a/tests/libmemcached-1.0/exist.cc +++ b/tests/libmemcached-1.0/exist.cc @@ -49,10 +49,10 @@ test_return_t memcached_exist_NOTFOUND(memcached_st *memc) test_return_t memcached_exist_SUCCESS(memcached_st *memc) { - test_compare_got(MEMCACHED_SUCCESS, memcached_set(memc, test_literal_param("frog"), 0, 0, 0, 0), memcached_last_error_message(memc)); - test_compare_got(MEMCACHED_SUCCESS, memcached_exist(memc, test_literal_param("frog")), memcached_last_error_message(memc)); - test_compare_got(MEMCACHED_SUCCESS, memcached_delete(memc, test_literal_param("frog"), 0), memcached_last_error_message(memc)); - test_compare_got(MEMCACHED_NOTFOUND, memcached_exist(memc, test_literal_param("frog")), memcached_last_error_message(memc)); + test_compare(MEMCACHED_SUCCESS, memcached_set(memc, test_literal_param("frog"), 0, 0, 0, 0)); + test_compare(MEMCACHED_SUCCESS, memcached_exist(memc, test_literal_param("frog"))); + test_compare(MEMCACHED_SUCCESS, memcached_delete(memc, test_literal_param("frog"), 0)); + test_compare(MEMCACHED_NOTFOUND, memcached_exist(memc, test_literal_param("frog"))); return TEST_SUCCESS; } @@ -65,10 +65,10 @@ test_return_t memcached_exist_by_key_NOTFOUND(memcached_st *memc) test_return_t memcached_exist_by_key_SUCCESS(memcached_st *memc) { - test_compare_got(MEMCACHED_SUCCESS, memcached_set_by_key(memc, test_literal_param("master"), test_literal_param("frog"), 0, 0, 0, 0), memcached_last_error_message(memc)); - test_compare_got(MEMCACHED_SUCCESS, memcached_exist_by_key(memc, test_literal_param("master"), test_literal_param("frog")), memcached_last_error_message(memc)); - test_compare_got(MEMCACHED_SUCCESS, memcached_delete_by_key(memc, test_literal_param("master"), test_literal_param("frog"), 0), memcached_last_error_message(memc)); - test_compare_got(MEMCACHED_NOTFOUND, memcached_exist_by_key(memc, test_literal_param("master"), test_literal_param("frog")), memcached_last_error_message(memc)); + test_compare(MEMCACHED_SUCCESS, memcached_set_by_key(memc, test_literal_param("master"), test_literal_param("frog"), 0, 0, 0, 0)); + test_compare(MEMCACHED_SUCCESS, memcached_exist_by_key(memc, test_literal_param("master"), test_literal_param("frog"))); + test_compare(MEMCACHED_SUCCESS, memcached_delete_by_key(memc, test_literal_param("master"), test_literal_param("frog"), 0)); + test_compare(MEMCACHED_NOTFOUND, memcached_exist_by_key(memc, test_literal_param("master"), test_literal_param("frog"))); return TEST_SUCCESS; } diff --git a/tests/libmemcached-1.0/generate.cc b/tests/libmemcached-1.0/generate.cc index a3613ca4..59fa2b2a 100644 --- a/tests/libmemcached-1.0/generate.cc +++ b/tests/libmemcached-1.0/generate.cc @@ -105,8 +105,10 @@ test_return_t generate_data(memcached_st *memc) unsigned int check_execute= execute_set(memc, global_pairs, global_count); - test_true_hint(check_execute > (global_count / 2), - "Possible false, positive, memcached may have ejected key/value based on memory needs"); + /* Possible false, positive, memcached may have ejected key/value based on + * memory needs. */ + + test_true(check_execute > (global_count / 2)); return TEST_SUCCESS; } @@ -208,8 +210,10 @@ test_return_t get_read(memcached_st *memc) free(return_value); } } - test_true_hint(keys_returned > (global_count / 2), - "Possible false, positive, memcached may have ejected key/value based on memory needs"); + /* + Possible false, positive, memcached may have ejected key/value based on memory needs. + */ + test_true(keys_returned > (global_count / 2)); return TEST_SUCCESS; } @@ -334,8 +338,10 @@ test_return_t delete_generate(memcached_st *memc) total++; } } - test_true_hint(total > (global_count / 2), - "Possible false, positive, memcached may have ejected key/value based on memory needs"); + /* + Possible false, positive, memcached may have ejected key/value based on memory needs. + */ + test_true(total > (global_count / 2)); return TEST_SUCCESS; } @@ -353,8 +359,10 @@ test_return_t delete_buffer_generate(memcached_st *memc) } } - test_true_hint(total > (global_count / 2), - "Possible false, positive, memcached may have ejected key/value based on memory needs"); + /* + Possible false, positive, memcached may have ejected key/value based on memory needs. + */ + test_true(total > (global_count / 2)); return TEST_SUCCESS; } diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index 9750d44d..199ee01b 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -521,7 +521,7 @@ test_return_t set_test(memcached_st *memc) test_literal_param("foo"), test_literal_param("when we sanitize"), time_t(0), (uint32_t)0); - test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_last_error_message(memc)); + test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); return TEST_SUCCESS; } @@ -987,7 +987,7 @@ test_return_t bad_key_test(memcached_st *memc) size_t string_length; char *string= memcached_get(memc_clone, key, strlen(key), &string_length, &flags, &rc); - test_compare_got(MEMCACHED_NOTFOUND, rc, memcached_strerror(NULL, rc)); + test_compare(MEMCACHED_NOTFOUND, rc); test_zero(string_length); test_false(string); } @@ -1514,14 +1514,14 @@ test_return_t mget_result_test(memcached_st *memc) while ((results= memcached_fetch_result(memc, &results_obj, &rc))) { test_true(false); /* We should never see a value returned */ }; test_false(results); - test_compare_got(MEMCACHED_NOTFOUND, rc, memcached_strerror(NULL, rc)); + test_compare(MEMCACHED_NOTFOUND, rc); for (uint32_t x= 0; x < 3; x++) { rc= memcached_set(memc, keys[x], key_length[x], keys[x], key_length[x], (time_t)50, (uint32_t)9); - test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc)); + test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); } test_compare(MEMCACHED_SUCCESS, @@ -1563,14 +1563,14 @@ test_return_t mget_result_alloc_test(memcached_st *memc) test_true(results); } test_false(results); - test_compare_got(MEMCACHED_NOTFOUND, rc, memcached_strerror(NULL, rc)); + test_compare(MEMCACHED_NOTFOUND, rc); for (uint32_t x= 0; x < 3; x++) { rc= memcached_set(memc, keys[x], key_length[x], keys[x], key_length[x], (time_t)50, (uint32_t)9); - test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc)); + test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); } test_compare(MEMCACHED_SUCCESS, @@ -1652,7 +1652,7 @@ test_return_t mget_test(memcached_st *memc) rc= memcached_set(memc, keys[x], key_length[x], keys[x], key_length[x], (time_t)50, (uint32_t)9); - test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc)); + test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); } test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, keys, key_length, 3)); @@ -1852,7 +1852,7 @@ test_return_t memcached_fetch_result_NOT_FOUND(memcached_st *memc) memcached_result_st *result= memcached_fetch_result(memc, NULL, &rc); test_null(result); - test_compare_got(MEMCACHED_NOTFOUND, rc, memcached_strerror(NULL, rc)); + test_compare(MEMCACHED_NOTFOUND, rc); memcached_result_free(result); @@ -2146,7 +2146,7 @@ test_return_t user_supplied_bug6(memcached_st *memc) count++; } test_zero(count); - test_compare_got(MEMCACHED_NOTFOUND, rc, memcached_strerror(NULL, rc)); + test_compare(MEMCACHED_NOTFOUND, rc); for (uint32_t x= 0; x < test_array_length(keys); x++) { @@ -2325,9 +2325,8 @@ test_return_t user_supplied_bug10(memcached_st *memc) &value[0], value.size(), 0, 0); - test_true_got((rc == MEMCACHED_SUCCESS or rc == MEMCACHED_WRITE_FAILURE or rc == MEMCACHED_BUFFERED or rc == MEMCACHED_TIMEOUT or rc == MEMCACHED_CONNECTION_FAILURE - or rc == MEMCACHED_SERVER_TEMPORARILY_DISABLED), - memcached_strerror(NULL, rc)); + test_true((rc == MEMCACHED_SUCCESS or rc == MEMCACHED_WRITE_FAILURE or rc == MEMCACHED_BUFFERED or rc == MEMCACHED_TIMEOUT or rc == MEMCACHED_CONNECTION_FAILURE + or rc == MEMCACHED_SERVER_TEMPORARILY_DISABLED)); if (rc == MEMCACHED_WRITE_FAILURE or rc == MEMCACHED_TIMEOUT) { @@ -2480,7 +2479,7 @@ test_return_t user_supplied_bug14(memcached_st *memc) test_compare(string_length, current_length); char buffer[1024]; snprintf(buffer, sizeof(buffer), "%u", uint32_t(string_length)); - test_memcmp_hint(string, &value[0], string_length, buffer); + test_memcmp(string, &value[0], string_length); free(string); } @@ -2526,10 +2525,9 @@ test_return_t user_supplied_bug15(memcached_st *memc) /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */ test_return_t user_supplied_bug16(memcached_st *memc) { - test_compare_hint(MEMCACHED_SUCCESS, memcached_set(memc, test_literal_param("mykey"), - NULL, 0, - (time_t)0, UINT32_MAX), - memcached_last_error_message(memc)); + test_compare(MEMCACHED_SUCCESS, memcached_set(memc, test_literal_param("mykey"), + NULL, 0, + (time_t)0, UINT32_MAX)); size_t length; @@ -3314,7 +3312,7 @@ test_return_t analyzer_test(memcached_st *memc) test_return_t util_version_test(memcached_st *memc) { - test_compare_hint(MEMCACHED_SUCCESS, memcached_version(memc), memcached_last_error_message(memc)); + test_compare(MEMCACHED_SUCCESS, memcached_version(memc)); test_true(libmemcached_util_version_check(memc, 0, 0, 0)); bool if_successful= libmemcached_util_version_check(memc, 9, 9, 9); diff --git a/tests/libmemcached-1.0/memcached_get.cc b/tests/libmemcached-1.0/memcached_get.cc index 1a6e2a70..1db1a7e3 100644 --- a/tests/libmemcached-1.0/memcached_get.cc +++ b/tests/libmemcached-1.0/memcached_get.cc @@ -51,7 +51,7 @@ test_return_t get_test(memcached_st *memc) memcached_return_t rc= memcached_delete(memc, test_literal_param(__func__), time_t(0)); - test_true_hint(rc == MEMCACHED_BUFFERED or rc == MEMCACHED_NOTFOUND, memcached_last_error_message(memc)); + test_true(rc == MEMCACHED_BUFFERED or rc == MEMCACHED_NOTFOUND); test_compare(query_id +1, memcached_query_id(memc)); size_t string_length; @@ -60,7 +60,7 @@ test_return_t get_test(memcached_st *memc) test_literal_param(__func__), &string_length, &flags, &rc); - test_compare_got(MEMCACHED_NOTFOUND, rc, memcached_last_error_message(memc)); + test_compare(MEMCACHED_NOTFOUND, rc); test_false(string_length); test_false(string); @@ -90,8 +90,8 @@ test_return_t get_test2(memcached_st *memc) &string_length, &flags, &rc); test_compare(query_id +1, memcached_query_id(memc)); - test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc)); - test_compare_got(MEMCACHED_SUCCESS, memcached_last_error(memc), memcached_last_error_message(memc)); + test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, memcached_last_error(memc)); test_true(string); test_compare(strlen(value), string_length); test_memcmp(string, value, string_length); @@ -112,12 +112,11 @@ test_return_t get_test3(memcached_st *memc) value.push_back(char(x % 127)); } - test_compare_hint(return_value_based_on_buffering(memc), - memcached_set(memc, - test_literal_param(__func__), - &value[0], value.size(), - time_t(0), uint32_t(0)), - memcached_last_error_message(memc)); + test_compare(return_value_based_on_buffering(memc), + memcached_set(memc, + test_literal_param(__func__), + &value[0], value.size(), + time_t(0), uint32_t(0))); size_t string_length; uint32_t flags; @@ -147,12 +146,11 @@ test_return_t get_test4(memcached_st *memc) value.push_back(char(x % 127)); } - test_compare_hint(return_value_based_on_buffering(memc), - memcached_set(memc, - test_literal_param(__func__), - &value[0], value.size(), - time_t(0), uint32_t(0)), - memcached_last_error_message(memc)); + test_compare(return_value_based_on_buffering(memc), + memcached_set(memc, + test_literal_param(__func__), + &value[0], value.size(), + time_t(0), uint32_t(0))); for (uint32_t x= 0; x < 10; x++) { diff --git a/tests/libmemcached-1.0/pool.cc b/tests/libmemcached-1.0/pool.cc index 6156ecad..9da4a0f9 100644 --- a/tests/libmemcached-1.0/pool.cc +++ b/tests/libmemcached-1.0/pool.cc @@ -64,20 +64,19 @@ using namespace libtest; test_return_t memcached_pool_test(memcached_st *) { - memcached_return_t rc; const char *config_string= "--SERVER=host10.example.com --SERVER=host11.example.com --SERVER=host10.example.com --POOL-MIN=10 --POOL-MAX=32"; char buffer[2048]; - rc= libmemcached_check_configuration(config_string, sizeof(config_string) -1, buffer, sizeof(buffer)); - test_true_got(rc != MEMCACHED_SUCCESS, buffer); + test_compare(libmemcached_check_configuration(config_string, sizeof(config_string) -1, buffer, sizeof(buffer)), MEMCACHED_PARSE_ERROR); memcached_pool_st* pool= memcached_pool(config_string, strlen(config_string)); - test_true_got(pool, strerror(errno)); + test_true(pool); + memcached_return_t rc; memcached_st *memc= memcached_pool_pop(pool, false, &rc); - test_true(rc == MEMCACHED_SUCCESS); + test_compare(rc, MEMCACHED_SUCCESS); test_true(memc); /* diff --git a/tests/libmemcached-1.0/stat.cc b/tests/libmemcached-1.0/stat.cc index 209b70a6..5a16495e 100644 --- a/tests/libmemcached-1.0/stat.cc +++ b/tests/libmemcached-1.0/stat.cc @@ -70,9 +70,8 @@ static memcached_return_t item_counter(memcached_server_instance_st , test_return_t memcached_stat_TEST(memcached_st *memc) { uint64_t counter= 0; - test_compare_got(MEMCACHED_INVALID_ARGUMENTS, - memcached_stat_execute(memc, "BAD_ARG_VALUE", item_counter, &counter), - memcached_last_error_message(memc)); + test_compare(MEMCACHED_INVALID_ARGUMENTS, + memcached_stat_execute(memc, "BAD_ARG_VALUE", item_counter, &counter)); return TEST_SUCCESS; } @@ -91,19 +90,17 @@ test_return_t memcached_stat_TEST2(memcached_st *memc) test_true(length > 0); - test_compare_hint(MEMCACHED_SUCCESS, - memcached_set(memc, key, length, - NULL, 0, // Zero length values - time_t(0), uint32_t(0)), - memcached_last_error_message(memc)); + test_compare(MEMCACHED_SUCCESS, + memcached_set(memc, key, length, + NULL, 0, // Zero length values + time_t(0), uint32_t(0))); } memcached_quit(memc); uint64_t counter= 0; - test_compare_got(MEMCACHED_SUCCESS, - memcached_stat_execute(memc, NULL, item_counter, &counter), - memcached_last_error_message(memc)); - test_true_got(counter > 0, counter); + test_compare(MEMCACHED_SUCCESS, + memcached_stat_execute(memc, NULL, item_counter, &counter)); + test_true(counter); return TEST_SUCCESS; } diff --git a/tests/libmemcached-1.0/touch.cc b/tests/libmemcached-1.0/touch.cc index 425e308c..07f0096f 100644 --- a/tests/libmemcached-1.0/touch.cc +++ b/tests/libmemcached-1.0/touch.cc @@ -91,7 +91,7 @@ test_return_t test_memcached_touch(memcached_st *memc) test_skip(false ,memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)); rc= memcached_touch(memc, test_literal_param(__func__), 60 *60 *24 *60); - test_compare_hint(MEMCACHED_SUCCESS, rc, memcached_last_error_message(memc)); + test_compare(MEMCACHED_SUCCESS, rc); test_compare(MEMCACHED_NOTFOUND, memcached_exist(memc, test_literal_param(__func__))); diff --git a/tests/libmemcached-1.0/virtual_buckets.cc b/tests/libmemcached-1.0/virtual_buckets.cc index ec8225dc..82195e80 100644 --- a/tests/libmemcached-1.0/virtual_buckets.cc +++ b/tests/libmemcached-1.0/virtual_buckets.cc @@ -136,7 +136,7 @@ test_return_t virtual_back_map(memcached_st *) char buffer[1024]; snprintf(buffer, sizeof(buffer), "%.*s:%lu Got/Expected %u == %u", (int)ptr->key.size, ptr->key.c_str, (unsigned long)ptr->key.size, server_idx, ptr->server_id); - test_true_got(server_idx == ptr->server_id, buffer); + test_compare(server_idx, ptr->server_id); } memcached_server_list_free(server_pool); diff --git a/tests/runner.h b/tests/runner.h index fcce6e2f..0d1a767d 100644 --- a/tests/runner.h +++ b/tests/runner.h @@ -105,10 +105,9 @@ private: { char buffer[BUFSIZ]; - test_compare_got(MEMCACHED_SUCCESS, - libmemcached_check_configuration(container->construct.option_string().c_str(), container->construct.option_string().size(), - buffer, sizeof(buffer)), - container->construct.option_string().c_str()); + test_compare(MEMCACHED_SUCCESS, + libmemcached_check_configuration(container->construct.option_string().c_str(), container->construct.option_string().size(), + buffer, sizeof(buffer))); test_null(container->parent()); container->parent(memcached(container->construct.option_string().c_str(), container->construct.option_string().size())); -- 2.30.2