Erlang Code Evolution Control David Insa 1 , Sergio Prez 1 , Josep - - PowerPoint PPT Presentation

erlang code evolution control
SMART_READER_LITE
LIVE PREVIEW

Erlang Code Evolution Control David Insa 1 , Sergio Prez 1 , Josep - - PowerPoint PPT Presentation

Erlang Code Evolution Control David Insa 1 , Sergio Prez 1 , Josep Silva 1 , Salvador Tamarit 2 1 Universitat Politcnica de Valncia 2 Universidad Politcnica de Madrid LOPSTR 2017 12/10/2017 Content Introduction The technique in


slide-1
SLIDE 1

Erlang Code Evolution Control

1Universitat Politècnica de València 2Universidad Politécnica de Madrid

David Insa1, Sergio Pérez1, Josep Silva1, Salvador Tamarit2

LOPSTR 2017 12/10/2017

slide-2
SLIDE 2

Content

  • Introduction
  • The technique in detail
  • Type Analysis Phase
  • Test Case Generation Phase
  • Comparison Phase
  • Recordingthe trace
  • SecEr tool
  • Conclusions& Future Work
slide-3
SLIDE 3

Introduction

  • In debugging programmers use breakpoints to observe the values of an

expression during an execution

  • Is this feature available in testing?
  • It would be useful to focus the test cases on an specific point without code

modifications

OUR PROPOSAL

Ø Introduce the ability to specify Points Of Interest (POI) in the context of testing Ø A technique to compare two equivalent POIs in different versions

  • f the same program for Erlang
slide-4
SLIDE 4

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 functions 2.- 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 new version and both traces are compared 4.- A report of the success or failure of the test cases is provided

main(5,4) OldVersionTrace: 1 NewVersionTrace: 1 Success

Introduction

We have implemented our approach for Erlang in a tool named SecEr

slide-5
SLIDE 5

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 functions 2.- 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 new version and both traces are compared 4.- A report of the success or failure of the test cases is provided

main(5,4) OldVersionTrace: 1 NewVersionTrace: 1 Success

Introduction

We have implemented our approach for Erlang in a tool named SecEr

sub(Y,X) -> main(5,4) OldVersionTrace: 1 NewVersionTrace: -1 Failure

slide-6
SLIDE 6

Content

  • Introduction
  • The technique in detail
  • Type Analysis Phase
  • Test Case Generation Phase
  • Comparison Phase
  • Recordingthe trace
  • SecEr tool
  • Conclusions& Future Work
slide-7
SLIDE 7

Type Analysis Phase Test Case Generation Phase Comparison Phase

Input Test Case Final Report

The technique in detail

slide-8
SLIDE 8

Type Analysis Phase Test Case Generation Phase Comparison Phase

Input Test Case Final Report

The technique in detail

slide-9
SLIDE 9

TypEr PropEr CutEr

Input Input Types Module.erl

TypEr PropEr CutEr

Function

Type analysis phase

slide-10
SLIDE 10

TypEr

.erl Fun

2.- The length of the list is unkwnown 3.- The repeated-variable restrictionis ignored

f(1,[1,2,5,6]) f(1,[2,5])

Solution: Consider each clause independently and refine the result to types per clause

TypEr + new code

PropEr CutEr

Inputs Types 〈Clause ,Types〉 Input

f(A,[A,B]) “-spec f(1|2,[1|2|5|6])->…”

1.- The infered types refer to the whole function

g(0,0)->… g(1,1)->… “-spec g(0|1, 0|1)->…” g(0,1)

Type analysis phase

slide-11
SLIDE 11

.erl Fun

TypEr + new code

PropEr Property test

prop_identity() -> ?FORALL(X, any(), id(X) = X). id(X) -> X.

gen

PropEr Types Value

CutEr

Inputs Input 〈Clause ,Types〉

gen

PropEr true | false

Type analysis phase

. . . . . .

slide-12
SLIDE 12

PropEr gen

PropEr types Input .erl Fun

TypEr + new code

PropEr

PropEr + new code

CutEr

Inputs Input 〈Clause ,Types〉 TypEr types TypEr to PropEr Clause Parameters

2.- The length of the list is unknown 3.- Repeated variable relation is lost

Solution: Traverse the list parameters of the clause element by element Solution: Store the values of already treated variables

f(A,[A,B])

Type analysis phase

〈Clause ,Types〉 PropEr types TypEr types

slide-13
SLIDE 13

.erl Fun

TypEr + new code PropEr + new code

Input

concolic gen

Input Runtime Errors

〈Clause ,Types〉

CutEr

Inputs

CutEr + new code

CutEr

Inputs

. . . . . .

Inputs

Type analysis phase

slide-14
SLIDE 14

Type Analysis Phase Test Case Generation Phase Comparison Phase

Input Test Case Final Report

The technique in detail

slide-15
SLIDE 15

.erl1 POI1 code instrumentator .erl1’ Input Input execute Trace1 input selector random gen mutating gen New? New Input

T

New Input

F add

Continue until a limit is reached Store all the generated test cases (Input + Trace)

Test Case

Test case generation phase

slide-16
SLIDE 16

Type Analysis Phase Test Case Generation Phase Comparison Phase

Input Test Case Final Report

The technique in detail

slide-17
SLIDE 17

.erl2 POI2 code instrumentator .erl2’ Test Case test case selector Test case

Trace1 Input

execute Trace2 trace comparator Comparison Result Result Final Report Result analyzer add

Comparison phase

slide-18
SLIDE 18

Content

  • Introduction
  • The technique in detail
  • Type Analysis Phase
  • Test Case Generation Phase
  • Comparison Phase
  • Recordingthe trace
  • SecEr tool
  • Conclusions& Future Work
slide-19
SLIDE 19

Recording the trace

  • There are several tools for tracing executions in Erlang
  • None of them allows us to collect the trace of patterns
  • Debuggers will not provide a value for a POI if it is inside an

expression whose evaluation fails OUR PROPOSAL Ø Collect the traces as a side effect when executing the code Ø Approach based on message passing to a tracing server Ø The code needs to be instrumented (4 STEPS)

{1,B,3} = {1,2,4}

slide-20
SLIDE 20

Recording the trace (1 & 2)

  • 1. Obtain and annotate the Abstract Syntax Tree of the program.

Annotate each node with two lists of variables:

  • 2. Find the selected POI in the AST with a top-down traversal:

§ Variables beingbound in its subtree § Variables that were alreadybound when reaching the node § Store the current traversed path with tuples of the form (Node,ChildIndex) § The result is a path that yields directly to the POI

A B C D POI G F (POI,1) (F,1) (E,2) (B,1) E

slide-21
SLIDE 21
  • 3. Analyze the location of the POI
  • Expressions: Add a send command to inform the tracing server
  • Patterns: Need special treatment

Recording the trace (3)

{1,B,3} = {1,2,4}

Target expressions

  • Pattern-matching
  • List comprehension
  • Expressions with clauses:
  • if
  • case
  • functions
  • etc.

2

slide-22
SLIDE 22

Recording the trace (3)

Divide the AST path into two sub-paths:

  • PathBefore: Root -> deepest target expression
  • PathAfter: First child of the target expression -> POI

A B C D TE POI G F (POI,1) (F,1) (TE,2) (B,1)

PathBefore (B,1),(TE,2) PathAfter (F,1),(POI,1)

B TE F POI

slide-23
SLIDE 23

Recording the trace (4)

  • 4. Perform the actual instrumentation
  • Traverse the PathBefore
  • Transform the code following a rule according to PathAfter
  • TraversePathBefore backwards to update the AST

Five exclusive rules to instrument expressions

  • LEFT_PM (pattern-matching)
  • PAT_GEN_LC (list comprehensions)
  • CLAUSE_PAT (pattern in expressions with clauses)
  • CLAUSE_GUARD (guard in expressions with clauses)
  • EXPR (expressions)

A B C D TE G F B TE F POI New Subtree

slide-24
SLIDE 24

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 = e tracer!{add, npoi} np end

slide-25
SLIDE 25

Content

  • Introduction
  • The technique in detail
  • Type Analysis Phase
  • Test Case Generation Phase
  • Comparison Phase
  • Recordingthe trace
  • SecEr tool
  • Conclusions& Future Work
slide-26
SLIDE 26

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

slide-27
SLIDE 27

SecEr tool

happy0.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
slide-28
SLIDE 28

SecEr tool

slide-29
SLIDE 29

SecEr tool

slide-30
SLIDE 30

SecEr tool

slide-31
SLIDE 31

Content

  • Introduction
  • The technique in detail
  • Type Analysis Phase
  • Test Case Generation Phase
  • Comparison Phase
  • Recordingthe trace
  • SecEr tool
  • Conclusions& Future Work
slide-32
SLIDE 32

Conclusions

Conclusions

  • Combination of Erlang existing tools and mutation to improve the result
  • New approach to automatically check the behaviour preservation between

versions

  • New tracing process that allows for placing a POI in patterns, guards and

expressions

Type Analysis Phase

Test Case Generation Phase Comparison Phase

Input Test Case Final Report

{1,B,3} = {1,2,4} {1,B,3} = begin {1,POI,FV} = {1,2,4}, tracer ! POI, {1,POI,FV} end

slide-33
SLIDE 33

Future Work

  • Adapt the approach to deal with indeterminism
  • Increase the information stored in traces to report non-

functional properties such as efficiency

  • Allow for the specification of a list of POIs instead of a single POI
  • Make the tool compatible with tests previously defined by the

user

Future Work

slide-34
SLIDE 34

Thank you for your attention!! Any question?