From: Brian Aker Date: Sun, 13 May 2012 02:05:10 +0000 (-0400) Subject: Catch up with Gearman's libtest X-Git-Tag: 1.0.8~4^2~2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=23bbe3972dada1e21493437ba64be129e86b59fc;p=m6w6%2Flibmemcached Catch up with Gearman's libtest --- diff --git a/example/t/memcached_light.cc b/example/t/memcached_light.cc index e24d31c2..b9c4e5fb 100644 --- a/example/t/memcached_light.cc +++ b/example/t/memcached_light.cc @@ -233,9 +233,9 @@ static bool world_destroy(void *object) 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); } diff --git a/libtest/collection.cc b/libtest/collection.cc index c6fec1eb..5814c2f4 100644 --- a/libtest/collection.cc +++ b/libtest/collection.cc @@ -97,8 +97,6 @@ test_return_t Collection::exec() { for (test_st *run= _tests; run->name; run++) { - long int load_time= 0; - if (_frame->match(run->name)) { continue; @@ -123,7 +121,6 @@ test_return_t Collection::exec() catch (libtest::fatal &e) { Error << "Fatal exception was thrown: " << e.what(); - return_code= TEST_FAILURE; _failed++; throw; } diff --git a/libtest/fatal.cc b/libtest/fatal.cc index 9ab3292f..a4355920 100644 --- a/libtest/fatal.cc +++ b/libtest/fatal.cc @@ -42,8 +42,8 @@ namespace libtest { 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; diff --git a/libtest/framework.cc b/libtest/framework.cc index eb0f4120..ea7ca665 100644 --- a/libtest/framework.cc +++ b/libtest/framework.cc @@ -48,13 +48,14 @@ using namespace libtest; 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), @@ -64,7 +65,7 @@ Framework::Framework(libtest::SignalThread& signal, { 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)); } @@ -87,7 +88,6 @@ Framework::~Framework() { delete *iter; } - _collection.clear(); } bool Framework::match(const char* arg) diff --git a/libtest/framework.h b/libtest/framework.h index 45cd6533..da1d5b98 100644 --- a/libtest/framework.h +++ b/libtest/framework.h @@ -48,19 +48,24 @@ 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) { @@ -83,12 +88,6 @@ public: { 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) { @@ -154,10 +153,27 @@ public: 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; diff --git a/libtest/include.am b/libtest/include.am index a0d5aa04..9c7fe244 100644 --- a/libtest/include.am +++ b/libtest/include.am @@ -32,57 +32,56 @@ drd: 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 @@ -113,6 +112,7 @@ libtest_libtest_la_SOURCES+= libtest/server.cc libtest_libtest_la_SOURCES+= libtest/server_container.cc libtest_libtest_la_SOURCES+= libtest/signal.cc libtest_libtest_la_SOURCES+= libtest/socket.cc +libtest_libtest_la_SOURCES+= libtest/stream.cc libtest_libtest_la_SOURCES+= libtest/strerror.cc libtest_libtest_la_SOURCES+= libtest/timer.cc libtest_libtest_la_SOURCES+= libtest/tmpfile.cc @@ -190,9 +190,12 @@ endif 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 diff --git a/libtest/port.cc b/libtest/port.cc index 9f9a5bfe..904a0add 100644 --- a/libtest/port.cc +++ b/libtest/port.cc @@ -50,6 +50,9 @@ #include #include +#include +#include + #include #include @@ -61,13 +64,29 @@ using namespace libtest; struct socket_st { - std::vector 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::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); } } }; @@ -88,6 +107,11 @@ in_port_t default_port() 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); @@ -119,7 +143,7 @@ in_port_t get_free_port() } } - all_socket_fd.fd.push_back(sd); + all_socket_fd._pair.push_back(std::make_pair(sd, ret_port)); } if (ret_port > 1024) diff --git a/libtest/port.h b/libtest/port.h index 3d593136..bded6abc 100644 --- a/libtest/port.h +++ b/libtest/port.h @@ -48,4 +48,7 @@ in_port_t default_port(); LIBTEST_API in_port_t get_free_port(); +LIBTEST_API +void release_port(in_port_t arg); + } // namespace libtest diff --git a/libtest/server.cc b/libtest/server.cc index 31c58094..78b729f9 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -192,6 +192,7 @@ bool Server::start() return false; } + libtest::release_port(_port); Application::error_t ret; if (Application::SUCCESS != (ret= _app.run())) { diff --git a/libtest/skiptest.cc b/libtest/skiptest.cc index ac043719..354e2db1 100644 --- a/libtest/skiptest.cc +++ b/libtest/skiptest.cc @@ -53,5 +53,5 @@ static void *world_create(server_startup_st&, test_return_t& rc) void get_world(Framework *world) { - world->_create= world_create; + world->create(world_create); } diff --git a/libtest/stream.h b/libtest/stream.h index a32362f2..5d86be3e 100644 --- a/libtest/stream.h +++ b/libtest/stream.h @@ -153,6 +153,7 @@ public: make_cerr(const char* filename, int line_number, const char* func) : detail::log(std::cerr, filename, line_number, func) { } + }; class cerr : public detail::log { @@ -160,6 +161,7 @@ public: cerr(const char* filename, int line_number, const char* func) : detail::log(std::cout, filename, line_number, func) { } + }; class clog : public detail::log { diff --git a/libtest/unittest.cc b/libtest/unittest.cc index 234743f5..c27f366a 100644 --- a/libtest/unittest.cc +++ b/libtest/unittest.cc @@ -953,6 +953,6 @@ static void *world_create(server_startup_st& servers, test_return_t&) void get_world(Framework *world) { - world->collections= collection; - world->_create= world_create; + world->collections(collection); + world->create(world_create); } diff --git a/tests/cycle.cc b/tests/cycle.cc index 788d7e67..fe4ca1b3 100644 --- a/tests/cycle.cc +++ b/tests/cycle.cc @@ -123,7 +123,7 @@ static void *world_create(server_startup_st& servers, test_return_t& ) void get_world(Framework *world) { - world->collections= collection; - world->_create= world_create; + world->collections(collection); + world->create(world_create); } diff --git a/tests/failure.cc b/tests/failure.cc index d31518ee..445de246 100644 --- a/tests/failure.cc +++ b/tests/failure.cc @@ -213,10 +213,10 @@ void get_world(Framework *world) { 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); diff --git a/tests/hash_plus.cc b/tests/hash_plus.cc index 778ec220..9cb4b384 100644 --- a/tests/hash_plus.cc +++ b/tests/hash_plus.cc @@ -215,5 +215,5 @@ collection_st collection[] ={ void get_world(Framework *world) { - world->collections= collection; + world->collections(collection); } diff --git a/tests/hashkit_functions.cc b/tests/hashkit_functions.cc index e13a854b..4934b55b 100644 --- a/tests/hashkit_functions.cc +++ b/tests/hashkit_functions.cc @@ -564,7 +564,7 @@ static bool world_destroy(void *object) 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); } diff --git a/tests/libmemcached-1.0/all_tests.cc b/tests/libmemcached-1.0/all_tests.cc index e5a6d2bf..4d4d4ca8 100644 --- a/tests/libmemcached-1.0/all_tests.cc +++ b/tests/libmemcached-1.0/all_tests.cc @@ -82,10 +82,10 @@ void get_world(Framework *world) 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); diff --git a/tests/libmemcached-1.0/all_tests_socket.cc b/tests/libmemcached-1.0/all_tests_socket.cc index cdc7b211..958873fb 100644 --- a/tests/libmemcached-1.0/all_tests_socket.cc +++ b/tests/libmemcached-1.0/all_tests_socket.cc @@ -71,10 +71,10 @@ 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); } diff --git a/tests/libmemcached-1.0/atomsmasher.cc b/tests/libmemcached-1.0/atomsmasher.cc index 45171c8b..e5d53b60 100644 --- a/tests/libmemcached-1.0/atomsmasher.cc +++ b/tests/libmemcached-1.0/atomsmasher.cc @@ -275,10 +275,10 @@ collection_st collection[] ={ 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); } diff --git a/tests/libmemcached-1.0/internals.cc b/tests/libmemcached-1.0/internals.cc index 8c28d315..6e0232fc 100644 --- a/tests/libmemcached-1.0/internals.cc +++ b/tests/libmemcached-1.0/internals.cc @@ -63,5 +63,5 @@ collection_st collection[] ={ void get_world(Framework *frame) { - frame->collections= collection; + frame->collections(collection); } diff --git a/tests/libmemcached-1.0/plus.cpp b/tests/libmemcached-1.0/plus.cpp index 8539c5e6..a01544c5 100644 --- a/tests/libmemcached-1.0/plus.cpp +++ b/tests/libmemcached-1.0/plus.cpp @@ -286,10 +286,10 @@ collection_st collection[] ={ 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); } diff --git a/tests/libmemcached-1.0/sasl.cc b/tests/libmemcached-1.0/sasl.cc index 1c3d4a99..0ae101f2 100644 --- a/tests/libmemcached-1.0/sasl.cc +++ b/tests/libmemcached-1.0/sasl.cc @@ -101,10 +101,10 @@ collection_st collection[] ={ 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); diff --git a/tests/mem_udp.cc b/tests/mem_udp.cc index 4a567962..1bc4096a 100644 --- a/tests/mem_udp.cc +++ b/tests/mem_udp.cc @@ -566,10 +566,10 @@ collection_st collection[] ={ 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); } diff --git a/tests/memcapable.cc b/tests/memcapable.cc index ae50fefa..d0392d01 100644 --- a/tests/memcapable.cc +++ b/tests/memcapable.cc @@ -125,7 +125,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error) void get_world(Framework *world) { executable= "./clients/memcapable"; - world->collections= collection; - world->_create= world_create; + world->collections(collection); + world->create(world_create); } diff --git a/tests/memcat.cc b/tests/memcat.cc index e51cdce1..32e3f2c3 100644 --- a/tests/memcat.cc +++ b/tests/memcat.cc @@ -143,7 +143,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error) void get_world(Framework *world) { - world->collections= collection; - world->_create= world_create; + world->collections(collection); + world->create(world_create); } diff --git a/tests/memcp.cc b/tests/memcp.cc index eab8cfa5..8aba6088 100644 --- a/tests/memcp.cc +++ b/tests/memcp.cc @@ -102,7 +102,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error) void get_world(Framework *world) { - world->collections= collection; - world->_create= world_create; + world->collections(collection); + world->create(world_create); } diff --git a/tests/memdump.cc b/tests/memdump.cc index 4a308921..a8720e5b 100644 --- a/tests/memdump.cc +++ b/tests/memdump.cc @@ -129,7 +129,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error) void get_world(Framework *world) { - world->collections= collection; - world->_create= world_create; + world->collections(collection); + world->create(world_create); } diff --git a/tests/memerror.cc b/tests/memerror.cc index 914d2a03..dd7610ef 100644 --- a/tests/memerror.cc +++ b/tests/memerror.cc @@ -119,7 +119,7 @@ static void *world_create(server_startup_st&, test_return_t&) void get_world(Framework *world) { - world->collections= collection; - world->_create= world_create; + world->collections(collection); + world->create(world_create); } diff --git a/tests/memexist.cc b/tests/memexist.cc index 29ad5091..fb69354d 100644 --- a/tests/memexist.cc +++ b/tests/memexist.cc @@ -160,7 +160,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error) void get_world(Framework *world) { - world->collections= collection; - world->_create= world_create; + world->collections(collection); + world->create(world_create); } diff --git a/tests/memflush.cc b/tests/memflush.cc index f14b5b72..80a42453 100644 --- a/tests/memflush.cc +++ b/tests/memflush.cc @@ -113,7 +113,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error) void get_world(Framework *world) { executable= "./clients/memflush"; - world->collections= collection; - world->_create= world_create; + world->collections(collection); + world->create(world_create); } diff --git a/tests/memrm.cc b/tests/memrm.cc index 8d6109c0..29c66337 100644 --- a/tests/memrm.cc +++ b/tests/memrm.cc @@ -163,7 +163,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error) void get_world(Framework *world) { - world->collections= collection; - world->_create= world_create; + world->collections(collection); + world->create(world_create); } diff --git a/tests/memslap.cc b/tests/memslap.cc index 6f990af4..3c5ea250 100644 --- a/tests/memslap.cc +++ b/tests/memslap.cc @@ -186,7 +186,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error) void get_world(Framework *world) { executable= "./clients/memslap"; - world->collections= collection; - world->_create= world_create; + world->collections(collection); + world->create(world_create); } diff --git a/tests/memstat.cc b/tests/memstat.cc index ae8679fb..9b61697d 100644 --- a/tests/memstat.cc +++ b/tests/memstat.cc @@ -124,7 +124,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error) void get_world(Framework *world) { - world->collections= collection; - world->_create= world_create; + world->collections(collection); + world->create(world_create); } diff --git a/tests/memtouch.cc b/tests/memtouch.cc index fa65e8b4..c44e6a08 100644 --- a/tests/memtouch.cc +++ b/tests/memtouch.cc @@ -157,7 +157,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error) void get_world(Framework *world) { executable= "./clients/memtouch"; - world->collections= collection; - world->_create= world_create; + world->collections(collection); + world->create(world_create); } diff --git a/tests/parser.cc b/tests/parser.cc index 740a9c19..70783053 100644 --- a/tests/parser.cc +++ b/tests/parser.cc @@ -126,6 +126,6 @@ collection_st collection[] ={ void get_world(Framework *world) { - world->collections= collection; + world->collections(collection); }