Selected Topics of Software Technology 3 Repair & … Topics of Software Technology 3 2 Refactoring...
Transcript of Selected Topics of Software Technology 3 Repair & … Topics of Software Technology 3 2 Refactoring...
Selected Topics of Software Technology 3
Refactoring and Repair1
S C I E N C E P A S S I O N T E C H N O L O G Y
u www.tugraz.at
Selected Topics of Software Technology 3
Repair & Refactoring
Birgit Hofer
Institute for Software Technology
Selected Topics of Software Technology 3
Refactoring and Repair2
Outline
Model-based Software Debugging
o Traffic Light Example
Repair
o Genetic programming
o Software (C, Java)
o Spreadsheets
Refactoring
Exam
Selected Topics of Software Technology 3
Refactoring and Repair3
Outline
Model-based Software Debugging
o Traffic Light Example
Repair
o Genetic programming
o Software (C, Java)
o Spreadsheets
Refactoring
Exam
Selected Topics of Software Technology 3
Refactoring and Repair4
Traffic Light Example1. public static void test () {
2. TrafficLight tl = new TrafficLight(0); // initializes tl.state=0;
3. int i = 0;
4. int finalState;
5. while (i < 5) {
6. tl.printState();
7. if (tl.state == 0) {
8. tl.state = 1;
9. } else {
10. if (tl.state == 1) {
11. tl.state = 2;
12. } else {
13. if (tl.state == 2) {
14. tl.state = 3;
15. } else {
16. tl.state = 3; // should be tl.state = 0;
17. }
18. }
19. }
20. i++;
21. }
22. tl.printState();
23. finalState = tl.state;
24. }
Selected Topics of Software Technology 3
Refactoring and Repair5
Traffic Light Example – Hints for the solution
#FACTS
eq(not_intrace_0,0) # initialization
eq(finalState_0,1) # expected output value
eq(state_0,0) # input
Intrace variables
WHILEs are control-dependent of the previous WHILE
The IF in Line 7 is control-dependent on the previous WHILE
Each other IF is control-dependent on the previous IF.
Lines 8/11/12/16 are control-dependent on the previous IF
Line 20 is control-dependent on the previous WHILE
Line 23 is control-dependent on intrace_0.
Selected Topics of Software Technology 3
Refactoring and Repair6
Traffic Light Example
How many single fault solutions do you get?
Do you get a solution if you set the watchsumgeq/leg of the AB
variables to 0?
Would it help if you add more facts to the constraints system, e.g.
state_2=2?
Selected Topics of Software Technology 3
Refactoring and Repair7
Outline
Model-based Software Debugging
o Traffic Light Example
Repair
o Genetic programming
o Software (C, Java)
o Spreadsheets
Refactoring
Exam
Selected Topics of Software Technology 3
Refactoring and Repair8
Fault localization
Spectrum-based
Model-based
Repair Genetic
Spreadsheet
Quality Assurance
Techniques
Visualization
Static Analysis
Debugging
Testing
Modeling
Design & Maintenance
Support
Source: Jannach et al. “Avoiding, Finding and Fixing Spreadsheet Errors – A Survey of
Automated Approaches for Spreadsheet QA”, in Journal of Systems and Software, 2014.
Visualization: Patrick Koch,Diploma Seminar, TU Graz, 2015.
Debugging
Genetic
Selected Topics of Software Technology 3
Refactoring and Repair9
Evolutionary methodology to find computer
programs that perform a user-defined task
Genetic Programming
Selected Topics of Software Technology 3
Refactoring and Repair10
Principles of Genetic Programming (GP)
Evolution
Mutation
Cross-over
Survival of the fittest
Fitness function, e.g., test cases
Selected Topics of Software Technology 3
Refactoring and Repair11
Program Representation in GP
+
- *
/8
x
y
2
-
3
8 – x / 2 + y * (-3)
Selected Topics of Software Technology 3
Refactoring and Repair12
Mutation
+
- *
/8
x
y
2
-
3
8 – x / 2 + y * (-3)
+
8 + x / 2 + y * (-3)
Selected Topics of Software Technology 3
Refactoring and Repair13
Crossover 1
+
- *
8 y/
x 2
-
3
8 – x / 2 + y * (-3)
/
x 2
8 – x / 2 + y * x / 2
Selected Topics of Software Technology 3
Refactoring and Repair14
Crossover 2
-
/8
x 2
-
3x
Mutant 1 Mutant 2
/
x 2
Selected Topics of Software Technology 3
Refactoring and Repair15
Crossover 3 – Crossing back
-
/8
x 2
-
3x
Original program Mutant
/
x 2
Selected Topics of Software Technology 3
Refactoring and Repair16
Genetic Programming - Workflow
Source: Patrick W. Koch: “Framework for Automated Spreadsheet Debugging conducting Evolutionary Strategies”, Master-Project, 2013.
Selected Topics of Software Technology 3
Refactoring and Repair17
Outline
Model-based Software Debugging
o Traffic Light Example
Repair
o Genetic programming
o Software (C, Java)
o Spreadsheets
Refactoring
Exam
Selected Topics of Software Technology 3
Refactoring and Repair18
Genetic Programming For Automated Software Repair
Faulty
program
Test cases
AST
(abstract
syntax tree)
Copy1Copy2Copy1Copyn
Copy1Copy2Copy1Mutantn
Evaluation
(Fitness)
Elimination
Copy1Mutantn
Source: Forrest et al.: “A Genetic Programming Approach to Automated Software Repair”, GECCO, 2009.
Selected Topics of Software Technology 3
Refactoring and Repair19
Genetic Programming For Automated Software Repair
Faulty
program
Test cases
AST
(abstract
syntax tree)
Copy1Copy2Copy1Copyn
Copy1Copy2Copy1Mutantn
Evaluation
(Fitness)
Elimination
Copy1Mutantn
Source: Forrest et al.: “A Genetic Programming Approach to Automated Software Repair”, GECCO, 2009.
Minimized
Solution
Selected Topics of Software Technology 3
Refactoring and Repair20
Smart statement selection for mutation
Weighted pathStatement visited by
Negative TC 1.0
Positive and negative TC 0.1
Positive TC 0.0
Finer-grained selection possible
Do you have ideas for a finer selection?
Selected Topics of Software Technology 3
Refactoring and Repair21
Mutation operators
Delete statement
Insert statement
Swap statements
Selected Topics of Software Technology 3
Refactoring and Repair22
GCD Example
Source: Weimer et al.: “automatically finding patches using genetic programming”, ICSE, 2009.
Test case
gcc(0,55)
Selected Topics of Software Technology 3
Refactoring and Repair23
GCD Example
Program passes test case
We need more test cases
Source: Weimer et al.: “automatically finding patches using genetic programming”, ICSE, 2009.
Test case
gcc(0,55)
Test case
gcc(0,55)
gcc(1071,1029)
Selected Topics of Software Technology 3
Refactoring and Repair24
Test Cases and Fitness Function
Negative Test Cases Characterize the fault
Positive Test Cases Encode the functionality requirements
Fitness Function
The more passing test cases - the better the score
All test cases pass – repair found
Selected Topics of Software Technology 3
Refactoring and Repair25
GCD Example – Primary Repair
Source: Weimer et al.: “automatically finding patches using genetic programming”, ICSE, 2009.
Test case
gcc(0,55)
Test case
gcc(0,55)
gcc(1071,1029)
Selected Topics of Software Technology 3
Refactoring and Repair26
The Zune Bug
Source: Forrest et al.: “A Genetic Programming Approach to Automated Software Repair”, GECCO, 2009.
Test cases
Selected Topics of Software Technology 3
Refactoring and Repair29
ASTOR
Automatic Software Transformation fOr program Repair
Tool for automatically repairing Java programs
Under GPL v2 (GNU General Public License)
Uses Spoon (library for Java code analysis and
manipulation)
Source: Martinez and Monperrrus: “ASTOR - Evolutionary Automatic Software Repair for Java”,
Technical Report hal-01075976, Inria, 2014
Selected Topics of Software Technology 3
Refactoring and Repair30
Outline
Model-based Software Debugging
o Traffic Light Example
Repair
o Genetic programming
o Software (C, Java)
o Spreadsheets
Refactoring
Exam
Selected Topics of Software Technology 3
Refactoring and Repair31
GP for Spreadsheets – Mutations
Constants
Change Boolean values
Permutate digits
Increase / decrease number by 1
Use a random number
Change sign
References
Increase/decrease the borders of areas
Change a single reference
Formulas
Replace a binary operator with another binary operator
A1+A2 A1-A2
Replace a formula with another formula which can process the same arguments
SUM(A1:A4) AVG(A1:A4)
Remove parts of a formula
A3+A4*3 A3*3
Relocate parts of a formula
if(A1>1;A2;A3) if(A1>1;A3;A2)
Selected Topics of Software Technology 3
Refactoring and Repair32
Genetic Programming for Spreadsheet Repair I
Selected Topics of Software Technology 3
Refactoring and Repair33
Genetic Programming for Spreadsheet Repair II
Selected Topics of Software Technology 3
Refactoring and Repair34
Genetic Programming for Spreadsheets
Selected Topics of Software Technology 3
Refactoring and Repair35
Outline
Model-based Software Debugging
o Traffic Light Example
Repair
o Genetic programming
Refactoring
Exam
Selected Topics of Software Technology 3
Refactoring and Repair36
Process of changing the internal structure of
a program without changing the functionality
Refactoring
Selected Topics of Software Technology 3
Refactoring and Repair37
How does refactoring
contribute to the quality
of spreadsheets?
Selected Topics of Software Technology 3
Refactoring and Repair38
BumbleBee
f1 ↔ f2
SUM(R)/COUNT(R) ↔ AVERAGE(R)
Parameterized references via variables
A1+A2+A3 ↔ SUM(A1:A3)
{i,j} + {i,j+1} ↔ SUM({i,j}:{j,j+1})
Areas
{i,j}+…+{m,n} ↔ SUM({i,j}:{m,n})
Source: Hermans and Dig: “BumbleBee: A Refactoring Environment for Spreadsheet Formulas”, FSE 2014.
Selected Topics of Software Technology 3
Refactoring and Repair39
TableProg
Source: Harris and Gulwani: “Spreadsheet Table Transformations from Examples”, PLDI, 2011.
Selected Topics of Software Technology 3
Refactoring and Repair40
TableProg
Source: Harris and Gulwani: “Spreadsheet Table Transformations from Examples”, PLDI, 2011.
Selected Topics of Software Technology 3
Refactoring and Repair41
TableProg
Source: Harris and Gulwani: “Spreadsheet Table Transformations from Examples”, PLDI, 2011.
Selected Topics of Software Technology 3
Refactoring and Repair42
Outline
Model-based Software Debugging
o Traffic Light Example
Repair
o Genetic programming
o Software (C, Java)
o Spreadsheets
Refactoring
Exam
Selected Topics of Software Technology 3
Refactoring and Repair43
Exam
General
List Fault Types
List Quality Assurance Techniques (+ subcategories)
Explain R1C1 cell reference system
Static Code Analysis techniques
Explain the terms Code Smells and Refactoring
List, explain and identity Software/Spreadsheet Code Smells
List and explain Static Spreadsheet Analysis Techniques (UCheck, …)
Spectrum-based fault localization
Explain and apply SFL to software snippets and spreadsheets
Explain the terms
o Observation matrix
o Error vector
o Similarity coefficient
o Best/worst/average case ranking
o Cone
Selected Topics of Software Technology 3
Refactoring and Repair44
Exam
Model-based fault localization
List + explain all parts of diagnosis problem
Explain the terms
o Conflict / Conflict set
o Diagnosis / Minimal diagnosis
o Hitting Set / Minimal hitting set
o SSA form
Solve simple examples via conflicts and hitting sets (hardware, simple software)
Write (in pseudo code) a dependency-/value-based model for a given spreadsheet
Explain how to compute double fault diagnoses
List, explain and compare (+/-) the different types of behavior models
Explain how to derive a dependency-based model from a value-based model (+ apply
by means of an example)
Explain coincidental correctness + list examples
Explain how MBSD for Software works
Compare SFL with MBSD w.r.t. complexity, granularity, input, result …
Selected Topics of Software Technology 3
Refactoring and Repair45
Exam
Automatic repair
Explain the terms
o Genetic Programming
o Mutation (+ list different types)
o Crossover (+ list / explain different types)
o Fitness function
Explain how automatic repair with genetic programming works for
software/spreadsheets
Selected Topics of Software Technology 3
Refactoring and Repair46
Haven’t you had enough
of spreadsheets yet?
Master Project
Diploma Thesis