Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add semantic equivalence to UnfoldingEvent
[simgrid.git] / src / mc / explo / udpor / UnfoldingEvent_test.cpp
1 /* Copyright (c) 2017-2023. The SimGrid Team. All rights reserved.               */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "src/3rd-party/catch.hpp"
7 #include "src/mc/explo/udpor/UnfoldingEvent.hpp"
8 #include "src/mc/explo/udpor/udpor_tests_private.hpp"
9
10 using namespace simgrid::mc;
11 using namespace simgrid::mc::udpor;
12
13 TEST_CASE("simgrid::mc::udpor::UnfoldingEvent: Semantic Equivalence Tests")
14 {
15   UnfoldingEvent e1(EventSet(), std::make_shared<IndependentAction>(Transition::Type::UNKNOWN, 0, 0));
16   UnfoldingEvent e2(EventSet({&e1}), std::make_shared<IndependentAction>(Transition::Type::UNKNOWN, 0, 0));
17   UnfoldingEvent e3(EventSet({&e1}), std::make_shared<IndependentAction>(Transition::Type::UNKNOWN, 0, 0));
18   UnfoldingEvent e4(EventSet({&e1}), std::make_shared<IndependentAction>(Transition::Type::UNKNOWN, 0, 0));
19
20   UnfoldingEvent e5(EventSet({&e1, &e3, &e2}), std::make_shared<IndependentAction>(Transition::Type::UNKNOWN, 0, 0));
21   UnfoldingEvent e6(EventSet({&e1, &e3, &e2}), std::make_shared<IndependentAction>(Transition::Type::UNKNOWN, 0, 0));
22   UnfoldingEvent e7(EventSet({&e1, &e3, &e2}), std::make_shared<IndependentAction>(Transition::Type::UNKNOWN, 0, 0));
23
24   SECTION("Equivalence is an equivalence relation")
25   {
26     SECTION("Equivalence is reflexive")
27     {
28       REQUIRE(e1 == e1);
29       REQUIRE(e2 == e2);
30       REQUIRE(e3 == e3);
31       REQUIRE(e4 == e4);
32     }
33
34     SECTION("Equivalence is symmetric")
35     {
36       REQUIRE(e2 == e3);
37       REQUIRE(e3 == e2);
38       REQUIRE(e3 == e4);
39       REQUIRE(e4 == e3);
40       REQUIRE(e2 == e4);
41       REQUIRE(e4 == e2);
42     }
43
44     SECTION("Equivalence is transitive")
45     {
46       REQUIRE(e2 == e3);
47       REQUIRE(e3 == e4);
48       REQUIRE(e2 == e4);
49       REQUIRE(e5 == e6);
50       REQUIRE(e6 == e7);
51       REQUIRE(e5 == e7);
52     }
53   }
54
55   SECTION("Equivalence fails with different actors")
56   {
57     UnfoldingEvent e1_diff_actor(EventSet(), std::make_shared<IndependentAction>(Transition::Type::UNKNOWN, 1, 0));
58     UnfoldingEvent e2_diff_actor(EventSet({&e1}), std::make_shared<IndependentAction>(Transition::Type::UNKNOWN, 1, 0));
59     UnfoldingEvent e5_diff_actor(EventSet({&e1, &e3, &e2}),
60                                  std::make_shared<DependentAction>(Transition::Type::UNKNOWN, 1, 0));
61     REQUIRE(e1 != e1_diff_actor);
62     REQUIRE(e1 != e2_diff_actor);
63     REQUIRE(e1 != e5_diff_actor);
64   }
65
66   SECTION("Equivalence fails with different transition types")
67   {
68     // NOTE: We're comparing the transition `type_` field directly. To avoid
69     // modifying the `Type` enum that exists in `Transition` just for the tests,
70     // we instead provide different values of `Transition::Type` to simulate
71     // the different types
72     UnfoldingEvent e1_diff_transition(EventSet(),
73                                       std::make_shared<IndependentAction>(Transition::Type::ACTOR_JOIN, 0, 0));
74     UnfoldingEvent e2_diff_transition(EventSet({&e1}),
75                                       std::make_shared<IndependentAction>(Transition::Type::ACTOR_JOIN, 0, 0));
76     UnfoldingEvent e5_diff_transition(EventSet({&e1, &e3, &e2}),
77                                       std::make_shared<IndependentAction>(Transition::Type::ACTOR_JOIN, 0, 0));
78     REQUIRE(e1 != e1_diff_transition);
79     REQUIRE(e1 != e2_diff_transition);
80     REQUIRE(e1 != e5_diff_transition);
81   }
82
83   SECTION("Equivalence fails with different `times_considered`")
84   {
85     // With a different number for `times_considered`, we know
86     UnfoldingEvent e1_diff_considered(EventSet(), std::make_shared<IndependentAction>(Transition::Type::UNKNOWN, 0, 1));
87     UnfoldingEvent e2_diff_considered(EventSet({&e1}),
88                                       std::make_shared<IndependentAction>(Transition::Type::UNKNOWN, 0, 1));
89     UnfoldingEvent e5_diff_considered(EventSet({&e1, &e3, &e2}),
90                                       std::make_shared<IndependentAction>(Transition::Type::UNKNOWN, 0, 1));
91     REQUIRE(e1 != e1_diff_considered);
92     REQUIRE(e1 != e2_diff_considered);
93     REQUIRE(e1 != e5_diff_considered);
94   }
95
96   SECTION("Equivalence fails with different immediate histories of events")
97   {
98     UnfoldingEvent e1_diff_hist(EventSet({&e2}), std::make_shared<IndependentAction>(Transition::Type::UNKNOWN, 0, 0));
99     UnfoldingEvent e2_diff_hist(EventSet({&e3}), std::make_shared<IndependentAction>(Transition::Type::UNKNOWN, 0, 0));
100     UnfoldingEvent e5_diff_hist(EventSet({&e1, &e2}),
101                                 std::make_shared<IndependentAction>(Transition::Type::UNKNOWN, 0, 0));
102     REQUIRE(e1 != e1_diff_hist);
103     REQUIRE(e1 != e2_diff_hist);
104     REQUIRE(e1 != e5_diff_hist);
105   }
106 }
107
108 TEST_CASE("simgrid::mc::udpor::UnfoldingEvent: Dependency/Conflict Tests")
109 {
110   SECTION("Properties of the relations")
111   {
112     // The following tests concern the given event structure:
113     //                e1
114     //              /   /
115     //            e2    e6
116     //           /  /    /
117     //          e3   /   /
118     //         /  /    /
119     //        e4  e5   e7
120     //
121     // e5 and e6 are in conflict, e5 and e7 are in conflict, e2 and e6, and e2 ands e7 are in conflict
122     UnfoldingEvent e1(EventSet(), std::make_shared<ConditionallyDependentAction>());
123     UnfoldingEvent e2(EventSet({&e1}), std::make_shared<DependentAction>());
124     UnfoldingEvent e3(EventSet({&e2}), std::make_shared<IndependentAction>());
125     UnfoldingEvent e4(EventSet({&e3}), std::make_shared<ConditionallyDependentAction>());
126     UnfoldingEvent e5(EventSet({&e3}), std::make_shared<DependentAction>());
127     UnfoldingEvent e6(EventSet({&e1}), std::make_shared<ConditionallyDependentAction>());
128     UnfoldingEvent e7(EventSet({&e6, &e2}), std::make_shared<ConditionallyDependentAction>());
129
130     SECTION("Dependency relation properties")
131     {
132       SECTION("Dependency is reflexive")
133       {
134         REQUIRE(e2.is_dependent_with(&e2));
135         REQUIRE(e5.is_dependent_with(&e5));
136       }
137
138       SECTION("Dependency is symmetric")
139       {
140         REQUIRE(e2.is_dependent_with(&e6));
141         REQUIRE(e6.is_dependent_with(&e2));
142       }
143
144       SECTION("Dependency is NOT necessarily transitive")
145       {
146         REQUIRE(e1.is_dependent_with(&e5));
147         REQUIRE(e5.is_dependent_with(&e7));
148         REQUIRE_FALSE(e1.is_dependent_with(&e7));
149       }
150     }
151
152     SECTION("Conflict relation properties")
153     {
154       SECTION("Conflict relation is irreflexive")
155       {
156         REQUIRE_FALSE(e1.conflicts_with(&e1));
157         REQUIRE_FALSE(e2.conflicts_with(&e2));
158         REQUIRE_FALSE(e3.conflicts_with(&e3));
159         REQUIRE_FALSE(e4.conflicts_with(&e4));
160         REQUIRE_FALSE(e5.conflicts_with(&e5));
161         REQUIRE_FALSE(e6.conflicts_with(&e6));
162         REQUIRE_FALSE(e7.conflicts_with(&e7));
163
164         REQUIRE_FALSE(e1.immediately_conflicts_with(&e1));
165         REQUIRE_FALSE(e2.immediately_conflicts_with(&e2));
166         REQUIRE_FALSE(e3.immediately_conflicts_with(&e3));
167         REQUIRE_FALSE(e4.immediately_conflicts_with(&e4));
168         REQUIRE_FALSE(e5.immediately_conflicts_with(&e5));
169         REQUIRE_FALSE(e6.immediately_conflicts_with(&e6));
170         REQUIRE_FALSE(e7.immediately_conflicts_with(&e7));
171       }
172
173       SECTION("Conflict relation is symmetric")
174       {
175         REQUIRE(e5.conflicts_with(&e6));
176         REQUIRE(e6.conflicts_with(&e5));
177         REQUIRE(e5.immediately_conflicts_with(&e4));
178         REQUIRE(e4.immediately_conflicts_with(&e5));
179       }
180     }
181   }
182
183   SECTION("No conflicts whatsoever")
184   {
185     // The following tests concern the given event structure:
186     //                e1
187     //              /   /
188     //            e2    e6
189     //           /  /    /
190     //          e3   /   /
191     //         /  /    /
192     //        e4  e5   e7
193     UnfoldingEvent e1(EventSet(), std::make_shared<IndependentAction>());
194     UnfoldingEvent e2(EventSet({&e1}), std::make_shared<IndependentAction>());
195     UnfoldingEvent e3(EventSet({&e2}), std::make_shared<IndependentAction>());
196     UnfoldingEvent e4(EventSet({&e3}), std::make_shared<IndependentAction>());
197     UnfoldingEvent e5(EventSet({&e3}), std::make_shared<IndependentAction>());
198     UnfoldingEvent e6(EventSet({&e1}), std::make_shared<IndependentAction>());
199     UnfoldingEvent e7(EventSet({&e6, &e2}), std::make_shared<IndependentAction>());
200
201     // Since everyone's actions are independent of one another, we expect
202     // that there are no conflicts between each pair of events
203     SECTION("Mutual dependencies")
204     {
205       CHECK_FALSE(e1.is_dependent_with(&e1));
206       CHECK_FALSE(e1.is_dependent_with(&e2));
207       CHECK_FALSE(e1.is_dependent_with(&e3));
208       CHECK_FALSE(e1.is_dependent_with(&e4));
209       CHECK_FALSE(e1.is_dependent_with(&e5));
210       CHECK_FALSE(e1.is_dependent_with(&e6));
211       CHECK_FALSE(e1.is_dependent_with(&e7));
212
213       CHECK_FALSE(e2.is_dependent_with(&e2));
214       CHECK_FALSE(e2.is_dependent_with(&e3));
215       CHECK_FALSE(e2.is_dependent_with(&e4));
216       CHECK_FALSE(e2.is_dependent_with(&e5));
217       CHECK_FALSE(e2.is_dependent_with(&e6));
218       CHECK_FALSE(e2.is_dependent_with(&e7));
219
220       CHECK_FALSE(e3.is_dependent_with(&e3));
221       CHECK_FALSE(e3.is_dependent_with(&e4));
222       CHECK_FALSE(e3.is_dependent_with(&e5));
223       CHECK_FALSE(e3.is_dependent_with(&e6));
224       CHECK_FALSE(e3.is_dependent_with(&e7));
225
226       CHECK_FALSE(e4.is_dependent_with(&e4));
227       CHECK_FALSE(e4.is_dependent_with(&e5));
228       CHECK_FALSE(e4.is_dependent_with(&e6));
229       CHECK_FALSE(e4.is_dependent_with(&e7));
230
231       CHECK_FALSE(e5.is_dependent_with(&e5));
232       CHECK_FALSE(e5.is_dependent_with(&e6));
233       CHECK_FALSE(e5.is_dependent_with(&e7));
234
235       CHECK_FALSE(e6.is_dependent_with(&e6));
236       CHECK_FALSE(e6.is_dependent_with(&e7));
237
238       CHECK_FALSE(e7.is_dependent_with(&e7));
239     }
240
241     SECTION("Mutual conflicts")
242     {
243       CHECK_FALSE(e1.conflicts_with(&e1));
244       CHECK_FALSE(e1.conflicts_with(&e2));
245       CHECK_FALSE(e1.conflicts_with(&e3));
246       CHECK_FALSE(e1.conflicts_with(&e4));
247       CHECK_FALSE(e1.conflicts_with(&e5));
248       CHECK_FALSE(e1.conflicts_with(&e6));
249       CHECK_FALSE(e1.conflicts_with(&e7));
250
251       CHECK_FALSE(e2.conflicts_with(&e1));
252       CHECK_FALSE(e2.conflicts_with(&e2));
253       CHECK_FALSE(e2.conflicts_with(&e3));
254       CHECK_FALSE(e2.conflicts_with(&e4));
255       CHECK_FALSE(e2.conflicts_with(&e5));
256       CHECK_FALSE(e2.conflicts_with(&e6));
257       CHECK_FALSE(e2.conflicts_with(&e7));
258
259       CHECK_FALSE(e3.conflicts_with(&e1));
260       CHECK_FALSE(e3.conflicts_with(&e2));
261       CHECK_FALSE(e3.conflicts_with(&e3));
262       CHECK_FALSE(e3.conflicts_with(&e4));
263       CHECK_FALSE(e3.conflicts_with(&e5));
264       CHECK_FALSE(e3.conflicts_with(&e6));
265       CHECK_FALSE(e3.conflicts_with(&e7));
266
267       CHECK_FALSE(e4.conflicts_with(&e1));
268       CHECK_FALSE(e4.conflicts_with(&e2));
269       CHECK_FALSE(e4.conflicts_with(&e3));
270       CHECK_FALSE(e4.conflicts_with(&e4));
271       CHECK_FALSE(e4.conflicts_with(&e5));
272       CHECK_FALSE(e4.conflicts_with(&e6));
273       CHECK_FALSE(e4.conflicts_with(&e7));
274
275       CHECK_FALSE(e5.conflicts_with(&e1));
276       CHECK_FALSE(e5.conflicts_with(&e2));
277       CHECK_FALSE(e5.conflicts_with(&e3));
278       CHECK_FALSE(e5.conflicts_with(&e4));
279       CHECK_FALSE(e5.conflicts_with(&e5));
280       CHECK_FALSE(e5.conflicts_with(&e6));
281       CHECK_FALSE(e5.conflicts_with(&e7));
282
283       CHECK_FALSE(e6.conflicts_with(&e1));
284       CHECK_FALSE(e6.conflicts_with(&e2));
285       CHECK_FALSE(e6.conflicts_with(&e3));
286       CHECK_FALSE(e6.conflicts_with(&e4));
287       CHECK_FALSE(e6.conflicts_with(&e5));
288       CHECK_FALSE(e6.conflicts_with(&e6));
289       CHECK_FALSE(e6.conflicts_with(&e7));
290
291       CHECK_FALSE(e7.conflicts_with(&e1));
292       CHECK_FALSE(e7.conflicts_with(&e2));
293       CHECK_FALSE(e7.conflicts_with(&e3));
294       CHECK_FALSE(e7.conflicts_with(&e4));
295       CHECK_FALSE(e7.conflicts_with(&e5));
296       CHECK_FALSE(e7.conflicts_with(&e6));
297       CHECK_FALSE(e7.conflicts_with(&e7));
298     }
299   }
300
301   SECTION("General conflicts")
302   {
303     // The following tests concern the given event structure:
304     //                e1
305     //              /   /
306     //            e2    e6
307     //           /  /    /
308     //          e3   /   /
309     //         /  /    /
310     //        e4  e5   e7
311     UnfoldingEvent e1(EventSet(), std::make_shared<DependentAction>());
312     UnfoldingEvent e2(EventSet({&e1}), std::make_shared<DependentAction>());
313     UnfoldingEvent e3(EventSet({&e2}), std::make_shared<IndependentAction>());
314     UnfoldingEvent e4(EventSet({&e3}), std::make_shared<IndependentAction>());
315     UnfoldingEvent e5(EventSet({&e3}), std::make_shared<IndependentAction>());
316     UnfoldingEvent e6(EventSet({&e1}), std::make_shared<IndependentAction>());
317     UnfoldingEvent e7(EventSet({&e6, &e2}), std::make_shared<ConditionallyDependentAction>());
318
319     // Since everyone's actions are independent of one another, we expect
320     // that there are no conflicts between each pair of events
321     SECTION("Mutual dependencies")
322     {
323       CHECK(e1.is_dependent_with(&e1));
324       CHECK(e1.is_dependent_with(&e2));
325       CHECK_FALSE(e1.is_dependent_with(&e3));
326       CHECK_FALSE(e1.is_dependent_with(&e4));
327       CHECK_FALSE(e1.is_dependent_with(&e5));
328       CHECK_FALSE(e1.is_dependent_with(&e6));
329       CHECK(e1.is_dependent_with(&e7));
330
331       CHECK(e2.is_dependent_with(&e2));
332       CHECK_FALSE(e2.is_dependent_with(&e3));
333       CHECK_FALSE(e2.is_dependent_with(&e4));
334       CHECK_FALSE(e2.is_dependent_with(&e5));
335       CHECK_FALSE(e2.is_dependent_with(&e6));
336       CHECK(e2.is_dependent_with(&e7));
337
338       CHECK_FALSE(e3.is_dependent_with(&e3));
339       CHECK_FALSE(e3.is_dependent_with(&e4));
340       CHECK_FALSE(e3.is_dependent_with(&e5));
341       CHECK_FALSE(e3.is_dependent_with(&e6));
342       CHECK_FALSE(e3.is_dependent_with(&e7));
343
344       CHECK_FALSE(e4.is_dependent_with(&e4));
345       CHECK_FALSE(e4.is_dependent_with(&e5));
346       CHECK_FALSE(e4.is_dependent_with(&e6));
347       CHECK_FALSE(e4.is_dependent_with(&e7));
348
349       CHECK_FALSE(e5.is_dependent_with(&e5));
350       CHECK_FALSE(e5.is_dependent_with(&e6));
351       CHECK_FALSE(e5.is_dependent_with(&e7));
352
353       CHECK_FALSE(e6.is_dependent_with(&e6));
354       CHECK_FALSE(e6.is_dependent_with(&e7));
355
356       CHECK_FALSE(e7.is_dependent_with(&e7));
357     }
358
359     SECTION("Mutual conflicts")
360     {
361       // Although e1 is dependent with e1, e2, and e7,
362       // since they are related to one another, they are not
363       // considered to be in conflict
364       CHECK_FALSE(e1.conflicts_with(&e1));
365       CHECK_FALSE(e1.conflicts_with(&e2));
366       CHECK_FALSE(e1.conflicts_with(&e3));
367       CHECK_FALSE(e1.conflicts_with(&e4));
368       CHECK_FALSE(e1.conflicts_with(&e5));
369       CHECK_FALSE(e1.conflicts_with(&e6));
370       CHECK_FALSE(e1.conflicts_with(&e7));
371
372       // Same goes for e2 with e2 and e7
373       CHECK_FALSE(e2.conflicts_with(&e1));
374       CHECK_FALSE(e2.conflicts_with(&e2));
375       CHECK_FALSE(e2.conflicts_with(&e3));
376       CHECK_FALSE(e2.conflicts_with(&e4));
377       CHECK_FALSE(e2.conflicts_with(&e5));
378       CHECK_FALSE(e2.conflicts_with(&e6));
379       CHECK_FALSE(e2.conflicts_with(&e7));
380
381       CHECK_FALSE(e3.conflicts_with(&e1));
382       CHECK_FALSE(e3.conflicts_with(&e2));
383       CHECK_FALSE(e3.conflicts_with(&e3));
384       CHECK_FALSE(e3.conflicts_with(&e4));
385       CHECK_FALSE(e3.conflicts_with(&e5));
386       CHECK_FALSE(e3.conflicts_with(&e6));
387       CHECK_FALSE(e3.conflicts_with(&e7));
388
389       CHECK_FALSE(e4.conflicts_with(&e1));
390       CHECK_FALSE(e4.conflicts_with(&e2));
391       CHECK_FALSE(e4.conflicts_with(&e3));
392       CHECK_FALSE(e4.conflicts_with(&e4));
393       CHECK_FALSE(e4.conflicts_with(&e5));
394       CHECK_FALSE(e4.conflicts_with(&e6));
395       CHECK_FALSE(e4.conflicts_with(&e7));
396
397       CHECK_FALSE(e5.conflicts_with(&e1));
398       CHECK_FALSE(e5.conflicts_with(&e2));
399       CHECK_FALSE(e5.conflicts_with(&e3));
400       CHECK_FALSE(e5.conflicts_with(&e4));
401       CHECK_FALSE(e5.conflicts_with(&e5));
402       CHECK_FALSE(e5.conflicts_with(&e6));
403       CHECK_FALSE(e5.conflicts_with(&e7));
404
405       CHECK_FALSE(e6.conflicts_with(&e1));
406       CHECK_FALSE(e6.conflicts_with(&e2));
407       CHECK_FALSE(e6.conflicts_with(&e3));
408       CHECK_FALSE(e6.conflicts_with(&e4));
409       CHECK_FALSE(e6.conflicts_with(&e5));
410       CHECK_FALSE(e6.conflicts_with(&e6));
411       CHECK_FALSE(e6.conflicts_with(&e7));
412
413       CHECK_FALSE(e7.conflicts_with(&e1));
414       CHECK_FALSE(e7.conflicts_with(&e2));
415       CHECK_FALSE(e7.conflicts_with(&e3));
416       CHECK_FALSE(e7.conflicts_with(&e4));
417       CHECK_FALSE(e7.conflicts_with(&e5));
418       CHECK_FALSE(e7.conflicts_with(&e6));
419       CHECK_FALSE(e7.conflicts_with(&e7));
420     }
421   }
422
423   SECTION("More complicated conflicts")
424   {
425     // The following tests concern the given event structure:
426     //                e1
427     //              /   /
428     //            e2    e6
429     //           /      /
430     //          e3      /
431     //         /  /    e7
432     //        e4  e5
433     UnfoldingEvent e1(EventSet(), std::make_shared<IndependentAction>());
434     UnfoldingEvent e2(EventSet({&e1}), std::make_shared<ConditionallyDependentAction>());
435     UnfoldingEvent e3(EventSet({&e2}), std::make_shared<IndependentAction>());
436     UnfoldingEvent e4(EventSet({&e3}), std::make_shared<IndependentAction>());
437     UnfoldingEvent e5(EventSet({&e3}), std::make_shared<IndependentAction>());
438     UnfoldingEvent e6(EventSet({&e1}), std::make_shared<DependentAction>());
439     UnfoldingEvent e7(EventSet({&e6}), std::make_shared<IndependentAction>());
440
441     CHECK_FALSE(e1.conflicts_with(&e1));
442     CHECK_FALSE(e1.conflicts_with(&e2));
443     CHECK_FALSE(e1.conflicts_with(&e3));
444     CHECK_FALSE(e1.conflicts_with(&e4));
445     CHECK_FALSE(e1.conflicts_with(&e5));
446     CHECK_FALSE(e1.conflicts_with(&e6));
447     CHECK_FALSE(e1.conflicts_with(&e7));
448
449     // e2 conflicts with e6. Since e6 < e7,
450     // e2 also conflicts with e7
451     CHECK_FALSE(e2.conflicts_with(&e1));
452     CHECK_FALSE(e2.conflicts_with(&e2));
453     CHECK_FALSE(e2.conflicts_with(&e3));
454     CHECK_FALSE(e2.conflicts_with(&e4));
455     CHECK_FALSE(e2.conflicts_with(&e5));
456     CHECK(e2.conflicts_with(&e6));
457     REQUIRE(e2.conflicts_with(&e7));
458
459     // e3 and e6 are dependent and unrelated, so they conflict
460     CHECK_FALSE(e3.conflicts_with(&e1));
461     CHECK_FALSE(e3.conflicts_with(&e2));
462     CHECK_FALSE(e3.conflicts_with(&e3));
463     CHECK_FALSE(e3.conflicts_with(&e4));
464     CHECK_FALSE(e3.conflicts_with(&e5));
465     CHECK(e3.conflicts_with(&e6));
466     CHECK_FALSE(e3.conflicts_with(&e7));
467
468     // Since e3 and e6 conflict and e3 < e4, e4 and e6 conflict
469     CHECK_FALSE(e4.conflicts_with(&e1));
470     CHECK_FALSE(e4.conflicts_with(&e2));
471     CHECK_FALSE(e4.conflicts_with(&e3));
472     CHECK_FALSE(e4.conflicts_with(&e4));
473     CHECK_FALSE(e4.conflicts_with(&e5));
474     CHECK(e4.conflicts_with(&e6));
475     CHECK_FALSE(e4.conflicts_with(&e7));
476
477     // Likewise for e5
478     CHECK_FALSE(e5.conflicts_with(&e1));
479     CHECK_FALSE(e5.conflicts_with(&e2));
480     CHECK_FALSE(e5.conflicts_with(&e3));
481     CHECK_FALSE(e5.conflicts_with(&e4));
482     CHECK_FALSE(e5.conflicts_with(&e5));
483     CHECK(e5.conflicts_with(&e6));
484     CHECK_FALSE(e5.conflicts_with(&e7));
485
486     // Conflicts are symmetric
487     CHECK_FALSE(e6.conflicts_with(&e1));
488     CHECK(e6.conflicts_with(&e2));
489     CHECK(e6.conflicts_with(&e3));
490     CHECK(e6.conflicts_with(&e4));
491     CHECK(e6.conflicts_with(&e5));
492     CHECK_FALSE(e6.conflicts_with(&e6));
493     CHECK_FALSE(e6.conflicts_with(&e7));
494
495     CHECK_FALSE(e7.conflicts_with(&e1));
496     CHECK(e7.conflicts_with(&e2));
497     CHECK_FALSE(e7.conflicts_with(&e3));
498     CHECK_FALSE(e7.conflicts_with(&e4));
499     CHECK_FALSE(e7.conflicts_with(&e5));
500     CHECK_FALSE(e7.conflicts_with(&e6));
501     CHECK_FALSE(e7.conflicts_with(&e7));
502   }
503 }
504
505 TEST_CASE("simgrid::mc::udpor::UnfoldingEvent: Immediate Conflicts + Conflicts Stress Test")
506 {
507   // The following tests concern the given event structure:
508   //                e1
509   //              /  / /
510   //            e2  e3  e4
511   //                 / /  /
512   //                 e5   e10
513   //                  /
514   //                 e6
515   //                 / /
516   //               e7  e8
517   //                    /
518   //                    e9
519   //
520   // Immediate conflicts:
521   // e2 + e3
522   // e3 + e4
523   // e2 + e4
524   //
525   // NOTE: e7 + e8 ARE NOT in immediate conflict! The reason is that
526   // the set of events {e8, e6, e5, e3, e4, e1} is not a valid configuration,
527   // (nor is {e7, e6, e5, e3, e4, e1})
528   //
529   // NOTE: e2/e3 + e10 are NOT in immediate conflict! EVEN THOUGH {e1, e4, e10}
530   // is a valid configuration, {e1, e2/e3, e4} is not (since e2/e3 and e4 conflict)
531   UnfoldingEvent e1(EventSet(), std::make_shared<IndependentAction>());
532   UnfoldingEvent e2(EventSet({&e1}), std::make_shared<DependentAction>());
533   UnfoldingEvent e3(EventSet({&e1}), std::make_shared<DependentAction>());
534   UnfoldingEvent e4(EventSet({&e1}), std::make_shared<DependentAction>());
535   UnfoldingEvent e5(EventSet({&e3, &e4}), std::make_shared<IndependentAction>());
536   UnfoldingEvent e6(EventSet({&e5}), std::make_shared<IndependentAction>());
537   UnfoldingEvent e7(EventSet({&e6}), std::make_shared<DependentAction>());
538   UnfoldingEvent e8(EventSet({&e6}), std::make_shared<DependentAction>());
539   UnfoldingEvent e9(EventSet({&e8}), std::make_shared<IndependentAction>());
540   UnfoldingEvent e10(EventSet({&e4}), std::make_shared<DependentAction>());
541
542   REQUIRE(e2.immediately_conflicts_with(&e3));
543   REQUIRE(e3.immediately_conflicts_with(&e4));
544   REQUIRE(e2.immediately_conflicts_with(&e4));
545
546   REQUIRE(e2.conflicts_with(&e10));
547   REQUIRE(e3.conflicts_with(&e10));
548   REQUIRE(e7.conflicts_with(&e8));
549   REQUIRE_FALSE(e2.immediately_conflicts_with(&e10));
550   REQUIRE_FALSE(e3.immediately_conflicts_with(&e10));
551   REQUIRE_FALSE(e7.immediately_conflicts_with(&e8));
552 }