Skip to content

factor out common call graph unit test functions into header #2488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 1 addition & 24 deletions unit/analyses/call_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,17 @@ Module: Unit test for call graph generation

#include <iostream>

#include <testing-utils/call_graph_test_utils.h>
#include <testing-utils/catch.hpp>

#include <analyses/call_graph.h>
#include <analyses/call_graph_helpers.h>

#include <util/symbol_table.h>
#include <util/std_code.h>

#include <goto-programs/goto_convert_functions.h>

static symbolt create_void_function_symbol(
const irep_idt &name,
const codet &code)
{
const code_typet void_function_type({}, empty_typet());
symbolt function;
function.name=name;
function.type=void_function_type;
function.mode=ID_java;
function.value=code;
return function;
}

static bool multimap_key_matches(
const std::multimap<irep_idt, irep_idt> &map,
const irep_idt &key,
const std::set<irep_idt> &values)
{
auto matching_values=map.equal_range(key);
std::set<irep_idt> matching_set;
for(auto it=matching_values.first; it!=matching_values.second; ++it)
matching_set.insert(it->second);
return matching_set==values;
}

SCENARIO("call_graph",
"[core][util][call_graph]")
Expand Down
26 changes: 7 additions & 19 deletions unit/analyses/dependence_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,16 @@ Author: Chris Smowton, [email protected]

#include <iostream>

#include <testing-utils/catch.hpp>
#include <analyses/dependence_graph.h>
#include <util/symbol_table.h>
#include <util/std_code.h>
#include <util/c_types.h>
#include <util/arith_tools.h>
#include <ansi-c/ansi_c_language.h>
#include <goto-programs/goto_convert_functions.h>
#include <langapi/mode.h>
#include <ansi-c/ansi_c_language.h>

static symbolt create_void_function_symbol(
const irep_idt &name,
const codet &code)
{
const code_typet void_function_type({}, empty_typet());
symbolt function;
function.name = name;
function.type = void_function_type;
function.mode = ID_java;
function.value = code;
return function;
}
#include <testing-utils/call_graph_test_utils.h>
#include <testing-utils/catch.hpp>
#include <util/arith_tools.h>
#include <util/c_types.h>
#include <util/std_code.h>
#include <util/symbol_table.h>

const std::set<goto_programt::const_targett>&
dependence_graph_test_get_control_deps(const dep_graph_domaint &domain)
Expand Down
27 changes: 1 addition & 26 deletions unit/analyses/disconnect_unreachable_nodes_in_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,15 @@ Module: Unit test for graph class functions

#include <iostream>

#include <testing-utils/call_graph_test_utils.h>
#include <testing-utils/catch.hpp>

#include <analyses/call_graph.h>
#include <analyses/call_graph_helpers.h>

#include <util/std_code.h>
#include <util/symbol_table.h>

#include <goto-programs/goto_convert_functions.h>

static symbolt
create_void_function_symbol(const irep_idt &name, const codet &code)
{
const code_typet void_function_type({}, empty_typet());
symbolt function;
function.name = name;
function.type = void_function_type;
function.mode = ID_java;
function.value = code;
return function;
}

static bool multimap_key_matches(
const std::multimap<irep_idt, irep_idt> &map,
const irep_idt &key,
const std::set<irep_idt> &values)
{
auto matching_values = map.equal_range(key);
std::set<irep_idt> matching_set;
for(auto it = matching_values.first; it != matching_values.second; ++it)
matching_set.insert(it->second);
return matching_set == values;
}

SCENARIO("graph", "[core][util][graph]")
{
GIVEN("Some cyclic function calls")
Expand Down
1 change: 1 addition & 0 deletions unit/testing-utils/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SRC = \
call_graph_test_utils.cpp \
free_form_cmdline.cpp \
message.cpp \
require_expr.cpp \
Expand Down
33 changes: 33 additions & 0 deletions unit/testing-utils/call_graph_test_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************\

Module: Call graph test utils

Author: Chris Smowton, [email protected]

\*******************************************************************/

#include "call_graph_test_utils.h"

symbolt
create_void_function_symbol(const irep_idt &name, const codet &code)
{
const code_typet void_function_type({}, empty_typet());
symbolt function;
function.name = name;
function.type = void_function_type;
function.mode = ID_java;
function.value = code;
return function;
}

bool multimap_key_matches(
const std::multimap<irep_idt, irep_idt> &map,
const irep_idt &key,
const std::set<irep_idt> &values)
{
auto matching_values = map.equal_range(key);
std::set<irep_idt> matching_set;
for(auto it = matching_values.first; it != matching_values.second; ++it)
matching_set.insert(it->second);
return matching_set == values;
}
24 changes: 24 additions & 0 deletions unit/testing-utils/call_graph_test_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*******************************************************************\
Module: Call graph test utils
Author: Chris Smowton, [email protected]
\*******************************************************************/

#ifndef CPROVER_TESTING_UTILS_CALL_GRAPH_TEST_UTILS_H
#define CPROVER_TESTING_UTILS_CALL_GRAPH_TEST_UTILS_H

#include <analyses/call_graph.h>

#include <util/std_code.h>

symbolt
create_void_function_symbol(const irep_idt &name, const codet &code);

bool multimap_key_matches(
const std::multimap<irep_idt, irep_idt> &map,
const irep_idt &key,
const std::set<irep_idt> &values);

#endif /* CPROVER_TESTING_UTILS_CALL_GRAPH_TEST_UTILS_HT */
1 change: 1 addition & 0 deletions unit/testing-utils/module_dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ansi-c
testing-utils
util
analyses