1 /* Copyright (c) 2008-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include <xbt/sysdep.h>
10 #include <simgrid/modelchecker.h>
12 #include "src/mc/mc_record.h"
13 #include "src/mc/mc_private.h"
14 #include "src/mc/mc_ignore.h"
15 #include "src/mc/mc_protocol.h"
16 #include "src/mc/mc_client.h"
17 #include "src/mc/ModelChecker.hpp"
19 /** \file mc_client_api.cpp
21 * This is the implementation of the API used by the user simulated program to
22 * communicate with the MC (declared in modelchecker.h).
27 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_client_api, mc,
28 "Public API for the model-checked application");
32 // MC_random() is in mc_base.cpp
34 void MC_assert(int prop)
36 if (MC_is_active() && !prop) {
37 MC_client_send_simple_message(MC_MESSAGE_ASSERTION_FAILED);
38 MC_client_handle_messages();
42 void *MC_snapshot(void)
44 return simcall_mc_snapshot();
47 int simcall_HANDLER_mc_compare_snapshots(smx_simcall_t simcall,
48 mc_snapshot_t s1, mc_snapshot_t s2)
50 return snapshot_compare(s1, s2);
53 int MC_compare_snapshots(void *s1, void *s2)
55 return simcall_mc_compare_snapshots(s1, s2);
60 user_max_depth_reached = 1;
63 void MC_ignore(void* addr, size_t size)
65 xbt_assert(mc_mode != MC_MODE_SERVER);
66 if (mc_mode != MC_MODE_CLIENT)
69 s_mc_ignore_memory_message_t message;
70 message.type = MC_MESSAGE_IGNORE_MEMORY;
71 message.addr = (std::uintptr_t) addr;
73 MC_client_send_message(&message, sizeof(message));
76 void MC_automaton_new_propositional_symbol(const char *id, int(*fct)(void))
78 xbt_assert(mc_mode != MC_MODE_SERVER);
79 if (mc_mode != MC_MODE_CLIENT)
82 xbt_die("Support for client-side function proposition is not implemented: "
83 "use MC_automaton_new_propositional_symbol_pointer instead."
87 void MC_automaton_new_propositional_symbol_pointer(const char *name, int* value)
89 xbt_assert(mc_mode != MC_MODE_SERVER);
90 if (mc_mode != MC_MODE_CLIENT)
93 s_mc_register_symbol_message_t message;
94 message.type = MC_MESSAGE_REGISTER_SYMBOL;
95 if (strlen(name) + 1 > sizeof(message.name))
96 xbt_die("Symbol is too long");
97 strncpy(message.name, name, sizeof(message.name));
98 message.callback = nullptr;
100 MC_client_send_message(&message, sizeof(message));