1 /* Copyright (c) 2008-2019. 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. */
8 #include "xbt/sysdep.h"
9 #include <simgrid/modelchecker.h>
11 #include "src/mc/ModelChecker.hpp"
12 #include "src/mc/mc_ignore.hpp"
13 #include "src/mc/mc_private.hpp"
14 #include "src/mc/mc_record.hpp"
15 #include "src/mc/mc_replay.hpp"
16 #include "src/mc/remote/Client.hpp"
17 #include "src/mc/remote/mc_protocol.h"
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 xbt_assert(mc_model_checker == nullptr);
35 simgrid::mc::Client::get()->reportAssertionFailure();
36 if (MC_record_replay_is_active())
37 xbt_die("MC assertion failed");
43 xbt_assert(mc_model_checker == nullptr);
44 if (not MC_is_active())
46 // FIXME, We want to do this in the model-checker:
47 xbt_die("MC_cut() not implemented");
50 void MC_ignore(void* addr, size_t size)
52 xbt_assert(mc_model_checker == nullptr);
53 if (not MC_is_active())
55 simgrid::mc::Client::get()->ignoreMemory(addr, size);
58 void MC_automaton_new_propositional_symbol(const char* /*id*/, int (*/*fct*/)())
60 xbt_assert(mc_model_checker == nullptr);
61 if (not MC_is_active())
63 xbt_die("Support for client-side function proposition is not implemented: "
64 "use MC_automaton_new_propositional_symbol_pointer instead.");
67 void MC_automaton_new_propositional_symbol_pointer(const char *name, int* value)
69 xbt_assert(mc_model_checker == nullptr);
70 if (not MC_is_active())
72 simgrid::mc::Client::get()->declareSymbol(name, value);
75 /** @brief Register a stack in the model checker
77 * The stacks are allocated in the heap. The MC handle them specifically
78 * when we analyze/compare the content of the heap so it must be told where
79 * they are with this function.
81 * @param stack Where the stack is
82 * @param actor Actor owning the stack
83 * @param context The context associated to that stack
84 * @param size Size of the stack
86 void MC_register_stack_area(void* stack, smx_actor_t actor, ucontext_t* context, size_t size)
88 xbt_assert(mc_model_checker == nullptr);
89 if (not MC_is_active())
91 simgrid::mc::Client::get()->declareStack(stack, size, actor, context);
94 void MC_ignore_global_variable(const char* /*name*/)
96 xbt_assert(mc_model_checker == nullptr);
97 if (not MC_is_active())
99 // TODO, send a message to the model_checker
100 xbt_die("Unimplemented");
103 void MC_ignore_heap(void *address, size_t size)
105 xbt_assert(mc_model_checker == nullptr);
106 if (not MC_is_active())
108 simgrid::mc::Client::get()->ignoreHeap(address, size);
111 void MC_unignore_heap(void* address, size_t size)
113 xbt_assert(mc_model_checker == nullptr);
114 if (not MC_is_active())
116 simgrid::mc::Client::get()->unignoreHeap(address, size);