{
if (libtool() == NULL)
{
- throw "libtool requested, but know libtool was found";
+ throw fatal_message("libtool requested, but know libtool was found");
}
}
Application::~Application()
{
+ murder();
delete_argv();
}
if (spawn_ret)
{
+ _pid= -1;
return Application::INVALID;
}
return false;
}
+ bool data_was_read= false;
if (fds[0].revents & POLLIN)
{
ssize_t read_length;
break;
}
+
+ data_was_read= true;
_stdout_buffer.reserve(read_length +1);
for (size_t x= 0; x < read_length; x++)
{
break;
}
+
+ data_was_read= true;
_stderr_buffer.reserve(read_length +1);
for (size_t x= 0; x < read_length; x++)
{
}
}
- return true;
+ return data_was_read;
}
-Application::error_t Application::wait()
+Application::error_t Application::wait(bool nohang)
{
- fatal_assert(_pid != -1);
+ if (_pid == -1)
+ {
+ return Application::INVALID;
+ }
slurp();
{
int status= 0;
pid_t waited_pid;
- if ((waited_pid= waitpid(_pid, &status, 0)) == -1)
+ if ((waited_pid= waitpid(_pid, &status, nohang ? WNOHANG : 0)) == -1)
{
switch (errno)
{
Error << "Error occured while waitpid(" << strerror(errno) << ") on pid " << int(_pid);
}
}
+ else if (waited_pid == 0)
+ {
+ exit_code= Application::SUCCESS;
+ }
else
{
if (waited_pid != _pid)
if (pipe(_fd) == -1)
{
- throw strerror(errno);
+ throw fatal_message(strerror(errno));
}
_open[0]= true;
_open[1]= true;
if ((ret= posix_spawn_file_actions_adddup2(&file_actions, _fd[type], newfildes )) < 0)
{
Error << "posix_spawn_file_actions_adddup2(" << strerror(ret) << ")";
- throw strerror(ret);
+ throw fatal_message(strerror(ret));
}
if ((ret= posix_spawn_file_actions_addclose(&file_actions, _fd[type])) < 0)
{
Error << "posix_spawn_file_actions_adddup2(" << strerror(ret) << ")";
- throw strerror(ret);
+ throw fatal_message(strerror(ret));
}
}
return int(ret);
}
- return int(app.wait());
+ return int(app.wait(false));
}
const char *gearmand_binary()
void add_option(const std::string&, const std::string&);
void add_long_option(const std::string& option_name, const std::string& option_value);
error_t run(const char *args[]= NULL);
- error_t wait();
+ error_t wait(bool nohang= true);
libtest::vchar_t stdout_result() const
{
return _gdb_filename;
}
+ pid_t pid() const
+ {
+ return _pid;
+ }
+
private:
void create_argv(const char *args[]);
void delete_argv();
} // namespace libtest
-#define fatal_message(__mesg) libtest::fatal(LIBYATL_DEFAULT_PARAM, __mesg)
-#define fatal_assert(__assert) if((__assert)) {} else { libtest::fatal(LIBYATL_DEFAULT_PARAM, #__assert); }
+#define fatal_message(__mesg) libtest::fatal(LIBYATL_DEFAULT_PARAM, "%s", __mesg)
+#define fatal_assert(__assert) if((__assert)) {} else { libtest::fatal(LIBYATL_DEFAULT_PARAM, "%s", #__assert); }
Server::~Server()
{
- if (has_pid() and not kill(_pid))
- {
- Error << "Unable to kill:" << *this;
- }
-
- Application::error_t ret;
- if (Application::SUCCESS != (ret= _app.wait()))
- {
- Error << "Application::wait() " << _running << " " << ret << ": " << _app.stderr_result();
- }
}
bool Server::check()
uint32_t limit= 3;
// Try to ping, and kill the server #limit number of times
- pid_t current_pid;
while (--limit and
- is_pid_valid(current_pid= get_pid()))
+ is_pid_valid(_app.pid()))
{
- if (kill(current_pid))
+ if (kill())
{
- Log << "Killed existing server," << *this << " with pid:" << current_pid;
+ Log << "Killed existing server," << *this;
dream(0, 50000);
continue;
}
// For whatever reason we could not kill it, and we reached limit
if (limit == 0)
{
- Error << "Reached limit, could not kill server pid:" << current_pid;
+ Error << "Reached limit, could not kill server";
return false;
}
return wait.successful();
}
+bool Server::has_pid() const
+{
+ return (_pid > 1);
+}
+
+
bool Server::start()
{
// If we find that we already have a pid then kill it.
- if (has_pid() and kill(_pid) == false)
- {
- Error << "Could not kill() existing server during start() pid:" << _pid;
- return false;
- }
-
if (has_pid() == false)
{
fatal_message("has_pid() failed, programer error");
return true;
}
-bool Server::kill(pid_t pid_arg)
+bool Server::kill()
{
- if (check_pid(pid_arg) and kill_pid(pid_arg)) // If we kill it, reset
+ if (check_pid(_app.pid()) and kill_pid(_app.pid())) // If we kill it, reset
{
if (broken_pid_file() and pid_file().empty() == false)
{
return _pid;
}
- bool has_pid() const
- {
- return (_pid > 1);
- }
+ bool has_pid() const;
virtual bool wait_for_pidfile() const;
std::string log_and_pid();
- bool kill(pid_t pid_arg);
+ bool kill();
bool start();
bool command(libtest::Application& app);
{
Server* tmp= servers[number_of_host];
- if (tmp and tmp->has_pid() and not tmp->kill(tmp->pid()))
+ if (tmp and tmp->has_pid() and tmp->kill() == false)
{ }
else
{
{
for (std::vector<Server *>::iterator iter= servers.begin(); iter != servers.end(); iter++)
{
- if ((*iter)->has_pid() and not (*iter)->kill((*iter)->pid()))
+ if ((*iter)->has_pid() and (*iter)->kill() == false)
{
Error << "Unable to kill:" << *(*iter);
}
}
}
+ catch (libtest::fatal &e)
+ {
+ Error << "Fatal exception was thrown: " << e.what();
+ return_code= TEST_FAILURE;
+ }
catch (std::exception &e)
{
Error << "Exception was thrown: " << e.what();
test_compare(Application::SUCCESS, true_app.run(args));
test_compare(Application::SUCCESS, true_app.wait());
+ while (true_app.slurp() == false) {} ;
+
libtest::vchar_t response;
make_vector(response, test_literal_param("fubar\n"));
test_compare(response, true_app.stdout_result());
test_compare(Application::SUCCESS, true_app.run());
test_compare(Application::SUCCESS, true_app.wait());
+
libtest::vchar_t response;
make_vector(response, test_literal_param("fubar\n"));
test_compare(response, true_app.stdout_result());