Eonblast An Erlang Game Stack Erlang User Conference 2012 H. Diedrich Lua + Erlang + VoltDB.
Erlang Code Evolution Control - unich.it
Transcript of Erlang Code Evolution Control - unich.it
![Page 1: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/1.jpg)
Erlang Code EvolutionControl
1Universitat Politècnica de València2Universidad Politécnica de Madrid
David Insa1, Sergio Pérez1, Josep Silva1, Salvador Tamarit2
LOPSTR 2017 12/10/2017
![Page 2: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/2.jpg)
Content
• Introduction• The technique indetail• Type Analysis Phase• TestCaseGeneration Phase• Comparison Phase
• Recording the trace• SecEr tool• Conclusions&FutureWork
![Page 3: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/3.jpg)
Introduction• Indebugging programmers usebreakpoints toobservethe values ofanexpression during an execution
• Is this feature available intesting?
• It would beuseful tofocus the testcaseson an specific point without codemodifications
OURPROPOSALØ Introducethe ability tospecify Points OfInterest (POI) inthe context of
testing
Ø Atechnique tocomparetwo equivalent POIs indifferent versionsofthe same program for Erlang
![Page 4: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/4.jpg)
Old Version
main(X,Y) ->A = X + Y,
D = X – Y,A * D.
New Version
main(X,Y) ->A = add(X,Y),
D = sub(X,Y),A * D.
add(X,Y)->
X + Y.
sub(X,Y) ->
X – Y.
1.- Identify a POI and a set of input functions2.- A test suite is automatically generated
Each test case contains:• A call to an input function with specific arguments• The sequence of values the POI is evaluated to (trace)
3.- Each test case is passed against the newversion and both traces are compared
4.- A report of the success or failure of the testcases is provided
main(5,4)OldVersionTrace:1NewVersionTrace:1
Success
Introduction
We have implemented our approach for Erlanginatool named SecEr
![Page 5: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/5.jpg)
Old Version
main(X,Y) ->A = X + Y,
D = X – Y,A * D.
New Version
main(X,Y) ->A = add(X,Y),
D = sub(X,Y),A * D.
add(X,Y)->
X + Y.
X – Y.
1.- Identify a POI and a set of input functions2.- A test suite is automatically generated
Each test case contains:• A call to an input function with specific arguments• The sequence of values the POI is evaluated to (trace)
3.- Each test case is passed against the newversion and both traces are compared
4.- A report of the success or failure of the testcases is provided
main(5,4)OldVersionTrace:1NewVersionTrace:1
Success
Introduction
We have implemented our approach for Erlanginatool named SecEr
sub(Y,X) ->
main(5,4)OldVersionTrace:1NewVersionTrace:-1
Failure
![Page 6: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/6.jpg)
Content
• Introduction• The technique indetail• Type Analysis Phase• TestCaseGeneration Phase• Comparison Phase
• Recording the trace• SecEr tool• Conclusions&FutureWork
![Page 7: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/7.jpg)
TypeAnalysisPhase
TestCaseGeneration
Phase
ComparisonPhase
Input TestCase
FinalReport
The technique in detail
![Page 8: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/8.jpg)
TypeAnalysisPhase
TestCaseGeneration
Phase
ComparisonPhase
Input TestCase
FinalReport
The technique in detail
![Page 9: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/9.jpg)
TypEr PropEr CutErInput InputTypesModule.erl
TypEr PropEr CutErFunction
Type analysis phase
![Page 10: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/10.jpg)
TypEr.erl
Fun
2.- The length ofthe list is unkwnown
3.- The repeated-variablerestriction is ignored
f(1,[1,2,5,6])
f(1,[2,5])
Solution: Consider each clause independently andrefinethe result totypes perclause
TypEr+newcode PropEr CutEr InputsTypes〈Clause
,Types〉Input
f(A,[A,B]) “-spec f(1|2,[1|2|5|6])->…”
1.- The infered types refer tothe whole function
g(0,0)->…g(1,1)->… “-spec g(0|1, 0|1)->…”
g(0,1)
Type analysis phase
![Page 11: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/11.jpg)
.erl
FunTypEr
+newcode PropEr
Propertytest
prop_identity() ->?FORALL(X, any(), id(X) = X).
id(X) -> X.
genPropErTypes Value
CutEr InputsInput〈Clause,Types〉
gen
PropEr
true|false
Type analysis phase
... ...
![Page 12: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/12.jpg)
PropErgen
PropErtypes Input
.erl
FunTypEr
+ newcode PropErPropEr+newcode CutEr InputsInput〈Clause
,Types〉
TypErtypes
TypEr toPropEr
ClauseParameters
2.- The length ofthe list is unknown
3.- Repeated variablerelation is lostSolution: Traverse the list parameters ofthe clause element by element
Solution: Storethe values ofalready treated variables
f(A,[A,B])
Type analysis phase
〈Clause,Types〉
PropErtypes
TypErtypes ≠
![Page 13: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/13.jpg)
.erl
FunTypEr
+newcodePropEr
+newcodeInput
concolicgen
Input
RuntimeErrors
〈Clause,Types〉
CutEr InputsCutEr
+newcode
CutEr
Inputs...
...
Inputs
Type analysis phase
![Page 14: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/14.jpg)
TypeAnalysisPhase
TestCaseGeneration
Phase
ComparisonPhase
Input TestCase
FinalReport
The technique in detail
![Page 15: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/15.jpg)
.erl1
POI1
codeinstrumentator
.erl1’
Input Input execute Trace1inputselector
randomgen
mutatinggenNew? New
InputT
NewInput
F
add
Continue until alimit is reached
Storeall the generated testcases(Input+Trace)
TestCase
Test case generation phase
![Page 16: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/16.jpg)
TypeAnalysisPhase
TestCaseGeneration
Phase
ComparisonPhase
Input TestCase
FinalReport
The technique in detail
![Page 17: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/17.jpg)
.erl2
POI2
codeinstrumentator
.erl2’
TestCase
testcaseselector
Test case
Trace1
Input
execute Trace2 tracecomparator
ComparisonResult
Result
FinalReport
Resultanalyzer
add
Comparison phase
![Page 18: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/18.jpg)
Content
• Introduction• The technique indetail• Type Analysis Phase• TestCaseGeneration Phase• Comparison Phase
• Recording the trace• SecEr tool• Conclusions&FutureWork
![Page 19: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/19.jpg)
Recording the trace
• There areseveral tools for tracing executions inErlang• None ofthem allows us tocollect the traceofpatterns• Debuggers will not provide avalue for aPOIif it is inside anexpression whose evaluation failsOURPROPOSAL
Ø Collect the tracesasaside effect when executing the codeØ Approach based on message passing toatracing server
Ø The code needs tobeinstrumented (4STEPS)
{1,B,3} = {1,2,4}
![Page 20: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/20.jpg)
Recording the trace (1 & 2)
1. Obtain andannotate the Abstract Syntax Tree ofthe program.Annotate each node with two lists ofvariables:
2. Find the selected POIinthe ASTwith atop-down traversal:
§ Variablesbeingbound inits subtree§ Variablesthatwere alreadyboundwhen reaching the node
§ Storethe current traversed pathwith tuples oftheform (Node,ChildIndex)
§ The result is apath that yields directly tothe POI
A
B C
D
POI
GF
(POI,1)
(F,1)
(E,2)
(B,1)
E
![Page 21: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/21.jpg)
3. Analyze the location ofthe POI• Expressions: Add asend command toinform the tracing server• Patterns:Need special treatment
Recording the trace (3)
{1,B,3} = {1,2,4}
Targetexpressions• Pattern-matching• List comprehension• Expressions with clauses:
• if• case• functions• etc.
2
![Page 22: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/22.jpg)
Recording the trace (3)
Dividethe ASTpath into two sub-paths:• PathBefore:Root ->deepest targetexpression• PathAfter:First child ofthe targetexpression ->POI
A
B C
D TE
POI
GF
(POI,1)
(F,1)
(TE,2)
(B,1)PathBefore(B,1),(TE,2)
PathAfter(F,1),(POI,1)
B
TE
F
POI
![Page 23: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/23.jpg)
Recording the trace (4)
4. Perform the actualinstrumentation• Traverse the PathBefore• Transform the code following aruleaccording toPathAfter• TraversePathBefore backwards toupdate the AST
Five exclusiverulestoinstrument expressions• LEFT_PM(pattern-matching)• PAT_GEN_LC (list comprehensions)• CLAUSE_PAT (pattern inexpressions with clauses)• CLAUSE_GUARD (guard inexpressions with clauses)• EXPR(expressions)
A
B C
D TE
GF
B
TE
F
POI
NewSubtree
![Page 24: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/24.jpg)
p = e → p = begin np = e, tracer!{add, npoi}, np end(p = e, _ ) = last(PathBefore)⋀ (_, pos(p)) = hd(PathAfter)
(_, npoi, np) = pfv(p,PathAfter)
(LEFT_PM)if
where
Recording the trace (4)
{1,B,3} = {1,2,4}
{1,B,3} = begin{1,POI,FV} = {1,2,4},tracer ! {add,POI},{1,POI,FV}
end
p = e → p = begin np = e, tracer!{add, npoi}, np end(p = e, _ ) = last(PathBefore)⋀ (_, pos(p)) = hd(PathAfter)
(_, npoi, np) = pfv(p,PathAfter)
p = e
p = begin
np = etracer!{add, npoi}
npend
![Page 25: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/25.jpg)
Content
• Introduction• The technique indetail• Type Analysis Phase• TestCaseGeneration Phase• Comparison Phase
• Recording the trace• SecEr tool• Conclusions&FutureWork
![Page 26: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/26.jpg)
SecEr command:$ ./secer -f FILE –li LINE – var VARIABLE [-oc OCCURRENCE]
-f FILE –li LINE – var VARIABLE [-oc OCCURRENCE][-funs INPUT_FUNCTIONS] –to TIMEOUT
SecEr tool
Old_Version_POI
New_Version_POI
![Page 27: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/27.jpg)
SecEr toolhappy0.erl happy1.erl
$ ./secer -f happy0.erl –li 9 – var Happy -oc 1
-f happy1.erl –li 18 – var Happy -oc 1
-funs [main/2] –to 15
![Page 28: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/28.jpg)
SecEr tool
![Page 29: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/29.jpg)
SecEr tool
![Page 30: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/30.jpg)
SecEr tool
![Page 31: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/31.jpg)
Content
• Introduction• The technique indetail• Type Analysis Phase• TestCaseGeneration Phase• Comparison Phase
• Recording the trace• SecEr tool• Conclusions&FutureWork
![Page 32: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/32.jpg)
ConclusionsConclusions
• Combination ofErlang existing tools andmutation toimprove the result• Newapproach toautomatically check the behaviour preservation betweenversions
• Newtracing process that allows for placing aPOIinpatterns,guards andexpressions
Type AnalysisPhase
TestCaseGeneration
Phase
ComparisonPhaseInput Test
Case
FinalReport
{1,B,3} = {1,2,4}
{1,B,3} = begin{1,POI,FV} = {1,2,4},tracer ! POI,{1,POI,FV}
end
![Page 33: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/33.jpg)
FutureWork• Adapt the approach todeal with indeterminism• Increase the information stored intracestoreport non-functional properties such asefficiency
• Allow for the specification ofalist ofPOIs instead ofasinglePOI• Make the tool compatible with tests previously defined by theuser
Future Work
![Page 34: Erlang Code Evolution Control - unich.it](https://reader031.fdocuments.us/reader031/viewer/2022012516/6190b1c2f5f6e62f035e8232/html5/thumbnails/34.jpg)
Thank you for your attention!!
Any question?