From: Brian Aker Date: Fri, 4 Jan 2013 01:24:50 +0000 (-0500) Subject: Update of YATL. X-Git-Tag: 1.0.16~17^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=381d409b224ca3b4510e770a98bc960084cdf2c4;p=awesomized%2Flibmemcached Update of YATL. --- diff --git a/libtest/client.cc b/libtest/client.cc index c4d2df37..f3409cc8 100644 --- a/libtest/client.cc +++ b/libtest/client.cc @@ -176,6 +176,22 @@ bool SimpleClient::instance_connect() { 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); } diff --git a/libtest/cmdline.cc b/libtest/cmdline.cc index 3a61e4cf..60d2b1a4 100644 --- a/libtest/cmdline.cc +++ b/libtest/cmdline.cc @@ -687,8 +687,8 @@ void Application::create_argv(const char *args[]) 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) @@ -696,54 +696,54 @@ void Application::create_argv(const char *args[]) /* 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()); } } @@ -751,7 +751,7 @@ void Application::create_argv(const char *args[]) { for (const char **ptr= args; *ptr; ++ptr) { - built_argv.push_back(strdup(*ptr)); + vchar::append(built_argv, *ptr); } } built_argv.push_back(NULL); @@ -766,7 +766,7 @@ std::string Application::arguments() { 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) { @@ -776,21 +776,9 @@ std::string Application::arguments() return arg_buffer.str(); } -struct DeleteFromVector -{ - template - 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; diff --git a/libtest/cmdline.h b/libtest/cmdline.h index 460a520c..2f639116 100644 --- a/libtest/cmdline.h +++ b/libtest/cmdline.h @@ -207,6 +207,7 @@ public: private: void create_argv(const char *args[]); void delete_argv(); + void add_to_build_argv(const char*); private: const bool _use_libtool; diff --git a/libtest/common.h b/libtest/common.h index 6c7e294c..7be0221c 100644 --- a/libtest/common.h +++ b/libtest/common.h @@ -97,3 +97,25 @@ #include #include +struct FreeFromVector +{ + template + void operator() ( T* ptr) const + { + if (ptr) + { + free(ptr); + ptr= NULL; + } + } +}; + +struct DeleteFromVector +{ + template + void operator() ( T* ptr) const + { + delete ptr; + ptr= NULL; + } +}; diff --git a/libtest/formatter.cc b/libtest/formatter.cc index 6d4f1a33..01c57609 100644 --- a/libtest/formatter.cc +++ b/libtest/formatter.cc @@ -38,8 +38,9 @@ #include -#include +#include #include +#include namespace libtest { @@ -97,10 +98,8 @@ Formatter::Formatter(const std::string& frame_name, const std::string& arg) 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() diff --git a/libtest/framework.cc b/libtest/framework.cc index f8bc78c9..546ccb37 100644 --- a/libtest/framework.cc +++ b/libtest/framework.cc @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -86,12 +87,8 @@ Framework::~Framework() delete _runner; - for (std::vector::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) diff --git a/libtest/gearmand.cc b/libtest/gearmand.cc index 66ab7bdc..337fb725 100644 --- a/libtest/gearmand.cc +++ b/libtest/gearmand.cc @@ -39,10 +39,6 @@ #include -#include "util/instance.hpp" -#include "util/operation.hpp" - -using namespace datadifferential; using namespace libtest; #include @@ -159,8 +155,13 @@ libtest::Server *build_gearmand(const char *hostname, in_port_t try_port, const { 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 } diff --git a/libtest/include.am b/libtest/include.am index b303e2e8..90641783 100644 --- a/libtest/include.am +++ b/libtest/include.am @@ -164,20 +164,10 @@ libtest_libtest_la_CXXFLAGS+= $(libdrizzle_CFLAGS) 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 diff --git a/libtest/lite.h b/libtest/lite.h index 56ea4c17..aad47cf3 100644 --- a/libtest/lite.h +++ b/libtest/lite.h @@ -67,6 +67,10 @@ # 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")) @@ -114,7 +118,10 @@ static inline int yatl_strcmp(const char *s1, const char *s2, size_t *s1_length, 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) @@ -149,10 +156,9 @@ do \ 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) @@ -172,10 +178,9 @@ do \ 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) @@ -186,10 +191,12 @@ do \ 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) @@ -200,10 +207,9 @@ do \ 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) @@ -223,10 +229,9 @@ do \ 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) @@ -254,13 +259,12 @@ do \ 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) @@ -288,13 +292,12 @@ do \ 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) @@ -314,10 +317,9 @@ do \ 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) diff --git a/libtest/main.cc b/libtest/main.cc index 6231ba12..588512d1 100644 --- a/libtest/main.cc +++ b/libtest/main.cc @@ -132,7 +132,7 @@ int main(int argc, char *argv[]) { { "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 }, @@ -284,6 +284,7 @@ int main(int argc, char *argv[]) std::auto_ptr frame(new libtest::Framework(signal, binary_name, collection_to_run, wildcard)); // Run create(), bail on error. + try { switch (frame->create()) { @@ -298,6 +299,10 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } } + catch (libtest::__skipped e) + { + return EXIT_SKIP; + } frame->exec(); @@ -340,6 +345,15 @@ 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) + { + 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; diff --git a/libtest/port.cc b/libtest/port.cc index b955ca4b..1d3f4e5f 100644 --- a/libtest/port.cc +++ b/libtest/port.cc @@ -142,10 +142,10 @@ in_port_t get_free_port() { 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; @@ -156,7 +156,7 @@ in_port_t get_free_port() 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); diff --git a/libtest/result.cc b/libtest/result.cc index 2bc83171..1cf615b1 100644 --- a/libtest/result.cc +++ b/libtest/result.cc @@ -52,9 +52,45 @@ __success::__success(const char *file_arg, int line_arg, const char *func_arg): { } -__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, ...) : diff --git a/libtest/result.hpp b/libtest/result.hpp index 9e6bf209..a5592640 100644 --- a/libtest/result.hpp +++ b/libtest/result.hpp @@ -44,7 +44,12 @@ #include #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 \ diff --git a/libtest/result/skip.hpp b/libtest/result/skip.hpp index 41df316f..663044fe 100644 --- a/libtest/result/skip.hpp +++ b/libtest/result/skip.hpp @@ -41,14 +41,20 @@ namespace libtest { 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 diff --git a/libtest/runner.cc b/libtest/runner.cc index 456af7d1..059e9843 100644 --- a/libtest/runner.cc +++ b/libtest/runner.cc @@ -56,7 +56,7 @@ test_return_t Runner::run(test_callback_fn* func, void *object) try { return func(object); } - catch (libtest::__skipped) + catch (libtest::__skipped e) { return TEST_SKIPPED; } @@ -81,13 +81,13 @@ test_return_t Runner::pre(test_callback_fn* func, void *object) 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) @@ -106,7 +106,7 @@ test_return_t Runner::post(test_callback_fn* func, void *object) try { return func(object); } - catch (libtest::__skipped) + catch (libtest::__skipped e) { return TEST_SKIPPED; } diff --git a/libtest/server.cc b/libtest/server.cc index 02aeec70..044772f5 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -98,7 +98,7 @@ class Buffer { public: Buffer(char *b) : b_(b) {} - ~Buffer() { free(b_); } + ~Buffer() { if (b_) free(b_); } char* buf() { return b_; } private: char *b_; diff --git a/libtest/server_container.cc b/libtest/server_container.cc index e9b2f4e0..513e472c 100644 --- a/libtest/server_container.cc +++ b/libtest/server_container.cc @@ -38,7 +38,6 @@ #include "libtest/common.h" -#include #include #include #include @@ -88,7 +87,6 @@ void server_startup_st::push_server(Server *arg) } server_list+= server_config_string; - } Server* server_startup_st::pop_server() @@ -118,10 +116,7 @@ bool server_startup_st::shutdown(uint32_t host_to_shutdown) void server_startup_st::clear() { - for (std::vector::iterator iter= servers.begin(); iter != servers.end(); ++iter) - { - delete *iter; - } + std::for_each(servers.begin(), servers.end(), DeleteFromVector()); servers.clear(); } @@ -167,7 +162,6 @@ server_startup_st::server_startup_st() : _magic(MAGIC_MEMORY), _socket(false), _sasl(false), - _count(0), udp(0), _servers_to_run(5) { } @@ -187,80 +181,131 @@ bool server_startup(server_startup_st& construct, const std::string& server_type 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; } @@ -278,7 +323,6 @@ bool server_startup_st::start_server(const std::string& server_type, in_port_t t if (server->start() == false) { - delete server; return false; } else @@ -295,121 +339,53 @@ bool server_startup_st::start_server(const std::string& server_type, in_port_t t #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 diff --git a/libtest/server_container.h b/libtest/server_container.h index b8743033..9e083365 100644 --- a/libtest/server_container.h +++ b/libtest/server_container.h @@ -54,7 +54,6 @@ private: std::string server_list; bool _socket; bool _sasl; - uint32_t _count; std::string _username; std::string _password; @@ -125,6 +124,8 @@ public: 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; @@ -135,6 +136,13 @@ public: _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; }; diff --git a/libtest/stream.h b/libtest/stream.h index 5d86be3e..dea371b9 100644 --- a/libtest/stream.h +++ b/libtest/stream.h @@ -171,6 +171,14 @@ public: { } }; +class make_cout : public detail::log { +public: + make_cout(const char* filename, int line_number, const char* func) : + detail::log(std::cout, filename, line_number, func) + { } + +}; + class cout : public detail::log { public: cout(const char* filename, int line_number, const char* func) : diff --git a/libtest/test.hpp b/libtest/test.hpp index 1722c4dc..7c18d6bc 100644 --- a/libtest/test.hpp +++ b/libtest/test.hpp @@ -40,8 +40,12 @@ #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 diff --git a/libtest/unittest.cc b/libtest/unittest.cc index e35911bf..b3e90c79 100644 --- a/libtest/unittest.cc +++ b/libtest/unittest.cc @@ -123,20 +123,41 @@ static test_return_t test_throw_success_TEST(void *) 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; } @@ -200,7 +221,7 @@ static test_return_t test_failure_test(void *) { return TEST_SKIPPED; // Only run this when debugging - test_compare(1, 2); + ASSERT_EQ(1, 2); return TEST_SUCCESS; } @@ -232,20 +253,20 @@ static test_return_t local_not_test(void *) // 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; @@ -253,31 +274,31 @@ static test_return_t local_not_test(void *) 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; } @@ -339,7 +360,7 @@ static test_return_t var_drizzle_rm_test(void *) 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; } @@ -348,7 +369,7 @@ static test_return_t _compare_memcached_return_t_test(void *) { 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; @@ -358,7 +379,7 @@ static test_return_t _compare_gearman_return_t_test(void *) { 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; @@ -400,18 +421,18 @@ static test_return_t skip_shim(bool a, bool b) 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; } @@ -421,7 +442,7 @@ static test_return_t server_startup_fail_TEST(void *object) 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; @@ -432,19 +453,19 @@ static test_return_t server_startup_TEST(void *object) 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; @@ -488,8 +509,8 @@ static test_return_t application_true_BINARY(void *) 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; } @@ -502,8 +523,8 @@ static test_return_t application_gdb_true_BINARY2(void *) 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; } @@ -517,8 +538,8 @@ static test_return_t application_gdb_true_BINARY(void *) 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; } @@ -529,8 +550,8 @@ static test_return_t application_true_fubar_BINARY(void *) 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; @@ -545,12 +566,12 @@ static test_return_t application_doesnotexist_BINARY(void *) 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()); @@ -562,7 +583,7 @@ static test_return_t GET_TEST(void *) { libtest::http::GET get("http://foo.example.com/"); - test_compare(false, get.execute()); + ASSERT_EQ(false, get.execute()); return TEST_SUCCESS; } @@ -572,7 +593,7 @@ static test_return_t POST_TEST(void *) 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; } @@ -582,7 +603,7 @@ static test_return_t TRACE_TEST(void *) 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; } @@ -592,7 +613,7 @@ static test_return_t vchar_t_TEST(void *) { libtest::vchar_t response; libtest::make_vector(response, test_literal_param("fubar\n")); - test_compare(response, response); + ASSERT_EQ(response, response); return TEST_SUCCESS; } @@ -616,13 +637,13 @@ static test_return_t application_echo_fubar_BINARY(void *) 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; @@ -637,12 +658,12 @@ static test_return_t application_echo_fubar_BINARY2(void *) 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; @@ -651,7 +672,7 @@ static test_return_t application_echo_fubar_BINARY2(void *) 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; } @@ -660,7 +681,7 @@ static test_return_t core_count_BINARY(void *) { 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; } @@ -669,7 +690,7 @@ static test_return_t wait_BINARY(void *) { 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; } @@ -678,7 +699,7 @@ static test_return_t wait_help_BINARY(void *) { 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; } @@ -687,7 +708,7 @@ static test_return_t wait_version_BINARY(void *) { 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; } @@ -698,7 +719,7 @@ static test_return_t wait_services_BINARY(void *) 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; } @@ -709,7 +730,7 @@ static test_return_t wait_services_BINARY2(void *) 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; } @@ -724,8 +745,8 @@ static test_return_t wait_services_appliction_TEST(void *) 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; } @@ -745,8 +766,8 @@ static test_return_t gdb_wait_services_appliction_TEST(void *) 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; } @@ -764,17 +785,17 @@ static test_return_t gdb_abort_services_appliction_TEST(void *) 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; } @@ -791,7 +812,7 @@ static test_return_t get_free_port_TEST(void *) 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; @@ -821,7 +842,7 @@ static test_return_t Timer_TEST(void *) check.reset(); check.offset(minutes, 2, 200); - test_compare(check.minutes(), minutes); + ASSERT_EQ(check.minutes(), minutes); return TEST_SUCCESS; } @@ -847,23 +868,23 @@ static test_return_t create_tmpfile_TEST(void *) { 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; @@ -872,8 +893,8 @@ static test_return_t fatal_message_TEST(void *) 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; } @@ -979,7 +1000,8 @@ test_st tests_log[] ={ {"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 }, diff --git a/libtest/vchar.cc b/libtest/vchar.cc index 81c03453..68646083 100644 --- a/libtest/vchar.cc +++ b/libtest/vchar.cc @@ -88,6 +88,19 @@ void make(libtest::vchar_t& arg, size_t length) } } +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) diff --git a/libtest/vchar.hpp b/libtest/vchar.hpp index 17f98efc..737b6df1 100644 --- a/libtest/vchar.hpp +++ b/libtest/vchar.hpp @@ -54,6 +54,7 @@ namespace vchar { 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