Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid into tomerge
[simgrid.git] / src / mc / mc_client_api.cpp
1 /* Copyright (c) 2008-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include <xbt/log.h>
8 #include <xbt/fifo.h>
9 #include <xbt/sysdep.h>
10 #include <simgrid/modelchecker.h>
11
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"
19
20 /** \file mc_client_api.cpp
21  *
22  *  This is the implementation of the API used by the user simulated program to
23  *  communicate with the MC (declared in modelchecker.h).
24  */
25
26 extern "C" {
27
28 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_client_api, mc,
29   "Public API for the model-checked application");
30
31 void MC_assert(int prop)
32 {
33   if (MC_is_active() && !prop) {
34     MC_client_send_simple_message(MC_MESSAGE_ASSERTION_FAILED);
35     MC_client_handle_messages();
36   }
37 }
38
39 // TODO, MC_automaton_new_propositional_symbol
40
41 void *MC_snapshot(void)
42 {
43   return simcall_mc_snapshot();
44 }
45
46 int simcall_HANDLER_mc_compare_snapshots(smx_simcall_t simcall,
47                                    mc_snapshot_t s1, mc_snapshot_t s2)
48 {
49   return snapshot_compare(s1, s2);
50 }
51
52 int MC_compare_snapshots(void *s1, void *s2)
53 {
54   return simcall_mc_compare_snapshots(s1, s2);
55 }
56
57 void MC_cut(void)
58 {
59   user_max_depth_reached = 1;
60 }
61
62 void MC_ignore(void* addr, size_t size)
63 {
64   xbt_assert(mc_mode != MC_MODE_SERVER);
65   if (mc_mode != MC_MODE_CLIENT)
66     return;
67
68   s_mc_ignore_memory_message_t message;
69   message.type = MC_MESSAGE_IGNORE_MEMORY;
70   message.addr = (std::uintptr_t) addr;
71   message.size = size;
72   MC_client_send_message(&message, sizeof(message));
73 }
74
75 void MC_automaton_new_propositional_symbol(const char *id, int(*fct)(void))
76 {
77   xbt_assert(mc_mode != MC_MODE_SERVER);
78   if (mc_mode != MC_MODE_CLIENT)
79     return;
80
81   xbt_die("Support for client-side function proposition is not implemented: "
82     "use MC_automaton_new_propositional_symbol_pointer instead."
83   );
84 }
85
86 void MC_automaton_new_propositional_symbol_pointer(const char *name, int* value)
87 {
88   xbt_assert(mc_mode != MC_MODE_SERVER);
89   if (mc_mode != MC_MODE_CLIENT)
90     return;
91
92   s_mc_register_symbol_message_t message;
93   message.type = MC_MESSAGE_REGISTER_SYMBOL;
94   if (strlen(name) + 1 > sizeof(message.name))
95     xbt_die("Symbol is too long");
96   strncpy(message.name, name, sizeof(message.name));
97   message.callback = nullptr;
98   message.data = value;
99   MC_client_send_message(&message, sizeof(message));
100 }
101
102 }