From: Michael Wallner Date: Tue, 21 Jan 2020 11:49:50 +0000 (+0100) Subject: tests: run memcached verbosely, catch output and show it on failure X-Git-Tag: pre_cmake~28 X-Git-Url: https://git.m6w6.name/?p=awesomized%2Flibmemcached;a=commitdiff_plain;h=b220134a312e2a488810abfef510f5dbf59078a4 tests: run memcached verbosely, catch output and show it on failure --- diff --git a/libtest/cmdline.h b/libtest/cmdline.h index 368daaec..52ced4bf 100644 --- a/libtest/cmdline.h +++ b/libtest/cmdline.h @@ -182,6 +182,13 @@ public: bool slurp(); void murder(); + void clear() + { + slurp(); + _stdout_buffer.clear(); + _stderr_buffer.clear(); + } + void use_gdb(bool arg) { _use_gdb= arg; diff --git a/libtest/collection.cc b/libtest/collection.cc index 0b2b3249..040dd8b4 100644 --- a/libtest/collection.cc +++ b/libtest/collection.cc @@ -140,7 +140,20 @@ test_return_t Collection::exec() { _failed++; formatter()->failed(); - stream::make_cerr(e.file(), e.line(), e.func()) << e.what(); + stream::make_cerr err(e.file(), e.line(), e.func()); + err << e.what(); + for (auto server : _frame->servers().servers) + { + auto output = server->output(); + if (output.first.size()) + { + err << "Server stdout:\n" << output.first << "\n"; + } + if (output.second.size()) + { + err << "Server stderr:\n" << output.second << "\n"; + } + } throw; } @@ -154,6 +167,18 @@ test_return_t Collection::exec() case TEST_FAILURE: _failed++; formatter()->failed(); + for (auto server : _frame->servers().servers) + { + auto output = server->output(); + if (output.first.size()) + { + Out << "Server stdout:\n" << output.first << "\n"; + } + if (output.second.size()) + { + Out << "Server stderr:\n" << output.second << "\n"; + } + } break; case TEST_SKIPPED: diff --git a/libtest/memcached.cc b/libtest/memcached.cc index e3516620..7af26092 100644 --- a/libtest/memcached.cc +++ b/libtest/memcached.cc @@ -214,6 +214,8 @@ bool Memcached::build() add_option(sasl()); } + add_option("-vv"); + return true; } diff --git a/libtest/server.cc b/libtest/server.cc index 7f3a2d1e..401218ba 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -129,7 +130,7 @@ Server::~Server() bool Server::check() { - _app.slurp(); + _app.clear(); return _app.check(); } @@ -528,4 +529,20 @@ bool Server::kill() return false; } +std::pair Server::output() +{ + _app.slurp(); + return { + std::string { + _app.stdout_result().data(), + _app.stdout_result().size() + }, + std::string { + _app.stderr_result().data(), + _app.stderr_result().size() + } + }; +} + + } // namespace libtest diff --git a/libtest/server.h b/libtest/server.h index bbebe957..10c1d374 100644 --- a/libtest/server.h +++ b/libtest/server.h @@ -205,6 +205,8 @@ public: _log_file.clear(); } + std::pair output(); + pid_t pid() const; bool has_pid() const; diff --git a/libtest/vchar.cc b/libtest/vchar.cc index 4af110b4..a4bddfde 100644 --- a/libtest/vchar.cc +++ b/libtest/vchar.cc @@ -160,7 +160,7 @@ void make_vector(libtest::vchar_t& arg, const char *str, size_t length) std::ostream& operator<<(std::ostream& output, const libtest::vchar_t& arg) { - std::string tmp= libtest::printer(&arg[0], arg.size()); + std::string tmp= libtest::printer(arg.data(), arg.size()); output << tmp << "[" << arg.size() << "]"; return output; diff --git a/tests/libmemcached-1.0/dump.cc b/tests/libmemcached-1.0/dump.cc index a265434c..1e19c4a9 100644 --- a/tests/libmemcached-1.0/dump.cc +++ b/tests/libmemcached-1.0/dump.cc @@ -124,7 +124,7 @@ test_return_t memcached_dump_TEST2(memcached_st *memc) NULL, 0, // Zero length values time_t(0), uint32_t(0))); } - //memcached_quit(memc); + memcached_quit(memc); uint64_t counter= 0; test_compare(MEMCACHED_SUCCESS,