/[eiffelstudio]/branches/eth/eve/Src/framework/auto_fix/utility/afx_fixer.e
ViewVC logotype

Contents of /branches/eth/eve/Src/framework/auto_fix/utility/afx_fixer.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 95332 - (show annotations)
Fri Jun 27 12:57:49 2014 UTC (5 years, 3 months ago) by maxpei
File size: 13980 byte(s)
Fixed a few bugs in AutoFix and AutoDebug.
1 note
2 description: "Summary description for {AFX_FIXER}."
3 author: ""
4 date: "$Date$"
5 revision: "$Revision$"
6
7 class
8 AFX_FIXER
9
10 inherit
11
12 SHARED_WORKBENCH
13
14 SHARED_DEBUGGER_MANAGER
15
16 EPA_SHARED_CLASS_THEORY
17
18 EPA_DEBUGGER_UTILITY
19
20 AFX_SHARED_STATE_SERVER
21
22 SHARED_EIFFEL_PARSER
23
24 AFX_UTILITY
25
26 EPA_COMPILATION_UTILITY
27
28 EPA_SHARED_EQUALITY_TESTERS
29
30 EQA_TEST_EXECUTION_MODE
31
32 SHARED_SERVER
33
34 AFX_PROGRAM_EXECUTION_INVARIANT_ACCESS_MODE
35
36 AFX_SHARED_SESSION
37
38 feature -- Access
39
40 fixes: DS_ARRAYED_LIST [AFX_FIX_TO_FAULT]
41 -- Fixes generated.
42
43 features_to_monitor: DS_ARRAYED_LIST [AFX_FEATURE_TO_MONITOR]
44 --
45
46 feature -- Basic operation
47
48 execute
49 --
50 local
51 l_traces_before_fixing, l_traces_after_relaxing, l_traces_for_validation: AFX_PROGRAM_EXECUTION_TRACE_REPOSITORY
52 l_fixing_targets: DS_ARRAYED_LIST [AFX_FIXING_TARGET]
53 l_contract_fixes: DS_ARRAYED_LIST [AFX_CONTRACT_FIX_TO_FAULT]
54 l_code_fixes, l_valid_code_fixes: DS_ARRAYED_LIST [AFX_CODE_FIX_TO_FAULT]
55 l_feature_to_relax: AFX_FEATURE_TO_MONITOR
56 l_features_to_relax: DS_ARRAYED_LIST [AFX_FEATURE_TO_MONITOR]
57 do
58 disable_catcall_warnings
59 create fixes.make_equal (30)
60
61 -- HACK: force re-compiling the root class by "touch"ing it, otherwise expression evaluation might fail.
62 (create {PLAIN_TEXT_FILE}.make_with_name (root_class_of_system.file_name)).touch
63 compile_project (eiffel_project, True)
64
65 session.initialize_logging
66 session.start
67 event_actions.notify_on_session_started
68
69 reproduce_failure
70 l_traces_before_fixing := collect_behavior_of_regular_tests
71
72 if config.is_fixing_implementation then
73 l_fixing_targets := localize_faulty_targets (l_traces_before_fixing)
74 l_code_fixes := generate_implementation_fixes (l_fixing_targets)
75 l_valid_code_fixes := validate_implementation_fixes (l_traces_before_fixing, l_code_fixes)
76 fixes.append_last (l_valid_code_fixes)
77 end
78
79 if config.is_fixing_contract then
80 create l_feature_to_relax.make_from_feature_with_context_class (session.exception_from_execution.exception_feature_with_context)
81 l_feature_to_relax.set_monitor_contracts (True)
82 l_feature_to_relax.set_monitor_body (False)
83 l_traces_after_relaxing := collect_behavior_of_relaxed_tests (l_feature_to_relax)
84
85 l_contract_fixes := generate_contract_fixes (l_traces_before_fixing, l_traces_after_relaxing)
86 validate_contract_fixes (l_contract_fixes)
87 sort_contract_fixes (l_contract_fixes)
88 fixes.append_last (l_contract_fixes)
89 end
90
91 rank_fixes
92 event_actions.notify_on_session_terminated
93 session.clean_up
94
95 end
96
97 feature{NONE} -- Implementation
98
99 reproduce_failure
100 --
101 local
102 l_reproducer: AFX_FAILURE_REPRODUCER
103 do
104 create l_reproducer
105 l_reproducer.reproduce (False)
106 features_to_monitor := l_reproducer.features_to_monitor
107 end
108
109 collect_behavior_of_regular_tests: AFX_PROGRAM_EXECUTION_TRACE_REPOSITORY
110 --
111 local
112 l_collector: AFX_TRACE_COLLECTOR
113 do
114 event_actions.notify_on_test_case_analysis_started (session.number_of_test_cases_for_fixing)
115
116 create l_collector
117 l_collector.set_monitor_mode (l_collector.mode_analyze_tc)
118 l_collector.set_features_to_monitor (features_to_monitor)
119 l_collector.collect (config.is_fixing_contract)
120 Result := l_collector.trace_repository.derived_compound_repository (features_to_monitor, True)
121
122 event_actions.notify_on_test_case_analysis_finished
123 end
124
125 localize_faulty_targets (a_trace_repository: AFX_PROGRAM_EXECUTION_TRACE_REPOSITORY): DS_ARRAYED_LIST [AFX_FIXING_TARGET]
126 -- Compute suspiciousness values of fixing targets.
127 local
128 l_trace_analyzer: AFX_EXECUTION_TRACE_ANALYZER
129 l_feature_cursor: DS_ARRAYED_LIST_CURSOR [AFX_FEATURE_TO_MONITOR]
130 l_feature: AFX_FEATURE_TO_MONITOR
131 l_bpt_interval: INTEGER_INTERVAL
132 l_bpts: DS_HASH_SET [INTEGER]
133
134 l_recipient: AFX_FEATURE_TO_MONITOR
135 l_ranker: AFX_PROGRAM_STATE_RANKER
136 l_invariant_detecter: AFX_PROGRAM_EXECUTION_INVARIANT_DETECTER
137 do
138 if session.should_continue then
139 progression_monitor.set_progression (progression_monitor.progression_fault_localization_start)
140 event_actions.notify_on_implementation_fix_generation_started
141
142 create l_trace_analyzer
143 from
144 l_recipient := session.exception_from_execution.recipient_feature_with_context
145 l_feature_cursor := features_to_monitor.new_cursor
146 l_feature_cursor.start
147 until
148 l_feature_cursor.after
149 loop
150 l_feature := l_feature_cursor.item
151
152 if l_recipient.is_about_same_feature (l_feature) then
153 l_bpt_interval := l_feature.first_breakpoint_in_body |..| l_feature.last_breakpoint_in_body
154 create l_bpts.make_equal (l_bpt_interval.count)
155 l_bpt_interval.do_all (agent l_bpts.force)
156 l_trace_analyzer.add_breakpoints_for_feature (l_bpts, l_feature)
157 end
158
159 l_feature_cursor.forth
160 end
161
162 l_trace_analyzer.collect_statistics_from_trace_repository (a_trace_repository, {AFX_EXECUTION_TRACE_STATISTICS_UPDATE_MODE}.Update_mode_merge_presence)
163
164 create l_ranker.make (session.exception_from_execution)
165 l_ranker.compute_ranks (l_trace_analyzer.statistics_from_passing, l_trace_analyzer.statistics_from_failing)
166 Result := l_ranker.fixing_target_list
167
168 progression_monitor.set_progression (progression_monitor.progression_fault_localization_end)
169 else
170 Result := Void
171 end
172 end
173
174 generate_implementation_fixes (a_fixing_target_list: DS_ARRAYED_LIST [AFX_FIXING_TARGET]): DS_ARRAYED_LIST [AFX_CODE_FIX_TO_FAULT]
175 -- <Precursor>
176 local
177 l_generator: AFX_RANDOM_BASED_FIX_GENERATOR
178 l_fix_texts: DS_HASH_SET [STRING]
179 l_fixes: DS_ARRAYED_LIST [AFX_CODE_FIX_TO_FAULT]
180 l_fix_cursor: DS_ARRAYED_LIST_CURSOR [AFX_CODE_FIX_TO_FAULT]
181 l_fix: AFX_CODE_FIX_TO_FAULT
182 l_text: STRING
183 do
184 create Result.make_equal (1)
185 if session.should_continue then
186 progression_monitor.set_progression (progression_monitor.progression_fix_generation_start)
187
188 -- Generation
189 create l_generator
190 l_generator.set_fixing_target_list (a_fixing_target_list)
191 l_generator.generate
192
193 Result := l_generator.fixes
194
195 event_actions.notify_on_implementation_fix_generation_finished (Result)
196 progression_monitor.set_progression (progression_monitor.progression_fix_generation_end)
197 end
198 end
199
200 validate_implementation_fixes (a_trace_repository: AFX_PROGRAM_EXECUTION_TRACE_REPOSITORY; l_fixes: DS_ARRAYED_LIST [AFX_CODE_FIX_TO_FAULT]): DS_ARRAYED_LIST [AFX_CODE_FIX_TO_FAULT]
201 local
202 l_validator: AFX_FIX_VALIDATOR_NEW
203 do
204 if session.should_continue then
205 create l_validator.make (a_trace_repository, l_fixes)
206 progression_monitor.set_progression (progression_monitor.progression_fix_validation_start)
207 event_actions.notify_on_implementation_fix_validation_started (l_validator.fixes)
208
209 l_validator.validate
210 Result := l_validator.valid_fixes
211
212 event_actions.notify_on_implementation_fix_validation_finished (l_validator.valid_fixes)
213 progression_monitor.set_progression (progression_monitor.progression_fix_validation_end)
214 end
215 end
216
217 collect_behavior_of_relaxed_tests (a_feature_to_relax: AFX_FEATURE_TO_MONITOR): AFX_PROGRAM_EXECUTION_TRACE_REPOSITORY
218 --
219 local
220 l_features: DS_HASH_SET [AFX_FEATURE_TO_MONITOR]
221 l_features_to_monitor: DS_ARRAYED_LIST [AFX_FEATURE_TO_MONITOR]
222 l_feature_table: DS_HASH_TABLE [DS_HASH_SET [EPA_FEATURE_WITH_CONTEXT_CLASS], BOOLEAN]
223 l_feature_contract_remover: EPA_FEATURE_CONTRACT_REMOVER
224 l_collector: AFX_TRACE_COLLECTOR
225 do
226 event_actions.notify_on_weakest_contract_inference_started (a_feature_to_relax)
227
228 -- Relax feature contracts
229 create l_features.make_equal (1)
230 l_features.force (a_feature_to_relax)
231 create l_feature_table.make_equal (2)
232 l_feature_table.force (l_features, True)
233 l_feature_table.force (l_features.twin, False)
234 create l_feature_contract_remover
235 l_feature_contract_remover.remove_contracts_of_features (l_feature_table)
236 compile_project (Eiffel_project, True)
237
238 -- Monitor behavior of feature with relaxed contracts
239 create l_features_to_monitor.make_equal (1)
240 l_features_to_monitor.force_last (a_feature_to_relax)
241 create l_collector
242 l_collector.set_monitor_mode (l_collector.mode_analyze_relaxed_tc)
243 l_collector.set_features_to_monitor (l_features_to_monitor)
244 l_collector.collect (True)
245 if l_collector.trace_repository /= Void then
246 Result := l_collector.trace_repository.derived_compound_repository (l_features_to_monitor, True)
247 else
248 create Result.make_default
249 end
250 l_feature_contract_remover.undo_last_removal
251 compile_project (Eiffel_project, True)
252
253 event_actions.notify_on_weakest_contract_inference_finished (a_feature_to_relax)
254 end
255
256 generate_contract_fixes (a_traces_before_fixing, a_traces_after_relaxing: AFX_PROGRAM_EXECUTION_TRACE_REPOSITORY): DS_ARRAYED_LIST [AFX_CONTRACT_FIX_TO_FAULT]
257 --
258 local
259 l_fixes: DS_ARRAYED_LIST [AFX_CONTRACT_FIX_ACROSS_FEATURES]
260 l_strengthener: AFX_TRACE_BASED_CONTRACT_STRENGTHENER
261 l_weakener: AFX_TRACE_BASED_CONTRACT_WEAKENER
262 l_regular_traces, l_relaxed_traces, l_failing_regular_traces, l_passing_regular_traces, l_all_traces: DS_ARRAYED_LIST [AFX_PROGRAM_EXECUTION_TRACE]
263
264 l_fix: AFX_CONTRACT_FIX_ACROSS_FEATURES
265 l_new_fix: AFX_CONTRACT_FIX_TO_FAULT
266 do
267 create Result.make_equal (64)
268 if session.should_continue then
269 event_actions.notify_on_contract_fix_generation_started
270
271 create l_regular_traces.make_equal (a_traces_before_fixing.count + 1)
272 a_traces_before_fixing.do_all (agent l_regular_traces.force_last)
273 create l_relaxed_traces.make_equal (a_traces_after_relaxing.count + 1)
274 a_traces_after_relaxing.do_all (agent l_relaxed_traces.force_last)
275 create l_passing_regular_traces.make_equal (a_traces_before_fixing.count + 1)
276 l_regular_traces.do_if (agent l_passing_regular_traces.force_last, agent {AFX_PROGRAM_EXECUTION_TRACE}.is_passing)
277 create l_failing_regular_traces.make_equal (a_traces_before_fixing.count + 1)
278 l_regular_traces.do_if (agent l_failing_regular_traces.force_last, agent {AFX_PROGRAM_EXECUTION_TRACE}.is_failing)
279 create l_all_traces.make_equal (l_regular_traces.count + l_relaxed_traces.count + 1)
280 l_regular_traces.do_all (agent l_all_traces.force_last)
281 l_relaxed_traces.do_all (agent l_all_traces.force_last)
282
283 -- Prefer weakening
284 create l_weakener
285 l_weakener.fix_traces (l_regular_traces, l_relaxed_traces, features_to_monitor)
286 Result.append_last (l_weakener.last_contract_fixes)
287
288 create l_strengthener
289 l_strengthener.fix_traces (l_passing_regular_traces, l_failing_regular_traces, l_relaxed_traces, features_to_monitor)
290 Result.append_last (l_strengthener.last_contract_fixes)
291
292 event_actions.notify_on_contract_fix_generation_finished (Result)
293 end
294 end
295
296 validate_contract_fixes (a_contract_fixes: DS_ARRAYED_LIST [AFX_CONTRACT_FIX_TO_FAULT])
297 --
298 local
299 l_features_to_weaken: DS_HASH_SET [AFX_FEATURE_TO_MONITOR]
300 l_feature_table: DS_HASH_TABLE [DS_HASH_SET [EPA_FEATURE_WITH_CONTEXT_CLASS], BOOLEAN]
301 l_fix_validator: AFX_TEST_CASE_MONITOR_FOR_FIX_VALIDATION
302 l_collector: AFX_TRACE_COLLECTOR
303 l_trace_for_validation: AFX_PROGRAM_EXECUTION_TRACE_REPOSITORY
304 l_cursor: DS_ARRAYED_LIST_CURSOR [AFX_CONTRACT_FIX_TO_FAULT]
305 l_feature_contract_remover: EPA_FEATURE_CONTRACT_REMOVER
306 do
307 if session.should_continue then
308 event_actions.notify_on_contract_fix_validation_started (a_contract_fixes)
309
310 -- Disable the preconditions of `features_to_monitor'.
311 create l_features_to_weaken.make_equal (10)
312 features_to_monitor.do_all (agent l_features_to_weaken.force_last)
313 create l_feature_table.make_equal (2)
314 l_feature_table.force (l_features_to_weaken, True)
315 create l_feature_contract_remover
316 l_feature_contract_remover.remove_contracts_of_features (l_feature_table)
317 compile_project (Eiffel_project, True)
318
319 -- Run all available tests and collect the traces.
320 create l_collector
321 l_collector.set_monitor_mode (l_collector.mode_analyze_all_tc)
322 l_collector.set_features_to_monitor (features_to_monitor)
323 l_collector.collect (True)
324 l_trace_for_validation := l_collector.trace_repository.derived_compound_repository (features_to_monitor, True)
325
326 -- Restore the preconditions.
327 l_feature_contract_remover.undo_last_removal
328 compile_project (Eiffel_project, True)
329
330 -- Validate fixes w.r.t. the observed traces.
331 a_contract_fixes.do_all (
332 agent (a_fix: AFX_CONTRACT_FIX_TO_FAULT; a_traces: AFX_PROGRAM_EXECUTION_TRACE_REPOSITORY; a_all_features_to_monitor: DS_ARRAYED_LIST [AFX_FEATURE_TO_MONITOR])
333 do a_fix.compute_ranking_wrt_trace_repository (a_traces, a_all_features_to_monitor) end (?, l_trace_for_validation, features_to_monitor))
334
335 -- Remove invalid fixes.
336 from
337 l_cursor := a_contract_fixes.new_cursor
338 l_cursor.start
339 until
340 l_cursor.after
341 loop
342 if l_cursor.item.ranking >= {AFX_CONTRACT_FIX_TO_FAULT}.Ranking_weight_for_failing then
343 a_contract_fixes.remove_at_cursor (l_cursor)
344 else
345 l_cursor.forth
346 end
347 end
348
349 event_actions.notify_on_contract_fix_validation_finished (a_contract_fixes)
350 end
351 end
352
353 sort_contract_fixes (a_contract_fixes: DS_ARRAYED_LIST [AFX_CONTRACT_FIX_TO_FAULT])
354 --
355 local
356 l_sorter: DS_QUICK_SORTER [AFX_CONTRACT_FIX_TO_FAULT]
357 do
358 create l_sorter.make (create {AGENT_BASED_EQUALITY_TESTER [AFX_CONTRACT_FIX_TO_FAULT]}.make (
359 agent (f1, f2: AFX_CONTRACT_FIX_TO_FAULT): BOOLEAN
360 do
361 Result := f1.ranking <= f2.ranking
362 end (?, ?)))
363 l_sorter.sort (a_contract_fixes)
364 end
365
366 rank_fixes
367 --
368 local
369 do
370 event_actions.notify_on_fix_ranking_started (fixes)
371
372
373 event_actions.notify_on_fix_ranking_finished (fixes)
374 end
375
376 disable_catcall_warnings
377 -- Disable catcall console and debugger warnings.
378 external
379 "C inline"
380 alias
381 "[
382 extern int catcall_detection_mode;
383 catcall_detection_mode = 0;
384 ]"
385 end
386
387 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23