/[eiffelstudio]/branches/eth/eve/Src/framework/auto_fix/strategies/enumeration_based/fault_localization/dynamic_analysis/monitoring/afx_execution_monitor.e
ViewVC logotype

Contents of /branches/eth/eve/Src/framework/auto_fix/strategies/enumeration_based/fault_localization/dynamic_analysis/monitoring/afx_execution_monitor.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 98118 - (show annotations)
Thu Nov 19 13:59:02 2015 UTC (3 years, 10 months ago) by maxpei
File size: 16399 byte(s)
Fixed a fault in AutoFix. Due to the fault, violated contract expression may not be used as a fixing target.
1 note
2 description: "Summary description for {AFX_INTRA_FEATURE_TRACE_COLLECTOR}."
3 author: ""
4 date: "$Date$"
5 revision: "$Revision$"
6
7 deferred class
8 AFX_EXECUTION_MONITOR
9
10 inherit
11
12 AFX_SHARED_SESSION
13
14 AFX_UTILITY
15
16 AFX_SHARED_PROJECT_ROOT_INFO
17
18 EQA_TEST_EXECUTION_MODE
19
20 EPA_DEBUGGER_UTILITY
21 rename
22 start_debugger as start_debugger_general
23 end
24
25 REFACTORING_HELPER
26
27 feature -- Trace for monitoring
28
29 trace_repository: AFX_PROGRAM_EXECUTION_TRACE_REPOSITORY assign set_trace_repository
30 -- Traces collected by monitoring program execution.
31
32 feature{AFX_EXECUTION_MONITOR} -- Trace for monitoring (set)
33
34 set_trace_repository (a_repository: like trace_repository)
35 do
36 trace_repository := a_repository
37 end
38
39 feature -- Scope of monitoring
40
41 features_to_monitor: DS_ARRAYED_LIST [AFX_FEATURE_TO_MONITOR] assign set_features_to_monitor
42 -- Features to be monitored during execution.
43 do
44 if features_to_monitor_cache = Void then
45 create features_to_monitor_cache.make_equal (1)
46 end
47 Result := features_to_monitor_cache
48 end
49
50 set_features_to_monitor (a_features: like features_to_monitor)
51 require
52 a_features /= Void
53 do
54 features_to_monitor_cache := a_features.twin
55 end
56
57 feature{NONE} -- Scope of monitoring (implementation)
58
59 features_to_monitor_cache: like features_to_monitor
60 -- Cache for `features_to_monitor'.
61
62 feature -- Basic operation
63
64 collect (a_should_update_values_of_old_expressions: BOOLEAN)
65 -- Run current project to collect execution traces into `trace_repository'.
66 local
67 l_time_left: INTEGER
68 l_retried: BOOLEAN
69 do
70 if not l_retried then
71 create trace_repository.make_default
72 if session.should_continue then
73 set_up
74 start_debugger
75 wrap_up (a_should_update_values_of_old_expressions)
76 end
77 end
78 rescue
79 l_retried := True
80 session.cancel
81 retry
82 end
83
84 feature{NONE} -- Steps
85
86 set_up
87 -- Set up the collector.
88 do
89 -- Reset result.
90 create trace_repository.make_default
91
92 -- Monitoring
93 remove_breakpoint (debugger_manager, Test_case_super_class)
94 create monitored_breakpoint_managers.make
95 init_test_case_info_skeleton
96 init_test_case_boundary_breakpoint_managers
97 create test_case_execution_event_listeners.make
98 test_case_execution_event_listeners.force_last (trace_repository)
99
100 -- Register debugger event listener.
101 app_stop_agent := agent on_application_stopped
102 app_exit_agent := agent on_application_exit
103 debugger_manager.observer_provider.application_stopped_actions.extend (app_stop_agent)
104 debugger_manager.observer_provider.application_exited_actions.extend (app_exit_agent)
105 debugger_manager.set_should_menu_be_raised_when_application_stopped (False)
106 dbg_timer := debugger_manager.new_timer
107 dbg_timer.actions.extend (agent on_debugger_time_up)
108
109 -- Test case execution status related
110 test_case_info := Void
111 is_inside_test_case := False
112 current_test_case_execution_mode := Mode_default
113
114 if session.has_limited_length then
115 update_timer (session.time_left_for_session)
116 end
117 end
118
119 start_debugger
120 -- Start debugging with proper arguments.
121 deferred
122 end
123
124 wrap_up (a_should_update_values_of_old_expressions: BOOLEAN)
125 -- Wrap up the collection process.
126 do
127 debugger_manager.observer_provider.application_stopped_actions.prune_all (app_stop_agent)
128 debugger_manager.observer_provider.application_exited_actions.prune_all (app_exit_agent)
129
130 -- Disable/Remove breakpoints
131 entry_breakpoint_manager.toggle_breakpoints (False)
132 enable_state_monitoring (False)
133 remove_breakpoint (debugger_manager, Test_case_super_class)
134
135 remove_debugger_session
136
137 prune_empty_and_invalid_traces
138
139 if a_should_update_values_of_old_expressions then
140 trace_repository.do_all (agent {AFX_PROGRAM_EXECUTION_TRACE}.update_values_of_old_expressions (features_to_monitor_by_names (features_to_monitor)))
141 end
142 end
143
144 feature{NONE} -- Initialization
145
146 init_test_case_info_skeleton
147 -- Initialize `test_case_info_skeleton'.
148 local
149 l_class: CLASS_C
150 l_feature: FEATURE_I
151 l_expr: EPA_AST_EXPRESSION
152 l_expr_set: like test_case_info_skeleton
153 do
154 l_class := test_case_super_class
155 l_feature := test_case_setup_feature
156
157 create l_expr_set.make_equal (14)
158 create l_expr.make_with_text (l_class, l_feature, {EQA_SERIALIZED_TEST_SET}.Txt_tci_class_name, l_class)
159 l_expr_set.force_last (l_expr)
160 create l_expr.make_with_text (l_class, l_feature, {EQA_SERIALIZED_TEST_SET}.Txt_execution_mode, l_class)
161 l_expr_set.force_last (l_expr)
162 create l_expr.make_with_text (l_class, l_feature, {EQA_SERIALIZED_TEST_SET}.Txt_tci_class_uuid, l_class)
163 l_expr_set.force_last (l_expr)
164 create l_expr.make_with_text (l_class, l_feature, {EQA_SERIALIZED_TEST_SET}.Txt_tci_class_under_test, l_class)
165 l_expr_set.force_last (l_expr)
166 create l_expr.make_with_text (l_class, l_feature, {EQA_SERIALIZED_TEST_SET}.Txt_tci_feature_under_test, l_class)
167 l_expr_set.force_last (l_expr)
168 create l_expr.make_with_text (l_class, l_feature, {EQA_SERIALIZED_TEST_SET}.Txt_tci_breakpoint_index, l_class)
169 l_expr_set.force_last (l_expr)
170 create l_expr.make_with_text (l_class, l_feature, {EQA_SERIALIZED_TEST_SET}.Txt_tci_is_creation, l_class)
171 l_expr_set.force_last (l_expr)
172 create l_expr.make_with_text (l_class, l_feature, {EQA_SERIALIZED_TEST_SET}.Txt_tci_is_query, l_class)
173 l_expr_set.force_last (l_expr)
174 create l_expr.make_with_text (l_class, l_feature, {EQA_SERIALIZED_TEST_SET}.Txt_tci_is_passing, l_class)
175 l_expr_set.force_last (l_expr)
176 create l_expr.make_with_text (l_class, l_feature, {EQA_SERIALIZED_TEST_SET}.Txt_tci_exception_code, l_class)
177 l_expr_set.force_last (l_expr)
178 create l_expr.make_with_text (l_class, l_feature, {EQA_SERIALIZED_TEST_SET}.Txt_tci_assertion_tag, l_class)
179 l_expr_set.force_last (l_expr)
180 create l_expr.make_with_text (l_class, l_feature, {EQA_SERIALIZED_TEST_SET}.Txt_tci_exception_recipient_class, l_class)
181 l_expr_set.force_last (l_expr)
182 create l_expr.make_with_text (l_class, l_feature, {EQA_SERIALIZED_TEST_SET}.Txt_tci_exception_recipient, l_class)
183 l_expr_set.force_last (l_expr)
184 create l_expr.make_with_text (l_class, l_feature, {EQA_SERIALIZED_TEST_SET}.Txt_tci_exception_trace, l_class)
185 l_expr_set.force_last (l_expr)
186
187 test_case_info_skeleton := l_expr_set
188 ensure
189 test_case_info_skeleton_initialized: test_case_info_skeleton /= Void and then test_case_info_skeleton.count = 14
190 end
191
192 init_test_case_boundary_breakpoint_managers
193 -- Init breakpoint managers to handle test case entries and exits.
194 -- Use `entry_breakpoint_manager' to enable/disable breakpoints at entries;
195 -- Breakpoint at the exit is always enabled.
196 local
197 l_bp_manager: BREAKPOINTS_MANAGER
198 l_bp_location: BREAKPOINT_LOCATION
199 l_breakpoint: BREAKPOINT
200 do
201 create entry_breakpoint_manager.make (Test_case_super_class, Test_case_setup_feature)
202 entry_breakpoint_manager.set_breakpoint_with_expression_and_action (1, test_case_info_skeleton, agent on_test_case_entry)
203 entry_breakpoint_manager.toggle_breakpoints (True)
204
205 -- Disable state monitoring on test case exit.
206 l_bp_manager := debugger_manager.breakpoints_manager
207 l_bp_location := l_bp_manager.breakpoint_location (Test_case_exit_feature.e_feature, 1, False)
208 l_breakpoint := l_bp_manager.new_user_breakpoint (l_bp_location)
209 l_breakpoint.add_when_hits_action (create {BREAKPOINT_WHEN_HITS_ACTION_EXECUTE}.make (agent on_test_case_exit))
210 l_breakpoint.set_continue_execution (True)
211 l_bp_manager.add_breakpoint (l_breakpoint)
212 l_bp_manager.notify_breakpoints_changes
213 end
214
215 feature{NONE} -- Debugger
216
217 app_stop_agent: PROCEDURE [ANY, TUPLE [DEBUGGER_MANAGER]]
218 -- Debugger action when application is stopped.
219
220 app_exit_agent: PROCEDURE [ANY, TUPLE [DEBUGGER_MANAGER]]
221 -- Debugger action when application exits.
222
223 on_application_exit (a_dm: DEBUGGER_MANAGER)
224 -- Action to be performed when application exited.
225 do
226 test_case_execution_event_listeners.do_all (agent {AFX_TEST_CASE_EXECUTION_EVENT_LISTENER}.on_application_exit)
227
228 entry_breakpoint_manager.toggle_breakpoints (False)
229 enable_state_monitoring (False)
230 remove_breakpoint (a_dm, Test_case_super_class)
231 end
232
233 on_application_stopped (a_dm: DEBUGGER_MANAGER)
234 -- Action on application stopped.
235 do
236 if a_dm.application_is_executing and then a_dm.application_is_stopped then
237 if a_dm.application_status.reason_is_catcall then
238 a_dm.controller.resume_workbench_application
239 elseif a_dm.application_status.reason_is_overflow then
240 a_dm.application.kill
241 else
242 if a_dm.application_status.exception_occurred then
243 on_application_exception (a_dm)
244 end
245 a_dm.controller.resume_workbench_application
246 end
247 end
248 end
249
250 on_application_exception (a_dm: DEBUGGER_MANAGER)
251 -- Action on application exception.
252 deferred
253 end
254
255 feature{NONE} -- Timer for debugging
256
257 dbg_timer: DEBUGGER_TIMER
258 -- Debugger timer.
259
260 update_timer (a_interval: INTEGER)
261 -- Update `dbg_timer' with `a_interval'.
262 do
263 if a_interval < 0 then
264 dbg_timer.set_interval (1)
265 elseif a_interval >= 0 then
266 dbg_timer.set_interval (a_interval)
267 end
268 end
269
270 on_debugger_time_up
271 -- Action on debugger time up.
272 do
273 kill_debuggee (debugger_manager)
274 wrap_up (False)
275 end
276
277 feature{NONE} -- Test case events
278
279 test_case_execution_event_listeners: DS_LINKED_LIST[AFX_TEST_CASE_EXECUTION_EVENT_LISTENER]
280 -- Subscribed event listeners.
281
282 on_test_case_entry (a_breakpoint: BREAKPOINT; a_test_case_info: EPA_STATE)
283 -- Action to be performed when entering a new test case.
284 local
285 l_class_under_test: CLASS_C
286 l_execution_mode: INTEGER
287 l_feature_under_test: FEATURE_I
288 l_recipient_class_name, l_recipient_feature_name: STRING
289 l_recipient_class: CLASS_C
290 l_recipient: FEATURE_I
291 l_exception_code: INTEGER
292 l_bpslot: INTEGER
293 l_tag: STRING
294 l_passing: BOOLEAN
295 l_table: HASH_TABLE [EPA_EXPRESSION_VALUE, STRING]
296 l_spot: AFX_EXCEPTION_SPOT
297 l_uuid: STRING
298 l_trace: STRING
299 l_start_index, l_end_index: INTEGER
300 l_expression_set: DS_HASH_SET [AFX_PROGRAM_STATE_EXPRESSION]
301 l_repository: like trace_repository
302 do
303 l_table := a_test_case_info.to_hash_table
304
305 l_class_under_test := first_class_starts_with_name (l_table.item ({EQA_SERIALIZED_TEST_SET}.Txt_tci_class_under_test).out)
306 l_execution_mode := l_table.item ({EQA_SERIALIZED_TEST_SET}.Txt_execution_mode).out.to_integer
307 l_feature_under_test := l_class_under_test.feature_named (l_table.item ({EQA_SERIALIZED_TEST_SET}.Txt_tci_feature_under_test).out)
308 l_recipient_class_name := l_table.item ({EQA_SERIALIZED_TEST_SET}.Txt_tci_exception_recipient_class).out
309 l_recipient_feature_name := l_table.item ({EQA_SERIALIZED_TEST_SET}.Txt_tci_exception_recipient).out
310 l_recipient_class := first_class_starts_with_name (l_recipient_class_name)
311 l_recipient := l_recipient_class.feature_named (l_recipient_feature_name)
312 l_exception_code := l_table.item ({EQA_SERIALIZED_TEST_SET}.Txt_tci_exception_code).out.to_integer
313 l_bpslot := l_table.item ({EQA_SERIALIZED_TEST_SET}.Txt_tci_breakpoint_index).out.to_integer
314 l_tag := l_table.item ({EQA_SERIALIZED_TEST_SET}.Txt_tci_assertion_tag).out
315 l_passing := l_table.item ({EQA_SERIALIZED_TEST_SET}.Txt_tci_is_passing).out.to_boolean
316 l_uuid := l_table.item ({EQA_SERIALIZED_TEST_SET}.Txt_tci_class_uuid).out
317 l_trace := l_table.item ({EQA_SERIALIZED_TEST_SET}.Txt_tci_exception_trace).out
318
319 create test_case_info.make (l_uuid, l_uuid)
320 test_case_execution_event_listeners.do_all (agent {AFX_TEST_CASE_EXECUTION_EVENT_LISTENER}.on_new_test_case(test_case_info))
321 event_actions.notify_on_test_case_entered (test_case_info)
322
323 enable_state_monitoring (True)
324
325 current_test_case_execution_mode := l_execution_mode
326 class_under_test := l_class_under_test
327 feature_under_test := l_feature_under_test
328
329 test_case_starting_time := session.time_now
330 update_timer (session.time_left_for_test_case (test_case_starting_time))
331 is_inside_test_case := True
332 end
333
334 on_breakpoint_hit_in_test_case (a_class: CLASS_C; a_feature: FEATURE_I; a_breakpoint: BREAKPOINT; a_state: EPA_STATE)
335 -- Action to be performed when `a_breakpoint' is hit.
336 -- `a_breakpoint' is a break point in a test case.
337 -- `a_state' stores the values of all evaluated expressions'.
338 local
339 l_current_program_location_context: EPA_FEATURE_WITH_CONTEXT_CLASS
340 do
341 a_state.keep_if (
342 agent (a_equation: EPA_EQUATION): BOOLEAN
343 do
344 Result := a_equation.value.is_boolean or else a_equation.value.is_integer
345 end)
346
347 create l_current_program_location_context.make (debugger_manager.application_status.e_feature.associated_feature_i,
348 debugger_manager.application_status.dynamic_class)
349 test_case_execution_event_listeners.do_all (agent {AFX_TEST_CASE_EXECUTION_EVENT_LISTENER}.on_breakpoint_hit (test_case_info, a_state,
350 create {AFX_PROGRAM_LOCATION}.make (l_current_program_location_context, a_breakpoint.breakable_line_number)))
351 event_actions.notify_on_break_point_hit (a_class, a_feature, a_breakpoint.breakable_line_number)
352 end
353
354 on_test_case_exit (a_bp: BREAKPOINT; a_dm: DEBUGGER_MANAGER)
355 -- Action on exiting test case.
356 do
357 enable_state_monitoring (False)
358 is_inside_test_case := False
359 update_timer (0) -- Reset debugger timer
360 end
361
362 feature{NONE} -- Execution monitoring
363
364 monitored_breakpoint_managers: DS_LINKED_LIST [EPA_EXPRESSION_EVALUATION_BREAKPOINT_MANAGER]
365 -- Managers for breakpoints where program states need to be monitored.
366
367 entry_breakpoint_manager: EPA_EXPRESSION_EVALUATION_BREAKPOINT_MANAGER
368 -- Manager for the breakpoint that marks the entries of test cases.
369
370 register_program_state_monitoring
371 -- Register program state monitors.
372 deferred
373 end
374
375 enable_state_monitoring (a_flag: BOOLEAN)
376 -- Enable breakpoints for state monitoring, if `a_flag'.
377 -- Diable otherwise.
378 do
379 monitored_breakpoint_managers.do_all (agent {EPA_EXPRESSION_EVALUATION_BREAKPOINT_MANAGER}.toggle_breakpoints (a_flag))
380 end
381
382 feature{NONE} -- Test cases
383
384 test_case_info: EPA_TEST_CASE_INFO
385 -- Information about the test case currently being executed.
386
387 is_inside_test_case: BOOLEAN
388
389 class_under_test: CLASS_C
390 -- Class under test.
391
392 feature_under_test: FEATURE_I
393 -- Feature under test.
394
395 test_case_starting_time: DT_DATE_TIME
396 -- Time when the current test case started executing.
397
398 current_test_case_execution_mode: INTEGER
399 -- Execution mode of the current test case.
400
401 is_in_mode_execute: BOOLEAN
402 -- Is current test case being executed?
403 do
404 Result := current_test_case_execution_mode = Mode_execute
405 end
406
407 is_in_mode_monitor: BOOLEAN
408 -- Is current test case being monitored?
409 do
410 Result := current_test_case_execution_mode = Mode_monitor
411 end
412
413 test_case_info_skeleton: DS_HASH_SET [EPA_EXPRESSION]
414 -- State skeleton of test case information.
415
416 feature{NONE} -- Implementation
417
418 prune_empty_and_invalid_traces
419 -- Prune empty and invalid traces from `trace_repository'.
420 local
421 l_cursor: DS_HASH_TABLE_CURSOR [AFX_PROGRAM_EXECUTION_TRACE, EPA_TEST_CASE_INFO]
422 l_new_repository: AFX_PROGRAM_EXECUTION_TRACE_REPOSITORY
423 do
424 from
425 create l_new_repository.make_default
426 l_cursor := trace_repository.new_cursor
427 l_cursor.start
428 until
429 l_cursor.after
430 loop
431 if not l_cursor.item.is_empty and then (l_cursor.item.is_passing or else l_cursor.item.is_failing) then
432 l_new_repository.force (l_cursor.item, l_cursor.key)
433 end
434 l_cursor.forth
435 end
436 trace_repository := l_new_repository
437 end
438
439 feature{NONE} -- Constant
440
441 Test_case_super_class: CLASS_C
442 -- Super class of all test case classes.
443 once
444 Result := first_class_starts_with_name (once "EQA_SERIALIZED_TEST_SET")
445 ensure
446 result_attached: Result /= Void
447 end
448
449 Test_case_setup_feature: FEATURE_I
450 -- Feature for setting up the test cases.
451 once
452 Result := test_case_super_class.feature_named (once "right_before_test")
453 ensure
454 result_attached: Result /= Void
455 end
456
457 Test_case_exit_feature: FEATURE_I
458 -- Feature for exiting the test cases.
459 once
460 Result := test_case_super_class.feature_named (once "right_after_test")
461 end
462
463 Test_case_surrounding_feature_name: STRING
464 -- Name of the feature for preparing and executin the test cases.
465 once
466 Result := "generated_test_1"
467 end
468
469 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23