Skip to content

Commit 5423ea4

Browse files
authored
Merge pull request diffblue#2488 from polgreen/common_call_graph_funcs
factor out common call graph unit test functions into header
2 parents a2a5662 + 2431ac0 commit 5423ea4

7 files changed

+68
-69
lines changed

unit/analyses/call_graph.cpp

+1-24
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,17 @@ Module: Unit test for call graph generation
88

99
#include <iostream>
1010

11+
#include <testing-utils/call_graph_test_utils.h>
1112
#include <testing-utils/catch.hpp>
1213

1314
#include <analyses/call_graph.h>
1415
#include <analyses/call_graph_helpers.h>
1516

1617
#include <util/symbol_table.h>
17-
#include <util/std_code.h>
1818

1919
#include <goto-programs/goto_convert_functions.h>
2020

21-
static symbolt create_void_function_symbol(
22-
const irep_idt &name,
23-
const codet &code)
24-
{
25-
const code_typet void_function_type({}, empty_typet());
26-
symbolt function;
27-
function.name=name;
28-
function.type=void_function_type;
29-
function.mode=ID_java;
30-
function.value=code;
31-
return function;
32-
}
3321

34-
static bool multimap_key_matches(
35-
const std::multimap<irep_idt, irep_idt> &map,
36-
const irep_idt &key,
37-
const std::set<irep_idt> &values)
38-
{
39-
auto matching_values=map.equal_range(key);
40-
std::set<irep_idt> matching_set;
41-
for(auto it=matching_values.first; it!=matching_values.second; ++it)
42-
matching_set.insert(it->second);
43-
return matching_set==values;
44-
}
4522

4623
SCENARIO("call_graph",
4724
"[core][util][call_graph]")

unit/analyses/dependence_graph.cpp

+7-19
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,16 @@ Author: Chris Smowton, [email protected]
88

99
#include <iostream>
1010

11-
#include <testing-utils/catch.hpp>
1211
#include <analyses/dependence_graph.h>
13-
#include <util/symbol_table.h>
14-
#include <util/std_code.h>
15-
#include <util/c_types.h>
16-
#include <util/arith_tools.h>
12+
#include <ansi-c/ansi_c_language.h>
1713
#include <goto-programs/goto_convert_functions.h>
1814
#include <langapi/mode.h>
19-
#include <ansi-c/ansi_c_language.h>
20-
21-
static symbolt create_void_function_symbol(
22-
const irep_idt &name,
23-
const codet &code)
24-
{
25-
const code_typet void_function_type({}, empty_typet());
26-
symbolt function;
27-
function.name = name;
28-
function.type = void_function_type;
29-
function.mode = ID_java;
30-
function.value = code;
31-
return function;
32-
}
15+
#include <testing-utils/call_graph_test_utils.h>
16+
#include <testing-utils/catch.hpp>
17+
#include <util/arith_tools.h>
18+
#include <util/c_types.h>
19+
#include <util/std_code.h>
20+
#include <util/symbol_table.h>
3321

3422
const std::set<goto_programt::const_targett>&
3523
dependence_graph_test_get_control_deps(const dep_graph_domaint &domain)

unit/analyses/disconnect_unreachable_nodes_in_graph.cpp

+1-26
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,15 @@ Module: Unit test for graph class functions
88

99
#include <iostream>
1010

11+
#include <testing-utils/call_graph_test_utils.h>
1112
#include <testing-utils/catch.hpp>
1213

13-
#include <analyses/call_graph.h>
1414
#include <analyses/call_graph_helpers.h>
1515

16-
#include <util/std_code.h>
1716
#include <util/symbol_table.h>
1817

1918
#include <goto-programs/goto_convert_functions.h>
2019

21-
static symbolt
22-
create_void_function_symbol(const irep_idt &name, const codet &code)
23-
{
24-
const code_typet void_function_type({}, empty_typet());
25-
symbolt function;
26-
function.name = name;
27-
function.type = void_function_type;
28-
function.mode = ID_java;
29-
function.value = code;
30-
return function;
31-
}
32-
33-
static bool multimap_key_matches(
34-
const std::multimap<irep_idt, irep_idt> &map,
35-
const irep_idt &key,
36-
const std::set<irep_idt> &values)
37-
{
38-
auto matching_values = map.equal_range(key);
39-
std::set<irep_idt> matching_set;
40-
for(auto it = matching_values.first; it != matching_values.second; ++it)
41-
matching_set.insert(it->second);
42-
return matching_set == values;
43-
}
44-
4520
SCENARIO("graph", "[core][util][graph]")
4621
{
4722
GIVEN("Some cyclic function calls")

unit/testing-utils/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
SRC = \
2+
call_graph_test_utils.cpp \
23
free_form_cmdline.cpp \
34
message.cpp \
45
require_expr.cpp \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*******************************************************************\
2+
3+
Module: Call graph test utils
4+
5+
Author: Chris Smowton, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#include "call_graph_test_utils.h"
10+
11+
symbolt
12+
create_void_function_symbol(const irep_idt &name, const codet &code)
13+
{
14+
const code_typet void_function_type({}, empty_typet());
15+
symbolt function;
16+
function.name = name;
17+
function.type = void_function_type;
18+
function.mode = ID_java;
19+
function.value = code;
20+
return function;
21+
}
22+
23+
bool multimap_key_matches(
24+
const std::multimap<irep_idt, irep_idt> &map,
25+
const irep_idt &key,
26+
const std::set<irep_idt> &values)
27+
{
28+
auto matching_values = map.equal_range(key);
29+
std::set<irep_idt> matching_set;
30+
for(auto it = matching_values.first; it != matching_values.second; ++it)
31+
matching_set.insert(it->second);
32+
return matching_set == values;
33+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*******************************************************************\
2+
3+
Module: Call graph test utils
4+
5+
Author: Chris Smowton, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_TESTING_UTILS_CALL_GRAPH_TEST_UTILS_H
10+
#define CPROVER_TESTING_UTILS_CALL_GRAPH_TEST_UTILS_H
11+
12+
#include <analyses/call_graph.h>
13+
14+
#include <util/std_code.h>
15+
16+
symbolt
17+
create_void_function_symbol(const irep_idt &name, const codet &code);
18+
19+
bool multimap_key_matches(
20+
const std::multimap<irep_idt, irep_idt> &map,
21+
const irep_idt &key,
22+
const std::set<irep_idt> &values);
23+
24+
#endif /* CPROVER_TESTING_UTILS_CALL_GRAPH_TEST_UTILS_HT */
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
ansi-c
22
testing-utils
33
util
4+
analyses

0 commit comments

Comments
 (0)