Server::~Server()
{
- if (has_pid() and not kill())
+ if (has_pid() and not kill(_pid))
{
Error << "Unable to kill:" << *this;
}
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();
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());
return false;
}
+ if (is_valgrind() or is_helgrind())
+ {
+ _running+= " &";
+ }
+
if (system(_running.c_str()) == -1)
{
Error << "system() failed:" << strerror(errno);
return false;
}
+ if (is_helgrind())
+ {
+ sleep(4);
+ }
+
if (pid_file_option() and not pid_file().empty())
{
Wait wait(pid_file());
}
}
- int count= 5;
+ int count= is_helgrind() ? 20 : 5;
while (not ping() and --count)
{
nap();
}
// A failing get_pid() at this point is considered an error
- _pid= get_pid(false);
+ _pid= get_pid(true);
return has_pid();
}
}
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();
}
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();
}
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())
{
{
for (std::vector<Server *>::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);
}
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
{
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())
}
else
{
- Log << "STARTING SERVER(pid:" << server->pid() << "): " << server->running();
+ Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running();
}
construct.push_server(server);
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)
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())
}
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;
}