1 /* Copyright (c) 2017-2023. The SimGrid Team. All rights reserved. */
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. */
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"
10 using namespace simgrid::mc::udpor;
12 TEST_CASE("simgrid::mc::udpor::UnfoldingEvent: Dependency/Conflict Tests")
14 SECTION("Properties of the relations")
16 // The following tests concern the given event structure:
25 // e5 and e6 are in conflict, e5 and e7 are in conflict, e2 and e6, and e2 ands e7 are in conflict
26 UnfoldingEvent e1(EventSet(), std::make_shared<ConditionallyDependentAction>());
27 UnfoldingEvent e2(EventSet({&e1}), std::make_shared<DependentAction>());
28 UnfoldingEvent e3(EventSet({&e2}), std::make_shared<IndependentAction>());
29 UnfoldingEvent e4(EventSet({&e3}), std::make_shared<IndependentAction>());
30 UnfoldingEvent e5(EventSet({&e3}), std::make_shared<DependentAction>());
31 UnfoldingEvent e6(EventSet({&e1}), std::make_shared<ConditionallyDependentAction>());
32 UnfoldingEvent e7(EventSet({&e6, &e2}), std::make_shared<ConditionallyDependentAction>());
34 SECTION("Dependency relation properties")
36 SECTION("Dependency is reflexive")
38 REQUIRE(e2.is_dependent_with(&e2));
39 REQUIRE(e5.is_dependent_with(&e5));
42 SECTION("Dependency is symmetric")
44 REQUIRE(e2.is_dependent_with(&e6));
45 REQUIRE(e6.is_dependent_with(&e2));
48 SECTION("Dependency is NOT necessarily transitive")
50 REQUIRE(e1.is_dependent_with(&e5));
51 REQUIRE(e5.is_dependent_with(&e7));
52 REQUIRE_FALSE(e1.is_dependent_with(&e7));
56 SECTION("Conflict relation properties")
58 SECTION("Conflict relation is irreflexive")
60 REQUIRE_FALSE(e1.conflicts_with(&e1));
61 REQUIRE_FALSE(e2.conflicts_with(&e2));
62 REQUIRE_FALSE(e3.conflicts_with(&e3));
63 REQUIRE_FALSE(e4.conflicts_with(&e4));
64 REQUIRE_FALSE(e5.conflicts_with(&e5));
65 REQUIRE_FALSE(e6.conflicts_with(&e6));
66 REQUIRE_FALSE(e7.conflicts_with(&e7));
69 SECTION("Conflict relation is symmetric")
71 REQUIRE(e5.conflicts_with(&e6));
72 REQUIRE(e6.conflicts_with(&e5));
77 SECTION("No conflicts whatsoever")
79 // The following tests concern the given event structure:
87 UnfoldingEvent e1(EventSet(), std::make_shared<IndependentAction>());
88 UnfoldingEvent e2(EventSet({&e1}), std::make_shared<IndependentAction>());
89 UnfoldingEvent e3(EventSet({&e2}), std::make_shared<IndependentAction>());
90 UnfoldingEvent e4(EventSet({&e3}), std::make_shared<IndependentAction>());
91 UnfoldingEvent e5(EventSet({&e3}), std::make_shared<IndependentAction>());
92 UnfoldingEvent e6(EventSet({&e1}), std::make_shared<IndependentAction>());
93 UnfoldingEvent e7(EventSet({&e6, &e2}), std::make_shared<IndependentAction>());
95 // Since everyone's actions are independent of one another, we expect
96 // that there are no conflicts between each pair of events
97 SECTION("Mutual dependencies")
99 CHECK_FALSE(e1.is_dependent_with(&e1));
100 CHECK_FALSE(e1.is_dependent_with(&e2));
101 CHECK_FALSE(e1.is_dependent_with(&e3));
102 CHECK_FALSE(e1.is_dependent_with(&e4));
103 CHECK_FALSE(e1.is_dependent_with(&e5));
104 CHECK_FALSE(e1.is_dependent_with(&e6));
105 CHECK_FALSE(e1.is_dependent_with(&e7));
107 CHECK_FALSE(e2.is_dependent_with(&e2));
108 CHECK_FALSE(e2.is_dependent_with(&e3));
109 CHECK_FALSE(e2.is_dependent_with(&e4));
110 CHECK_FALSE(e2.is_dependent_with(&e5));
111 CHECK_FALSE(e2.is_dependent_with(&e6));
112 CHECK_FALSE(e2.is_dependent_with(&e7));
114 CHECK_FALSE(e3.is_dependent_with(&e3));
115 CHECK_FALSE(e3.is_dependent_with(&e4));
116 CHECK_FALSE(e3.is_dependent_with(&e5));
117 CHECK_FALSE(e3.is_dependent_with(&e6));
118 CHECK_FALSE(e3.is_dependent_with(&e7));
120 CHECK_FALSE(e4.is_dependent_with(&e4));
121 CHECK_FALSE(e4.is_dependent_with(&e5));
122 CHECK_FALSE(e4.is_dependent_with(&e6));
123 CHECK_FALSE(e4.is_dependent_with(&e7));
125 CHECK_FALSE(e5.is_dependent_with(&e5));
126 CHECK_FALSE(e5.is_dependent_with(&e6));
127 CHECK_FALSE(e5.is_dependent_with(&e7));
129 CHECK_FALSE(e6.is_dependent_with(&e6));
130 CHECK_FALSE(e6.is_dependent_with(&e7));
132 CHECK_FALSE(e7.is_dependent_with(&e7));
135 SECTION("Mutual conflicts")
137 CHECK_FALSE(e1.conflicts_with(&e1));
138 CHECK_FALSE(e1.conflicts_with(&e2));
139 CHECK_FALSE(e1.conflicts_with(&e3));
140 CHECK_FALSE(e1.conflicts_with(&e4));
141 CHECK_FALSE(e1.conflicts_with(&e5));
142 CHECK_FALSE(e1.conflicts_with(&e6));
143 CHECK_FALSE(e1.conflicts_with(&e7));
145 CHECK_FALSE(e2.conflicts_with(&e1));
146 CHECK_FALSE(e2.conflicts_with(&e2));
147 CHECK_FALSE(e2.conflicts_with(&e3));
148 CHECK_FALSE(e2.conflicts_with(&e4));
149 CHECK_FALSE(e2.conflicts_with(&e5));
150 CHECK_FALSE(e2.conflicts_with(&e6));
151 CHECK_FALSE(e2.conflicts_with(&e7));
153 CHECK_FALSE(e3.conflicts_with(&e1));
154 CHECK_FALSE(e3.conflicts_with(&e2));
155 CHECK_FALSE(e3.conflicts_with(&e3));
156 CHECK_FALSE(e3.conflicts_with(&e4));
157 CHECK_FALSE(e3.conflicts_with(&e5));
158 CHECK_FALSE(e3.conflicts_with(&e6));
159 CHECK_FALSE(e3.conflicts_with(&e7));
161 CHECK_FALSE(e4.conflicts_with(&e1));
162 CHECK_FALSE(e4.conflicts_with(&e2));
163 CHECK_FALSE(e4.conflicts_with(&e3));
164 CHECK_FALSE(e4.conflicts_with(&e4));
165 CHECK_FALSE(e4.conflicts_with(&e5));
166 CHECK_FALSE(e4.conflicts_with(&e6));
167 CHECK_FALSE(e4.conflicts_with(&e7));
169 CHECK_FALSE(e5.conflicts_with(&e1));
170 CHECK_FALSE(e5.conflicts_with(&e2));
171 CHECK_FALSE(e5.conflicts_with(&e3));
172 CHECK_FALSE(e5.conflicts_with(&e4));
173 CHECK_FALSE(e5.conflicts_with(&e5));
174 CHECK_FALSE(e5.conflicts_with(&e6));
175 CHECK_FALSE(e5.conflicts_with(&e7));
177 CHECK_FALSE(e6.conflicts_with(&e1));
178 CHECK_FALSE(e6.conflicts_with(&e2));
179 CHECK_FALSE(e6.conflicts_with(&e3));
180 CHECK_FALSE(e6.conflicts_with(&e4));
181 CHECK_FALSE(e6.conflicts_with(&e5));
182 CHECK_FALSE(e6.conflicts_with(&e6));
183 CHECK_FALSE(e6.conflicts_with(&e7));
185 CHECK_FALSE(e7.conflicts_with(&e1));
186 CHECK_FALSE(e7.conflicts_with(&e2));
187 CHECK_FALSE(e7.conflicts_with(&e3));
188 CHECK_FALSE(e7.conflicts_with(&e4));
189 CHECK_FALSE(e7.conflicts_with(&e5));
190 CHECK_FALSE(e7.conflicts_with(&e6));
191 CHECK_FALSE(e7.conflicts_with(&e7));
195 SECTION("General conflicts")
197 // The following tests concern the given event structure:
205 UnfoldingEvent e1(EventSet(), std::make_shared<DependentAction>());
206 UnfoldingEvent e2(EventSet({&e1}), std::make_shared<DependentAction>());
207 UnfoldingEvent e3(EventSet({&e2}), std::make_shared<IndependentAction>());
208 UnfoldingEvent e4(EventSet({&e3}), std::make_shared<IndependentAction>());
209 UnfoldingEvent e5(EventSet({&e3}), std::make_shared<IndependentAction>());
210 UnfoldingEvent e6(EventSet({&e1}), std::make_shared<IndependentAction>());
211 UnfoldingEvent e7(EventSet({&e6, &e2}), std::make_shared<ConditionallyDependentAction>());
213 // Since everyone's actions are independent of one another, we expect
214 // that there are no conflicts between each pair of events
215 SECTION("Mutual dependencies")
217 CHECK(e1.is_dependent_with(&e1));
218 CHECK(e1.is_dependent_with(&e2));
219 CHECK_FALSE(e1.is_dependent_with(&e3));
220 CHECK_FALSE(e1.is_dependent_with(&e4));
221 CHECK_FALSE(e1.is_dependent_with(&e5));
222 CHECK_FALSE(e1.is_dependent_with(&e6));
223 CHECK(e1.is_dependent_with(&e7));
225 CHECK(e2.is_dependent_with(&e2));
226 CHECK_FALSE(e2.is_dependent_with(&e3));
227 CHECK_FALSE(e2.is_dependent_with(&e4));
228 CHECK_FALSE(e2.is_dependent_with(&e5));
229 CHECK_FALSE(e2.is_dependent_with(&e6));
230 CHECK(e2.is_dependent_with(&e7));
232 CHECK_FALSE(e3.is_dependent_with(&e3));
233 CHECK_FALSE(e3.is_dependent_with(&e4));
234 CHECK_FALSE(e3.is_dependent_with(&e5));
235 CHECK_FALSE(e3.is_dependent_with(&e6));
236 CHECK_FALSE(e3.is_dependent_with(&e7));
238 CHECK_FALSE(e4.is_dependent_with(&e4));
239 CHECK_FALSE(e4.is_dependent_with(&e5));
240 CHECK_FALSE(e4.is_dependent_with(&e6));
241 CHECK_FALSE(e4.is_dependent_with(&e7));
243 CHECK_FALSE(e5.is_dependent_with(&e5));
244 CHECK_FALSE(e5.is_dependent_with(&e6));
245 CHECK_FALSE(e5.is_dependent_with(&e7));
247 CHECK_FALSE(e6.is_dependent_with(&e6));
248 CHECK_FALSE(e6.is_dependent_with(&e7));
250 CHECK_FALSE(e7.is_dependent_with(&e7));
253 SECTION("Mutual conflicts")
255 // Although e1 is dependent with e1, e2, and e7,
256 // since they are related to one another, they are not
257 // considered to be in conflict
258 CHECK_FALSE(e1.conflicts_with(&e1));
259 CHECK_FALSE(e1.conflicts_with(&e2));
260 CHECK_FALSE(e1.conflicts_with(&e3));
261 CHECK_FALSE(e1.conflicts_with(&e4));
262 CHECK_FALSE(e1.conflicts_with(&e5));
263 CHECK_FALSE(e1.conflicts_with(&e6));
264 CHECK_FALSE(e1.conflicts_with(&e7));
266 // Same goes for e2 with e2 and e7
267 CHECK_FALSE(e2.conflicts_with(&e1));
268 CHECK_FALSE(e2.conflicts_with(&e2));
269 CHECK_FALSE(e2.conflicts_with(&e3));
270 CHECK_FALSE(e2.conflicts_with(&e4));
271 CHECK_FALSE(e2.conflicts_with(&e5));
272 CHECK_FALSE(e2.conflicts_with(&e6));
273 CHECK_FALSE(e2.conflicts_with(&e7));
275 CHECK_FALSE(e3.conflicts_with(&e1));
276 CHECK_FALSE(e3.conflicts_with(&e2));
277 CHECK_FALSE(e3.conflicts_with(&e3));
278 CHECK_FALSE(e3.conflicts_with(&e4));
279 CHECK_FALSE(e3.conflicts_with(&e5));
280 CHECK_FALSE(e3.conflicts_with(&e6));
281 CHECK_FALSE(e3.conflicts_with(&e7));
283 CHECK_FALSE(e4.conflicts_with(&e1));
284 CHECK_FALSE(e4.conflicts_with(&e2));
285 CHECK_FALSE(e4.conflicts_with(&e3));
286 CHECK_FALSE(e4.conflicts_with(&e4));
287 CHECK_FALSE(e4.conflicts_with(&e5));
288 CHECK_FALSE(e4.conflicts_with(&e6));
289 CHECK_FALSE(e4.conflicts_with(&e7));
291 CHECK_FALSE(e5.conflicts_with(&e1));
292 CHECK_FALSE(e5.conflicts_with(&e2));
293 CHECK_FALSE(e5.conflicts_with(&e3));
294 CHECK_FALSE(e5.conflicts_with(&e4));
295 CHECK_FALSE(e5.conflicts_with(&e5));
296 CHECK_FALSE(e5.conflicts_with(&e6));
297 CHECK_FALSE(e5.conflicts_with(&e7));
299 CHECK_FALSE(e6.conflicts_with(&e1));
300 CHECK_FALSE(e6.conflicts_with(&e2));
301 CHECK_FALSE(e6.conflicts_with(&e3));
302 CHECK_FALSE(e6.conflicts_with(&e4));
303 CHECK_FALSE(e6.conflicts_with(&e5));
304 CHECK_FALSE(e6.conflicts_with(&e6));
305 CHECK_FALSE(e6.conflicts_with(&e7));
307 CHECK_FALSE(e7.conflicts_with(&e1));
308 CHECK_FALSE(e7.conflicts_with(&e2));
309 CHECK_FALSE(e7.conflicts_with(&e3));
310 CHECK_FALSE(e7.conflicts_with(&e4));
311 CHECK_FALSE(e7.conflicts_with(&e5));
312 CHECK_FALSE(e7.conflicts_with(&e6));
313 CHECK_FALSE(e7.conflicts_with(&e7));
317 SECTION("More complicated conflicts")
319 // The following tests concern the given event structure:
327 UnfoldingEvent e1(EventSet(), std::make_shared<IndependentAction>());
328 UnfoldingEvent e2(EventSet({&e1}), std::make_shared<ConditionallyDependentAction>());
329 UnfoldingEvent e3(EventSet({&e2}), std::make_shared<IndependentAction>());
330 UnfoldingEvent e4(EventSet({&e3}), std::make_shared<IndependentAction>());
331 UnfoldingEvent e5(EventSet({&e3}), std::make_shared<IndependentAction>());
332 UnfoldingEvent e6(EventSet({&e1}), std::make_shared<DependentAction>());
333 UnfoldingEvent e7(EventSet({&e6}), std::make_shared<IndependentAction>());
335 CHECK_FALSE(e1.conflicts_with(&e1));
336 CHECK_FALSE(e1.conflicts_with(&e2));
337 CHECK_FALSE(e1.conflicts_with(&e3));
338 CHECK_FALSE(e1.conflicts_with(&e4));
339 CHECK_FALSE(e1.conflicts_with(&e5));
340 CHECK_FALSE(e1.conflicts_with(&e6));
341 CHECK_FALSE(e1.conflicts_with(&e7));
343 // e2 conflicts with e6. Since e6 < e7,
344 // e2 also conflicts with e7
345 CHECK_FALSE(e2.conflicts_with(&e1));
346 CHECK_FALSE(e2.conflicts_with(&e2));
347 CHECK_FALSE(e2.conflicts_with(&e3));
348 CHECK_FALSE(e2.conflicts_with(&e4));
349 CHECK_FALSE(e2.conflicts_with(&e5));
350 CHECK(e2.conflicts_with(&e6));
351 REQUIRE(e2.conflicts_with(&e7));
353 // e3 and e6 are dependent and unrelated, so they conflict
354 CHECK_FALSE(e3.conflicts_with(&e1));
355 CHECK_FALSE(e3.conflicts_with(&e2));
356 CHECK_FALSE(e3.conflicts_with(&e3));
357 CHECK_FALSE(e3.conflicts_with(&e4));
358 CHECK_FALSE(e3.conflicts_with(&e5));
359 CHECK(e3.conflicts_with(&e6));
360 CHECK_FALSE(e3.conflicts_with(&e7));
362 // Since e3 and e6 conflict and e3 < e4, e4 and e6 conflict
363 CHECK_FALSE(e4.conflicts_with(&e1));
364 CHECK_FALSE(e4.conflicts_with(&e2));
365 CHECK_FALSE(e4.conflicts_with(&e3));
366 CHECK_FALSE(e4.conflicts_with(&e4));
367 CHECK_FALSE(e4.conflicts_with(&e5));
368 CHECK(e4.conflicts_with(&e6));
369 CHECK_FALSE(e4.conflicts_with(&e7));
372 CHECK_FALSE(e5.conflicts_with(&e1));
373 CHECK_FALSE(e5.conflicts_with(&e2));
374 CHECK_FALSE(e5.conflicts_with(&e3));
375 CHECK_FALSE(e5.conflicts_with(&e4));
376 CHECK_FALSE(e5.conflicts_with(&e5));
377 CHECK(e5.conflicts_with(&e6));
378 CHECK_FALSE(e5.conflicts_with(&e7));
380 // Conflicts are symmetric
381 CHECK_FALSE(e6.conflicts_with(&e1));
382 CHECK(e6.conflicts_with(&e2));
383 CHECK(e6.conflicts_with(&e3));
384 CHECK(e6.conflicts_with(&e4));
385 CHECK(e6.conflicts_with(&e5));
386 CHECK_FALSE(e6.conflicts_with(&e6));
387 CHECK_FALSE(e6.conflicts_with(&e7));
389 CHECK_FALSE(e7.conflicts_with(&e1));
390 CHECK(e7.conflicts_with(&e2));
391 CHECK_FALSE(e7.conflicts_with(&e3));
392 CHECK_FALSE(e7.conflicts_with(&e4));
393 CHECK_FALSE(e7.conflicts_with(&e5));
394 CHECK_FALSE(e7.conflicts_with(&e6));
395 CHECK_FALSE(e7.conflicts_with(&e7));