tests/testudp
tests/var/
unittests/unittests
+libtest/version.h
HASHKIT_LIBRARY_VERSION=1:0:0
AC_SUBST(HASHKIT_LIBRARY_VERSION)
-AC_DEFINE([HAVE_LIBMEMCACHED], [ 1 ], [dummy rule for libtest])
-AC_SUBST(HAVE_LIBMEMCACHED, 1)
-AM_CONDITIONAL(HAVE_LIBMEMCACHED, true)
LT_INIT
+AM_CONDITIONAL(BUILDING_LIBMEMCACHED, true)
+AM_CONDITIONAL(HAVE_LIBMEMCACHED, false)
+
+AM_CONDITIONAL(BUILDING_GEARMAN, false)
+AM_CONDITIONAL(HAVE_LIBGEARMAN, false)
AC_SEARCH_LIBS(getopt_long, gnugetopt)
AC_SEARCH_LIBS(gethostbyname, nsl)
ENABLE_MURMUR_HASH
ENABLE_MEMASLAP
PROTOCOL_BINARY_TEST
-WITH_MEMCACHED
ENABLE_DEPRECATED
PANDORA_HAVE_LIBINNODB
PANDORA_HAVE_SASL
-WITH_LIBGEARMAN
AC_CHECK_FUNCS([alarm])
AC_CHECK_FUNCS([dup2])
support/libmemcached.pc
support/libmemcached.spec
support/libmemcached-fc.spec
+ libtest/version.h
])
AC_OUTPUT
#include <libtest/common.h>
+
#include <libtest/blobslap_worker.h>
#include <libtest/killpid.h>
#include <libtest/common.h>
-#include <libtest/cmdline.h>
-
using namespace libtest;
#include <cstdlib>
#include <string>
#include <sstream>
+namespace libtest {
+
bool exec_cmdline(const std::string& executable, const char *args[])
{
std::stringstream arg_buffer;
return true;
}
+
+} // namespace exec_cmdline
#pragma once
+namespace libtest {
+
bool exec_cmdline(const std::string& executable, const char *args[]);
+
+}
*/
/*
- Common include file for libmemached
+ Common include file for libtest
*/
#pragma once
#include <fnmatch.h>
#endif
+#include <libtest/gearmand.h>
+#include <libtest/blobslap_worker.h>
+#include <libtest/memcached.h>
+
#include <libtest/test.hpp>
#include <typeinfo>
#include <libtest/strerror.h>
+
+#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
#include <libmemcached/memcached.h>
+#endif
+
+#if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
+#include <libgearman/gearman.h>
+#endif
namespace libtest {
{
if (__expected != __actual)
{
- if (typeid(__expected) == typeid(memcached_return_t))
+ if (typeid(__expected) == typeid(test_return_t))
+ {
+ libtest::stream::make_cerr(file, line, func) << "Expected \""
+ << test_strerror(test_return_t(__expected))
+ << "\" got \""
+ << test_strerror(test_return_t(__actual)) << "\"";
+ }
+#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
+ else if (typeid(__expected) == typeid(memcached_return_t))
{
libtest::stream::make_cerr(file, line, func) << "Expected \""
<< memcached_strerror(NULL, memcached_return_t(__expected))
<< "\" got \""
<< memcached_strerror(NULL, memcached_return_t(__actual)) << "\"";
}
- else if (typeid(__expected) == typeid(test_return_t))
+#endif
+#if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
+ else if (typeid(__expected) == typeid(gearman_return_t))
{
libtest::stream::make_cerr(file, line, func) << "Expected \""
- << test_strerror(test_return_t(__expected))
+ << gearman_strerror(gearman_return_t(__expected))
<< "\" got \""
- << test_strerror(test_return_t(__actual)) << "\"";
+ << gearman_strerror(gearman_return_t(__actual)) << "\"";
}
+#endif
else
{
libtest::stream::make_cerr(file, line, func) << "Expected \"" << __expected << "\" got \"" << __actual << "\"";
#include <libtest/common.h>
+
#include <libtest/gearmand.h>
#include "util/instance.hpp"
using namespace libtest;
-class Gearmand : public Server
+class Gearmand : public libtest::Server
{
private:
public:
Gearmand(const std::string& host_arg, in_port_t port_arg) :
- Server(host_arg, port_arg)
+ libtest::Server(host_arg, port_arg)
{ }
pid_t get_pid(bool error_is_ok)
namespace libtest {
-Server *build_gearmand(const char *hostname, in_port_t try_port)
+libtest::Server *build_gearmand(const char *hostname, in_port_t try_port)
{
return new Gearmand(hostname, try_port);
}
#pragma once
+#include <arpa/inet.h>
+
+namespace libtest { class Server; }
+
namespace libtest {
-Server *build_gearmand(const char *hostname, in_port_t try_port);
+libtest::Server *build_gearmand(const char *hostname, in_port_t try_port);
}
tests/var/run/* \
tests/var/tmp/*
+.PHONY: distclean-tests-check
+distclean-tests-check:
+ -rm -rf tests/var
+
noinst_HEADERS+= \
libtest/blobslap_worker.h \
libtest/callbacks.h \
libtest_libtest_la_CXXFLAGS+= $(PTHREAD_CFLAGS)
libtest_libtest_la_LIBADD=
libtest_libtest_la_LIBADD+= $(PTHREAD_LIBS)
+libtest_libtest_la_DEPENDENCIES=
LIBTEST_LDADD= libtest/libtest.la
-if HAVE_LIBMEMCACHED
+# 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
endif
+if HAVE_LIBMEMCACHED
+libtest_libtest_la_LIBADD+= $(libmemcached_LIBS) -lmemcachedutil
+libtest_libtest_la_SOURCES+= libtest/memcached.cc
+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
+endif
if HAVE_LIBGEARMAN
-LIBTEST_LDADD+= libgearman/libgearman.la
+libtest_libtest_la_DEPENDENCIES+= libgearman/libgearman.la
+libtest_libtest_la_LIBADD+= $(libgearman_LIBS)
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
endif
-libtest_tmp_dir: tests/var/log tests/var/tmp tests/var/run clearn-var
-
-clearn-var:
- @rm -f tests/var/log/*
- @rm -f tests/var/run/*
- @rm -f tests/var/tmp/*
+libtest_tmp_dir: tests/var/log tests/var/tmp tests/var/run
tests/var:
@$(mkdir_p) tests/var
tests/var/run: tests/var
@$(mkdir_p) tests/var/run
-.PHONY+= tests/var
-
libtest_unittest_CFLAGS=
libtest_unittest_LDADD= ${LIBTEST_LDADD}
libtest_wait_SOURCES= libtest/wait.cc
noinst_PROGRAMS+= libtest/wait
-
using namespace libtest;
-class Memcached : public Server
+class Memcached : public libtest::Server
{
public:
Memcached(const std::string& host_arg, const in_port_t port_arg, const bool is_socket_arg) :
- Server(host_arg, port_arg, is_socket_arg)
+ libtest::Server(host_arg, port_arg, is_socket_arg)
{ }
pid_t get_pid(bool error_is_ok)
return false;
}
+ bool broken_socket_cleanup()
+ {
+ return true;
+ }
+
// Memcached's pidfile is broken
bool broken_pid_file()
{
namespace libtest {
-Server *build_memcached(const std::string& hostname, const in_port_t try_port)
+libtest::Server *build_memcached(const std::string& hostname, const in_port_t try_port)
{
return new Memcached(hostname, try_port, false);
}
-Server *build_memcached_socket(const std::string& hostname, const in_port_t try_port)
+libtest::Server *build_memcached_socket(const std::string& hostname, const in_port_t try_port)
{
return new Memcached(hostname, try_port, true);
}
namespace libtest {
-LIBTEST_API
-Server *build_memcached(const std::string& hostname, const in_port_t try_port);
+libtest::Server *build_memcached(const std::string& hostname, const in_port_t try_port);
-LIBTEST_API
-Server *build_memcached_socket(const std::string& socket_file, const in_port_t try_port);
+libtest::Server *build_memcached_socket(const std::string& socket_file, const in_port_t try_port);
}
#include <libtest/stream.h>
#include <libtest/killpid.h>
-#ifdef HAVE_LIBGEARMAN
-#include <libtest/gearmand.h>
-#include <libtest/blobslap_worker.h>
-#endif
-
-#ifdef HAVE_LIBMEMCACHED
-#include <libtest/memcached.h>
-#endif
-
extern "C" {
static bool exited_successfully(int status)
{
}
else
{
- snprintf(file_buffer, sizeof(file_buffer), "tests/var/run/%s.socketXXXXXX", name());
+ snprintf(file_buffer, sizeof(file_buffer), "var/run/%s.socketXXXXXX", name());
}
int fd;
}
else
{
- snprintf(file_buffer, sizeof(file_buffer), "tests/var/run/%s.pidXXXXXX", name());
+ snprintf(file_buffer, sizeof(file_buffer), "var/run/%s.pidXXXXXX", name());
}
int fd;
char file_buffer[FILENAME_MAX];
file_buffer[0]= 0;
- snprintf(file_buffer, sizeof(file_buffer), "tests/var/log/%s.logXXXXXX", name());
+ snprintf(file_buffer, sizeof(file_buffer), "var/log/%s.logXXXXXX", name());
int fd;
if ((fd= mkstemp(file_buffer)) == -1)
{
unlink(pid_file().c_str());
}
+ if (broken_socket_cleanup() and has_socket() and not socket().empty())
+ {
+ unlink(socket().c_str());
+ }
+
reset_pid();
return true;
}
}
- Server *server= NULL;
+ libtest::Server *server= NULL;
if (0)
{ }
else if (server_type.compare("gearmand") == 0)
{
-#ifdef GEARMAND_BINARY
- #ifdef HAVE_LIBGEARMAN
- server= build_gearmand("localhost", try_port);
- #else
- Error << "Libgearman was not found";
- #endif
-#else
- Error << "No gearmand binary is available";
-#endif
+ if (GEARMAND_BINARY)
+ {
+ if (HAVE_LIBGEARMAN)
+ {
+ server= build_gearmand("localhost", try_port);
+ }
+ else
+ {
+ Error << "Libgearman was not found";
+ }
+ }
+ else
+ {
+ Error << "No gearmand binary is available";
+ }
}
else if (server_type.compare("blobslap_worker") == 0)
{
-#ifdef GEARMAND_BINARY
- #ifdef HAVE_LIBGEARMAN
- server= build_blobslap_worker(try_port);
- #else
- Error << "Libgearman was not found";
- #endif
-#else
- Error << "No gearmand binary is available";
-#endif
+ if (GEARMAND_BINARY)
+ {
+ if (HAVE_LIBGEARMAN)
+ {
+ server= build_blobslap_worker(try_port);
+ }
+ else
+ {
+ Error << "Libgearman was not found";
+ }
+ }
+ else
+ {
+ Error << "No gearmand binary is available";
+ }
}
else if (server_type.compare("memcached") == 0)
{
-#ifdef MEMCACHED_BINARY
-#ifdef HAVE_LIBMEMCACHED
- server= build_memcached("localhost", try_port);
-#else
- Error << "Libmemcached was not found";
-#endif
-#else
- Error << "No memcached binary is available";
-#endif
+ if (MEMCACHED_BINARY)
+ {
+ if (HAVE_LIBMEMCACHED)
+ {
+ server= build_memcached("localhost", try_port);
+ }
+ else
+ {
+ Error << "Libmemcached was not found";
+ }
+ }
+ else
+ {
+ Error << "No memcached binary is available";
+ }
}
else
{
}
else if (server_type.compare("memcached") == 0)
{
-#ifdef MEMCACHED_BINARY
-#ifdef HAVE_LIBMEMCACHED
- server= build_memcached_socket("localhost", try_port);
-#else
- Error << "Libmemcached was not found";
-#endif
-#else
- Error << "No memcached binary is available";
-#endif
+ if (MEMCACHED_BINARY)
+ {
+ if (HAVE_LIBMEMCACHED)
+ {
+ server= build_memcached_socket("localhost", try_port);
+ }
+ else
+ {
+ Error << "Libmemcached was not found";
+ }
+ }
+ else
+ {
+ Error << "No memcached binary is available";
+ }
}
else
{
virtual const char *log_file_option()= 0;
virtual bool is_libtool()= 0;
+ virtual bool broken_socket_cleanup()
+ {
+ return false;
+ }
+
virtual const char *socket_file_option() const
{
return NULL;
{
srandom((unsigned int)time(NULL));
+ if (getenv("srcdir"))
+ {
+ char buffer[1024];
+ snprintf(buffer, sizeof(buffer), "%s/%s", getenv("srcdir"), "tests");
+ chdir(buffer);
+ }
+ else
+ {
+ chdir("tests");
+ }
+
world= new Framework();
if (not world)
#include <arpa/inet.h>
#include <libtest/visibility.h>
+#include <libtest/version.h>
#include <libtest/error.h>
#include <libtest/server.h>
return TEST_SUCCESS;
}
+static test_return_t var_exists_test(void *)
+{
+ test_compare(0, access("var", R_OK | W_OK | X_OK));
+ return TEST_SUCCESS;
+}
+
+static test_return_t var_tmp_exists_test(void *)
+{
+ test_compare(0, access("var/tmp", R_OK | W_OK | X_OK));
+ return TEST_SUCCESS;
+}
+
+static test_return_t var_run_exists_test(void *)
+{
+ test_compare(0, access("var/run", R_OK | W_OK | X_OK));
+ return TEST_SUCCESS;
+}
+
+static test_return_t var_log_exists_test(void *)
+{
+ test_compare(0, access("var/log", R_OK | W_OK | X_OK));
+ return TEST_SUCCESS;
+}
+
+static test_return_t var_tmp_test(void *)
+{
+ FILE *file= fopen("var/tmp/junk", "w+");
+ test_true(file);
+ fclose(file);
+ return TEST_SUCCESS;
+}
+
+static test_return_t var_run_test(void *)
+{
+ FILE *file= fopen("var/run/junk", "w+");
+ test_true(file);
+ fclose(file);
+ return TEST_SUCCESS;
+}
+
+static test_return_t var_log_test(void *)
+{
+ FILE *file= fopen("var/log/junk", "w+");
+ test_true(file);
+ fclose(file);
+ return TEST_SUCCESS;
+}
+
+static test_return_t var_tmp_rm_test(void *)
+{
+ test_true(unlink("var/tmp/junk") == 0);
+ return TEST_SUCCESS;
+}
+
+static test_return_t var_run_rm_test(void *)
+{
+ test_true(unlink("var/run/junk") == 0);
+ return TEST_SUCCESS;
+}
+
+static test_return_t var_log_rm_test(void *)
+{
+ test_true(unlink("var/log/junk") == 0);
+ return TEST_SUCCESS;
+}
+
+
#if 0
static test_return_t pause_test(void *)
{
server_startup_st *servers= (server_startup_st*)object;
test_true(servers);
-#ifndef HAVE_LIBGEARMAN
- return TEST_SKIPPED;
-#endif
+ if (HAVE_LIBGEARMAN)
+ {
+ const char *argv[1]= { "cycle_gearmand" };
+ test_true(server_startup(*servers, "gearmand", 9999, 1, argv));
- const char *argv[1]= { "cycle_gearmand" };
- test_true(server_startup(*servers, "gearmand", 9999, 1, argv));
+ return TEST_SUCCESS;
+ }
- return TEST_SUCCESS;
+ return TEST_SKIPPED;
}
static test_return_t memcached_cycle_test(void *object)
server_startup_st *servers= (server_startup_st*)object;
test_true(servers);
-#if !defined(MEMCACHED_BINARY) || !defined(HAVE_LIBMEMCACHED)
- return TEST_SKIPPED;
-#endif
+ if (MEMCACHED_BINARY and HAVE_LIBMEMCACHED)
+ {
+ const char *argv[1]= { "cycle_memcached" };
+ test_true(server_startup(*servers, "memcached", 9998, 1, argv));
- const char *argv[1]= { "cycle_memcached" };
- test_true(server_startup(*servers, "memcached", 9998, 1, argv));
+ return TEST_SUCCESS;
+ }
- return TEST_SUCCESS;
+ return TEST_SKIPPED;
}
static test_return_t memcached_socket_cycle_test(void *object)
server_startup_st *servers= (server_startup_st*)object;
test_true(servers);
-#if !defined(MEMCACHED_BINARY) || !defined(HAVE_LIBMEMCACHED)
- return TEST_SKIPPED;
-#endif
+ if (MEMCACHED_BINARY and HAVE_LIBMEMCACHED)
+ {
+ const char *argv[1]= { "cycle_memcached" };
+ test_true(servers->start_socket_server("memcached", 9997, 1, argv));
- const char *argv[1]= { "cycle_memcached" };
- test_true(servers->start_socket_server("memcached", 9997, 1, argv));
+ return TEST_SUCCESS;
+ }
- return TEST_SUCCESS;
+ return TEST_SKIPPED;
}
test_st gearmand_tests[] ={
{0, 0, 0}
};
+test_st directories_tests[] ={
+ {"var exists", 0, var_exists_test },
+ {"var/tmp exists", 0, var_tmp_exists_test },
+ {"var/run exists", 0, var_run_exists_test },
+ {"var/log exists", 0, var_log_exists_test },
+ {"var/tmp", 0, var_tmp_test },
+ {"var/run", 0, var_run_test },
+ {"var/log", 0, var_log_test },
+ {"var/tmp rm", 0, var_tmp_rm_test },
+ {"var/run rm", 0, var_run_rm_test },
+ {"var/log rm", 0, var_log_rm_test },
+ {0, 0, 0}
+};
+
collection_st collection[] ={
{"environment", 0, 0, environment_tests},
{"return values", 0, 0, tests_log},
{"local", 0, 0, local_log},
+ {"directories", 0, 0, directories_tests},
{"gearmand", 0, 0, gearmand_tests},
{"memcached", 0, 0, memcached_tests},
{0, 0, 0, 0}
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * libtest
+ *
+ * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define LIBTEST_VERSION_STRING "@VERSION@"
+#define LIBTEST_VERSION_HEX @HEX_VERSION@
+
+#ifdef __cplusplus
+}
+#endif
+++ /dev/null
-AC_DEFUN([_WITH_LIBGEARMAN],
- [ AC_ARG_ENABLE([libgearman],
- [AS_HELP_STRING([--disable-libgearman],
- [Build with libgearman support @<:@default=on@:>@])],
- [ac_enable_libgearman="$enableval"],
- [ac_enable_libgearman="yes"])
-
- AS_IF([test "x$ac_enable_libgearman" = "xyes"],
- [ PKG_CHECK_MODULES([libgearman], [ libgearman >= 0.24 ],
- [AC_DEFINE([HAVE_LIBGEARMAN], [ 1 ], [Enable libgearman support])],
- [ac_enable_libgearman="no"] )])
-
- AM_CONDITIONAL(HAVE_LIBGEARMAN, test "x${ac_enable_libgearman}" = "xyes")
- ])
-
-AC_DEFUN([WITH_LIBGEARMAN], [ AC_REQUIRE([_WITH_LIBGEARMAN]) ])