#include <iostream>
#include <unistd.h>
-#include "generator.h"
+#include "clients/generator.h"
/* Use this for string generation */
static const char ALPHANUMERICS[]=
return (size_t)random() % ALPHANUMERICS_SIZE;
}
-static void get_random_string(char *buffer, size_t size)
+void get_random_string(char *buffer, size_t size)
{
char *buffer_ptr= buffer;
while (--size)
+ {
*buffer_ptr++= ALPHANUMERICS[get_alpha_num()];
+ }
*buffer_ptr++= ALPHANUMERICS[get_alpha_num()];
}
pthread_mutex_init(&sleeper_mutex, NULL);
pthread_cond_init(&sleep_threshhold, NULL);
- scheduler(servers, &conclusion);
+ int error_code= EXIT_SUCCESS;
+ try {
+ scheduler(servers, &conclusion);
+ }
+ catch(std::exception& e)
+ {
+ std::cerr << "Died with exception: " << e.what() << std::endl;
+ error_code= EXIT_FAILURE;
+ }
free(opt_servers);
conclusions_print(&conclusion);
memcached_server_list_free(servers);
- return EXIT_SUCCESS;
+ return error_code;
}
void scheduler(memcached_server_st *servers, conclusions_st *conclusion)
pthread_t *threads= new (std::nothrow) pthread_t[opt_concurrency];
- if (not threads)
+ if (threads == NULL)
{
exit(EXIT_FAILURE);
}
AX_COMPILER_VENDOR
+AC_CHECK_TYPES([in_port_t])
AC_CHECK_TYPES([ptrdiff_t])
AC_HEADER_STDBOOL
AC_TYPE_INT16_T
AC_DEFINE([HAVE_CLOCK_GETTIME],[1],[Have clock_gettime])],
[AC_DEFINE([HAVE_CLOCK_GETTIME],[0],[Have clock_gettime])])
+
# Check for the ability to call dlopen (used in libhostile)
AX_DLOPEN
#pragma once
+#ifdef _WIN32
+# include <malloc.h>
+#else
+# include <alloca.h>
+#endif
+
+#include <cstdarg>
+
#ifdef NDEBUG
#define assert_msg(__expr, __mesg) (void)(__expr); (void)(__mesg);
+#define assert_vmsg(__expr, __mesg, ...) (void)(__expr); (void)(__mesg);
#else
#define assert_msg(__expr, __mesg) \
} \
} while (0)
+#define assert_vmsg(__expr, __mesg, ...) \
+do \
+{ \
+ if (not (__expr)) \
+ { \
+ size_t ask= snprintf(0, 0, (__mesg), __VA_ARGS__); \
+ ask++; \
+ char *_error_message= (char*)alloca(sizeof(char) * ask); \
+ size_t _error_message_size= snprintf(_error_message, ask, (__mesg), __VA_ARGS__); \
+ fprintf(stderr, "\n%s:%d Assertion '%s' failed for function '%s' [ %.*s ]\n", __FILE__, __LINE__, #__expr, __func__, int(_error_message_size), _error_message);\
+ custom_backtrace(); \
+ abort(); \
+ } \
+} while (0)
+
#endif
break;
case EAI_AGAIN:
- if (server->address_info)
- {
- freeaddrinfo(server->address_info);
- server->address_info= NULL;
- server->address_info_next= NULL;
- }
return memcached_set_error(*server, MEMCACHED_TIMEOUT, MEMCACHED_AT, memcached_string_make_from_cstr(gai_strerror(errcode)));
case EAI_SYSTEM:
return MEMCACHED_SUCCESS;
}
-static memcached_return_t server_add(memcached_st *ptr,
+static memcached_return_t server_add(memcached_st *memc,
const memcached_string_t& hostname,
in_port_t port,
uint32_t weight,
memcached_connection_t type)
{
- assert_msg(ptr, "Programmer mistake, somehow server_add() was passed a NULL memcached_st");
+ assert_msg(memc, "Programmer mistake, somehow server_add() was passed a NULL memcached_st");
- if (ptr->number_of_hosts)
+ if (memc->number_of_hosts)
{
- assert(memcached_instance_list(ptr));
+ assert(memcached_instance_list(memc));
}
- if (memcached_instance_list(ptr))
+ if (memcached_instance_list(memc))
{
- assert(ptr->number_of_hosts);
+ assert(memc->number_of_hosts);
}
- uint32_t host_list_size= ptr->number_of_hosts +1;
- org::libmemcached::Instance* new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), host_list_size, org::libmemcached::Instance);
+ uint32_t host_list_size= memc->number_of_hosts +1;
+ org::libmemcached::Instance* new_host_list= libmemcached_xrealloc(memc, memcached_instance_list(memc), host_list_size, org::libmemcached::Instance);
if (new_host_list == NULL)
{
- return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
+ return memcached_set_error(*memc, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
}
- memcached_instance_set(ptr, new_host_list, host_list_size);
- assert(ptr->number_of_hosts == host_list_size);
+ memcached_instance_set(memc, new_host_list, host_list_size);
+ assert(memc->number_of_hosts == host_list_size);
/* TODO: Check return type */
- org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, memcached_server_count(ptr) -1);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(memc, memcached_server_count(memc) -1);
- if (__instance_create_with(ptr, instance, hostname, port, weight, type) == NULL)
+ if (__instance_create_with(memc, instance, hostname, port, weight, type) == NULL)
{
- return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
+ return memcached_set_error(*memc, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
}
if (weight > 1)
{
- if (memcached_is_consistent_distribution(ptr))
+ if (memcached_is_consistent_distribution(memc))
{
- memcached_set_weighted_ketama(ptr, true);
+ memcached_set_weighted_ketama(memc, true);
}
}
- return run_distribution(ptr);
+ return run_distribution(memc);
}
libmemcached_libmemcached_la_LIBADD+= @DL_LIB@
if HAVE_SASL
-if HAVE_LIBSASL
libmemcached_libmemcached_la_CXXFLAGS+= @PTHREAD_CFLAGS@
libmemcached_libmemcached_la_LIBADD+= @PTHREAD_LIBS@
libmemcached_libmemcached_la_LIBADD+= @LIBSASL_LIB@
endif
-endif
if HAVE_DTRACE
BUILT_SOURCES+= libmemcached/dtrace_probes.h
{
if (self)
{
- memcached_instance_list_free(memcached_instance_list(self), self->number_of_hosts);
+ libmemcached_free(self, self->ketama.continuum);
+ self->ketama.continuum= NULL;
+ memcached_instance_list_free(memcached_instance_list(self), self->number_of_hosts);
memcached_instance_set(self, NULL, 0);
- self->number_of_hosts= 0;
- memcached_instance_free((org::libmemcached::Instance*)self->last_disconnected_server);
- self->last_disconnected_server= NULL;
+
+ memcached_reset_last_disconnected_server(self);
}
}
void memcached_instance_set(memcached_st* memc, org::libmemcached::Instance* list, const uint32_t host_list_size)
{
+ assert(memc);
memc->servers= list;
memc->number_of_hosts= host_list_size;
}
#include <cstdlib>
#include <cstdio>
-#include <libmemcachedutil-1.0/util.h>
-#include <libmemcached/assert.hpp>
-#include <libmemcached/backtrace.hpp>
+#include "libmemcachedutil-1.0/util.h"
+#include "libmemcached/assert.hpp"
+#include "libmemcached/backtrace.hpp"
for (int x= 0; x <= firstfree; ++x)
{
memcached_free(server_pool[x]);
- server_pool[x] = NULL;
+ server_pool[x]= NULL;
+ }
+
+ int error;
+ if ((error= pthread_mutex_destroy(&mutex)) != 0)
+ {
+ assert_vmsg(error != 0, "pthread_mutex_destroy() %s(%d)", strerror(error), error);
+ }
+
+ if ((error= pthread_cond_destroy(&cond)) != 0)
+ {
+ assert_vmsg(error != 0, "pthread_cond_destroy() %s", strerror(error));
}
- pthread_mutex_destroy(&mutex);
- pthread_cond_destroy(&cond);
delete [] server_pool;
if (_owns_master)
{
bool memcached_pool_st::init(uint32_t initial)
{
server_pool= new (std::nothrow) memcached_st *[size];
- if (not server_pool)
+ if (server_pool == NULL)
+ {
return false;
+ }
/*
Try to create the initial size of the pool. An allocation failure at
int unlock_error;
if ((unlock_error= pthread_mutex_unlock(&mutex)) != 0)
{
+ assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error));
}
if (thread_ret == ETIMEDOUT)
int unlock_error;
if ((unlock_error= pthread_mutex_unlock(&mutex)) != 0)
{
+ assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error));
}
return NULL;
if ((error= pthread_mutex_unlock(&mutex)) != 0)
{
+ assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error));
}
return ret;
/* we might have people waiting for a connection.. wake them up :-) */
if ((error= pthread_cond_broadcast(&cond)) != 0)
{
+ assert_vmsg(error != 0, "pthread_cond_broadcast() %s", strerror(error));
}
}
{
if ((error= pthread_mutex_unlock(&pool->mutex)) != 0)
{
+ assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error));
}
return rc;
}
if ((error= pthread_mutex_unlock(&pool->mutex)) != 0)
{
+ assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error));
}
return rc;
if ((error= pthread_mutex_unlock(&pool->mutex)) != 0)
{
+ assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error));
}
return MEMCACHED_SUCCESS;
#include <sys/wait.h>
#include <unistd.h>
-#include <libgearman/gearman.h>
-
#ifndef __INTEL_COMPILER
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
for (size_t x= 0 ; x < argc ; x++)
{
+ if (argv[x] == NULL)
+ {
+ break;
+ }
+
add_option(argv[x]);
}
bool is_error() const
{
- return _error.size();
+ return _error.size() ? true : false;
}
private: // Methods
{
std::stringstream arg_buffer;
- for (size_t x= _use_libtool ? 2 : 0;
- x < _argc and built_argv[x];
- ++x)
+ // Skip printing out the libtool reference
+ for (size_t x= _use_libtool ? 2 : 0; x < _argc; ++x)
{
- arg_buffer << built_argv[x] << " ";
+ if (built_argv[x])
+ {
+ arg_buffer << built_argv[x] << " ";
+ }
}
return arg_buffer.str();
#include <libtest/common.h>
+// @todo possibly have this code fork off so if it fails nothing goes bad
static test_return_t runner_code(libtest::Framework* frame,
test_st* run,
libtest::Timer& _timer)
try
{
_timer.reset();
- return_code= frame->runner()->run(run->test_fn, frame->creators_ptr());
+ return_code= frame->runner()->main(run->test_fn, frame->creators_ptr());
}
// Special case where check for the testing of the exception
// system.
test_return_t Collection::exec()
{
- if (test_success(_frame->runner()->pre(_pre, _frame->creators_ptr())))
+ if (test_success(_frame->runner()->setup(_pre, _frame->creators_ptr())))
{
for (test_st *run= _tests; run->name; run++)
{
#endif
}
- (void) _frame->runner()->post(_post, _frame->creators_ptr());
+ (void) _frame->runner()->teardown(_post, _frame->creators_ptr());
}
if (_failed == 0 and _skipped == 0 and _success)
for (size_t x= 0 ; x < argc ; x++)
{
+ if (argv[x] == NULL)
+ {
+ break;
+ }
+
add_option(argv[x]);
}
for (size_t x= 0 ; x < argc ; x++)
{
+ if (argv[x] == NULL)
+ {
+ break;
+ }
+
add_option(argv[x]);
}
#pragma once
#ifdef __cplusplus
+# include <cstdarg>
# include <cstddef>
+# include <cstdio>
# include <cstdlib>
# include <cstring>
-#include <cstdarg>
#else
+# include <stdarg.h>
+# include <stdbool.h>
# include <stddef.h>
+# include <stdio.h>
# include <stdlib.h>
-# include <stdbool.h>
# include <string.h>
-# include <stdarg.h>
#endif
-#include <alloca.h>
+#ifdef _WIN32
+# include <malloc.h>
+#else
+# include <alloca.h>
+#endif
#ifndef __PRETTY_FUNCTION__
# define __PRETTY_FUNCTION__ __func__
#endif
#ifndef FAIL
-# define FAIL(__message_format, ...)
+# define FAIL(__message_format, ...)
#endif
#ifndef SKIP
-# define SKIP(__message_format, ...)
+# define SKIP(__message_format, ...)
#endif
static inline bool valgrind_is_caller(void)
} \
} while (0)
+#define SKIP_IF_(__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) { \
+ SKIP(#__expression, buffer); \
+ } \
+ fprintf(stdout, "\n%s:%d: %s SKIP '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \
+ exit(EXIT_SKIP); \
+ } \
+} while (0)
+
#define ASSERT_TRUE(__expression) \
do \
{ \
ask++; \
char *buffer= (char*)alloca(sizeof(char) * ask); \
snprintf(buffer, ask, __VA_ARGS__); \
+ if (YATL_FULL) { \
+ FAIL("Assertion '%s' != NULL [ %s ]", #__expression, buffer);\
+ } \
fprintf(stderr, "\n%s:%d: %s Assertion '%s' != NULL [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer);\
exit(EXIT_FAILURE); \
} \
do \
{ \
if ((__expression) == NULL) { \
+ if (YATL_FULL) { \
+ FAIL("Assertion '%s' == NULL", #__expression,);\
+ } \
fprintf(stderr, "\n%s:%d: %s Assertion '%s' == NULL\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression,);\
exit(EXIT_FAILURE); \
} \
do \
{ \
if ((__expression) == NULL) { \
- size_t ask= snprintf(0, 0, __VA_ARGS__); \
- 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);\
- exit(EXIT_FAILURE); \
- } \
-} while (0)
-
-#define SKIP_IF_(__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) { \
- SKIP(#__expression, buffer); \
+ FAIL("Assertion '%s' == NULL [ %s ]", #__expression, buffer);\
} \
- fprintf(stdout, "\n%s:%d: %s SKIP '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \
- exit(EXIT_SKIP); \
+ fprintf(stderr, "\n%s:%d: %s Assertion '%s' == NULL [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer);\
+ exit(EXIT_FAILURE); \
} \
} while (0)
ask++; \
char *buffer= (char*)alloca(sizeof(char) * ask); \
snprintf(buffer, ask, __VA_ARGS__); \
+ if (YATL_FULL) { \
+ FAIL("Assertion '%s' [ %s ]", #__expression, buffer); \
+ } \
fprintf(stderr, "\n%s:%d: %s Assertion '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \
exit(EXIT_FAILURE); \
} \
do \
{ \
if ((__expected) != (__actual)) { \
+ if (YATL_FULL) { \
+ FAIL("Assertion '%s' != '%s'", #__expected, #__actual); \
+ } \
fprintf(stderr, "\n%s:%d: %s Assertion '%s' != '%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual); \
exit(EXIT_FAILURE); \
} \
ask++; \
char *buffer= (char*)alloca(sizeof(char) * ask); \
snprintf(buffer, ask, __VA_ARGS__); \
+ if (YATL_FULL) { \
+ FAIL("Assertion '%s' != '%s' [ %s ]", #__expected, #__actual, buffer); \
+ } \
fprintf(stderr, "\n%s:%d: %s Assertion '%s' != '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual, buffer); \
exit(EXIT_FAILURE); \
} \
size_t __actual_length; \
int ret= yatl_strcmp(__expected_str, __actual_str, &__expected_length, &__actual_length); \
if (ret) { \
+ if (YATL_FULL) { \
+ FAIL("Assertion '%.*s' != '%.*s'\n", \
+ (int)(__expected_length), (__expected_str), \
+ (int)__actual_length, (__actual_str)) ; \
+ } \
fprintf(stderr, "\n%s:%d: %s Assertion '%.*s' != '%.*s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, \
(int)(__expected_length), (__expected_str), \
(int)__actual_length, (__actual_str)) ; \
ask++; \
char *buffer= (char*)alloca(sizeof(char) * ask); \
ask= snprintf(buffer, ask, __VA_ARGS__); \
+ if (YATL_FULL) { \
+ FAIL("Assertion '%.*s' != '%.*s' [ %.*s ]", \
+ (int)(__expected_length), (__expected_str), \
+ (int)(__actual_length), (__actual_str), \
+ (int)(ask), buffer); \
+ } \
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), \
size_t __actual_length; \
int ret= yatl_strcmp(__expected_str, __actual_str, &__expected_length, &__actual_length); \
if (ret == 0) { \
+ if (YATL_FULL) { \
+ FAIL("Assertion '%.*s' == '%.*s'", \
+ (int)(__expected_length), (__expected_str), \
+ (int)__actual_length, (__actual_str)) ; \
+ } \
fprintf(stderr, "\n%s:%d: %s Assertion '%.*s' == '%.*s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, \
(int)(__expected_length), (__expected_str), \
(int)__actual_length, (__actual_str)) ; \
ask++; \
char *buffer= (char*)alloca(sizeof(char) * ask); \
ask= snprintf(buffer, ask, __VA_ARGS__); \
+ if (YATL_FULL) { \
+ FAIL("Assertion '%.*s' == '%.*s' [ %.*s ]", \
+ (int)(__expected_length), (__expected_str), \
+ (int)(__actual_length), (__actual_str), \
+ (int)(ask), buffer); \
+ } \
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), \
do \
{ \
if ((__expected) == (__actual)) { \
+ if (YATL_FULL) { \
+ FAIL("Assertion '%s' == '%s'", #__expected, #__actual); \
+ } \
fprintf(stderr, "\n%s:%d: %s Assertion '%s' == '%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual); \
exit(EXIT_FAILURE); \
} \
ask++; \
char *buffer= (char*)alloca(sizeof(char) * ask); \
snprintf(buffer, ask, __VA_ARGS__); \
+ if (YATL_FULL) { \
+ FAIL("Assertion '%s' == '%s' [ %s ]", #__expected, #__actual, buffer); \
+ } \
fprintf(stderr, "\n%s:%d: %s Assertion '%s' == '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual, buffer); \
exit(EXIT_FAILURE); \
} \
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); \
+ FAIL("Assertion '!%s' [ %s ]", #__expression, buffer); \
} \
fprintf(stderr, "\n%s:%d: %s Assertion '!%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \
exit(EXIT_FAILURE); \
for (size_t x= 0 ; x < argc ; x++)
{
+ if (argv[x] == NULL)
+ {
+ break;
+ }
+
add_option(argv[x]);
}
{
}
+test_return_t Runner::main(test_callback_fn* func, void *object)
+{
+ test_return_t ret;
+ try {
+ ret= run(func, object);
+ }
+ catch (libtest::__skipped e)
+ {
+ ret= TEST_SKIPPED;
+ }
+ catch (libtest::__failure e)
+ {
+ libtest::stream::make_cerr(e.file(), e.line(), e.func()) << e.what();
+ ret= TEST_FAILURE;
+ }
+ catch (libtest::__success)
+ {
+ ret= TEST_SUCCESS;
+ }
+ catch (libtest::fatal& e)
+ {
+ throw;
+ }
+ catch (std::exception& e)
+ {
+ libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what();
+ throw;
+ }
+ catch (...)
+ {
+ libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << "Unknown exception thrown";
+ throw;
+ }
+
+ return ret;
+}
+
+test_return_t Runner::setup(test_callback_fn* func, void *object)
+{
+ test_return_t ret;
+ try {
+ ret= pre(func, object);
+ }
+ catch (libtest::__skipped e)
+ {
+ ret= TEST_SKIPPED;
+ }
+ catch (libtest::__failure e)
+ {
+ libtest::stream::make_cout(e.file(), e.line(), e.func()) << e.what();
+ ret= TEST_FAILURE;
+ }
+ catch (libtest::__success)
+ {
+ ret= TEST_SUCCESS;
+ }
+ catch (libtest::fatal& e)
+ {
+ throw;
+ }
+ catch (std::exception& e)
+ {
+ libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what();
+ throw;
+ }
+ catch (...)
+ {
+ libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << "Unknown exception thrown";
+ throw;
+ }
+
+ return ret;
+}
+
+test_return_t Runner::teardown(test_callback_fn* func, void *object)
+{
+ test_return_t ret;
+ try {
+ ret= post(func, object);
+ }
+ catch (libtest::__skipped e)
+ {
+ ret= TEST_SKIPPED;
+ }
+ catch (libtest::__failure e)
+ {
+ libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what();
+ ret= TEST_FAILURE;
+ }
+ catch (libtest::__success)
+ {
+ ret= TEST_SUCCESS;
+ }
+ catch (libtest::fatal& e)
+ {
+ throw;
+ }
+ catch (std::exception& e)
+ {
+ libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << e.what();
+ throw;
+ }
+ catch (...)
+ {
+ libtest::stream::make_cerr(LIBYATL_DEFAULT_PARAM) << "Unknown exception thrown";
+ throw;
+ }
+
+ return ret;
+}
+
test_return_t Runner::flush(void*)
{
return TEST_SUCCESS;
{
if (func)
{
- try {
- return func(object);
- }
- catch (libtest::__skipped e)
- {
- return TEST_SKIPPED;
- }
- catch (libtest::__failure e)
- {
- libtest::stream::make_cerr(e.file(), e.line(), e.func()) << e.what();
- return TEST_FAILURE;
- }
- catch (libtest::__success)
- {
- return TEST_SUCCESS;
- }
+ return func(object);
}
return TEST_SUCCESS;
{
if (func)
{
- try {
- return func(object);
- }
- catch (libtest::__skipped e)
- {
- return TEST_SKIPPED;
- }
- catch (libtest::__failure e)
- {
- libtest::stream::make_cout(e.file(), e.line(), e.func()) << e.what();
- return TEST_FAILURE;
- }
- catch (libtest::__success)
- {
- return TEST_SUCCESS;
- }
+ return func(object);
}
return TEST_SUCCESS;
{
if (func)
{
- try {
- return func(object);
- }
- catch (libtest::__skipped e)
- {
- return TEST_SKIPPED;
- }
- catch (libtest::__failure e)
- {
- libtest::stream::make_cerr(e.file(), e.line(), e.func()) << e.what();
- return TEST_FAILURE;
- }
- catch (libtest::__success)
- {
- return TEST_SUCCESS;
- }
+ return func(object);
}
return TEST_SUCCESS;
}
+void Runner::set_servers(libtest::server_startup_st& arg)
+{
+ _servers= &arg;
+}
+
+bool Runner::check()
+{
+ return _servers ? _servers->check() : true;
+}
+
} // namespace libtest
*/
class Runner {
public:
- virtual test_return_t flush(void*);
- virtual test_return_t run(test_callback_fn* func, void *object);
- virtual test_return_t pre(test_callback_fn* func, void *object);
- virtual test_return_t post(test_callback_fn* func, void *object);
+ test_return_t main(test_callback_fn* func, void *object);
+ test_return_t setup(test_callback_fn* func, void *object);
+ test_return_t teardown(test_callback_fn* func, void *object);
Runner();
- void set_servers(libtest::server_startup_st& arg)
- {
- _servers= &arg;
- }
+ void set_servers(libtest::server_startup_st& arg);
- bool check()
- {
- return _servers ? _servers->check() : true;
- }
+ bool check();
virtual ~Runner() { }
+ virtual test_return_t flush(void*);
+ virtual test_return_t run(test_callback_fn* func, void *object);
+ virtual test_return_t pre(test_callback_fn* func, void *object);
+ virtual test_return_t post(test_callback_fn* func, void *object);
+
private:
libtest::server_startup_st* _servers;
};
if (pinged == false)
{
- Error << "ping(" << _app.pid() << ") wait: " << this_wait << " " << hostname() << ":" << port() << " run:" << _running << " " << error();
+#if 0
+ Error << "Failed to ping(" << _app.pid() << ") wait: " << this_wait << " " << hostname() << ":" << port() << " run:" << _running << " " << error();
+#endif
// 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))
for (Options::const_iterator iter= _options.begin(); iter != _options.end(); ++iter)
{
- if ((*iter).second.empty() == false)
- {
- app.add_option((*iter).first, (*iter).second);
- }
- else
+ if ((*iter).first.empty() == false)
{
- app.add_option((*iter).first);
+ if ((*iter).second.empty() == false)
+ {
+ app.add_option((*iter).first, (*iter).second);
+ }
+ else
+ {
+ app.add_option((*iter).first);
+ }
}
}
assert(magic_memory == MAGIC_MEMORY);
if (bool(getenv("LIBTEST_IN_GDB")) == false)
{
+ assert(sigismember(&set, SIGALRM));
assert(sigismember(&set, SIGABRT));
assert(sigismember(&set, SIGQUIT));
assert(sigismember(&set, SIGINT));
switch (sig)
{
+ case SIGALRM:
+ Error << "SIGALRM";
+ if (gdb_is_caller())
+ {
+ abort();
+ }
+ exit(EXIT_SKIP);
+
case SIGVTALRM:
Error << "SIGVTALRM was called";
context->unblock();
sigemptyset(&set);
if (bool(getenv("LIBTEST_IN_GDB")) == false)
{
+ sigaddset(&set, SIGALRM);
sigaddset(&set, SIGABRT);
sigaddset(&set, SIGQUIT);
sigaddset(&set, SIGINT);
sigaddset(&set, SIGVTALRM);
}
+ else
+ {
+ Out << "Inside of GDB, disabling signal handlers";
+ }
+
sigaddset(&set, SIGPIPE);
sigaddset(&set, SIGUSR2);
class Barrier
{
public:
- Barrier(uint32_t count):
+ explicit Barrier(uint32_t count):
_threshold(count),
_count(count),
_generation(0)
return TEST_SUCCESS;
}
+static test_return_t vchar_t_make_append_TEST(void *)
+{
+ libtest::vchar_t hostname;
+ libtest::vchar::make(hostname, 23);
+ libtest::vchar::append(hostname, ".com");
+ ASSERT_EQ(28, hostname.size());
+ ASSERT_EQ(0, hostname[27]);
+
+ return TEST_SUCCESS;
+}
+
static test_return_t vchar_t_compare_neg_TEST(void *)
{
libtest::vchar_t response;
test_st application_tests[] ={
{"vchar_t", 0, vchar_t_TEST },
+ {"vchar_t make() append()", 0, vchar_t_make_append_TEST },
{"vchar_t compare()", 0, vchar_t_compare_neg_TEST },
{"true", 0, application_true_BINARY },
{"gbd true --fubar", 0, application_gdb_true_BINARY },
#include "libtest/yatlcon.h"
#include <libtest/common.h>
+/* Use this for string generation */
+static const char ALPHANUMERICS[]=
+ "0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
+
+#define ALPHANUMERICS_SIZE (sizeof(ALPHANUMERICS)-1)
+
+static size_t get_alpha_num(void)
+{
+ return (size_t)random() % ALPHANUMERICS_SIZE;
+}
+
namespace libtest {
static std::string printer(const char *str, size_t length)
void make(libtest::vchar_t& arg, size_t length)
{
arg.reserve(length);
- for (uint32_t x= 0; x < length; x++)
+ for (uint32_t x= 0; x < length; ++x)
+ {
+ arg.push_back(ALPHANUMERICS[get_alpha_num()]);
+ }
+}
+
+void chomp(libtest::vchar_t& arg)
+{
+ while(arg.size())
{
- arg.push_back(char(x % 127));
+ if (arg.back() == 0)
+ {
+ arg.pop_back();
+ }
+ else
+ {
+ break;
+ }
}
}
{
fatal_message("UNABLE to allocate %s(%p)", ptr, ptr);
}
+
arg.push_back(new_ptr);
}
}
+void append(libtest::vchar_t& arg, const char* ptr)
+{
+ if (ptr)
+ {
+ size_t length= strlen(ptr);
+ ASSERT_TRUE(length);
+ arg.reserve(length);
+ do
+ {
+ arg.push_back(*ptr);
+ ++ptr;
+ } while (*ptr);
+
+ arg.push_back(0);
+ }
+}
+
} // namespace vchar
void make_vector(libtest::vchar_t& arg, const char *str, size_t length)
namespace vchar {
int compare(libtest::vchar_t& arg, const char *str, size_t length);
+void chomp(libtest::vchar_t& arg);
void make(libtest::vchar_t& arg);
void make(libtest::vchar_t& arg, size_t length);
void append(libtest::vchar_ptr_t& arg, const char*);
+void append(libtest::vchar_t& arg, const char*);
} // namespace vchar
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
-#serial 6
+#serial 7
AC_DEFUN([AX_CHECK_LIBRARY],
[AC_ARG_VAR($1[_CPPFLAGS],[C preprocessor flags for ]$1[ headers])
AC_SUBST($1[_LIB],[-l]$3)
ifelse([$4], , :, [$4])],
[ifelse([$5], , :, [$5])])
- AM_CONDITIONAL([HAVE_]$1,[test "$]AS_TR_SH([ax_cv_have_]$1)[" = "yes"])
])
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#serial 4
+#serial 5
AC_DEFUN([AX_DEBUG],
[AC_PREREQ([2.63])dnl
[AS_HELP_STRING([--enable-debug],
[Add debug code/turns off optimizations (yes|no) @<:@default=no@:>@])],
[ax_enable_debug=yes
- AC_DEFINE(DEBUG,[1],[Define to 1 to enable debugging code.])],
+ AC_DEFINE([DEBUG],[1],[Define to 1 to enable debugging code.])
+ AX_CHECK_LIBRARY([MCHECK],[mcheck.h],[mcheck],[AX_APPEND_LINK_FLAGS([-lmcheck])])],
[ax_enable_debug=no
- AC_DEFINE(DEBUG, [ 0 ], [Define to 1 to enable debugging code.])])
+ AC_SUBST([MCHECK])
+ AC_DEFINE([DEBUG],[0],[Define to 1 to enable debugging code.])])
AC_MSG_CHECKING([for debug])
AC_MSG_RESULT([$ax_enable_debug])
- ])
+ AM_CONDITIONAL([DEBUG],[test "x${ax_enable_debug}" = "xyes"])])
-#serial 1
+#serial 2
AC_DEFUN([AX_DLOPEN],
- [AS_IF([test "x$enable_shared" = xyes],
- [AX_CHECK_LIBRARY([DL],[dlfcn.h],[dl],
- [AC_DEFINE([HAVE_LIBDL],[1],[Have dlopen])
- AC_CHECK_LIB([dl],[dlopen],[AC_DEFINE([HAVE_DLOPEN],[1],[Have dlopen])])
- AC_CHECK_LIB([dl],[dladdr],[AC_DEFINE([HAVE_DLADDR],[1],[Have dladdr])])])],
- [AM_CONDITIONAL([HAVE_DL],false)])
- ])
+ [AS_IF([test "x$enable_shared" = xyes],
+ [AX_CHECK_LIBRARY([DL],[dlfcn.h],[dl],
+ [AC_DEFINE([HAVE_LIBDL],[1],[Have dlopen])
+ AC_CHECK_LIB([dl],[dlopen],[AC_DEFINE([HAVE_DLOPEN],[1],[Have dlopen])])
+ AC_CHECK_LIB([dl],[dladdr],[AC_DEFINE([HAVE_DLADDR],[1],[Have dladdr])])])])
+ ])
AC_DEFUN([_HARDEN_CC_COMPILER_FLAGS],
[AC_LANG_PUSH([C])dnl
- _APPEND_COMPILE_FLAGS_ERROR([-g])
AS_IF([test "x$ax_enable_debug" = xyes],
- [_APPEND_COMPILE_FLAGS_ERROR([-ggdb])
- _APPEND_COMPILE_FLAGS_ERROR([-O0])],
- [_APPEND_COMPILE_FLAGS_ERROR([-O2])])
+ [CFLAGS=''
+ _APPEND_COMPILE_FLAGS_ERROR([-ggdb])
+ _APPEND_COMPILE_FLAGS_ERROR([-g])
+ _APPEND_COMPILE_FLAGS_ERROR([-O0])],
+ [_APPEND_COMPILE_FLAGS_ERROR([-g])
+ _APPEND_COMPILE_FLAGS_ERROR([-O2])])
_APPEND_COMPILE_FLAGS_ERROR([-Wno-pragmas])
_APPEND_COMPILE_FLAGS_ERROR([-Wall])
_APPEND_COMPILE_FLAGS_ERROR([-floop-parallelize-all])
_APPEND_COMPILE_FLAGS_ERROR([-fwrapv])
_APPEND_COMPILE_FLAGS_ERROR([-fmudflapt])
+ _APPEND_COMPILE_FLAGS_ERROR([-pipe])
AS_IF([test "x$ax_enable_debug" = xno],
[AS_IF([test "x$ac_cv_vcs_checkout" = xyes],
[_APPEND_COMPILE_FLAGS_ERROR([-fstack-check])
AS_IF([test "x$ac_c_gcc_recent" = xyes],
[_APPEND_COMPILE_FLAGS_ERROR([-D_FORTIFY_SOURCE=2])
- _APPEND_COMPILE_FLAGS_ERROR([-Wstack-protector])
+# _APPEND_COMPILE_FLAGS_ERROR([-Wstack-protector])
_APPEND_COMPILE_FLAGS_ERROR([-fstack-protector])
- _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector-all])
+# _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector-all])
])])])
AS_IF([test "x$ac_cv_vcs_checkout" = xyes],
[AC_LANG_PUSH([C++])
AC_REQUIRE([_APPEND_COMPILE_FLAGS_ERROR])
- _APPEND_COMPILE_FLAGS_ERROR([-g])
- AS_IF([test "x$ax_enable_debug" = xyes],
- [_APPEND_COMPILE_FLAGS_ERROR([-O0])
- _APPEND_COMPILE_FLAGS_ERROR([-ggdb])],
- [_APPEND_COMPILE_FLAGS_ERROR([-O2])])
+ AS_IF([test "x$ax_enable_debug" = xyes],
+ [CXXFLAGS=''
+ _APPEND_COMPILE_FLAGS_ERROR([-ggdb])
+ _APPEND_COMPILE_FLAGS_ERROR([-g])
+ _APPEND_COMPILE_FLAGS_ERROR([-O0])],
+ [_APPEND_COMPILE_FLAGS_ERROR([-g])
+ _APPEND_COMPILE_FLAGS_ERROR([-O2])])
- AS_IF([test "x$ac_cv_vcs_checkout" = xyes],
- [_APPEND_COMPILE_FLAGS_ERROR([-fstack-check])],
- [_APPEND_COMPILE_FLAGS_ERROR([-Wno-pragmas])])
+ AS_IF([test "x$ac_cv_vcs_checkout" = xyes],
+ [_APPEND_COMPILE_FLAGS_ERROR([-fstack-check])],
+ [_APPEND_COMPILE_FLAGS_ERROR([-Wno-pragmas])])
- _APPEND_COMPILE_FLAGS_ERROR([-Wall])
- _APPEND_COMPILE_FLAGS_ERROR([-Wextra])
- _APPEND_COMPILE_FLAGS_ERROR([-Wunknown-pragmas])
- _APPEND_COMPILE_FLAGS_ERROR([-Wthis-test-should-fail])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wall])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wextra])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wunknown-pragmas])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wthis-test-should-fail])
# Anything below this comment please keep sorted.
- _APPEND_COMPILE_FLAGS_ERROR([--param=ssp-buffer-size=1])
+ _APPEND_COMPILE_FLAGS_ERROR([--param=ssp-buffer-size=1])
# _APPEND_COMPILE_FLAGS_ERROR([-Wmissing-format-attribute])
- _APPEND_COMPILE_FLAGS_ERROR([-Wno-attributes])
- _APPEND_COMPILE_FLAGS_ERROR([-Waddress])
- _APPEND_COMPILE_FLAGS_ERROR([-Warray-bounds])
- _APPEND_COMPILE_FLAGS_ERROR([-Wchar-subscripts])
- _APPEND_COMPILE_FLAGS_ERROR([-Wcomment])
- _APPEND_COMPILE_FLAGS_ERROR([-Wctor-dtor-privacy])
- _APPEND_COMPILE_FLAGS_ERROR([-Wfloat-equal])
- _APPEND_COMPILE_FLAGS_ERROR([-Wformat=2])
- _APPEND_COMPILE_FLAGS_ERROR([-Wmaybe-uninitialized])
- _APPEND_COMPILE_FLAGS_ERROR([-Wmissing-field-initializers])
- _APPEND_COMPILE_FLAGS_ERROR([-Wlogical-op])
- _APPEND_COMPILE_FLAGS_ERROR([-Wnon-virtual-dtor])
- _APPEND_COMPILE_FLAGS_ERROR([-Wnormalized=id])
- _APPEND_COMPILE_FLAGS_ERROR([-Woverloaded-virtual])
- _APPEND_COMPILE_FLAGS_ERROR([-Wpointer-arith])
- AS_IF([test "x$MINGW" = xyes],
- [_APPEND_COMPILE_FLAGS_ERROR([-Wno-suggest-attribute=const])
- _APPEND_COMPILE_FLAGS_ERROR([-Wno-missing-noreturn])
- _APPEND_COMPILE_FLAGS_ERROR([-Wmissing-noreturn])
- _APPEND_COMPILE_FLAGS_ERROR([-Wno-suggest-attribute=noreturn])
- _APPEND_COMPILE_FLAGS_ERROR([-Wno-error=suggest-attribute=noreturn])
- _APPEND_COMPILE_FLAGS_ERROR([-Wno-redundant-decls])],
- [_APPEND_COMPILE_FLAGS_ERROR([-Wredundant-decls])])
- _APPEND_COMPILE_FLAGS_ERROR([-Wshadow])
- _APPEND_COMPILE_FLAGS_ERROR([-Wshorten-64-to-32])
- _APPEND_COMPILE_FLAGS_ERROR([-Wsign-compare])
- _APPEND_COMPILE_FLAGS_ERROR([-Wstrict-overflow=1])
- _APPEND_COMPILE_FLAGS_ERROR([-Wswitch-enum])
- _APPEND_COMPILE_FLAGS_ERROR([-Wundef])
- _APPEND_COMPILE_FLAGS_ERROR([-Wc++11-compat])
- _APPEND_COMPILE_FLAGS_ERROR([-Wunused])
- _APPEND_COMPILE_FLAGS_ERROR([-Wunused-result])
- _APPEND_COMPILE_FLAGS_ERROR([-Wunused-variable])
- _APPEND_COMPILE_FLAGS_ERROR([-Wwrite-strings])
- _APPEND_COMPILE_FLAGS_ERROR([-Wformat-security])
- _APPEND_COMPILE_FLAGS_ERROR([-floop-parallelize-all])
- _APPEND_COMPILE_FLAGS_ERROR([-fwrapv])
- _APPEND_COMPILE_FLAGS_ERROR([-fmudflapt])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wno-attributes])
+ _APPEND_COMPILE_FLAGS_ERROR([-Waddress])
+ _APPEND_COMPILE_FLAGS_ERROR([-Warray-bounds])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wchar-subscripts])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wcomment])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wctor-dtor-privacy])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wfloat-equal])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wformat=2])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wmaybe-uninitialized])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wmissing-field-initializers])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wlogical-op])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wnon-virtual-dtor])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wnormalized=id])
+ _APPEND_COMPILE_FLAGS_ERROR([-Woverloaded-virtual])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wpointer-arith])
+ AS_IF([test "x$MINGW" = xyes],
+ [_APPEND_COMPILE_FLAGS_ERROR([-Wno-suggest-attribute=const])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wno-missing-noreturn])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wmissing-noreturn])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wno-suggest-attribute=noreturn])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wno-error=suggest-attribute=noreturn])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wno-redundant-decls])],
+ [_APPEND_COMPILE_FLAGS_ERROR([-Wredundant-decls])])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wshadow])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wshorten-64-to-32])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wsign-compare])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wstrict-overflow=1])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wswitch-enum])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wundef])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wc++11-compat])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wunused])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wunused-result])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wunused-variable])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wwrite-strings])
+ _APPEND_COMPILE_FLAGS_ERROR([-Wformat-security])
+ _APPEND_COMPILE_FLAGS_ERROR([-floop-parallelize-all])
+ _APPEND_COMPILE_FLAGS_ERROR([-fwrapv])
+ _APPEND_COMPILE_FLAGS_ERROR([-fmudflapt])
+ _APPEND_COMPILE_FLAGS_ERROR([-pipe])
- AS_IF([test "x$ax_enable_debug" = xno],
- [AS_IF([test "x$ac_cv_vcs_checkout" = xyes],
- [_APPEND_COMPILE_FLAGS_ERROR([-fstack-check])
- AS_IF([test "x$ac_c_gcc_recent" = xyes],
- [_APPEND_COMPILE_FLAGS_ERROR([-D_FORTIFY_SOURCE=2])
- _APPEND_COMPILE_FLAGS_ERROR([-Wstack-protector])
- _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector])
- _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector-all])
- ])])])
+ AS_IF([test "x$ax_enable_debug" = xno],
+ [AS_IF([test "x$ac_cv_vcs_checkout" = xyes],
+ [_APPEND_COMPILE_FLAGS_ERROR([-fstack-check])
+ AS_IF([test "x$ac_c_gcc_recent" = xyes],
+ [_APPEND_COMPILE_FLAGS_ERROR([-D_FORTIFY_SOURCE=2])
+# _APPEND_COMPILE_FLAGS_ERROR([-Wstack-protector])
+ _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector])
+# _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector-all])
+ ])])])
- AS_IF([test "x$ac_cv_warnings_as_errors" = xyes],
- [AX_APPEND_FLAG([-Werror])])
- AC_LANG_POP([C++])
+ AS_IF([test "x$ac_cv_warnings_as_errors" = xyes],
+ [AX_APPEND_FLAG([-Werror])])
+ AC_LANG_POP([C++])
])
- AC_DEFUN([_CC_OTHER_FLAGS],
- [AC_REQUIRE([_APPEND_COMPILE_FLAGS_ERROR])
-
- AC_LANG_PUSH([C])
- _APPEND_COMPILE_FLAGS_ERROR([-pipe])
- AC_LANG_POP([C])
- ])
-
# All of the heavy lifting happens in _HARDEN_LINKER_FLAGS,
-# _HARDEN_CC_COMPILER_FLAGS, _HARDEN_CXX_COMPILER_FLAGS, _CC_OTHER_FLAGS
+# _HARDEN_CC_COMPILER_FLAGS, _HARDEN_CXX_COMPILER_FLAGS
AC_DEFUN([AX_HARDEN_COMPILER_FLAGS],
[AC_PREREQ([2.63])dnl
AC_REQUIRE([_WARNINGS_AS_ERRORS])
AC_REQUIRE([_HARDEN_LINKER_FLAGS])
AC_REQUIRE([_HARDEN_CC_COMPILER_FLAGS])
AC_REQUIRE([_HARDEN_CXX_COMPILER_FLAGS])
- AC_REQUIRE([_CC_OTHER_FLAGS])
])
check_PROGRAMS+= tests/memslap
noinst_PROGRAMS+= tests/memslap
+test-memslap: tests/memslap
+ @tests/memslap
+
+gdb-memslap: tests/memslap
+ @$(GDB_COMMAND) tests/memslap
+
tests_memdump_SOURCES= tests/memdump.cc
tests_memdump_CXXFLAGS= $(AM_CXXFLAGS) $(NO_EFF_CXX)
EXTRA_tests_memdump_DEPENDENCIES= clients/memdump
{0, 0, (test_callback_fn*)0}
};
-test_st memcached_server_add_tests[] ={
+test_st memcached_server_add_TESTS[] ={
{"memcached_server_add(\"\")", false, (test_callback_fn*)memcached_server_add_empty_test },
{"memcached_server_add(NULL)", false, (test_callback_fn*)memcached_server_add_null_test },
+ {"memcached_server_add(many)", false, (test_callback_fn*)memcached_server_many_TEST },
+ {"memcached_server_add(many weighted)", false, (test_callback_fn*)memcached_server_many_weighted_TEST },
{0, 0, (test_callback_fn*)0}
};
{"basic", 0, 0, basic_tests},
{"hsieh_availability", 0, 0, hsieh_availability},
{"murmur_availability", 0, 0, murmur_availability},
- {"memcached_server_add", 0, 0, memcached_server_add_tests},
+ {"memcached_server_add", (test_callback_fn*)memcached_servers_reset_SETUP, 0, memcached_server_add_TESTS},
+ {"memcached_server_add(MEMCACHED_DISTRIBUTION_CONSISTENT)", (test_callback_fn*)memcached_servers_reset_MEMCACHED_DISTRIBUTION_CONSISTENT_SETUP, 0, memcached_server_add_TESTS},
+ {"memcached_server_add(MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED)", (test_callback_fn*)memcached_servers_reset_MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED_SETUP, 0, memcached_server_add_TESTS},
{"block", 0, 0, tests},
{"binary", (test_callback_fn*)pre_binary, 0, tests},
{"nonblock", (test_callback_fn*)pre_nonblock, 0, tests},
static test_return_t pre_sasl(memcached_st *)
{
- if (LIBMEMCACHED_WITH_SASL_SUPPORT == 0)
- {
- return TEST_SKIPPED;
- }
+ SKIP_IF(true);
+#if 0
+ SKIP_IF_(true, "currently we are not testing sasl support");
+#endif
+ SKIP_IF(LIBMEMCACHED_WITH_SASL_SUPPORT == 0);
return TEST_SUCCESS;
}
*/
#include <mem_config.h>
-#include <libtest/test.hpp>
+#include <libtest/yatl.h>
+
+#include <string>
using namespace libtest;
#include <tests/server_add.h>
-test_return_t memcached_server_add_null_test(memcached_st*)
+static std::string random_hostname()
{
- memcached_st *memc= memcached_create(NULL);
+ libtest::vchar_t hostname;
+ libtest::vchar::make(hostname, 23);
+ libtest::vchar::append(hostname, ".com");
- test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, NULL, 0));
+ return std::string(&hostname[0]);
+}
- memcached_free(memc);
+test_return_t memcached_server_add_null_test(memcached_st* memc)
+{
+ ASSERT_EQ(0, memcached_server_count(memc));
+
+ test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, NULL, 0));
return TEST_SUCCESS;
}
-test_return_t memcached_server_add_empty_test(memcached_st*)
+test_return_t memcached_server_add_empty_test(memcached_st* memc)
{
- memcached_st *memc= memcached_create(NULL);
+ ASSERT_EQ(0, memcached_server_count(memc));
test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, "", 0));
- memcached_free(memc);
+ return TEST_SUCCESS;
+}
+
+test_return_t memcached_server_many_TEST(memcached_st* memc)
+{
+ ASSERT_EQ(0, memcached_server_count(memc));
+
+ in_port_t base_port= 5555;
+ for (in_port_t x= 0; x < 100; ++x)
+ {
+ std::string hostname(random_hostname());
+ ASSERT_TRUE(hostname.size());
+ test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, hostname.c_str(), base_port +x));
+ }
+
+ return TEST_SUCCESS;
+}
+
+test_return_t memcached_server_many_weighted_TEST(memcached_st* memc)
+{
+ SKIP_IF(true);
+ ASSERT_EQ(0, memcached_server_count(memc));
+
+ in_port_t base_port= 5555;
+ for (in_port_t x= 0; x < 100; ++x)
+ {
+ std::string hostname(random_hostname());
+ ASSERT_TRUE(hostname.size());
+ test_compare(MEMCACHED_SUCCESS, memcached_server_add_with_weight(memc, hostname.c_str(), base_port +x, random() % 10));
+ }
return TEST_SUCCESS;
}
return TEST_SUCCESS;
}
+test_return_t memcached_servers_reset_SETUP(memcached_st *memc)
+{
+ memcached_servers_reset(memc);
+ test_compare(0U, memcached_server_count(memc));
+ return TEST_SUCCESS;
+}
+
+test_return_t memcached_servers_reset_MEMCACHED_DISTRIBUTION_CONSISTENT_SETUP(memcached_st *memc)
+{
+ test_compare(TEST_SUCCESS, memcached_servers_reset_SETUP(memc));
+
+ test_compare(MEMCACHED_SUCCESS, memcached_behavior_set_distribution(memc, MEMCACHED_DISTRIBUTION_CONSISTENT));
+ test_compare(memcached_behavior_get_distribution(memc), MEMCACHED_DISTRIBUTION_CONSISTENT);
+
+ return TEST_SUCCESS;
+}
+
+test_return_t memcached_servers_reset_MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED_SETUP(memcached_st *memc)
+{
+ test_compare(TEST_SUCCESS, memcached_servers_reset_SETUP(memc));
+ ASSERT_EQ(0U, memcached_server_count(0));
+
+ test_compare(MEMCACHED_SUCCESS, memcached_behavior_set_distribution(memc, MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED));
+ test_compare(memcached_behavior_get_distribution(memc), MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED);
+
+ return TEST_SUCCESS;
+}
+
test_return_t pre_behavior_ketama(memcached_st *memc)
{
test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA, 1));
test_return_t pre_settimer(memcached_st*);
test_return_t pre_unix_socket(memcached_st*);
test_return_t pre_buffer(memcached_st*);
+test_return_t memcached_servers_reset_MEMCACHED_DISTRIBUTION_CONSISTENT_SETUP(memcached_st *memc);
+test_return_t memcached_servers_reset_MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED_SETUP(memcached_st *memc);
+test_return_t memcached_servers_reset_SETUP(memcached_st *memc);
{
uint64_t* counter= (uint64_t*)context;
unsigned long number_value= strtoul(value, (char **)NULL, 10);
- if (number_value == ULONG_MAX)
- {
- return MEMCACHED_FAILURE;
- }
+ ASSERT_NEQ(number_value, ULONG_MAX);
*counter= *counter +number_value;
}
for (uint32_t x= 0; x < memcached_dump_TEST2_COUNT; x++)
{
char key[1024];
-
int length= snprintf(key, sizeof(key), "%s%u", __func__, x);
- test_true(length > 0);
+ ASSERT_TRUE(length > 0);
test_compare(MEMCACHED_SUCCESS,
memcached_set(memc, key, length,
memcached_quit(memc);
uint64_t counter= 0;
- test_compare(MEMCACHED_SUCCESS,
- memcached_stat_execute(memc, NULL, item_counter, &counter));
- test_true(counter);
+ ASSERT_EQ(MEMCACHED_SUCCESS,
+ memcached_stat_execute(memc, NULL, item_counter, &counter));
+ ASSERT_TRUE(counter);
return TEST_SUCCESS;
}
if (func)
{
test_true(container);
- try {
- ret= func(&memc);
- }
- catch (std::exception& e)
- {
- libtest::Error << e.what();
- ret= TEST_FAILURE;
- }
+ ret= func(&memc);
}
return ret;
test_return_t memcached_server_add_null_test(memcached_st*);
test_return_t memcached_server_add_empty_test(memcached_st*);
+test_return_t memcached_server_many_TEST(memcached_st*);
+test_return_t memcached_server_many_weighted_TEST(memcached_st*);