Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] C++ification of State
[simgrid.git] / src / mc / mc_record.h
1 /* Copyright (c) 2014-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 /** \file
8  *  This file contains the MC replay/record functionnality.
9  *  A MC path may be recorded by using ``-cfg=model-check/record:1`'`.
10  *  The path is written in the log output and an be replayed with MC disabled
11  *  (even with an non-LC build) with `--cfg=model-check/replay:$replayPath`.
12  *
13  *  The same version of Simgrid should be used and the same arguments should be
14  *  passed to the application (without the MC specific arguments).
15  */
16
17 #ifndef SIMGRID_MC_RECORD_H
18 #define SIMGRID_MC_RECORD_H
19
20 #include <string>
21 #include <vector>
22
23 #include <xbt/base.h>
24 #include <xbt/dynar.h>
25 #include <xbt/fifo.h>
26
27 namespace simgrid {
28 namespace mc {
29
30 /** An element in the recorded path
31  *
32  *  At each decision point, we need to record which process transition
33  *  is trigerred and potentially which value is associated with this
34  *  transition. The value is used to find which communication is triggerred
35  *  in things like waitany and for associating a given value of MC_random()
36  *  calls.
37  */
38 struct RecordTraceElement {
39   int pid = 0;
40   int value = 0;
41   RecordTraceElement() {}
42   RecordTraceElement(int pid, int value) : pid(pid), value(value) {}
43 };
44
45 typedef std::vector<RecordTraceElement> RecordTrace;
46
47 /** Convert a string representation of the path into a array of `simgrid::mc::RecordTraceElement`
48  */
49 XBT_PRIVATE RecordTrace parseRecordTrace(const char* data);
50 XBT_PRIVATE std::string traceToString(simgrid::mc::RecordTrace const& trace);
51 XBT_PRIVATE void dumpRecordPath();
52
53 XBT_PRIVATE void replay(RecordTrace const& trace);
54 XBT_PRIVATE void replay(const char* trace);
55
56 }
57 }
58
59 SG_BEGIN_DECL()
60
61 /** Whether the MC record mode is enabled
62  *
63  *  The behaviour is not changed. The only real difference is that
64  *  the path is writtent in the log when an interesting path is found.
65  */
66 #define MC_record_is_active() _sg_do_model_check_record
67
68 // **** Data conversion
69
70 /** Generate a string representation
71 *
72 * The current format is a ";"-delimited list of pairs:
73 * "pid0,value0;pid2,value2;pid3,value3". The value can be
74 * omitted is it is null.
75 */
76 XBT_PRIVATE char* MC_record_stack_to_string(xbt_fifo_t stack);
77
78 SG_END_DECL()
79
80 #endif