AC_PREREQ([2.61])
AC_CONFIG_HEADERS([mem_config.h:mem_config.in])dnl Keep filename to 8.3 for MS-DOS.
+AC_SUBST([AUTOHEADER_FILE],[mem_config.h])
AC_CONFIG_SRCDIR([libmemcached/memcached.cc])
#shared library versioning
# Checks for header files.
AC_CHECK_HEADERS_ONCE([arpa/inet.h])
-AC_CHECK_HEADERS_ONCE([dlfcn.h])
AC_CHECK_HEADERS_ONCE([errno.h])
AC_CHECK_HEADERS_ONCE([execinfo.h])
AC_CHECK_HEADERS_ONCE([fcntl.h])
[AC_DEFINE([HAVE_CLOCK_GETTIME],[0],[Have clock_gettime])])
# Check for the ability to call dlopen (used in libhostile)
-AS_IF([test "x$enable_shared" = xyes],
- [AX_CHECK_LIBRARY([DL],[dlfcn.h],[dl],
- [AC_DEFINE([HAVE_LIBDL],[1],[Have dlopen])
- AC_CHECK_LIB([dl],[dlopen],[AC_DEFINE([HAVE_DLOPEN],[1],[Have dlopen])])
- AC_CHECK_LIB([dl],[dladdr],[AC_DEFINE([HAVE_DLADDR],[1],[Have dladdr])])])
- ])
+AX_DLOPEN
AC_CHECK_HEADERS([atomic.h])
AS_IF([test "x$ac_cv_header_atomic_h" = "xyes"],
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
+
#include <libtest/common.h>
#include <sys/time.h>
void set_alarm()
{
- if (gdb_is_caller() == false)
+ if (setitimer(ITIMER_VIRTUAL, &defualt_timer, NULL) == -1)
{
- if (setitimer(ITIMER_VIRTUAL, &defualt_timer, NULL) == -1)
- {
- Error << "setitimer() failed";
- }
+ Error << "setitimer() failed";
}
}
void set_alarm(long tv_sec, long tv_usec)
{
- if (gdb_is_caller() == false)
+ // For the moment use any value to YATL_ALARM to cancel alarming.
+ if (getenv("YATL_ALARM"))
{
+ errno= 0;
+ tv_sec= strtol(getenv("YATL_ALARM"), (char **) NULL, 10);
+
+ if (errno != 0)
+ {
+ fatal_message("Bad value for YATL_ALARM");
+ }
+ else if (tv_sec == 0)
+ {
+ cancel_alarm();
+ }
+ }
+
#if defined(TARGET_OS_OSX) && TARGET_OS_OSX
- struct timeval it_value= { time_t(tv_sec), suseconds_t(tv_usec) };
+ struct timeval it_value= { time_t(tv_sec), suseconds_t(tv_usec) };
#else
- struct timeval it_value= { tv_sec, tv_usec };
+ struct timeval it_value= { tv_sec, tv_usec };
#endif
- struct itimerval timer= { default_it_interval, it_value };
+ struct itimerval timer= { default_it_interval, it_value };
- if (setitimer(ITIMER_VIRTUAL, &timer, NULL) == -1)
- {
- Error << "setitimer() failed";
- }
+ if (setitimer(ITIMER_VIRTUAL, &timer, NULL) == -1)
+ {
+ Error << "setitimer() failed";
}
}
void cancel_alarm()
{
- if (gdb_is_caller() == false)
+ if (setitimer(ITIMER_VIRTUAL, &cancel_timer, NULL) == -1)
{
- if (setitimer(ITIMER_VIRTUAL, &cancel_timer, NULL) == -1)
- {
- Error << "setitimer() failed";
- }
+ Error << "setitimer() failed";
}
}
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
namespace libtest {
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
#include <libtest/blobslap_worker.h>
*
*/
-#include "mem_config.h"
-
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
-#ifdef HAVE_POLL_H
-# include <poll.h>
-#endif
-
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <string>
-#ifndef HAVE_MSG_NOSIGNAL
-# define MSG_NOSIGNAL 0
-#endif
namespace libtest {
SimpleClient::SimpleClient(const std::string& hostname_, in_port_t port_) :
+ _is_connected(false),
_hostname(hostname_),
_port(port_),
sock_fd(INVALID_SOCKET),
fds[0].events= event_;
fds[0].revents= 0;
- int ready_fds= poll(fds, 1, 5000);
+ int timeout= 5000;
+ if (_is_connected == false)
+ {
+ timeout= timeout * 30;
+ }
+
+ int ready_fds= poll(fds, 1, timeout);
if (ready_fds == -1)
{
return false;
}
+ _is_connected= true;
if (fds[0].revents & event_)
{
return true;
hints.ai_socktype= SOCK_STREAM;
hints.ai_protocol= IPPROTO_TCP;
- char service[NI_MAXSERV];
- (void)snprintf(service, NI_MAXSERV, "%d", _port);
+ libtest::vchar_t service;
+ service.resize(NI_MAXSERV);
+ (void)snprintf(&service[0], service.size(), "%d", _port);
int getaddrinfo_error;
- if ((getaddrinfo_error= getaddrinfo(_hostname.c_str(), service, &hints, &ai)) != 0)
+ if ((getaddrinfo_error= getaddrinfo(_hostname.c_str(), &service[0], &hints, &ai)) != 0)
{
if (getaddrinfo_error != EAI_SYSTEM)
{
void SimpleClient::close_socket()
{
- close(sock_fd);
- sock_fd= INVALID_SOCKET;
+ if (sock_fd != INVALID_SOCKET)
+ {
+ close(sock_fd);
+ sock_fd= INVALID_SOCKET;
+ }
}
bool SimpleClient::instance_connect()
{
+ _is_connected= false;
struct addrinfo *ai;
if ((ai= lookup()))
{
return true;
}
-bool SimpleClient::message(const std::string& arg)
+bool SimpleClient::message(const char* ptr, const size_t len)
{
if (is_valid())
{
if (ready(POLLOUT))
{
off_t offset= 0;
- const char* ptr= arg.c_str();
- size_t len= arg.size();
-
do
{
ssize_t nw= send(sock_fd, ptr + offset, len - offset, MSG_NOSIGNAL);
bool SimpleClient::send_message(const std::string& arg)
{
- if (message(arg) == true)
+ if (message(arg.c_str(), arg.size()) == true)
+ {
+ return message("\r\n", 2);
+ }
+
+ return false;
+}
+
+bool SimpleClient::send_data(const libtest::vchar_t& message_, libtest::vchar_t& response_)
+{
+ requested_message++;
+ if (message(&message_[0], message_.size()))
{
- return message("\r\n");
+ return response(response_);
}
return false;
return false;
}
+bool SimpleClient::response(libtest::vchar_t& response_)
+{
+ response_.clear();
+
+ if (is_valid())
+ {
+ if (ready(POLLIN))
+ {
+ bool more= true;
+ char buffer[2];
+ buffer[1]= 0;
+ do
+ {
+ ssize_t nr= recv(sock_fd, buffer, 1, MSG_NOSIGNAL);
+ if (nr == -1)
+ {
+ if (errno != EINTR)
+ {
+ _error= strerror(errno);
+ return false;
+ }
+ }
+ else if (nr == 0)
+ {
+ close_socket();
+ more= false;
+ }
+ else
+ {
+ response_.reserve(response_.size() + nr +1);
+ fatal_assert(nr == 1);
+ if (buffer[0] == '\n')
+ {
+ more= false;
+ }
+ response_.insert(response_.end(), buffer, buffer +nr);
+ }
+ } while (more);
+
+ return response_.size();
+ }
+ }
+
+ fatal_assert(_error.size());
+ return false;
+}
+
bool SimpleClient::response(std::string& response_)
{
response_.clear();
return false;
}
}
+ else if (nr == 0)
+ {
+ close_socket();
+ more= false;
+ }
else
{
fatal_assert(nr == 1);
SimpleClient(const std::string& hostname_, in_port_t port_);
~SimpleClient();
- bool send_message(const std::string& arg);
- bool send_message(const std::string& message_, std::string& response_);
+ bool send_data(const libtest::vchar_t&, libtest::vchar_t&);
+ bool send_message(const std::string&);
+ bool send_message(const std::string&, std::string&);
bool response(std::string&);
+ bool response(libtest::vchar_t&);
bool is_valid();
void close_socket();
bool instance_connect();
struct addrinfo* lookup();
- bool message(const std::string&);
+ bool message(const char* ptr, const size_t len);
bool ready(int event_);
private:
+ bool _is_connected;
std::string _hostname;
in_port_t _port;
int sock_fd;
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
+
#include "libtest/common.h"
using namespace libtest;
error_string+= built_argv[0];
throw std::logic_error(error_string);
}
- else if WIFSIGNALED(_status)
+ else if (WIFSIGNALED(_status))
{
if (WTERMSIG(_status) != SIGTERM and WTERMSIG(_status) != SIGHUP)
{
throw std::runtime_error(error_string);
}
-#if 0
// If we terminted it on purpose then it counts as a success.
Out << "waitpid() application terminated at request"
<< " pid:" << _pid
<< " name:" << built_argv[0];
-#endif
}
else
{
bool data_was_read= false;
+ libtest::vchar_t buffer;
+ buffer.resize(1024);
ssize_t read_length;
- char buffer[1024]= { 0 };
- while ((read_length= ::read(_pipe_fd[READ], buffer, sizeof(buffer))))
+ while ((read_length= ::read(_pipe_fd[READ], &buffer[0], buffer.size())))
{
if (read_length == -1)
{
built_argv.push_back(strdup("--free-fill=DE"));
std::string log_file= create_tmpfile("valgrind");
- char buffer[1024];
- int length= snprintf(buffer, sizeof(buffer), "--log-file=%s", log_file.c_str());
- fatal_assert(length > 0 and size_t(length) < sizeof(buffer));
- built_argv.push_back(strdup(buffer));
+ libtest::vchar_t buffer;
+ buffer.resize(1024);
+ int length= snprintf(&buffer[0], buffer.size(), "--log-file=%s", log_file.c_str());
+ fatal_assert(length > 0 and size_t(length) < buffer.size());
+ built_argv.push_back(strdup(&buffer[0]));
}
else if (_use_ptrcheck)
{
built_argv.push_back(strdup("--error-exitcode=1"));
built_argv.push_back(strdup("--tool=exp-ptrcheck"));
std::string log_file= create_tmpfile("ptrcheck");
- char buffer[1024];
- int length= snprintf(buffer, sizeof(buffer), "--log-file=%s", log_file.c_str());
- fatal_assert(length > 0 and size_t(length) < sizeof(buffer));
- built_argv.push_back(strdup(buffer));
+ libtest::vchar_t buffer;
+ buffer.resize(1024);
+ int length= snprintf(&buffer[0], buffer.size(), "--log-file=%s", log_file.c_str());
+ fatal_assert(length > 0 and size_t(length) < buffer.size());
+ built_argv.push_back(&buffer[0]);
}
else if (_use_gdb)
{
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
namespace libtest {
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <cstdlib>
#include <fcntl.h>
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
#include <unistd.h>
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
#include <sys/types.h>
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
namespace libtest {
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
#include <libtest/drizzled.h>
{
if (arg > 0)
{
- char buffer[1024];
- snprintf(buffer, sizeof(buffer), "--drizzle-protocol.port=%d", int(arg));
- app.add_option(buffer);
+ libtest::vchar_t buffer;
+ buffer.resize(1024);
+ snprintf(&buffer[1024], buffer.size(), "--drizzle-protocol.port=%d", int(arg));
+ app.add_option(&buffer[1024]);
}
}
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
#include <libtest/failed.h>
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
#include <cstdarg>
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
#include <libtest/collection.h>
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
#include <libtest/gearmand.h>
bool ping()
{
+ reset_error();
+
if (out_of_ban_killed())
{
return false;
SimpleClient client(_hostname, _port);
std::string response;
- return client.send_message("version", response);
+ bool ret= client.send_message("version", response);
+
+ if (client.is_error())
+ {
+ error(client.error());
+ }
+
+ return ret;
}
const char *name()
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
#include <cstdlib>
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
-#if defined(HAVE_CURL_CURL_H) && HAVE_CURL_CURL_H
+#if defined(HAVE_LIBCURL) && HAVE_LIBCURL
#include <curl/curl.h>
#else
class CURL;
static void cleanup_curl(void)
{
-#if defined(HAVE_CURL_CURL_H) && HAVE_CURL_CURL_H
+#if defined(HAVE_LIBCURL) && HAVE_LIBCURL
curl_global_cleanup();
#endif
}
static void initialize_curl_startup()
{
-#if defined(HAVE_CURL_CURL_H) && HAVE_CURL_CURL_H
+#if defined(HAVE_LIBCURL) && HAVE_LIBCURL
if (curl_global_init(CURL_GLOBAL_ALL))
{
fatal_message("curl_global_init(CURL_GLOBAL_ALL) failed");
EXTRA_DIST+= libtest/run.gdb
EXTRA_DIST+= libtest/version.h
-CLEANFILES+= tmp_chroot
-
BUILT_SOURCES+= libtest/version.h
.PHONY: clean-libtest-check
noinst_HEADERS+= libtest/memcached.hpp
noinst_HEADERS+= libtest/poll_error.hpp
noinst_HEADERS+= libtest/port.h
+noinst_HEADERS+= libtest/result.hpp
noinst_HEADERS+= libtest/runner.h
noinst_HEADERS+= libtest/server.h
noinst_HEADERS+= libtest/server_container.h
noinst_HEADERS+= libtest/string.hpp
noinst_HEADERS+= libtest/test.h
noinst_HEADERS+= libtest/test.hpp
+noinst_HEADERS+= libtest/thread.hpp
noinst_HEADERS+= libtest/tmpfile.hpp
noinst_HEADERS+= libtest/vchar.hpp
noinst_HEADERS+= libtest/version.h
libtest_libtest_la_SOURCES+= libtest/libtool.cc
libtest_libtest_la_SOURCES+= libtest/main.cc
libtest_libtest_la_SOURCES+= libtest/port.cc
+libtest_libtest_la_SOURCES+= libtest/result.cc
libtest_libtest_la_SOURCES+= libtest/runner.cc
libtest_libtest_la_SOURCES+= libtest/server.cc
libtest_libtest_la_SOURCES+= libtest/server_container.cc
libtest_libtest_la_CXXFLAGS+= -DLIBTEST_TEMP="\"tmp_chroot\""
libtest_libtest_la_CXXFLAGS+= $(CURL_CFLAGS)
-libtest_libtest_la_LIBADD+= $(CURL_LIBS)
libtest_libtest_la_LIBADD+= @PTHREAD_LIBS@
+libtest_libtest_la_LIBADD+= $(CURL_LIBS)
libtest_libtest_la_LIBADD+= @RT_LIB@
libtest_libtest_la_DEPENDENCIES+= libtest_tmp_dir
# We are either building in tree, or with
if BUILDING_LIBMEMCACHED
-libtest_libtest_la_DEPENDENCIES+= libmemcached/libmemcached.la
-libtest_libtest_la_DEPENDENCIES+= libmemcached/libmemcachedutil.la
-libtest_libtest_la_LIBADD+= libmemcached/libmemcached.la
-libtest_libtest_la_LIBADD+= libmemcached/libmemcachedutil.la
libtest_libtest_la_SOURCES+= libtest/memcached.cc
libtest_libtest_la_CXXFLAGS+= -DHAVE_LIBMEMCACHED
libtest_unittest_CXXFLAGS+= -DHAVE_LIBMEMCACHED
-libtest_unittest_LDADD+= libmemcached/libmemcached.la
-libtest_unittest_LDADD+= libmemcached/libmemcachedutil.la
-libtest_unittest_DEPENDENCIES+= libmemcached/libmemcached.la
-libtest_unittest_DEPENDENCIES+= libmemcached/libmemcachedutil.la
else
if HAVE_LIBMEMCACHED
-libtest_libtest_la_LIBADD+= $(LIBMEMCACHED_UTIL_LDFLAGS)
libtest_libtest_la_SOURCES+= libtest/memcached.cc
else
libtest_libtest_la_CXXFLAGS+= -DHAVE_LIBMEMCACHED=0
endif
if HAVE_LIBDRIZZLE
+
libtest_libtest_la_LIBADD+= $(libdrizzle_LIBS)
libtest_libtest_la_CXXFLAGS+= $(libdrizzle_CFLAGS)
+
endif
if BUILDING_GEARMAN
-libtest_libtest_la_DEPENDENCIES+= libgearman/libgearman.la
-libtest_libtest_la_LIBADD+= libgearman/libgearman.la
libtest_libtest_la_SOURCES+= libtest/blobslap_worker.cc
libtest_libtest_la_SOURCES+= libtest/gearmand.cc
libtest_libtest_la_SOURCES+= util/instance.cc
libtest_libtest_la_SOURCES+= util/operation.cc
-
-libtest_unittest_LDADD+= libgearman/libgearman.la
-libtest_unittest_DEPENDENCIES+= libgearman/libgearman.la
libtest_unittest_DEPENDENCIES+= gearmand/gearmand
else
if HAVE_LIBGEARMAN
-libtest_libtest_la_LIBADD+= @LIBGEARMAN_LIB@
libtest_libtest_la_SOURCES+= libtest/blobslap_worker.cc
libtest_libtest_la_SOURCES+= libtest/gearmand.cc
libtest_libtest_la_SOURCES+= util/instance.cc
endif
endif
-libtest_tmp_dir: tmp_chroot/var/log tmp_chroot/var/tmp tmp_chroot/var/run tmp_chroot/var/drizzle
-
-tmp_chroot: tmp_chroot/etc
- @$(mkdir_p) tmp_chroot
+TMP_DIR := tmp_chroot/etc tmp_chroot/var/log tmp_chroot/var/tmp tmp_chroot/var/run tmp_chroot/var/drizzle
-tmp_chroot/etc:
- @$(mkdir_p) tmp_chroot/etc
-
-tmp_chroot/var: tmp_chroot
- @$(mkdir_p) tmp_chroot/var
-
-tmp_chroot/var/log: tmp_chroot/var
- @$(mkdir_p) tmp_chroot/var/log
-
-tmp_chroot/var/tmp: tmp_chroot/var
- @$(mkdir_p) tmp_chroot/var/tmp
-
-tmp_chroot/var/drizzle: tmp_chroot/var
- @$(mkdir_p) tmp_chroot/var/drizzle
-
-tmp_chroot/var/run: tmp_chroot/var
- @$(mkdir_p) tmp_chroot/var/run
+.PHONY: libtest_tmp_dir
+libtest_tmp_dir: | $(TMP_DIR)
+$(TMP_DIR):
+ @$(mkdir_p) $(TMP_DIR)
libtest_unittest_DEPENDENCIES+= libtest/libtest.la
libtest_unittest_LDADD+= libtest/libtest.la
gdb-backtrace: libtest/backtrace
@$(GDB_COMMAND) libtest/backtrace
+
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
#include <cstdlib>
FILE *fp;
if ((fp= fopen(filename.c_str(), "r")))
{
- char pid_buffer[1024];
+ libtest::vchar_t pid_buffer;
+ pid_buffer.resize(1024);
- char *ptr= fgets(pid_buffer, sizeof(pid_buffer), fp);
+ char *ptr= fgets(&pid_buffer[0], int(pid_buffer.size()), fp);
fclose(fp);
if (ptr)
{
- pid_t pid= (pid_t)atoi(pid_buffer);
+ pid_t pid= (pid_t)atoi(&pid_buffer[0]);
if (pid > 0)
{
return (::kill(pid, 0) == 0);
FILE *fp;
if ((fp= fopen(filename.c_str(), "r")))
{
- char pid_buffer[1024];
+ libtest::vchar_t pid_buffer;
+ pid_buffer.resize(1024);
- char *ptr= fgets(pid_buffer, sizeof(pid_buffer), fp);
+ char *ptr= fgets(&pid_buffer[0], int(pid_buffer.size()), fp);
fclose(fp);
if (ptr)
{
- pid_t pid= (pid_t)atoi(pid_buffer);
+ pid_t pid= (pid_t)atoi(&pid_buffer[0]);
if (pid != 0)
{
bool ret= kill_pid(pid);
pid_t get_pid_from_file(const std::string &filename, std::stringstream& error_message)
{
pid_t ret= -1;
- FILE *fp;
if (filename.empty())
{
return ret;
}
+ FILE *fp;
if ((fp= fopen(filename.c_str(), "r")))
{
- char pid_buffer[1024];
-
- char *ptr= fgets(pid_buffer, sizeof(pid_buffer), fp);
- fclose(fp);
+ libtest::vchar_t pid_buffer;
+ pid_buffer.resize(1024);
+ char *ptr= fgets(&pid_buffer[0], int(pid_buffer.size()), fp);
if (ptr)
{
- ret= (pid_t)atoi(pid_buffer);
+ ret= (pid_t)atoi(&pid_buffer[0]);
if (ret < 1)
{
error_message << LIBTEST_AT << " Invalid pid was read from file " << filename;
error_message << LIBTEST_AT << " File " << filename << " was empty ";
}
+ fclose(fp);
+
return ret;
}
else
{
- char buffer[1024];
- char *current_directory= getcwd(buffer, sizeof(buffer));
+ libtest::vchar_t buffer;
+ buffer.resize(1024);
+ char *current_directory= getcwd(&buffer[0], buffer.size());
error_message << "Error while opening " << current_directory << "/" << filename << " " << strerror(errno);
}
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
#include <string>
#
# This macro calls:
#
+# AC_SUBST(MYSQL_INCLUDE)
# AC_SUBST(MYSQL_CFLAGS)
# AC_SUBST(MYSQL_LDFLAGS)
# AC_SUBST(MYSQL_VERSION)
# and this notice are preserved. This file is offered as-is, without any
# warranty.
-#serial 12
+#serial 13
AC_DEFUN([AX_LIB_MYSQL],
[
)
AC_ARG_VAR([MYSQL_CONFIG], [Full path to mysql_config program])
+ MYSQL_INCLUDE=""
MYSQL_CFLAGS=""
MYSQL_LDFLAGS=""
MYSQL_VERSION=""
fi
if test "$MYSQL_CONFIG" != "no"; then
+ MYSQL_INCLUDE="`$MYSQL_CONFIG --include`"
MYSQL_CFLAGS="`$MYSQL_CONFIG --cflags`"
MYSQL_LDFLAGS="`$MYSQL_CONFIG --libs`"
fi
AC_SUBST([MYSQL_VERSION])
+ AC_SUBST([MYSQL_INCLUDE])
AC_SUBST([MYSQL_CFLAGS])
AC_SUBST([MYSQL_LDFLAGS])
])
-AX_PROG_MYSQLD
-AX_WITH_PROG(MEMCACHED_BINARY, [memcached])
-AS_IF([test -f "$ac_cv_path_MEMCACHED_BINARY"],
- [
+#serial 1
+
+ AC_DEFUN([YATL_MEMCACHED], [
+ AC_REQUIRE([AX_ENABLE_LIBMEMCACHED])
+
+ AX_WITH_PROG(MEMCACHED_BINARY, [memcached])
+ AS_IF([test -f "$ac_cv_path_MEMCACHED_BINARY"],[
AC_DEFINE([HAVE_MEMCACHED_BINARY], [1], [If Memcached binary is available])
AC_DEFINE_UNQUOTED([MEMCACHED_BINARY], "$ac_cv_path_MEMCACHED_BINARY", [Name of the memcached binary used in make test])
- ],
- [
+ ],[
AC_DEFINE([HAVE_MEMCACHED_BINARY], [1], [If Memcached binary is available])
AC_DEFINE([MEMCACHED_BINARY], ["memcached/memcached"], [Name of the memcached binary used in make test])
+ ])
])
m4_include([libtest/m4/ax_lib_mysql.m4])
m4_include([libtest/m4/ax_prog_mysqld.m4])
-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"],
- [
+#serial 1
+
+ AC_DEFUN([YATL_MYSQL], [
+ AC_REQUIRE([AX_PROG_MYSQLD])
+
+ 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])
+ ])
+
+ 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])
+ ])
])
-
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
#include <cassert>
is_massive(opt_massive);
}
- char tmp_directory[1024];
+ libtest::vchar_t tmp_directory;
+ tmp_directory.resize(1024);
if (getenv("LIBTEST_TMP"))
{
- snprintf(tmp_directory, sizeof(tmp_directory), "%s", getenv("LIBTEST_TMP"));
+ snprintf(&tmp_directory[0], tmp_directory.size(), "%s", getenv("LIBTEST_TMP"));
}
else
{
- snprintf(tmp_directory, sizeof(tmp_directory), "%s", LIBTEST_TEMP);
+ snprintf(&tmp_directory[0], tmp_directory.size(), "%s", LIBTEST_TEMP);
}
- if (chdir(tmp_directory) == -1)
+ if (chdir(&tmp_directory[0]) == -1)
{
- char getcwd_buffer[1024];
- char *dir= getcwd(getcwd_buffer, sizeof(getcwd_buffer));
+ libtest::vchar_t getcwd_buffer;
+ getcwd_buffer.resize(1024);
+ char *dir= getcwd(&getcwd_buffer[0], getcwd_buffer.size());
- Error << "Unable to chdir() from " << dir << " to " << tmp_directory << " errno:" << strerror(errno);
+ Error << "Unable to chdir() from " << dir << " to " << &tmp_directory[0] << " errno:" << strerror(errno);
return EXIT_FAILURE;
}
std::ofstream xml_file;
std::string file_name;
- file_name.append(tmp_directory);
+ file_name.append(&tmp_directory[0]);
file_name.append(frame->name());
file_name.append(".xml");
xml_file.open(file_name.c_str(), std::ios::trunc);
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
-#include <libtest/common.h>
+#include "libtest/common.h"
#include <cassert>
#include <cerrno>
virtual const char *sasl() const
{
- return "-S";
+ return NULL;
}
const std::string& password() const
add_option("-M");
#endif
- if (_username.size())
+ if (sasl())
{
add_option(sasl());
}
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
#include <cassert>
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Data Differential YATL (i.e. libtest) library
+ *
+ * Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * The names of its contributors may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "libtest/yatlcon.h"
+#include <libtest/common.h>
+#include <cstdarg>
+
+namespace libtest {
+
+__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)
+{
+}
+
+__skipped::__skipped(const char *file_arg, int line_arg, const char *func_arg):
+ __test_result(file_arg, line_arg, func_arg)
+{
+}
+
+__failure::__failure(const char *file_arg, int line_arg, const char *func_arg, const std::string& mesg):
+ __test_result(file_arg, line_arg, func_arg)
+{
+ snprintf(_error_message, sizeof(_error_message), "%.*s", int(mesg.size()), mesg.c_str());
+}
+
+} // namespace libtest
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Data Differential YATL (i.e. libtest) library
+ *
+ * Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * The names of its contributors may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+
+#include <libtest/fatal.hpp>
+
+namespace libtest {
+
+class __test_result : public std::exception
+{
+public:
+ __test_result(const char *file, int line, const char *func);
+
+ int line()
+ {
+ return _line;
+ }
+
+ const char* file()
+ {
+ return _file;
+ }
+
+ const char* func()
+ {
+ return _func;
+ }
+
+private:
+ int _line;
+ const char* _file;
+ const char* _func;
+};
+
+class __success : public __test_result
+{
+public:
+ __success(const char *file, int line, const char *func);
+
+ const char* what() const throw()
+ {
+ return "SUCCESS";
+ }
+
+private:
+};
+
+class __skipped : public __test_result
+{
+public:
+ __skipped(const char *file, int line, const char *func);
+
+ const char* what() const throw()
+ {
+ return "SKIPPED";
+ }
+
+private:
+};
+
+class __failure : public __test_result
+{
+public:
+ __failure(const char *file, int line, const char *func, const std::string&);
+
+ const char* what() const throw()
+ {
+ return _error_message;
+ }
+
+private:
+ char _error_message[BUFSIZ];
+};
+
+
+} // namespace libtest
+
+#define _SUCCESS throw libtest::__success(LIBYATL_DEFAULT_PARAM)
+#define SKIP throw libtest::__skipped(LIBYATL_DEFAULT_PARAM)
+#define FAIL(__mesg) throw libtest::__failure(LIBYATL_DEFAULT_PARAM, __mesg)
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
namespace libtest {
{
if (func)
{
- return func(object);
+ try {
+ return func(object);
+ }
+ catch (libtest::__skipped)
+ {
+ return TEST_SKIPPED;
+ }
+ catch (libtest::__failure e)
+ {
+ libtest::stream::make_cerr(e.file(), e.line(), e.func()) << e.what();
+ return TEST_FAILURE;
+ }
+ catch (libtest::__success)
+ {
+ return TEST_SUCCESS;
+ }
}
return TEST_SUCCESS;
{
if (func)
{
- return func(object);
+ try {
+ return func(object);
+ }
+ catch (libtest::__skipped)
+ {
+ return TEST_SKIPPED;
+ }
+ catch (libtest::__failure e)
+ {
+ libtest::stream::make_cerr(e.file(), e.line(), e.func()) << e.what();
+ return TEST_FAILURE;
+ }
+ catch (libtest::__success)
+ {
+ return TEST_SUCCESS;
+ }
}
return TEST_SUCCESS;
{
if (func)
{
- return func(object);
+ try {
+ return func(object);
+ }
+ catch (libtest::__skipped)
+ {
+ return TEST_SKIPPED;
+ }
+ catch (libtest::__failure e)
+ {
+ libtest::stream::make_cerr(e.file(), e.line(), e.func()) << e.what();
+ return TEST_FAILURE;
+ }
+ catch (libtest::__success)
+ {
+ return TEST_SUCCESS;
+ }
}
return TEST_SUCCESS;
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
+
#include <libtest/common.h>
#include <cassert>
_port(port_arg),
_hostname(host_arg),
_app(executable, _is_libtool),
- out_of_ban_killed_(false)
+ out_of_ban_killed_(false),
+ _timeout(40)
{
}
Buffer buf( get_current_dir_name());
char *getcwd_buf= buf.buf();
#else
- char buf[PATH_MAX];
- char *getcwd_buf= getcwd(buf, sizeof(buf));
+ libtest::vchar_t buf;
+ buf.resize(PATH_MAX);
+ char *getcwd_buf= getcwd(&buf[0], buf.size());
#endif // __GLIBC__
throw libtest::disconnected(LIBYATL_DEFAULT_PARAM,
hostname(), port(),
bool pinged= false;
uint32_t this_wait= 0;
{
- uint32_t timeout= 40; // This number should be high enough for valgrind startup (which is slow)
uint32_t waited;
uint32_t retry;
{
break;
}
- else if (waited >= timeout)
+ else if (waited >= _timeout)
{
break;
}
bool Server::set_socket_file()
{
- char file_buffer[FILENAME_MAX];
+ libtest::vchar_t file_buffer;
+ file_buffer.resize(FILENAME_MAX);
file_buffer[0]= 0;
if (broken_pid_file())
{
- snprintf(file_buffer, sizeof(file_buffer), "/tmp/%s.socketXXXXXX", name());
+ snprintf(&file_buffer[0], file_buffer.size(), "/tmp/%s.socketXXXXXX", name());
}
else
{
- snprintf(file_buffer, sizeof(file_buffer), "var/run/%s.socketXXXXXX", name());
+ snprintf(&file_buffer[0], file_buffer.size(), "var/run/%s.socketXXXXXX", name());
}
int fd;
- if ((fd= mkstemp(file_buffer)) == -1)
+ if ((fd= mkstemp(&file_buffer[0])) == -1)
{
- perror(file_buffer);
+ perror(&file_buffer[0]);
return false;
}
close(fd);
- unlink(file_buffer);
+ unlink(&file_buffer[0]);
- _socket= file_buffer;
+ _socket= &file_buffer[0];
return true;
}
bool Server::set_pid_file()
{
- char file_buffer[FILENAME_MAX];
+ libtest::vchar_t file_buffer;
+ file_buffer.resize(FILENAME_MAX);
file_buffer[0]= 0;
if (broken_pid_file())
{
- snprintf(file_buffer, sizeof(file_buffer), "/tmp/%s.pidXXXXXX", name());
+ snprintf(&file_buffer[0], file_buffer.size(), "/tmp/%s.pidXXXXXX", name());
}
else
{
- snprintf(file_buffer, sizeof(file_buffer), "var/run/%s.pidXXXXXX", name());
+ snprintf(&file_buffer[0], file_buffer.size(), "var/run/%s.pidXXXXXX", name());
}
int fd;
- if ((fd= mkstemp(file_buffer)) == -1)
+ if ((fd= mkstemp(&file_buffer[0])) == -1)
{
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "mkstemp() failed on %s with %s", file_buffer, strerror(errno));
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "mkstemp() failed on %s with %s", &file_buffer[0], strerror(errno));
}
close(fd);
- unlink(file_buffer);
+ unlink(&file_buffer[0]);
- _pid_file= file_buffer;
+ _pid_file= &file_buffer[0];
return true;
}
bool Server::set_log_file()
{
- char file_buffer[FILENAME_MAX];
+ libtest::vchar_t file_buffer;
+ file_buffer.resize(FILENAME_MAX);
file_buffer[0]= 0;
- snprintf(file_buffer, sizeof(file_buffer), "var/log/%s.logXXXXXX", name());
+ snprintf(&file_buffer[0], file_buffer.size(), "var/log/%s.logXXXXXX", name());
int fd;
- if ((fd= mkstemp(file_buffer)) == -1)
+ if ((fd= mkstemp(&file_buffer[0])) == -1)
{
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "mkstemp() failed on %s with %s", file_buffer, strerror(errno));
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "mkstemp() failed on %s with %s", &file_buffer[0], strerror(errno));
}
close(fd);
- _log_file= file_buffer;
+ _log_file= &file_buffer[0];
return true;
}
_error= arg;
}
+ void reset_error()
+ {
+ _error.clear();
+ }
+
virtual bool wait_for_pidfile() const;
bool check_pid(pid_t pid_arg) const
return out_of_ban_killed_;
}
+ void timeout(uint32_t timeout_)
+ {
+ _timeout= timeout_;
+ }
+
protected:
bool set_pid_file();
Options _options;
bool args(Application&);
std::string _error;
+ uint32_t _timeout; // This number should be high enough for valgrind startup (which is slow)
};
std::ostream& operator<<(std::ostream& output, const libtest::Server &arg);
} // namespace libtest
+
+
*
*/
-#include "mem_config.h"
-#include <libtest/common.h>
+#include "libtest/yatlcon.h"
+
+#include "libtest/common.h"
#include <cassert>
#include <cerrno>
}
else
{
- char port_str[NI_MAXSERV]= { 0 };
- snprintf(port_str, sizeof(port_str), "%u", int(arg->port()));
+ libtest::vchar_t port_str;
+ port_str.resize(NI_MAXSERV);
+ snprintf(&port_str[0], port_str.size(), "%u", int(arg->port()));
server_config_string+= "--server=";
server_config_string+= arg->hostname();
server_config_string+= ":";
- server_config_string+= port_str;
+ server_config_string+= &port_str[0];
server_config_string+= " ";
}
}
}
}
- else if (server_type.compare("memcached-sasl") == 0)
- {
- if (MEMCACHED_BINARY)
- {
- if (HAVE_LIBMEMCACHED)
- {
- server= build_memcached_sasl("localhost", try_port, username(), password());
- }
- }
- }
else if (server_type.compare("memcached") == 0)
{
if (HAVE_MEMCACHED_BINARY)
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
#include <csignal>
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/test.hpp>
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
static char global_socket[1024]= { 0 };
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
namespace libtest {
#include <libtest/vchar.hpp>
#include <libtest/fatal.hpp>
+#include <libtest/result.hpp>
#include <libtest/has.hpp>
#include <libtest/error.h>
#include <libtest/cpu.hpp>
#include <libtest/tmpfile.hpp>
#include <libtest/client.hpp>
+#include <libtest/thread.hpp>
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Data Differential YATL (i.e. libtest) library
+ *
+ * Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * The names of its contributors may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+
+#include <pthread.h>
+
+namespace libtest
+{
+namespace thread
+{
+
+class Mutex
+{
+public:
+ Mutex()
+ {
+ int err;
+ if ((err= pthread_mutex_init(&_mutex, NULL)))
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_mutex_init: %s", strerror(err));
+ }
+ }
+
+ ~Mutex()
+ {
+ int err;
+ if ((err= pthread_mutex_destroy(&_mutex)))
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_cond_destroy: %s", strerror(err));
+ }
+ }
+
+ pthread_mutex_t* handle()
+ {
+ return &_mutex;
+ }
+
+private:
+ pthread_mutex_t _mutex;
+};
+
+class ScopedLock
+{
+public:
+ ScopedLock(Mutex& mutex_) :
+ _mutex(mutex_)
+ {
+ init();
+ }
+
+ ~ScopedLock()
+ {
+ int err;
+ if ((err= pthread_mutex_unlock(_mutex.handle())))
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_mutex_unlock: %s", strerror(err));
+ }
+ }
+
+ Mutex* handle()
+ {
+ return &_mutex;
+ }
+
+private:
+ void init()
+ {
+ int err;
+ if ((err= pthread_mutex_lock(_mutex.handle())))
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_mutex_lock: %s", strerror(err));
+ }
+ }
+
+private:
+ Mutex& _mutex;
+};
+
+class Condition
+{
+public:
+ Condition()
+ {
+ int err;
+ if ((err= pthread_cond_init(&_cond, NULL)))
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_mutex_init: %s", strerror(err));
+ }
+ }
+
+ ~Condition()
+ {
+ int err;
+ if ((err= pthread_cond_destroy(&_cond)))
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_cond_destroy: %s", strerror(err));
+ }
+ }
+
+ void broadcast()
+ {
+ int err;
+ if ((err= pthread_cond_broadcast(&_cond)))
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_cond_broadcast: %s", strerror(err));
+ }
+ }
+
+ void signal()
+ {
+ int err;
+ if ((err= pthread_cond_signal(&_cond)))
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_cond_broadcast: %s", strerror(err));
+ }
+ }
+
+ void wait(ScopedLock& lock_)
+ {
+ int err;
+ if ((err= pthread_cond_wait(&_cond, lock_.handle()->handle())))
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_cond_wait: %s", strerror(err));
+ }
+ }
+
+private:
+ pthread_cond_t _cond;
+};
+
+class Barrier
+{
+public:
+ Barrier(uint32_t count):
+ _threshold(count),
+ _count(count),
+ _generation(0)
+ {
+ if (_count == 0)
+ {
+ fatal_assert("Zero is an invalid value");
+ }
+ }
+
+ ~Barrier()
+ {
+ }
+
+ bool wait()
+ {
+ ScopedLock l(_mutex);
+ uint32_t gen = _generation;
+
+ if (--_count == 0)
+ {
+ _generation++;
+ _count = _threshold;
+ _cond.broadcast();
+
+ return true;
+ }
+
+ while (gen == _generation)
+ {
+ _cond.wait(l);
+ }
+
+ return false;
+ }
+
+private:
+ Mutex _mutex;
+ Condition _cond;
+ uint32_t _threshold;
+ uint32_t _count;
+ uint32_t _generation;
+};
+
+class Thread
+{
+private:
+ typedef void *(*start_routine_fn) (void *);
+
+public:
+ template <class Function,class Arg1>
+ Thread(Function func, Arg1 arg):
+ _joined(false),
+ _func((start_routine_fn)func),
+ _context(arg)
+ {
+ int err;
+ if ((err= pthread_create(&_thread, NULL, entry_func, (void*)this)))
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_create: %s", strerror(err));
+ }
+ _owner= pthread_self();
+ }
+
+ bool running() const
+ {
+ return (pthread_kill(_thread, 0) == 0);
+ }
+
+ bool detached()
+ {
+ if (EDEADLK == pthread_join(_thread, NULL))
+ {
+ return true;
+ }
+
+ /* Result of pthread_join was EINVAL == detached thread */
+ return false;
+ }
+
+ bool join()
+ {
+ if (_thread == pthread_self())
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Thread cannot join on itself");
+ }
+
+ if (_owner != pthread_self())
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Attempt made by a non-owner thead to join on thread");
+ }
+
+ bool ret= false;
+ {
+ ScopedLock l(_join_mutex);
+ if (_joined == false)
+ {
+ int err;
+ if ((err= pthread_join(_thread, NULL)))
+ {
+ switch(err)
+ {
+ case EINVAL:
+ break;
+
+ case ESRCH:
+ ret= true;
+ break;
+
+ case EDEADLK:
+ default:
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_join: %s", strerror(err));
+ }
+ }
+ else
+ {
+ ret= true;
+ }
+
+ _joined= true;
+ }
+ }
+
+ return ret;
+ }
+
+ ~Thread()
+ {
+ join();
+ }
+
+protected:
+ void run()
+ {
+ _func(_context);
+ }
+
+private:
+ static void * entry_func(void* This)
+ {
+ ((Thread *)This)->run();
+ return NULL;
+ }
+
+private:
+ bool _joined;
+ pthread_t _thread;
+ pthread_t _owner;
+ start_routine_fn _func;
+ void* _context;
+ Mutex _join_mutex;
+};
+
+} // namespace thread
+} // namespace libtest
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/timer.hpp>
*
*/
+#include "libtest/yatlcon.h"
+
#include <libtest/common.h>
namespace libtest {
std::string create_tmpfile(const std::string& name)
{
- char file_buffer[FILENAME_MAX];
+ libtest::vchar_t file_buffer;
+ file_buffer.resize(FILENAME_MAX);
file_buffer[0]= 0;
- int length= snprintf(file_buffer, sizeof(file_buffer), "var/tmp/%s.XXXXXX", name.c_str());
+ int length= snprintf(&file_buffer[0], file_buffer.size(), "var/tmp/%s.XXXXXX", name.c_str());
fatal_assert(length > 0);
int fd;
- if ((fd= mkstemp(file_buffer)) == -1)
+ if ((fd= mkstemp(&file_buffer[0])) == -1)
{
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "mkstemp() failed on %s with %s", file_buffer, strerror(errno));
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "mkstemp() failed on %s with %s", &file_buffer[0], strerror(errno));
}
close(fd);
- unlink(file_buffer);
+ unlink(&file_buffer[0]);
- return file_buffer;
+ return &file_buffer[0];
}
} // namespace libtest
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/test.hpp>
-#if defined(LIBTEST_WITH_LIBMEMCACHED_SUPPORT) && LIBTEST_WITH_LIBMEMCACHED_SUPPORT
-#include <libmemcached-1.0/memcached.h>
+#if defined(HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H) && HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H
+# include <libmemcached-1.0/types/return.h>
#endif
-#if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
-#include <libgearman/gearman.h>
+#if defined(HAVE_LIBGEARMAN_1_0_RETURN_H) && HAVE_LIBGEARMAN_1_0_RETURN_H
+# include <libgearman-1.0/return.h>
#endif
#include <cstdlib>
// Used to track setups where we see if failure is happening
static uint32_t fatal_calls= 0;
+static test_return_t getenv_TEST(void *)
+{
+#if 0
+ for (char **ptr= environ; *ptr; ptr++)
+ {
+ Error << *ptr;
+ }
+#endif
+
+ return TEST_SUCCESS;
+}
+
static test_return_t LIBTOOL_COMMAND_test(void *)
{
test_true(getenv("LIBTOOL_COMMAND"));
static test_return_t test_success_equals_one_test(void *)
{
test_skip(HAVE_LIBMEMCACHED, 1);
-#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
+#if defined(HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H) && HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H
test_zero(MEMCACHED_SUCCESS);
#endif
return TEST_SUCCESS;
return TEST_SUCCESS;
}
+static test_return_t test_throw_success_TEST(void *)
+{
+ try {
+ _SUCCESS;
+ }
+ catch (libtest::__success)
+ {
+ return TEST_SUCCESS;
+ }
+ catch (...)
+ {
+ return TEST_FAILURE;
+ }
+
+ return TEST_FAILURE;
+}
+
+static test_return_t test_throw_skip_TEST(void *)
+{
+ try {
+ SKIP;
+ }
+ catch (libtest::__skipped)
+ {
+ return TEST_SUCCESS;
+ }
+ catch (...)
+ {
+ return TEST_FAILURE;
+ }
+
+ return TEST_FAILURE;
+}
+
+static test_return_t test_throw_fail_TEST(void *)
+{
+ std::string error_messsage("test message!");
+ try {
+ FAIL(error_messsage);
+ }
+ catch (libtest::__failure e)
+ {
+ std::string compare_message("test message!");
+ test_zero(compare_message.compare(e.what()));
+ return TEST_SUCCESS;
+ }
+ catch (...)
+ {
+ return TEST_FAILURE;
+ }
+
+ return TEST_FAILURE;
+}
+
static test_return_t test_failure_test(void *)
{
return TEST_SKIPPED; // Only run this when debugging
static test_return_t _compare_memcached_return_t_test(void *)
{
test_skip(HAVE_LIBMEMCACHED, true);
-#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
+#if defined(HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H) && HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H
test_compare(MEMCACHED_SUCCESS, MEMCACHED_SUCCESS);
#endif
static test_return_t _compare_gearman_return_t_test(void *)
{
test_skip(HAVE_LIBGEARMAN, true);
-#if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
+#if defined(HAVE_LIBGEARMAN_1_0_RETURN_H) && HAVE_LIBGEARMAN_1_0_RETURN_H
test_compare(GEARMAN_SUCCESS, GEARMAN_SUCCESS);
#endif
static test_return_t application_gdb_true_BINARY2(void *)
{
test_skip(0, access("/usr/bin/gdb", X_OK ));
+ test_skip(0, access("/usr/bin/true", X_OK ));
+
Application true_app("/usr/bin/true");
true_app.use_gdb();
static test_return_t application_gdb_true_BINARY(void *)
{
test_skip(0, access("/usr/bin/gdb", X_OK ));
+ test_skip(0, access("/usr/bin/true", X_OK ));
+
Application true_app("/usr/bin/true");
true_app.use_gdb();
const char *args[]= { "--fubar", 0 };
#if defined(TARGET_OS_OSX) && TARGET_OS_OSX
test_compare(Application::INVALID_POSIX_SPAWN, true_app.run(args));
+#elif defined(TARGET_OS_FREEBSD) && TARGET_OS_FREEBSD
+ test_compare(Application::INVALID_POSIX_SPAWN, true_app.run(args));
#else
test_compare(Application::SUCCESS, true_app.run(args));
test_compare(Application::INVALID_POSIX_SPAWN, true_app.join());
static test_return_t wait_services_appliction_TEST(void *)
{
- test_skip(0, access("/usr/bin/gdb", X_OK ));
test_skip(0, access("/etc/services", R_OK ));
+ test_skip(0, access("/usr/bin/gdb", X_OK ));
+ test_skip(0, access("libtest/wait", X_OK ));
libtest::Application wait_app("libtest/wait", true);
wait_app.use_gdb();
test_skip(0, TARGET_OS_OSX);
#endif
- test_skip(0, access("/usr/bin/gdb", X_OK ));
test_skip(0, access("/etc/services", R_OK ));
+ test_skip(0, access("/usr/bin/gdb", X_OK ));
+ test_skip(0, access("libtest/wait", X_OK ));
libtest::Application wait_app("libtest/wait", true);
wait_app.use_gdb();
static test_return_t gdb_abort_services_appliction_TEST(void *)
{
- test_skip(true, false);
test_skip(0, access("/usr/bin/gdb", X_OK ));
+ test_skip(0, access("libtest/abort", X_OK ));
+ test_skip(true, false);
#if defined(TARGET_OS_OSX) && TARGET_OS_OSX
test_skip(0, TARGET_OS_OSX);
};
test_st environment_tests[] ={
+ {"getenv()", 0, getenv_TEST },
{"LIBTOOL_COMMAND", 0, LIBTOOL_COMMAND_test },
{"VALGRIND_COMMAND", 0, VALGRIND_COMMAND_test },
{"HELGRIND_COMMAND", 0, HELGRIND_COMMAND_test },
{"TEST_SUCCESS", false, test_success_test },
{"TEST_FAILURE", false, test_failure_test },
{"TEST_SUCCESS == 0", false, test_success_equals_one_test },
+ {"SUCCESS", false, test_throw_success_TEST },
+ {"SKIP", false, test_throw_skip_TEST },
+ {"FAIL", false, test_throw_fail_TEST },
{0, 0, 0}
};
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <libtest/common.h>
namespace libtest {
*
*/
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
#include <cstdlib>
#include <fcntl.h>
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
-AC_SUBST([LIBTEST_VERSION], [1.0])
+AC_SUBST([LIBTEST_VERSION],[1.0])
AC_CONFIG_FILES([libtest/version.h])
m4_include([libtest/m4/mysql.m4])
m4_include([libtest/m4/memcached.m4])
+AC_DEFINE([HAVE_MEMCACHED_SASL_BINARY],[0],[If Memcached binary with sasl support is available])
+
+YATL_MYSQL
+YATL_MEMCACHED
+
+AC_CONFIG_FILES([libtest/yatlcon.h])
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Data Differential YATL (i.e. libtest) library
+ *
+ * Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * The names of its contributors may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+
+#pragma once
+
+#include "@AUTOHEADER_FILE@"
--- /dev/null
+#serial 1
+
+AC_DEFUN([AX_DLOPEN],
+ [AS_IF([test "x$enable_shared" = xyes],
+ [AX_CHECK_LIBRARY([DL],[dlfcn.h],[dl],
+ [AC_DEFINE([HAVE_LIBDL],[1],[Have dlopen])
+ AC_CHECK_LIB([dl],[dlopen],[AC_DEFINE([HAVE_DLOPEN],[1],[Have dlopen])])
+ AC_CHECK_LIB([dl],[dladdr],[AC_DEFINE([HAVE_DLADDR],[1],[Have dladdr])])])],
+ [AM_CONDITIONAL([HAVE_DL],false)])
+ ])
+
return NULL;
}
+ if (HAVE_MEMCACHED_SASL_BINARY == 0)
+ {
+ error= TEST_SKIPPED;
+ return NULL;
+ }
+
// Assume we are running under valgrind, and bail
if (servers.sasl() and getenv("TESTS_ENVIRONMENT"))
{