Skip to content

Commit ebe000a

Browse files
committed
unit tests for depth limited search on call graph
1 parent 685fa4f commit ebe000a

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

unit/analyses/call_graph.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,48 @@ SCENARIO("call_graph",
223223
REQUIRE(exported.has_edge(nodes_by_name["B"], nodes_by_name["D"]));
224224
}
225225

226+
THEN("We expect {A,B} to be reachable from {A} in 1 step")
227+
{
228+
irep_idt function_name = "A";
229+
std::size_t depth = 1;
230+
std::set<irep_idt> reachable = get_functions_reachable_within_n_steps(
231+
exported, function_name, depth, true);
232+
REQUIRE(reachable.size() == 2);
233+
REQUIRE(reachable.count("A"));
234+
REQUIRE(reachable.count("B"));
235+
}
236+
THEN("We expect {A,B,C,D} to be reachable from {A} in 2 and 3 steps")
237+
{
238+
irep_idt function_name = "A";
239+
std::size_t depth = 2;
240+
std::set<irep_idt> reachable = get_functions_reachable_within_n_steps(
241+
exported, function_name, depth, true);
242+
REQUIRE(reachable.size() == 4);
243+
REQUIRE(reachable.count("A"));
244+
REQUIRE(reachable.count("B"));
245+
REQUIRE(reachable.count("C"));
246+
REQUIRE(reachable.count("D"));
247+
248+
depth = 3;
249+
reachable = get_functions_reachable_within_n_steps(
250+
exported, function_name, depth, true);
251+
REQUIRE(reachable.size() == 4);
252+
REQUIRE(reachable.count("A"));
253+
REQUIRE(reachable.count("B"));
254+
REQUIRE(reachable.count("C"));
255+
REQUIRE(reachable.count("D"));
256+
}
257+
258+
THEN("We expect only {A} to be reachable from {A} in 0 steps")
259+
{
260+
irep_idt function_name = "A";
261+
std::size_t depth = 0;
262+
std::set<irep_idt> reachable = get_functions_reachable_within_n_steps(
263+
exported, function_name, depth, true);
264+
REQUIRE(reachable.size() == 1);
265+
REQUIRE(reachable.count("A"));
266+
}
267+
226268
THEN("We expect A to have successors {A, B}")
227269
{
228270
std::set<irep_idt> successors = get_callees(exported, "A");

0 commit comments

Comments
 (0)