1 /* Copyright (c) 2008-2017. 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.h"
13 #include "src/mc/mc_private.hpp"
14 #include "src/mc/mc_record.hpp"
15 #include "src/mc/remote/Client.hpp"
16 #include "src/mc/remote/mc_protocol.h"
18 /** @file mc_client_api.cpp
20 * This is the implementation of the API used by the user simulated program to
21 * communicate with the MC (declared in modelchecker.h).
24 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_client_api, mc,
25 "Public API for the model-checked application");
27 // MC_random() is in mc_base.cpp
29 void MC_assert(int prop)
31 xbt_assert(mc_model_checker == nullptr);
32 if (MC_is_active() && not prop)
33 simgrid::mc::Client::get()->reportAssertionFailure();
38 xbt_assert(mc_model_checker == nullptr);
39 if (not MC_is_active())
41 // FIXME, We want to do this in the model-checker:
42 xbt_die("MC_cut() not implemented");
45 void MC_ignore(void* addr, size_t size)
47 xbt_assert(mc_model_checker == nullptr);
48 if (not MC_is_active())
50 simgrid::mc::Client::get()->ignoreMemory(addr, size);
53 void MC_automaton_new_propositional_symbol(const char* id, int (*fct)())
55 xbt_assert(mc_model_checker == nullptr);
56 if (not MC_is_active())
58 xbt_die("Support for client-side function proposition is not implemented: "
59 "use MC_automaton_new_propositional_symbol_pointer instead.");
62 void MC_automaton_new_propositional_symbol_pointer(const char *name, int* value)
64 xbt_assert(mc_model_checker == nullptr);
65 if (not MC_is_active())
67 simgrid::mc::Client::get()->declareSymbol(name, value);
70 /** @brief Register a stack in the model checker
72 * The stacks are allocated in the heap. The MC handle them specifically
73 * when we analyze/compare the content of the heap so it must be told where
74 * they are with this function.
76 * @param stack Where the stack is
77 * @param actor Actor owning the stack
78 * @param context The context associated to that stack
79 * @param size Size of the stack
81 void MC_register_stack_area(void* stack, smx_actor_t actor, ucontext_t* context, size_t size)
83 xbt_assert(mc_model_checker == nullptr);
84 if (not MC_is_active())
86 simgrid::mc::Client::get()->declareStack(stack, size, actor, context);
89 void MC_ignore_global_variable(const char *name)
91 xbt_assert(mc_model_checker == nullptr);
92 if (not MC_is_active())
94 // TODO, send a message to the model_checker
95 xbt_die("Unimplemented");
98 void MC_ignore_heap(void *address, size_t size)
100 xbt_assert(mc_model_checker == nullptr);
101 if (not MC_is_active())
103 simgrid::mc::Client::get()->ignoreHeap(address, size);
106 void MC_unignore_heap(void* address, size_t size)
108 xbt_assert(mc_model_checker == nullptr);
109 if (not MC_is_active())
111 simgrid::mc::Client::get()->unignoreHeap(address, size);