{
if (connect(sock_fd, address_info_next->ai_addr, address_info_next->ai_addrlen) == SOCKET_ERROR)
{
+ switch (errno)
+ {
+ case EINTR:
+ close_socket();
+ continue;
+
+ case EINPROGRESS: // nonblocking mode - first return
+ case EALREADY: // nonblocking mode - subsequent returns
+ continue; // Jump to while() and continue on
+
+
+ case ECONNREFUSED:
+ default:
+ break;
+ }
+
close_socket();
_error= strerror(errno);
}
if (_use_libtool)
{
assert(libtool());
- built_argv.push_back(strdup(libtool()));
- built_argv.push_back(strdup("--mode=execute"));
+ vchar::append(built_argv, libtool());
+ vchar::append(built_argv, "--mode=execute");
}
if (_use_valgrind)
/*
valgrind --error-exitcode=1 --leak-check=yes --track-fds=yes --malloc-fill=A5 --free-fill=DE
*/
- built_argv.push_back(strdup("valgrind"));
- built_argv.push_back(strdup("--error-exitcode=1"));
- built_argv.push_back(strdup("--leak-check=yes"));
+ vchar::append(built_argv, "valgrind");
+ vchar::append(built_argv, "--error-exitcode=1");
+ vchar::append(built_argv, "--leak-check=yes");
#if 0
- built_argv.push_back(strdup("--show-reachable=yes"));
+ vchar::append(built_argv, "--show-reachable=yes"));
#endif
- built_argv.push_back(strdup("--track-fds=yes"));
+ vchar::append(built_argv, "--track-fds=yes");
#if 0
built_argv[x++]= strdup("--track-origin=yes");
#endif
- built_argv.push_back(strdup("--malloc-fill=A5"));
- built_argv.push_back(strdup("--free-fill=DE"));
+ vchar::append(built_argv, "--malloc-fill=A5");
+ vchar::append(built_argv, "--free-fill=DE");
std::string log_file= create_tmpfile("valgrind");
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]));
+ vchar::append(built_argv, &buffer[0]);
}
else if (_use_ptrcheck)
{
/*
valgrind --error-exitcode=1 --tool=exp-ptrcheck --log-file=
*/
- built_argv.push_back(strdup("valgrind"));
- built_argv.push_back(strdup("--error-exitcode=1"));
- built_argv.push_back(strdup("--tool=exp-ptrcheck"));
+ vchar::append(built_argv, "valgrind");
+ vchar::append(built_argv, "--error-exitcode=1");
+ vchar::append(built_argv, "--tool=exp-ptrcheck");
std::string log_file= create_tmpfile("ptrcheck");
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]));
+ vchar::append(built_argv, &buffer[0]);
}
else if (_use_gdb)
{
- built_argv.push_back(strdup("gdb"));
+ vchar::append(built_argv, "gdb");
}
- built_argv.push_back(strdup(_exectuble_with_path.c_str()));
+ vchar::append(built_argv, _exectuble_with_path.c_str());
for (Options::const_iterator iter= _options.begin(); iter != _options.end(); ++iter)
{
- built_argv.push_back(strdup((*iter).first.c_str()));
+ vchar::append(built_argv, (*iter).first.c_str());
if ((*iter).second.empty() == false)
{
- built_argv.push_back(strdup((*iter).second.c_str()));
+ vchar::append(built_argv, (*iter).second.c_str());
}
}
{
for (const char **ptr= args; *ptr; ++ptr)
{
- built_argv.push_back(strdup(*ptr));
+ vchar::append(built_argv, *ptr);
}
}
built_argv.push_back(NULL);
{
std::stringstream arg_buffer;
- for (size_t x= (1 +_use_libtool) ? 2 : 0;
+ for (size_t x= _use_libtool ? 2 : 0;
x < _argc and built_argv[x];
++x)
{
return arg_buffer.str();
}
-struct DeleteFromVector
-{
- template <class T>
- void operator() ( T* ptr) const
- {
- if (ptr)
- {
- free(ptr);
- }
- }
-};
-
void Application::delete_argv()
{
- std::for_each(built_argv.begin(), built_argv.end(), DeleteFromVector());
+ std::for_each(built_argv.begin(), built_argv.end(), FreeFromVector());
built_argv.clear();
_argc= 0;
private:
void create_argv(const char *args[]);
void delete_argv();
+ void add_to_build_argv(const char*);
private:
const bool _use_libtool;
#include <libtest/dns.hpp>
#include <libtest/formatter.hpp>
+struct FreeFromVector
+{
+ template <class T>
+ void operator() ( T* ptr) const
+ {
+ if (ptr)
+ {
+ free(ptr);
+ ptr= NULL;
+ }
+ }
+};
+
+struct DeleteFromVector
+{
+ template <class T>
+ void operator() ( T* ptr) const
+ {
+ delete ptr;
+ ptr= NULL;
+ }
+};
#include <libtest/common.h>
-#include <iostream>
+#include <algorithm>
#include <fstream>
+#include <iostream>
namespace libtest {
Formatter::~Formatter()
{
- for (TestCases::iterator iter= _testcases.begin(); iter != _testcases.end(); ++iter)
- {
- delete *iter;
- }
+ std::for_each(_testcases.begin(), _testcases.end(), DeleteFromVector());
+ _testcases.clear();
}
TestCase* Formatter::current()
#include <libtest/collection.h>
#include <libtest/signal.h>
+#include <algorithm>
#include <fnmatch.h>
#include <iostream>
delete _runner;
- for (std::vector<Collection*>::iterator iter= _collection.begin();
- iter != _collection.end();
- ++iter)
- {
- delete *iter;
- }
+ std::for_each(_collection.begin(), _collection.end(), DeleteFromVector());
+ _collection.clear();
}
bool Framework::match(const char* arg)
#include <libtest/gearmand.h>
-#include "util/instance.hpp"
-#include "util/operation.hpp"
-
-using namespace datadifferential;
using namespace libtest;
#include <cassert>
{
if (binary == NULL)
{
-#if defined(GEARMAND_BINARY)
- binary= GEARMAND_BINARY;
+#if defined(HAVE_GEARMAND_BINARY)
+# if defined(GEARMAND_BINARY)
+ if (HAVE_GEARMAND_BINARY)
+ {
+ binary= GEARMAND_BINARY;
+ }
+# endif
#endif
}
endif
-if BUILDING_GEARMAN
-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
-else
-if HAVE_LIBGEARMAN
+if BUILDING_GEARMAN
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
endif
TMP_DIR := tmp_chroot/etc tmp_chroot/var/log tmp_chroot/var/tmp tmp_chroot/var/run tmp_chroot/var/drizzle
# define FAIL(__message_format, ...)
#endif
+#ifndef SKIP
+# define SKIP(__message_format, ...)
+#endif
+
static inline bool valgrind_is_caller(void)
{
if (getenv("TESTS_ENVIRONMENT") && strstr(getenv("TESTS_ENVIRONMENT"), "valgrind"))
do \
{ \
if ((__expression)) { \
- fprintf(stderr, "\n%s:%d: %s SKIP '!%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression); \
+ if (YATL_FULL) { \
+ SKIP(#__expression); \
+ } \
+ fprintf(stdout, "\n%s:%d: %s SKIP '!(%s)'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression); \
exit(EXIT_SKIP); \
} \
} while (0)
if ((__expression) != NULL) { \
size_t ask= snprintf(0, 0, __VA_ARGS__); \
ask++; \
- char *buffer= (char*)malloc(sizeof(char) * ask); \
+ char *buffer= (char*)alloca(sizeof(char) * ask); \
snprintf(buffer, ask, __VA_ARGS__); \
fprintf(stderr, "\n%s:%d: %s Assertion '%s' != NULL [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer);\
- free(buffer); \
exit(EXIT_FAILURE); \
} \
} while (0)
if ((__expression) == NULL) { \
size_t ask= snprintf(0, 0, __VA_ARGS__); \
ask++; \
- char *buffer= (char*)malloc(sizeof(char) * ask); \
+ char *buffer= (char*)alloca(sizeof(char) * ask); \
snprintf(buffer, ask, __VA_ARGS__); \
fprintf(stderr, "\n%s:%d: %s Assertion '%s' == NULL [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer);\
- free(buffer); \
exit(EXIT_FAILURE); \
} \
} while (0)
if ((__expression)) { \
size_t ask= snprintf(0, 0, __VA_ARGS__); \
ask++; \
- char *buffer= (char*)malloc(sizeof(char) * ask); \
+ char *buffer= (char*)alloca(sizeof(char) * ask); \
snprintf(buffer, ask, __VA_ARGS__); \
+ if (YATL_FULL) { \
+ SKIP(#__expression, buffer); \
+ } \
fprintf(stdout, "\n%s:%d: %s SKIP '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \
- free(buffer); \
exit(EXIT_SKIP); \
} \
} while (0)
if (! (__expression)) { \
size_t ask= snprintf(0, 0, __VA_ARGS__); \
ask++; \
- char *buffer= (char*)malloc(sizeof(char) * ask); \
+ char *buffer= (char*)alloca(sizeof(char) * ask); \
snprintf(buffer, ask, __VA_ARGS__); \
fprintf(stderr, "\n%s:%d: %s Assertion '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \
- free(buffer); \
exit(EXIT_FAILURE); \
} \
} while (0)
if ((__expected) != (__actual)) { \
size_t ask= snprintf(0, 0, __VA_ARGS__); \
ask++; \
- char *buffer= (char*)malloc(sizeof(char) * ask); \
+ char *buffer= (char*)alloca(sizeof(char) * ask); \
snprintf(buffer, ask, __VA_ARGS__); \
fprintf(stderr, "\n%s:%d: %s Assertion '%s' != '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual, buffer); \
- free(buffer); \
exit(EXIT_FAILURE); \
} \
} while (0)
if (ret) { \
size_t ask= snprintf(0, 0, __VA_ARGS__); \
ask++; \
- char *buffer= (char*)malloc(sizeof(char) * ask); \
+ char *buffer= (char*)alloca(sizeof(char) * ask); \
ask= snprintf(buffer, ask, __VA_ARGS__); \
fprintf(stderr, "\n%s:%d: %s Assertion '%.*s' != '%.*s' [ %.*s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, \
(int)(__expected_length), (__expected_str), \
(int)(__actual_length), (__actual_str), \
(int)(ask), buffer); \
- free(buffer); \
exit(EXIT_FAILURE); \
} \
} while (0)
if (ret == 0) { \
size_t ask= snprintf(0, 0, __VA_ARGS__); \
ask++; \
- char *buffer= (char*)malloc(sizeof(char) * ask); \
+ char *buffer= (char*)alloca(sizeof(char) * ask); \
ask= snprintf(buffer, ask, __VA_ARGS__); \
fprintf(stderr, "\n%s:%d: %s Assertion '%.*s' == '%.*s' [ %.*s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, \
(int)(__expected_length), (__expected_str), \
(int)(__actual_length), (__actual_str), \
(int)(ask), buffer); \
- free(buffer); \
exit(EXIT_FAILURE); \
} \
} while (0)
if ((__expected) == (__actual)) { \
size_t ask= snprintf(0, 0, __VA_ARGS__); \
ask++; \
- char *buffer= (char*)malloc(sizeof(char) * ask); \
+ char *buffer= (char*)alloca(sizeof(char) * ask); \
snprintf(buffer, ask, __VA_ARGS__); \
fprintf(stderr, "\n%s:%d: %s Assertion '%s' == '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual, buffer); \
- free(buffer); \
exit(EXIT_FAILURE); \
} \
} while (0)
{
{ "version", no_argument, NULL, OPT_LIBYATL_VERSION },
{ "quiet", no_argument, NULL, OPT_LIBYATL_QUIET },
- { "repeat", no_argument, NULL, OPT_LIBYATL_REPEAT },
+ { "repeat", required_argument, NULL, OPT_LIBYATL_REPEAT },
{ "collection", required_argument, NULL, OPT_LIBYATL_MATCH_COLLECTION },
{ "wildcard", required_argument, NULL, OPT_LIBYATL_MATCH_WILDCARD },
{ "massive", no_argument, NULL, OPT_LIBYATL_MASSIVE },
std::auto_ptr<libtest::Framework> frame(new libtest::Framework(signal, binary_name, collection_to_run, wildcard));
// Run create(), bail on error.
+ try
{
switch (frame->create())
{
return EXIT_FAILURE;
}
}
+ catch (libtest::__skipped e)
+ {
+ return EXIT_SKIP;
+ }
frame->exec();
Outn(); // Generate a blank to break up the messages if make check/test has been run
} while (exit_code == EXIT_SUCCESS and --opt_repeat);
}
+ catch (libtest::__skipped e)
+ {
+ return EXIT_SKIP;
+ }
+ catch (libtest::__failure e)
+ {
+ libtest::stream::make_cout(e.file(), e.line(), e.func()) << e.what();
+ exit_code= EXIT_FAILURE;
+ }
catch (libtest::fatal& e)
{
std::cerr << "FATAL:" << e.what() << std::endl;
{
ret_port= default_port;
int sd;
- if ((sd= socket(AF_INET, SOCK_STREAM, 0)) != -1)
+ if ((sd= socket(AF_INET, SOCK_STREAM, 0)) != SOCKET_ERROR)
{
int optval= 1;
- if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) != -1)
+ if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) != SOCKET_ERROR)
{
struct sockaddr_in sin;
sin.sin_port= 0;
int bind_ret;
do
{
- if ((bind_ret= bind(sd, (struct sockaddr *)&sin, sizeof(struct sockaddr_in) )) != -1)
+ if ((bind_ret= bind(sd, (struct sockaddr *)&sin, sizeof(struct sockaddr_in) )) != SOCKET_ERROR)
{
socklen_t addrlen= sizeof(sin);
{
}
-__skipped::__skipped(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),
+ _error_message(NULL),
+ _error_message_size(0)
+{
+ va_list args;
+ va_start(args, func_arg);
+ const char *format= va_arg(args, const char *);
+ _error_message_size= vasprintf(&_error_message, format, args);
+ assert(_error_message_size != -1);
+ if (_error_message_size > 0)
+ {
+ _error_message_size++;
+ }
+ va_end(args);
+}
+
+__skipped::__skipped( const __skipped& other ) :
+ __test_result(other),
+ _error_message_size(other._error_message_size)
+{
+ _error_message= (char*) malloc(_error_message_size);
+ if (_error_message)
+ {
+ memcpy(_error_message, other._error_message, _error_message_size);
+ }
+ else
+ {
+ _error_message_size= -1;
+ }
+}
+
+__skipped::~__skipped() throw()
{
+ if ((_error_message_size > 0) and _error_message)
+ {
+ free(_error_message);
+ _error_message= NULL;
+ }
}
__failure::__failure(const char *file_arg, int line_arg, const char *func_arg, ...) :
#include <libtest/result/success.hpp>
#define _SUCCESS throw libtest::__success(LIBYATL_DEFAULT_PARAM)
-#define SKIP throw libtest::__skipped(LIBYATL_DEFAULT_PARAM)
+
+#define SKIP(...) \
+do \
+{ \
+ throw libtest::__skipped(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \
+} while (0)
#define FAIL(...) \
do \
class __skipped : public __test_result
{
public:
- __skipped(const char *file, int line, const char *func);
+ __skipped(const char *file, int line, const char *func, ...);
+
+ __skipped(const __skipped&);
+
+ ~__skipped() throw();
const char* what() const throw()
{
- return "SKIPPED";
+ return &_error_message[0];
}
private:
+ char* _error_message;
+ int _error_message_size;
};
} // namespace libtest
try {
return func(object);
}
- catch (libtest::__skipped)
+ catch (libtest::__skipped e)
{
return TEST_SKIPPED;
}
try {
return func(object);
}
- catch (libtest::__skipped)
+ catch (libtest::__skipped e)
{
return TEST_SKIPPED;
}
catch (libtest::__failure e)
{
- libtest::stream::make_cerr(e.file(), e.line(), e.func()) << e.what();
+ libtest::stream::make_cout(e.file(), e.line(), e.func()) << e.what();
return TEST_FAILURE;
}
catch (libtest::__success)
try {
return func(object);
}
- catch (libtest::__skipped)
+ catch (libtest::__skipped e)
{
return TEST_SKIPPED;
}
{
public:
Buffer(char *b) : b_(b) {}
- ~Buffer() { free(b_); }
+ ~Buffer() { if (b_) free(b_); }
char* buf() { return b_; }
private:
char *b_;
#include "libtest/common.h"
-#include <cassert>
#include <cerrno>
#include <cstdlib>
#include <iostream>
}
server_list+= server_config_string;
-
}
Server* server_startup_st::pop_server()
void server_startup_st::clear()
{
- for (std::vector<Server *>::iterator iter= servers.begin(); iter != servers.end(); ++iter)
- {
- delete *iter;
- }
+ std::for_each(servers.begin(), servers.end(), DeleteFromVector());
servers.clear();
}
_magic(MAGIC_MEMORY),
_socket(false),
_sasl(false),
- _count(0),
udp(0),
_servers_to_run(5)
{ }
return construct.start_server(server_type, try_port, argc, argv, opt_startup_message);
}
-bool server_startup_st::start_server(const std::string& server_type, in_port_t try_port, int argc, const char *argv[], const bool opt_startup_message)
+libtest::Server* server_startup_st::create(const std::string& server_type, in_port_t try_port, const bool is_socket)
{
- if (try_port <= 0)
+ libtest::Server *server= NULL;
+
+ if (is_socket == false)
{
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "was passed the invalid port number %d", int(try_port));
+ if (try_port <= 0)
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "was passed the invalid port number %d", int(try_port));
+ }
}
- libtest::Server *server= NULL;
- try {
- if (0)
- { }
- else if (server_type.compare("gearmand") == 0)
+ if (is_socket)
+ {
+ if (server_type.compare("memcached") == 0)
{
- if (GEARMAND_BINARY)
- {
- server= build_gearmand("localhost", try_port);
- }
+ server= build_memcached_socket("localhost", try_port);
}
- else if (server_type.compare("hostile-gearmand") == 0)
+ else
{
- if (GEARMAND_BINARY)
- {
- server= build_gearmand("localhost", try_port, "gearmand/hostile_gearmand");
- }
+ Error << "Socket is not support for server: " << server_type;
+ return NULL;
}
- else if (server_type.compare("drizzled") == 0)
+ }
+ else if (server_type.compare("gearmand") == 0)
+ {
+ server= build_gearmand("localhost", try_port);
+ }
+ else if (server_type.compare("hostile-gearmand") == 0)
+ {
+ server= build_gearmand("localhost", try_port, "gearmand/hostile_gearmand");
+ }
+ else if (server_type.compare("drizzled") == 0)
+ {
+ if (DRIZZLED_BINARY)
{
- if (DRIZZLED_BINARY)
+ if (HAVE_LIBDRIZZLE)
{
- if (HAVE_LIBDRIZZLE)
- {
- server= build_drizzled("localhost", try_port);
- }
+ server= build_drizzled("localhost", try_port);
}
}
- else if (server_type.compare("blobslap_worker") == 0)
+ }
+ else if (server_type.compare("blobslap_worker") == 0)
+ {
+ if (GEARMAND_BINARY)
{
- if (GEARMAND_BINARY)
+ if (GEARMAND_BLOBSLAP_WORKER)
{
- if (GEARMAND_BLOBSLAP_WORKER)
+ if (HAVE_LIBGEARMAN)
{
- if (HAVE_LIBGEARMAN)
- {
- server= build_blobslap_worker(try_port);
- }
+ server= build_blobslap_worker(try_port);
}
}
}
- else if (server_type.compare("memcached") == 0)
+ }
+ else if (server_type.compare("memcached") == 0)
+ {
+ if (HAVE_MEMCACHED_BINARY)
{
- if (HAVE_MEMCACHED_BINARY)
- {
- server= build_memcached("localhost", try_port);
- }
+ server= build_memcached("localhost", try_port);
}
+ }
- if (server == NULL)
- {
- throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Launching of an unknown server was attempted: %s", server_type.c_str());
- }
+ return server;
+}
+
+class ServerPtr {
+public:
+ ServerPtr(libtest::Server* server_):
+ _server(server_)
+ { }
+
+ ~ServerPtr()
+ {
+ delete _server;
}
- catch (...)
+
+ void reset()
{
- throw;
+ delete _server;
+ _server= NULL;
+ }
+
+ libtest::Server* release(libtest::Server* server_= NULL)
+ {
+ libtest::Server* tmp= _server;
+ _server= server_;
+ return tmp;
+ }
+
+ libtest::Server* operator->() const
+ {
+ return _server;
+ }
+
+ libtest::Server* operator&() const
+ {
+ return _server;
}
+private:
+ libtest::Server* _server;
+};
+
+bool server_startup_st::_start_server(const bool is_socket,
+ const std::string& server_type,
+ in_port_t try_port,
+ int argc, const char *argv[],
+ const bool opt_startup_message)
+{
try {
+ ServerPtr server(create(server_type, try_port, is_socket));
+
+ if (&server == NULL)
+ {
+ Error << "Could not allocate server: " << server_type;
+ return false;
+ }
+
/*
We will now cycle the server we have created.
*/
if (server->cycle() == false)
{
- Error << "Could not start up server " << *server;
- delete server;
+ Error << "Could not start up server " << &server;
return false;
}
if (server->start() == false)
{
- delete server;
return false;
}
else
#endif
}
}
+
+ push_server(server.release());
+
+ if (is_socket and &server)
+ {
+ set_default_socket(server->socket().c_str());
+ }
}
catch (libtest::disconnected& err)
{
if (fatal::is_disabled() == false and try_port != LIBTEST_FAIL_PORT)
{
stream::cerr(err.file(), err.line(), err.func()) << err.what();
- delete server;
return false;
}
}
- catch (...)
+ catch (libtest::__test_result& err)
{
- delete server;
- throw;
+ stream::cerr(err.file(), err.line(), err.func()) << err.what();
+ return false;
}
-
- push_server(server);
-
- return true;
-}
-
-bool server_startup_st::start_socket_server(const std::string& server_type, const in_port_t try_port, int argc,
- const char *argv[],
- const bool opt_startup_message)
-{
- (void)try_port;
- Outn();
-
- Server *server= NULL;
- try {
- if (0)
- { }
- else if (server_type.compare("gearmand") == 0)
- {
- Error << "Socket files are not supported for gearmand yet";
- }
- else if (server_type.compare("memcached") == 0)
- {
- if (HAVE_MEMCACHED_BINARY)
- {
- server= build_memcached_socket("localhost", try_port);
- }
- else
- {
- Error << "No memcached binary is available";
- }
- }
- else
- {
- Error << "Failed to start " << server_type << ", no support was found to be compiled in for it.";
- }
-
- if (server == NULL)
- {
- Error << "Failure occured while creating server: " << server_type;
- return false;
- }
-
- /*
- We will now cycle the server we have created.
- */
- if (server->cycle() == false)
- {
- Error << "Could not start up server " << *server;
- delete server;
- return false;
- }
-
- server->build(argc, argv);
-
-#if 0
- if (false)
- {
- Out << "Pausing for startup, hit return when ready.";
- std::string gdb_command= server->base_command();
- std::string options;
- Out << "run " << server->args(options);
- getchar();
- }
- else
-#endif
- if (server->start() == false)
- {
- Error << "Failed to start " << *server;
- delete server;
- return false;
- }
- else
- {
- if (opt_startup_message)
- {
-#if defined(DEBUG)
- if (DEBUG)
- {
- Outn();
- Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running();
- Outn();
- }
-#endif
- }
- }
+ catch (std::exception& err)
+ {
+ Error << err.what();
+ return false;
}
catch (...)
{
- delete server;
- throw;
+ Error << "error occured while creating server: " << server_type;
+ return false;
}
- push_server(server);
-
- set_default_socket(server->socket().c_str());
+ return true;
+}
- Outn();
+bool server_startup_st::start_server(const std::string& server_type, in_port_t try_port,
+ int argc, const char *argv[],
+ const bool opt_startup_message)
+{
+ return _start_server(false, server_type, try_port, argc, argv, opt_startup_message);
+}
- return true;
+bool server_startup_st::start_socket_server(const std::string& server_type, const in_port_t try_port,
+ int argc, const char *argv[],
+ const bool opt_startup_message)
+{
+ return _start_server(true, server_type, try_port, argc, argv, opt_startup_message);
}
std::string server_startup_st::option_string() const
std::string server_list;
bool _socket;
bool _sasl;
- uint32_t _count;
std::string _username;
std::string _password;
Server* last();
Server *pop_server();
+ Server* create(const std::string& server_type, in_port_t try_port, const bool is_socket);
+
unsigned long int servers_to_run() const
{
return _servers_to_run;
_servers_to_run= arg;
}
+private:
+ bool _start_server(const bool is_socket,
+ const std::string& server_type,
+ const in_port_t try_port,
+ int argc, const char *argv[],
+ const bool opt_startup_message);
+
private:
unsigned long int _servers_to_run;
};
{ }
};
+class make_cout : public detail::log<detail::channelln> {
+public:
+ make_cout(const char* filename, int line_number, const char* func) :
+ detail::log<detail::channelln>(std::cout, filename, line_number, func)
+ { }
+
+};
+
class cout : public detail::log<detail::channel> {
public:
cout(const char* filename, int line_number, const char* func) :
#pragma once
+#ifndef YATL_FULL
+# define YATL_FULL 1
+#endif
+
#ifndef __PRETTY_FUNCTION__
-#define __PRETTY_FUNCTION__ __func__
+# define __PRETTY_FUNCTION__ __func__
#endif
#define YATL_STRINGIFY(x) #x
return TEST_FAILURE;
}
+static test_return_t test_throw_skip_macro_TEST(void *)
+{
+ try {
+ SKIP_IF(true);
+ }
+ catch (libtest::__skipped e)
+ {
+ return TEST_SUCCESS;
+ }
+ catch (...)
+ {
+ FAIL("SLIP_IF() failed to throw libtest::_skipped");
+ }
+
+ FAIL("SLIP_IF() failed to throw");
+
+ return TEST_FAILURE;
+}
+
static test_return_t test_throw_skip_TEST(void *)
{
try {
- SKIP;
+ throw libtest::__skipped(LIBYATL_DEFAULT_PARAM, "basic test");
}
- catch (libtest::__skipped)
+ catch (libtest::__skipped e)
{
return TEST_SUCCESS;
}
catch (...)
{
- return TEST_FAILURE;
+ FAIL("SLIP_IF() failed to throw libtest::_skipped");
}
+ FAIL("SLIP_IF() failed to throw");
+
return TEST_FAILURE;
}
{
return TEST_SKIPPED; // Only run this when debugging
- test_compare(1, 2);
+ ASSERT_EQ(1, 2);
return TEST_SUCCESS;
}
// unsetenv() will cause issues with valgrind
_compare(__FILE__, __LINE__, __func__, 0, unsetenv("LIBTEST_LOCAL"), true);
- test_compare(0, unsetenv("LIBTEST_LOCAL"));
+ ASSERT_EQ(0, unsetenv("LIBTEST_LOCAL"));
test_false(test_is_local());
- test_compare(0, setenv("LIBTEST_LOCAL", "1", 1));
+ ASSERT_EQ(0, setenv("LIBTEST_LOCAL", "1", 1));
test_true(test_is_local());
if (temp.empty())
{
- test_compare(0, unsetenv("LIBTEST_LOCAL"));
+ ASSERT_EQ(0, unsetenv("LIBTEST_LOCAL"));
}
else
{
char *old_string= strdup(temp.c_str());
- test_compare(0, setenv("LIBTEST_LOCAL", old_string, 1));
+ ASSERT_EQ(0, setenv("LIBTEST_LOCAL", old_string, 1));
}
return TEST_SUCCESS;
static test_return_t var_exists_test(void *)
{
- test_compare(0, access("var", R_OK | W_OK | X_OK));
+ ASSERT_EQ(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));
+ ASSERT_EQ(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));
+ ASSERT_EQ(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));
+ ASSERT_EQ(0, access("var/log", R_OK | W_OK | X_OK));
return TEST_SUCCESS;
}
static test_return_t var_drizzle_exists_test(void *)
{
- test_compare(0, access("var/drizzle", R_OK | W_OK | X_OK));
+ ASSERT_EQ(0, access("var/drizzle", R_OK | W_OK | X_OK));
return TEST_SUCCESS;
}
static test_return_t _compare_test_return_t_test(void *)
{
- test_compare(TEST_SUCCESS, TEST_SUCCESS);
+ ASSERT_EQ(TEST_SUCCESS, TEST_SUCCESS);
return TEST_SUCCESS;
}
{
test_skip(HAVE_LIBMEMCACHED, true);
#if defined(HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H) && HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H
- test_compare(MEMCACHED_SUCCESS, MEMCACHED_SUCCESS);
+ ASSERT_EQ(MEMCACHED_SUCCESS, MEMCACHED_SUCCESS);
#endif
return TEST_SUCCESS;
{
test_skip(HAVE_LIBGEARMAN, true);
#if defined(HAVE_LIBGEARMAN_1_0_RETURN_H) && HAVE_LIBGEARMAN_1_0_RETURN_H
- test_compare(GEARMAN_SUCCESS, GEARMAN_SUCCESS);
+ ASSERT_EQ(GEARMAN_SUCCESS, GEARMAN_SUCCESS);
#endif
return TEST_SUCCESS;
static test_return_t test_skip_true_TEST(void*)
{
- test_compare(true, true);
- test_compare(false, false);
- test_compare(TEST_SUCCESS, skip_shim(true, true));
- test_compare(TEST_SUCCESS, skip_shim(false, false));
+ ASSERT_EQ(true, true);
+ ASSERT_EQ(false, false);
+ ASSERT_EQ(TEST_SUCCESS, skip_shim(true, true));
+ ASSERT_EQ(TEST_SUCCESS, skip_shim(false, false));
return TEST_SUCCESS;
}
static test_return_t test_skip_false_TEST(void*)
{
- test_compare(TEST_SKIPPED, skip_shim(true, false));
- test_compare(TEST_SKIPPED, skip_shim(false, true));
+ ASSERT_EQ(TEST_SKIPPED, skip_shim(true, false));
+ ASSERT_EQ(TEST_SKIPPED, skip_shim(false, true));
return TEST_SUCCESS;
}
test_true(servers);
fatal::disable();
- test_compare(servers->start_server(testing_service, LIBTEST_FAIL_PORT, 0, NULL, false), true);
+ ASSERT_EQ(servers->start_server(testing_service, LIBTEST_FAIL_PORT, 0, NULL, false), true);
fatal::enable();
return TEST_SUCCESS;
server_startup_st *servers= (server_startup_st*)object;
test_true(servers);
- test_compare(servers->start_server(testing_service, get_free_port(), 0, NULL, false), true);
+ ASSERT_EQ(servers->start_server(testing_service, get_free_port(), 0, NULL, false), true);
test_true(servers->last());
pid_t last_pid= servers->last()->pid();
- test_compare(servers->last()->pid(), last_pid);
+ ASSERT_EQ(servers->last()->pid(), last_pid);
test_true(last_pid > 1);
- test_compare(kill(last_pid, 0), 0);
+ ASSERT_EQ(kill(last_pid, 0), 0);
test_true(servers->shutdown());
#if 0
- test_compare(servers->last()->pid(), -1);
- test_compare(kill(last_pid, 0), -1);
+ ASSERT_EQ(servers->last()->pid(), -1);
+ ASSERT_EQ(kill(last_pid, 0), -1);
#endif
return TEST_SUCCESS;
test_skip(0, access("/usr/bin/true", X_OK ));
Application true_app("/usr/bin/true");
- test_compare(Application::SUCCESS, true_app.run());
- test_compare(Application::SUCCESS, true_app.join());
+ ASSERT_EQ(Application::SUCCESS, true_app.run());
+ ASSERT_EQ(Application::SUCCESS, true_app.join());
return TEST_SUCCESS;
}
Application true_app("/usr/bin/true");
true_app.use_gdb(true);
- test_compare(Application::SUCCESS, true_app.run());
- test_compare(Application::SUCCESS, true_app.join());
+ ASSERT_EQ(Application::SUCCESS, true_app.run());
+ ASSERT_EQ(Application::SUCCESS, true_app.join());
return TEST_SUCCESS;
}
true_app.use_gdb(true);
const char *args[]= { "--fubar", 0 };
- test_compare(Application::SUCCESS, true_app.run(args));
- test_compare(Application::SUCCESS, true_app.join());
+ ASSERT_EQ(Application::SUCCESS, true_app.run(args));
+ ASSERT_EQ(Application::SUCCESS, true_app.join());
return TEST_SUCCESS;
}
Application true_app("/usr/bin/true");
const char *args[]= { "--fubar", 0 };
- test_compare(Application::SUCCESS, true_app.run(args));
- test_compare(Application::SUCCESS, true_app.join());
+ ASSERT_EQ(Application::SUCCESS, true_app.run(args));
+ ASSERT_EQ(Application::SUCCESS, true_app.join());
test_zero(true_app.stdout_result().size());
return TEST_SUCCESS;
const char *args[]= { "--fubar", 0 };
#if defined(TARGET_OS_OSX) && TARGET_OS_OSX
- test_compare(Application::INVALID_POSIX_SPAWN, true_app.run(args));
+ ASSERT_EQ(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));
+ ASSERT_EQ(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());
+ ASSERT_EQ(Application::SUCCESS, true_app.run(args));
+ ASSERT_EQ(Application::INVALID_POSIX_SPAWN, true_app.join());
#endif
test_zero(true_app.stdout_result().size());
{
libtest::http::GET get("http://foo.example.com/");
- test_compare(false, get.execute());
+ ASSERT_EQ(false, get.execute());
return TEST_SUCCESS;
}
libtest::vchar_t body;
libtest::http::POST post("http://foo.example.com/", body);
- test_compare(false, post.execute());
+ ASSERT_EQ(false, post.execute());
return TEST_SUCCESS;
}
libtest::vchar_t body;
libtest::http::TRACE trace("http://foo.example.com/", body);
- test_compare(false, trace.execute());
+ ASSERT_EQ(false, trace.execute());
return TEST_SUCCESS;
}
{
libtest::vchar_t response;
libtest::make_vector(response, test_literal_param("fubar\n"));
- test_compare(response, response);
+ ASSERT_EQ(response, response);
return TEST_SUCCESS;
}
Application true_app("/bin/echo");
const char *args[]= { "fubar", 0 };
- test_compare(Application::SUCCESS, true_app.run(args));
+ ASSERT_EQ(Application::SUCCESS, true_app.run(args));
while (true_app.slurp() == false) {} ;
libtest::vchar_t response;
make_vector(response, test_literal_param("fubar\n"));
- test_compare(response, true_app.stdout_result());
+ ASSERT_EQ(response, true_app.stdout_result());
}
return TEST_SUCCESS;
true_app.add_option("fubar");
- test_compare(Application::SUCCESS, true_app.run());
- test_compare(Application::SUCCESS, true_app.join());
+ ASSERT_EQ(Application::SUCCESS, true_app.run());
+ ASSERT_EQ(Application::SUCCESS, true_app.join());
libtest::vchar_t response;
make_vector(response, test_literal_param("fubar\n"));
- test_compare(response, true_app.stdout_result());
+ ASSERT_EQ(response, true_app.stdout_result());
}
return TEST_SUCCESS;
static test_return_t echo_fubar_BINARY(void *)
{
const char *args[]= { "fubar", 0 };
- test_compare(EXIT_SUCCESS, exec_cmdline("/bin/echo", args));
+ ASSERT_EQ(EXIT_SUCCESS, exec_cmdline("/bin/echo", args));
return TEST_SUCCESS;
}
{
const char *args[]= { 0 };
- test_compare(EXIT_SUCCESS, exec_cmdline("libtest/core-count", args, true));
+ ASSERT_EQ(EXIT_SUCCESS, exec_cmdline("libtest/core-count", args, true));
return TEST_SUCCESS;
}
{
const char *args[]= { "--quiet", 0 };
- test_compare(EXIT_FAILURE, exec_cmdline("libtest/wait", args, true));
+ ASSERT_EQ(EXIT_FAILURE, exec_cmdline("libtest/wait", args, true));
return TEST_SUCCESS;
}
{
const char *args[]= { "--quiet", "--help", 0 };
- test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
+ ASSERT_EQ(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
return TEST_SUCCESS;
}
{
const char *args[]= { "--quiet", "--version", 0 };
- test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
+ ASSERT_EQ(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
return TEST_SUCCESS;
}
const char *args[]= { "--quiet", "/etc/services", 0 };
- test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
+ ASSERT_EQ(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
return TEST_SUCCESS;
}
const char *args[]= { "/etc/services", 0 };
- test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
+ ASSERT_EQ(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
return TEST_SUCCESS;
}
wait_app.use_gdb(true);
const char *args[]= { "/etc/services", 0 };
- test_compare(Application::SUCCESS, wait_app.run(args));
- test_compare(Application::SUCCESS, wait_app.join());
+ ASSERT_EQ(Application::SUCCESS, wait_app.run(args));
+ ASSERT_EQ(Application::SUCCESS, wait_app.join());
return TEST_SUCCESS;
}
wait_app.use_gdb(true);
const char *args[]= { "/etc/services", 0 };
- test_compare(Application::SUCCESS, wait_app.run(args));
- test_compare(Application::SUCCESS, wait_app.join());
+ ASSERT_EQ(Application::SUCCESS, wait_app.run(args));
+ ASSERT_EQ(Application::SUCCESS, wait_app.join());
return TEST_SUCCESS;
}
libtest::Application abort_app("libtest/abort", true);
abort_app.use_gdb(true);
- test_compare(Application::SUCCESS, abort_app.run());
- test_compare(Application::SUCCESS, abort_app.join());
+ ASSERT_EQ(Application::SUCCESS, abort_app.run());
+ ASSERT_EQ(Application::SUCCESS, abort_app.join());
std::string gdb_filename= abort_app.gdb_filename();
test_skip(0, access(gdb_filename.c_str(), R_OK ));
const char *args[]= { "SIGABRT", gdb_filename.c_str(), 0 };
- test_compare(EXIT_SUCCESS, exec_cmdline("grep", args));
+ ASSERT_EQ(EXIT_SUCCESS, exec_cmdline("grep", args));
// Sanity test
args[0]= "THIS_WILL_NOT_BE_FOUND";
- test_compare(EXIT_FAILURE, exec_cmdline("grep", args));
+ ASSERT_EQ(EXIT_FAILURE, exec_cmdline("grep", args));
return TEST_SUCCESS;
}
static test_return_t fatal_TEST(void *)
{
- test_compare(fatal_calls++, fatal::disabled_counter());
+ ASSERT_EQ(fatal_calls++, fatal::disabled_counter());
throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Testing va_args based fatal(): %d", 10);
return TEST_SUCCESS;
check.reset();
check.offset(minutes, 2, 200);
- test_compare(check.minutes(), minutes);
+ ASSERT_EQ(check.minutes(), minutes);
return TEST_SUCCESS;
}
{
test_skip(0, access("/usr/bin/touch", X_OK ));
std::string tmp= create_tmpfile(__func__);
- test_compare(-1, access(tmp.c_str(), R_OK));
- test_compare(-1, access(tmp.c_str(), F_OK));
+ ASSERT_EQ(-1, access(tmp.c_str(), R_OK));
+ ASSERT_EQ(-1, access(tmp.c_str(), F_OK));
Application touch_app("/usr/bin/touch");
const char *args[]= { tmp.c_str(), 0 };
- test_compare(Application::SUCCESS, touch_app.run(args));
- test_compare(Application::SUCCESS, touch_app.join());
+ ASSERT_EQ(Application::SUCCESS, touch_app.run(args));
+ ASSERT_EQ(Application::SUCCESS, touch_app.join());
- test_compare(0, access(tmp.c_str(), R_OK));
- test_compare(0, unlink(tmp.c_str()));
+ ASSERT_EQ(0, access(tmp.c_str(), R_OK));
+ ASSERT_EQ(0, unlink(tmp.c_str()));
return TEST_SUCCESS;
}
static test_return_t fatal_message_TEST(void *)
{
- test_compare(fatal_calls++, fatal::disabled_counter());
+ ASSERT_EQ(fatal_calls++, fatal::disabled_counter());
fatal_message("Fatal test");
return TEST_SUCCESS;
static test_return_t default_port_TEST(void *)
{
in_port_t ret_port= default_port();
- test_compare(ret_port, libtest::default_port());
- test_compare(ret_port, libtest::default_port());
+ ASSERT_EQ(ret_port, libtest::default_port());
+ ASSERT_EQ(ret_port, libtest::default_port());
return TEST_SUCCESS;
}
{"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 },
+ {"libtest::__skipped", false, test_throw_skip_TEST },
+ {"SKIP_IF", false, test_throw_skip_macro_TEST },
{"FAIL", false, test_throw_fail_TEST },
{"ASSERT_FALSE_", false, ASSERT_FALSE__TEST },
{"ASSERT_FALSE", false, ASSERT_FALSE_TEST },
}
}
+void append(libtest::vchar_ptr_t& arg, const char* ptr)
+{
+ if (ptr)
+ {
+ char* new_ptr= strdup(ptr);
+ if (new_ptr == NULL)
+ {
+ fatal_message("UNABLE to allocate %s(%p)", ptr, ptr);
+ }
+ arg.push_back(new_ptr);
+ }
+}
+
} // namespace vchar
void make_vector(libtest::vchar_t& arg, const char *str, size_t length)
int compare(libtest::vchar_t& arg, const char *str, size_t length);
void make(libtest::vchar_t& arg);
void make(libtest::vchar_t& arg, size_t length);
+void append(libtest::vchar_ptr_t& arg, const char*);
} // namespace vchar