From bcc7e71dd0d2c7d875ddb3583fd5ab2585304642 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Sun, 9 Dec 2012 06:40:11 -0500 Subject: [PATCH] Merge in updated yatl. --- configure.ac | 9 +- libtest/alarm.cc | 46 ++--- libtest/binaries.cc | 2 +- libtest/blobslap_worker.cc | 2 +- libtest/client.cc | 107 +++++++++--- libtest/client.hpp | 9 +- libtest/cmdline.cc | 30 ++-- libtest/collection.cc | 2 +- libtest/comparison.cc | 2 +- libtest/core.cc | 2 +- libtest/core_count.cc | 2 +- libtest/cpu.cc | 2 +- libtest/dns.cc | 2 +- libtest/dream.cc | 2 +- libtest/drizzled.cc | 9 +- libtest/failed.cc | 2 +- libtest/fatal.cc | 2 +- libtest/formatter.cc | 2 +- libtest/framework.cc | 2 +- libtest/gearmand.cc | 13 +- libtest/has.cc | 2 +- libtest/http.cc | 8 +- libtest/include.am | 51 ++---- libtest/is_local.cc | 2 +- libtest/killpid.cc | 34 ++-- libtest/libtool.cc | 2 +- libtest/m4/ax_lib_mysql.m4 | 6 +- libtest/m4/memcached.m4 | 15 +- libtest/m4/mysql.m4 | 31 ++-- libtest/main.cc | 20 ++- libtest/memcached.cc | 8 +- libtest/port.cc | 2 +- libtest/result.cc | 66 ++++++++ libtest/result.hpp | 114 +++++++++++++ libtest/runner.cc | 53 +++++- libtest/server.cc | 55 +++--- libtest/server.h | 13 ++ libtest/server_container.cc | 22 +-- libtest/signal.cc | 2 +- libtest/skiptest.cc | 2 +- libtest/socket.cc | 2 +- libtest/strerror.cc | 2 +- libtest/test.hpp | 2 + libtest/thread.hpp | 323 ++++++++++++++++++++++++++++++++++++ libtest/timer.cc | 2 +- libtest/tmpfile.cc | 15 +- libtest/unittest.cc | 101 +++++++++-- libtest/vchar.cc | 2 +- libtest/wait.cc | 2 +- libtest/yatl.m4 | 8 +- libtest/yatlcon.h.in | 41 +++++ m4/ax_dlopen.m4 | 11 ++ tests/libmemcached_world.h | 6 + 53 files changed, 1025 insertions(+), 249 deletions(-) create mode 100644 libtest/result.cc create mode 100644 libtest/result.hpp create mode 100644 libtest/thread.hpp create mode 100644 libtest/yatlcon.h.in create mode 100644 m4/ax_dlopen.m4 diff --git a/configure.ac b/configure.ac index 5c584132..19e56af8 100644 --- a/configure.ac +++ b/configure.ac @@ -19,6 +19,7 @@ AM_INIT_AUTOMAKE([1.11 color-tests -Wno-portability subdir-objects foreign tar-u 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 @@ -109,7 +110,6 @@ AC_SEARCH_LIBS([gethostbyname],[nsl]) # 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]) @@ -219,12 +219,7 @@ AC_CHECK_LIB([rt],[clock_gettime], [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"], diff --git a/libtest/alarm.cc b/libtest/alarm.cc index 93c8ccf7..80d7b2f6 100644 --- a/libtest/alarm.cc +++ b/libtest/alarm.cc @@ -34,7 +34,8 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" + #include #include @@ -51,42 +52,49 @@ static const struct itimerval cancel_timer= { default_it_interval, default_it_in 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"; } } diff --git a/libtest/binaries.cc b/libtest/binaries.cc index f58378f7..9adfb893 100644 --- a/libtest/binaries.cc +++ b/libtest/binaries.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" namespace libtest { diff --git a/libtest/blobslap_worker.cc b/libtest/blobslap_worker.cc index a6237b34..da43f619 100644 --- a/libtest/blobslap_worker.cc +++ b/libtest/blobslap_worker.cc @@ -35,7 +35,7 @@ */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include #include diff --git a/libtest/client.cc b/libtest/client.cc index fa3fcbdb..e392e6b0 100644 --- a/libtest/client.cc +++ b/libtest/client.cc @@ -34,26 +34,19 @@ * */ -#include "mem_config.h" - +#include "libtest/yatlcon.h" #include -#ifdef HAVE_POLL_H -# include -#endif - #include #include #include #include -#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), @@ -68,7 +61,13 @@ bool SimpleClient::ready(int event_) 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) { @@ -98,6 +97,7 @@ bool SimpleClient::ready(int event_) return false; } + _is_connected= true; if (fds[0].revents & event_) { return true; @@ -118,11 +118,12 @@ struct addrinfo* SimpleClient::lookup() 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) { @@ -146,12 +147,16 @@ SimpleClient::~SimpleClient() 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())) { @@ -200,16 +205,13 @@ bool SimpleClient::is_valid() 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); @@ -238,9 +240,20 @@ bool SimpleClient::message(const std::string& arg) 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; @@ -257,6 +270,53 @@ bool SimpleClient::send_message(const std::string& message_, std::string& respon 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(); @@ -279,6 +339,11 @@ bool SimpleClient::response(std::string& response_) return false; } } + else if (nr == 0) + { + close_socket(); + more= false; + } else { fatal_assert(nr == 1); diff --git a/libtest/client.hpp b/libtest/client.hpp index 25d0992f..a6439869 100644 --- a/libtest/client.hpp +++ b/libtest/client.hpp @@ -43,9 +43,11 @@ public: 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(); @@ -63,10 +65,11 @@ private: // Methods 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; diff --git a/libtest/cmdline.cc b/libtest/cmdline.cc index 709aac10..e5e3e733 100644 --- a/libtest/cmdline.cc +++ b/libtest/cmdline.cc @@ -34,7 +34,8 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" + #include "libtest/common.h" using namespace libtest; @@ -426,7 +427,7 @@ Application::error_t Application::join() 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) { @@ -437,12 +438,10 @@ Application::error_t Application::join() 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 { @@ -517,9 +516,10 @@ bool Application::Pipe::read(libtest::vchar_t& arg) 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) { @@ -706,10 +706,11 @@ void Application::create_argv(const char *args[]) 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) { @@ -720,10 +721,11 @@ void Application::create_argv(const char *args[]) 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) { diff --git a/libtest/collection.cc b/libtest/collection.cc index bfd1fac2..b3bdbdee 100644 --- a/libtest/collection.cc +++ b/libtest/collection.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include diff --git a/libtest/comparison.cc b/libtest/comparison.cc index 4a1d99a3..46aabe78 100644 --- a/libtest/comparison.cc +++ b/libtest/comparison.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include namespace libtest { diff --git a/libtest/core.cc b/libtest/core.cc index eb2ac3a1..8e887471 100644 --- a/libtest/core.cc +++ b/libtest/core.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include diff --git a/libtest/core_count.cc b/libtest/core_count.cc index 3cab0b4f..36ebc226 100644 --- a/libtest/core_count.cc +++ b/libtest/core_count.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include #include diff --git a/libtest/cpu.cc b/libtest/cpu.cc index a1844c5b..838804d7 100644 --- a/libtest/cpu.cc +++ b/libtest/cpu.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include #include diff --git a/libtest/dns.cc b/libtest/dns.cc index a293caa3..3623c4a1 100644 --- a/libtest/dns.cc +++ b/libtest/dns.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include #include diff --git a/libtest/dream.cc b/libtest/dream.cc index ebd8291a..114ac672 100644 --- a/libtest/dream.cc +++ b/libtest/dream.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include namespace libtest { diff --git a/libtest/drizzled.cc b/libtest/drizzled.cc index 3653eea2..8f5d3f58 100644 --- a/libtest/drizzled.cc +++ b/libtest/drizzled.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include #include @@ -182,9 +182,10 @@ public: { 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]); } } diff --git a/libtest/failed.cc b/libtest/failed.cc index 731d4998..df5d083f 100644 --- a/libtest/failed.cc +++ b/libtest/failed.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include #include diff --git a/libtest/fatal.cc b/libtest/fatal.cc index 7178d7f9..3327e381 100644 --- a/libtest/fatal.cc +++ b/libtest/fatal.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include #include diff --git a/libtest/formatter.cc b/libtest/formatter.cc index e0a347a0..6d4f1a33 100644 --- a/libtest/formatter.cc +++ b/libtest/formatter.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include diff --git a/libtest/framework.cc b/libtest/framework.cc index 9b351048..9fef09b2 100644 --- a/libtest/framework.cc +++ b/libtest/framework.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include #include diff --git a/libtest/gearmand.cc b/libtest/gearmand.cc index 8106bec4..66ab7bdc 100644 --- a/libtest/gearmand.cc +++ b/libtest/gearmand.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include #include @@ -71,6 +71,8 @@ public: bool ping() { + reset_error(); + if (out_of_ban_killed()) { return false; @@ -79,7 +81,14 @@ public: 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() diff --git a/libtest/has.cc b/libtest/has.cc index 1e020a20..9b26b96b 100644 --- a/libtest/has.cc +++ b/libtest/has.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include #include diff --git a/libtest/http.cc b/libtest/http.cc index 59497d69..917e668f 100644 --- a/libtest/http.cc +++ b/libtest/http.cc @@ -34,11 +34,11 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include -#if defined(HAVE_CURL_CURL_H) && HAVE_CURL_CURL_H +#if defined(HAVE_LIBCURL) && HAVE_LIBCURL #include #else class CURL; @@ -47,14 +47,14 @@ 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"); diff --git a/libtest/include.am b/libtest/include.am index 8a823ba3..fe43701f 100644 --- a/libtest/include.am +++ b/libtest/include.am @@ -35,8 +35,6 @@ drd: EXTRA_DIST+= libtest/run.gdb EXTRA_DIST+= libtest/version.h -CLEANFILES+= tmp_chroot - BUILT_SOURCES+= libtest/version.h .PHONY: clean-libtest-check @@ -75,6 +73,7 @@ noinst_HEADERS+= libtest/memcached.h 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 @@ -85,6 +84,7 @@ noinst_HEADERS+= libtest/strerror.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 @@ -119,6 +119,7 @@ libtest_libtest_la_SOURCES+= libtest/killpid.cc 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 @@ -134,8 +135,8 @@ libtest_libtest_la_CXXFLAGS+= @PTHREAD_CFLAGS@ 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 @@ -149,21 +150,12 @@ libtest_unittest_DEPENDENCIES= # 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 @@ -172,24 +164,20 @@ endif 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 @@ -197,29 +185,13 @@ libtest_libtest_la_SOURCES+= util/operation.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 @@ -270,3 +242,4 @@ test-backtrace: libtest/backtrace gdb-backtrace: libtest/backtrace @$(GDB_COMMAND) libtest/backtrace + diff --git a/libtest/is_local.cc b/libtest/is_local.cc index b223dd99..ef4059c3 100644 --- a/libtest/is_local.cc +++ b/libtest/is_local.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include diff --git a/libtest/killpid.cc b/libtest/killpid.cc index 4f8f3370..7f5630ba 100644 --- a/libtest/killpid.cc +++ b/libtest/killpid.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include #include @@ -123,14 +123,15 @@ bool check_pid(const std::string &filename) 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); @@ -152,14 +153,15 @@ bool kill_file(const std::string &filename) 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); @@ -180,7 +182,6 @@ bool kill_file(const std::string &filename) pid_t get_pid_from_file(const std::string &filename, std::stringstream& error_message) { pid_t ret= -1; - FILE *fp; if (filename.empty()) { @@ -188,16 +189,16 @@ pid_t get_pid_from_file(const std::string &filename, std::stringstream& error_me 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; @@ -208,12 +209,15 @@ pid_t get_pid_from_file(const std::string &filename, std::stringstream& error_me 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); } diff --git a/libtest/libtool.cc b/libtest/libtool.cc index 4a7d3cea..9d4b0f50 100644 --- a/libtest/libtool.cc +++ b/libtest/libtool.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include #include diff --git a/libtest/m4/ax_lib_mysql.m4 b/libtest/m4/ax_lib_mysql.m4 index e27d755d..53888bd0 100644 --- a/libtest/m4/ax_lib_mysql.m4 +++ b/libtest/m4/ax_lib_mysql.m4 @@ -26,6 +26,7 @@ # # This macro calls: # +# AC_SUBST(MYSQL_INCLUDE) # AC_SUBST(MYSQL_CFLAGS) # AC_SUBST(MYSQL_LDFLAGS) # AC_SUBST(MYSQL_VERSION) @@ -43,7 +44,7 @@ # and this notice are preserved. This file is offered as-is, without any # warranty. -#serial 12 +#serial 13 AC_DEFUN([AX_LIB_MYSQL], [ @@ -65,6 +66,7 @@ AC_DEFUN([AX_LIB_MYSQL], ) AC_ARG_VAR([MYSQL_CONFIG], [Full path to mysql_config program]) + MYSQL_INCLUDE="" MYSQL_CFLAGS="" MYSQL_LDFLAGS="" MYSQL_VERSION="" @@ -80,6 +82,7 @@ AC_DEFUN([AX_LIB_MYSQL], fi if test "$MYSQL_CONFIG" != "no"; then + MYSQL_INCLUDE="`$MYSQL_CONFIG --include`" MYSQL_CFLAGS="`$MYSQL_CONFIG --cflags`" MYSQL_LDFLAGS="`$MYSQL_CONFIG --libs`" @@ -142,6 +145,7 @@ AC_DEFUN([AX_LIB_MYSQL], fi AC_SUBST([MYSQL_VERSION]) + AC_SUBST([MYSQL_INCLUDE]) AC_SUBST([MYSQL_CFLAGS]) AC_SUBST([MYSQL_LDFLAGS]) ]) diff --git a/libtest/m4/memcached.m4 b/libtest/m4/memcached.m4 index ac8068b3..42d949e8 100644 --- a/libtest/m4/memcached.m4 +++ b/libtest/m4/memcached.m4 @@ -1,11 +1,14 @@ -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]) + ]) ]) diff --git a/libtest/m4/mysql.m4 b/libtest/m4/mysql.m4 index 2edd3b86..5775f0d3 100644 --- a/libtest/m4/mysql.m4 +++ b/libtest/m4/mysql.m4 @@ -1,23 +1,24 @@ 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]) + ]) ]) - diff --git a/libtest/main.cc b/libtest/main.cc index 967ec71a..c405bf20 100644 --- a/libtest/main.cc +++ b/libtest/main.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include #include @@ -220,22 +220,24 @@ int main(int argc, char *argv[]) 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; } @@ -329,7 +331,7 @@ int main(int argc, char *argv[]) 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); diff --git a/libtest/memcached.cc b/libtest/memcached.cc index c54c6b90..717ccb69 100644 --- a/libtest/memcached.cc +++ b/libtest/memcached.cc @@ -34,9 +34,9 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" -#include +#include "libtest/common.h" #include #include @@ -86,7 +86,7 @@ public: virtual const char *sasl() const { - return "-S"; + return NULL; } const std::string& password() const @@ -207,7 +207,7 @@ bool Memcached::build(size_t argc, const char *argv[]) add_option("-M"); #endif - if (_username.size()) + if (sasl()) { add_option(sasl()); } diff --git a/libtest/port.cc b/libtest/port.cc index 3d48a09c..b955ca4b 100644 --- a/libtest/port.cc +++ b/libtest/port.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include #include diff --git a/libtest/result.cc b/libtest/result.cc new file mode 100644 index 00000000..65038f91 --- /dev/null +++ b/libtest/result.cc @@ -0,0 +1,66 @@ +/* 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 +#include + +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 diff --git a/libtest/result.hpp b/libtest/result.hpp new file mode 100644 index 00000000..784ae72b --- /dev/null +++ b/libtest/result.hpp @@ -0,0 +1,114 @@ +/* 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 + +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) diff --git a/libtest/runner.cc b/libtest/runner.cc index 5f1acf56..456af7d1 100644 --- a/libtest/runner.cc +++ b/libtest/runner.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include namespace libtest { @@ -53,7 +53,22 @@ test_return_t Runner::run(test_callback_fn* func, void *object) { 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; @@ -63,7 +78,22 @@ test_return_t Runner::pre(test_callback_fn* func, void *object) { 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; @@ -73,7 +103,22 @@ test_return_t Runner::post(test_callback_fn* func, void *object) { 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; diff --git a/libtest/server.cc b/libtest/server.cc index 01d15625..a80a1812 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -34,7 +34,8 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" + #include #include @@ -116,7 +117,8 @@ Server::Server(const std::string& host_arg, const in_port_t port_arg, _port(port_arg), _hostname(host_arg), _app(executable, _is_libtool), - out_of_ban_killed_(false) + out_of_ban_killed_(false), + _timeout(40) { } @@ -253,8 +255,9 @@ bool Server::start() 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(), @@ -269,7 +272,6 @@ bool Server::start() 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; @@ -284,7 +286,7 @@ bool Server::start() { break; } - else if (waited >= timeout) + else if (waited >= _timeout) { break; } @@ -365,73 +367,76 @@ void Server::add_option(const std::string& name_, const std::string& value_) 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; } diff --git a/libtest/server.h b/libtest/server.h index fa524056..f5138808 100644 --- a/libtest/server.h +++ b/libtest/server.h @@ -223,6 +223,11 @@ public: _error= arg; } + void reset_error() + { + _error.clear(); + } + virtual bool wait_for_pidfile() const; bool check_pid(pid_t pid_arg) const @@ -260,6 +265,11 @@ public: return out_of_ban_killed_; } + void timeout(uint32_t timeout_) + { + _timeout= timeout_; + } + protected: bool set_pid_file(); Options _options; @@ -276,8 +286,11 @@ private: 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 + + diff --git a/libtest/server_container.cc b/libtest/server_container.cc index 05997238..5e081f62 100644 --- a/libtest/server_container.cc +++ b/libtest/server_container.cc @@ -34,8 +34,9 @@ * */ -#include "mem_config.h" -#include +#include "libtest/yatlcon.h" + +#include "libtest/common.h" #include #include @@ -75,13 +76,14 @@ void server_startup_st::push_server(Server *arg) } 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+= " "; } @@ -239,16 +241,6 @@ bool server_startup_st::start_server(const std::string& server_type, in_port_t t } } } - 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) diff --git a/libtest/signal.cc b/libtest/signal.cc index e680ccbc..1c4ecb73 100644 --- a/libtest/signal.cc +++ b/libtest/signal.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include #include diff --git a/libtest/skiptest.cc b/libtest/skiptest.cc index 2a2ff222..098a5753 100644 --- a/libtest/skiptest.cc +++ b/libtest/skiptest.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include diff --git a/libtest/socket.cc b/libtest/socket.cc index 667a0219..76ac5bf1 100644 --- a/libtest/socket.cc +++ b/libtest/socket.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include static char global_socket[1024]= { 0 }; diff --git a/libtest/strerror.cc b/libtest/strerror.cc index 39108d3c..901652fa 100644 --- a/libtest/strerror.cc +++ b/libtest/strerror.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include namespace libtest { diff --git a/libtest/test.hpp b/libtest/test.hpp index 7da55bd5..24fa7c8b 100644 --- a/libtest/test.hpp +++ b/libtest/test.hpp @@ -47,6 +47,7 @@ #include #include +#include #include #include @@ -76,3 +77,4 @@ #include #include #include +#include diff --git a/libtest/thread.hpp b/libtest/thread.hpp new file mode 100644 index 00000000..05f7fad4 --- /dev/null +++ b/libtest/thread.hpp @@ -0,0 +1,323 @@ +/* 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 + +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 + 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 diff --git a/libtest/timer.cc b/libtest/timer.cc index b34cb4f9..fe164ecf 100644 --- a/libtest/timer.cc +++ b/libtest/timer.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include diff --git a/libtest/tmpfile.cc b/libtest/tmpfile.cc index d2457e2b..a88c0ede 100644 --- a/libtest/tmpfile.cc +++ b/libtest/tmpfile.cc @@ -34,27 +34,30 @@ * */ +#include "libtest/yatlcon.h" + #include 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 diff --git a/libtest/unittest.cc b/libtest/unittest.cc index 0d504477..b81ef5e7 100644 --- a/libtest/unittest.cc +++ b/libtest/unittest.cc @@ -34,16 +34,16 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include -#if defined(LIBTEST_WITH_LIBMEMCACHED_SUPPORT) && LIBTEST_WITH_LIBMEMCACHED_SUPPORT -#include +#if defined(HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H) && HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H +# include #endif -#if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN -#include +#if defined(HAVE_LIBGEARMAN_1_0_RETURN_H) && HAVE_LIBGEARMAN_1_0_RETURN_H +# include #endif #include @@ -56,6 +56,18 @@ static std::string testing_service; // 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")); @@ -83,7 +95,7 @@ static test_return_t GDB_COMMAND_test(void *) 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; @@ -94,6 +106,60 @@ static test_return_t test_success_test(void *) 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 @@ -245,7 +311,7 @@ static test_return_t _compare_test_return_t_test(void *) 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 @@ -255,7 +321,7 @@ static test_return_t _compare_memcached_return_t_test(void *) 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 @@ -395,6 +461,8 @@ static test_return_t application_true_BINARY(void *) 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(); @@ -407,6 +475,8 @@ static test_return_t application_gdb_true_BINARY2(void *) 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(); @@ -440,6 +510,8 @@ static test_return_t application_doesnotexist_BINARY(void *) 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()); @@ -608,8 +680,9 @@ static test_return_t wait_services_BINARY2(void *) 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(); @@ -628,8 +701,9 @@ static test_return_t gdb_wait_services_appliction_TEST(void *) 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(); @@ -643,8 +717,9 @@ static test_return_t gdb_wait_services_appliction_TEST(void *) 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); @@ -853,6 +928,7 @@ test_st test_skip_TESTS[] ={ }; 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 }, @@ -864,6 +940,9 @@ test_st tests_log[] ={ {"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} }; diff --git a/libtest/vchar.cc b/libtest/vchar.cc index 1473509f..81c03453 100644 --- a/libtest/vchar.cc +++ b/libtest/vchar.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include namespace libtest { diff --git a/libtest/wait.cc b/libtest/wait.cc index a946d246..d1292e18 100644 --- a/libtest/wait.cc +++ b/libtest/wait.cc @@ -34,7 +34,7 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include #include diff --git a/libtest/yatl.m4 b/libtest/yatl.m4 index 8a42407b..4415863f 100644 --- a/libtest/yatl.m4 +++ b/libtest/yatl.m4 @@ -3,8 +3,14 @@ dnl This file is free software; Data Differential, LLC. 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]) diff --git a/libtest/yatlcon.h.in b/libtest/yatlcon.h.in new file mode 100644 index 00000000..17cb0aeb --- /dev/null +++ b/libtest/yatlcon.h.in @@ -0,0 +1,41 @@ +/* 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@" diff --git a/m4/ax_dlopen.m4 b/m4/ax_dlopen.m4 new file mode 100644 index 00000000..89d97088 --- /dev/null +++ b/m4/ax_dlopen.m4 @@ -0,0 +1,11 @@ +#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)]) + ]) + diff --git a/tests/libmemcached_world.h b/tests/libmemcached_world.h index 8b3ba641..fd5a51c9 100644 --- a/tests/libmemcached_world.h +++ b/tests/libmemcached_world.h @@ -55,6 +55,12 @@ static void *world_create(libtest::server_startup_st& servers, test_return_t& er 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")) { -- 2.30.2