Skip to content

Commit d0aea6e

Browse files
author
Matthias Güdemann
committed
Add unit test for non-instrumentation of Java virtual calls
1 parent 012985f commit d0aea6e

File tree

4 files changed

+64
-5
lines changed

4 files changed

+64
-5
lines changed

src/goto-instrument/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ INCLUDES= -I ..
9494

9595
LIBS =
9696

97-
CLEANFILES = goto-instrument$(EXEEXT)
97+
CLEANFILES = goto-instrument$(EXEEXT) goto-instrument$(LIBEXT)
9898

9999
include ../config.inc
100100
include ../common
101101

102-
all: goto-instrument$(EXEEXT)
102+
all: goto-instrument$(EXEEXT) goto-instrument$(LIBEXT)
103103

104104
ifneq ($(LIB_GLPK),)
105105
LIBS += $(LIB_GLPK)
@@ -111,6 +111,9 @@ endif
111111
goto-instrument$(EXEEXT): $(OBJ)
112112
$(LINKBIN)
113113

114+
goto-instrument$(LIBEXT): $(OBJ)
115+
$(LINKLIB)
116+
114117
.PHONY: goto-instrument-mac-signed
115118

116119
goto-instrument-mac-signed: goto-instrument$(EXEEXT)

unit/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ target_include_directories(unit
3636
${CBMC_SOURCE_DIR}
3737
${CMAKE_CURRENT_SOURCE_DIR}
3838
)
39-
target_link_libraries(unit testing-utils ansi-c solvers java_bytecode)
39+
target_link_libraries(
40+
unit
41+
testing-utils
42+
ansi-c
43+
solvers
44+
java_bytecode
45+
goto-programs
46+
goto-instrument-lib)
47+
4048
add_test(
4149
NAME unit
4250
COMMAND $<TARGET_FILE:unit>

unit/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ CPROVER_LIBS =../src/java_bytecode/java_bytecode$(LIBEXT) \
6666
../src/util/util$(LIBEXT) \
6767
../src/big-int/big-int$(LIBEXT) \
6868
../src/goto-programs/goto-programs$(LIBEXT) \
69+
../src/goto-instrument/goto-instrument$(LIBEXT) \
6970
../src/pointer-analysis/pointer-analysis$(LIBEXT) \
7071
../src/langapi/langapi$(LIBEXT) \
7172
../src/assembler/assembler$(LIBEXT) \

unit/java_bytecode/java_virtual_functions/virtual_functions.cpp

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
#include <goto-programs/goto_convert_functions.h>
1414
#include <goto-programs/remove_virtual_functions.h>
1515
#include <util/config.h>
16-
16+
#include <goto-instrument/cover.h>
17+
#include <util/options.h>
1718
#include <util/std_expr.h>
1819

1920
void check_function_call(
@@ -113,8 +114,54 @@ SCENARIO(
113114
}
114115
}
115116
}
116-
117117
REQUIRE(found_function);
118+
119+
WHEN("basic blocks are instrumented")
120+
{
121+
optionst options;
122+
options.set_option("cover", "location");
123+
THEN("instrumentation assertions are inserted")
124+
{
125+
REQUIRE_FALSE(
126+
instrument_cover_goals(
127+
options, new_table, new_goto_functions, null_output));
128+
}
129+
THEN(
130+
"instructions are marked as originating from virtual function call "
131+
"removal")
132+
{
133+
auto function = new_goto_functions.function_map.find(function_name);
134+
REQUIRE(function != new_goto_functions.function_map.end());
135+
136+
const goto_programt &goto_program = function->second.body;
137+
auto it = std::find_if(
138+
goto_program.instructions.begin(),
139+
goto_program.instructions.end(),
140+
[](const goto_programt::instructiont &instruction) {
141+
return instruction.type == goto_program_instruction_typet::GOTO &&
142+
instruction.guard.id() == ID_equal;
143+
});
144+
REQUIRE(it != goto_program.instructions.end());
145+
THEN(
146+
"all instructions that share the same bytecode index "
147+
"are marked as originating from a removed virtual function "
148+
"call and there is no GOTO ASSERT")
149+
{
150+
const source_locationt &loc = it->source_location;
151+
REQUIRE(loc != source_locationt::nil());
152+
REQUIRE(!loc.get_java_bytecode_index().empty());
153+
154+
while(it->source_location != source_locationt::nil() &&
155+
it->source_location.get_java_bytecode_index() ==
156+
loc.get_java_bytecode_index())
157+
{
158+
REQUIRE(it->source_location.get_java_removed_virtual_call());
159+
REQUIRE(it->type != goto_program_instruction_typet::ASSERT);
160+
++it;
161+
}
162+
}
163+
}
164+
}
118165
}
119166
}
120167
}

0 commit comments

Comments
 (0)