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).
25 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_client_api, mc,
26 "Public API for the model-checked application");
28 // MC_random() is in mc_base.cpp
30 void MC_assert(int prop)
32 if (MC_is_active() && !prop) {
33 if (simgrid::mc::Client::get()->getChannel().send(MC_MESSAGE_ASSERTION_FAILED))
34 xbt_die("Could not send assertion to model-checker");
35 simgrid::mc::Client::get()->handleMessages();
41 user_max_depth_reached = 1;
44 void MC_ignore(void* addr, size_t size)
46 xbt_assert(mc_mode != MC_MODE_SERVER);
47 if (mc_mode != MC_MODE_CLIENT)
50 s_mc_ignore_memory_message_t message;
51 message.type = MC_MESSAGE_IGNORE_MEMORY;
52 message.addr = (std::uintptr_t) addr;
54 if (simgrid::mc::Client::get()->getChannel().send(message))
55 xbt_die("Could not send IGNORE_MEMORY mesage to model-checker");
58 void MC_automaton_new_propositional_symbol(const char *id, int(*fct)(void))
60 xbt_assert(mc_mode != MC_MODE_SERVER);
61 if (mc_mode != MC_MODE_CLIENT)
64 xbt_die("Support for client-side function proposition is not implemented: "
65 "use MC_automaton_new_propositional_symbol_pointer instead."
69 void MC_automaton_new_propositional_symbol_pointer(const char *name, int* value)
71 xbt_assert(mc_mode != MC_MODE_SERVER);
72 if (mc_mode != MC_MODE_CLIENT)
75 s_mc_register_symbol_message_t message;
76 message.type = MC_MESSAGE_REGISTER_SYMBOL;
77 if (strlen(name) + 1 > sizeof(message.name))
78 xbt_die("Symbol is too long");
79 strncpy(message.name, name, sizeof(message.name));
80 message.callback = nullptr;
82 if (simgrid::mc::Client::get()->getChannel().send(message))
83 xbt_die("Could send REGISTER_SYMBOL message to model-checker");