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/History.hpp"
8 #include "src/mc/explo/udpor/UnfoldingEvent.hpp"
10 using namespace simgrid::mc::udpor;
12 TEST_CASE("simgrid::mc::udpor::History: History generation")
14 // The following tests concern the given event tree
21 UnfoldingEvent e2{&e1}, e6{&e1};
22 UnfoldingEvent e3{&e2}, e4{&e2};
23 UnfoldingEvent e5{&e2, &e6}, e7{&e6};
25 SECTION("History with no events")
28 REQUIRE(history.get_all_events() == EventSet());
29 REQUIRE_FALSE(history.contains(&e1));
30 REQUIRE_FALSE(history.contains(&e2));
31 REQUIRE_FALSE(history.contains(&e3));
32 REQUIRE_FALSE(history.contains(&e4));
33 REQUIRE_FALSE(history.contains(&e5));
34 REQUIRE_FALSE(history.contains(&e6));
35 REQUIRE_FALSE(history.contains(&e7));
38 SECTION("Histories with a single event")
40 SECTION("Root event's history has a single event")
43 REQUIRE(history.get_all_events() == EventSet({&e1}));
46 SECTION("Check node e2")
49 REQUIRE(history.get_all_events() == EventSet({&e1, &e2}));
50 REQUIRE(history.contains(&e1));
51 REQUIRE(history.contains(&e2));
52 REQUIRE_FALSE(history.contains(&e3));
53 REQUIRE_FALSE(history.contains(&e4));
54 REQUIRE_FALSE(history.contains(&e5));
55 REQUIRE_FALSE(history.contains(&e6));
56 REQUIRE_FALSE(history.contains(&e7));
59 SECTION("Check node e3")
62 REQUIRE(history.get_all_events() == EventSet({&e1, &e2, &e3}));
63 REQUIRE(history.contains(&e1));
64 REQUIRE(history.contains(&e2));
65 REQUIRE(history.contains(&e3));
66 REQUIRE_FALSE(history.contains(&e4));
67 REQUIRE_FALSE(history.contains(&e5));
68 REQUIRE_FALSE(history.contains(&e6));
69 REQUIRE_FALSE(history.contains(&e7));
72 SECTION("Check node e4")
75 REQUIRE(history.get_all_events() == EventSet({&e1, &e2, &e4}));
76 REQUIRE(history.contains(&e1));
77 REQUIRE(history.contains(&e2));
78 REQUIRE_FALSE(history.contains(&e3));
79 REQUIRE(history.contains(&e4));
80 REQUIRE_FALSE(history.contains(&e5));
81 REQUIRE_FALSE(history.contains(&e6));
82 REQUIRE_FALSE(history.contains(&e7));
85 SECTION("Check node e5")
88 REQUIRE(history.get_all_events() == EventSet({&e1, &e2, &e6, &e5}));
89 REQUIRE(history.contains(&e1));
90 REQUIRE(history.contains(&e2));
91 REQUIRE_FALSE(history.contains(&e3));
92 REQUIRE_FALSE(history.contains(&e4));
93 REQUIRE(history.contains(&e5));
94 REQUIRE(history.contains(&e6));
95 REQUIRE_FALSE(history.contains(&e7));
98 SECTION("Check node e6")
100 History history(&e6);
101 REQUIRE(history.get_all_events() == EventSet({&e1, &e6}));
102 REQUIRE(history.contains(&e1));
103 REQUIRE_FALSE(history.contains(&e2));
104 REQUIRE_FALSE(history.contains(&e3));
105 REQUIRE_FALSE(history.contains(&e4));
106 REQUIRE_FALSE(history.contains(&e5));
107 REQUIRE(history.contains(&e6));
108 REQUIRE_FALSE(history.contains(&e7));
111 SECTION("Check node e7")
113 History history(&e7);
114 REQUIRE(history.get_all_events() == EventSet({&e1, &e6, &e7}));
115 REQUIRE(history.contains(&e1));
116 REQUIRE_FALSE(history.contains(&e2));
117 REQUIRE_FALSE(history.contains(&e3));
118 REQUIRE_FALSE(history.contains(&e4));
119 REQUIRE_FALSE(history.contains(&e5));
120 REQUIRE(history.contains(&e6));
121 REQUIRE(history.contains(&e7));
125 SECTION("Histories with multiple nodes")
127 SECTION("Nodes contained in the same branch")
129 History history_e1e2(EventSet({&e1, &e2}));
130 REQUIRE(history_e1e2.get_all_events() == EventSet({&e1, &e2}));
131 REQUIRE(history_e1e2.contains(&e1));
132 REQUIRE(history_e1e2.contains(&e2));
133 REQUIRE_FALSE(history_e1e2.contains(&e3));
134 REQUIRE_FALSE(history_e1e2.contains(&e4));
135 REQUIRE_FALSE(history_e1e2.contains(&e5));
136 REQUIRE_FALSE(history_e1e2.contains(&e6));
137 REQUIRE_FALSE(history_e1e2.contains(&e7));
139 History history_e1e3(EventSet({&e1, &e3}));
140 REQUIRE(history_e1e3.get_all_events() == EventSet({&e1, &e2, &e3}));
141 REQUIRE(history_e1e3.contains(&e1));
142 REQUIRE(history_e1e3.contains(&e2));
143 REQUIRE(history_e1e3.contains(&e3));
144 REQUIRE_FALSE(history_e1e3.contains(&e4));
145 REQUIRE_FALSE(history_e1e3.contains(&e5));
146 REQUIRE_FALSE(history_e1e3.contains(&e6));
147 REQUIRE_FALSE(history_e1e3.contains(&e7));
149 History history_e6e7(EventSet({&e6, &e7}));
150 REQUIRE(history_e6e7.get_all_events() == EventSet({&e1, &e6, &e7}));
151 REQUIRE(history_e6e7.contains(&e1));
152 REQUIRE_FALSE(history_e6e7.contains(&e2));
153 REQUIRE_FALSE(history_e6e7.contains(&e3));
154 REQUIRE_FALSE(history_e6e7.contains(&e4));
155 REQUIRE_FALSE(history_e6e7.contains(&e5));
156 REQUIRE(history_e6e7.contains(&e6));
157 REQUIRE(history_e6e7.contains(&e7));
160 SECTION("Nodes with the same ancestor")
162 History history_e3e5(EventSet({&e3, &e5}));
163 REQUIRE(history_e3e5.get_all_events() == EventSet({&e1, &e2, &e3, &e5, &e6}));
164 REQUIRE(history_e3e5.contains(&e1));
165 REQUIRE(history_e3e5.contains(&e2));
166 REQUIRE(history_e3e5.contains(&e3));
167 REQUIRE_FALSE(history_e3e5.contains(&e4));
168 REQUIRE(history_e3e5.contains(&e5));
169 REQUIRE(history_e3e5.contains(&e6));
170 REQUIRE_FALSE(history_e3e5.contains(&e7));
173 SECTION("Nodes with different ancestors")
175 History history_e4e7(EventSet({&e4, &e7}));
176 REQUIRE(history_e4e7.get_all_events() == EventSet({&e1, &e2, &e4, &e6, &e7}));
177 REQUIRE(history_e4e7.contains(&e1));
178 REQUIRE(history_e4e7.contains(&e2));
179 REQUIRE_FALSE(history_e4e7.contains(&e3));
180 REQUIRE(history_e4e7.contains(&e4));
181 REQUIRE_FALSE(history_e4e7.contains(&e5));
182 REQUIRE(history_e4e7.contains(&e6));
183 REQUIRE(history_e4e7.contains(&e7));
186 SECTION("Large number of nodes")
188 History history_e2356(EventSet({&e2, &e3, &e5, &e6}));
189 REQUIRE(history_e2356.get_all_events() == EventSet({&e1, &e2, &e3, &e5, &e6}));
190 REQUIRE(history_e2356.contains(&e1));
191 REQUIRE(history_e2356.contains(&e2));
192 REQUIRE(history_e2356.contains(&e3));
193 REQUIRE_FALSE(history_e2356.contains(&e4));
194 REQUIRE(history_e2356.contains(&e5));
195 REQUIRE(history_e2356.contains(&e6));
196 REQUIRE_FALSE(history_e2356.contains(&e7));
199 SECTION("History of the entire graph yields the entire graph")
201 History history(EventSet({&e1, &e2, &e3, &e4, &e5, &e6, &e7}));
202 REQUIRE(history.get_all_events() == EventSet({&e1, &e2, &e3, &e4, &e5, &e6, &e7}));
203 REQUIRE(history.contains(&e1));
204 REQUIRE(history.contains(&e2));
205 REQUIRE(history.contains(&e3));
206 REQUIRE(history.contains(&e4));
207 REQUIRE(history.contains(&e5));
208 REQUIRE(history.contains(&e6));
209 REQUIRE(history.contains(&e7));