@@ -16,60 +16,53 @@ void link_edges(goto_programt::targett source, goto_programt::targett target)
16
16
target->incoming_edges .insert (source);
17
17
}
18
18
19
+ source_locationt simple_location (const std::string &file, unsigned line)
20
+ {
21
+ source_locationt location;
22
+ location.set_file (file);
23
+ location.set_line (line);
24
+ return location;
25
+ }
26
+
27
+ goto_programt::targett add_instruction (
28
+ const source_locationt &location,
29
+ goto_programt::instructionst &instructions)
30
+ {
31
+ goto_programt::instructiont instruction;
32
+ instruction.location_number = instructions.size ();
33
+ instruction.source_location = location;
34
+ instructions.push_back (instruction);
35
+ return std::next (instructions.begin (), instruction.location_number );
36
+ }
37
+
19
38
TEST_CASE (" structured_trace_util" , " [core][util][trace]" )
20
39
{
21
40
goto_programt::instructionst instructions;
22
41
23
42
source_locationt nil_location;
24
43
25
- source_locationt unrelated_location;
26
- unrelated_location.set_file (" foo.c" );
27
- unrelated_location.set_line (1 );
44
+ const source_locationt unrelated_location = simple_location (" foo.c" , 1 );
28
45
29
46
source_locationt no_file_location;
30
- unrelated_location.set_line (1 );
31
-
32
- source_locationt basic_location;
33
- basic_location.set_file (" test.c" );
34
- basic_location.set_line (1 );
35
-
36
- source_locationt loop_head_location;
37
- loop_head_location.set_file (" test.c" );
38
- loop_head_location.set_line (2 );
47
+ no_file_location.set_line (1 );
39
48
40
- source_locationt back_edge_location ;
41
- back_edge_location. set_file (" test.c" );
42
- back_edge_location. set_line ( 3 );
49
+ const source_locationt basic_location = simple_location ( " test.c " , 1 ) ;
50
+ const source_locationt loop_head_location = simple_location (" test.c" , 2 );
51
+ const source_locationt back_edge_location = simple_location ( " test.c " , 3 );
43
52
44
53
// 0 # normal_location
54
+ add_instruction (basic_location, instructions);
45
55
// 1 # loop_head
56
+ add_instruction (loop_head_location, instructions);
46
57
// 2: goto 1 # back_edge
58
+ const auto back_edge = add_instruction (back_edge_location, instructions);
59
+ back_edge->type = GOTO;
47
60
// 3: no_location
48
- // 4: no_file
49
- goto_programt::instructiont normal_instruction;
50
- normal_instruction.location_number = 0 ;
51
- normal_instruction.source_location = basic_location;
52
- instructions.push_back (normal_instruction);
53
-
54
- goto_programt::instructiont loop_head;
55
- loop_head.location_number = 1 ;
56
- loop_head.source_location = loop_head_location;
57
- instructions.push_back (loop_head);
58
-
59
- goto_programt::instructiont back_edge;
60
- back_edge.source_location = back_edge_location;
61
- back_edge.location_number = 2 ;
62
- back_edge.type = GOTO;
63
- instructions.push_back (back_edge);
64
-
65
61
goto_programt::instructiont no_location;
66
62
no_location.location_number = 3 ;
67
63
instructions.push_back (no_location);
68
-
69
- goto_programt::instructiont no_file;
70
- no_file.location_number = 4 ;
71
- no_file.source_location = no_file_location;
72
- instructions.push_back (no_file);
64
+ // 4: no_file
65
+ add_instruction (no_file_location, instructions);
73
66
74
67
link_edges (
75
68
std::next (instructions.begin (), 2 ), std::next (instructions.begin (), 1 ));
@@ -133,7 +126,7 @@ TEST_CASE("structured_trace_util", "[core][util][trace]")
133
126
goto_trace_stept step;
134
127
step.step_nr = 1 ;
135
128
step.thread_nr = 2 ;
136
- step.hidden = true ;
129
+ step.hidden = false ;
137
130
step.pc = std::next (instructions.begin (), 1 );
138
131
SECTION (" Simple step" )
139
132
{
@@ -142,7 +135,7 @@ TEST_CASE("structured_trace_util", "[core][util][trace]")
142
135
REQUIRE (parsed_step);
143
136
REQUIRE (parsed_step->step_number == 1 );
144
137
REQUIRE (parsed_step->thread_number == 2 );
145
- REQUIRE (parsed_step->hidden );
138
+ REQUIRE_FALSE (parsed_step->hidden );
146
139
REQUIRE (parsed_step->kind == default_step_kindt::LOOP_HEAD);
147
140
REQUIRE (parsed_step->location == loop_head_location);
148
141
}
@@ -153,7 +146,7 @@ TEST_CASE("structured_trace_util", "[core][util][trace]")
153
146
REQUIRE (parsed_step);
154
147
REQUIRE (parsed_step->step_number == 1 );
155
148
REQUIRE (parsed_step->thread_number == 2 );
156
- REQUIRE (parsed_step->hidden );
149
+ REQUIRE_FALSE (parsed_step->hidden );
157
150
REQUIRE (parsed_step->kind == default_step_kindt::LOOP_HEAD);
158
151
REQUIRE (parsed_step->location == loop_head_location);
159
152
}
0 commit comments