X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=libtest%2Fserver.cc;h=d5329b11971851b1e04c50fa28aeb2735443d38a;hb=3c4d734f56530d43520f385bff97162c04ac81ac;hp=ed7e87f11672ffe0c547d4a4d7d8e85b4a7231c2;hpb=28602fd2f5f1c758b50cd82d4545da8e6c55f5c7;p=m6w6%2Flibmemcached diff --git a/libtest/server.cc b/libtest/server.cc index ed7e87f1..d5329b11 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -116,7 +116,7 @@ Server::Server(const std::string& host_arg, const in_port_t port_arg, bool is_so Server::~Server() { - if (has_pid() and not kill()) + if (has_pid() and not kill(_pid)) { Error << "Unable to kill:" << *this; } @@ -138,7 +138,7 @@ bool Server::cycle() pid_t current_pid; while (--limit and (current_pid= get_pid()) != -1) { - if (kill()) + if (kill(current_pid)) { Log << "Killed existing server," << *this << " with pid:" << current_pid; nap(); @@ -174,9 +174,9 @@ bool Server::command(std::string& command_arg) bool Server::start() { // If we find that we already have a pid then kill it. - if (has_pid() and not kill()) + if (has_pid() and not kill(_pid)) { - Error << "Could not kill() existing server during start()"; + Error << "Could not kill() existing server during start() pid:" << _pid; return false; } assert(not has_pid()); @@ -188,6 +188,11 @@ bool Server::start() return false; } + if (is_valgrind() or is_helgrind()) + { + _running+= " &"; + } + if (system(_running.c_str()) == -1) { Error << "system() failed:" << strerror(errno); @@ -195,6 +200,11 @@ bool Server::start() return false; } + if (is_helgrind()) + { + sleep(4); + } + if (pid_file_option() and not pid_file().empty()) { Wait wait(pid_file()); @@ -205,7 +215,7 @@ bool Server::start() } } - int count= 5; + int count= is_helgrind() ? 20 : 5; while (not ping() and --count) { nap(); @@ -219,7 +229,7 @@ bool Server::start() } // A failing get_pid() at this point is considered an error - _pid= get_pid(false); + _pid= get_pid(true); return has_pid(); } @@ -325,7 +335,12 @@ void Server::rebuild_base_command() } else if (is_valgrind()) { - _base_command+= "valgrind --log-file=tests/var/tmp/valgrind.out --leak-check=full --show-reachable=yes "; + _base_command+= "valgrind --log-file=tests/var/tmp/valgrind.out --error-exitcode=1 --leak-check=yes --show-reachable=yes --track-fds=yes --malloc-fill=A5 --free-fill=DE "; + + } + else if (is_helgrind()) + { + _base_command+= "valgrind --log-file=tests/var/tmp/helgrind.out --tool=helgrind --read-var-info=yes --error-exitcode=1 -v "; } _base_command+= executable(); @@ -359,7 +374,7 @@ bool Server::args(std::string& options) } assert(daemon_file_option()); - if (daemon_file_option()) + if (daemon_file_option() and not is_valgrind() and not is_helgrind()) { arg_buffer << " " << daemon_file_option(); } @@ -396,9 +411,14 @@ bool Server::is_valgrind() const return bool(getenv("LIBTEST_MANUAL_VALGRIND")); } -bool Server::kill() +bool Server::is_helgrind() const +{ + return bool(getenv("LIBTEST_MANUAL_HELGRIND")); +} + +bool Server::kill(pid_t pid_arg) { - if (has_pid() and kill_pid(_pid)) // If we kill it, reset + if (check_pid(pid_arg) and kill_pid(pid_arg)) // If we kill it, reset { if (broken_pid_file() and not pid_file().empty()) { @@ -463,7 +483,7 @@ void server_startup_st::shutdown(bool remove) { for (std::vector::iterator iter= servers.begin(); iter != servers.end(); iter++) { - if ((*iter)->has_pid() and not (*iter)->kill()) + if ((*iter)->has_pid() and not (*iter)->kill((*iter)->pid())) { Error << "Unable to kill:" << *(*iter); } @@ -486,9 +506,15 @@ bool server_startup_st::is_valgrind() const return bool(getenv("LIBTEST_MANUAL_VALGRIND")); } +bool server_startup_st::is_helgrind() const +{ + return bool(getenv("LIBTEST_MANUAL_HELGRIND")); +} + + bool server_startup(server_startup_st& construct, const std::string& server_type, in_port_t try_port, int argc, const char *argv[]) { - Logn(); + Outn(); // Look to see if we are being provided ports to use { @@ -557,10 +583,10 @@ bool server_startup(server_startup_st& construct, const std::string& server_type if (construct.is_debug()) { - Log << "Pausing for startup, hit return when ready."; + Out << "Pausing for startup, hit return when ready."; std::string gdb_command= server->base_command(); std::string options; - Log << "run " << server->args(options); + Out << "run " << server->args(options); getchar(); } else if (not server->start()) @@ -571,7 +597,7 @@ bool server_startup(server_startup_st& construct, const std::string& server_type } else { - Log << "STARTING SERVER(pid:" << server->pid() << "): " << server->running(); + Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running(); } construct.push_server(server); @@ -582,14 +608,15 @@ bool server_startup(server_startup_st& construct, const std::string& server_type set_default_port(server->port()); } - Logn(); + Outn(); return true; } bool server_startup_st::start_socket_server(const std::string& server_type, const in_port_t try_port, int argc, const char *argv[]) { - Logn(); + (void)try_port; + Outn(); Server *server= NULL; if (0) @@ -635,10 +662,10 @@ bool server_startup_st::start_socket_server(const std::string& server_type, cons if (is_debug()) { - Log << "Pausing for startup, hit return when ready."; + Out << "Pausing for startup, hit return when ready."; std::string gdb_command= server->base_command(); std::string options; - Log << "run " << server->args(options); + Out << "run " << server->args(options); getchar(); } else if (not server->start()) @@ -649,14 +676,14 @@ bool server_startup_st::start_socket_server(const std::string& server_type, cons } else { - Log << "STARTING SERVER(pid:" << server->pid() << "): " << server->running(); + Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running(); } push_server(server); set_default_socket(server->socket().c_str()); - Logn(); + Outn(); return true; }