From: Brian Aker Date: Tue, 1 Jan 2013 01:46:35 +0000 (-0500) Subject: First pass on sync with gearman yatl. X-Git-Tag: 1.0.16~20^2~2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=293e7b59e12ff6b95b5463614b09bc0158f14592;p=awesomized%2Flibmemcached First pass on sync with gearman yatl. --- diff --git a/libtest/cmdline.cc b/libtest/cmdline.cc index 43e5ef2d..3a61e4cf 100644 --- a/libtest/cmdline.cc +++ b/libtest/cmdline.cc @@ -409,7 +409,6 @@ bool Application::slurp() Application::error_t Application::join() { pid_t waited_pid= waitpid(_pid, &_status, 0); - if (waited_pid == _pid and WIFEXITED(_status) == false) { /* @@ -730,7 +729,7 @@ void Application::create_argv(const char *args[]) 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(&buffer[0]); + built_argv.push_back(strdup(&buffer[0])); } else if (_use_gdb) { @@ -782,7 +781,10 @@ struct DeleteFromVector template void operator() ( T* ptr) const { - free(ptr); + if (ptr) + { + free(ptr); + } } }; diff --git a/libtest/cmdline.h b/libtest/cmdline.h index ae4d9ba1..460a520c 100644 --- a/libtest/cmdline.h +++ b/libtest/cmdline.h @@ -39,8 +39,13 @@ #include // http://www.gnu.org/software/automake/manual/automake.html#Using-the-TAP-test-protocol -#define EXIT_SKIP 77 -#define EXIT_FATAL 77 +#ifndef EXIT_SKIP +# define EXIT_SKIP 77 +#endif + +#ifndef EXIT_FATAL +# define EXIT_FATAL 99 +#endif #ifndef EX_NOEXEC # define EX_NOEXEC 126 @@ -162,7 +167,7 @@ public: std::string print(); - void use_valgrind(bool arg= true) + void use_valgrind(bool arg) { _use_valgrind= arg; } @@ -172,12 +177,12 @@ public: bool slurp(); void murder(); - void use_gdb(bool arg= true) + void use_gdb(bool arg) { _use_gdb= arg; } - void use_ptrcheck(bool arg= true) + void use_ptrcheck(bool arg) { _use_ptrcheck= arg; } diff --git a/libtest/comparison.cc b/libtest/comparison.cc index 46aabe78..9b3e45e5 100644 --- a/libtest/comparison.cc +++ b/libtest/comparison.cc @@ -49,16 +49,6 @@ bool jenkins_is_caller(void) return false; } -bool valgrind_is_caller(void) -{ - if (bool(getenv("TESTS_ENVIRONMENT")) and strstr(getenv("TESTS_ENVIRONMENT"), "valgrind")) - { - return true; - } - - return false; -} - bool gdb_is_caller(void) { if (bool(getenv("TESTS_ENVIRONMENT")) and strstr(getenv("TESTS_ENVIRONMENT"), "gdb")) diff --git a/libtest/comparison.hpp b/libtest/comparison.hpp index d75e97fc..dcbcefd8 100644 --- a/libtest/comparison.hpp +++ b/libtest/comparison.hpp @@ -39,13 +39,13 @@ #include #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED -# include -# include -# include +#include +#include +#include #endif #if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN -# include +#include #endif namespace libtest { @@ -56,9 +56,6 @@ bool jenkins_is_caller(void); LIBTEST_API bool gdb_is_caller(void); -LIBTEST_API -bool valgrind_is_caller(void); - LIBTEST_API bool _in_valgrind(const char *file, int line, const char *func); diff --git a/libtest/fatal.cc b/libtest/fatal.cc index e96d723c..626ec6f8 100644 --- a/libtest/fatal.cc +++ b/libtest/fatal.cc @@ -41,21 +41,16 @@ namespace libtest { #pragma GCC diagnostic ignored "-Wformat-nonliteral" -fatal::fatal(const char *file_arg, int line_arg, const char *func_arg, const char *format, ...) : - std::runtime_error(func_arg), - _line(line_arg), - _file(file_arg), - _func(func_arg) +fatal::fatal(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, format); - char last_error[BUFSIZ]; - int last_error_length= vsnprintf(last_error, sizeof(last_error), format, args); + va_start(args, func_arg); + const char *format= va_arg(args, const char *); + int last_error_length= vsnprintf(0, 0, format, args); + _error_message.resize(last_error_length +1); + last_error_length= vsnprintf(&_error_message[0], _error_message.size(), format, args); va_end(args); - - strncpy(_mesg, last_error, sizeof(_mesg)); - - snprintf(_error_message, sizeof(_error_message), "%.*s", last_error_length, last_error); } static bool _disabled= false; @@ -90,8 +85,7 @@ void fatal::increment_disabled_counter() #pragma GCC diagnostic ignored "-Wformat-nonliteral" disconnected::disconnected(const char *file_arg, int line_arg, const char *func_arg, - const std::string& instance, const in_port_t port, - const char *format, ...) : + const std::string& instance, const in_port_t port, ...) : std::runtime_error(func_arg), _port(port), _line(line_arg), @@ -99,7 +93,8 @@ disconnected::disconnected(const char *file_arg, int line_arg, const char *func_ _func(func_arg) { va_list args; - va_start(args, format); + va_start(args, port); + const char *format= va_arg(args, const char *); char last_error[BUFSIZ]; (void)vsnprintf(last_error, sizeof(last_error), format, args); va_end(args); diff --git a/libtest/fatal.hpp b/libtest/fatal.hpp index bb8cc938..8b810e7b 100644 --- a/libtest/fatal.hpp +++ b/libtest/fatal.hpp @@ -38,74 +38,16 @@ #include -#ifndef __PRETTY_FUNCTION__ -#define __PRETTY_FUNCTION__ __func__ -#endif - -#define YATL_STRINGIFY(x) #x -#define YATL_TOSTRING(x) YATL_STRINGIFY(x) -#define YATL_AT __FILE__ ":" YATL_TOSTRING(__LINE__) -#define YATL_AT_PARAM __func__, AT -#define YATL_UNIQUE __FILE__ ":" YATL_TOSTRING(__LINE__) "_unique" -#define YATL_UNIQUE_FUNC_NAME __FILE__ ":" YATL_TOSTRING(__LINE__) "_unique_func" - -#define LIBYATL_DEFAULT_PARAM __FILE__, __LINE__, __PRETTY_FUNCTION__ - namespace libtest { -class fatal : std::runtime_error -{ -public: - fatal(const char *file, int line, const char *func, const char *format, ...); - - const char* what() const throw() - { - return _error_message; - } - - const char* mesg() const throw() - { - return _error_message; - } - - // 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() - { - return _line; - } - - const char* file() - { - return _file; - } - - const char* func() - { - return _func; - } - -private: - char _error_message[BUFSIZ]; - char _mesg[BUFSIZ]; - int _line; - const char* _file; - const char* _func; -}; - class disconnected : std::runtime_error { public: - disconnected(const char *file, int line, const char *func, const std::string&, const in_port_t port, const char *format, ...); + 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; + return &_error_message[0]; } // The following are just for unittesting the exception class @@ -139,8 +81,4 @@ private: const char* _func; }; - } // namespace libtest - -#define fatal_message(__mesg) throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "%s", __mesg) -#define fatal_assert(__assert) if((__assert)) {} else { throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "%s", #__assert); } diff --git a/libtest/framework.cc b/libtest/framework.cc index 9fef09b2..f8bc78c9 100644 --- a/libtest/framework.cc +++ b/libtest/framework.cc @@ -139,7 +139,7 @@ void Framework::exec() catch (libtest::fatal& e) { _failed++; - stream::cerr(e.file(), e.line(), e.func()) << e.mesg(); + stream::cerr(e.file(), e.line(), e.func()) << e.what(); } catch (libtest::disconnected& e) { diff --git a/libtest/include.am b/libtest/include.am index 0a662a17..1b6f8e29 100644 --- a/libtest/include.am +++ b/libtest/include.am @@ -2,7 +2,7 @@ # # included from Top Level Makefile.am # All paths should be given relative to the root -# +# LIBTOOL_COMMAND= ${abs_top_builddir}/libtool --mode=execute VALGRIND_EXEC_COMMAND= $(LIBTOOL_COMMAND) valgrind --error-exitcode=1 --leak-check=yes --track-fds=yes --malloc-fill=A5 --free-fill=DE @@ -45,51 +45,58 @@ noinst_HEADERS+= libtest/client.hpp noinst_HEADERS+= libtest/formatter.hpp noinst_HEADERS+= libtest/timer.hpp noinst_HEADERS+= libtest/alarm.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/dns.hpp -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/binaries.h +noinst_HEADERS+= libtest/cpu.hpp +noinst_HEADERS+= libtest/blobslap_worker.h +noinst_HEADERS+= libtest/callbacks.h +noinst_HEADERS+= libtest/dns.hpp +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/memcached.hpp noinst_HEADERS+= libtest/poll_error.hpp -noinst_HEADERS+= libtest/port.h -noinst_HEADERS+= libtest/result.hpp -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/port.h +noinst_HEADERS+= libtest/result.hpp +noinst_HEADERS+= libtest/result/base.hpp +noinst_HEADERS+= libtest/result/fail.hpp +noinst_HEADERS+= libtest/result/fatal.hpp +noinst_HEADERS+= libtest/result/skip.hpp +noinst_HEADERS+= libtest/result/success.hpp +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/thread.hpp -noinst_HEADERS+= libtest/tmpfile.hpp -noinst_HEADERS+= libtest/vchar.hpp -noinst_HEADERS+= libtest/version.h -noinst_HEADERS+= libtest/visibility.h +noinst_HEADERS+= libtest/tmpfile.hpp +noinst_HEADERS+= libtest/lite.h +noinst_HEADERS+= libtest/vchar.hpp +noinst_HEADERS+= libtest/version.h +noinst_HEADERS+= libtest/visibility.h noinst_HEADERS+= libtest/wait.h +noinst_HEADERS+= libtest/yatl.h noinst_LTLIBRARIES+= libtest/libtest.la @@ -98,36 +105,36 @@ EXTRA_libtest_libtest_la_DEPENDENCIES= libtest_libtest_la_LIBADD= libtest_libtest_la_SOURCES= -libtest_libtest_la_SOURCES+= libtest/alarm.cc -libtest_libtest_la_SOURCES+= libtest/binaries.cc -libtest_libtest_la_SOURCES+= libtest/cmdline.cc -libtest_libtest_la_SOURCES+= libtest/collection.cc -libtest_libtest_la_SOURCES+= libtest/comparison.cc -libtest_libtest_la_SOURCES+= libtest/core.cc -libtest_libtest_la_SOURCES+= libtest/cpu.cc -libtest_libtest_la_SOURCES+= libtest/dns.cc -libtest_libtest_la_SOURCES+= libtest/dream.cc -libtest_libtest_la_SOURCES+= libtest/drizzled.cc -libtest_libtest_la_SOURCES+= libtest/fatal.cc -libtest_libtest_la_SOURCES+= libtest/formatter.cc -libtest_libtest_la_SOURCES+= libtest/client.cc -libtest_libtest_la_SOURCES+= libtest/framework.cc -libtest_libtest_la_SOURCES+= libtest/has.cc -libtest_libtest_la_SOURCES+= libtest/http.cc -libtest_libtest_la_SOURCES+= libtest/is_local.cc -libtest_libtest_la_SOURCES+= libtest/killpid.cc -libtest_libtest_la_SOURCES+= libtest/libtool.cc -libtest_libtest_la_SOURCES+= libtest/main.cc -libtest_libtest_la_SOURCES+= libtest/port.cc -libtest_libtest_la_SOURCES+= libtest/result.cc -libtest_libtest_la_SOURCES+= libtest/runner.cc -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/strerror.cc -libtest_libtest_la_SOURCES+= libtest/timer.cc -libtest_libtest_la_SOURCES+= libtest/tmpfile.cc +libtest_libtest_la_SOURCES+= libtest/alarm.cc +libtest_libtest_la_SOURCES+= libtest/binaries.cc +libtest_libtest_la_SOURCES+= libtest/cmdline.cc +libtest_libtest_la_SOURCES+= libtest/collection.cc +libtest_libtest_la_SOURCES+= libtest/comparison.cc +libtest_libtest_la_SOURCES+= libtest/core.cc +libtest_libtest_la_SOURCES+= libtest/cpu.cc +libtest_libtest_la_SOURCES+= libtest/dns.cc +libtest_libtest_la_SOURCES+= libtest/dream.cc +libtest_libtest_la_SOURCES+= libtest/drizzled.cc +libtest_libtest_la_SOURCES+= libtest/fatal.cc +libtest_libtest_la_SOURCES+= libtest/formatter.cc +libtest_libtest_la_SOURCES+= libtest/client.cc +libtest_libtest_la_SOURCES+= libtest/framework.cc +libtest_libtest_la_SOURCES+= libtest/has.cc +libtest_libtest_la_SOURCES+= libtest/http.cc +libtest_libtest_la_SOURCES+= libtest/is_local.cc +libtest_libtest_la_SOURCES+= libtest/killpid.cc +libtest_libtest_la_SOURCES+= libtest/libtool.cc +libtest_libtest_la_SOURCES+= libtest/main.cc +libtest_libtest_la_SOURCES+= libtest/port.cc +libtest_libtest_la_SOURCES+= libtest/result.cc +libtest_libtest_la_SOURCES+= libtest/runner.cc +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/strerror.cc +libtest_libtest_la_SOURCES+= libtest/timer.cc +libtest_libtest_la_SOURCES+= libtest/tmpfile.cc libtest_libtest_la_SOURCES+= libtest/vchar.cc libtest_libtest_la_CXXFLAGS+= -DBUILDING_LIBTEST @@ -140,26 +147,16 @@ libtest_libtest_la_LIBADD+= $(CURL_LIBS) libtest_libtest_la_LIBADD+= @RT_LIB@ EXTRA_libtest_libtest_la_DEPENDENCIES+= libtest_tmp_dir -EXTRA_libtest_libtest_la_DEPENDENCIES+= libtest/abort -EXTRA_libtest_libtest_la_DEPENDENCIES+= libtest/wait +EXTRA_libtest_libtest_la_DEPENDENCIES+=libtest/abort +EXTRA_libtest_libtest_la_DEPENDENCIES+=libtest/wait # Declare unittest so that we can append to it libtest_unittest_CXXFLAGS= libtest_unittest_LDADD= # We are either building in tree, or with -if BUILDING_LIBMEMCACHED -libtest_libtest_la_SOURCES+= libtest/memcached.cc -libtest_libtest_la_CXXFLAGS+= -DHAVE_LIBMEMCACHED - -libtest_unittest_CXXFLAGS+= -DHAVE_LIBMEMCACHED -else -if HAVE_LIBMEMCACHED +if HAVE_MEMCACHED_BINARY libtest_libtest_la_SOURCES+= libtest/memcached.cc -else -libtest_libtest_la_CXXFLAGS+= -DHAVE_LIBMEMCACHED=0 -libtest_unittest_CXXFLAGS+= -DHAVE_LIBMEMCACHED=0 -endif endif if HAVE_LIBDRIZZLE diff --git a/libtest/lite.h b/libtest/lite.h new file mode 100644 index 00000000..56ea4c17 --- /dev/null +++ b/libtest/lite.h @@ -0,0 +1,339 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Data Differential YATL (i.e. libtest) library + * + * Copyright (C) 2012 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 + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +#ifdef __cplusplus +# include +# include +# include +#include +#else +# include +# include +# include +# include +# include +#endif + +#include + +#ifndef __PRETTY_FUNCTION__ +# define __PRETTY_FUNCTION__ __func__ +#endif + +#ifndef EXIT_SKIP +# define EXIT_SKIP 77 +#endif + +#ifndef YATL_FULL +# define YATL_FULL 0 +#endif + +#ifndef FAIL +# define FAIL(__message_format, ...) +#endif + +static inline bool valgrind_is_caller(void) +{ + if (getenv("TESTS_ENVIRONMENT") && strstr(getenv("TESTS_ENVIRONMENT"), "valgrind")) + { + return true; + } + + return false; +} + +static inline size_t yatl_strlen(const char *s) +{ + if (s) + { + return strlen(s); + } + + return (size_t)(0); +} + +static inline int yatl_strcmp(const char *s1, const char *s2, size_t *s1_length, size_t *s2_length) +{ + *s1_length= yatl_strlen(s1); + *s2_length= yatl_strlen(s2); + + if (*s1_length == 0 && *s1_length == *s2_length) + { + return 0; + } + + if (*s1_length == 0 && *s2_length) + { + return 1; + } + + if (*s1_length && *s2_length == 0) + { + return 1; + } + + return strcmp(s1, s2); +} + +#define SKIP_IF(__expression) \ +do \ +{ \ + if ((__expression)) { \ + fprintf(stderr, "\n%s:%d: %s SKIP '!%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression); \ + exit(EXIT_SKIP); \ + } \ +} while (0) + +#define ASSERT_TRUE(__expression) \ +do \ +{ \ + if (! (__expression)) { \ + if (YATL_FULL) { \ + FAIL("Assertion '%s'", #__expression); \ + } \ + fprintf(stderr, "\n%s:%d: %s Assertion '%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression);\ + exit(EXIT_FAILURE); \ + } \ +} while (0) + +#define ASSERT_FALSE(__expression) \ +do \ +{ \ + if ((__expression)) { \ + if (YATL_FULL) { \ + FAIL("Assertion '!%s'", #__expression); \ + } \ + fprintf(stderr, "\n%s:%d: %s Assertion '!%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression);\ + exit(EXIT_FAILURE); \ + } \ +} while (0) + +#define ASSERT_NULL_(__expression, ...) \ +do \ +{ \ + if ((__expression) != NULL) { \ + size_t ask= snprintf(0, 0, __VA_ARGS__); \ + ask++; \ + char *buffer= (char*)malloc(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) + +#define ASSERT_NOT_NULL(__expression) \ +do \ +{ \ + if ((__expression) == NULL) { \ + fprintf(stderr, "\n%s:%d: %s Assertion '%s' == NULL\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression,);\ + exit(EXIT_FAILURE); \ + } \ +} while (0) + +#define ASSERT_NOT_NULL_(__expression, ...) \ +do \ +{ \ + if ((__expression) == NULL) { \ + size_t ask= snprintf(0, 0, __VA_ARGS__); \ + ask++; \ + char *buffer= (char*)malloc(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) + +#define SKIP_IF_(__expression, ...) \ +do \ +{ \ + if ((__expression)) { \ + size_t ask= snprintf(0, 0, __VA_ARGS__); \ + ask++; \ + char *buffer= (char*)malloc(sizeof(char) * ask); \ + snprintf(buffer, ask, __VA_ARGS__); \ + fprintf(stdout, "\n%s:%d: %s SKIP '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \ + free(buffer); \ + exit(EXIT_SKIP); \ + } \ +} while (0) + +#define ASSERT_TRUE_(__expression, ...) \ +do \ +{ \ + if (! (__expression)) { \ + size_t ask= snprintf(0, 0, __VA_ARGS__); \ + ask++; \ + char *buffer= (char*)malloc(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) + +#define ASSERT_EQ(__expected, __actual) \ +do \ +{ \ + if ((__expected) != (__actual)) { \ + fprintf(stderr, "\n%s:%d: %s Assertion '%s' != '%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual); \ + exit(EXIT_FAILURE); \ + } \ +} while (0) + +#define ASSERT_EQ_(__expected, __actual, ...) \ +do \ +{ \ + if ((__expected) != (__actual)) { \ + size_t ask= snprintf(0, 0, __VA_ARGS__); \ + ask++; \ + char *buffer= (char*)malloc(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) + +#define ASSERT_STREQ(__expected_str, __actual_str) \ +do \ +{ \ + size_t __expected_length; \ + size_t __actual_length; \ + int ret= yatl_strcmp(__expected_str, __actual_str, &__expected_length, &__actual_length); \ + if (ret) { \ + fprintf(stderr, "\n%s:%d: %s Assertion '%.*s' != '%.*s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, \ + (int)(__expected_length), (__expected_str), \ + (int)__actual_length, (__actual_str)) ; \ + exit(EXIT_FAILURE); \ + } \ +} while (0) + +#define ASSERT_STREQ_(__expected_str, __actual_str, ...) \ +do \ +{ \ + size_t __expected_length; \ + size_t __actual_length; \ + int ret= yatl_strcmp(__expected_str, __actual_str, &__expected_length, &__actual_length); \ + if (ret) { \ + size_t ask= snprintf(0, 0, __VA_ARGS__); \ + ask++; \ + char *buffer= (char*)malloc(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) + +#define ASSERT_STRNE(__expected_str, __actual_str) \ +do \ +{ \ + size_t __expected_length; \ + size_t __actual_length; \ + int ret= yatl_strcmp(__expected_str, __actual_str, &__expected_length, &__actual_length); \ + if (ret == 0) { \ + fprintf(stderr, "\n%s:%d: %s Assertion '%.*s' == '%.*s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, \ + (int)(__expected_length), (__expected_str), \ + (int)__actual_length, (__actual_str)) ; \ + exit(EXIT_FAILURE); \ + } \ +} while (0) + +#define ASSERT_STRNE_(__expected_str, __actual_str, ...) \ +do \ +{ \ + size_t __expected_length; \ + size_t __actual_length; \ + int ret= yatl_strcmp(__expected_str, __actual_str, &__expected_length, &__actual_length); \ + if (ret == 0) { \ + size_t ask= snprintf(0, 0, __VA_ARGS__); \ + ask++; \ + char *buffer= (char*)malloc(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) + +#define ASSERT_NEQ(__expected, __actual, ...) \ +do \ +{ \ + if ((__expected) == (__actual)) { \ + fprintf(stderr, "\n%s:%d: %s Assertion '%s' == '%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual); \ + exit(EXIT_FAILURE); \ + } \ +} while (0) + +#define ASSERT_NEQ_(__expected, __actual, ...) \ +do \ +{ \ + if ((__expected) == (__actual)) { \ + size_t ask= snprintf(0, 0, __VA_ARGS__); \ + ask++; \ + char *buffer= (char*)malloc(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) + +#define ASSERT_FALSE_(__expression, ...) \ +do \ +{ \ + if ((__expression)) { \ + size_t ask= snprintf(0, 0, __VA_ARGS__); \ + ask++; \ + char *buffer= (char*)alloca(sizeof(char) * ask); \ + snprintf(buffer, ask, __VA_ARGS__); \ + if (YATL_FULL) { \ + throw libtest::__failure(__FILE__, __LINE__, __PRETTY_FUNCTION__, "Assertion '!%s' [ %s ]", #__expression, buffer); \ + } \ + fprintf(stderr, "\n%s:%d: %s Assertion '!%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \ + exit(EXIT_FAILURE); \ + } \ +} while (0) diff --git a/libtest/m4/memcached.m4 b/libtest/m4/memcached.m4 index 42d949e8..43b87433 100644 --- a/libtest/m4/memcached.m4 +++ b/libtest/m4/memcached.m4 @@ -1,14 +1,14 @@ -#serial 1 +#serial 2 - AC_DEFUN([YATL_MEMCACHED], [ - AC_REQUIRE([AX_ENABLE_LIBMEMCACHED]) +AC_DEFUN([YATL_MEMCACHED], + [AC_REQUIRE([AX_ENABLE_LIBMEMCACHED]) - AX_WITH_PROG(MEMCACHED_BINARY, [memcached]) - AS_IF([test -f "$ac_cv_path_MEMCACHED_BINARY"],[ - AC_DEFINE([HAVE_MEMCACHED_BINARY], [1], [If Memcached binary is available]) - AC_DEFINE_UNQUOTED([MEMCACHED_BINARY], "$ac_cv_path_MEMCACHED_BINARY", [Name of the memcached binary used in make test]) - ],[ - AC_DEFINE([HAVE_MEMCACHED_BINARY], [1], [If Memcached binary is available]) - AC_DEFINE([MEMCACHED_BINARY], ["memcached/memcached"], [Name of the memcached binary used in make test]) - ]) - ]) + AX_WITH_PROG(MEMCACHED_BINARY, [memcached]) + AS_IF([test -f "$ac_cv_path_MEMCACHED_BINARY"], + [AC_DEFINE([HAVE_MEMCACHED_BINARY], [1], [If Memcached binary is available]) + AC_DEFINE_UNQUOTED([MEMCACHED_BINARY], "$ac_cv_path_MEMCACHED_BINARY", [Name of the memcached binary used in make test])], + [AC_DEFINE([HAVE_MEMCACHED_BINARY], [1], [If Memcached binary is available]) + AC_DEFINE([MEMCACHED_BINARY], ["memcached/memcached"], [Name of the memcached binary used in make test]) + ]) + AM_CONDITIONAL([HAVE_MEMCACHED_BINARY],[test -f "$ac_cv_path_MEMCACHED_BINARY"]) + ]) diff --git a/libtest/main.cc b/libtest/main.cc index c405bf20..6231ba12 100644 --- a/libtest/main.cc +++ b/libtest/main.cc @@ -294,7 +294,7 @@ int main(int argc, char *argv[]) return EXIT_SKIP; case TEST_FAILURE: - std::cerr << "frame->create()" << std::endl; + std::cerr << "Could not call frame->create()" << std::endl; return EXIT_FAILURE; } } diff --git a/libtest/result.cc b/libtest/result.cc index 65038f91..2bc83171 100644 --- a/libtest/result.cc +++ b/libtest/result.cc @@ -57,10 +57,46 @@ __skipped::__skipped(const char *file_arg, int line_arg, const char *func_arg): { } -__failure::__failure(const char *file_arg, int line_arg, const char *func_arg, const std::string& mesg): - __test_result(file_arg, line_arg, func_arg) +__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) +{ + 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); +} + +__failure::__failure( const __failure& other ) : + __test_result(other), + _error_message_size(other._error_message_size) { - snprintf(_error_message, sizeof(_error_message), "%.*s", int(mesg.size()), mesg.c_str()); + _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() +{ + if ((_error_message_size > 0) and _error_message) + { + free(_error_message); + _error_message= NULL; + } +} + + } // namespace libtest diff --git a/libtest/result.hpp b/libtest/result.hpp index 784ae72b..9e6bf209 100644 --- a/libtest/result.hpp +++ b/libtest/result.hpp @@ -37,78 +37,25 @@ #pragma once #include +#include +#include +#include +#include +#include -namespace libtest { - -class __test_result : public std::exception -{ -public: - __test_result(const char *file, int line, const char *func); - - int line() - { - return _line; - } - - const char* file() - { - return _file; - } - - const char* func() - { - return _func; - } - -private: - int _line; - const char* _file; - const char* _func; -}; - -class __success : public __test_result -{ -public: - __success(const char *file, int line, const char *func); - - const char* what() const throw() - { - return "SUCCESS"; - } - -private: -}; - -class __skipped : public __test_result -{ -public: - __skipped(const char *file, int line, const char *func); - - const char* what() const throw() - { - return "SKIPPED"; - } - -private: -}; - -class __failure : public __test_result -{ -public: - __failure(const char *file, int line, const char *func, const std::string&); - - const char* what() const throw() - { - return _error_message; - } - -private: - char _error_message[BUFSIZ]; -}; +#define _SUCCESS throw libtest::__success(LIBYATL_DEFAULT_PARAM) +#define SKIP throw libtest::__skipped(LIBYATL_DEFAULT_PARAM) +#define FAIL(...) \ +do \ +{ \ + throw libtest::__failure(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \ +} while (0) -} // namespace libtest +#define fatal_message(...) \ +do \ +{ \ + throw libtest::fatal(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \ +} while (0) -#define _SUCCESS throw libtest::__success(LIBYATL_DEFAULT_PARAM) -#define SKIP throw libtest::__skipped(LIBYATL_DEFAULT_PARAM) -#define FAIL(__mesg) throw libtest::__failure(LIBYATL_DEFAULT_PARAM, __mesg) +#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 new file mode 100644 index 00000000..1859c22a --- /dev/null +++ b/libtest/result/base.hpp @@ -0,0 +1,74 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Data Differential YATL (i.e. libtest) library + * + * Copyright (C) 2012 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 + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +namespace libtest { + +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) + { + } + + int line() + { + return _line; + } + + const char* file() + { + return _file; + } + + const char* func() + { + return _func; + } + +private: + int _line; + const char* _file; + const char* _func; +}; + +} // namespace libtest diff --git a/libtest/result/fail.hpp b/libtest/result/fail.hpp new file mode 100644 index 00000000..dae4a08b --- /dev/null +++ b/libtest/result/fail.hpp @@ -0,0 +1,61 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Data Differential YATL (i.e. libtest) library + * + * Copyright (C) 2012 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 + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +namespace libtest { + +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; + } + +private: + char* _error_message; + int _error_message_size; +}; + +} // namespace libtest + diff --git a/libtest/result/fatal.hpp b/libtest/result/fatal.hpp new file mode 100644 index 00000000..39778ab8 --- /dev/null +++ b/libtest/result/fatal.hpp @@ -0,0 +1,66 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Data Differential YATL (i.e. libtest) library + * + * Copyright (C) 2012 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 + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +namespace libtest { + +class fatal : public __test_result +{ +public: + fatal(const char *file, int line, const char *func, ...); + + ~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(); + +private: + vchar_t _error_message; +}; + +} // namespace libtest diff --git a/libtest/result/skip.hpp b/libtest/result/skip.hpp new file mode 100644 index 00000000..41df316f --- /dev/null +++ b/libtest/result/skip.hpp @@ -0,0 +1,54 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Data Differential YATL (i.e. libtest) library + * + * Copyright (C) 2012 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 + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +namespace libtest { + +class __skipped : public __test_result +{ +public: + __skipped(const char *file, int line, const char *func); + + const char* what() const throw() + { + return "SKIPPED"; + } + +private: +}; + +} // namespace libtest diff --git a/libtest/result/success.hpp b/libtest/result/success.hpp new file mode 100644 index 00000000..2931f2d0 --- /dev/null +++ b/libtest/result/success.hpp @@ -0,0 +1,54 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Data Differential YATL (i.e. libtest) library + * + * Copyright (C) 2012 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 + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +namespace libtest { + +class __success : public __test_result +{ +public: + __success(const char *file, int line, const char *func); + + const char* what() const throw() + { + return "SUCCESS"; + } + +private: +}; + +} // namespace libtest diff --git a/libtest/server.cc b/libtest/server.cc index 42c6b480..02aeec70 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -189,13 +189,10 @@ bool Server::start() #endif } - // This needs more work. -#if 0 - if (gdb_is_caller()) + if (getenv("YATL_GDB_SERVER")) { - _app.use_gdb(); + _app.use_gdb(true); } -#endif if (port() == LIBTEST_FAIL_PORT) { @@ -205,11 +202,11 @@ bool Server::start() if (getenv("YATL_PTRCHECK_SERVER")) { - _app.use_ptrcheck(); + _app.use_ptrcheck(true); } else if (getenv("YATL_VALGRIND_SERVER")) { - _app.use_valgrind(); + _app.use_valgrind(true); } out_of_ban_killed(false); @@ -275,7 +272,7 @@ bool Server::start() uint32_t waited; uint32_t retry; - for (waited= 0, retry= 7; ; retry++, waited+= this_wait) + for (waited= 0, retry= 1; ; retry++, waited+= this_wait) { if (_app.check() == false) { @@ -291,8 +288,6 @@ bool Server::start() break; } - Error << "ping(" << _app.pid() << ") wait: " << this_wait << " " << hostname() << ":" << port() << " run:" << _running << " " << error(); - this_wait= retry * retry / 3 + 1; libtest::dream(this_wait, 0); } @@ -300,6 +295,8 @@ bool Server::start() if (pinged == false) { + Error << "ping(" << _app.pid() << ") wait: " << this_wait << " " << hostname() << ":" << port() << " run:" << _running << " " << error(); + // If we happen to have a pid file, lets try to kill it if ((pid_file().empty() == false) and (access(pid_file().c_str(), R_OK) == 0)) { diff --git a/libtest/server_container.cc b/libtest/server_container.cc index 17dd6d44..802514d2 100644 --- a/libtest/server_container.cc +++ b/libtest/server_container.cc @@ -202,20 +202,14 @@ bool server_startup_st::start_server(const std::string& server_type, in_port_t t { if (GEARMAND_BINARY) { - if (HAVE_LIBGEARMAN) - { - server= build_gearmand("localhost", try_port); - } + server= build_gearmand("localhost", try_port); } } else if (server_type.compare("hostile-gearmand") == 0) { if (GEARMAND_BINARY) { - if (HAVE_LIBGEARMAN) - { - server= build_gearmand("localhost", try_port, "gearmand/hostile_gearmand"); - } + server= build_gearmand("localhost", try_port, "gearmand/hostile_gearmand"); } } else if (server_type.compare("drizzled") == 0) @@ -245,10 +239,7 @@ bool server_startup_st::start_server(const std::string& server_type, in_port_t t { if (HAVE_MEMCACHED_BINARY) { - if (HAVE_LIBMEMCACHED) - { - server= build_memcached("localhost", try_port); - } + server= build_memcached("localhost", try_port); } } @@ -344,14 +335,7 @@ bool server_startup_st::start_socket_server(const std::string& server_type, cons { if (MEMCACHED_BINARY) { - if (HAVE_LIBMEMCACHED) - { server= build_memcached_socket("localhost", try_port); - } - else - { - Error << "Libmemcached was not found"; - } } else { diff --git a/libtest/test.h b/libtest/test.h index 78cdb4e4..3c3c37d1 100644 --- a/libtest/test.h +++ b/libtest/test.h @@ -40,6 +40,8 @@ #pragma GCC diagnostic ignored "-Wold-style-cast" #endif +#include + /** A structure describing the test case. */ @@ -61,17 +63,6 @@ do \ } \ } while (0) -#define test_assert(A, B) \ -do \ -{ \ - if ((A)) { \ - fprintf(stderr, "\n%s:%d: Assertion failed %s, with message %s, in %s", __FILE__, __LINE__, (B), #A, __func__ );\ - fprintf(stderr, "\n"); \ - libtest::create_core(); \ - assert((A)); \ - } \ -} while (0) - #define test_truth(A) \ do \ { \ diff --git a/libtest/test.hpp b/libtest/test.hpp index 24fa7c8b..1722c4dc 100644 --- a/libtest/test.hpp +++ b/libtest/test.hpp @@ -38,6 +38,21 @@ Structures for generic tests. */ +#pragma once + +#ifndef __PRETTY_FUNCTION__ +#define __PRETTY_FUNCTION__ __func__ +#endif + +#define YATL_STRINGIFY(x) #x +#define YATL_TOSTRING(x) YATL_STRINGIFY(x) +#define YATL_AT __FILE__ ":" YATL_TOSTRING(__LINE__) +#define YATL_AT_PARAM __func__, AT +#define YATL_UNIQUE __FILE__ ":" YATL_TOSTRING(__LINE__) "_unique" +#define YATL_UNIQUE_FUNC_NAME __FILE__ ":" YATL_TOSTRING(__LINE__) "_unique_func" + +#define LIBYATL_DEFAULT_PARAM __FILE__, __LINE__, __PRETTY_FUNCTION__ + #include #include #include diff --git a/libtest/unittest.cc b/libtest/unittest.cc index b81ef5e7..75b41f70 100644 --- a/libtest/unittest.cc +++ b/libtest/unittest.cc @@ -36,7 +36,7 @@ #include "libtest/yatlcon.h" -#include +#include #if defined(HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H) && HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H # include @@ -142,11 +142,13 @@ static test_return_t test_throw_skip_TEST(void *) static test_return_t test_throw_fail_TEST(void *) { - std::string error_messsage("test message!"); try { - FAIL(error_messsage); +#if 0 + FAIL("test message!"); +#endif + throw libtest::__failure(LIBYATL_DEFAULT_PARAM, "test message!"); } - catch (libtest::__failure e) + catch (const libtest::__failure& e) { std::string compare_message("test message!"); test_zero(compare_message.compare(e.what())); @@ -159,6 +161,45 @@ static test_return_t test_throw_fail_TEST(void *) return TEST_FAILURE; } +#pragma GCC diagnostic ignored "-Wstack-protector" + +static test_return_t ASSERT_FALSE__TEST(void *) +{ + try { + ASSERT_FALSE_(true, __func__); + } + catch (libtest::__failure e) + { + std::string compare_message(__func__); + ASSERT_EQ(compare_message.compare(e.what()), -32); + return TEST_SUCCESS; + } + catch (...) + { + return TEST_FAILURE; + } + + return TEST_FAILURE; +} + +static test_return_t ASSERT_FALSE_TEST(void *) +{ + try { + FAIL(__func__); + } + catch (libtest::__failure e) + { + std::string compare_message(__func__); + ASSERT_EQ(0, compare_message.compare(e.what())); + return TEST_SUCCESS; + } + catch (...) + { + return TEST_FAILURE; + } + + return TEST_FAILURE; +} static test_return_t test_failure_test(void *) { @@ -464,7 +505,7 @@ static test_return_t application_gdb_true_BINARY2(void *) test_skip(0, access("/usr/bin/true", X_OK )); Application true_app("/usr/bin/true"); - true_app.use_gdb(); + true_app.use_gdb(true); test_compare(Application::SUCCESS, true_app.run()); test_compare(Application::SUCCESS, true_app.join()); @@ -478,7 +519,7 @@ static test_return_t application_gdb_true_BINARY(void *) test_skip(0, access("/usr/bin/true", X_OK )); Application true_app("/usr/bin/true"); - true_app.use_gdb(); + true_app.use_gdb(true); const char *args[]= { "--fubar", 0 }; test_compare(Application::SUCCESS, true_app.run(args)); @@ -685,7 +726,7 @@ static test_return_t wait_services_appliction_TEST(void *) test_skip(0, access("libtest/wait", X_OK )); libtest::Application wait_app("libtest/wait", true); - wait_app.use_gdb(); + wait_app.use_gdb(true); const char *args[]= { "/etc/services", 0 }; test_compare(Application::SUCCESS, wait_app.run(args)); @@ -706,7 +747,7 @@ static test_return_t gdb_wait_services_appliction_TEST(void *) test_skip(0, access("libtest/wait", X_OK )); libtest::Application wait_app("libtest/wait", true); - wait_app.use_gdb(); + wait_app.use_gdb(true); const char *args[]= { "/etc/services", 0 }; test_compare(Application::SUCCESS, wait_app.run(args)); @@ -726,7 +767,7 @@ static test_return_t gdb_abort_services_appliction_TEST(void *) #endif libtest::Application abort_app("libtest/abort", true); - abort_app.use_gdb(); + abort_app.use_gdb(true); test_compare(Application::SUCCESS, abort_app.run()); test_compare(Application::SUCCESS, abort_app.join()); @@ -849,7 +890,10 @@ static test_return_t check_for_gearman(void *) #if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY if (GEARMAND_BINARY) { - test_zero(access(GEARMAND_BINARY, X_OK )); + if (strcmp(GEARMAND_BINARY, "./gearmand/gearmand")) + { + test_zero(access(GEARMAND_BINARY, X_OK )); + } } else { @@ -899,9 +943,8 @@ static test_return_t clear_servers(void* object) return TEST_SUCCESS; } -static test_return_t check_for_libmemcached(void* object) +static test_return_t check_for_memcached(void* object) { - test_skip(true, HAVE_LIBMEMCACHED); test_skip(true, has_memcached()); server_startup_st *servers= (server_startup_st*)object; @@ -943,6 +986,8 @@ test_st tests_log[] ={ {"SUCCESS", false, test_throw_success_TEST }, {"SKIP", false, test_throw_skip_TEST }, {"FAIL", false, test_throw_fail_TEST }, + {"ASSERT_FALSE_", false, ASSERT_FALSE__TEST }, + {"ASSERT_FALSE", false, ASSERT_FALSE_TEST }, {0, 0, 0} }; @@ -1069,7 +1114,7 @@ collection_st collection[] ={ {"directories", 0, 0, directories_tests}, {"comparison", 0, 0, comparison_tests}, {"gearmand", check_for_gearman, clear_servers, gearmand_tests}, - {"memcached", check_for_libmemcached, clear_servers, memcached_TESTS }, + {"memcached", check_for_memcached, clear_servers, memcached_TESTS }, {"drizzled", check_for_drizzle, clear_servers, drizzled_tests}, {"cmdline", 0, 0, cmdline_tests}, {"application", 0, 0, application_tests}, diff --git a/libtest/version.h.in b/libtest/version.h.in index f2af4442..1bec2a84 100644 --- a/libtest/version.h.in +++ b/libtest/version.h.in @@ -2,7 +2,7 @@ * * Data Differential YATL (i.e. libtest) library * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/ * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/libtest/yatl.h b/libtest/yatl.h new file mode 100644 index 00000000..6da02a3d --- /dev/null +++ b/libtest/yatl.h @@ -0,0 +1,43 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Data Differential YATL (i.e. libtest) library + * + * Copyright (C) 2012 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 + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +#ifndef YATL_FULL +# define YATL_FULL 1 +#endif + +#include