X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/901f09137597064bab9349e26b7d882181ee3bdd..e6ca184e99d50d0ee8fe405a83ee5277e2ecfce6:/src/mc/ModelChecker.cpp diff --git a/src/mc/ModelChecker.cpp b/src/mc/ModelChecker.cpp index ca9a1b2ae4..0d97a6418b 100644 --- a/src/mc/ModelChecker.cpp +++ b/src/mc/ModelChecker.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "simgrid/sg_config.h" @@ -49,9 +50,9 @@ namespace simgrid { namespace mc { ModelChecker::ModelChecker(std::unique_ptr process) : - process_(std::move(process)), hostnames_(xbt_dict_new()), page_store_(500), + process_(std::move(process)), parent_snapshot_(nullptr) { @@ -83,7 +84,7 @@ void ModelChecker::start() sigemptyset(&set); sigaddset(&set, SIGCHLD); if (sigprocmask(SIG_BLOCK, &set, nullptr) == -1) - throw std::system_error(errno, std::system_category()); + throw simgrid::xbt::errno_error(errno); sigset_t full_set; sigfillset(&full_set); @@ -97,7 +98,7 @@ void ModelChecker::start() int signal_fd = signalfd(-1, &set, 0); if (signal_fd == -1) - throw std::system_error(errno, std::system_category()); + throw simgrid::xbt::errno_error(errno); struct pollfd* signalfd_pollfd = &fds_[SIGNAL_FD_INDEX]; signalfd_pollfd->fd = signal_fd; @@ -178,7 +179,7 @@ void ModelChecker::resume(simgrid::mc::Process& process) { int res = process.send_message(MC_MESSAGE_CONTINUE); if (res) - throw std::system_error(res, std::system_category()); + throw simgrid::xbt::errno_error(res); process.cache_flags = (mc_process_cache_flags_t) 0; } @@ -189,7 +190,7 @@ void throw_socket_error(int fd) socklen_t errlen = sizeof(error); if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&error, &errlen) == -1) error = errno; - throw std::system_error(error, std::system_category()); + throw simgrid::xbt::errno_error(errno); } bool ModelChecker::handle_message(char* buffer, ssize_t size) @@ -262,7 +263,7 @@ bool ModelChecker::handle_message(char* buffer, ssize_t size) _mc_property_automaton = xbt_automaton_new(); simgrid::mc::Process* process = &this->process(); - simgrid::mc::remote_ptr address + simgrid::mc::RemotePtr address = simgrid::mc::remote((int*) message.data); simgrid::xbt::add_proposition(_mc_property_automaton, message.name, @@ -277,7 +278,7 @@ bool ModelChecker::handle_message(char* buffer, ssize_t size) case MC_MESSAGE_ASSERTION_FAILED: MC_report_assertion_error(); - ::exit(SIMGRID_MC_EXIT_SAFETY); + this->exit(SIMGRID_MC_EXIT_SAFETY); break; default: @@ -287,6 +288,15 @@ bool ModelChecker::handle_message(char* buffer, ssize_t size) return true; } +/** Terminate the model-checker aplication */ +void ModelChecker::exit(int status) +{ + // TODO, terminate the model checker politely instead of exiting rudel + if (process().running()) + kill(process().pid(), SIGKILL); + ::exit(status); +} + bool ModelChecker::handle_events() { char buffer[MC_MESSAGE_LENGTH]; @@ -298,7 +308,7 @@ bool ModelChecker::handle_events() case EINTR: continue; default: - throw std::system_error(errno, std::system_category()); + throw simgrid::xbt::errno_error(errno); } } @@ -306,12 +316,11 @@ bool ModelChecker::handle_events() if (socket_pollfd->revents & POLLIN) { ssize_t size = MC_receive_message(socket_pollfd->fd, buffer, sizeof(buffer), MSG_DONTWAIT); if (size == -1 && errno != EAGAIN) - throw std::system_error(errno, std::system_category()); + throw simgrid::xbt::errno_error(errno); return handle_message(buffer, size); } - if (socket_pollfd->revents & POLLERR) { + if (socket_pollfd->revents & POLLERR) throw_socket_error(socket_pollfd->fd); - } if (socket_pollfd->revents & POLLHUP) xbt_die("Socket hang up?"); } @@ -321,9 +330,8 @@ bool ModelChecker::handle_events() this->handle_signals(); return true; } - if (signalfd_pollfd->revents & POLLERR) { + if (signalfd_pollfd->revents & POLLERR) throw_socket_error(signalfd_pollfd->fd); - } if (signalfd_pollfd->revents & POLLHUP) xbt_die("Signalfd hang up?"); } @@ -347,7 +355,7 @@ void ModelChecker::handle_signals() if (errno == EINTR) continue; else - throw std::system_error(errno, std::system_category()); + throw simgrid::xbt::errno_error(errno); } else if (size != sizeof(info)) return throw std::runtime_error( "Bad communication with model-checked application"); @@ -372,7 +380,7 @@ void ModelChecker::handle_waitpid() break; } else { XBT_ERROR("Could not wait for pid"); - throw std::system_error(errno, std::system_category()); + throw simgrid::xbt::errno_error(errno); } } @@ -384,7 +392,7 @@ void ModelChecker::handle_waitpid() xbt_die("Could not get exit status"); if (WIFSIGNALED(status)) { MC_report_crash(status); - ::exit(SIMGRID_MC_EXIT_PROGRAM_CRASH); + mc_model_checker->exit(SIMGRID_MC_EXIT_PROGRAM_CRASH); } } @@ -417,10 +425,9 @@ void ModelChecker::on_signal(const struct signalfd_siginfo* info) void ModelChecker::wait_client(simgrid::mc::Process& process) { this->resume(process); - while (this->process().running()) { + while (this->process().running()) if (!this->handle_events()) return; - } } void ModelChecker::simcall_handle(simgrid::mc::Process& process, unsigned long pid, int value) @@ -432,10 +439,9 @@ void ModelChecker::simcall_handle(simgrid::mc::Process& process, unsigned long p m.value = value; process.send_message(m); process.cache_flags = (mc_process_cache_flags_t) 0; - while (process.running()) { + while (process.running()) if (!this->handle_events()) return; - } } }