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 "mc_record.h"
13 #include "mc_private.h"
14 #include "mc_mmalloc.h"
15 #include "mc_ignore.h"
16 #include "mc_protocol.h"
17 #include "mc_client.h"
18 #include "ModelChecker.hpp"
20 /** \file mc_client_api.cpp
22 * This is the implementation of the API used by the user simulated program to
23 * communicate with the MC (declared in modelchecker.h).
28 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_client_api, mc,
29 "Public API for the model-checked application");
31 int MC_random(int min, int max)
33 xbt_assert(mc_mode != MC_MODE_SERVER);
34 // TODO, if the MC is disabled we do not really need to make a simcall for this :)
35 /* FIXME: return mc_current_state->executed_transition->random.value; */
36 return simcall_mc_random(min, max);
39 void MC_assert(int prop)
41 if (MC_is_active() && !prop) {
42 MC_client_send_simple_message(MC_MESSAGE_ASSERTION_FAILED);
43 MC_client_handle_messages();
47 // TODO, MC_automaton_new_propositional_symbol
49 void *MC_snapshot(void)
51 return simcall_mc_snapshot();
54 int simcall_HANDLER_mc_compare_snapshots(smx_simcall_t simcall,
55 mc_snapshot_t s1, mc_snapshot_t s2)
57 return snapshot_compare(s1, s2);
60 int MC_compare_snapshots(void *s1, void *s2)
62 return simcall_mc_compare_snapshots(s1, s2);
67 user_max_depth_reached = 1;
70 void MC_ignore(void* addr, size_t size)
72 xbt_assert(mc_mode != MC_MODE_SERVER);
73 if (mc_mode != MC_MODE_CLIENT)
76 s_mc_ignore_memory_message_t message;
77 message.type = MC_MESSAGE_IGNORE_MEMORY;
78 message.addr = (std::uintptr_t) addr;
80 MC_client_send_message(&message, sizeof(message));
83 void MC_automaton_new_propositional_symbol(const char *id, int(*fct)(void))
85 xbt_assert(mc_mode != MC_MODE_SERVER);
86 if (mc_mode != MC_MODE_CLIENT)
89 xbt_die("Support for client-side function proposition is not implemented: "
90 "use MC_automaton_new_propositional_symbol_pointer instead."
94 void MC_automaton_new_propositional_symbol_pointer(const char *name, int* value)
96 xbt_assert(mc_mode != MC_MODE_SERVER);
97 if (mc_mode != MC_MODE_CLIENT)
100 s_mc_register_symbol_message_t message;
101 message.type = MC_MESSAGE_REGISTER_SYMBOL;
102 if (strlen(name) + 1 > sizeof(message.name))
103 xbt_die("Symbol is too long");
104 strncpy(message.name, name, sizeof(message.name));
105 message.callback = nullptr;
106 message.data = value;
107 MC_client_send_message(&message, sizeof(message));