#include <cstdint>
#include <xbt/dynar.h>
+#include <xbt/dynar.hpp>
#include <xbt/fifo.h>
#include <xbt/log.h>
#include <xbt/sysdep.h>
#include "src/mc/mc_private.h"
#include "src/mc/mc_record.h"
#include "src/mc/mc_smx.h"
-#include "src/mc/mc_client.h"
+#include "src/mc/Client.hpp"
#include "src/mc/mc_exit.h"
using simgrid::mc::remote;
-extern "C" {
-
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_comm_determinism, mc,
"Logging specific to MC communication determinism detection");
+extern "C" {
+
/********** Global variables **********/
xbt_dynar_t initial_communications_pattern;
int i;
const int maxpid = MC_smx_get_maxpid();
- if (_sg_mc_visited > 0)
- visited_states = xbt_dynar_new(sizeof(mc_visited_state_t), visited_state_free_voidp);
+ simgrid::mc::visited_states.clear();
// Create initial_communications_pattern elements:
initial_communications_pattern = xbt_dynar_new(sizeof(mc_list_comm_pattern_t), MC_list_comm_pattern_free_voidp);
/* Get an enabled process and insert it in the interleave set of the initial state */
for (auto& p : mc_model_checker->process().simix_processes())
- if (MC_process_is_enabled(&p.copy))
+ if (simgrid::mc::process_is_enabled(&p.copy))
MC_state_interleave_process(initial_state, &p.copy);
xbt_fifo_unshift(mc_stack, initial_state);
}
+static inline
+bool all_communications_are_finished()
+{
+ for (size_t current_process = 1; current_process < MC_smx_get_maxpid(); current_process++) {
+ xbt_dynar_t pattern = xbt_dynar_get_as(
+ incomplete_communications_pattern, current_process, xbt_dynar_t);
+ if (!xbt_dynar_is_empty(pattern)) {
+ XBT_DEBUG("Some communications are not finished, cannot stop the exploration ! State not visited.");
+ return false;
+ }
+ }
+ return true;
+}
+
static int MC_modelcheck_comm_determinism_main(void)
{
char *req_str = nullptr;
int value;
- mc_visited_state_t visited_state = nullptr;
+ std::unique_ptr<simgrid::mc::VisitedState> visited_state = nullptr;
smx_simcall_t req = nullptr;
mc_state_t state = nullptr, next_state = NULL;
&& (req = MC_state_get_request(state, &value))
&& (visited_state == nullptr)) {
- req_str = MC_request_to_string(req, value, MC_REQUEST_SIMIX);
+ req_str = simgrid::mc::request_to_string(req, value, simgrid::mc::RequestType::simix);
XBT_DEBUG("Execute: %s", req_str);
xbt_free(req_str);
if (dot_output != nullptr)
- req_str = MC_request_get_dot_output(req, value);
+ req_str = simgrid::mc::request_get_dot_output(req, value);
MC_state_set_executed_request(state, req, value);
mc_stats->executed_transitions++;
call = MC_get_call_type(req);
/* Answer the request */
- MC_simcall_handle(req, value); /* After this call req is no longer useful */
+ simgrid::mc::handle_simcall(req, value); /* After this call req is no longer useful */
if(!initial_global_state->initial_communications_pattern_done)
MC_handle_comm_pattern(call, req, value, initial_communications_pattern, 0);
/* Create the new expanded state */
next_state = MC_state_new();
- if ((visited_state = is_visited_state(next_state)) == nullptr) {
+ /* If comm determinism verification, we cannot stop the exploration if
+ some communications are not finished (at least, data are transfered).
+ These communications are incomplete and they cannot be analyzed and
+ compared with the initial pattern. */
+ bool compare_snapshots = all_communications_are_finished()
+ && initial_global_state->initial_communications_pattern_done;
+
+ if (_sg_mc_visited == 0 || (visited_state = simgrid::mc::is_visited_state(next_state, compare_snapshots)) == nullptr) {
/* Get enabled processes and insert them in the interleave set of the next state */
for (auto& p : mc_model_checker->process().simix_processes())
- if (MC_process_is_enabled(&p.copy))
+ if (simgrid::mc::process_is_enabled(&p.copy))
MC_state_interleave_process(next_state, &p.copy);
if (dot_output != nullptr)
visited_state = nullptr;
/* Check for deadlocks */
- if (MC_deadlock_check()) {
- MC_show_deadlock(nullptr);
+ if (mc_model_checker->checkDeadlock()) {
+ MC_show_deadlock();
return SIMGRID_MC_EXIT_DEADLOCK;
}
int MC_modelcheck_comm_determinism(void)
{
XBT_INFO("Check communication determinism");
- mc_reduce_kind = e_mc_reduce_none;
mc_model_checker->wait_for_requests();
if (mc_mode == MC_MODE_CLIENT)
// This will move somehwere else:
- MC_client_handle_messages();
+ simgrid::mc::Client::get()->handleMessages();
/* Create exploration stack */
mc_stack = xbt_fifo_new();