Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
850be7afb9bf4121147cac7d48b7fa7f3e5107bb
[simgrid.git] / src / mc / LivenessChecker.cpp
1 /* Copyright (c) 2011-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 <cstring>
8
9 #include <algorithm>
10 #include <memory>
11
12 #include <unistd.h>
13 #include <sys/wait.h>
14
15 #include <xbt/automaton.h>
16 #include <xbt/dynar.h>
17 #include <xbt/dynar.hpp>
18 #include <xbt/fifo.h>
19 #include <xbt/log.h>
20 #include <xbt/sysdep.h>
21
22 #include "src/mc/mc_request.h"
23 #include "src/mc/LivenessChecker.hpp"
24 #include "src/mc/mc_private.h"
25 #include "src/mc/mc_record.h"
26 #include "src/mc/mc_smx.h"
27 #include "src/mc/Client.hpp"
28 #include "src/mc/mc_private.h"
29 #include "src/mc/mc_replay.h"
30 #include "src/mc/mc_safety.h"
31 #include "src/mc/mc_exit.h"
32
33 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_liveness, mc,
34                                 "Logging specific to algorithms for liveness properties verification");
35
36 /********* Global variables *********/
37
38 xbt_dynar_t acceptance_pairs;
39 static xbt_fifo_t liveness_stack;
40
41 /********* Static functions *********/
42
43 namespace simgrid {
44 namespace mc {
45
46 VisitedPair::VisitedPair(int pair_num, xbt_automaton_state_t automaton_state, xbt_dynar_t atomic_propositions, mc_state_t graph_state)
47 {
48   simgrid::mc::Process* process = &(mc_model_checker->process());
49
50   this->graph_state = graph_state;
51   if(this->graph_state->system_state == nullptr)
52     this->graph_state->system_state = simgrid::mc::take_snapshot(pair_num);
53   this->heap_bytes_used = mmalloc_get_bytes_used_remote(
54     process->get_heap()->heaplimit,
55     process->get_malloc_info());
56
57   this->nb_processes =
58     mc_model_checker->process().simix_processes().size();
59
60   this->automaton_state = automaton_state;
61   this->num = pair_num;
62   this->other_num = -1;
63   this->acceptance_removed = 0;
64   this->visited_removed = 0;
65   this->acceptance_pair = 0;
66   this->atomic_propositions = simgrid::xbt::unique_ptr<s_xbt_dynar_t>(
67     xbt_dynar_new(sizeof(int), nullptr));
68
69   unsigned int cursor = 0;
70   int value;
71   xbt_dynar_foreach(atomic_propositions, cursor, value)
72       xbt_dynar_push_as(this->atomic_propositions.get(), int, value);
73 }
74
75 static int is_exploration_stack_pair(simgrid::mc::VisitedPair* pair){
76   xbt_fifo_item_t item = xbt_fifo_get_first_item(liveness_stack);
77   while (item) {
78     if (((simgrid::mc::Pair*)xbt_fifo_get_item_content(item))->num == pair->num){
79       ((simgrid::mc::Pair*)xbt_fifo_get_item_content(item))->visited_pair_removed = 1;
80       return 1;
81     }
82     item = xbt_fifo_get_next_item(item);
83   }
84   return 0;
85 }
86
87 VisitedPair::~VisitedPair()
88 {
89   if( !is_exploration_stack_pair(this))
90     MC_state_delete(this->graph_state, 1);
91 }
92
93 static int MC_automaton_evaluate_label(xbt_automaton_exp_label_t l,
94                                        xbt_dynar_t atomic_propositions_values)
95 {
96
97   switch (l->type) {
98   case 0:{
99       int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp, atomic_propositions_values);
100       int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp, atomic_propositions_values);
101       return (left_res || right_res);
102     }
103   case 1:{
104       int left_res = MC_automaton_evaluate_label(l->u.or_and.left_exp, atomic_propositions_values);
105       int right_res = MC_automaton_evaluate_label(l->u.or_and.right_exp, atomic_propositions_values);
106       return (left_res && right_res);
107     }
108   case 2:{
109       int res = MC_automaton_evaluate_label(l->u.exp_not, atomic_propositions_values);
110       return (!res);
111     }
112   case 3:{
113       unsigned int cursor = 0;
114       xbt_automaton_propositional_symbol_t p = nullptr;
115       xbt_dynar_foreach(simgrid::mc::property_automaton->propositional_symbols, cursor, p) {
116         if (std::strcmp(xbt_automaton_propositional_symbol_get_name(p), l->u.predicat) == 0)
117           return (int) xbt_dynar_get_as(atomic_propositions_values, cursor, int);
118       }
119       return -1;
120     }
121   case 4:
122     return 2;
123   default:
124     return -1;
125   }
126 }
127
128 static xbt_dynar_t visited_pairs;
129
130 Pair::Pair() : num(++mc_stats->expanded_pairs),
131   visited_pair_removed(_sg_mc_visited > 0 ? 0 : 1)
132 {}
133
134 Pair::~Pair() {
135   if (this->visited_pair_removed)
136     MC_state_delete(this->graph_state, 1);
137 }
138
139 simgrid::xbt::unique_ptr<s_xbt_dynar_t> LivenessChecker::getPropositionValues()
140 {
141   unsigned int cursor = 0;
142   xbt_automaton_propositional_symbol_t ps = nullptr;
143   simgrid::xbt::unique_ptr<s_xbt_dynar_t> values = simgrid::xbt::unique_ptr<s_xbt_dynar_t>(xbt_dynar_new(sizeof(int), nullptr));
144   xbt_dynar_foreach(simgrid::mc::property_automaton->propositional_symbols, cursor, ps) {
145     int res = xbt_automaton_propositional_symbol_evaluate(ps);
146     xbt_dynar_push_as(values.get(), int, res);
147   }
148   return std::move(values);
149 }
150
151 int LivenessChecker::compare(simgrid::mc::VisitedPair* state1, simgrid::mc::VisitedPair* state2)
152 {
153   simgrid::mc::Snapshot* s1 = state1->graph_state->system_state;
154   simgrid::mc::Snapshot* s2 = state2->graph_state->system_state;
155   int num1 = state1->num;
156   int num2 = state2->num;
157   return simgrid::mc::snapshot_compare(num1, s1, num2, s2);
158 }
159
160 simgrid::mc::VisitedPair* LivenessChecker::insertAcceptancePair(simgrid::mc::Pair* pair)
161 {
162   auto acceptance_pairs = simgrid::xbt::range<simgrid::mc::VisitedPair*>(::acceptance_pairs);
163   auto new_pair =
164     std::unique_ptr<simgrid::mc::VisitedPair>(new VisitedPair(
165       pair->num, pair->automaton_state, pair->atomic_propositions.get(),
166       pair->graph_state));
167   new_pair->acceptance_pair = 1;
168
169   auto res = std::equal_range(acceptance_pairs.begin(), acceptance_pairs.end(),
170     new_pair, simgrid::mc::DerefAndCompareByNbProcessesAndUsedHeap());
171
172   if (pair->search_cycle == 1)
173     for (auto i = res.first; i != res.second; ++i) {
174       simgrid::mc::VisitedPair* pair_test = *i;
175       if (xbt_automaton_state_compare(pair_test->automaton_state, new_pair->automaton_state) == 0) {
176         if (xbt_automaton_propositional_symbols_compare_value(
177             pair_test->atomic_propositions.get(),
178             new_pair->atomic_propositions.get()) == 0) {
179           if (this->compare(pair_test, new_pair.get()) == 0) {
180             XBT_INFO("Pair %d already reached (equal to pair %d) !", new_pair->num, pair_test->num);
181             xbt_fifo_shift(liveness_stack);
182             if (dot_output != nullptr)
183               fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", initial_global_state->prev_pair, pair_test->num, initial_global_state->prev_req);
184             return nullptr;
185           }
186         }
187       }
188     }
189
190   auto new_raw_pair = new_pair.release();
191   xbt_dynar_insert_at(
192     ::acceptance_pairs, res.first - acceptance_pairs.begin(), &new_raw_pair);
193   return new_raw_pair;
194 }
195
196 void LivenessChecker::removeAcceptancePair(int pair_num)
197 {
198   unsigned int cursor = 0;
199   simgrid::mc::VisitedPair* pair_test = nullptr;
200   int pair_found = 0;
201
202   xbt_dynar_foreach(acceptance_pairs, cursor, pair_test)
203     if (pair_test->num == pair_num) {
204        pair_found = 1;
205       break;
206     }
207
208   if(pair_found == 1) {
209     xbt_dynar_remove_at(acceptance_pairs, cursor, &pair_test);
210
211     pair_test->acceptance_removed = 1;
212
213     if (_sg_mc_visited == 0 || pair_test->visited_removed == 1) 
214       delete pair_test;
215
216   }
217 }
218
219 void LivenessChecker::prepare(void)
220 {
221   simgrid::mc::Pair* initial_pair = nullptr;
222   mc_model_checker->wait_for_requests();
223   acceptance_pairs = xbt_dynar_new(sizeof(simgrid::mc::VisitedPair*), nullptr);
224   if(_sg_mc_visited > 0)
225     simgrid::mc::visited_pairs = xbt_dynar_new(sizeof(simgrid::mc::VisitedPair*), nullptr);
226
227   initial_global_state->snapshot = simgrid::mc::take_snapshot(0);
228   initial_global_state->prev_pair = 0;
229
230   unsigned int cursor = 0;
231   xbt_automaton_state_t automaton_state;
232
233   xbt_dynar_foreach(simgrid::mc::property_automaton->states, cursor, automaton_state) {
234     if (automaton_state->type == -1) {  /* Initial automaton state */
235
236       initial_pair = new Pair();
237       initial_pair->automaton_state = automaton_state;
238       initial_pair->graph_state = MC_state_new();
239       initial_pair->atomic_propositions = this->getPropositionValues();
240       initial_pair->depth = 1;
241
242       /* Get enabled processes and insert them in the interleave set of the graph_state */
243       for (auto& p : mc_model_checker->process().simix_processes())
244         if (simgrid::mc::process_is_enabled(&p.copy))
245           MC_state_interleave_process(initial_pair->graph_state, &p.copy);
246
247       initial_pair->requests = MC_state_interleave_size(initial_pair->graph_state);
248       initial_pair->search_cycle = 0;
249
250       xbt_fifo_unshift(liveness_stack, initial_pair);
251     }
252   }
253 }
254
255
256 void LivenessChecker::replay(xbt_fifo_t stack)
257 {
258   xbt_fifo_item_t item;
259   simgrid::mc::Pair* pair = nullptr;
260   mc_state_t state = nullptr;
261   smx_simcall_t req = nullptr, saved_req = NULL;
262   int value, depth = 1;
263   char *req_str;
264
265   XBT_DEBUG("**** Begin Replay ****");
266
267   /* Intermediate backtracking */
268   if(_sg_mc_checkpoint > 0) {
269     item = xbt_fifo_get_first_item(stack);
270     pair = (simgrid::mc::Pair*) xbt_fifo_get_item_content(item);
271     if(pair->graph_state->system_state){
272       simgrid::mc::restore_snapshot(pair->graph_state->system_state);
273       return;
274     }
275   }
276
277   /* Restore the initial state */
278   simgrid::mc::restore_snapshot(initial_global_state->snapshot);
279
280     /* Traverse the stack from the initial state and re-execute the transitions */
281     for (item = xbt_fifo_get_last_item(stack);
282          item != xbt_fifo_get_first_item(stack);
283          item = xbt_fifo_get_prev_item(item)) {
284
285       pair = (simgrid::mc::Pair*) xbt_fifo_get_item_content(item);
286
287       state = (mc_state_t) pair->graph_state;
288
289       if (pair->exploration_started) {
290
291         saved_req = MC_state_get_executed_request(state, &value);
292
293         if (saved_req != nullptr) {
294           /* because we got a copy of the executed request, we have to fetch the
295              real one, pointed by the request field of the issuer process */
296           const smx_process_t issuer = MC_smx_simcall_get_issuer(saved_req);
297           req = &issuer->simcall;
298
299           /* Debug information */
300           if (XBT_LOG_ISENABLED(mc_liveness, xbt_log_priority_debug)) {
301             req_str = simgrid::mc::request_to_string(req, value, simgrid::mc::RequestType::simix);
302             XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
303             xbt_free(req_str);
304           }
305
306         }
307
308         simgrid::mc::handle_simcall(req, value);
309         mc_model_checker->wait_for_requests();
310       }
311
312       /* Update statistics */
313       mc_stats->visited_pairs++;
314       mc_stats->executed_transitions++;
315
316       depth++;
317
318     }
319
320   XBT_DEBUG("**** End Replay ****");
321 }
322
323 /**
324  * \brief Checks whether a given pair has already been visited by the algorithm.
325  */
326 int LivenessChecker::insertVisitedPair(simgrid::mc::VisitedPair* visited_pair, simgrid::mc::Pair* pair)
327 {
328   if (_sg_mc_visited == 0)
329     return -1;
330
331   simgrid::mc::VisitedPair* new_visited_pair = nullptr;
332   if (visited_pair == nullptr)
333     new_visited_pair = new simgrid::mc::VisitedPair(
334       pair->num, pair->automaton_state, pair->atomic_propositions.get(),
335       pair->graph_state);
336   else
337     new_visited_pair = visited_pair;
338
339   auto visited_pairs = simgrid::xbt::range<simgrid::mc::VisitedPair*>(simgrid::mc::visited_pairs);
340
341   auto range = std::equal_range(visited_pairs.begin(), visited_pairs.end(),
342     new_visited_pair, simgrid::mc::DerefAndCompareByNbProcessesAndUsedHeap());
343
344   for (auto i = range.first; i != range.second; ++i) {
345     simgrid::mc::VisitedPair* pair_test = *i;
346     std::size_t cursor = i - visited_pairs.begin();
347     if (xbt_automaton_state_compare(pair_test->automaton_state, new_visited_pair->automaton_state) == 0) {
348       if (xbt_automaton_propositional_symbols_compare_value(
349           pair_test->atomic_propositions.get(),
350           new_visited_pair->atomic_propositions.get()) == 0) {
351         if (this->compare(pair_test, new_visited_pair) == 0) {
352           if (pair_test->other_num == -1)
353             new_visited_pair->other_num = pair_test->num;
354           else
355             new_visited_pair->other_num = pair_test->other_num;
356           if (dot_output == nullptr)
357             XBT_DEBUG("Pair %d already visited ! (equal to pair %d)", new_visited_pair->num, pair_test->num);
358           else
359             XBT_DEBUG("Pair %d already visited ! (equal to pair %d (pair %d in dot_output))", new_visited_pair->num, pair_test->num, new_visited_pair->other_num);
360           xbt_dynar_remove_at(simgrid::mc::visited_pairs, cursor, &pair_test);
361           xbt_dynar_insert_at(simgrid::mc::visited_pairs, cursor, &new_visited_pair);
362           pair_test->visited_removed = 1;
363           if (!pair_test->acceptance_pair
364               || pair_test->acceptance_removed == 1)
365             delete pair_test;
366           return new_visited_pair->other_num;
367         }
368       }
369     }
370   }
371
372   xbt_dynar_insert_at(simgrid::mc::visited_pairs, range.first - visited_pairs.begin(), &new_visited_pair);
373
374   if ((ssize_t) visited_pairs.size() > _sg_mc_visited) {
375     int min2 = mc_stats->expanded_pairs;
376     unsigned int index2 = 0;
377     for (std::size_t i = 0; i != (std::size_t) visited_pairs.size(); ++i) {
378       simgrid::mc::VisitedPair* pair_test = visited_pairs[i];
379       if (!mc_model_checker->is_important_snapshot(*pair_test->graph_state->system_state)
380           && pair_test->num < min2) {
381         index2 = i;
382         min2 = pair_test->num;
383       }
384     }
385     simgrid::mc::VisitedPair* pair_test = nullptr;
386     xbt_dynar_remove_at(simgrid::mc::visited_pairs, index2, &pair_test);
387     pair_test->visited_removed = 1;
388     if (!pair_test->acceptance_pair || pair_test->acceptance_removed)
389       delete pair_test;
390   }
391
392   return -1;
393 }
394
395 LivenessChecker::LivenessChecker(Session& session) : Checker(session)
396 {
397 }
398
399 LivenessChecker::~LivenessChecker()
400 {
401 }
402
403 RecordTrace LivenessChecker::getRecordTrace() // override
404 {
405   RecordTrace res;
406
407   xbt_fifo_item_t start = xbt_fifo_get_last_item(liveness_stack);
408   for (xbt_fifo_item_t item = start; item; item = xbt_fifo_get_prev_item(item)) {
409     simgrid::mc::Pair* pair = (simgrid::mc::Pair*) xbt_fifo_get_item_content(item);
410     int value;
411     smx_simcall_t req = MC_state_get_executed_request(pair->graph_state, &value);
412     if (req && req->call != SIMCALL_NONE) {
413       smx_process_t issuer = MC_smx_simcall_get_issuer(req);
414       const int pid = issuer->pid;
415
416       // Serialization the (pid, value) pair:
417       res.push_back(RecordTraceElement(pid, value));
418     }
419   }
420
421   return std::move(res);
422 }
423
424 void LivenessChecker::showAcceptanceCycle(std::size_t depth)
425 {
426   XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
427   XBT_INFO("|             ACCEPTANCE CYCLE            |");
428   XBT_INFO("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
429   XBT_INFO("Counter-example that violates formula :");
430   simgrid::mc::dumpRecordPath();
431   for (auto& s : this->getTextualTrace())
432     XBT_INFO("%s", s.c_str());
433   MC_print_statistics(mc_stats);
434   XBT_INFO("Counter-example depth : %zd", depth);
435 }
436
437 std::vector<std::string> LivenessChecker::getTextualTrace() // override
438 {
439   std::vector<std::string> trace;
440   for (xbt_fifo_item_t item = xbt_fifo_get_last_item(liveness_stack);
441        item; item = xbt_fifo_get_prev_item(item)) {
442     simgrid::mc::Pair* pair = (simgrid::mc::Pair*) xbt_fifo_get_item_content(item);
443     int value;
444     smx_simcall_t req = MC_state_get_executed_request(pair->graph_state, &value);
445     if (req && req->call != SIMCALL_NONE) {
446       char* req_str = simgrid::mc::request_to_string(req, value, simgrid::mc::RequestType::executed);
447       trace.push_back(std::string(req_str));
448       xbt_free(req_str);
449     }
450   }
451   return std::move(trace);
452 }
453
454 int LivenessChecker::main(void)
455 {
456   simgrid::mc::Pair* current_pair = nullptr;
457   int value, res, visited_num = -1;
458   smx_simcall_t req = nullptr;
459   xbt_automaton_transition_t transition_succ = nullptr;
460   int cursor = 0;
461   simgrid::mc::Pair* next_pair = nullptr;
462   simgrid::xbt::unique_ptr<s_xbt_dynar_t> prop_values;
463   simgrid::mc::VisitedPair* reached_pair = nullptr;
464
465   while(xbt_fifo_size(liveness_stack) > 0){
466
467     /* Get current pair */
468     current_pair = (simgrid::mc::Pair*) xbt_fifo_get_item_content(xbt_fifo_get_first_item(liveness_stack));
469
470     /* Update current state in buchi automaton */
471     simgrid::mc::property_automaton->current_state = current_pair->automaton_state;
472
473     XBT_DEBUG("********************* ( Depth = %d, search_cycle = %d, interleave size = %d, pair_num = %d, requests = %d)",
474        current_pair->depth, current_pair->search_cycle,
475        MC_state_interleave_size(current_pair->graph_state), current_pair->num,
476        current_pair->requests);
477
478     if (current_pair->requests > 0) {
479
480       if (current_pair->automaton_state->type == 1 && current_pair->exploration_started == 0) {
481         /* If new acceptance pair, return new pair */
482         if ((reached_pair = this->insertAcceptancePair(current_pair)) == nullptr) {
483           this->showAcceptanceCycle(current_pair->depth);
484           return SIMGRID_MC_EXIT_LIVENESS;
485         }
486       }
487
488       /* Pair already visited ? stop the exploration on the current path */
489       if ((current_pair->exploration_started == 0)
490         && (visited_num = this->insertVisitedPair(
491           reached_pair, current_pair)) != -1) {
492
493         if (dot_output != nullptr){
494           fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", initial_global_state->prev_pair, visited_num, initial_global_state->prev_req);
495           fflush(dot_output);
496         }
497
498         XBT_DEBUG("Pair already visited (equal to pair %d), exploration on the current path stopped.", visited_num);
499         current_pair->requests = 0;
500         goto backtracking;
501
502       }else{
503
504         req = MC_state_get_request(current_pair->graph_state, &value);
505
506          if (dot_output != nullptr) {
507            if (initial_global_state->prev_pair != 0 && initial_global_state->prev_pair != current_pair->num) {
508              fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", initial_global_state->prev_pair, current_pair->num, initial_global_state->prev_req);
509              xbt_free(initial_global_state->prev_req);
510            }
511            initial_global_state->prev_pair = current_pair->num;
512            initial_global_state->prev_req = simgrid::mc::request_get_dot_output(req, value);
513            if (current_pair->search_cycle)
514              fprintf(dot_output, "%d [shape=doublecircle];\n", current_pair->num);
515            fflush(dot_output);
516          }
517
518          char* req_str = simgrid::mc::request_to_string(req, value, simgrid::mc::RequestType::simix);
519          XBT_DEBUG("Execute: %s", req_str);
520          xbt_free(req_str);
521
522          /* Set request as executed */
523          MC_state_set_executed_request(current_pair->graph_state, req, value);
524
525          /* Update mc_stats */
526          mc_stats->executed_transitions++;
527          if(current_pair->exploration_started == 0)
528            mc_stats->visited_pairs++;
529
530          /* Answer the request */
531          simgrid::mc::handle_simcall(req, value);
532
533          /* Wait for requests (schedules processes) */
534          mc_model_checker->wait_for_requests();
535
536          current_pair->requests--;
537          current_pair->exploration_started = 1;
538
539          /* Get values of atomic propositions (variables used in the property formula) */
540          prop_values = this->getPropositionValues();
541
542          /* Evaluate enabled/true transitions in automaton according to atomic propositions values and create new pairs */
543          cursor = xbt_dynar_length(current_pair->automaton_state->out) - 1;
544          while (cursor >= 0) {
545            transition_succ = (xbt_automaton_transition_t)xbt_dynar_get_as(current_pair->automaton_state->out, cursor, xbt_automaton_transition_t);
546            res = MC_automaton_evaluate_label(transition_succ->label, prop_values.get());
547            if (res == 1 || res == 2) { /* 1 = True transition (always enabled), 2 = enabled transition according to atomic prop values */
548               next_pair = new Pair();
549               next_pair->graph_state = MC_state_new();
550               next_pair->automaton_state = transition_succ->dst;
551               next_pair->atomic_propositions = this->getPropositionValues();
552               next_pair->depth = current_pair->depth + 1;
553               /* Get enabled processes and insert them in the interleave set of the next graph_state */
554               for (auto& p : mc_model_checker->process().simix_processes())
555                 if (simgrid::mc::process_is_enabled(&p.copy))
556                   MC_state_interleave_process(next_pair->graph_state, &p.copy);
557
558               next_pair->requests = MC_state_interleave_size(next_pair->graph_state);
559
560               /* FIXME : get search_cycle value for each acceptant state */
561               if (next_pair->automaton_state->type == 1 || current_pair->search_cycle)
562                 next_pair->search_cycle = 1;
563
564               /* Add new pair to the exploration stack */
565               xbt_fifo_unshift(liveness_stack, next_pair);
566
567            }
568            cursor--;
569          }
570
571       } /* End of visited_pair test */
572
573     } else {
574
575     backtracking:
576       if(visited_num == -1)
577         XBT_DEBUG("No more request to execute. Looking for backtracking point.");
578
579       prop_values.reset();
580
581       /* Traverse the stack backwards until a pair with a non empty interleave
582          set is found, deleting all the pairs that have it empty in the way. */
583       while ((current_pair = (simgrid::mc::Pair*) xbt_fifo_shift(liveness_stack)) != nullptr) {
584         if (current_pair->requests > 0) {
585           /* We found a backtracking point */
586           XBT_DEBUG("Backtracking to depth %d", current_pair->depth);
587           xbt_fifo_unshift(liveness_stack, current_pair);
588           this->replay(liveness_stack);
589           XBT_DEBUG("Backtracking done");
590           break;
591         }else{
592           /* Delete pair */
593           XBT_DEBUG("Delete pair %d at depth %d", current_pair->num, current_pair->depth);
594           if (current_pair->automaton_state->type == 1)
595             this->removeAcceptancePair(current_pair->num);
596           delete current_pair;
597         }
598       }
599
600     } /* End of if (current_pair->requests > 0) else ... */
601
602   } /* End of while(xbt_fifo_size(liveness_stack) > 0) */
603
604   XBT_INFO("No property violation found.");
605   MC_print_statistics(mc_stats);
606   return SIMGRID_MC_EXIT_SUCCESS;
607 }
608
609 int LivenessChecker::run()
610 {
611   XBT_INFO("Check the liveness property %s", _sg_mc_property_file);
612   MC_automaton_load(_sg_mc_property_file);
613   mc_model_checker->wait_for_requests();
614
615   XBT_DEBUG("Starting the liveness algorithm");
616   _sg_mc_liveness = 1;
617
618   /* Create exploration stack */
619   liveness_stack = xbt_fifo_new();
620
621   /* Create the initial state */
622   initial_global_state = xbt_new0(s_mc_global_t, 1);
623
624   this->prepare();
625   return this->main();
626 }
627
628 }
629 }