From cc7f3ad60dd92d7e41e0efbf922bb4f6fc9a848f Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Thu, 24 Jan 2013 06:17:17 -0500 Subject: [PATCH] Correct style, use of newer YATL. --- configure.ac | 2 + libtest/alarm.cc | 2 +- libtest/blobslap_worker.cc | 16 +---- libtest/client.cc | 2 +- libtest/cmdline.cc | 19 +++-- libtest/cmdline.h | 12 +--- libtest/collection.cc | 6 +- libtest/collection.h | 4 ++ libtest/comparison.hpp | 2 +- libtest/dns.cc | 1 - libtest/drizzled.cc | 41 ++++------- libtest/fatal.cc | 54 +++++---------- libtest/fatal.hpp | 16 +++-- libtest/framework.cc | 4 +- libtest/framework.h | 6 +- libtest/gearmand.cc | 14 +--- libtest/http.cc | 6 +- libtest/include.am | 15 ++-- libtest/killpid.cc | 2 +- libtest/main.cc | 12 ++-- libtest/memcached.cc | 17 ++--- libtest/port.cc | 8 +-- libtest/result.cc | 111 +++++++++++++----------------- libtest/result.hpp | 18 ++++- libtest/result/base.hpp | 28 +++++--- libtest/result/fail.hpp | 12 +--- libtest/result/fatal.hpp | 19 ++--- libtest/result/skip.hpp | 11 --- libtest/runner.cc | 30 ++++---- libtest/runner.h | 4 ++ libtest/server.cc | 22 +++++- libtest/server.h | 7 +- libtest/server_container.cc | 32 ++++----- libtest/server_container.h | 11 ++- libtest/signal.cc | 5 -- libtest/stream.h | 23 ++++++- libtest/strerror.cc | 2 +- libtest/thread.hpp | 20 +++--- libtest/timer.cc | 83 ++++++++++++++++++++++ libtest/timer.hpp | 95 ++++--------------------- libtest/unittest.cc | 22 +++--- libtest/vchar.cc | 2 +- libtest/wait.h | 3 +- tests/cycle.cc | 6 +- tests/failure.cc | 2 +- tests/libmemcached-1.0/pool.cc | 25 ++----- tests/libmemcached_world.h | 4 +- tests/libmemcached_world_socket.h | 4 +- tests/memcapable.cc | 2 +- tests/memcat.cc | 2 +- tests/memcp.cc | 2 +- tests/memdump.cc | 2 +- tests/memexist.cc | 2 +- tests/memflush.cc | 2 +- tests/memrm.cc | 2 +- tests/memslap.cc | 4 +- tests/memstat.cc | 2 +- tests/memtouch.cc | 2 +- 58 files changed, 416 insertions(+), 468 deletions(-) diff --git a/configure.ac b/configure.ac index 2435c69e..68c9fa10 100644 --- a/configure.ac +++ b/configure.ac @@ -84,6 +84,8 @@ AM_CONDITIONAL([BUILDING_LIBMEMCACHED],[true]) AM_CONDITIONAL([HAVE_LIBMEMCACHED],[false]) AM_CONDITIONAL([HAVE_LIBDRIZZLE],[false]) AC_DEFINE([HAVE_LIBMEMCACHED],[1],[Enables libmemcached Support]) +AC_SUBST([LIBMEMCACHED_CFLAGS]) +AC_SUBST([LIBMEMCACHED_LIB],[libmemcached/libmemcached.la]) AM_CONDITIONAL([BUILDING_GEARMAN],[false]) diff --git a/libtest/alarm.cc b/libtest/alarm.cc index 80d7b2f6..a8bf17e8 100644 --- a/libtest/alarm.cc +++ b/libtest/alarm.cc @@ -68,7 +68,7 @@ void set_alarm(long tv_sec, long tv_usec) if (errno != 0) { - fatal_message("Bad value for YATL_ALARM"); + FATAL("Bad value for YATL_ALARM"); } else if (tv_sec == 0) { diff --git a/libtest/blobslap_worker.cc b/libtest/blobslap_worker.cc index 612847e5..5100a388 100644 --- a/libtest/blobslap_worker.cc +++ b/libtest/blobslap_worker.cc @@ -146,26 +146,14 @@ public: return true; } - bool build(size_t argc, const char *argv[]); + bool build(); }; #include -bool BlobslapWorker::build(size_t argc, const char *argv[]) +bool BlobslapWorker::build() { - std::stringstream arg_buffer; - - for (size_t x= 0 ; x < argc ; x++) - { - if (argv[x] == NULL) - { - break; - } - - add_option(argv[x]); - } - return true; } diff --git a/libtest/client.cc b/libtest/client.cc index f3409cc8..c536e9dd 100644 --- a/libtest/client.cc +++ b/libtest/client.cc @@ -198,7 +198,7 @@ bool SimpleClient::instance_connect() } else { - fatal_message(strerror(errno)); + FATAL(strerror(errno)); } address_info_next= address_info_next->ai_next; } diff --git a/libtest/cmdline.cc b/libtest/cmdline.cc index c8b63eec..df4ae1f3 100644 --- a/libtest/cmdline.cc +++ b/libtest/cmdline.cc @@ -138,7 +138,7 @@ Application::Application(const std::string& arg, const bool _use_libtool_arg) : { if (libtool() == NULL) { - fatal_message("libtool requested, but know libtool was found"); + FATAL("libtool requested, but know libtool was found"); } } @@ -366,15 +366,15 @@ bool Application::slurp() case EFAULT: case ENOMEM: - fatal_message(strerror(error)); + FATAL(strerror(error)); break; case EINVAL: - fatal_message("RLIMIT_NOFILE exceeded, or if OSX the timeout value was invalid"); + FATAL("RLIMIT_NOFILE exceeded, or if OSX the timeout value was invalid"); break; default: - fatal_message(strerror(error)); + FATAL(strerror(error)); break; } @@ -589,18 +589,17 @@ void Application::Pipe::reset() if (pipe(_pipe_fd) == -1) #endif { - fatal_message(strerror(errno)); + FATAL(strerror(errno)); } _open[0]= true; _open[1]= true; #if defined(HAVE_PIPE2) && HAVE_PIPE2 - return; -#endif { nonblock(); cloexec(); } +#endif } void Application::Pipe::cloexec() @@ -656,14 +655,12 @@ void Application::Pipe::dup_for_spawn(posix_spawn_file_actions_t& file_actions) int ret; if ((ret= posix_spawn_file_actions_adddup2(&file_actions, _pipe_fd[type], _std_fd )) < 0) { - Error << "posix_spawn_file_actions_adddup2(" << strerror(ret) << ")"; - fatal_message(strerror(ret)); + FATAL("posix_spawn_file_actions_adddup2(%s)", strerror(ret)); } if ((ret= posix_spawn_file_actions_addclose(&file_actions, _pipe_fd[type])) < 0) { - Error << "posix_spawn_file_actions_adddup2(" << strerror(ret) << ")"; - fatal_message(strerror(ret)); + FATAL("posix_spawn_file_actions_addclose(%s)", strerror(ret)); } } diff --git a/libtest/cmdline.h b/libtest/cmdline.h index d150ff59..8db4804a 100644 --- a/libtest/cmdline.h +++ b/libtest/cmdline.h @@ -36,13 +36,7 @@ #pragma once -#ifdef _WIN32 -typedef int posix_spawn_file_actions_t; -#else -# include -#endif - -#include +#include // http://www.gnu.org/software/automake/manual/automake.html#Using-the-TAP-test-protocol #ifndef EXIT_SKIP @@ -54,11 +48,11 @@ typedef int posix_spawn_file_actions_t; #endif #ifndef EX_NOEXEC -# define EX_NOEXEC 126 +# define EX_NOEXEC 126 #endif #ifndef EX_NOTFOUND -# define EX_NOTFOUND 127 +# define EX_NOTFOUND 127 #endif namespace libtest { diff --git a/libtest/collection.cc b/libtest/collection.cc index 1b4915e1..86e7f864 100644 --- a/libtest/collection.cc +++ b/libtest/collection.cc @@ -55,7 +55,7 @@ static test_return_t runner_code(libtest::Framework* frame, } // Special case where check for the testing of the exception // system. - catch (libtest::fatal &e) + catch (const libtest::fatal& e) { if (libtest::fatal::is_disabled()) { @@ -133,7 +133,7 @@ test_return_t Collection::exec() } libtest::cancel_alarm(); } - catch (libtest::fatal &e) + catch (const libtest::fatal& e) { stream::cerr(e.file(), e.line(), e.func()) << e.what(); _failed++; @@ -159,7 +159,7 @@ test_return_t Collection::exec() break; default: - fatal_message("invalid return code"); + FATAL("invalid return code"); } #if 0 @TODO add code here to allow for a collection to define a method to reset to allow tests to continue. diff --git a/libtest/collection.h b/libtest/collection.h index bc879e30..a9f9cba8 100644 --- a/libtest/collection.h +++ b/libtest/collection.h @@ -103,6 +103,10 @@ private: uint32_t _total; libtest::Timer _timer; libtest::Formatter _formatter; + +private: + Collection( const Collection& ); + const Collection& operator=( const Collection& ); }; } // namespace libtest diff --git a/libtest/comparison.hpp b/libtest/comparison.hpp index dcbcefd8..c67bc33f 100644 --- a/libtest/comparison.hpp +++ b/libtest/comparison.hpp @@ -95,7 +95,7 @@ bool _compare_strcmp(const char *file, int line, const char *func, const T1_comp { if (__expected == NULL) { - fatal_message("Expected value was NULL, programmer error"); + FATAL("Expected value was NULL, programmer error"); } if (__actual == NULL) diff --git a/libtest/dns.cc b/libtest/dns.cc index e8e1e7fc..0becfc99 100644 --- a/libtest/dns.cc +++ b/libtest/dns.cc @@ -61,7 +61,6 @@ bool lookup(const char* host) } int ret; - fprintf(stderr, ":%s:\n", host); if ((ret= getaddrinfo(host, NULL, NULL, &addrinfo)) == 0) { success= true; diff --git a/libtest/drizzled.cc b/libtest/drizzled.cc index 16933c4b..b8068ac8 100644 --- a/libtest/drizzled.cc +++ b/libtest/drizzled.cc @@ -62,7 +62,7 @@ using namespace libtest; #endif #if defined(HAVE_LIBDRIZZLE) && HAVE_LIBDRIZZLE -#include +# include #endif using namespace libtest; @@ -72,31 +72,25 @@ bool ping_drizzled(const in_port_t _port) { (void)(_port); #if defined(HAVE_LIBDRIZZLE) && HAVE_LIBDRIZZLE + if (HAVE_LIBDRIZZLE) { - drizzle_st *drizzle= drizzle_create(NULL); + drizzle_st *drizzle= drizzle_create_tcp(getenv("MYSQL_SERVER"), + getenv("MYSQL_PORT") ? atoi("MYSQL_PORT") : DRIZZLE_DEFAULT_TCP_PORT, + getenv("MYSQL_USER"), + getenv("MYSQL_PASSWORD"), + getenv("MYSQL_SCHEMA"), drizzle_options_t()); if (drizzle == NULL) { return false; } - drizzle_con_st *con; - - if ((con= drizzle_con_create(drizzle, NULL)) == NULL) - { - drizzle_free(drizzle); - return false; - } - - drizzle_con_set_tcp(con, "localhost", _port); - drizzle_con_set_auth(con, "root", 0); - bool success= false; drizzle_return_t rc; - if ((rc= drizzle_con_connect(con)) == DRIZZLE_RETURN_OK) + if ((rc= drizzle_connect(drizzle)) == DRIZZLE_RETURN_OK) { - drizzle_result_st *result= drizzle_ping(con, NULL, &rc); + drizzle_result_st *result= drizzle_ping(drizzle, &rc); success= bool(result); drizzle_result_free(result); } @@ -108,8 +102,7 @@ bool ping_drizzled(const in_port_t _port) Error << drizzle_error(drizzle) << " localhost:" << _port; } - drizzle_con_free(con); - drizzle_free(drizzle); + drizzle_quit(drizzle); return success; } @@ -189,10 +182,10 @@ public: } } - bool build(size_t argc, const char *argv[]); + bool build(); }; -bool Drizzle::build(size_t argc, const char *argv[]) +bool Drizzle::build() { if (getuid() == 0 or geteuid() == 0) { @@ -204,16 +197,6 @@ bool Drizzle::build(size_t argc, const char *argv[]) add_option("--datadir=var/drizzle"); #endif - for (size_t x= 0 ; x < argc ; x++) - { - if (argv[x] == NULL) - { - break; - } - - add_option(argv[x]); - } - return true; } diff --git a/libtest/fatal.cc b/libtest/fatal.cc index 99b15535..0ed06c2c 100644 --- a/libtest/fatal.cc +++ b/libtest/fatal.cc @@ -43,72 +43,45 @@ namespace libtest { #pragma GCC diagnostic ignored "-Wformat-nonliteral" fatal::fatal(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) + __test_result(file_arg, line_arg, func_arg) { 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++; - } + init(args); va_end(args); } fatal::fatal( const fatal& 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; - } -} - -fatal::~fatal() throw() + __test_result(other) { - if ((_error_message_size > 0) and _error_message) - { - free(_error_message); - _error_message= NULL; - } } static bool _disabled= false; static uint32_t _counter= 0; -bool fatal::is_disabled() +bool fatal::is_disabled() throw() { return _disabled; } -void fatal::disable() +void fatal::disable() throw() { _counter= 0; _disabled= true; } -void fatal::enable() +void fatal::enable() throw() { _counter= 0; _disabled= false; } -uint32_t fatal::disabled_counter() +uint32_t fatal::disabled_counter() throw() { return _counter; } -void fatal::increment_disabled_counter() +void fatal::increment_disabled_counter() throw() { _counter++; } @@ -132,4 +105,15 @@ disconnected::disconnected(const char *file_arg, int line_arg, const char *func_ snprintf(_error_message, sizeof(_error_message), "%s:%u %s", instance.c_str(), uint32_t(port), last_error); } +disconnected::disconnected(const disconnected& other): + std::runtime_error(other._func), + _port(other._port), + _line(other._line), + _file(other._file), + _func(other._func) +{ + strncpy(_error_message, other._error_message, BUFSIZ); + strncpy(_instance, other._instance, BUFSIZ); +} + } // namespace libtest diff --git a/libtest/fatal.hpp b/libtest/fatal.hpp index 7e627a46..c679f9b0 100644 --- a/libtest/fatal.hpp +++ b/libtest/fatal.hpp @@ -40,34 +40,36 @@ namespace libtest { -class disconnected : std::runtime_error +class disconnected : public std::runtime_error { public: disconnected(const char *file, int line, const char *func, const std::string&, const in_port_t port, ...); const char* what() const throw() { - return &_error_message[0]; + return _error_message; } + disconnected(const disconnected&); + // The following are just for unittesting the exception class static bool is_disabled(); static void disable(); - + static void enable(); static uint32_t disabled_counter(); static void increment_disabled_counter(); - int line() + int line() const { return _line; } - const char* file() + const char* file() const { return _file; } - const char* func() + const char* func() const { return _func; } @@ -75,7 +77,7 @@ public: private: char _error_message[BUFSIZ]; in_port_t _port; - char _instance[1024]; + char _instance[BUFSIZ]; int _line; const char* _file; const char* _func; diff --git a/libtest/framework.cc b/libtest/framework.cc index 546ccb37..30f511af 100644 --- a/libtest/framework.cc +++ b/libtest/framework.cc @@ -133,12 +133,12 @@ void Framework::exec() break; } } - catch (libtest::fatal& e) + catch (const libtest::fatal& e) { _failed++; stream::cerr(e.file(), e.line(), e.func()) << e.what(); } - catch (libtest::disconnected& e) + catch (const libtest::disconnected& e) { _failed++; Error << "Unhandled disconnection occurred:" << e.what(); diff --git a/libtest/framework.h b/libtest/framework.h index f6dfc94a..7a24466a 100644 --- a/libtest/framework.h +++ b/libtest/framework.h @@ -162,8 +162,6 @@ public: } private: - Framework& operator=(const Framework&); - uint32_t _total; uint32_t _success; uint32_t _skipped; @@ -193,6 +191,10 @@ private: std::string _only_run; std::string _wildcard; std::string _name; + +private: + Framework( const Framework& ); + const Framework& operator=( const Framework& ); }; } // namespace libtest diff --git a/libtest/gearmand.cc b/libtest/gearmand.cc index d9dcf192..852cf194 100644 --- a/libtest/gearmand.cc +++ b/libtest/gearmand.cc @@ -123,7 +123,7 @@ public: return true; } - bool build(size_t argc, const char *argv[]); + bool build(); }; Gearmand::Gearmand(const std::string& host_arg, in_port_t port_arg, bool libtool_, const char* binary_arg) : @@ -132,7 +132,7 @@ Gearmand::Gearmand(const std::string& host_arg, in_port_t port_arg, bool libtool set_pid_file(); } -bool Gearmand::build(size_t argc, const char *argv[]) +bool Gearmand::build() { if (getuid() == 0 or geteuid() == 0) { @@ -141,16 +141,6 @@ bool Gearmand::build(size_t argc, const char *argv[]) add_option("--listen=localhost"); - for (size_t x= 0 ; x < argc ; x++) - { - if (argv[x] == NULL) - { - break; - } - - add_option(argv[x]); - } - return true; } diff --git a/libtest/http.cc b/libtest/http.cc index 917e668f..621c714c 100644 --- a/libtest/http.cc +++ b/libtest/http.cc @@ -57,13 +57,13 @@ static void initialize_curl_startup() #if defined(HAVE_LIBCURL) && HAVE_LIBCURL if (curl_global_init(CURL_GLOBAL_ALL)) { - fatal_message("curl_global_init(CURL_GLOBAL_ALL) failed"); + FATAL("curl_global_init(CURL_GLOBAL_ALL) failed"); } #endif if (atexit(cleanup_curl)) { - fatal_message("atexit() failed"); + FATAL("atexit() failed"); } } @@ -73,7 +73,7 @@ static void initialize_curl(void) int ret; if ((ret= pthread_once(&start_key_once, initialize_curl_startup)) != 0) { - fatal_message(strerror(ret)); + FATAL(strerror(ret)); } } diff --git a/libtest/include.am b/libtest/include.am index 90641783..14a95472 100644 --- a/libtest/include.am +++ b/libtest/include.am @@ -13,6 +13,7 @@ MASSIF_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=massif GDB_COMMAND= $(LIBTOOL_COMMAND) gdb -f -x libtest/run.gdb PTRCHECK_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=exp-ptrcheck --error-exitcode=1 PAHOLE_COMMAND= $(LIBTOOL_COMMAND) --mode=execute pahole +VALGRIND_SUPRESSION= $(LIBTOOL_COMMAND) valgrind --leak-check=full --show-reachable=yes --error-limit=no --gen-suppressions=all --log-file=minimalraw.log export LIBTOOL_COMMAND export VALGRIND_COMMAND @@ -23,6 +24,9 @@ export GDB_COMMAND valgrind: @echo make check TESTS_ENVIRONMENT="\"$(VALGRIND_EXEC_COMMAND)\"" +valgrind-supressions: + @echo make check TESTS_ENVIRONMENT="\"$(VALGRIND_SUPRESSION)\"" + gdb: @echo make check TESTS_ENVIRONMENT="\"$(GDB_COMMAND)\"" @@ -104,6 +108,8 @@ libtest_libtest_la_CXXFLAGS= EXTRA_libtest_libtest_la_DEPENDENCIES= libtest_libtest_la_LIBADD= libtest_libtest_la_SOURCES= +libtest_libtest_la_CXXFLAGS+= @LIBMEMCACHED_CFLAGS@ +libtest_libtest_la_LIBADD+= @LIBMEMCACHED_LIB@ libtest_libtest_la_SOURCES+= libtest/alarm.cc libtest_libtest_la_SOURCES+= libtest/binaries.cc @@ -153,16 +159,13 @@ EXTRA_libtest_libtest_la_DEPENDENCIES+=libtest/wait # Declare unittest so that we can append to it libtest_unittest_CXXFLAGS= libtest_unittest_LDADD= +libtest_libtest_la_LDFLAGS= # We are either building in tree, or with libtest_libtest_la_SOURCES+= libtest/memcached.cc -if HAVE_LIBDRIZZLE - -libtest_libtest_la_LIBADD+= $(libdrizzle_LIBS) -libtest_libtest_la_CXXFLAGS+= $(libdrizzle_CFLAGS) - -endif +libtest_libtest_la_LDFLAGS+= @LIBDRIZZLE_LDFLAGS@ +libtest_libtest_la_LIBADD+= @LIBDRIZZLE_LIB@ libtest_libtest_la_SOURCES+= libtest/gearmand.cc diff --git a/libtest/killpid.cc b/libtest/killpid.cc index 7f5630ba..2cefff2c 100644 --- a/libtest/killpid.cc +++ b/libtest/killpid.cc @@ -86,7 +86,7 @@ bool kill_pid(pid_t pid_arg) uint32_t waited; uint32_t retry; - for (waited= 0, retry= 4; ; retry++, waited+= this_wait) + for (waited= 0, retry= 1; ; retry++, waited+= this_wait) { int status= 0; if (waitpid(pid_arg, &status, WNOHANG) == 0) diff --git a/libtest/main.cc b/libtest/main.cc index 588512d1..fe8938b9 100644 --- a/libtest/main.cc +++ b/libtest/main.cc @@ -299,7 +299,7 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } } - catch (libtest::__skipped e) + catch (const libtest::__skipped& e) { return EXIT_SKIP; } @@ -345,26 +345,26 @@ int main(int argc, char *argv[]) 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) + catch (const libtest::__skipped& e) { return EXIT_SKIP; } - catch (libtest::__failure e) + catch (const libtest::__failure& e) { libtest::stream::make_cout(e.file(), e.line(), e.func()) << e.what(); exit_code= EXIT_FAILURE; } - catch (libtest::fatal& e) + catch (const libtest::fatal& e) { std::cerr << "FATAL:" << e.what() << std::endl; exit_code= EXIT_FAILURE; } - catch (libtest::disconnected& e) + catch (const libtest::disconnected& e) { std::cerr << "Unhandled disconnection occurred:" << e.what() << std::endl; exit_code= EXIT_FAILURE; } - catch (std::exception& e) + catch (const std::exception& e) { std::cerr << "std::exception:" << e.what() << std::endl; exit_code= EXIT_FAILURE; diff --git a/libtest/memcached.cc b/libtest/memcached.cc index 2c150f90..24bc3b8d 100644 --- a/libtest/memcached.cc +++ b/libtest/memcached.cc @@ -188,13 +188,13 @@ public: return true; } - bool build(size_t argc, const char *argv[]); + bool build(); }; #include -bool Memcached::build(size_t argc, const char *argv[]) +bool Memcached::build() { if (getuid() == 0 or geteuid() == 0) { @@ -202,7 +202,8 @@ bool Memcached::build(size_t argc, const char *argv[]) } add_option("-l", "localhost"); -#ifndef TARGET_OS_OSX +#ifdef __APPLE__ +#else add_option("-m", "128"); add_option("-M"); #endif @@ -212,16 +213,6 @@ bool Memcached::build(size_t argc, const char *argv[]) add_option(sasl()); } - for (size_t x= 0 ; x < argc ; x++) - { - if (argv[x] == NULL) - { - break; - } - - add_option(argv[x]); - } - return true; } diff --git a/libtest/port.cc b/libtest/port.cc index 1d3f4e5f..d8e8c12d 100644 --- a/libtest/port.cc +++ b/libtest/port.cc @@ -204,22 +204,22 @@ in_port_t get_free_port() // We handle the case where if we max out retries, we still abort. if (retries == 0) { - fatal_message("No port could be found, exhausted retry"); + FATAL("No port could be found, exhausted retry"); } if (ret_port == 0) { - fatal_message("No port could be found"); + FATAL("No port could be found"); } if (ret_port == default_port) { - fatal_message("No port could be found"); + FATAL("No port could be found"); } if (ret_port <= 1024) { - fatal_message("No port could be found, though some where available below or at 1024"); + FATAL("No port could be found, though some where available below or at 1024"); } all_socket_fd.last_port= ret_port; diff --git a/libtest/result.cc b/libtest/result.cc index ae37e8d2..9a1c8fba 100644 --- a/libtest/result.cc +++ b/libtest/result.cc @@ -2,7 +2,7 @@ * * Data Differential YATL (i.e. libtest) library * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ + * Copyright (C) 2012-2013 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 @@ -38,104 +38,87 @@ #include #include -#ifndef __INTEL_COMPILER -# pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif - 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) + _func(func_arg), + _error_message(NULL), + _error_message_size(0) { } -__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) +#ifndef __INTEL_COMPILER +# pragma GCC diagnostic ignored "-Wformat-nonliteral" +#endif +void __test_result::init(va_list args_) { - va_list args; - va_start(args, func_arg); - const char *format= va_arg(args, const char *); - _error_message_size= vasprintf(&_error_message, format, args); + 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), +__test_result::~__test_result() throw() +{ + free(_error_message); +} + +__test_result::__test_result(const __test_result& other) : + _line(other._line), + _file(other._file), + _func(other._func), _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 + if (_error_message_size > 0) { - _error_message_size= -1; + _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() +__success::__success(const char *file_arg, int line_arg, const char *func_arg): + __test_result(file_arg, line_arg, func_arg) { - 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, ...) : - __test_result(file_arg, line_arg, func_arg), - _error_message(NULL), - _error_message_size(0) +__skipped::__skipped(const char *file_arg, int line_arg, const char *func_arg, ...): + __test_result(file_arg, line_arg, func_arg) { 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++; - } + init(args); va_end(args); } -__failure::__failure( const __failure& other ) : - __test_result(other), - _error_message_size(other._error_message_size) +__skipped::__skipped(const __skipped& other) : + __test_result(other) { - _error_message= (char*) malloc(_error_message_size); - if (_error_message) - { - memcpy(_error_message, other._error_message, _error_message_size); - } - else - { - _error_message_size= -1; - } } -__failure::~__failure() throw() +__failure::__failure(const char *file_arg, int line_arg, const char *func_arg, ...) : + __test_result(file_arg, line_arg, func_arg) +{ + va_list args; + va_start(args, func_arg); + init(args); + va_end(args); +} + +__failure::__failure(const __failure& other) : + __test_result(other) { - if ((_error_message_size > 0) and _error_message) - { - free(_error_message); - _error_message= NULL; - } } diff --git a/libtest/result.hpp b/libtest/result.hpp index a5592640..0c78b998 100644 --- a/libtest/result.hpp +++ b/libtest/result.hpp @@ -57,10 +57,26 @@ do \ throw libtest::__failure(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \ } while (0) -#define fatal_message(...) \ +#define FATAL(...) \ do \ { \ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \ } while (0) +#define FATAL_IF(__expression, ...) \ +do \ +{ \ + if ((__expression)) { \ + throw libtest::fatal(LIBYATL_DEFAULT_PARAM, (#__expression)); \ + } \ +} while (0) + +#define FATAL_IF_(__expression, ...) \ +do \ +{ \ + if ((__expression)) { \ + throw libtest::fatal(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \ + } \ +} while (0) + #define fatal_assert(__assert) if((__assert)) {} else { throw libtest::fatal(LIBYATL_DEFAULT_PARAM, #__assert); } diff --git a/libtest/result/base.hpp b/libtest/result/base.hpp index 1859c22a..51ee995d 100644 --- a/libtest/result/base.hpp +++ b/libtest/result/base.hpp @@ -2,7 +2,7 @@ * * Data Differential YATL (i.e. libtest) library * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ + * Copyright (C) 2012-2013 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 @@ -43,32 +43,44 @@ class __test_result : public std::exception public: __test_result(const char *file, int line, const char *func); - __test_result( const __test_result& other ) : - _line(other._line), - _file(other._file), - _func(other._func) + __test_result( const __test_result& ); + + virtual ~__test_result() throw(); + + virtual const char* what() const throw() { + if (_error_message) + { + return _error_message; + } + + return ""; } - int line() + int line() const { return _line; } - const char* file() + const char* file() const { return _file; } - const char* func() + const char* func() const { return _func; } +protected: + void init(va_list); + private: int _line; const char* _file; const char* _func; + char* _error_message; + int _error_message_size; }; } // namespace libtest diff --git a/libtest/result/fail.hpp b/libtest/result/fail.hpp index dae4a08b..fd8766a9 100644 --- a/libtest/result/fail.hpp +++ b/libtest/result/fail.hpp @@ -43,19 +43,9 @@ class __failure : public __test_result public: __failure(const char *file, int line, const char *func, ...); - __failure(const __failure& other); - - ~__failure() throw(); - - const char* what() const throw() - { - return _error_message; - } + __failure(const __failure&); private: - char* _error_message; - int _error_message_size; }; } // namespace libtest - diff --git a/libtest/result/fatal.hpp b/libtest/result/fatal.hpp index deebb358..8e6d1346 100644 --- a/libtest/result/fatal.hpp +++ b/libtest/result/fatal.hpp @@ -45,23 +45,14 @@ public: fatal(const fatal&); - ~fatal() throw(); - - const char* what() const throw() - { - return &_error_message[0]; - } - // The following are just for unittesting the exception class - static bool is_disabled(); - static void disable(); - static void enable(); - static uint32_t disabled_counter(); - static void increment_disabled_counter(); + static bool is_disabled() throw(); + static void disable() throw(); + static void enable() throw(); + static uint32_t disabled_counter() throw(); + static void increment_disabled_counter() throw(); private: - char* _error_message; - int _error_message_size; }; } // namespace libtest diff --git a/libtest/result/skip.hpp b/libtest/result/skip.hpp index 663044fe..d0226e9f 100644 --- a/libtest/result/skip.hpp +++ b/libtest/result/skip.hpp @@ -44,17 +44,6 @@ public: __skipped(const char *file, int line, const char *func, ...); __skipped(const __skipped&); - - ~__skipped() throw(); - - const char* what() const throw() - { - return &_error_message[0]; - } - -private: - char* _error_message; - int _error_message_size; }; } // namespace libtest diff --git a/libtest/runner.cc b/libtest/runner.cc index fdabb7c6..2f94ad37 100644 --- a/libtest/runner.cc +++ b/libtest/runner.cc @@ -50,24 +50,24 @@ test_return_t Runner::main(test_callback_fn* func, void *object) try { ret= run(func, object); } - catch (libtest::__skipped e) + catch (const libtest::__skipped& e) { ret= TEST_SKIPPED; } - catch (libtest::__failure e) + catch (const libtest::__failure& e) { libtest::stream::make_cerr(e.file(), e.line(), e.func()) << e.what(); ret= TEST_FAILURE; } - catch (libtest::__success) + catch (const libtest::__success&) { ret= TEST_SUCCESS; } - catch (libtest::fatal& e) + catch (const libtest::fatal&) { throw; } - catch (std::exception& e) + catch (const std::exception& e) { libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what(); throw; @@ -87,24 +87,24 @@ test_return_t Runner::setup(test_callback_fn* func, void *object) try { ret= pre(func, object); } - catch (libtest::__skipped e) + catch (const libtest::__skipped& e) { ret= TEST_SKIPPED; } - catch (libtest::__failure e) + catch (const libtest::__failure& e) { libtest::stream::make_cout(e.file(), e.line(), e.func()) << e.what(); ret= TEST_FAILURE; } - catch (libtest::__success) + catch (const libtest::__success&) { ret= TEST_SUCCESS; } - catch (libtest::fatal& e) + catch (const libtest::fatal& e) { throw; } - catch (std::exception& e) + catch (const std::exception& e) { libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what(); throw; @@ -124,24 +124,24 @@ test_return_t Runner::teardown(test_callback_fn* func, void *object) try { ret= post(func, object); } - catch (libtest::__skipped e) + catch (const libtest::__skipped& e) { ret= TEST_SKIPPED; } - catch (libtest::__failure e) + catch (const libtest::__failure& e) { libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what(); ret= TEST_FAILURE; } - catch (libtest::__success) + catch (const libtest::__success&) { ret= TEST_SUCCESS; } - catch (libtest::fatal& e) + catch (const libtest::fatal& e) { throw; } - catch (std::exception& e) + catch (const std::exception& e) { libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what(); throw; diff --git a/libtest/runner.h b/libtest/runner.h index d90b70e4..627a0a8e 100644 --- a/libtest/runner.h +++ b/libtest/runner.h @@ -64,6 +64,10 @@ public: private: libtest::server_startup_st* _servers; + +private: + Runner( const Runner& ); + const Runner& operator=( const Runner& ); }; } // namespace Runner diff --git a/libtest/server.cc b/libtest/server.cc index 522120be..d024d054 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -124,7 +124,7 @@ Server::Server(const std::string& host_arg, const in_port_t port_arg, Server::~Server() { - murder(); + kill(); } bool Server::check() @@ -148,7 +148,7 @@ bool Server::cycle() while (--limit and is_pid_valid(_app.pid())) { - if (murder()) + if (kill()) { Log << "Killed existing server," << *this; dream(0, 50000); @@ -173,6 +173,22 @@ bool Server::wait_for_pidfile() const return wait.successful(); } +bool Server::init(const char *argv[]) +{ + if (argv) + { + for (const char **ptr= argv; *ptr ; ++ptr) + { + if (ptr) + { + add_option(*ptr); + } + } + } + + return build(); +} + bool Server::has_pid() const { return (_app.pid() > 1); @@ -498,7 +514,7 @@ bool Server::args(Application& app) return true; } -bool Server::murder() +bool Server::kill() { if (check_pid(_app.pid())) // If we kill it, reset { diff --git a/libtest/server.h b/libtest/server.h index 5b26fcdd..bbebe957 100644 --- a/libtest/server.h +++ b/libtest/server.h @@ -41,10 +41,8 @@ #include #include #include - #include #include - #include #include #include @@ -179,7 +177,8 @@ public: virtual bool ping()= 0; - virtual bool build(size_t argc, const char *argv[])= 0; + bool init(const char *argv[]); + virtual bool build()= 0; void add_option(const std::string&); void add_option(const std::string&, const std::string&); @@ -251,7 +250,7 @@ public: std::string log_and_pid(); - bool murder(); + bool kill(); bool start(); bool command(libtest::Application& app); diff --git a/libtest/server_container.cc b/libtest/server_container.cc index cc1e0a56..3a5a7a0e 100644 --- a/libtest/server_container.cc +++ b/libtest/server_container.cc @@ -103,7 +103,7 @@ bool server_startup_st::shutdown(uint32_t host_to_shutdown) { Server* tmp= servers[host_to_shutdown]; - if (tmp and tmp->murder() == false) + if (tmp and tmp->kill() == false) { } else { @@ -139,7 +139,7 @@ bool server_startup_st::shutdown() bool success= true; for (std::vector::iterator iter= servers.begin(); iter != servers.end(); ++iter) { - if ((*iter)->has_pid() and (*iter)->murder() == false) + if ((*iter)->has_pid() and (*iter)->kill() == false) { Error << "Unable to kill:" << *(*iter); success= false; @@ -176,9 +176,9 @@ bool server_startup_st::validate() return _magic == MAGIC_MEMORY; } -bool server_startup(server_startup_st& construct, const std::string& server_type, in_port_t try_port, int argc, const char *argv[], const bool opt_startup_message) +bool server_startup(server_startup_st& construct, const std::string& server_type, in_port_t try_port, const char *argv[]) { - return construct.start_server(server_type, try_port, argc, argv, opt_startup_message); + return construct.start_server(server_type, try_port, argv); } libtest::Server* server_startup_st::create(const std::string& server_type, in_port_t try_port, const bool is_socket) @@ -288,8 +288,7 @@ private: 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) + const char *argv[]) { try { ServerPtr server(create(server_type, try_port, is_socket)); @@ -309,7 +308,7 @@ bool server_startup_st::_start_server(const bool is_socket, return false; } - server->build(argc, argv); + server->init(argv); #if 0 if (false) @@ -327,7 +326,6 @@ bool server_startup_st::_start_server(const bool is_socket, } else { - if (opt_startup_message) { #if defined(DEBUG) if (DEBUG) @@ -347,7 +345,7 @@ bool server_startup_st::_start_server(const bool is_socket, set_default_socket(server->socket().c_str()); } } - catch (libtest::disconnected& err) + catch (const libtest::disconnected& err) { if (fatal::is_disabled() == false and try_port != LIBTEST_FAIL_PORT) { @@ -355,12 +353,12 @@ bool server_startup_st::_start_server(const bool is_socket, return false; } } - catch (libtest::__test_result& err) + catch (const libtest::__test_result& err) { stream::cerr(err.file(), err.line(), err.func()) << err.what(); return false; } - catch (std::exception& err) + catch (const std::exception& err) { Error << err.what(); return false; @@ -374,18 +372,14 @@ bool server_startup_st::_start_server(const bool is_socket, return true; } -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) +bool server_startup_st::start_server(const std::string& server_type, in_port_t try_port, const char *argv[]) { - return _start_server(false, server_type, try_port, argc, argv, opt_startup_message); + return _start_server(false, server_type, try_port, argv); } -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) +bool server_startup_st::start_socket_server(const std::string& server_type, const in_port_t try_port, const char *argv[]) { - return _start_server(true, server_type, try_port, argc, argv, opt_startup_message); + return _start_server(true, server_type, try_port, argv); } std::string server_startup_st::option_string() const diff --git a/libtest/server_container.h b/libtest/server_container.h index 48d90901..88e4763d 100644 --- a/libtest/server_container.h +++ b/libtest/server_container.h @@ -39,10 +39,8 @@ #include #include #include - #include #include - #include #include #include @@ -69,8 +67,8 @@ public: bool validate(); - bool start_socket_server(const std::string& server_type, const in_port_t try_port, int argc, const char *argv[], const bool opt_startup_message= true); - bool start_server(const std::string& server_type, const in_port_t try_port, int argc, const char *argv[], const bool opt_startup_message= true); + bool start_socket_server(const std::string& server_type, const in_port_t try_port, const char *argv[]); + bool start_server(const std::string& server_type, const in_port_t try_port, const char *argv[]); uint32_t count() const { @@ -142,13 +140,12 @@ 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); + const char *argv[]); private: unsigned long int _servers_to_run; }; -bool server_startup(server_startup_st&, const std::string&, in_port_t try_port, int argc, const char *argv[], const bool opt_startup_message= true); +bool server_startup(server_startup_st&, const std::string&, in_port_t try_port, const char *argv[]); } // namespace libtest diff --git a/libtest/signal.cc b/libtest/signal.cc index 165915f5..51f42a4e 100644 --- a/libtest/signal.cc +++ b/libtest/signal.cc @@ -209,11 +209,6 @@ SignalThread::SignalThread() : sigaddset(&set, SIGINT); sigaddset(&set, SIGVTALRM); } - else - { - Out << "Inside of GDB, disabling signal handlers"; - } - sigaddset(&set, SIGPIPE); sigaddset(&set, SIGUSR2); diff --git a/libtest/stream.h b/libtest/stream.h index dea371b9..081c2bf0 100644 --- a/libtest/stream.h +++ b/libtest/stream.h @@ -130,7 +130,7 @@ template