-/* Copyright (c) 2008-2019. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2008-2020. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "src/mc/mc_config.hpp"
#include "src/mc/mc_exit.hpp"
#include "src/mc/mc_private.hpp"
-#include "src/mc/remote/RemoteClient.hpp"
+#include "src/mc/remote/RemoteClientMemory.hpp"
#include "xbt/automaton.hpp"
#include "xbt/system_error.hpp"
namespace simgrid {
namespace mc {
-ModelChecker::ModelChecker(std::unique_ptr<RemoteClient> process) : process_(std::move(process)) {}
-
-ModelChecker::~ModelChecker()
-{
- if (socket_event_ != nullptr)
- event_free(socket_event_);
- if (signal_event_ != nullptr)
- event_free(signal_event_);
- if (base_ != nullptr)
- event_base_free(base_);
-}
+ModelChecker::ModelChecker(std::unique_ptr<RemoteClientMemory> process) : process_(std::move(process)) {}
void ModelChecker::start()
{
- base_ = event_base_new();
- event_callback_fn event_callback = [](evutil_socket_t fd, short events, void *arg)
- {
- ((ModelChecker *)arg)->handle_events(fd, events);
- };
- socket_event_ = event_new(base_, process_->get_channel().get_socket(), EV_READ | EV_PERSIST, event_callback, this);
- event_add(socket_event_, NULL);
- signal_event_ = event_new(base_,
- SIGCHLD,
- EV_SIGNAL|EV_PERSIST,
- event_callback, this);
- event_add(signal_event_, NULL);
+ event_loop_.start(process_->get_channel().get_socket(), [](evutil_socket_t sig, short events, void* arg) {
+ ((ModelChecker*)arg)->handle_events(sig, events);
+ });
XBT_DEBUG("Waiting for the model-checked process");
int status;
void ModelChecker::setup_ignore()
{
- RemoteClient& process = this->process();
+ RemoteClientMemory& process = this->process();
for (std::pair<const char*, const char*> const& var :
ignored_local_variables)
process.ignore_local_variable(var.first, var.second);
{
XBT_DEBUG("Shuting down model-checker");
- RemoteClient* process = &this->process();
+ RemoteClientMemory* process = &this->process();
if (process->running()) {
XBT_DEBUG("Killing process");
kill(process->pid(), SIGKILL);
}
}
-void ModelChecker::resume(RemoteClient& process)
+void ModelChecker::resume(RemoteClientMemory& process)
{
int res = process.get_channel().send(MC_MESSAGE_CONTINUE);
if (res)
session->log_state();
}
-bool ModelChecker::handle_message(char* buffer, ssize_t size)
+bool ModelChecker::handle_message(const char* buffer, ssize_t size)
{
s_mc_message_t base_message;
xbt_assert(size >= (ssize_t)sizeof(base_message), "Broken message");
if (property_automaton == nullptr)
property_automaton = xbt_automaton_new();
- RemoteClient* process = &this->process();
+ RemoteClientMemory* process = &this->process();
RemotePtr<int> address = remote((int*)message.data);
xbt::add_proposition(property_automaton, message.name, [process, address]() { return process->read(address); });
::exit(status);
}
-void ModelChecker::handle_events(int fd, short events)
+void ModelChecker::handle_events(int sig, short events)
{
if (events == EV_READ) {
char buffer[MC_MESSAGE_LENGTH];
ssize_t size = process_->get_channel().receive(buffer, sizeof(buffer), false);
if (size == -1 && errno != EAGAIN)
throw simgrid::xbt::errno_error();
- if (not handle_message(buffer, size)) {
- event_base_loopbreak(base_);
- }
+
+ if (not handle_message(buffer, size))
+ event_loop_.break_loop();
}
else if (events == EV_SIGNAL) {
- on_signal(fd);
+ if (sig == SIGCHLD)
+ this->handle_waitpid();
}
else {
xbt_die("Unexpected event");
}
}
-void ModelChecker::loop()
-{
- if (this->process().running())
- event_base_dispatch(base_);
-}
-
void ModelChecker::handle_waitpid()
{
XBT_DEBUG("Check for wait event");
}
}
-void ModelChecker::on_signal(int signo)
-{
- if (signo == SIGCHLD)
- this->handle_waitpid();
-}
-
void ModelChecker::wait_for_requests()
{
this->resume(process());
if (this->process().running())
- event_base_dispatch(base_);
+ event_loop_.dispatch();
}
void ModelChecker::handle_simcall(Transition const& transition)
this->process_->get_channel().send(m);
this->process_->clear_cache();
if (this->process_->running())
- event_base_dispatch(base_);
+ event_loop_.dispatch();
}
bool ModelChecker::checkDeadlock()