AM_CONDITIONAL([HAVE_LIBMEMCACHED],[false])
AM_CONDITIONAL([HAVE_LIBDRIZZLE],[false])
AC_DEFINE([HAVE_LIBMEMCACHED],[1],[Enables libmemcached Support])
+AC_SUBST([LIBMEMCACHED_CFLAGS])
+AC_SUBST([LIBMEMCACHED_LIB],[libmemcached/libmemcached.la])
AM_CONDITIONAL([BUILDING_GEARMAN],[false])
if (errno != 0)
{
- fatal_message("Bad value for YATL_ALARM");
+ FATAL("Bad value for YATL_ALARM");
}
else if (tv_sec == 0)
{
return true;
}
- bool build(size_t argc, const char *argv[]);
+ bool build();
};
#include <sstream>
-bool BlobslapWorker::build(size_t argc, const char *argv[])
+bool BlobslapWorker::build()
{
- std::stringstream arg_buffer;
-
- for (size_t x= 0 ; x < argc ; x++)
- {
- if (argv[x] == NULL)
- {
- break;
- }
-
- add_option(argv[x]);
- }
-
return true;
}
}
else
{
- fatal_message(strerror(errno));
+ FATAL(strerror(errno));
}
address_info_next= address_info_next->ai_next;
}
{
if (libtool() == NULL)
{
- fatal_message("libtool requested, but know libtool was found");
+ FATAL("libtool requested, but know libtool was found");
}
}
case EFAULT:
case ENOMEM:
- fatal_message(strerror(error));
+ FATAL(strerror(error));
break;
case EINVAL:
- fatal_message("RLIMIT_NOFILE exceeded, or if OSX the timeout value was invalid");
+ FATAL("RLIMIT_NOFILE exceeded, or if OSX the timeout value was invalid");
break;
default:
- fatal_message(strerror(error));
+ FATAL(strerror(error));
break;
}
if (pipe(_pipe_fd) == -1)
#endif
{
- fatal_message(strerror(errno));
+ FATAL(strerror(errno));
}
_open[0]= true;
_open[1]= true;
#if defined(HAVE_PIPE2) && HAVE_PIPE2
- return;
-#endif
{
nonblock();
cloexec();
}
+#endif
}
void Application::Pipe::cloexec()
int ret;
if ((ret= posix_spawn_file_actions_adddup2(&file_actions, _pipe_fd[type], _std_fd )) < 0)
{
- Error << "posix_spawn_file_actions_adddup2(" << strerror(ret) << ")";
- fatal_message(strerror(ret));
+ FATAL("posix_spawn_file_actions_adddup2(%s)", strerror(ret));
}
if ((ret= posix_spawn_file_actions_addclose(&file_actions, _pipe_fd[type])) < 0)
{
- Error << "posix_spawn_file_actions_adddup2(" << strerror(ret) << ")";
- fatal_message(strerror(ret));
+ FATAL("posix_spawn_file_actions_addclose(%s)", strerror(ret));
}
}
#pragma once
-#ifdef _WIN32
-typedef int posix_spawn_file_actions_t;
-#else
-# include <spawn.h>
-#endif
-
-#include <pthread.h>
+#include <spawn.h>
// http://www.gnu.org/software/automake/manual/automake.html#Using-the-TAP-test-protocol
#ifndef EXIT_SKIP
#endif
#ifndef EX_NOEXEC
-# define EX_NOEXEC 126
+# define EX_NOEXEC 126
#endif
#ifndef EX_NOTFOUND
-# define EX_NOTFOUND 127
+# define EX_NOTFOUND 127
#endif
namespace libtest {
}
// Special case where check for the testing of the exception
// system.
- catch (libtest::fatal &e)
+ catch (const libtest::fatal& e)
{
if (libtest::fatal::is_disabled())
{
}
libtest::cancel_alarm();
}
- catch (libtest::fatal &e)
+ catch (const libtest::fatal& e)
{
stream::cerr(e.file(), e.line(), e.func()) << e.what();
_failed++;
break;
default:
- fatal_message("invalid return code");
+ FATAL("invalid return code");
}
#if 0
@TODO add code here to allow for a collection to define a method to reset to allow tests to continue.
uint32_t _total;
libtest::Timer _timer;
libtest::Formatter _formatter;
+
+private:
+ Collection( const Collection& );
+ const Collection& operator=( const Collection& );
};
} // namespace libtest
{
if (__expected == NULL)
{
- fatal_message("Expected value was NULL, programmer error");
+ FATAL("Expected value was NULL, programmer error");
}
if (__actual == NULL)
}
int ret;
- fprintf(stderr, ":%s:\n", host);
if ((ret= getaddrinfo(host, NULL, NULL, &addrinfo)) == 0)
{
success= true;
#endif
#if defined(HAVE_LIBDRIZZLE) && HAVE_LIBDRIZZLE
-#include <libdrizzle-1.0/drizzle_client.h>
+# include <libdrizzle-5.1/drizzle_client.h>
#endif
using namespace libtest;
{
(void)(_port);
#if defined(HAVE_LIBDRIZZLE) && HAVE_LIBDRIZZLE
+ if (HAVE_LIBDRIZZLE)
{
- drizzle_st *drizzle= drizzle_create(NULL);
+ drizzle_st *drizzle= drizzle_create_tcp(getenv("MYSQL_SERVER"),
+ getenv("MYSQL_PORT") ? atoi("MYSQL_PORT") : DRIZZLE_DEFAULT_TCP_PORT,
+ getenv("MYSQL_USER"),
+ getenv("MYSQL_PASSWORD"),
+ getenv("MYSQL_SCHEMA"), drizzle_options_t());
if (drizzle == NULL)
{
return false;
}
- drizzle_con_st *con;
-
- if ((con= drizzle_con_create(drizzle, NULL)) == NULL)
- {
- drizzle_free(drizzle);
- return false;
- }
-
- drizzle_con_set_tcp(con, "localhost", _port);
- drizzle_con_set_auth(con, "root", 0);
-
bool success= false;
drizzle_return_t rc;
- if ((rc= drizzle_con_connect(con)) == DRIZZLE_RETURN_OK)
+ if ((rc= drizzle_connect(drizzle)) == DRIZZLE_RETURN_OK)
{
- drizzle_result_st *result= drizzle_ping(con, NULL, &rc);
+ drizzle_result_st *result= drizzle_ping(drizzle, &rc);
success= bool(result);
drizzle_result_free(result);
}
Error << drizzle_error(drizzle) << " localhost:" << _port;
}
- drizzle_con_free(con);
- drizzle_free(drizzle);
+ drizzle_quit(drizzle);
return success;
}
}
}
- bool build(size_t argc, const char *argv[]);
+ bool build();
};
-bool Drizzle::build(size_t argc, const char *argv[])
+bool Drizzle::build()
{
if (getuid() == 0 or geteuid() == 0)
{
add_option("--datadir=var/drizzle");
#endif
- for (size_t x= 0 ; x < argc ; x++)
- {
- if (argv[x] == NULL)
- {
- break;
- }
-
- add_option(argv[x]);
- }
-
return true;
}
#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),
- _error_message(NULL),
- _error_message_size(0)
+ __test_result(file_arg, line_arg, func_arg)
{
va_list args;
va_start(args, func_arg);
- 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)
- {
- _error_message_size++;
- }
+ init(args);
va_end(args);
}
fatal::fatal( const fatal& other ) :
- __test_result(other),
- _error_message_size(other._error_message_size)
-{
- _error_message= (char*) malloc(_error_message_size);
- if (_error_message)
- {
- memcpy(_error_message, other._error_message, _error_message_size);
- }
- else
- {
- _error_message_size= -1;
- }
-}
-
-fatal::~fatal() throw()
+ __test_result(other)
{
- if ((_error_message_size > 0) and _error_message)
- {
- free(_error_message);
- _error_message= NULL;
- }
}
static bool _disabled= false;
static uint32_t _counter= 0;
-bool fatal::is_disabled()
+bool fatal::is_disabled() throw()
{
return _disabled;
}
-void fatal::disable()
+void fatal::disable() throw()
{
_counter= 0;
_disabled= true;
}
-void fatal::enable()
+void fatal::enable() throw()
{
_counter= 0;
_disabled= false;
}
-uint32_t fatal::disabled_counter()
+uint32_t fatal::disabled_counter() throw()
{
return _counter;
}
-void fatal::increment_disabled_counter()
+void fatal::increment_disabled_counter() throw()
{
_counter++;
}
snprintf(_error_message, sizeof(_error_message), "%s:%u %s", instance.c_str(), uint32_t(port), last_error);
}
+disconnected::disconnected(const disconnected& other):
+ std::runtime_error(other._func),
+ _port(other._port),
+ _line(other._line),
+ _file(other._file),
+ _func(other._func)
+{
+ strncpy(_error_message, other._error_message, BUFSIZ);
+ strncpy(_instance, other._instance, BUFSIZ);
+}
+
} // namespace libtest
namespace libtest {
-class disconnected : std::runtime_error
+class disconnected : public std::runtime_error
{
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[0];
+ return _error_message;
}
+ disconnected(const disconnected&);
+
// The following are just for unittesting the exception class
static bool is_disabled();
static void disable();
-
+ static void enable();
static uint32_t disabled_counter();
static void increment_disabled_counter();
- int line()
+ int line() const
{
return _line;
}
- const char* file()
+ const char* file() const
{
return _file;
}
- const char* func()
+ const char* func() const
{
return _func;
}
private:
char _error_message[BUFSIZ];
in_port_t _port;
- char _instance[1024];
+ char _instance[BUFSIZ];
int _line;
const char* _file;
const char* _func;
break;
}
}
- catch (libtest::fatal& e)
+ catch (const libtest::fatal& e)
{
_failed++;
stream::cerr(e.file(), e.line(), e.func()) << e.what();
}
- catch (libtest::disconnected& e)
+ catch (const libtest::disconnected& e)
{
_failed++;
Error << "Unhandled disconnection occurred:" << e.what();
}
private:
- Framework& operator=(const Framework&);
-
uint32_t _total;
uint32_t _success;
uint32_t _skipped;
std::string _only_run;
std::string _wildcard;
std::string _name;
+
+private:
+ Framework( const Framework& );
+ const Framework& operator=( const Framework& );
};
} // namespace libtest
return true;
}
- bool build(size_t argc, const char *argv[]);
+ bool build();
};
Gearmand::Gearmand(const std::string& host_arg, in_port_t port_arg, bool libtool_, const char* binary_arg) :
set_pid_file();
}
-bool Gearmand::build(size_t argc, const char *argv[])
+bool Gearmand::build()
{
if (getuid() == 0 or geteuid() == 0)
{
add_option("--listen=localhost");
- for (size_t x= 0 ; x < argc ; x++)
- {
- if (argv[x] == NULL)
- {
- break;
- }
-
- add_option(argv[x]);
- }
-
return true;
}
#if defined(HAVE_LIBCURL) && HAVE_LIBCURL
if (curl_global_init(CURL_GLOBAL_ALL))
{
- fatal_message("curl_global_init(CURL_GLOBAL_ALL) failed");
+ FATAL("curl_global_init(CURL_GLOBAL_ALL) failed");
}
#endif
if (atexit(cleanup_curl))
{
- fatal_message("atexit() failed");
+ FATAL("atexit() failed");
}
}
int ret;
if ((ret= pthread_once(&start_key_once, initialize_curl_startup)) != 0)
{
- fatal_message(strerror(ret));
+ FATAL(strerror(ret));
}
}
GDB_COMMAND= $(LIBTOOL_COMMAND) gdb -f -x libtest/run.gdb
PTRCHECK_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=exp-ptrcheck --error-exitcode=1
PAHOLE_COMMAND= $(LIBTOOL_COMMAND) --mode=execute pahole
+VALGRIND_SUPRESSION= $(LIBTOOL_COMMAND) valgrind --leak-check=full --show-reachable=yes --error-limit=no --gen-suppressions=all --log-file=minimalraw.log
export LIBTOOL_COMMAND
export VALGRIND_COMMAND
valgrind:
@echo make check TESTS_ENVIRONMENT="\"$(VALGRIND_EXEC_COMMAND)\""
+valgrind-supressions:
+ @echo make check TESTS_ENVIRONMENT="\"$(VALGRIND_SUPRESSION)\""
+
gdb:
@echo make check TESTS_ENVIRONMENT="\"$(GDB_COMMAND)\""
EXTRA_libtest_libtest_la_DEPENDENCIES=
libtest_libtest_la_LIBADD=
libtest_libtest_la_SOURCES=
+libtest_libtest_la_CXXFLAGS+= @LIBMEMCACHED_CFLAGS@
+libtest_libtest_la_LIBADD+= @LIBMEMCACHED_LIB@
libtest_libtest_la_SOURCES+= libtest/alarm.cc
libtest_libtest_la_SOURCES+= libtest/binaries.cc
# Declare unittest so that we can append to it
libtest_unittest_CXXFLAGS=
libtest_unittest_LDADD=
+libtest_libtest_la_LDFLAGS=
# We are either building in tree, or with
libtest_libtest_la_SOURCES+= libtest/memcached.cc
-if HAVE_LIBDRIZZLE
-
-libtest_libtest_la_LIBADD+= $(libdrizzle_LIBS)
-libtest_libtest_la_CXXFLAGS+= $(libdrizzle_CFLAGS)
-
-endif
+libtest_libtest_la_LDFLAGS+= @LIBDRIZZLE_LDFLAGS@
+libtest_libtest_la_LIBADD+= @LIBDRIZZLE_LIB@
libtest_libtest_la_SOURCES+= libtest/gearmand.cc
uint32_t waited;
uint32_t retry;
- for (waited= 0, retry= 4; ; retry++, waited+= this_wait)
+ for (waited= 0, retry= 1; ; retry++, waited+= this_wait)
{
int status= 0;
if (waitpid(pid_arg, &status, WNOHANG) == 0)
return EXIT_FAILURE;
}
}
- catch (libtest::__skipped e)
+ catch (const libtest::__skipped& e)
{
return EXIT_SKIP;
}
Outn(); // Generate a blank to break up the messages if make check/test has been run
} while (exit_code == EXIT_SUCCESS and --opt_repeat);
}
- catch (libtest::__skipped e)
+ catch (const libtest::__skipped& e)
{
return EXIT_SKIP;
}
- catch (libtest::__failure e)
+ catch (const libtest::__failure& e)
{
libtest::stream::make_cout(e.file(), e.line(), e.func()) << e.what();
exit_code= EXIT_FAILURE;
}
- catch (libtest::fatal& e)
+ catch (const libtest::fatal& e)
{
std::cerr << "FATAL:" << e.what() << std::endl;
exit_code= EXIT_FAILURE;
}
- catch (libtest::disconnected& e)
+ catch (const libtest::disconnected& e)
{
std::cerr << "Unhandled disconnection occurred:" << e.what() << std::endl;
exit_code= EXIT_FAILURE;
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
std::cerr << "std::exception:" << e.what() << std::endl;
exit_code= EXIT_FAILURE;
return true;
}
- bool build(size_t argc, const char *argv[]);
+ bool build();
};
#include <sstream>
-bool Memcached::build(size_t argc, const char *argv[])
+bool Memcached::build()
{
if (getuid() == 0 or geteuid() == 0)
{
}
add_option("-l", "localhost");
-#ifndef TARGET_OS_OSX
+#ifdef __APPLE__
+#else
add_option("-m", "128");
add_option("-M");
#endif
add_option(sasl());
}
- for (size_t x= 0 ; x < argc ; x++)
- {
- if (argv[x] == NULL)
- {
- break;
- }
-
- add_option(argv[x]);
- }
-
return true;
}
// We handle the case where if we max out retries, we still abort.
if (retries == 0)
{
- fatal_message("No port could be found, exhausted retry");
+ FATAL("No port could be found, exhausted retry");
}
if (ret_port == 0)
{
- fatal_message("No port could be found");
+ FATAL("No port could be found");
}
if (ret_port == default_port)
{
- fatal_message("No port could be found");
+ FATAL("No port could be found");
}
if (ret_port <= 1024)
{
- fatal_message("No port could be found, though some where available below or at 1024");
+ FATAL("No port could be found, though some where available below or at 1024");
}
all_socket_fd.last_port= ret_port;
*
* 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
#include <libtest/common.h>
#include <cstdarg>
-#ifndef __INTEL_COMPILER
-# pragma GCC diagnostic ignored "-Wformat-nonliteral"
-#endif
-
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)
-{
-}
-
-__success::__success(const char *file_arg, int line_arg, const char *func_arg):
- __test_result(file_arg, line_arg, func_arg)
+ _func(func_arg),
+ _error_message(NULL),
+ _error_message_size(0)
{
}
-__skipped::__skipped(const char *file_arg, int line_arg, const char *func_arg, ...):
- __test_result(file_arg, line_arg, 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_)
{
- va_list args;
- va_start(args, func_arg);
- const char *format= va_arg(args, const char *);
- _error_message_size= vasprintf(&_error_message, format, 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)
{
_error_message_size++;
}
- va_end(args);
}
-__skipped::__skipped( const __skipped& other ) :
- __test_result(other),
+__test_result::~__test_result() throw()
+{
+ free(_error_message);
+}
+
+__test_result::__test_result(const __test_result& other) :
+ _line(other._line),
+ _file(other._file),
+ _func(other._func),
_error_message_size(other._error_message_size)
{
- _error_message= (char*) malloc(_error_message_size);
- if (_error_message)
- {
- memcpy(_error_message, other._error_message, _error_message_size);
- }
- else
+ if (_error_message_size > 0)
{
- _error_message_size= -1;
+ _error_message= (char*) malloc(_error_message_size);
+ if (_error_message)
+ {
+ memcpy(_error_message, other._error_message, _error_message_size);
+ }
+ else
+ {
+ _error_message_size= -1;
+ }
}
}
-__skipped::~__skipped() throw()
+__success::__success(const char *file_arg, int line_arg, const char *func_arg):
+ __test_result(file_arg, line_arg, func_arg)
{
- if ((_error_message_size > 0) and _error_message)
- {
- free(_error_message);
- _error_message= NULL;
- }
}
-__failure::__failure(const char *file_arg, int line_arg, const char *func_arg, ...) :
- __test_result(file_arg, line_arg, func_arg),
- _error_message(NULL),
- _error_message_size(0)
+__skipped::__skipped(const char *file_arg, int line_arg, const char *func_arg, ...):
+ __test_result(file_arg, line_arg, func_arg)
{
va_list args;
va_start(args, func_arg);
- 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)
- {
- _error_message_size++;
- }
+ init(args);
va_end(args);
}
-__failure::__failure( const __failure& other ) :
- __test_result(other),
- _error_message_size(other._error_message_size)
+__skipped::__skipped(const __skipped& other) :
+ __test_result(other)
{
- _error_message= (char*) malloc(_error_message_size);
- if (_error_message)
- {
- memcpy(_error_message, other._error_message, _error_message_size);
- }
- else
- {
- _error_message_size= -1;
- }
}
-__failure::~__failure() throw()
+__failure::__failure(const char *file_arg, int line_arg, const char *func_arg, ...) :
+ __test_result(file_arg, line_arg, func_arg)
+{
+ va_list args;
+ va_start(args, func_arg);
+ init(args);
+ va_end(args);
+}
+
+__failure::__failure(const __failure& other) :
+ __test_result(other)
{
- if ((_error_message_size > 0) and _error_message)
- {
- free(_error_message);
- _error_message= NULL;
- }
}
throw libtest::__failure(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \
} while (0)
-#define fatal_message(...) \
+#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); }
*
* 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
public:
__test_result(const char *file, int line, const char *func);
- __test_result( const __test_result& other ) :
- _line(other._line),
- _file(other._file),
- _func(other._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()
+ int line() const
{
return _line;
}
- const char* file()
+ const char* file() const
{
return _file;
}
- const char* func()
+ const char* func() const
{
return _func;
}
+protected:
+ void init(va_list);
+
private:
int _line;
const char* _file;
const char* _func;
+ char* _error_message;
+ int _error_message_size;
};
} // namespace libtest
public:
__failure(const char *file, int line, const char *func, ...);
- __failure(const __failure& other);
-
- ~__failure() throw();
-
- const char* what() const throw()
- {
- return _error_message;
- }
+ __failure(const __failure&);
private:
- char* _error_message;
- int _error_message_size;
};
} // namespace libtest
-
fatal(const fatal&);
- ~fatal() throw();
-
- const char* what() const throw()
- {
- return &_error_message[0];
- }
-
// The following are just for unittesting the exception class
- static bool is_disabled();
- static void disable();
- static void enable();
- static uint32_t disabled_counter();
- static void increment_disabled_counter();
+ static bool is_disabled() throw();
+ static void disable() throw();
+ static void enable() throw();
+ static uint32_t disabled_counter() throw();
+ static void increment_disabled_counter() throw();
private:
- char* _error_message;
- int _error_message_size;
};
} // namespace libtest
__skipped(const char *file, int line, const char *func, ...);
__skipped(const __skipped&);
-
- ~__skipped() throw();
-
- const char* what() const throw()
- {
- return &_error_message[0];
- }
-
-private:
- char* _error_message;
- int _error_message_size;
};
} // namespace libtest
try {
ret= run(func, object);
}
- catch (libtest::__skipped e)
+ catch (const libtest::__skipped& e)
{
ret= TEST_SKIPPED;
}
- catch (libtest::__failure e)
+ catch (const libtest::__failure& e)
{
libtest::stream::make_cerr(e.file(), e.line(), e.func()) << e.what();
ret= TEST_FAILURE;
}
- catch (libtest::__success)
+ catch (const libtest::__success&)
{
ret= TEST_SUCCESS;
}
- catch (libtest::fatal& e)
+ catch (const libtest::fatal&)
{
throw;
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what();
throw;
try {
ret= pre(func, object);
}
- catch (libtest::__skipped e)
+ catch (const libtest::__skipped& e)
{
ret= TEST_SKIPPED;
}
- catch (libtest::__failure e)
+ catch (const libtest::__failure& e)
{
libtest::stream::make_cout(e.file(), e.line(), e.func()) << e.what();
ret= TEST_FAILURE;
}
- catch (libtest::__success)
+ catch (const libtest::__success&)
{
ret= TEST_SUCCESS;
}
- catch (libtest::fatal& e)
+ catch (const libtest::fatal& e)
{
throw;
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what();
throw;
try {
ret= post(func, object);
}
- catch (libtest::__skipped e)
+ catch (const libtest::__skipped& e)
{
ret= TEST_SKIPPED;
}
- catch (libtest::__failure e)
+ catch (const libtest::__failure& e)
{
libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what();
ret= TEST_FAILURE;
}
- catch (libtest::__success)
+ catch (const libtest::__success&)
{
ret= TEST_SUCCESS;
}
- catch (libtest::fatal& e)
+ catch (const libtest::fatal& e)
{
throw;
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what();
throw;
private:
libtest::server_startup_st* _servers;
+
+private:
+ Runner( const Runner& );
+ const Runner& operator=( const Runner& );
};
} // namespace Runner
Server::~Server()
{
- murder();
+ kill();
}
bool Server::check()
while (--limit and
is_pid_valid(_app.pid()))
{
- if (murder())
+ if (kill())
{
Log << "Killed existing server," << *this;
dream(0, 50000);
return wait.successful();
}
+bool Server::init(const char *argv[])
+{
+ if (argv)
+ {
+ for (const char **ptr= argv; *ptr ; ++ptr)
+ {
+ if (ptr)
+ {
+ add_option(*ptr);
+ }
+ }
+ }
+
+ return build();
+}
+
bool Server::has_pid() const
{
return (_app.pid() > 1);
return true;
}
-bool Server::murder()
+bool Server::kill()
{
if (check_pid(_app.pid())) // If we kill it, reset
{
#include <cassert>
#include <cstdio>
#include <cstring>
-
#include <netdb.h>
#include <netinet/in.h>
-
#include <string>
#include <unistd.h>
#include <vector>
virtual bool ping()= 0;
- virtual bool build(size_t argc, const char *argv[])= 0;
+ bool init(const char *argv[]);
+ virtual bool build()= 0;
void add_option(const std::string&);
void add_option(const std::string&, const std::string&);
std::string log_and_pid();
- bool murder();
+ bool kill();
bool start();
bool command(libtest::Application& app);
{
Server* tmp= servers[host_to_shutdown];
- if (tmp and tmp->murder() == false)
+ if (tmp and tmp->kill() == false)
{ }
else
{
bool success= true;
for (std::vector<Server *>::iterator iter= servers.begin(); iter != servers.end(); ++iter)
{
- if ((*iter)->has_pid() and (*iter)->murder() == false)
+ if ((*iter)->has_pid() and (*iter)->kill() == false)
{
Error << "Unable to kill:" << *(*iter);
success= false;
return _magic == MAGIC_MEMORY;
}
-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)
+bool server_startup(server_startup_st& construct, const std::string& server_type, in_port_t try_port, const char *argv[])
{
- return construct.start_server(server_type, try_port, argc, argv, opt_startup_message);
+ return construct.start_server(server_type, try_port, argv);
}
libtest::Server* server_startup_st::create(const std::string& server_type, in_port_t try_port, const bool is_socket)
bool server_startup_st::_start_server(const bool is_socket,
const std::string& server_type,
in_port_t try_port,
- int argc, const char *argv[],
- const bool opt_startup_message)
+ const char *argv[])
{
try {
ServerPtr server(create(server_type, try_port, is_socket));
return false;
}
- server->build(argc, argv);
+ server->init(argv);
#if 0
if (false)
}
else
{
- if (opt_startup_message)
{
#if defined(DEBUG)
if (DEBUG)
set_default_socket(server->socket().c_str());
}
}
- catch (libtest::disconnected& err)
+ catch (const libtest::disconnected& err)
{
if (fatal::is_disabled() == false and try_port != LIBTEST_FAIL_PORT)
{
return false;
}
}
- catch (libtest::__test_result& err)
+ catch (const libtest::__test_result& err)
{
stream::cerr(err.file(), err.line(), err.func()) << err.what();
return false;
}
- catch (std::exception& err)
+ catch (const std::exception& err)
{
Error << err.what();
return false;
return true;
}
-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)
+bool server_startup_st::start_server(const std::string& server_type, in_port_t try_port, const char *argv[])
{
- return _start_server(false, server_type, try_port, argc, argv, opt_startup_message);
+ return _start_server(false, server_type, try_port, 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)
+bool server_startup_st::start_socket_server(const std::string& server_type, const in_port_t try_port, const char *argv[])
{
- return _start_server(true, server_type, try_port, argc, argv, opt_startup_message);
+ return _start_server(true, server_type, try_port, argv);
}
std::string server_startup_st::option_string() const
#include <cassert>
#include <cstdio>
#include <cstring>
-
#include <netdb.h>
#include <netinet/in.h>
-
#include <string>
#include <unistd.h>
#include <vector>
bool validate();
- 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);
+ bool start_socket_server(const std::string& server_type, const in_port_t try_port, const char *argv[]);
+ bool start_server(const std::string& server_type, const in_port_t try_port, const char *argv[]);
uint32_t count() const
{
bool _start_server(const bool is_socket,
const std::string& server_type,
const in_port_t try_port,
- int argc, const char *argv[],
- const bool opt_startup_message);
+ const char *argv[]);
private:
unsigned long int _servers_to_run;
};
-bool server_startup(server_startup_st&, const std::string&, in_port_t try_port, int argc, const char *argv[], const bool opt_startup_message= true);
+bool server_startup(server_startup_st&, const std::string&, in_port_t try_port, const char *argv[]);
} // namespace libtest
sigaddset(&set, SIGINT);
sigaddset(&set, SIGVTALRM);
}
- else
- {
- Out << "Inside of GDB, disabling signal handlers";
- }
-
sigaddset(&set, SIGPIPE);
sigaddset(&set, SIGUSR2);
_func(func)
{ }
- ~log()
+ virtual ~log()
{
output_policy()(arg, _out, _filename, _line_number, _func);
}
private:
typename output_policy::stream_buffer arg;
+
+ private:
+ log( const log& );
+ const log& operator=( const log& );
};
} // namespace detail
detail::log<detail::channelln>(std::cerr, filename, line_number, func)
{ }
+private:
+ make_cerr( const make_cerr& );
+ const make_cerr& operator=( const make_cerr& );
};
class cerr : public detail::log<detail::channel> {
detail::log<detail::channel>(std::cout, filename, line_number, func)
{ }
+private:
+ cerr( const cerr& );
+ const cerr& operator=( const cerr& );
};
class clog : public detail::log<detail::channel> {
clog(const char* filename, int line_number, const char* func) :
detail::log<detail::channel>(std::clog, filename, line_number, func)
{ }
+
+private:
+ clog( const clog& );
+ const clog& operator=( const clog& );
};
class make_cout : public detail::log<detail::channelln> {
detail::log<detail::channelln>(std::cout, filename, line_number, func)
{ }
+private:
+ make_cout( const make_cout& );
+ const make_cout& operator=( const make_cout& );
};
class cout : public detail::log<detail::channel> {
cout(const char* filename, int line_number, const char* func) :
detail::log<detail::channel>(std::cout, filename, line_number, func)
{ }
+
+private:
+ cout( const cout& );
+ const cout& operator=( const cout& );
};
return "skipped";
}
- fatal_message("No port could be found");
+ FATAL("No port could be found");
}
} // namespace libtest
class Mutex
{
public:
- Mutex()
+ Mutex() :
+ _err(0)
{
- int err;
- if ((err= pthread_mutex_init(&_mutex, NULL)))
- {
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_mutex_init: %s", strerror(err));
- }
+ _err= pthread_mutex_init(&_mutex, NULL);
}
~Mutex()
{
- int err;
- if ((err= pthread_mutex_destroy(&_mutex)))
+ if ((_err= pthread_mutex_destroy(&_mutex)))
{
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_cond_destroy: %s", strerror(err));
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_cond_destroy: %s", strerror(_err));
}
}
pthread_mutex_t* handle()
{
+ if (_err != 0)
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_mutex_init: %s", strerror(_err));
+ }
+
return &_mutex;
}
private:
+ int _err;
pthread_mutex_t _mutex;
};
#include <ctime>
#include <iomanip>
+#ifdef __MACH__
+# include <mach/clock.h>
+# include <mach/mach.h>
+#else
+# include <sys/time.h>
+#endif
+
namespace libtest {
+Timer::Timer()
+{
+ _begin.tv_sec= 0;
+ _begin.tv_nsec= 0;
+ _end.tv_sec= 0;
+ _end.tv_nsec= 0;
+}
+
+void Timer::reset()
+{
+ _end.tv_sec= 0;
+ _end.tv_nsec= 0;
+ _time(_begin);
+}
+
+void Timer::sample()
+{
+ _time(_end);
+}
+
+void Timer::offset(int64_t minutes_arg, int64_t seconds_arg, int64_t nanoseconds)
+{
+ reset();
+ _end= _begin;
+ _end.tv_sec+= (minutes_arg * 60) +seconds_arg;
+ _end.tv_nsec+= nanoseconds;
+}
+
+int64_t Timer::minutes()
+{
+ struct timespec result;
+ difference(result);
+ return int64_t(result.tv_sec / 60);
+}
+
+uint64_t Timer::elapsed_milliseconds() const
+{
+ struct timespec temp;
+ difference(temp);
+
+ return temp.tv_sec*1000 +temp.tv_nsec/1000000;
+}
+
+void Timer::difference(struct timespec& arg) const
+{
+ if ((_end.tv_nsec -_begin.tv_nsec) < 0)
+ {
+ arg.tv_sec= _end.tv_sec -_begin.tv_sec -1;
+ arg.tv_nsec= 1000000000 +_end.tv_nsec -_begin.tv_nsec;
+
+ }
+ else
+ {
+ arg.tv_sec= _end.tv_sec -_begin.tv_sec;
+ arg.tv_nsec= _end.tv_nsec -_begin.tv_nsec;
+ }
+}
+
+void Timer::_time(struct timespec& ts)
+{
+#ifdef __MACH__ // OSX lacks clock_gettime()
+ clock_serv_t _clock_serv;
+ mach_timespec_t _mach_timespec;
+ host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &_clock_serv);
+ clock_get_time(_clock_serv, &_mach_timespec);
+ mach_port_deallocate(mach_task_self(), _clock_serv);
+ ts.tv_sec= _mach_timespec.tv_sec;
+ ts.tv_nsec= _mach_timespec.tv_nsec;
+#elif defined(_WIN32)
+ ts.tv_sec= time(NULL);
+ ts.tv_nsec= 0;
+#else
+ clock_gettime(CLOCK_REALTIME, &ts);
+#endif
+}
+
std::ostream& operator<<(std::ostream& output, const libtest::Timer& arg)
{
struct timespec temp;
#include <ctime>
#include <iostream>
-#ifdef __MACH__
-# include <mach/clock.h>
-# include <mach/mach.h>
-#else
-# include <sys/time.h>
-#endif
-
namespace libtest {
class Timer {
public:
- Timer()
- {
- _begin.tv_sec= 0;
- _begin.tv_nsec= 0;
- _end.tv_sec= 0;
- _end.tv_nsec= 0;
- }
-
- void reset()
- {
- _end.tv_sec= 0;
- _end.tv_nsec= 0;
- _time(_begin);
- }
-
- void sample()
- {
- _time(_end);
- }
-
- void offset(int64_t minutes_arg, int64_t seconds_arg, int64_t nanoseconds)
- {
- reset();
- _end= _begin;
- _end.tv_sec+= (minutes_arg * 60) +seconds_arg;
- _end.tv_nsec+= nanoseconds;
- }
-
- int64_t minutes()
- {
- struct timespec result;
- difference(result);
- return int64_t(result.tv_sec / 60);
- }
-
- uint64_t elapsed_milliseconds() const
- {
- struct timespec temp;
- difference(temp);
-
- return temp.tv_sec*1000 +temp.tv_nsec/1000000;
- }
-
- void difference(struct timespec& arg) const
- {
- if ((_end.tv_nsec -_begin.tv_nsec) < 0)
- {
- arg.tv_sec= _end.tv_sec -_begin.tv_sec -1;
- arg.tv_nsec= 1000000000 +_end.tv_nsec -_begin.tv_nsec;
-
- }
- else
- {
- arg.tv_sec= _end.tv_sec -_begin.tv_sec;
- arg.tv_nsec= _end.tv_nsec -_begin.tv_nsec;
- }
- }
+ Timer();
+
+ void reset();
+
+ void sample();
+
+ void offset(int64_t minutes_arg, int64_t seconds_arg, int64_t nanoseconds);
+
+ int64_t minutes();
+
+ uint64_t elapsed_milliseconds() const;
+
+ void difference(struct timespec& arg) const;
private:
- void _time(struct timespec& ts)
- {
-#ifdef __MACH__ // OSX lacks clock_gettime()
- clock_serv_t _clock_serv;
- mach_timespec_t _mach_timespec;
- host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &_clock_serv);
- clock_get_time(_clock_serv, &_mach_timespec);
- mach_port_deallocate(mach_task_self(), _clock_serv);
- ts.tv_sec= _mach_timespec.tv_sec;
- ts.tv_nsec= _mach_timespec.tv_nsec;
-#elif defined(_WIN32)
- ts.tv_sec= time(NULL);
- ts.tv_nsec= 0;
-#else
- clock_gettime(CLOCK_REALTIME, &ts);
-#endif
- }
+ void _time(struct timespec& ts);
private:
struct timespec _begin;
try {
_SUCCESS;
}
- catch (libtest::__success)
+ catch (const libtest::__success&)
{
return TEST_SUCCESS;
}
try {
SKIP_IF(true);
}
- catch (libtest::__skipped e)
+ catch (const libtest::__skipped&)
{
return TEST_SUCCESS;
}
try {
throw libtest::__skipped(LIBYATL_DEFAULT_PARAM, "basic test");
}
- catch (libtest::__skipped e)
+ catch (const libtest::__skipped&)
{
return TEST_SUCCESS;
}
test_skip(true, has_drizzled());
- test_skip(true, server_startup(*servers, "drizzled", get_free_port(), 0, NULL, false));
+ test_skip(true, server_startup(*servers, "drizzled", get_free_port(), NULL));
return TEST_SUCCESS;
}
test_true(servers and servers->validate());
test_skip(true, has_gearmand());
- test_skip(true, server_startup(*servers, "gearmand", get_free_port(), 0, NULL, false));
+ test_skip(true, server_startup(*servers, "gearmand", get_free_port(), NULL));
servers->clear();
return TEST_SUCCESS;
test_true(servers);
fatal::disable();
- ASSERT_EQ(servers->start_server(testing_service, LIBTEST_FAIL_PORT, 0, NULL, false), true);
+ ASSERT_EQ(servers->start_server(testing_service, LIBTEST_FAIL_PORT, NULL), true);
fatal::enable();
return TEST_SUCCESS;
server_startup_st *servers= (server_startup_st*)object;
test_true(servers);
- ASSERT_EQ(servers->start_server(testing_service, get_free_port(), 0, NULL, false), true);
+ ASSERT_EQ(servers->start_server(testing_service, get_free_port(), NULL), true);
test_true(servers->last());
pid_t last_pid= servers->last()->pid();
server_startup_st *servers= (server_startup_st*)object;
test_true(servers);
- test_true(servers->start_socket_server(testing_service, get_free_port(), 0, NULL, false));
+ test_true(servers->start_socket_server(testing_service, get_free_port(), NULL));
return TEST_SUCCESS;
}
if (HAVE_LIBMEMCACHED)
{
test_true(has_memcached_sasl());
- test_true(server_startup(*servers, "memcached-sasl", get_free_port(), 0, NULL, false));
+ test_true(server_startup(*servers, "memcached-sasl", get_free_port(), NULL));
return TEST_SUCCESS;
}
static test_return_t fatal_message_TEST(void *)
{
ASSERT_EQ(fatal_calls++, fatal::disabled_counter());
- fatal_message("Fatal test");
+ FATAL("Fatal test");
return TEST_SUCCESS;
}
static test_return_t check_for_drizzle(void *)
{
- test_skip(true, HAVE_LIBDRIZZLE);
test_skip(true, has_drizzled());
testing_service= "drizzled";
static test_return_t check_for_curl(void *)
{
+ test_skip_valgrind();
test_skip(true, HAVE_LIBCURL);
return TEST_SUCCESS;
}
char* new_ptr= strdup(ptr);
if (new_ptr == NULL)
{
- fatal_message("UNABLE to allocate %s(%p)", ptr, ptr);
+ FATAL("UNABLE to allocate %s(%p)", ptr, ptr);
}
arg.push_back(new_ptr);
#include <unistd.h>
#include <string>
-#include <csignal>
+#include <signal.h>
-#include <sys/types.h>
#include <libtest/dream.h>
namespace libtest {
static test_return_t server_startup_single_TEST(void *obj)
{
server_startup_st *servers= (server_startup_st*)obj;
- test_compare(true, server_startup(*servers, "memcached", libtest::get_free_port(), 0, NULL, false));
+ test_compare(true, server_startup(*servers, "memcached", libtest::get_free_port(), NULL));
test_compare(true, servers->shutdown());
test_skip(true, jenkins_is_caller());
server_startup_st *servers= (server_startup_st*)obj;
- for (size_t x= 0; x < 10; x++)
+ for (size_t x= 0; x < 10; ++x)
{
- test_compare(true, server_startup(*servers, "memcached", libtest::get_free_port(), 0, NULL, false));
+ test_compare(true, server_startup(*servers, "memcached", libtest::get_free_port(), NULL));
}
test_compare(true, servers->shutdown());
while (memcached_server_count(memc) < 2)
{
const char *argv[1]= { "add_shutdown_server" };
- test_true(global_framework->servers().start_socket_server("memcached", libtest::default_port(), 1, argv));
+ test_true(global_framework->servers().start_socket_server("memcached", libtest::default_port(), argv));
test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, "localhost", libtest::default_port()));
}
static __attribute__((noreturn)) void* connection_release(void *arg)
{
test_pool_context_st *resource= static_cast<test_pool_context_st *>(arg);
- if (resource == NULL)
- {
- fatal_message("resource == NULL");
- }
+ FATAL_IF(resource == NULL);
// Release all of the memc we are holding
resource->rc= memcached_pool_release(resource->pool, resource->mmc);
static void set_running(const bool arg)
{
int error;
- if ((error= pthread_mutex_lock(&mutex)) != 0)
- {
- fatal_message(strerror(error));
- }
+ FATAL_IF_((error= pthread_mutex_lock(&mutex)) != 0, strerror(error));
_running= arg;
- if ((error= pthread_mutex_unlock(&mutex)) != 0)
- {
- fatal_message(strerror(error));
- }
+ FATAL_IF_((error= pthread_mutex_unlock(&mutex)) != 0, strerror(error));
}
static bool running()
int error;
bool ret;
- if ((error= pthread_mutex_lock(&mutex)) != 0)
- {
- fatal_message(strerror(error));
- }
+ FATAL_IF_((error= pthread_mutex_lock(&mutex)) != 0, strerror(error));
ret= _running;
- if ((error= pthread_mutex_unlock(&mutex)) != 0)
- {
- fatal_message(strerror(error));
- }
+ FATAL_IF_((error= pthread_mutex_unlock(&mutex)) != 0, strerror(error));
return ret;
}
if (servers.sasl())
{
- if (server_startup(servers, "memcached-sasl", port, 0, NULL) == false)
+ if (server_startup(servers, "memcached-sasl", port, NULL) == false)
{
error= TEST_SKIPPED;
return NULL;
}
else
{
- if (server_startup(servers, "memcached", port, 0, NULL) == false)
+ if (server_startup(servers, "memcached", port, NULL) == false)
{
error= TEST_SKIPPED;
return NULL;
for (uint32_t x= 0; x < servers.servers_to_run(); x++)
{
- const char *argv[1]= { "memcached" };
- if (servers.start_socket_server("memcached", libtest::get_free_port(), 1, argv) == false)
+ const char *argv[]= { "memcached", 0 };
+ if (servers.start_socket_server("memcached", libtest::get_free_port(), argv) == false)
{
#if 0
fatal_message("Could not launch memcached");
return NULL;
}
- if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
+ if (server_startup(servers, "memcached", libtest::default_port(), NULL) == false)
{
error= TEST_SKIPPED;
}
return NULL;
}
- if (not server_startup(servers, "memcached", libtest::default_port(), 0, NULL))
+ if (not server_startup(servers, "memcached", libtest::default_port(), NULL))
{
error= TEST_FAILURE;
}
return NULL;
}
- if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
+ if (server_startup(servers, "memcached", libtest::default_port(), NULL) == false)
{
error= TEST_FAILURE;
}
return NULL;
}
- if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
+ if (server_startup(servers, "memcached", libtest::default_port(), NULL) == false)
{
error= TEST_FAILURE;
return NULL;
return NULL;
}
- if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
+ if (server_startup(servers, "memcached", libtest::default_port(), NULL) == false)
{
error= TEST_SKIPPED;
}
return NULL;
}
- if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == 0)
+ if (server_startup(servers, "memcached", libtest::default_port(), NULL) == 0)
{
error= TEST_SKIPPED;
}
return NULL;
}
- if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
+ if (server_startup(servers, "memcached", libtest::default_port(), NULL) == false)
{
error= TEST_FAILURE;
}
return NULL;
}
- const char *argv[1]= { "memslap" };
- if (not server_startup(servers, "memcached", libtest::default_port(), 1, argv))
+ const char *argv[]= { "memslap", 0 };
+ if (server_startup(servers, "memcached", libtest::default_port(), argv) == false)
{
error= TEST_FAILURE;
}
return NULL;
}
- if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
+ if (server_startup(servers, "memcached", libtest::default_port(), NULL) == false)
{
error= TEST_SKIPPED;
}
return NULL;
}
- if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
+ if (server_startup(servers, "memcached", libtest::default_port(), NULL) == false)
{
error= TEST_SKIPPED;
}