|
8 | 8 |
|
9 | 9 | #include <testing-utils/catch.hpp>
|
10 | 10 | #include <testing-utils/load_java_class.h>
|
11 |
| -#include <testing-utils/require_goto_statements.h> |
12 | 11 |
|
13 | 12 | #include <goto-programs/goto_convert_functions.h>
|
14 | 13 | #include <goto-programs/remove_virtual_functions.h>
|
15 | 14 | #include <util/config.h>
|
16 |
| - |
17 |
| -#include <util/std_expr.h> |
| 15 | +#include <goto-instrument/cover.h> |
| 16 | +#include <util/options.h> |
| 17 | +#include <iostream> |
18 | 18 |
|
19 | 19 | void check_function_call(
|
20 | 20 | const equal_exprt &eq_expr,
|
@@ -115,6 +115,54 @@ SCENARIO(
|
115 | 115 | }
|
116 | 116 |
|
117 | 117 | REQUIRE(found_function);
|
| 118 | + |
| 119 | + WHEN("basic blocks are instrumented") |
| 120 | + { |
| 121 | + optionst options; |
| 122 | + options.set_option("cover", "location"); |
| 123 | + REQUIRE_FALSE( |
| 124 | + instrument_cover_goals( |
| 125 | + options, new_table, new_goto_functions, null_output)); |
| 126 | + |
| 127 | + auto function = new_goto_functions.function_map.find(function_name); |
| 128 | + REQUIRE(function != new_goto_functions.function_map.end()); |
| 129 | + |
| 130 | + const goto_programt &goto_program = function->second.body; |
| 131 | + // Skip the first instruction which is a declaration with no location |
| 132 | + auto it = std::next(goto_program.instructions.begin()); |
| 133 | + REQUIRE(it != goto_program.instructions.end()); |
| 134 | + |
| 135 | + THEN( |
| 136 | + "Each instruction with a new bytecode index begins with ASSERT" |
| 137 | + " and coverage assertions are at the beginning of the block") |
| 138 | + { |
| 139 | + irep_idt current_index; |
| 140 | + |
| 141 | + while(it->type != goto_program_instruction_typet::END_FUNCTION) |
| 142 | + { |
| 143 | + const source_locationt &loc = it->source_location; |
| 144 | + REQUIRE(loc != source_locationt::nil()); |
| 145 | + REQUIRE_FALSE(loc.get_java_bytecode_index().empty()); |
| 146 | + const auto new_index = loc.get_java_bytecode_index(); |
| 147 | + |
| 148 | + if(new_index != current_index) |
| 149 | + { |
| 150 | + current_index = new_index; |
| 151 | + // instruction with a new bytecode index begins with ASSERT |
| 152 | + REQUIRE(it->type == goto_program_instruction_typet::ASSERT); |
| 153 | + // the assertion corresponds to a line coverage goal |
| 154 | + REQUIRE_FALSE(loc.get_basic_block_covered_lines().empty()); |
| 155 | + } |
| 156 | + else |
| 157 | + { |
| 158 | + // there is no line coverage goal in the middle of a block |
| 159 | + REQUIRE(loc.get_basic_block_covered_lines().empty()); |
| 160 | + } |
| 161 | + |
| 162 | + ++it; |
| 163 | + } |
| 164 | + } |
| 165 | + } |
118 | 166 | }
|
119 | 167 | }
|
120 | 168 | }
|
0 commit comments