void get_world(Framework *world)
{
- world->_create= world_create;
- world->_destroy= world_destroy;
- world->collections= collection;
+ world->create(world_create);
+ world->destroy(world_destroy);
+ world->collections(collection);
world->set_runner(new MemcachedLightRunner);
}
posix_spawn_file_actions_t file_actions;
posix_spawn_file_actions_init(&file_actions);
- stdin_fd.dup_for_spawn(Application::Pipe::READ, file_actions);
- stdout_fd.dup_for_spawn(Application::Pipe::WRITE, file_actions);
- stderr_fd.dup_for_spawn(Application::Pipe::WRITE, file_actions);
+ stdin_fd.dup_for_spawn(file_actions);
+ stdout_fd.dup_for_spawn(file_actions);
+ stderr_fd.dup_for_spawn(file_actions);
posix_spawnattr_t spawnattr;
posix_spawnattr_init(&spawnattr);
Application::Pipe::~Pipe()
{
- close(READ);
- close(WRITE);
+ if (_pipe_fd[0] != -1)
+ {
+ ::close(_pipe_fd[0]);
+ }
+
+ if (_pipe_fd[1] != -1)
+ {
+ ::close(_pipe_fd[1]);
+ }
}
-void Application::Pipe::dup_for_spawn(const close_t& arg, posix_spawn_file_actions_t& file_actions)
+void Application::Pipe::dup_for_spawn(posix_spawn_file_actions_t& file_actions)
{
- int type= int(arg);
+ int type= STDIN_FILENO == _std_fd ? 0 : 1;
int ret;
if ((ret= posix_spawn_file_actions_adddup2(&file_actions, _pipe_fd[type], _std_fd )) < 0)
void reset();
void close(const close_t& arg);
- void dup_for_spawn(const close_t& arg,
- posix_spawn_file_actions_t& file_actions);
+ void dup_for_spawn(posix_spawn_file_actions_t& file_actions);
void nonblock();
void cloexec();
{
for (test_st *run= _tests; run->name; run++)
{
- long int load_time= 0;
-
if (_frame->match(run->name))
{
continue;
catch (libtest::fatal &e)
{
Error << "Fatal exception was thrown: " << e.what();
- return_code= TEST_FAILURE;
_failed++;
throw;
}
return true;
}
+template <class T1_comparable, class T2_comparable>
+bool _compare_strcmp(const char *file, int line, const char *func, const T1_comparable& __expected, const T2_comparable& __actual)
+{
+ if (__expected == NULL)
+ {
+ fatal_message("Expected value was NULL, programmer error");
+ }
+
+ if (__actual == NULL)
+ {
+ libtest::stream::make_cerr(file, line, func) << "Expected " << __expected << " but got NULL";
+ return false;
+ }
+
+ if (strncmp(__expected, __actual, strlen(__expected)))
+ {
+ libtest::stream::make_cerr(file, line, func) << "Expected " << __expected << " passed \"" << __actual << "\"";
+ return false;
+ }
+
+ return true;
+}
+
template <class T_comparable>
bool _compare_zero(const char *file, int line, const char *func, T_comparable __actual)
{
fatal::fatal(const char *file_arg, int line_arg, const char *func_arg, const char *format, ...) :
std::runtime_error(func_arg),
- _file(file_arg),
_line(line_arg),
+ _file(file_arg),
_func(func_arg)
{
va_list args;
Framework::Framework(libtest::SignalThread& signal,
const std::string& only_run_arg,
const std::string& wildcard_arg) :
- collections(NULL),
+ _collections(NULL),
_total(0),
_success(0),
_skipped(0),
_failed(0),
_create(NULL),
_destroy(NULL),
+ _on_error(NULL),
_runner(NULL),
_socket(false),
_creators_ptr(NULL),
{
get_world(this);
- for (collection_st *next= collections; next and next->name; next++)
+ for (collection_st *next= _collections; next and next->name; next++)
{
_collection.push_back(new Collection(this, next));
}
{
delete *iter;
}
- _collection.clear();
}
bool Framework::match(const char* arg)
class Framework {
public:
- collection_st *collections;
-
- /* These methods are called outside of any collection call. */
- test_callback_create_fn *_create;
- test_callback_destroy_fn *_destroy;
public:
test_return_t create();
- /**
- If an error occurs during the test, this is called.
- */
- test_callback_error_fn *_on_error;
+ void create(test_callback_create_fn* arg)
+ {
+ _create= arg;
+ }
+
+ void destroy(test_callback_destroy_fn* arg)
+ {
+ _destroy= arg;
+ }
+
+ void collections(collection_st* arg)
+ {
+ _collections= arg;
+ }
void set_on_error(test_callback_error_fn *arg)
{
{
return _servers;
}
-
- /**
- Runner represents the callers for the tests. If not implemented we will use
- a set of default implementations.
- */
- libtest::Runner *_runner;
void set_runner(libtest::Runner *arg)
{
private:
Framework& operator=(const Framework&);
+ collection_st *_collections;
+
uint32_t _total;
uint32_t _success;
uint32_t _skipped;
uint32_t _failed;
+
+ /* These methods are called outside of any collection call. */
+ test_callback_create_fn *_create;
+ test_callback_destroy_fn *_destroy;
+
+ /**
+ If an error occurs during the test, this is called.
+ */
+ test_callback_error_fn *_on_error;
+
+ /**
+ Runner represents the callers for the tests. If not implemented we will use
+ a set of default implementations.
+ */
+ libtest::Runner *_runner;
libtest::server_startup_st _servers;
bool _socket;
EXTRA_DIST+= libtest/run.gdb
-CLEANFILES+= \
- tmp_chroot/var/drizzle/* \
- tmp_chroot/var/log/* \
- tmp_chroot/var/run/* \
- tmp_chroot/var/tmp/*
+CLEANFILES+= tmp_chroot/etc/*
+CLEANFILES+= tmp_chroot/var/drizzle/*
+CLEANFILES+= tmp_chroot/var/log/*
+CLEANFILES+= tmp_chroot/var/run/*
+CLEANFILES+= tmp_chroot/var/tmp/*
.PHONY: distclean-libtest-check
distclean-libtest-check:
-rm -rf tmp_chroot
noinst_HEADERS+= libtest/timer.hpp
-noinst_HEADERS+= \
- libtest/binaries.h \
- libtest/cpu.hpp \
- libtest/blobslap_worker.h \
- libtest/callbacks.h \
- libtest/cmdline.h \
- libtest/collection.h \
- libtest/common.h \
- libtest/comparison.hpp \
- libtest/core.h \
- libtest/dream.h \
- libtest/error.h \
- libtest/failed.h \
- libtest/fatal.hpp \
- libtest/framework.h \
- libtest/gearmand.h \
- libtest/drizzled.h \
- libtest/get.h \
- libtest/has.hpp \
- libtest/http.hpp \
- libtest/is_pid.hpp \
- libtest/is_local.hpp \
- libtest/killpid.h \
- libtest/libtool.hpp \
- libtest/memcached.h \
- libtest/port.h \
- libtest/runner.h \
- libtest/server.h \
- libtest/server_container.h \
- libtest/signal.h \
- libtest/socket.hpp \
- libtest/stream.h \
- libtest/strerror.h \
- libtest/string.hpp \
- libtest/test.h \
- libtest/test.hpp \
- libtest/tmpfile.hpp \
- libtest/vchar.hpp \
- libtest/visibility.h \
- libtest/wait.h
+noinst_HEADERS+=libtest/binaries.h
+noinst_HEADERS+=libtest/cpu.hpp
+noinst_HEADERS+=libtest/blobslap_worker.h
+noinst_HEADERS+=libtest/callbacks.h
+noinst_HEADERS+=libtest/cmdline.h
+noinst_HEADERS+=libtest/collection.h
+noinst_HEADERS+=libtest/common.h
+noinst_HEADERS+=libtest/comparison.hpp
+noinst_HEADERS+=libtest/core.h
+noinst_HEADERS+=libtest/dream.h
+noinst_HEADERS+=libtest/error.h
+noinst_HEADERS+=libtest/failed.h
+noinst_HEADERS+=libtest/fatal.hpp
+noinst_HEADERS+=libtest/framework.h
+noinst_HEADERS+=libtest/gearmand.h
+noinst_HEADERS+=libtest/drizzled.h
+noinst_HEADERS+=libtest/get.h
+noinst_HEADERS+=libtest/has.hpp
+noinst_HEADERS+=libtest/http.hpp
+noinst_HEADERS+=libtest/is_pid.hpp
+noinst_HEADERS+=libtest/is_local.hpp
+noinst_HEADERS+=libtest/killpid.h
+noinst_HEADERS+=libtest/libtool.hpp
+noinst_HEADERS+=libtest/memcached.h
+noinst_HEADERS+=libtest/port.h
+noinst_HEADERS+=libtest/runner.h
+noinst_HEADERS+=libtest/server.h
+noinst_HEADERS+=libtest/server_container.h
+noinst_HEADERS+=libtest/signal.h
+noinst_HEADERS+=libtest/socket.hpp
+noinst_HEADERS+=libtest/stream.h
+noinst_HEADERS+=libtest/strerror.h
+noinst_HEADERS+=libtest/string.hpp
+noinst_HEADERS+=libtest/test.h
+noinst_HEADERS+=libtest/test.hpp
+noinst_HEADERS+=libtest/tmpfile.hpp
+noinst_HEADERS+=libtest/vchar.hpp
+noinst_HEADERS+=libtest/visibility.h
+noinst_HEADERS+=libtest/wait.h
noinst_LTLIBRARIES+= libtest/libtest.la
libtest_tmp_dir: tmp_chroot/var/log tmp_chroot/var/tmp tmp_chroot/var/run tmp_chroot/var/drizzle
-tmp_chroot:
+tmp_chroot: tmp_chroot/etc
@$(mkdir_p) tmp_chroot
+tmp_chroot/etc:
+ @$(mkdir_p) tmp_chroot/etc
+
tmp_chroot/var: tmp_chroot
@$(mkdir_p) tmp_chroot/var
#include <sys/wait.h>
#include <unistd.h>
+#include <utility>
+#include <vector>
+
#include <signal.h>
#include <libtest/signal.h>
using namespace libtest;
struct socket_st {
- std::vector<int> fd;
+ typedef std::vector< std::pair< int, in_port_t> > socket_port_t;
+ socket_port_t _pair;
+
+ void release(in_port_t _arg)
+ {
+ for(socket_port_t::iterator iter= _pair.begin();
+ iter != _pair.end();
+ iter++)
+ {
+ if ((*iter).second == _arg)
+ {
+ close((*iter).first);
+ }
+ }
+ }
~socket_st()
{
- for(std::vector<int>::iterator iter= fd.begin(); iter != fd.end(); iter++)
+ for(socket_port_t::iterator iter= _pair.begin();
+ iter != _pair.end();
+ iter++)
{
- close(*iter);
+ close((*iter).first);
}
}
};
return global_port;
}
+void release_port(in_port_t arg)
+{
+ all_socket_fd.release(arg);
+}
+
in_port_t get_free_port()
{
in_port_t ret_port= in_port_t(0);
}
}
- all_socket_fd.fd.push_back(sd);
+ all_socket_fd._pair.push_back(std::make_pair(sd, ret_port));
}
if (ret_port > 1024)
LIBTEST_API
in_port_t get_free_port();
+LIBTEST_API
+void release_port(in_port_t arg);
+
} // namespace libtest
return false;
}
+ libtest::release_port(_port);
Application::error_t ret;
if (Application::SUCCESS != (ret= _app.run()))
{
void get_world(Framework *world)
{
- world->_create= world_create;
+ world->create(world_create);
}
make_cerr(const char* filename, int line_number, const char* func) :
detail::log<detail::channelln>(std::cerr, filename, line_number, func)
{ }
+
};
class cerr : public detail::log<detail::channel> {
cerr(const char* filename, int line_number, const char* func) :
detail::log<detail::channel>(std::cout, filename, line_number, func)
{ }
+
};
class clog : public detail::log<detail::channel> {
} while (0)
-#define test_strcmp(A,B) \
+#define test_strcmp(__expected, __actual) \
do \
{ \
- if ((A) == NULL or (B) == NULL or strcmp((A), (B))) \
- { \
- if ((B) == NULL) fprintf(stderr, "\n%s:%d: Expected %s, got <null>\n", __FILE__, __LINE__, (A)); \
- else fprintf(stderr, "\n%s:%d: Expected %s, got \"%s\"\n", __FILE__, __LINE__, (A), (B)); \
- libtest::create_core(); \
- return TEST_FAILURE; \
- } \
+ void(libtest::_compare_strcmp(__FILE__, __LINE__, __func__, (__expected), (__actual))); \
} while (0)
#define test_memcmp(A,B,C) \
void get_world(Framework *world)
{
- world->collections= collection;
- world->_create= world_create;
+ world->collections(collection);
+ world->create(world_create);
}
void get_world(Framework *world)
{
- world->collections= collection;
- world->_create= world_create;
+ world->collections(collection);
+ world->create(world_create);
}
{
world->servers().set_servers_to_run(1);
- world->collections= collection;
+ world->collections(collection);
- world->_create= (test_callback_create_fn*)world_create;
- world->_destroy= (test_callback_destroy_fn*)world_destroy;
+ world->create((test_callback_create_fn*)world_create);
+ world->destroy((test_callback_destroy_fn*)world_destroy);
world->set_runner(new LibmemcachedRunner);
void get_world(Framework *world)
{
- world->collections= collection;
+ world->collections(collection);
}
void get_world(Framework *world)
{
- world->collections= collection;
- world->_create= world_create;
- world->_destroy= world_destroy;
+ world->collections(collection);
+ world->create(world_create);
+ world->destroy(world_destroy);
}
world->servers().set_servers_to_run(8);
}
- world->collections= collection;
+ world->collections(collection);
- world->_create= (test_callback_create_fn*)world_create;
- world->_destroy= (test_callback_destroy_fn*)world_destroy;
+ world->create((test_callback_create_fn*)world_create);
+ world->destroy((test_callback_destroy_fn*)world_destroy);
world->set_runner(new LibmemcachedRunner);
void get_world(Framework *world)
{
- world->collections= collection;
+ world->collections(collection);
- world->_create= (test_callback_create_fn*)world_create;
- world->_destroy= (test_callback_destroy_fn*)world_destroy;
+ world->create((test_callback_create_fn*)world_create);
+ world->destroy((test_callback_destroy_fn*)world_destroy);
world->set_runner(new LibmemcachedRunner);
}
void get_world(Framework *world)
{
- world->collections= collection;
+ world->collections(collection);
- world->_create= (test_callback_create_fn*)world_create;
- world->_destroy= (test_callback_destroy_fn*)world_destroy;
+ world->create((test_callback_create_fn*)world_create);
+ world->destroy((test_callback_destroy_fn*)world_destroy);
world->set_runner(new LibmemcachedRunner);
}
void get_world(Framework *frame)
{
- frame->collections= collection;
+ frame->collections(collection);
}
memcached_mget(memc, keys, key_length, 1));
memcached_return_t rc;
- memcached_result_st *results = memcached_fetch_result(memc, NULL, &rc);
+ memcached_result_st *results= memcached_fetch_result(memc, NULL, &rc);
test_true(results);
test_compare(MEMCACHED_SUCCESS, rc);
uint64_t cas_value= memcached_result_cas(results);
test_true(cas_value);
+ memcached_result_free(results);
+
// Bad cas value, sanity check
test_true(cas_value != 9999);
test_compare(MEMCACHED_END,
void get_world(Framework *world)
{
- world->collections= collection;
+ world->collections(collection);
- world->_create= world_create;
- world->_destroy= world_destroy;
+ world->create((test_callback_create_fn*)world_create);
+ world->destroy((test_callback_destroy_fn*)world_destroy);
world->set_runner(new LibmemcachedRunner);
}
void get_world(Framework *world)
{
- world->collections= collection;
+ world->collections(collection);
- world->_create= (test_callback_create_fn*)world_create;
- world->_destroy= (test_callback_destroy_fn*)world_destroy;
+ world->create((test_callback_create_fn*)world_create);
+ world->destroy((test_callback_destroy_fn*)world_destroy);
world->set_runner(new LibmemcachedRunner);
void get_world(Framework *world)
{
- world->collections= collection;
+ world->collections(collection);
- world->_create= (test_callback_create_fn*)world_create;
- world->_destroy= (test_callback_destroy_fn*)world_destroy;
+ world->create((test_callback_create_fn*)world_create);
+ world->destroy((test_callback_destroy_fn*)world_destroy);
world->set_runner(new LibmemcachedRunner);
}
void get_world(Framework *world)
{
executable= "./clients/memcapable";
- world->collections= collection;
- world->_create= world_create;
+ world->collections(collection);
+ world->create(world_create);
}
void get_world(Framework *world)
{
- world->collections= collection;
- world->_create= world_create;
+ world->collections(collection);
+ world->create(world_create);
}
void get_world(Framework *world)
{
- world->collections= collection;
- world->_create= world_create;
+ world->collections(collection);
+ world->create(world_create);
}
void get_world(Framework *world)
{
- world->collections= collection;
- world->_create= world_create;
+ world->collections(collection);
+ world->create(world_create);
}
void get_world(Framework *world)
{
- world->collections= collection;
- world->_create= world_create;
+ world->collections(collection);
+ world->create(world_create);
}
void get_world(Framework *world)
{
- world->collections= collection;
- world->_create= world_create;
+ world->collections(collection);
+ world->create(world_create);
}
void get_world(Framework *world)
{
executable= "./clients/memflush";
- world->collections= collection;
- world->_create= world_create;
+ world->collections(collection);
+ world->create(world_create);
}
void get_world(Framework *world)
{
- world->collections= collection;
- world->_create= world_create;
+ world->collections(collection);
+ world->create(world_create);
}
void get_world(Framework *world)
{
executable= "./clients/memslap";
- world->collections= collection;
- world->_create= world_create;
+ world->collections(collection);
+ world->create(world_create);
}
void get_world(Framework *world)
{
- world->collections= collection;
- world->_create= world_create;
+ world->collections(collection);
+ world->create(world_create);
}
void get_world(Framework *world)
{
executable= "./clients/memtouch";
- world->collections= collection;
- world->_create= world_create;
+ world->collections(collection);
+ world->create(world_create);
}
void get_world(Framework *world)
{
- world->collections= collection;
+ world->collections(collection);
}