From: Brian Aker Date: Fri, 3 May 2013 07:36:06 +0000 (-0400) Subject: Update libtest. X-Git-Tag: 1.0.18~24^2~4 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=a07e53df4cd8d1e215a49eeac5d5d06fa0a50fb4;p=m6w6%2Flibmemcached Update libtest. --- diff --git a/Makefile.am b/Makefile.am index 6a851b50..cc65cb78 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,6 +19,7 @@ noinst_PROGRAMS = include_HEADERS = nobase_include_HEADERS = check_PROGRAMS = +check_LTLIBRARIES= EXTRA_HEADERS = BUILT_SOURCES= EXTRA_DIST= diff --git a/clients/memcapable.cc b/clients/memcapable.cc index b38cf311..f9145206 100644 --- a/clients/memcapable.cc +++ b/clients/memcapable.cc @@ -110,9 +110,13 @@ static struct addrinfo *lookuphost(const char *hostname, const char *port) if (error != 0) { if (error != EAI_SYSTEM) + { fprintf(stderr, "getaddrinfo(): %s\n", gai_strerror(error)); + } else + { perror("getaddrinfo()"); + } } return ai; @@ -249,7 +253,7 @@ static enum test_return ensure(bool val, const char *expression, const char *fil { if (verbose) { - fprintf(stderr, "\n%s:%d: %s", file, line, expression); + fprintf(stdout, "\n%s:%d: %s", file, line, expression); } if (do_core) @@ -334,7 +338,7 @@ static enum test_return retry_read(void *buf, size_t len) ssize_t nr= timeout_io_op(sock, POLLIN, ((char*) buf) + offset, len - offset); switch (nr) { case -1 : - fprintf(stderr, "Errno: %d %s\n", get_socket_errno(), strerror(errno)); + fprintf(stderr, "Errno: %d %s\n", get_socket_errno(), strerror(errno)); verify(get_socket_errno() == EINTR || get_socket_errno() == EAGAIN); break; @@ -2197,12 +2201,24 @@ int main(int argc, char **argv) reconnect= true; ++failed; if (verbose) + { fprintf(stderr, "\n"); + } } else if (ret == TEST_PASS_RECONNECT) + { reconnect= true; + } + + if (ret == TEST_FAIL) + { + fprintf(stderr, "%s\n", status_msg[ret]); + } + else + { + fprintf(stdout, "%s\n", status_msg[ret]); + } - fprintf(stderr, "%s\n", status_msg[ret]); if (reconnect) { closesocket(sock); diff --git a/libtest/collection.cc b/libtest/collection.cc index 86e7f864..2f1cba31 100644 --- a/libtest/collection.cc +++ b/libtest/collection.cc @@ -51,6 +51,9 @@ static test_return_t runner_code(libtest::Framework* frame, try { _timer.reset(); + assert(frame); + assert(frame->runner()); + assert(run->test_fn); return_code= frame->runner()->main(run->test_fn, frame->creators_ptr()); } // Special case where check for the testing of the exception diff --git a/libtest/dns.cc b/libtest/dns.cc index 0becfc99..75a5bbfb 100644 --- a/libtest/dns.cc +++ b/libtest/dns.cc @@ -46,10 +46,14 @@ namespace libtest { bool lookup(const char* host) { bool success= false; - if (host) + assert(host and host[0]); + if (host and host[0]) { - assert(host); struct addrinfo *addrinfo= NULL; + struct addrinfo hints; + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype= SOCK_STREAM; + hints.ai_protocol= IPPROTO_TCP; int limit= 5; while (--limit and success == false) @@ -61,7 +65,7 @@ bool lookup(const char* host) } int ret; - if ((ret= getaddrinfo(host, NULL, NULL, &addrinfo)) == 0) + if ((ret= getaddrinfo(host, "echo", &hints, &addrinfo)) == 0) { success= true; break; @@ -92,6 +96,11 @@ bool lookup(const char* host) bool check_dns() { + if (valgrind_is_caller()) + { + return false; + } + if (lookup("exist.gearman.info") == false) { return false; diff --git a/libtest/framework.cc b/libtest/framework.cc index 92aacfee..2c9ba74b 100644 --- a/libtest/framework.cc +++ b/libtest/framework.cc @@ -107,47 +107,50 @@ void Framework::exec() iter != _collection.end() and (_signal.is_shutdown() == false); ++iter) { - if (_only_run.empty() == false and - fnmatch(_only_run.c_str(), (*iter)->name(), 0)) + if (*iter) { - continue; - } - - _total++; + if (_only_run.empty() == false and + fnmatch(_only_run.c_str(), (*iter)->name(), 0)) + { + continue; + } - try { - switch ((*iter)->exec()) + _total++; + + try { + switch ((*iter)->exec()) + { + case TEST_FAILURE: + _failed++; + break; + + case TEST_SKIPPED: + _skipped++; + break; + + // exec() can return SUCCESS, but that doesn't mean that some tests did + // not fail or get skipped. + case TEST_SUCCESS: + _success++; + break; + } + } + catch (const libtest::fatal& e) { - case TEST_FAILURE: _failed++; - break; - - case TEST_SKIPPED: - _skipped++; - break; - - // exec() can return SUCCESS, but that doesn't mean that some tests did - // not fail or get skipped. - case TEST_SUCCESS: - _success++; - break; + stream::cerr(e.file(), e.line(), e.func()) << e.what(); + } + catch (const libtest::disconnected& e) + { + _failed++; + Error << "Unhandled disconnection occurred:" << e.what(); + throw; + } + catch (...) + { + _failed++; + throw; } - } - catch (const libtest::fatal& e) - { - _failed++; - stream::cerr(e.file(), e.line(), e.func()) << e.what(); - } - catch (const libtest::disconnected& e) - { - _failed++; - Error << "Unhandled disconnection occurred:" << e.what(); - throw; - } - catch (...) - { - _failed++; - throw; } } diff --git a/libtest/has.cc b/libtest/has.cc index b957bc6a..2d9abf6b 100644 --- a/libtest/has.cc +++ b/libtest/has.cc @@ -45,13 +45,6 @@ namespace libtest { bool has_libmemcached_sasl(void) { -#if defined(LIBMEMCACHED_WITH_SASL_SUPPORT) && LIBMEMCACHED_WITH_SASL_SUPPORT - if (LIBMEMCACHED_WITH_SASL_SUPPORT) - { - return true; - } -#endif - return false; } @@ -192,7 +185,6 @@ bool has_memcached() { initialize_memcached_binary(); - if (memcached_binary_path[0]) if (memcached_binary_path[0] and (strlen(memcached_binary_path) > 0)) { return true; @@ -213,45 +205,6 @@ const char* memcached_binary() return NULL; } -static char memcached_sasl_binary_path[FILENAME_MAX]; - -static void initialize_has_memcached_sasl() -{ - memcached_sasl_binary_path[0]= 0; - -#if defined(MEMCACHED_BINARY) && defined(HAVE_MEMCACHED_BINARY) && HAVE_MEMCACHED_BINARY - if (HAVE_MEMCACHED_BINARY) - { - std::stringstream arg_buffer; - - char *getenv_ptr; - if (bool((getenv_ptr= getenv("PWD"))) and strcmp(MEMCACHED_BINARY, "memcached/memcached") == 0) - { - arg_buffer << getenv_ptr; - arg_buffer << "/"; - } - arg_buffer << MEMCACHED_BINARY; - - if (access(arg_buffer.str().c_str(), X_OK) == 0) - { - strncpy(memcached_sasl_binary_path, arg_buffer.str().c_str(), FILENAME_MAX); - } - } -#endif -} - -bool has_memcached_sasl() -{ - initialize_has_memcached_sasl(); - - if (memcached_sasl_binary_path[0] and (strlen(memcached_sasl_binary_path) > 0)) - { - return true; - } - - return false; -} - const char *gearmand_binary() { #if defined(GEARMAND_BINARY) diff --git a/libtest/http.cc b/libtest/http.cc index c6caa09f..29873dc6 100644 --- a/libtest/http.cc +++ b/libtest/http.cc @@ -194,7 +194,7 @@ bool HEAD::execute() #if defined(HAVE_LIBCURL) && HAVE_LIBCURL if (HAVE_LIBCURL) { - CURL *curl= curl_easy_init();; + CURL *curl= curl_easy_init(); init(curl, url()); diff --git a/libtest/include.am b/libtest/include.am index 97991375..4d1d8428 100644 --- a/libtest/include.am +++ b/libtest/include.am @@ -109,18 +109,12 @@ noinst_HEADERS+= libtest/visibility.h noinst_HEADERS+= libtest/wait.h noinst_HEADERS+= libtest/yatl.h -noinst_LTLIBRARIES+= libtest/libtest.la +check_LTLIBRARIES+= libtest/libtest.la libtest_libtest_la_CXXFLAGS= EXTRA_libtest_libtest_la_DEPENDENCIES= libtest_libtest_la_LIBADD= libtest_libtest_la_SOURCES= -if BUILDING_LIBMEMCACHED -libtest_libtest_la_LIBADD+= libmemcached/libmemcached.la -else -libtest_libtest_la_CXXFLAGS+= @LIBMEMCACHED_CFLAGS@ -libtest_libtest_la_LIBADD+= @LIBMEMCACHED_LIB@ -endif libtest_libtest_la_SOURCES+= libtest/alarm.cc libtest_libtest_la_SOURCES+= libtest/binaries.cc diff --git a/libtest/run.gdb b/libtest/run.gdb index 25dcdd53..c35ab767 100644 --- a/libtest/run.gdb +++ b/libtest/run.gdb @@ -2,5 +2,6 @@ set logging on set logging overwrite on set environment LIBTEST_IN_GDB=1 #set ASAN_OPTIONS=abort_on_error=1 +handle SIGVTALRM stop run thread apply all bt diff --git a/libtest/unittest.cc b/libtest/unittest.cc index 59351762..bbb56c66 100644 --- a/libtest/unittest.cc +++ b/libtest/unittest.cc @@ -960,6 +960,12 @@ static test_return_t default_port_TEST(void *) return TEST_SUCCESS; } +static test_return_t check_for_VALGRIND(void *) +{ + test_skip_valgrind(); + return TEST_SUCCESS; +} + static test_return_t check_for_gearman(void *) { test_skip(true, HAVE_LIBGEARMAN); @@ -1206,7 +1212,7 @@ collection_st collection[] ={ {"fatal", disable_fatal_exception, enable_fatal_exception, fatal_message_TESTS }, {"number_of_cpus()", 0, 0, number_of_cpus_TESTS }, {"create_tmpfile()", 0, 0, create_tmpfile_TESTS }, - {"dns", 0, 0, dns_TESTS }, + {"dns", check_for_VALGRIND, 0, dns_TESTS }, {"libtest::Timer", 0, 0, timer_TESTS }, {0, 0, 0, 0} }; diff --git a/tests/memcapable.cc b/tests/memcapable.cc index d494a2f8..4e7c957d 100644 --- a/tests/memcapable.cc +++ b/tests/memcapable.cc @@ -47,14 +47,16 @@ using namespace libtest; #ifndef __INTEL_COMPILER -#pragma GCC diagnostic ignored "-Wstrict-aliasing" +# pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif static std::string executable; static test_return_t quiet_test(void *) { - const char *args[]= { "-q", 0 }; + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "%d", int(get_free_port())); + const char *args[]= { "-p", buffer, "-q", 0 }; test_compare(EXIT_FAILURE, exec_cmdline(executable, args, true)); @@ -105,7 +107,7 @@ collection_st collection[] ={ {0, 0, 0, 0} }; -static void *world_create(server_startup_st& servers, test_return_t& error) +static void *world_create(server_startup_st& servers, test_return_t&) { SKIP_UNLESS(libtest::has_memcached());