xbt_assert(mc_model_checker == nullptr, "Did you manage to start the MC twice in this process?");
- std::unique_ptr<simgrid::mc::RemoteClient> process(new simgrid::mc::RemoteClient(pid, sockets[1]));
+ auto process = std::unique_ptr<simgrid::mc::RemoteClient>(new simgrid::mc::RemoteClient(pid, sockets[1]));
model_checker_.reset(new simgrid::mc::ModelChecker(std::move(process)));
mc_model_checker = model_checker_.get();
- mc_model_checker->start();
+ model_checker_->start();
}
Session::~Session()
void Session::initialize()
{
xbt_assert(initial_snapshot_ == nullptr);
- mc_model_checker->wait_for_requests();
+ model_checker_->wait_for_requests();
initial_snapshot_ = std::make_shared<simgrid::mc::Snapshot>(0);
}
void Session::restore_initial_state()
{
- this->initial_snapshot_->restore(&mc_model_checker->process());
+ this->initial_snapshot_->restore(&model_checker_->process());
}
void Session::log_state()
{
- mc_model_checker->getChecker()->log_state();
+ model_checker_->getChecker()->log_state();
if (not _sg_mc_dot_output_file.get().empty()) {
fprintf(dot_output, "}\n");
// Fetch socket from MC_ENV_SOCKET_FD:
const char* fd_env = std::getenv(MC_ENV_SOCKET_FD);
- if (not fd_env)
- xbt_die("No MC socket passed in the environment");
- int fd =
- xbt_str_parse_int(fd_env, bprintf("Variable %s should contain a number but contains '%%s'", MC_ENV_SOCKET_FD));
+ int fd = xbt_str_parse_int(fd_env, "Variable '" MC_ENV_SOCKET_FD "' should contain a number but contains '%s'");
XBT_DEBUG("Model-checked application found socket FD %i", fd);
// Check the socket type/validity:
socklen_t socklen = sizeof(type);
if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &type, &socklen) != 0)
xbt_die("Could not check socket type");
- if (type != SOCK_SEQPACKET)
- xbt_die("Unexpected socket type %i", type);
+ xbt_assert(type == SOCK_SEQPACKET, "Unexpected socket type %i", type);
XBT_DEBUG("Model-checked application found expected socket type");
instance_.reset(new simgrid::mc::Client(fd));
void Client::handle_simcall(const s_mc_message_simcall_handle_t* message)
{
smx_actor_t process = SIMIX_process_from_PID(message->pid);
- if (not process)
- xbt_die("Invalid pid %lu", (unsigned long)message->pid);
+ xbt_assert(process != nullptr, "Invalid pid %lu", message->pid);
process->simcall_handle(message->value);
if (channel_.send(MC_MESSAGE_WAITING))
xbt_die("Could not send MESSAGE_WAITING to model-checker");
channel_.send(answer);
}
+#define assert_msg_size(_name_, _type_) \
+ xbt_assert(received_size == sizeof(_type_), "Unexpected size for " _name_ " (%zd != %zu)", received_size, \
+ sizeof(_type_))
+
void Client::handle_messages()
{
while (1) {
char message_buffer[MC_MESSAGE_LENGTH];
ssize_t received_size = channel_.receive(&message_buffer, sizeof(message_buffer));
- if (received_size < 0)
- xbt_die("Could not receive commands from the model-checker");
+ xbt_assert(received_size >= 0, "Could not receive commands from the model-checker");
const s_mc_message_t* message = (s_mc_message_t*)message_buffer;
switch (message->type) {
case MC_MESSAGE_DEADLOCK_CHECK:
- xbt_assert(received_size == sizeof(s_mc_message_t), "Unexpected size for DEADLOCK_CHECK (%zd != %zu)",
- received_size, sizeof(s_mc_message_t));
+ assert_msg_size("DEADLOCK_CHECK", s_mc_message_t);
handle_deadlock_check(message);
break;
case MC_MESSAGE_CONTINUE:
- xbt_assert(received_size == sizeof(s_mc_message_t), "Unexpected size for MESSAGE_CONTINUE (%zd != %zu)",
- received_size, sizeof(s_mc_message_t));
+ assert_msg_size("MESSAGE_CONTINUE", s_mc_message_t);
handle_continue(message);
return;
case MC_MESSAGE_SIMCALL_HANDLE:
- xbt_assert(received_size == sizeof(s_mc_message_simcall_handle_t),
- "Unexpected size for SIMCALL_HANDLE (%zd != %zu)", received_size,
- sizeof(s_mc_message_simcall_handle_t));
+ assert_msg_size("SIMCALL_HANDLE", s_mc_message_simcall_handle_t);
handle_simcall((s_mc_message_simcall_handle_t*)message_buffer);
break;
case MC_MESSAGE_ACTOR_ENABLED:
- xbt_assert(received_size == sizeof(s_mc_message_actor_enabled_t),
- "Unexpected size for ACTOR_ENABLED (%zd != %zu)", received_size,
- sizeof(s_mc_message_actor_enabled_t));
+ assert_msg_size("ACTOR_ENABLED", s_mc_message_actor_enabled_t);
handle_actor_enabled((s_mc_message_actor_enabled_t*)message_buffer);
break;